------------------------------------------------------------ revno: 21619 committer: Lars Helge Overland <larshe...@gmail.com> branch nick: dhis2 timestamp: Wed 2016-01-06 14:45:38 +0100 message: AnalyticalObjectStore, impl methods for getting objects by dimensional item objects added: dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/AnalyticalObjectStoreTest.java modified: dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AnalyticalObjectStore.java dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateAnalyticalObjectStore.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.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/AnalyticalObjectStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AnalyticalObjectStore.java 2016-01-04 02:27:49 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AnalyticalObjectStore.java 2016-01-06 13:45:38 +0000 @@ -1,5 +1,7 @@ package org.hisp.dhis.common; +import java.util.List; + /* * Copyright (c) 2004-2016, University of Oslo * All rights reserved. @@ -42,17 +44,31 @@ public interface AnalyticalObjectStore<T extends BaseAnalyticalObject> extends GenericIdentifiableObjectStore<T> { - int countDataSetAnalyticalObject( DataSet dataSet ); - - int countIndicatorAnalyticalObject( Indicator indicator ); - - int countDataElementAnalyticalObject( DataElement dataElement ); - - int countProgramIndicatorAnalyticalObject( ProgramIndicator programIndicator ); - - int countPeriodAnalyticalObject( Period period ); - - int countOrganisationUnitAnalyticalObject( OrganisationUnit organisationUnit ); - - int countCategoryOptionGroupAnalyticalObject( CategoryOptionGroup categoryOptionGroup ); + List<T> getAnalyticalObjects( Indicator indicator ); + + List<T> getAnalyticalObjects( DataElement dataElement ); + + List<T> getAnalyticalObjects( DataSet dataSet ); + + List<T> getAnalyticalObjects( ProgramIndicator programIndicator ); + + List<T> getAnalyticalObjects( Period period ); + + List<T> getAnalyticalObjects( OrganisationUnit organisationUnit ); + + List<T> getAnalyticalObjects( CategoryOptionGroup categoryOptionGroup ); + + int countAnalyticalObject( Indicator indicator ); + + int countAnalyticalObject( DataElement dataElement ); + + int countAnalyticalObject( DataSet dataSet ); + + int countAnalyticalObject( ProgramIndicator programIndicator ); + + int countAnalyticalObject( Period period ); + + int countAnalyticalObject( OrganisationUnit organisationUnit ); + + int countAnalyticalObject( CategoryOptionGroup categoryOptionGroup ); } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java 2016-01-04 02:27:49 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java 2016-01-06 13:45:38 +0000 @@ -135,6 +135,11 @@ { } + public MapView( String layer ) + { + this.layer = layer; + } + // ------------------------------------------------------------------------- // Analytical // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java 2016-01-04 02:27:49 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java 2016-01-06 13:45:38 +0000 @@ -231,7 +231,7 @@ public ReportTable() { } - + /** * Default constructor. * === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateAnalyticalObjectStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateAnalyticalObjectStore.java 2016-01-04 02:27:49 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateAnalyticalObjectStore.java 2016-01-06 13:45:38 +0000 @@ -39,6 +39,8 @@ import org.hisp.dhis.period.Period; import org.hisp.dhis.program.ProgramIndicator; +import java.util.List; + /** * @author Morten Olav Hansen <morte...@gmail.com> */ @@ -46,9 +48,65 @@ extends HibernateIdentifiableObjectStore<T> implements AnalyticalObjectStore<T> { //TODO program indicator, tracked entity attribute + + @Override + @SuppressWarnings("unchecked") + public List<T> getAnalyticalObjects( Indicator indicator ) + { + String hql = "select distinct c from " + clazz.getSimpleName() + " c join c.dataDimensionItems d where d.indicator = :indicator"; + return getQuery( hql ).setEntity( "indicator", indicator ).list(); + } + + @Override + @SuppressWarnings("unchecked") + public List<T> getAnalyticalObjects( DataElement dataElement ) + { + String hql = "select distinct c from " + clazz.getName() + " c join c.dataDimensionItems d where d.dataElement = :dataElement"; + return getQuery( hql ).setEntity( "dataElement", dataElement ).list(); + } + + @Override + @SuppressWarnings("unchecked") + public List<T> getAnalyticalObjects( DataSet dataSet ) + { + String hql = "select distinct c from " + clazz.getName() + " c join c.dataDimensionItems d where d.dataElement = :dataElement"; + return getQuery( hql ).setEntity( "dataSet", dataSet ).list(); + } + + @Override + @SuppressWarnings("unchecked") + public List<T> getAnalyticalObjects( ProgramIndicator programIndicator ) + { + String hql = "select distinct c from " + clazz.getName() + " c join c.dataDimensionItems d where d.dataElement = :dataElement"; + return getQuery( hql ).setEntity( "programIndicator", programIndicator ).list(); + } + + @Override + @SuppressWarnings("unchecked") + public List<T> getAnalyticalObjects( Period period ) + { + String hql = "from " + clazz.getName() + " c where :period in elements(c.periods)"; + return getQuery( hql ).setEntity( "period", period ).list(); + } + + @Override + @SuppressWarnings("unchecked") + public List<T> getAnalyticalObjects( OrganisationUnit organisationUnit ) + { + String hql = "from " + clazz.getName() + " c where :organisationUnit in elements(c.organisationUnits)"; + return getQuery( hql ).setEntity( "organisationUnit", organisationUnit ).list(); + } + + @Override + @SuppressWarnings("unchecked") + public List<T> getAnalyticalObjects( CategoryOptionGroup categoryOptionGroup ) + { + String hql = "from " + clazz.getName() + " c where :categoryOptionGroup in elements(c.categoryOptionGroups)"; + return getQuery( hql ).setEntity( "categoryOptionGroup", categoryOptionGroup ).list(); + } @Override - public int countIndicatorAnalyticalObject( Indicator indicator ) + public int countAnalyticalObject( Indicator indicator ) { Query query = getQuery( "select count(distinct c) from " + clazz.getName() + " c join c.dataDimensionItems d where d.indicator = :indicator" ); query.setEntity( "indicator", indicator ); @@ -57,7 +115,7 @@ } @Override - public int countDataElementAnalyticalObject( DataElement dataElement ) + public int countAnalyticalObject( DataElement dataElement ) { Query query = getQuery( "select count(distinct c) from " + clazz.getName() + " c join c.dataDimensionItems d where d.dataElement = :dataElement" ); query.setEntity( "dataElement", dataElement ); @@ -66,7 +124,7 @@ } @Override - public int countDataSetAnalyticalObject( DataSet dataSet ) + public int countAnalyticalObject( DataSet dataSet ) { Query query = getQuery( "select count(distinct c) from " + clazz.getName() + " c join c.dataDimensionItems d where d.dataSet = :dataSet" ); query.setEntity( "dataSet", dataSet ); @@ -75,7 +133,7 @@ } @Override - public int countProgramIndicatorAnalyticalObject( ProgramIndicator programIndicator ) + public int countAnalyticalObject( ProgramIndicator programIndicator ) { Query query = getQuery( "select count(distinct c) from " + clazz.getName() + " c join c.dataDimensionItems d where d.programIndicator = :programIndicator" ); query.setEntity( "dataSet", programIndicator ); @@ -84,7 +142,7 @@ } @Override - public int countPeriodAnalyticalObject( Period period ) + public int countAnalyticalObject( Period period ) { Query query = getQuery( "select count(distinct c) from " + clazz.getName() + " c where :period in elements(c.periods)" ); query.setEntity( "period", period ); @@ -93,7 +151,7 @@ } @Override - public int countOrganisationUnitAnalyticalObject( OrganisationUnit organisationUnit ) + public int countAnalyticalObject( OrganisationUnit organisationUnit ) { Query query = getQuery( "select count(distinct c) from " + clazz.getName() + " c where :organisationUnit in elements(c.organisationUnits)" ); query.setEntity( "organisationUnit", organisationUnit ); @@ -102,7 +160,7 @@ } @Override - public int countCategoryOptionGroupAnalyticalObject( CategoryOptionGroup categoryOptionGroup ) + public int countAnalyticalObject( CategoryOptionGroup categoryOptionGroup ) { Query query = getQuery( "select count(distinct c) from " + clazz.getName() + " c where :categoryOptionGroup in elements(c.categoryOptionGroups)" ); query.setEntity( "categoryOptionGroup", categoryOptionGroup ); === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2016-01-04 02:27:49 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2016-01-06 13:45:38 +0000 @@ -317,30 +317,30 @@ @Override public int countDataSetMapViews( DataSet dataSet ) { - return mapViewStore.countDataSetAnalyticalObject( dataSet ); + return mapViewStore.countAnalyticalObject( dataSet ); } @Override public int countIndicatorMapViews( Indicator indicator ) { - return mapViewStore.countIndicatorAnalyticalObject( indicator ); + return mapViewStore.countAnalyticalObject( indicator ); } @Override public int countDataElementMapViews( DataElement dataElement ) { - return mapViewStore.countDataElementAnalyticalObject( dataElement ); + return mapViewStore.countAnalyticalObject( dataElement ); } @Override public int countPeriodMapViews( Period period ) { - return mapViewStore.countPeriodAnalyticalObject( period ); + return mapViewStore.countAnalyticalObject( period ); } @Override public int countOrganisationUnitMapViews( OrganisationUnit organisationUnit ) { - return mapViewStore.countOrganisationUnitAnalyticalObject( organisationUnit ); + return mapViewStore.countAnalyticalObject( organisationUnit ); } } === added file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/AnalyticalObjectStoreTest.java' --- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/AnalyticalObjectStoreTest.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/AnalyticalObjectStoreTest.java 2016-01-06 13:45:38 +0000 @@ -0,0 +1,126 @@ +package org.hisp.dhis.common; + +/* + * Copyright (c) 2004-2016, 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.List; + +import javax.annotation.Resource; + +import org.hisp.dhis.DhisSpringTest; +import org.hisp.dhis.indicator.Indicator; +import org.hisp.dhis.indicator.IndicatorType; +import org.hisp.dhis.mapping.MapView; +import org.hisp.dhis.mapping.MapViewStore; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import static org.junit.Assert.*; + +/** + * @author Lars Helge Overland + */ +public class AnalyticalObjectStoreTest + extends DhisSpringTest +{ + private IndicatorType itA; + + private Indicator inA; + private Indicator inB; + + private OrganisationUnit ouA; + private OrganisationUnit ouB; + + private MapView mvA; + private MapView mvB; + private MapView mvC; + + @Autowired + private IdentifiableObjectManager idObjectManager; + + @Resource( name = "org.hisp.dhis.mapping.MapViewStore" ) + private MapViewStore mapViewStore; + + @Override + public void setUpTest() + { + itA = createIndicatorType( 'A' ); + + idObjectManager.save( itA ); + + inA = createIndicator( 'A', itA ); + inB = createIndicator( 'B', itA ); + + idObjectManager.save( inA ); + idObjectManager.save( inB ); + + ouA = createOrganisationUnit( 'A' ); + ouB = createOrganisationUnit( 'B' ); + + idObjectManager.save( ouA ); + idObjectManager.save( ouB ); + + mvA = new MapView( MapView.LAYER_THEMATIC1 ); + mvB = new MapView( MapView.LAYER_THEMATIC1 ); + mvC = new MapView( MapView.LAYER_THEMATIC1 ); + + mvA.addDataDimensionItem( inA ); + mvA.getOrganisationUnits().add( ouA ); + mvB.addDataDimensionItem( inB ); + mvB.getOrganisationUnits().add( ouA ); + mvC.addDataDimensionItem( inA ); + mvC.getOrganisationUnits().add( ouB ); + + mapViewStore.save( mvA ); + mapViewStore.save( mvB ); + mapViewStore.save( mvC ); + } + + @Test + public void testGetByIndicator() + { + List<MapView> actual = mapViewStore.getAnalyticalObjects( inA ); + + assertEquals( 2, actual.size() ); + + assertTrue( actual.contains( mvA ) ); + assertTrue( actual.contains( mvC ) ); + } + + @Test + public void testGetByOrgansiationUnit() + { + List<MapView> actual = mapViewStore.getAnalyticalObjects( ouA ); + + assertEquals( 2, actual.size() ); + + assertTrue( actual.contains( mvA ) ); + assertTrue( actual.contains( mvB ) ); + } +} === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java 2016-01-04 02:27:49 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java 2016-01-06 13:45:38 +0000 @@ -984,36 +984,36 @@ @Override public int countDataSetCharts( DataSet dataSet ) { - return chartStore.countDataSetAnalyticalObject( dataSet ); + return chartStore.countAnalyticalObject( dataSet ); } @Override public int countIndicatorCharts( Indicator indicator ) { - return chartStore.countIndicatorAnalyticalObject( indicator ); + return chartStore.countAnalyticalObject( indicator ); } @Override public int countDataElementCharts( DataElement dataElement ) { - return chartStore.countDataElementAnalyticalObject( dataElement ); + return chartStore.countAnalyticalObject( dataElement ); } @Override public int countPeriodCharts( Period period ) { - return chartStore.countPeriodAnalyticalObject( period ); + return chartStore.countAnalyticalObject( period ); } @Override public int countOrganisationUnitCharts( OrganisationUnit organisationUnit ) { - return chartStore.countOrganisationUnitAnalyticalObject( organisationUnit ); + return chartStore.countAnalyticalObject( organisationUnit ); } @Override public int countCategoryOptionGroups( CategoryOptionGroup categoryOptionGroup ) { - return chartStore.countCategoryOptionGroupAnalyticalObject( categoryOptionGroup ); + return chartStore.countAnalyticalObject( categoryOptionGroup ); } } === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java 2016-01-04 02:27:49 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java 2016-01-06 13:45:38 +0000 @@ -228,36 +228,36 @@ @Override public int countDataSetReportTables( DataSet dataSet ) { - return reportTableStore.countDataSetAnalyticalObject( dataSet ); + return reportTableStore.countAnalyticalObject( dataSet ); } @Override public int countIndicatorReportTables( Indicator indicator ) { - return reportTableStore.countIndicatorAnalyticalObject( indicator ); + return reportTableStore.countAnalyticalObject( indicator ); } @Override public int countDataElementReportTables( DataElement dataElement ) { - return reportTableStore.countDataElementAnalyticalObject( dataElement ); + return reportTableStore.countAnalyticalObject( dataElement ); } @Override public int countPeriodReportTables( Period period ) { - return reportTableStore.countPeriodAnalyticalObject( period ); + return reportTableStore.countAnalyticalObject( period ); } @Override public int countOrganisationUnitReportTables( OrganisationUnit organisationUnit ) { - return reportTableStore.countOrganisationUnitAnalyticalObject( organisationUnit ); + return reportTableStore.countAnalyticalObject( organisationUnit ); } @Override public int countCategoryOptionGroups( CategoryOptionGroup categoryOptionGroup ) { - return reportTableStore.countCategoryOptionGroupAnalyticalObject( categoryOptionGroup ); + return reportTableStore.countAnalyticalObject( categoryOptionGroup ); } }
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp