dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #01385
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 408: Made the association between DataSet and Source bi-directional. Improved performance of the valid...
------------------------------------------------------------
revno: 408
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Wed 2009-07-01 01:08:22 +0200
message:
Made the association between DataSet and Source bi-directional. Improved performance of the validation process.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/source/Source.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/source/hibernate/Source.hbm.xml
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleServiceTest.java
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/source/Source.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/source/Source.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/source/Source.java 2009-06-30 23:08:22 +0000
@@ -28,6 +28,10 @@
*/
import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.hisp.dhis.dataset.DataSet;
/**
* @author Torgeir Lorange Ostby
@@ -36,8 +40,10 @@
public abstract class Source
implements Serializable
{
- private int id;
+ protected int id;
+ protected Set<DataSet> dataSets = new HashSet<DataSet>();
+
// -------------------------------------------------------------------------
// hashCode, equals and toString
// -------------------------------------------------------------------------
@@ -61,4 +67,14 @@
{
this.id = id;
}
+
+ public Set<DataSet> getDataSets()
+ {
+ return dataSets;
+ }
+
+ public void setDataSets( Set<DataSet> dataSets )
+ {
+ this.dataSets = dataSets;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java 2009-06-20 14:26:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java 2009-06-30 23:08:22 +0000
@@ -103,13 +103,15 @@
Collection<ValidationRule> relevantRules = null;
- for ( Period period : periodService.getIntersectingPeriods( startDate, endDate ) )
- {
- for ( Source source : sources )
+ Collection<Period> relevantPeriods = periodService.getIntersectingPeriods( startDate, endDate );
+
+ for ( Source source : sources )
+ {
+ for ( DataSet dataSet : source.getDataSets() )
{
- for ( DataSet dataSet : getRelevantDataSets( source ) )
+ if ( ( relevantRules = getRelevantValidationRules( dataSet ) ).size() > 0 )
{
- if ( ( relevantRules = getRelevantValidationRules( dataSet ) ).size() > 0 )
+ for ( Period period : relevantPeriods )
{
validationViolations.addAll( validate( period, source, relevantRules ) );
}
@@ -127,13 +129,15 @@
Collection<ValidationRule> relevantRules = null;
- for ( Period period : periodService.getIntersectingPeriods( startDate, endDate ) )
- {
- for ( Source source : sources )
+ Collection<Period> relevantPeriods = periodService.getIntersectingPeriods( startDate, endDate );
+
+ for ( Source source : sources )
+ {
+ for ( DataSet dataSet : source.getDataSets() )
{
- for ( DataSet dataSet : getRelevantDataSets( source ) )
+ if ( ( relevantRules = CollectionUtils.intersection( getRelevantValidationRules( dataSet ), group.getMembers() ) ).size() > 0 )
{
- if ( ( relevantRules = CollectionUtils.intersection( getRelevantValidationRules( dataSet ), group.getMembers() ) ).size() > 0 )
+ for ( Period period : relevantPeriods )
{
validationViolations.addAll( validate( period, source, relevantRules ) );
}
@@ -150,12 +154,14 @@
Collection<ValidationRule> relevantRules = null;
- for ( Period period : periodService.getIntersectingPeriods( startDate, endDate ) )
+ Collection<Period> relevantPeriods = periodService.getIntersectingPeriods( startDate, endDate );
+
+ for ( DataSet dataSet : source.getDataSets() )
{
- for ( DataSet dataSet : getRelevantDataSets( source ) )
+ if ( ( relevantRules = getRelevantValidationRules( dataSet ) ).size() > 0 )
{
- if ( ( relevantRules = getRelevantValidationRules( dataSet ) ).size() > 0 )
- {
+ for ( Period period : relevantPeriods )
+ {
validationViolations.addAll( validate( period, source, relevantRules ) );
}
}
@@ -219,9 +225,7 @@
*/
private Collection<ValidationRule> getRelevantValidationRules( final DataSet dataSet )
{
- final Collection<ValidationRule> rules = validationRuleStore.getAll();
-
- return getRelevantValidationRules( dataSet, rules );
+ return getRelevantValidationRules( dataSet, getAllValidationRules() );
}
/**
@@ -258,7 +262,7 @@
* @param source the source.
* @return all data sets which the given source is assigned to.
*/
- private Collection<DataSet> getRelevantDataSets( final Source source )
+ private Collection<DataSet> getRelevantDataSets2( final Source source )
{
final Collection<DataSet> relevantDataSets = new HashSet<DataSet>();
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml 2009-06-10 22:25:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml 2009-06-30 23:08:22 +0000
@@ -52,8 +52,7 @@
<set name="dataSets" table="datasetmembers" inverse="true">
<key column="dataelementid"/>
- <many-to-many class="org.hisp.dhis.dataset.DataSet"
- column="datasetid"/>
+ <many-to-many class="org.hisp.dhis.dataset.DataSet" column="datasetid"/>
</set>
<list name="aggregationLevels" table="dataelementaggregationlevels">
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/source/hibernate/Source.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/source/hibernate/Source.hbm.xml 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/source/hibernate/Source.hbm.xml 2009-06-30 23:08:22 +0000
@@ -9,6 +9,12 @@
<id name="id" column="sourceid">
<generator class="native"/>
</id>
+
+ <set name="dataSets" table="datasetsource" inverse="true">
+ <key column="sourceid"/>
+ <many-to-many class="org.hisp.dhis.dataset.DataSet" column="datasetid"/>
+ </set>
+
</class>
</hibernate-mapping>
\ No newline at end of file
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleServiceTest.java 2009-06-10 22:25:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleServiceTest.java 2009-06-30 23:08:22 +0000
@@ -169,18 +169,21 @@
periodA = createPeriod( new MonthlyPeriodType(), getDate( 2000, 3, 1 ), getDate( 2000, 3, 31 ) );
periodB = createPeriod( new MonthlyPeriodType(), getDate( 2000, 4, 1 ), getDate( 2000, 4, 30 ) );
+
+ dataSet = createDataSet( 'A', periodType );
sourceA = new DummySource( "SourceA" );
sourceB = new DummySource( "SourceB" );
+ sourceA.getDataSets().add( dataSet );
+ sourceB.getDataSets().add( dataSet );
+
sourceStore.addSource( sourceA );
sourceStore.addSource( sourceB );
sourcesA.add( sourceA );
sourcesA.add( sourceB );
- dataSet = createDataSet( 'A', periodType );
-
dataSet.getDataElements().add( dataElementA );
dataSet.getDataElements().add( dataElementB );
dataSet.getDataElements().add( dataElementC );
--
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.