dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #03031
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1020: Work in progress on DimenionService
------------------------------------------------------------
revno: 1020
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Tue 2009-11-10 16:17:51 +0100
message:
Work in progress on DimenionService
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/DimensionService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.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/dimension/DimensionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/DimensionService.java 2009-11-10 14:02:08 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/DimensionService.java 2009-11-10 15:17:51 +0000
@@ -27,8 +27,11 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.Collection;
import java.util.Map;
+import org.hisp.dhis.dataelement.DataElement;
+
/**
* @author Lars Helge Overland
*/
@@ -36,5 +39,7 @@
{
final String ID = DimensionService.class.getName();
- Map<String, String> getDimensionSets();
+ Map<String, String> getDataElementDimensionSets();
+
+ Collection<DataElement> getDataElements( String identifier );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.java 2009-11-10 14:02:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.java 2009-11-10 15:17:51 +0000
@@ -27,19 +27,38 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryCombo;
import org.hisp.dhis.dataelement.DataElementCategoryService;
+import org.hisp.dhis.dataelement.DataElementGroupSet;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.indicator.IndicatorService;
+import org.hisp.dhis.system.util.ConversionUtils;
/**
+ * The DimensionSet identifier is on the format
+ * [TYPE]SEPARATOR_TYPE[id]SEPARATOR_ID[id]SEPARATOR[id], for instance
+ * groupSet_1-2-3 and categoryCombo_1 .
+ *
* @author Lars Helge Overland
* @version $Id: Indicator.java 5540 2008-08-19 10:47:07Z larshelg $
*/
public class DefaultDimensionService
implements DimensionService
{
+ final String TYPE_CATEGORY_COMBO = "categoryCombo";
+ final String TYPE_GROUP_SET = "groupSet";
+ final String SEPARATOR_TYPE = "_";
+ final String SEPARATOR_ID = "-";
+ final String SEPARATOR_NAME = ",";
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -69,8 +88,122 @@
// DimensionService implementation
// -------------------------------------------------------------------------
- public Map<String, String> getDimensionSets()
+ public Map<String, String> getDataElementDimensionSets()
{
+ Map<String, String> dimensions = new HashMap<String, String>();
+
+ for ( DataElementCategoryCombo categoryCombo : categoryService.getAllDataElementCategoryCombos() )
+ {
+ dimensions.put( getCategoryComboIdentifier( categoryCombo ), categoryCombo.getName() );
+ }
+
+ for ( Set<DataElementGroupSet> dimensionSet : getDistinctDataElemenDimensionSets() )
+ {
+ dimensions.put( getGroupSetIdentifier( dimensionSet ), getGroupSetName( dimensionSet ) );
+ }
+
+ return dimensions;
+ }
+
+ public Collection<DataElement> getDataElements( String identifier )
+ {
+ if ( identifier != null )
+ {
+ if ( getDimensionSetType( identifier ).equals( TYPE_CATEGORY_COMBO ) )
+ {
+ DataElementCategoryCombo categoryCombo = categoryService.getDataElementCategoryCombo( getDimensionSetIdentifiers( identifier )[0] );
+
+ return dataElementService.getDataElementByCategoryCombo( categoryCombo );
+ }
+ else // TYPE_GROUP_SET
+ {
+ Set<DataElementGroupSet> dimensionSet = getDataElementDimensionSet( getDimensionSetIdentifiers( identifier ) );
+
+ // TODO return dataElementService.getDataElementsByDimensionSet( dimensionSet );
+ }
+ }
+
return null;
}
+
+ // -------------------------------------------------------------------------
+ // Supportive methods
+ // -------------------------------------------------------------------------
+
+ private String getDimensionSetType( String identifier )
+ {
+ return identifier.split( SEPARATOR_TYPE )[0];
+ }
+
+ private Integer[] getDimensionSetIdentifiers( String identifier )
+ {
+ return ConversionUtils.getIntegerArray( identifier.split( SEPARATOR_TYPE )[1].split( SEPARATOR_ID ) );
+ }
+
+ private Set<DataElementGroupSet> getDataElementDimensionSet( Integer[] identifiers )
+ {
+ Set<DataElementGroupSet> dimensionSet = new HashSet<DataElementGroupSet>();
+
+ for ( Integer id : identifiers )
+ {
+ dimensionSet.add( dataElementService.getDataElementGroupSet( id ) );
+ }
+
+ return dimensionSet;
+ }
+
+ private Set<Set<DataElementGroupSet>> getDistinctDataElemenDimensionSets()
+ {
+ Set<Set<DataElementGroupSet>> dimensionSets = new HashSet<Set<DataElementGroupSet>>();
+
+ for ( DataElement dataElement : dataElementService.getDataElementsWithGroupSets() )
+ {
+ dimensionSets.add( new HashSet<DataElementGroupSet>( dataElement.getGroupSets() ) );
+ }
+
+ return dimensionSets;
+ }
+
+ private String getCategoryComboIdentifier( DataElementCategoryCombo categoryCombo )
+ {
+ return TYPE_CATEGORY_COMBO + SEPARATOR_TYPE + categoryCombo.getId();
+ }
+
+ private String getGroupSetIdentifier( Set<DataElementGroupSet> groupSets )
+ {
+ StringBuffer identifier = new StringBuffer( TYPE_GROUP_SET + SEPARATOR_TYPE );
+
+ Iterator<DataElementGroupSet> iterator = groupSets.iterator();
+
+ while ( iterator.hasNext() )
+ {
+ identifier.append( iterator.next().getId() );
+
+ if ( iterator.hasNext() )
+ {
+ identifier.append( SEPARATOR_ID );
+ }
+ }
+
+ return identifier.toString();
+ }
+
+ private String getGroupSetName( Set<DataElementGroupSet> groupSets )
+ {
+ StringBuffer name = new StringBuffer();
+
+ Iterator<DataElementGroupSet> iterator = groupSets.iterator();
+
+ while ( iterator.hasNext() )
+ {
+ name.append( iterator.next().getName() );
+
+ if ( iterator.hasNext() )
+ {
+ name.append( SEPARATOR_NAME );
+ }
+ }
+
+ return name.toString();
+ }
}
=== 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 2009-11-02 15:55:44 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ConversionUtils.java 2009-11-10 15:17:51 +0000
@@ -77,14 +77,33 @@
{
Collection<Integer> integers = new ArrayList<Integer>();
- if ( strings == null )
+ if ( strings != null )
{
- return integers;
+ for ( String string : strings )
+ {
+ integers.add( Integer.valueOf( string ) );
+ }
}
- for ( String string : strings )
+ return integers;
+ }
+
+ /**
+ * Creates an array of Integers out of an array of Strings.
+ *
+ * @param strings the array of Strings.
+ * @return an array of Integers.
+ */
+ public static Integer[] getIntegerArray( String[] strings )
+ {
+ Integer[] integers = new Integer[strings.length];
+
+ if ( strings != null )
{
- integers.add( Integer.valueOf( string ) );
+ for ( int i = 0; i < strings.length; i++ )
+ {
+ integers[i] = Integer.valueOf( strings[i] );
+ }
}
return integers;