dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21020
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9848: Analytcs, adding name of category option combos to meta-data
------------------------------------------------------------
revno: 9848
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-02-19 17:12:47 +0100
message:
Analytcs, adding name of category option combos to meta-data
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Grid.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java
dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ConversionUtils.java
--
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-api/src/main/java/org/hisp/dhis/common/Grid.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Grid.java 2013-01-28 19:43:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Grid.java 2013-02-19 16:12:47 +0000
@@ -85,6 +85,11 @@
void setMetaData( Map<String, String> metaData );
/**
+ * Adds a key-value pair to meta-data.
+ */
+ void addMetaData( String key, String value );
+
+ /**
* Returns all visible headers, ie. headers which are not hidden.
*/
List<GridHeader> getVisibleHeaders();
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java 2013-02-13 03:57:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java 2013-02-19 16:12:47 +0000
@@ -308,11 +308,10 @@
name.append( "(" );
Iterator<DataElementCategoryOption> iterator = categoryOptions.iterator();
- DataElementCategoryOption dataElementCategoryOption = iterator.next();
-
- if ( dataElementCategoryOption != null )
+
+ if ( iterator.hasNext() )
{
- name.append( dataElementCategoryOption.getDisplayName() );
+ name.append( iterator.next().getDisplayName() );
}
while ( iterator.hasNext() )
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java 2013-01-05 15:22:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java 2013-02-19 16:12:47 +0000
@@ -302,6 +302,8 @@
* @return a Collection of DataElementCategoryOptionCombos.
*/
Collection<DataElementCategoryOptionCombo> getDataElementCategoryOptionCombos( Collection<Integer> identifiers );
+
+ Collection<DataElementCategoryOptionCombo> getDataElementCategoryOptionCombosByUid( Collection<String> uids );
/**
* Retrieves the DataElementCategoryOptionCombo with the given Collection
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2013-02-19 13:19:21 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2013-02-19 16:12:47 +0000
@@ -266,6 +266,17 @@
}
/**
+ * Returns the index of the category option combo dimension. Returns null
+ * if this dimension is not present.
+ */
+ public Integer getCocIndex()
+ {
+ int index = dimensions.indexOf( new Dimension( CATEGORYOPTIONCOMBO_DIM_ID ) );
+
+ return index == -1 ? null : index;
+ }
+
+ /**
* Indicates whether this object is of the given aggregation type.
*/
public boolean isAggregationType( AggregationType aggregationType )
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2013-02-19 13:19:21 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2013-02-19 16:12:47 +0000
@@ -45,8 +45,10 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -68,6 +70,8 @@
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.constant.ConstantService;
import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementGroupSet;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.dataelement.DataElementService;
@@ -86,6 +90,7 @@
import org.hisp.dhis.period.RelativePeriods;
import org.hisp.dhis.period.comparator.PeriodComparator;
import org.hisp.dhis.system.grid.ListGrid;
+import org.hisp.dhis.system.util.ConversionUtils;
import org.hisp.dhis.system.util.MathUtils;
import org.hisp.dhis.system.util.SystemUtils;
import org.hisp.dhis.system.util.Timer;
@@ -116,6 +121,9 @@
private DataElementService dataElementService;
@Autowired
+ private DataElementCategoryService categoryService;
+
+ @Autowired
private DataSetService dataSetService;
@Autowired
@@ -142,8 +150,7 @@
queryPlanner.validate( params );
params.conform();
-
-
+
// ---------------------------------------------------------------------
// Headers and meta-data
// ---------------------------------------------------------------------
@@ -271,6 +278,17 @@
}
}
+ // ---------------------------------------------------------------------
+ // Category option combo meta-data
+ // ---------------------------------------------------------------------
+
+ Integer cocIndex = params.getCocIndex();
+
+ if ( cocIndex != null )
+ {
+ addCocMetaData( grid, cocIndex );
+ }
+
return grid;
}
@@ -551,4 +569,16 @@
return map;
}
+
+ private void addCocMetaData( Grid grid, Integer cocIndex )
+ {
+ Set<String> uids = new HashSet<String>( ConversionUtils.<String>cast( grid.getColumn( cocIndex ) ) );
+
+ Collection<DataElementCategoryOptionCombo> cocs = categoryService.getDataElementCategoryOptionCombosByUid( uids );
+
+ for ( DataElementCategoryOptionCombo coc : cocs )
+ {
+ grid.addMetaData( coc.getUid(), coc.getName() );
+ }
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2013-02-04 04:14:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2013-02-19 16:12:47 +0000
@@ -325,6 +325,11 @@
}
} );
}
+
+ public Collection<DataElementCategoryOptionCombo> getDataElementCategoryOptionCombosByUid( Collection<String> uids )
+ {
+ return dataElementCategoryOptionComboStore.getByUid( uids );
+ }
public DataElementCategoryOptionCombo getDataElementCategoryOptionCombo(
Collection<DataElementCategoryOption> categoryOptions )
=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java 2013-02-07 08:40:18 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java 2013-02-19 16:12:47 +0000
@@ -392,6 +392,7 @@
}
@Override
+ @SuppressWarnings("unchecked")
public List<T> getAllEqName( String name )
{
Query query = sharingEnabled() ? getQueryAllEqNameACL( name ) : getQueryAllEqName( name );
@@ -423,6 +424,7 @@
}
@Override
+ @SuppressWarnings("unchecked")
public List<T> getAllEqNameIgnoreCase( String name )
{
Query query = sharingEnabled() ? getQueryAllEqNameACLIgnoreCase( name ) : getQueryAllEqNameIgnoreCase( name );
@@ -454,6 +456,7 @@
}
@Override
+ @SuppressWarnings("unchecked")
public List<T> getAllEqShortName( String shortName )
{
Query query = sharingEnabled() ? getQueryAllEqShortNameACL( shortName ) : getQueryAllEqShortName( shortName );
@@ -485,6 +488,7 @@
}
@Override
+ @SuppressWarnings("unchecked")
public List<T> getAllEqShortNameIgnoreCase( String shortName )
{
Query query = sharingEnabled() ? getQueryAllEqShortNameACLIgnoreCase( shortName ) : getQueryAllEqShortNameIgnoreCase( shortName );
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java 2013-01-28 19:43:36 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java 2013-02-19 16:12:47 +0000
@@ -229,6 +229,11 @@
this.metaData = metaData;
}
+ public void addMetaData( String key, String value )
+ {
+ this.metaData.put( key, value );
+ }
+
public int getVisibleWidth()
{
verifyGridState();
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ConversionUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ConversionUtils.java 2012-04-01 12:04:14 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ConversionUtils.java 2013-02-19 16:12:47 +0000
@@ -281,4 +281,24 @@
set.add( object );
return set;
}
+
+ /**
+ * Casts the elements in the given collection to the desired return type. It
+ * is the caller's responsibility that the types legally can be casted.
+ *
+ * @param collection the collection.
+ * @return a collection.
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> Collection<T> cast( Collection<? super T> collection )
+ {
+ Collection<T> list = new ArrayList<T>();
+
+ for ( Object o : collection )
+ {
+ list.add( (T) o );
+ }
+
+ return list;
+ }
}