dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #12370
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3792: Handling of Indicator-IndicatorGroup association
------------------------------------------------------------
revno: 3792
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-05-30 17:27:38 +0200
message:
Handling of Indicator-IndicatorGroup association
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorGroup.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/UpdateDataElementGroupAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicatorgroup/AddIndicatorGroupAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicatorgroup/UpdateIndicatorGroupAction.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/indicator/IndicatorGroup.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorGroup.java 2011-05-05 21:14:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorGroup.java 2011-05-30 15:27:38 +0000
@@ -60,6 +60,38 @@
{
this.name = name;
}
+
+ // -------------------------------------------------------------------------
+ // Logic
+ // -------------------------------------------------------------------------
+
+ public void addIndicator( Indicator indicator )
+ {
+ members.add( indicator );
+ indicator.getGroups().remove( this );
+ }
+
+ public void removeIndicator( Indicator indicator )
+ {
+ members.remove( indicator );
+ indicator.getGroups().remove( this );
+ }
+
+ public void updateIndicators( Set<Indicator> updates )
+ {
+ for ( Indicator indicator : new HashSet<Indicator>( members ) )
+ {
+ if ( !updates.contains( indicator ) )
+ {
+ removeIndicator( indicator );
+ }
+ }
+
+ for ( Indicator indicator : updates )
+ {
+ addIndicator( indicator );
+ }
+ }
// -------------------------------------------------------------------------
// hashCode and equals
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/UpdateDataElementGroupAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/UpdateDataElementGroupAction.java 2011-05-30 14:56:19 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/UpdateDataElementGroupAction.java 2011-05-30 15:27:38 +0000
@@ -104,18 +104,15 @@
dataElementGroup.setName( name );
}
- if ( !groupMembers.isEmpty() )
+ Set<DataElement> members = new HashSet<DataElement>();
+
+ for ( String id : groupMembers )
{
- Set<DataElement> members = new HashSet<DataElement>();
-
- for ( String id : groupMembers )
- {
- members.add( dataElementService.getDataElement( Integer.parseInt( id ) ) );
- }
-
- dataElementGroup.updateDataElements( members );
+ members.add( dataElementService.getDataElement( Integer.parseInt( id ) ) );
}
+ dataElementGroup.updateDataElements( members );
+
dataElementService.updateDataElementGroup( dataElementGroup );
return SUCCESS;
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicatorgroup/AddIndicatorGroupAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicatorgroup/AddIndicatorGroupAction.java 2011-05-05 21:15:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicatorgroup/AddIndicatorGroupAction.java 2011-05-30 15:27:38 +0000
@@ -27,11 +27,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
-import org.hisp.dhis.indicator.Indicator;
import org.hisp.dhis.indicator.IndicatorGroup;
import org.hisp.dhis.indicator.IndicatorService;
@@ -66,9 +64,9 @@
this.name = name;
}
- private Collection<String> groupMembers;
+ private Set<String> groupMembers = new HashSet<String>();
- public void setGroupMembers( Collection<String> groupMembers )
+ public void setGroupMembers( Set<String> groupMembers )
{
this.groupMembers = groupMembers;
}
@@ -88,18 +86,11 @@
{
indicatorGroup = new IndicatorGroup( name );
- if ( groupMembers != null )
+ for ( String id : groupMembers )
{
- Set<Indicator> members = new HashSet<Indicator>();
-
- for ( String id : groupMembers )
- {
- members.add( indicatorService.getIndicator( Integer.parseInt( id ) ) );
- }
-
- indicatorGroup.setMembers( members );
+ indicatorGroup.addIndicator( indicatorService.getIndicator( Integer.parseInt( id ) ) );
}
-
+
indicatorService.addIndicatorGroup( indicatorGroup );
return SUCCESS;
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicatorgroup/UpdateIndicatorGroupAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicatorgroup/UpdateIndicatorGroupAction.java 2011-05-05 21:15:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicatorgroup/UpdateIndicatorGroupAction.java 2011-05-30 15:27:38 +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;
@@ -74,9 +73,9 @@
this.name = name;
}
- private Collection<String> groupMembers;
+ private Set<String> groupMembers = new HashSet<String>();
- public void setGroupMembers( Collection<String> groupMembers )
+ public void setGroupMembers( Set<String> groupMembers )
{
this.groupMembers = groupMembers;
}
@@ -101,21 +100,14 @@
indicatorGroup.setName( name );
}
- if ( groupMembers != null )
- {
- Set<Indicator> members = new HashSet<Indicator>();
-
- for ( String memberId : groupMembers )
- {
- members.add( indicatorService.getIndicator( Integer.parseInt( memberId ) ) );
- }
-
- indicatorGroup.setMembers( members );
- }
- else
- {
- indicatorGroup.getMembers().clear();
- }
+ Set<Indicator> members = new HashSet<Indicator>();
+
+ for ( String memberId : groupMembers )
+ {
+ members.add( indicatorService.getIndicator( Integer.parseInt( memberId ) ) );
+ }
+
+ indicatorGroup.updateIndicators( members );
indicatorService.updateIndicatorGroup( indicatorGroup );