=== 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 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 getAllDimensionSets(); + + Collection getAllDimensions(); + + Collection 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 getAllDimensionSets() + { + Collection dimensionSets = new ArrayList(); + + 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 getAllDimensions() + { + Collection dimensions = new ArrayList(); + + dimensions.addAll( dataElementService.getAllDataElementGroupSets() ); + dimensions.addAll( indicatorService.getAllIndicatorGroupSets() ); + dimensions.addAll( categoryService.getAllDataElementCategories() ); + + return dimensions; + } + + public Collection getAllDimensionOptions() + { + Collection dimensionOptions = new ArrayList(); + + 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 @@ + + + + + + === 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 dimensions = dimensionService.getAllDimensions(); + + assertNotNull( dimensions ); + assertEquals( 3, dimensions.size() ); // Including default + assertTrue( dimensions.contains( dataElementGroupSetA ) ); + assertTrue( dimensions.contains( dataElementGroupSetB ) ); + } +}