dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #12367
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3791: Changed DataSet-DataElement association from Collection to Set
------------------------------------------------------------
revno: 3791
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-05-30 17:17:51 +0200
message:
Changed DataSet-DataElement association from Collection to Set
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java
dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/dataarchive/DataArchiveTest.java
dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/databrowser/DataBrowserTest.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/AddDataSetAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/UpdateDataSetAction.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/dataset/DataSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java 2011-05-30 14:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java 2011-05-30 15:17:51 +0000
@@ -27,7 +27,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
@@ -62,7 +61,7 @@
/**
* All DataElements associated with this DataSet.
*/
- private Collection<DataElement> dataElements = new HashSet<DataElement>();
+ private Set<DataElement> dataElements = new HashSet<DataElement>();
/**
* Indicators associated with this data set. Indicators are used for view and
@@ -177,6 +176,34 @@
}
}
+ public void addDataElement( DataElement dataElement )
+ {
+ dataElements.add( dataElement );
+ dataElement.getDataSets().add( this );
+ }
+
+ public void removeDataElement( DataElement dataElement )
+ {
+ dataElements.remove( dataElement );
+ dataElement.getDataSets().remove( dataElement );
+ }
+
+ public void updateDataElements( Set<DataElement> updates )
+ {
+ for ( DataElement dataElement : new HashSet<DataElement>( dataElements ) )
+ {
+ if ( !updates.contains( dataElement ) )
+ {
+ removeDataElement( dataElement );
+ }
+ }
+
+ for ( DataElement dataElement : updates )
+ {
+ addDataElement( dataElement );
+ }
+ }
+
public boolean hasDataEntryForm()
{
return dataEntryForm != null;
@@ -255,12 +282,12 @@
this.periodType = periodType;
}
- public Collection<DataElement> getDataElements()
+ public Set<DataElement> getDataElements()
{
return dataElements;
}
- public void setDataElements( Collection<DataElement> dataElements )
+ public void setDataElements( Set<DataElement> dataElements )
{
this.dataElements = dataElements;
}
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/dataarchive/DataArchiveTest.java'
--- dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/dataarchive/DataArchiveTest.java 2010-10-01 09:05:32 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/dataarchive/DataArchiveTest.java 2011-05-30 15:17:51 +0000
@@ -31,6 +31,7 @@
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Set;
import org.hisp.dhis.DhisTest;
import org.hisp.dhis.dataelement.DataElement;
@@ -174,9 +175,9 @@
dataElementIds.add( dataElementService.addDataElement( dataElementE ) );
dataElementIds.add( dataElementService.addDataElement( dataElementF ) );
- Collection<DataElement> dataElementsA = new HashSet<DataElement>();
- Collection<DataElement> dataElementsB = new HashSet<DataElement>();
- Collection<DataElement> dataElementsC = new HashSet<DataElement>();
+ Set<DataElement> dataElementsA = new HashSet<DataElement>();
+ Set<DataElement> dataElementsB = new HashSet<DataElement>();
+ Set<DataElement> dataElementsC = new HashSet<DataElement>();
// One dataElement
dataElementsA.add( dataElementA );
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/databrowser/DataBrowserTest.java'
--- dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/databrowser/DataBrowserTest.java 2011-03-14 09:16:45 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/databrowser/DataBrowserTest.java 2011-05-30 15:17:51 +0000
@@ -174,9 +174,9 @@
dataElementIds.add( dataElementService.addDataElement( dataElementE ) );
dataElementIds.add( dataElementService.addDataElement( dataElementF ) );
- Collection<DataElement> dataElementsA = new HashSet<DataElement>();
- Collection<DataElement> dataElementsB = new HashSet<DataElement>();
- Collection<DataElement> dataElementsC = new HashSet<DataElement>();
+ Set<DataElement> dataElementsA = new HashSet<DataElement>();
+ Set<DataElement> dataElementsB = new HashSet<DataElement>();
+ Set<DataElement> dataElementsC = new HashSet<DataElement>();
// One dataElement
dataElementsA.add( dataElementA );
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/AddDataSetAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/AddDataSetAction.java 2011-05-28 21:53:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/AddDataSetAction.java 2011-05-30 15:17:51 +0000
@@ -31,7 +31,6 @@
import java.util.HashSet;
import java.util.Set;
-import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
@@ -165,11 +164,11 @@
PeriodType periodType = periodService.getPeriodTypeByName( frequencySelect );
- Collection<DataElement> dataElements = new HashSet<DataElement>();
+ DataSet dataSet = new DataSet( name, shortName, code, periodType );
for ( String id : dataElementsSelectedList )
{
- dataElements.add( dataElementService.getDataElement( Integer.parseInt( id ) ) );
+ dataSet.addDataElement( dataElementService.getDataElement( Integer.parseInt( id ) ) );
}
Set<Indicator> indicators = new HashSet<Indicator>();
@@ -179,11 +178,8 @@
indicators.add( indicatorService.getIndicator( Integer.parseInt( id ) ) );
}
- DataSet dataSet = new DataSet( name, shortName, code, periodType );
-
dataSet.setMobile( mobile );
dataSet.setVersion( 1 );
- dataSet.setDataElements( dataElements );
dataSet.setIndicators( indicators );
dataSetService.addDataSet( dataSet );
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/UpdateDataSetAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/UpdateDataSetAction.java 2011-05-28 21:53:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/UpdateDataSetAction.java 2011-05-30 15:17:51 +0000
@@ -155,7 +155,7 @@
code = null;
}
- Collection<DataElement> dataElements = new HashSet<DataElement>();
+ Set<DataElement> dataElements = new HashSet<DataElement>();
for ( String id : dataElementsSelectedList )
{
@@ -177,7 +177,7 @@
dataSet.setShortName( shortName );
dataSet.setCode( code );
dataSet.setPeriodType( periodService.getPeriodTypeByClass( periodType.getClass() ) );
- dataSet.setDataElements( dataElements );
+ dataSet.updateDataElements( dataElements );
dataSet.setIndicators( indicators );
if ( dataSet.isMobile() )