dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08196
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1940: Merge in r2006 from trunk
Merge authors:
Lars <larshelg@larshelg-laptop>
------------------------------------------------------------
revno: 1940 [merge]
committer: Jo Størset <storset@xxxxxxxxx>
branch nick: cbhis-mobile
timestamp: Fri 2010-10-22 12:18:39 +0530
message:
Merge in r2006 from trunk
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementStoreTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataSetStoreTest.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/dataelement/DataElementService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2010-05-04 06:47:28 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2010-08-30 10:56:57 +0000
@@ -32,6 +32,7 @@
import java.util.Map;
import java.util.Set;
+import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.hierarchy.HierarchyViolationException;
import org.hisp.dhis.period.PeriodType;
@@ -289,6 +290,8 @@
*/
boolean dataElementCategoryOptionComboExists( int id );
+ Collection<DataElement> getDataElementsByDataSets( Collection<DataSet> dataSets );
+
// -------------------------------------------------------------------------
// Calculated Data Elements
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java 2010-08-30 10:56:57 +0000
@@ -29,6 +29,7 @@
import java.util.Collection;
+import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.hierarchy.HierarchyViolationException;
/**
@@ -226,6 +227,8 @@
* @return true or false.
*/
boolean dataElementCategoryOptionComboExists( int id );
+
+ Collection<DataElement> getDataElementsByDataSets( Collection<DataSet> dataSets );
// -------------------------------------------------------------------------
// Calculated Data Elements
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java 2010-09-24 11:12:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java 2010-10-22 06:48:39 +0000
@@ -119,6 +119,8 @@
* Returns all DataSets that can be collected through mobile.
*/
Collection<DataSet> getDataSetsForMobile();
+
+ Collection<DataSet> getDataSetsBySources( Collection<Source> sources );
// -------------------------------------------------------------------------
// FrequencyOverrideAssociation
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2010-06-03 08:13:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2010-08-30 10:56:57 +0000
@@ -45,6 +45,7 @@
import org.hisp.dhis.common.GenericIdentifiableObjectStore;
import org.hisp.dhis.common.comparator.CategoryComboSizeComparator;
+import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.hierarchy.HierarchyViolationException;
import org.hisp.dhis.i18n.I18nService;
import org.hisp.dhis.period.PeriodType;
@@ -479,6 +480,11 @@
return map;
}
+ public Collection<DataElement> getDataElementsByDataSets( Collection<DataSet> dataSets )
+ {
+ return i18n( i18nService, dataElementStore.getDataElementsByDataSets( dataSets ) );
+ }
+
// -------------------------------------------------------------------------
// DataElementGroup
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2010-08-27 07:07:57 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2010-08-30 10:56:57 +0000
@@ -46,6 +46,7 @@
import org.hisp.dhis.dataelement.DataElementGroup;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.dataelement.DataElementStore;
+import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.hierarchy.HierarchyViolationException;
import org.hisp.dhis.system.objectmapper.DataElementOperandMapper;
import org.hisp.dhis.system.util.ConversionUtils;
@@ -298,6 +299,14 @@
return statementManager.getHolder().queryForInteger( sql ) > 0;
}
+
+ @SuppressWarnings( "unchecked" )
+ public Collection<DataElement> getDataElementsByDataSets( Collection<DataSet> dataSets )
+ {
+ String hql = "select distinct de from DataElement de join de.dataSets ds where ds.id in (:ids)";
+
+ return sessionFactory.getCurrentSession().createQuery( hql ).setParameterList( "ids", ConversionUtils.getIdentifiers( DataSet.class, dataSets ) ).list();
+ }
// -------------------------------------------------------------------------
// CalculatedDataElement
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java 2010-09-24 11:12:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java 2010-10-22 06:48:39 +0000
@@ -155,14 +155,7 @@
public Collection<DataSet> getDataSetsBySources( Collection<? extends Source> sources )
{
- Set<DataSet> dataSets = new HashSet<DataSet>();
-
- for ( Source source : sources )
- {
- dataSets.addAll( getDataSetsBySource( source ) );
- }
-
- return dataSets;
+ return getDataSetsBySources( sources );
}
public int getSourcesAssociatedWithDataSet( DataSet dataSet, Collection<? extends Source> sources )
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java 2010-09-24 11:12:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java 2010-10-22 06:48:39 +0000
@@ -40,6 +40,7 @@
import org.hisp.dhis.period.PeriodStore;
import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.source.Source;
+import org.hisp.dhis.system.util.ConversionUtils;
import org.springframework.beans.factory.annotation.Autowired;
/**
@@ -164,6 +165,14 @@
return query.list();
}
+
+ @SuppressWarnings( "unchecked" )
+ public Collection<DataSet> getDataSetsBySources( Collection<Source> sources )
+ {
+ String hql = "select distinct d from DataSet d join d.sources s where s.id in (:ids)";
+
+ return sessionFactory.getCurrentSession().createQuery( hql ).setParameterList( "ids", ConversionUtils.getIdentifiers( Source.class, sources ) ).list();
+ }
@SuppressWarnings( "unchecked" )
public Collection<DataSet> getDataSetsForMobile() {
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementStoreTest.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementStoreTest.java 2010-08-30 10:56:57 +0000
@@ -41,7 +41,10 @@
import java.util.Set;
import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.expression.Expression;
+import org.hisp.dhis.period.MonthlyPeriodType;
import org.hisp.dhis.system.util.UUIdUtils;
import org.junit.Ignore;
import org.junit.Test;
@@ -55,6 +58,8 @@
{
private DataElementStore dataElementStore;
+ private DataSetService dataSetService;
+
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@@ -66,6 +71,8 @@
dataElementStore = (DataElementStore) getBean( DataElementStore.ID );
dataElementService = (DataElementService) getBean( DataElementService.ID );
+
+ dataSetService = (DataSetService) getBean( DataSetService.ID );
}
// -------------------------------------------------------------------------
@@ -504,6 +511,49 @@
assertTrue( equals( dataElements, dataElementA, dataElementB ) );
}
+
+ @Test
+ public void testGetDataElements()
+ {
+ DataElement dataElementA = createDataElement( 'A' );
+ DataElement dataElementB = createDataElement( 'B' );
+ DataElement dataElementC = createDataElement( 'C' );
+ DataElement dataElementD = createDataElement( 'D' );
+ DataElement dataElementE = createDataElement( 'E' );
+ DataElement dataElementF = createDataElement( 'F' );
+
+ dataElementStore.addDataElement( dataElementA );
+ dataElementStore.addDataElement( dataElementB );
+ dataElementStore.addDataElement( dataElementC );
+ dataElementStore.addDataElement( dataElementD );
+ dataElementStore.addDataElement( dataElementE );
+ dataElementStore.addDataElement( dataElementF );
+
+ DataSet dataSetA = createDataSet( 'A', new MonthlyPeriodType() );
+ DataSet dataSetB = createDataSet( 'B', new MonthlyPeriodType() );
+
+ dataSetA.getDataElements().add( dataElementA );
+ dataSetA.getDataElements().add( dataElementC );
+ dataSetA.getDataElements().add( dataElementF );
+ dataSetB.getDataElements().add( dataElementD );
+ dataSetB.getDataElements().add( dataElementF );
+
+ dataSetService.addDataSet( dataSetA );
+ dataSetService.addDataSet( dataSetB );
+
+ Collection<DataSet> dataSets = new HashSet<DataSet>();
+ dataSets.add( dataSetA );
+ dataSets.add( dataSetB );
+
+ Collection<DataElement> dataElements = dataElementStore.getDataElementsByDataSets( dataSets );
+
+ assertNotNull( dataElements );
+ assertEquals( 4, dataElements.size() );
+ assertTrue( dataElements.contains( dataElementA ) );
+ assertTrue( dataElements.contains( dataElementC ) );
+ assertTrue( dataElements.contains( dataElementD ) );
+ assertTrue( dataElements.contains( dataElementF ) );
+ }
// -------------------------------------------------------------------------
// CalculatedDataElements
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataSetStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataSetStoreTest.java 2010-06-02 22:52:41 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataSetStoreTest.java 2010-08-30 11:31:49 +0000
@@ -33,6 +33,7 @@
import static junit.framework.Assert.assertTrue;
import java.util.Collection;
+import java.util.HashSet;
import org.hisp.dhis.DhisSpringTest;
import org.hisp.dhis.mock.MockSource;
@@ -128,6 +129,51 @@
assertEquals( 0, dataSets.size() );
}
+
+ @Test
+ public void testGetDataSetsBySources()
+ {
+ OrganisationUnit unitA = createOrganisationUnit( 'A' );
+ OrganisationUnit unitB = createOrganisationUnit( 'B' );
+ OrganisationUnit unitC = createOrganisationUnit( 'C' );
+ organisationUnitService.addOrganisationUnit( unitA );
+ organisationUnitService.addOrganisationUnit( unitB );
+ organisationUnitService.addOrganisationUnit( unitC );
+
+ DataSet dataSetA = createDataSet( 'A', periodType );
+ DataSet dataSetB = createDataSet( 'B', periodType );
+ DataSet dataSetC = createDataSet( 'C', periodType );
+ DataSet dataSetD = createDataSet( 'D', periodType );
+ dataSetA.getSources().add( unitA );
+ dataSetA.getSources().add( unitB );
+ dataSetB.getSources().add( unitA );
+ dataSetC.getSources().add( unitB );
+
+ dataSetStore.addDataSet( dataSetA );
+ dataSetStore.addDataSet( dataSetB );
+ dataSetStore.addDataSet( dataSetC );
+ dataSetStore.addDataSet( dataSetD );
+
+ Collection<Source> sources = new HashSet<Source>();
+ sources.add( unitA );
+ sources.add( unitB );
+
+ Collection<DataSet> dataSets = dataSetStore.getDataSetsBySources( sources );
+
+ assertEquals( 3, dataSets.size() );
+ assertTrue( dataSets.contains( dataSetA ) );
+ assertTrue( dataSets.contains( dataSetB ) );
+ assertTrue( dataSets.contains( dataSetC ) );
+
+ sources = new HashSet<Source>();
+ sources.add( unitA );
+
+ dataSets = dataSetStore.getDataSetsBySources( sources );
+
+ assertEquals( 2, dataSets.size() );
+ assertTrue( dataSets.contains( dataSetA ) );
+ assertTrue( dataSets.contains( dataSetB ) );
+ }
@Test
public void testAddDataSet()