← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9919: (OrganisationUnitGroup) - Allowed to add/update a list of data set when creating an orgUnitGroup

 

------------------------------------------------------------
revno: 9919
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-02-28 12:58:17 +0700
message:
  (OrganisationUnitGroup) - Allowed to add/update a list of data set when creating an orgUnitGroup
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroup.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DataSetDeletionHandler.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupDeletionHandler.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataset/hibernate/DataSet.hbm.xml
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnitGroup.hbm.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroup/AddOrganisationUnitGroupAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroup/UpdateOrganisationUnitGroupAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/addOrganisationUnitGroupForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/updateOrganisationUnitGroupForm.vm


--
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	2013-02-27 10:24:44 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2013-02-28 05:58:17 +0000
@@ -48,6 +48,7 @@
 import org.hisp.dhis.dataentryform.DataEntryForm;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.user.UserGroup;
 
@@ -57,7 +58,7 @@
 /**
  * This class is used for defining the standardized DataSets. A DataSet consists
  * of a collection of DataElements.
- *
+ * 
  * @author Kristian Nordal
  */
 @JacksonXmlRootElement( localName = "dataSet", namespace = DxfNamespaces.DXF_2_0 )
@@ -65,8 +66,11 @@
     extends BaseNameableObject
 {
     public static final String TYPE_DEFAULT = "default";
+
     public static final String TYPE_SECTION = "section";
+
     public static final String TYPE_CUSTOM = "custom";
+
     public static final String TYPE_SECTION_MULTIORG = "multiorg_section";
 
     public static final int NO_EXPIRY = 0;
@@ -88,8 +92,8 @@
     private Set<DataElement> dataElements = new HashSet<DataElement>();
 
     /**
-     * Indicators associated with this data set. Indicators are used for view and
-     * output purposes, such as calculated fields in forms and reports.
+     * Indicators associated with this data set. Indicators are used for view
+     * and output purposes, such as calculated fields in forms and reports.
      */
     @Scanned
     private Set<Indicator> indicators = new HashSet<Indicator>();
@@ -107,6 +111,11 @@
     private Set<OrganisationUnit> sources = new HashSet<OrganisationUnit>();
 
     /**
+     * All OrganisationUnitGroup that register data with this DataSet.
+     */
+    private Set<OrganisationUnitGroup> organisationUnitGroups = new HashSet<OrganisationUnitGroup>();
+
+    /**
      * The Sections associated with the DataSet.
      */
     private Set<Section> sections = new HashSet<Section>();
@@ -117,7 +126,8 @@
     private Integer sortOrder;
 
     /**
-     * Property indicating if the dataset could be collected using mobile data entry.
+     * Property indicating if the dataset could be collected using mobile data
+     * entry.
      */
     private boolean mobile;
 
@@ -142,12 +152,14 @@
     private boolean skipAggregation;
 
     /**
-     * User group which will receive notifications when data set is marked complete.
+     * User group which will receive notifications when data set is marked
+     * complete.
      */
     private UserGroup notificationRecipients;
 
     /**
-     * Indicating whether the user completing this data set should be sent a notification.
+     * Indicating whether the user completing this data set should be sent a
+     * notification.
      */
     private boolean notifyCompletingUser;
 
@@ -156,7 +168,8 @@
     // -------------------------------------------------------------------------
 
     /**
-     * Property indicating whether it should allow to enter data for future periods.
+     * Property indicating whether it should allow to enter data for future
+     * periods.
      */
     private boolean allowFuturePeriods;
 
@@ -166,12 +179,14 @@
     private boolean fieldCombinationRequired;
 
     /**
-     * Property indicating that all validation rules must pass before the form can be completed.
+     * Property indicating that all validation rules must pass before the form
+     * can be completed.
      */
     private boolean validCompleteOnly;
 
     /**
-     * Property indicating whether offline storage is enabled for this dataSet or not
+     * Property indicating whether offline storage is enabled for this dataSet
+     * or not
      */
     private boolean skipOffline;
 
@@ -227,6 +242,11 @@
 
     public void removeAllOrganisationUnits()
     {
+        for ( OrganisationUnit unit : sources )
+        {
+            unit.getDataSets().remove( this );
+        }
+
         sources.clear();
     }
 
@@ -246,6 +266,44 @@
         }
     }
 
+    public void addOrganisationUnitGroup( OrganisationUnitGroup group )
+    {
+        organisationUnitGroups.add( group );
+        group.getDataSets().add( this );
+    }
+
+    public void removeOrganisationUnitGroup( OrganisationUnitGroup group )
+    {
+        organisationUnitGroups.remove( group );
+        group.getDataSets().remove( this );
+    }
+
+    public void removeAllOrganisationUnitGroups()
+    {
+        for ( OrganisationUnitGroup group : organisationUnitGroups )
+        {
+            group.getDataSets().remove( this );
+        }
+
+        organisationUnitGroups.clear();
+    }
+
+    public void updateOrganisationUnitGroups( Set<OrganisationUnitGroup> updates )
+    {
+        for ( OrganisationUnitGroup group : new HashSet<OrganisationUnitGroup>( organisationUnitGroups ) )
+        {
+            if ( !updates.contains( group ) )
+            {
+                removeOrganisationUnitGroup( group );
+            }
+        }
+        
+        for ( OrganisationUnitGroup group : updates )
+        {
+            addOrganisationUnitGroup( group );
+        }
+    }
+
     public void addDataElement( DataElement dataElement )
     {
         dataElements.add( dataElement );
@@ -453,6 +511,21 @@
         this.sources = sources;
     }
 
+    @JsonProperty( value = "organisationUnitGroups" )
+    @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlElementWrapper( localName = "organisationUnitGroups", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "organisationUnitGroup", namespace = DxfNamespaces.DXF_2_0 )
+    public Set<OrganisationUnitGroup> getOrganisationUnitGroups()
+    {
+        return organisationUnitGroups;
+    }
+
+    public void setOrganisationUnitGroups( Set<OrganisationUnitGroup> organisationUnitGroups )
+    {
+        this.organisationUnitGroups = organisationUnitGroups;
+    }
+
     public Integer getSortOrder()
     {
         return sortOrder;

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroup.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroup.java	2013-02-13 03:57:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroup.java	2013-02-28 05:58:17 +0000
@@ -27,12 +27,9 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonView;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import java.util.HashSet;
+import java.util.Set;
+
 import org.hisp.dhis.attribute.AttributeValue;
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.BaseNameableObject;
@@ -41,14 +38,19 @@
 import org.hisp.dhis.common.annotation.Scanned;
 import org.hisp.dhis.common.view.DetailedView;
 import org.hisp.dhis.common.view.ExportView;
+import org.hisp.dhis.dataset.DataSet;
 
-import java.util.HashSet;
-import java.util.Set;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonView;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
 
 /**
  * @author Kristian Nordal
  */
-@JacksonXmlRootElement( localName = "organisationUnitGroup", namespace = DxfNamespaces.DXF_2_0)
+@JacksonXmlRootElement( localName = "organisationUnitGroup", namespace = DxfNamespaces.DXF_2_0 )
 public class OrganisationUnitGroup
     extends BaseNameableObject
 {
@@ -58,14 +60,17 @@
     private static final long serialVersionUID = -1131637847640209166L;
 
     private String symbol;
-    
+
     @Scanned
     private Set<OrganisationUnit> members = new HashSet<OrganisationUnit>();
 
+    private Set<DataSet> dataSets = new HashSet<DataSet>();
+
     private OrganisationUnitGroupSet groupSet;
 
     /**
-     * Set of the dynamic attributes values that belong to this organisationUnit group.
+     * Set of the dynamic attributes values that belong to this organisationUnit
+     * group.
      */
     private Set<AttributeValue> attributeValues = new HashSet<AttributeValue>();
 
@@ -136,6 +141,44 @@
         }
     }
 
+    public void addDataSet( DataSet dataSet )
+    {
+        dataSets.add( dataSet );
+        dataSet.getOrganisationUnitGroups().add( this );
+    }
+
+    public void removeDataSet( DataSet dataSet )
+    {
+        dataSets.remove( dataSet );
+        dataSet.getOrganisationUnitGroups().remove( this );
+    }
+    
+    public void removeAllDataSets()
+    {
+        for ( DataSet ds : dataSets )
+        {
+            ds.getOrganisationUnitGroups().remove( this );
+        }
+        
+        dataSets.clear();
+    }
+
+    public void updateDataSets( Set<DataSet> updates )
+    {
+        for ( DataSet ds : new HashSet<DataSet>( dataSets ) )
+        {
+            if ( !updates.contains( ds ) )
+            {
+                removeDataSet( ds );
+            }
+        }
+
+        for ( DataSet ds : updates )
+        {
+            addDataSet( ds );
+        }
+    }
+
     // -------------------------------------------------------------------------
     // hashCode and equals
     // -------------------------------------------------------------------------
@@ -168,8 +211,8 @@
     // -------------------------------------------------------------------------
 
     @JsonProperty
-    @JsonView( {DetailedView.class, ExportView.class} )
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public String getSymbol()
     {
         return symbol;
@@ -183,8 +226,8 @@
     @JsonProperty( value = "organisationUnits" )
     @JsonSerialize( contentAs = BaseIdentifiableObject.class )
     @JsonView( { DetailedView.class, ExportView.class } )
-    @JacksonXmlElementWrapper( localName = "organisationUnits", namespace = DxfNamespaces.DXF_2_0)
-    @JacksonXmlProperty( localName = "organisationUnit", namespace = DxfNamespaces.DXF_2_0)
+    @JacksonXmlElementWrapper( localName = "organisationUnits", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "organisationUnit", namespace = DxfNamespaces.DXF_2_0 )
     public Set<OrganisationUnit> getMembers()
     {
         return members;
@@ -198,7 +241,7 @@
     @JsonProperty( value = "organisationUnitGroupSet" )
     @JsonSerialize( as = BaseIdentifiableObject.class )
     @JsonView( { DetailedView.class } )
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public OrganisationUnitGroupSet getGroupSet()
     {
         return groupSet;
@@ -211,8 +254,8 @@
 
     @JsonProperty( value = "attributes" )
     @JsonView( { DetailedView.class, ExportView.class } )
-    @JacksonXmlElementWrapper( localName = "attributes", namespace = DxfNamespaces.DXF_2_0)
-    @JacksonXmlProperty( localName = "attribute", namespace = DxfNamespaces.DXF_2_0)
+    @JacksonXmlElementWrapper( localName = "attributes", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "attribute", namespace = DxfNamespaces.DXF_2_0 )
     public Set<AttributeValue> getAttributeValues()
     {
         return attributeValues;
@@ -223,6 +266,20 @@
         this.attributeValues = attributeValues;
     }
 
+    @JsonProperty( value = "dataSets" )
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlElementWrapper( localName = "dataSets", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "dataSet", namespace = DxfNamespaces.DXF_2_0 )
+    public Set<DataSet> getDataSets()
+    {
+        return dataSets;
+    }
+
+    public void setDataSets( Set<DataSet> dataSets )
+    {
+        this.dataSets = dataSets;
+    }
+
     @Override
     public void mergeWith( IdentifiableObject other )
     {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DataSetDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DataSetDeletionHandler.java	2012-07-01 07:12:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DataSetDeletionHandler.java	2013-02-28 05:58:17 +0000
@@ -33,6 +33,7 @@
 import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.system.deletion.DeletionHandler;
 
 /**
@@ -130,4 +131,17 @@
             dataSetService.updateDataSet( dataSet );
         }
     }
+    
+    @Override
+    public void deleteOrganisationUnitGroup( OrganisationUnitGroup group )
+    {
+        Iterator<DataSet> iterator = group.getDataSets().iterator();
+        
+        while ( iterator.hasNext() )
+        {
+            DataSet dataSet = iterator.next();
+            dataSet.getOrganisationUnitGroups().remove( group );
+            dataSetService.updateDataSet( dataSet );
+        }
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupDeletionHandler.java	2012-07-01 07:12:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupDeletionHandler.java	2013-02-28 05:58:17 +0000
@@ -29,6 +29,7 @@
 
 import java.util.Iterator;
 
+import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.system.deletion.DeletionHandler;
 
 /**
@@ -71,4 +72,17 @@
             organisationUnitGroupService.updateOrganisationUnitGroup( group );
         }
     }
+    
+    @Override
+    public void deleteDataSet( DataSet dataSet )
+    {
+        Iterator<OrganisationUnitGroup> iterator = dataSet.getOrganisationUnitGroups().iterator();
+        
+        while ( iterator.hasNext() )
+        {
+            OrganisationUnitGroup group = iterator.next();
+            group.getDataSets().remove( dataSet );
+            organisationUnitGroupService.updateOrganisationUnitGroup( group );
+        }
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataset/hibernate/DataSet.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataset/hibernate/DataSet.hbm.xml	2013-02-08 04:20:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataset/hibernate/DataSet.hbm.xml	2013-02-28 05:58:17 +0000
@@ -49,6 +49,12 @@
       <many-to-many column="sourceid" class="org.hisp.dhis.organisationunit.OrganisationUnit"
         foreign-key="fk_dataset_organisationunit" />
     </set>
+	
+	<set name="organisationUnitGroups" table="orgunitgroupdatasets" inverse="true">
+	  <cache usage="read-write" />
+	  <key column="datasetid" />
+	  <many-to-many class="org.hisp.dhis.organisationunit.OrganisationUnitGroup" column="orgunitgroupid"/>
+	</set>
 
     <set name="sections" order-by="sortorder" inverse="true">
       <cache usage="read-write" />

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnitGroup.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnitGroup.hbm.xml	2013-02-07 12:38:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnitGroup.hbm.xml	2013-02-28 05:58:17 +0000
@@ -25,6 +25,13 @@
       <many-to-many class="org.hisp.dhis.organisationunit.OrganisationUnit" column="organisationunitid"
         foreign-key="fk_orgunitgroup_organisationunitid" />
     </set>
+	
+	<set name="dataSets" table="orgunitgroupdatasets">
+	  <cache usage="read-write" />
+	  <key column="orgunitgroupid" foreign-key="fk_orgunitgroupdatasets_orgunitgroupid" />
+	  <many-to-many class="org.hisp.dhis.dataset.DataSet" column="datasetid"
+	    foreign-key="fk_orgunitgroup_datasetid" />
+	</set>
 
     <!-- Dynamic attribute values -->
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroup/AddOrganisationUnitGroupAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroup/AddOrganisationUnitGroupAction.java	2012-10-24 13:47:13 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroup/AddOrganisationUnitGroupAction.java	2013-02-28 05:58:17 +0000
@@ -27,16 +27,18 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import com.opensymphony.xwork2.ActionSupport;
+import java.util.Collection;
+import java.util.List;
+
 import org.hisp.dhis.attribute.AttributeService;
+import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
 import org.hisp.dhis.oust.manager.SelectionTreeManager;
 import org.hisp.dhis.system.util.AttributeUtils;
 
-import java.util.Collection;
-import java.util.List;
+import com.opensymphony.xwork2.ActionSupport;
 
 /**
  * @author Torgeir Lorange Ostby
@@ -70,6 +72,13 @@
         this.attributeService = attributeService;
     }
 
+    private DataSetService dataSetService;
+
+    public void setDataSetService( DataSetService dataSetService )
+    {
+        this.dataSetService = dataSetService;
+    }
+
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
@@ -95,6 +104,13 @@
         this.jsonAttributeValues = jsonAttributeValues;
     }
 
+    private Collection<String> selectedDataSetsList;
+
+    public void setSelectedDataSetsList( Collection<String> selectedDataSetsList )
+    {
+        this.selectedDataSetsList = selectedDataSetsList;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -116,8 +132,13 @@
 
         if ( jsonAttributeValues != null )
         {
-            AttributeUtils.updateAttributeValuesFromJson( organisationUnitGroup.getAttributeValues(), jsonAttributeValues,
-                attributeService );
+            AttributeUtils.updateAttributeValuesFromJson( organisationUnitGroup.getAttributeValues(),
+                jsonAttributeValues, attributeService );
+        }
+
+        for ( String id : selectedDataSetsList )
+        {
+            organisationUnitGroup.addDataSet( dataSetService.getDataSet( Integer.parseInt( id ) ) );
         }
 
         organisationUnitGroupService.addOrganisationUnitGroup( organisationUnitGroup );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroup/UpdateOrganisationUnitGroupAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroup/UpdateOrganisationUnitGroupAction.java	2012-10-24 13:47:13 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroup/UpdateOrganisationUnitGroupAction.java	2013-02-28 05:58:17 +0000
@@ -29,6 +29,8 @@
 
 import com.opensymphony.xwork2.ActionSupport;
 import org.hisp.dhis.attribute.AttributeService;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
@@ -38,6 +40,7 @@
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 /**
  * @author Torgeir Lorange Ostby
@@ -71,6 +74,13 @@
         this.attributeService = attributeService;
     }
 
+    private DataSetService dataSetService;
+
+    public void setDataSetService( DataSetService dataSetService )
+    {
+        this.dataSetService = dataSetService;
+    }
+
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
@@ -103,6 +113,13 @@
         this.jsonAttributeValues = jsonAttributeValues;
     }
 
+    private Collection<String> selectedDataSetsList;
+
+    public void setSelectedDataSetsList( Collection<String> selectedDataSetsList )
+    {
+        this.selectedDataSetsList = selectedDataSetsList;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -115,15 +132,25 @@
         organisationUnitGroup.setName( name );
         organisationUnitGroup.setSymbol( symbol );
 
-        Collection<OrganisationUnit> selectedOrganisationUnits = selectionTreeManager.getReloadedSelectedOrganisationUnits();
+        Collection<OrganisationUnit> selectedOrganisationUnits = selectionTreeManager
+            .getReloadedSelectedOrganisationUnits();
 
         organisationUnitGroup.updateOrganisationUnits( new HashSet<OrganisationUnit>( selectedOrganisationUnits ) );
 
         if ( jsonAttributeValues != null )
         {
-            AttributeUtils.updateAttributeValuesFromJson( organisationUnitGroup.getAttributeValues(), jsonAttributeValues,
-                attributeService );
-        }
+            AttributeUtils.updateAttributeValuesFromJson( organisationUnitGroup.getAttributeValues(),
+                jsonAttributeValues, attributeService );
+        }
+
+        Set<DataSet> dataSets = new HashSet<DataSet>();
+
+        for ( String id : selectedDataSetsList )
+        {
+            dataSets.add( dataSetService.getDataSet( Integer.parseInt( id ) ) );
+        }
+        
+        organisationUnitGroup.updateDataSets( dataSets );
 
         organisationUnitGroupService.updateOrganisationUnitGroup( organisationUnitGroup );
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/META-INF/dhis/beans.xml	2012-12-14 13:46:47 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/META-INF/dhis/beans.xml	2013-02-28 05:58:17 +0000
@@ -109,6 +109,7 @@
     <property name="selectionTreeManager" ref="org.hisp.dhis.oust.manager.SelectionTreeManager" />
     <property name="organisationUnitGroupService" ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
     <property name="attributeService" ref="org.hisp.dhis.attribute.AttributeService" />
+    <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
   </bean>
 
   <bean id="org.hisp.dhis.oum.action.organisationunitgroup.UpdateOrganisationUnitGroupAction" class="org.hisp.dhis.oum.action.organisationunitgroup.UpdateOrganisationUnitGroupAction"
@@ -116,6 +117,7 @@
     <property name="selectionTreeManager" ref="org.hisp.dhis.oust.manager.SelectionTreeManager" />
     <property name="organisationUnitGroupService" ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
     <property name="attributeService" ref="org.hisp.dhis.attribute.AttributeService" />
+    <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
   </bean>
 
   <bean id="org.hisp.dhis.oum.action.organisationunitgroup.RemoveOrganisationUnitGroupAction" class="org.hisp.dhis.oum.action.organisationunitgroup.RemoveOrganisationUnitGroupAction"

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/addOrganisationUnitGroupForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/addOrganisationUnitGroupForm.vm	2012-10-24 13:47:13 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/addOrganisationUnitGroupForm.vm	2013-02-28 05:58:17 +0000
@@ -7,10 +7,25 @@
     }, {
         'beforeValidateHandler' : function()
         {
+			jQuery( "#selectedDataSetsList" ).find( "option" ).attr( "selected", "selected" );
+
             #tblDynamicAttributesJavascript()
         },
         'rules' : getValidationRules( "organisationUnitGroup" )
     } );
+	
+	jQuery( "#availableDataSetsList" ).dhisAjaxSelect({
+		source: "../dhis-web-commons-ajax-json/getDataSets.action",
+		iterator: "dataSets",
+		connectedTo: "selectedDataSetsList",
+		handler: function( item ) {
+			var option = jQuery( "<option />" );
+			option.text( item.name );
+			option.attr( "value", item.id );
+			
+			return option;
+		}
+	});
 
     checkValueIsExist( "name", "validateOrganisationUnitGroup.action" );
 } );
@@ -47,6 +62,37 @@
 	</tr>
 </table>
 
+<table id="dataSetSelectionArea">
+	<colgroup>
+		<col style="width: 500px;"/>
+		<col/>
+		<col style="width: 500px;"/>
+	</colgroup>
+	<thead>
+	<tr>
+		<th>$i18n.getString( "available_data_sets" )</th>
+		<th>$i18n.getString( "filter" )</th>
+		<th>$i18n.getString( "selected_data_sets" )</th>
+	</tr>
+	</thead>
+	<tbody>
+		<tr>
+			<td>
+				<select id="availableDataSetsList" multiple="multiple" style="height: 200px; width: 100%;"></select>
+			</td>
+			<td>
+				<input type="button" value="&gt;" title="$i18n.getString( 'move_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'availableDataSetsList' );"/><br/>
+				<input type="button" value="&lt;" title="$i18n.getString( 'remove_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'selectedDataSetsList' );"/><br/>
+				<input type="button" value="&gt;&gt;" title="$i18n.getString('move_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'availableDataSetsList' );"/><br/>
+				<input type="button" value="&lt;&lt;" title="$i18n.getString('remove_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'selectedDataSetsList' );"/>
+			</td>			
+			<td>
+				<select id="selectedDataSetsList" name="selectedDataSetsList" multiple="multiple" style="height: 200px; width: 100%; margin-top: 45px;"></select>
+			</td>
+		</tr>
+	</tbody>
+</table>
+
 <p>
 	<input type="submit" name="save" value="$i18n.getString( 'save' )" style="width:10em"/>
 	<input type="button" onclick="window.location.href='organisationUnitGroup.action'" value="$i18n.getString( 'cancel' )" style="width:10em"/>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/updateOrganisationUnitGroupForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/updateOrganisationUnitGroupForm.vm	2012-12-12 09:52:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/updateOrganisationUnitGroupForm.vm	2013-02-28 05:58:17 +0000
@@ -6,11 +6,26 @@
         }, {
             'beforeValidateHandler' : function()
             {
+				jQuery( "#selectedDataSetsList" ).find( "option" ).attr( "selected", "selected" );
+			
                 #tblDynamicAttributesJavascript()
             },
             'rules' : getValidationRules( "organisationUnitGroup" )
         } );
 
+		jQuery( "#availableDataSetsList" ).dhisAjaxSelect({
+			source: "../dhis-web-commons-ajax-json/getDataSets.action",
+			iterator: "dataSets",
+			connectedTo: "selectedDataSetsList",
+			handler: function( item ) {
+				var option = jQuery( "<option />" );
+				option.text( item.name );
+				option.attr( "value", item.id );
+				
+				return option;
+			}
+		});
+		
 		checkValueIsExist( "name", "validateOrganisationUnitGroup.action", {id:$!organisationUnitGroup.id} );
 	});
 </script>
@@ -53,6 +68,41 @@
     </tr>
 </table>
 
+<table id="dataSetSelectionArea">
+	<colgroup>
+		<col style="width: 500px;"/>
+		<col/>
+		<col style="width: 500px;"/>
+	</colgroup>
+	<thead>
+	<tr>
+		<th>$i18n.getString( "available_data_sets" )</th>
+		<th>$i18n.getString( "filter" )</th>
+		<th>$i18n.getString( "selected_data_sets" )</th>
+	</tr>
+	</thead>
+	<tbody>
+		<tr>
+			<td>
+				<select id="availableDataSetsList" multiple="multiple" style="height: 200px; width: 100%;"></select>
+			</td>
+			<td>
+				<input type="button" value="&gt;" title="$i18n.getString( 'move_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'availableDataSetsList' );"/><br/>
+				<input type="button" value="&lt;" title="$i18n.getString( 'remove_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'selectedDataSetsList' );"/><br/>
+				<input type="button" value="&gt;&gt;" title="$i18n.getString('move_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'availableDataSetsList' );"/><br/>
+				<input type="button" value="&lt;&lt;" title="$i18n.getString('remove_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'selectedDataSetsList' );"/>
+			</td>			
+			<td>$organisationUnitGroup.dataSets.size()
+				<select id="selectedDataSetsList" name="selectedDataSetsList" multiple="multiple" style="height: 200px; width: 100%; margin-top: 45px;">
+				#foreach( $dataSet in $organisationUnitGroup.dataSets )
+					<option value="$dataSet.id">$!encoder.htmlEncode( $dataSet.displayName )</option>
+				#end
+				</select>
+			</td>
+		</tr>
+	</tbody>
+</table>
+
 <p>
     <input type="submit" name="save" value="$i18n.getString( 'save' )" style="width:10em"/>
     <input type="button" onclick="window.location.href='organisationUnitGroup.action'" value="$i18n.getString( 'cancel' )" style="width:10em"/>