dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31575
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16113: Centralized method into GridUtils
------------------------------------------------------------
revno: 16113
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-07-13 11:35:14 +0200
message:
Centralized method into GridUtils
modified:
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/widgets.css
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java 2014-07-12 23:24:13 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java 2014-07-13 09:35:14 +0000
@@ -30,7 +30,6 @@
import static org.hisp.dhis.analytics.AnalyticsService.NAMES_META_KEY;
import static org.hisp.dhis.analytics.AnalyticsService.OU_HIERARCHY_KEY;
-import static org.hisp.dhis.common.DimensionalObject.DIMENSION_SEP;
import static org.hisp.dhis.common.DimensionalObject.ORGUNIT_DIM_ID;
import static org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID;
import static org.hisp.dhis.common.DimensionalObjectUtils.getDimensionFromParam;
@@ -47,7 +46,6 @@
import java.util.Map;
import java.util.Set;
-import org.apache.commons.lang.StringUtils;
import org.hisp.dhis.analytics.AnalyticsSecurityManager;
import org.hisp.dhis.analytics.AnalyticsService;
import org.hisp.dhis.analytics.SortOrder;
@@ -79,6 +77,7 @@
import org.hisp.dhis.program.ProgramService;
import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.program.ProgramStageService;
+import org.hisp.dhis.system.grid.GridUtils;
import org.hisp.dhis.system.grid.ListGrid;
import org.hisp.dhis.system.util.DateUtils;
import org.hisp.dhis.system.util.ListUtils;
@@ -220,28 +219,15 @@
}
public Map<String, Double> getAggregatedEventDataMappping( EventQueryParams params )
- {
- Map<String, Double> map = new HashMap<>();
-
+ {
Grid grid = getAggregatedEventData( params );
-
- List<Integer> metaIndexes = grid.getMetaColumnIndexes();
int valueIndex = grid.getWidth() - 1;
-
- for ( List<Object> row : grid.getRows() )
- {
- String key = StringUtils.join( ListUtils.getAtIndexes( row, metaIndexes ), DIMENSION_SEP );
- Object val = row.get( valueIndex );
- Double value = val != null ? ((Integer) val).doubleValue() : null;
- map.put( key, value );
- }
-
- return map;
+ return GridUtils.getMetaValueMapping( grid, valueIndex );
}
public Map<String, Double> getAggregatedEventDataMappping( BaseAnalyticalObject object, I18nFormat format )
{
- EventQueryParams params = getFromAnalyticalObject( (EventChart) object, format );
+ EventQueryParams params = getFromAnalyticalObject( object, format );
return getAggregatedEventDataMappping( params );
}
@@ -461,7 +447,7 @@
}
/**
- * TODO Generalize and change from EventChart to EventAnayticalObject.
+ * TODO Generalize and change from EventChart to EventAnalyticalObject.
*/
public EventQueryParams getFromAnalyticalObject( BaseAnalyticalObject object_, I18nFormat format )
{
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java 2014-07-13 09:35:14 +0000
@@ -28,6 +28,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.common.DimensionalObject.DIMENSION_SEP;
import static org.hisp.dhis.system.util.CsvUtils.NEWLINE;
import static org.hisp.dhis.system.util.CsvUtils.SEPARATOR_B;
import static org.hisp.dhis.system.util.CsvUtils.csvEncode;
@@ -40,11 +41,13 @@
import static org.hisp.dhis.system.util.PDFUtils.getTitleCell;
import static org.hisp.dhis.system.util.PDFUtils.openDocument;
import static org.hisp.dhis.system.util.PDFUtils.resetPaddings;
+import static org.apache.commons.lang.StringUtils.*;
import java.io.OutputStream;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -73,6 +76,7 @@
import org.hisp.dhis.system.util.DateUtils;
import org.hisp.dhis.system.util.Encoder;
import org.hisp.dhis.system.util.ExcelUtils;
+import org.hisp.dhis.system.util.ListUtils;
import org.hisp.dhis.system.util.MathUtils;
import org.hisp.dhis.system.util.StreamUtils;
import org.hisp.dhis.system.velocity.VelocityManager;
@@ -592,6 +596,33 @@
return value.trim().replaceAll( " ", EMPTY );
}
+ /**
+ * Returns a mapping based on the given grid where the key is a joined string
+ * of the string value of each value for meta columns. The value is the object
+ * at the given value index. The map contains at maximum one entry per row in
+ * the given grid, less if the joined key string are duplicates. The object
+ * at the value index must be numeric.
+ *
+ * @param grid the grid.
+ * @param valueIndex the index of the column holding the value, must be numeric.
+ * @return a meta string to value object mapping.
+ */
+ public static Map<String, Double> getMetaValueMapping( Grid grid, int valueIndex )
+ {
+ Map<String, Double> map = new HashMap<>();
+
+ List<Integer> metaIndexes = grid.getMetaColumnIndexes();
+
+ for ( List<Object> row : grid.getRows() )
+ {
+ String key = StringUtils.join( ListUtils.getAtIndexes( row, metaIndexes ), DIMENSION_SEP );
+
+ map.put( key, Double.parseDouble( trimToEmpty( String.valueOf( row.get( valueIndex ) ) ) ) );
+ }
+
+ return map;
+ }
+
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/widgets.css'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/widgets.css 2014-07-12 11:33:56 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/widgets.css 2014-07-13 09:35:14 +0000
@@ -477,7 +477,7 @@
border: 1px solid #a4d2a3;
background-color: #d0eBd0;
padding-top: 10px;
- padding-bottom: 11px;
+ padding-bottom: 10px;
padding-left: 20px;
margin-bottom: 15px;
border-radius: 3px;