dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #02760
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 912: Implemented a DimensionService, currently with methods for retrieving all DimensionSets, Dimensio...
------------------------------------------------------------
revno: 912
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Tue 2009-10-27 19:27:10 +0100
message:
Implemented a DimensionService, currently with methods for retrieving all DimensionSets, Dimensions and DimensionOptions.
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/DimensionService.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dimension/
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dimension/DimensionServiceTest.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Dimension.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java
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/resources/META-INF/dhis/beans.xml
--
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/Dimension.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Dimension.java 2009-10-21 18:41:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Dimension.java 2009-10-27 18:27:10 +0000
@@ -34,6 +34,8 @@
*/
public interface Dimension
{
+ //TODO move to dimension package
+
String getName();
List<? extends DimensionOption> getDimensionOptions();
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2009-10-22 07:54:37 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2009-10-27 18:27:10 +0000
@@ -209,6 +209,11 @@
return groupSets;
}
+ public boolean isDimensionSet()
+ {
+ return groupSets != null && groupSets.size() > 0;
+ }
+
// -------------------------------------------------------------------------
// hashCode, equals and toString
// -------------------------------------------------------------------------
=== added directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension'
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/DimensionService.java 2009-10-27 18:27:10 +0000
@@ -0,0 +1,49 @@
+package org.hisp.dhis.dimension;
+
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+import org.hisp.dhis.common.Dimension;
+import org.hisp.dhis.common.DimensionOption;
+import org.hisp.dhis.common.DimensionSet;
+
+/**
+ * @author Lars Helge Overland
+ * @version $Id: Indicator.java 5540 2008-08-19 10:47:07Z larshelg $
+ */
+public interface DimensionService
+{
+ final String ID = DimensionService.class.getName();
+
+ Collection<DimensionSet> getAllDimensionSets();
+
+ Collection<Dimension> getAllDimensions();
+
+ Collection<DimensionOption> getAllDimensionOptions();
+}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java 2009-10-22 07:54:37 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java 2009-10-27 18:27:10 +0000
@@ -102,6 +102,11 @@
return groupSets;
}
+ public boolean isDimensionSet()
+ {
+ return groupSets != null && groupSets.size() > 0;
+ }
+
// -------------------------------------------------------------------------
// hashCode and equals
// -------------------------------------------------------------------------
=== 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-10-27 16:24:02 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.java 2009-10-27 18:27:10 +0000
@@ -1,6 +1,124 @@
package org.hisp.dhis.dimension;
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.hisp.dhis.common.Dimension;
+import org.hisp.dhis.common.DimensionOption;
+import org.hisp.dhis.common.DimensionSet;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.indicator.Indicator;
+import org.hisp.dhis.indicator.IndicatorService;
+
+/**
+ * @author Lars Helge Overland
+ * @version $Id: Indicator.java 5540 2008-08-19 10:47:07Z larshelg $
+ */
public class DefaultDimensionService
+ implements DimensionService
{
-
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private DataElementService dataElementService;
+
+ public void setDataElementService( DataElementService dataElementService )
+ {
+ this.dataElementService = dataElementService;
+ }
+
+ private IndicatorService indicatorService;
+
+ public void setIndicatorService( IndicatorService indicatorService )
+ {
+ this.indicatorService = indicatorService;
+ }
+
+ private DataElementCategoryService categoryService;
+
+ public void setCategoryService( DataElementCategoryService categoryService )
+ {
+ this.categoryService = categoryService;
+ }
+
+ // -------------------------------------------------------------------------
+ // DimensionService implementation
+ // -------------------------------------------------------------------------
+
+ public Collection<DimensionSet> getAllDimensionSets()
+ {
+ Collection<DimensionSet> dimensionSets = new ArrayList<DimensionSet>();
+
+ for ( DataElement dataElement : dataElementService.getAllDataElements() )
+ {
+ if ( dataElement.isDimensionSet() )
+ {
+ dimensionSets.add( dataElement );
+ }
+ }
+
+ for ( Indicator indicator : indicatorService.getAllIndicators() )
+ {
+ if ( indicator.isDimensionSet() )
+ {
+ dimensionSets.add( indicator );
+ }
+ }
+
+ dimensionSets.addAll( categoryService.getAllDataElementCategoryCombos() );
+
+ return dimensionSets;
+ }
+
+ public Collection<Dimension> getAllDimensions()
+ {
+ Collection<Dimension> dimensions = new ArrayList<Dimension>();
+
+ dimensions.addAll( dataElementService.getAllDataElementGroupSets() );
+ dimensions.addAll( indicatorService.getAllIndicatorGroupSets() );
+ dimensions.addAll( categoryService.getAllDataElementCategories() );
+
+ return dimensions;
+ }
+
+ public Collection<DimensionOption> getAllDimensionOptions()
+ {
+ Collection<DimensionOption> dimensionOptions = new ArrayList<DimensionOption>();
+
+ dimensionOptions.addAll( dataElementService.getAllDataElementGroups() );
+ dimensionOptions.addAll( indicatorService.getAllIndicatorGroups() );
+ dimensionOptions.addAll( categoryService.getAllDataElementCategoryOptions() );
+
+ return dimensionOptions;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2009-10-27 17:41:53 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2009-10-27 18:27:10 +0000
@@ -277,6 +277,16 @@
<property name="i18nService"
ref="org.hisp.dhis.i18n.I18nService"/>
</bean>
+
+ <bean id="org.hisp.dhis.dimension.DimensionService"
+ class="org.hisp.dhis.dimension.DefaultDimensionService">
+ <property name="dataElementService"
+ ref="org.hisp.dhis.dataelement.DataElementService"/>
+ <property name="indicatorService"
+ ref="org.hisp.dhis.indicator.IndicatorService"/>
+ <property name="categoryService"
+ ref="org.hisp.dhis.dataelement.DataElementCategoryService"/>
+ </bean>
<!-- Startup routine definitions -->
=== added directory 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dimension'
=== added file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dimension/DimensionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dimension/DimensionServiceTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dimension/DimensionServiceTest.java 2009-10-27 18:27:10 +0000
@@ -0,0 +1,76 @@
+package org.hisp.dhis.dimension;
+
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.common.Dimension;
+import org.hisp.dhis.dataelement.DataElementGroupSet;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.junit.Test;
+
+import static junit.framework.Assert.*;
+
+/**
+ * @author Lars Helge Overland
+ * @version $Id$
+ */
+public class DimensionServiceTest
+ extends DhisSpringTest
+{
+ private DimensionService dimensionService;
+
+ private DataElementGroupSet dataElementGroupSetA;
+ private DataElementGroupSet dataElementGroupSetB;
+
+ @Override
+ public void setUpTest()
+ {
+ dataElementService = (DataElementService) getBean( DataElementService.ID );
+
+ dimensionService = (DimensionService) getBean( DimensionService.ID );
+
+ dataElementGroupSetA = new DataElementGroupSet( "DataElementGroupSetA" );
+ dataElementGroupSetB = new DataElementGroupSet( "DataElementGroupSetB" );
+
+ dataElementService.addDataElementGroupSet( dataElementGroupSetA );
+ dataElementService.addDataElementGroupSet( dataElementGroupSetB );
+ }
+
+ @Test
+ public void getDimensions()
+ {
+ Collection<Dimension> dimensions = dimensionService.getAllDimensions();
+
+ assertNotNull( dimensions );
+ assertEquals( 3, dimensions.size() ); // Including default
+ assertTrue( dimensions.contains( dataElementGroupSetA ) );
+ assertTrue( dimensions.contains( dataElementGroupSetB ) );
+ }
+}