dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #11021
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3056: Added function for managing datasets on add and update organisation unit
------------------------------------------------------------
revno: 3056
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-03-17 11:20:34 +0100
message:
Added function for managing datasets on add and update organisation unit
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/AddOrganisationUnitAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/GetOrganisationUnitAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/PrepareAddOrganisationUnitAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateOrganisationUnitAction.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/resources/org/hisp/dhis/oum/i18n_module.properties
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/addOrganisationUnitForm.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/updateOrganisationUnitForm.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 2011-02-17 08:25:53 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java 2011-03-17 10:20:34 +0000
@@ -286,6 +286,9 @@
return mobile;
}
+ /**
+ * Use getSources() for persistence operations.
+ */
public Set<OrganisationUnit> getOrganisationUnits()
{
Set<OrganisationUnit> result = new HashSet<OrganisationUnit>();
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/AddOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/AddOrganisationUnitAction.java 2011-02-15 13:44:03 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/AddOrganisationUnitAction.java 2011-03-17 10:20:34 +0000
@@ -29,8 +29,12 @@
import static org.hisp.dhis.system.util.TextUtils.nullIfEmpty;
+import java.util.Collection;
import java.util.Date;
+import java.util.HashSet;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -70,7 +74,14 @@
{
this.selectionManager = selectionManager;
}
+
+ private DataSetService dataSetService;
+ public void setDataSetService( DataSetService dataSetService )
+ {
+ this.dataSetService = dataSetService;
+ }
+
// -------------------------------------------------------------------------
// Input
// -------------------------------------------------------------------------
@@ -158,6 +169,13 @@
{
this.phoneNumber = phoneNumber;
}
+
+ private Collection<String> dataSets = new HashSet<String>();
+
+ public void setDataSets( Collection<String> dataSets )
+ {
+ this.dataSets = dataSets;
+ }
// -------------------------------------------------------------------------
// Output
@@ -223,7 +241,13 @@
organisationUnitId = organisationUnitService.addOrganisationUnit( organisationUnit );
+ for ( String id : dataSets )
+ {
+ DataSet dataSet = dataSetService.getDataSet( Integer.parseInt( id ) );
+ dataSet.getSources().add( organisationUnit );
+ dataSetService.updateDataSet( dataSet );
+ }
+
return SUCCESS;
}
-
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/GetOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/GetOrganisationUnitAction.java 2010-11-29 14:40:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/GetOrganisationUnitAction.java 2011-03-17 10:20:34 +0000
@@ -27,6 +27,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.dataset.comparator.DataSetNameComparator;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -50,6 +57,13 @@
this.organisationUnitService = organisationUnitService;
}
+ private DataSetService dataSetService;
+
+ public void setDataSetService( DataSetService dataSetService )
+ {
+ this.dataSetService = dataSetService;
+ }
+
// -------------------------------------------------------------------------
// Input/output
// -------------------------------------------------------------------------
@@ -75,6 +89,20 @@
return numberOfChildren;
}
+ private List<DataSet> availableDataSets;
+
+ public List<DataSet> getAvailableDataSets()
+ {
+ return availableDataSets;
+ }
+
+ private List<DataSet> dataSets;
+
+ public List<DataSet> getDataSets()
+ {
+ return dataSets;
+ }
+
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@@ -86,6 +114,14 @@
numberOfChildren = organisationUnit.getChildren().size();
+ availableDataSets = new ArrayList<DataSet>( dataSetService.getAllDataSets() );
+ availableDataSets.removeAll( organisationUnit.getDataSets() );
+
+ dataSets = new ArrayList<DataSet>( organisationUnit.getDataSets() );
+
+ Collections.sort( availableDataSets, new DataSetNameComparator() );
+ Collections.sort( dataSets, new DataSetNameComparator() );
+
return SUCCESS;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/PrepareAddOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/PrepareAddOrganisationUnitAction.java 2010-11-29 14:40:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/PrepareAddOrganisationUnitAction.java 2011-03-17 10:20:34 +0000
@@ -27,24 +27,44 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.Calendar;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.Date;
+import java.util.List;
+
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.dataset.comparator.DataSetNameComparator;
+import org.hisp.dhis.period.Cal;
+
import com.opensymphony.xwork2.ActionSupport;
/**
* @author Nguyen Dang Quang
- * @version $Id: PrepareAddOrganisationUnitAction.java 1898 2006-09-22 12:06:56Z torgeilo $
*/
-@SuppressWarnings("serial")
public class PrepareAddOrganisationUnitAction
extends ActionSupport
{
+ private DataSetService dataSetService;
+
+ public void setDataSetService( DataSetService dataSetService )
+ {
+ this.dataSetService = dataSetService;
+ }
+
private Date defaultDate;
public Date getDefaultDate()
{
return defaultDate;
}
+
+ private List<DataSet> dataSets;
+
+ public List<DataSet> getDataSets()
+ {
+ return dataSets;
+ }
// -------------------------------------------------------------------------
// Action implementation
@@ -52,11 +72,11 @@
public String execute()
{
- Calendar cal = Calendar.getInstance();
- cal.set( Calendar.YEAR, 1990 );
- cal.set( Calendar.MONTH, 0 );
- cal.set( Calendar.DATE, 1 );
- this.defaultDate = cal.getTime();
+ defaultDate = new Cal().set( 1900, 1, 1 ).time();
+
+ dataSets = new ArrayList<DataSet>( dataSetService.getAllDataSets() );
+
+ Collections.sort( dataSets, new DataSetNameComparator() );
return SUCCESS;
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateOrganisationUnitAction.java 2011-02-15 13:44:03 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateOrganisationUnitAction.java 2011-03-17 10:20:34 +0000
@@ -29,8 +29,12 @@
import static org.hisp.dhis.system.util.TextUtils.nullIfEmpty;
+import java.util.Collection;
import java.util.Date;
+import java.util.HashSet;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -62,6 +66,13 @@
this.organisationUnitService = organisationUnitService;
}
+ private DataSetService dataSetService;
+
+ public void setDataSetService( DataSetService dataSetService )
+ {
+ this.dataSetService = dataSetService;
+ }
+
// -------------------------------------------------------------------------
// Input
// -------------------------------------------------------------------------
@@ -171,6 +182,13 @@
this.phoneNumber = phoneNumber;
}
+ private Collection<String> dataSets = new HashSet<String>();
+
+ public void setDataSets( Collection<String> dataSets )
+ {
+ this.dataSets = dataSets;
+ }
+
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@@ -219,6 +237,15 @@
organisationUnit.setEmail( email );
organisationUnit.setPhoneNumber( phoneNumber );
+ organisationUnit.getDataSets().clear();
+
+ for ( String id : dataSets )
+ {
+ DataSet dataSet = dataSetService.getDataSet( Integer.parseInt( id ) );
+ dataSet.getSources().add( organisationUnit );
+ dataSetService.updateDataSet( dataSet );
+ }
+
organisationUnitService.updateOrganisationUnit( organisationUnit );
return SUCCESS;
=== 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 2011-02-15 13:45:11 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/META-INF/dhis/beans.xml 2011-03-17 10:20:34 +0000
@@ -25,6 +25,9 @@
<property name="organisationUnitService">
<ref bean="org.hisp.dhis.organisationunit.OrganisationUnitService" />
</property>
+ <property name="dataSetService">
+ <ref bean="org.hisp.dhis.dataset.DataSetService"/>
+ </property>
</bean>
<bean
@@ -43,6 +46,9 @@
<property name="organisationUnitService">
<ref bean="org.hisp.dhis.organisationunit.OrganisationUnitService" />
</property>
+ <property name="dataSetService">
+ <ref bean="org.hisp.dhis.dataset.DataSetService"/>
+ </property>
<property name="selectionManager">
<ref bean="org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager" />
</property>
@@ -79,6 +85,9 @@
<property name="organisationUnitService">
<ref bean="org.hisp.dhis.organisationunit.OrganisationUnitService" />
</property>
+ <property name="dataSetService">
+ <ref bean="org.hisp.dhis.dataset.DataSetService"/>
+ </property>
</bean>
<bean
@@ -94,6 +103,9 @@
id="org.hisp.dhis.oum.action.organisationunit.PrepareAddOrganisationUnitAction"
class="org.hisp.dhis.oum.action.organisationunit.PrepareAddOrganisationUnitAction"
scope="prototype">
+ <property name="dataSetService">
+ <ref bean="org.hisp.dhis.dataset.DataSetService"/>
+ </property>
</bean>
<!-- OrganisationUnitGroup -->
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties 2011-02-15 13:45:11 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties 2011-03-17 10:20:34 +0000
@@ -108,4 +108,6 @@
found = Found
all = All
please_select_from_tree = Please select from tree (optional)
-feature_type = Feature type
\ No newline at end of file
+feature_type = Feature type
+available_data_sets = Available data sets
+selected_data_sets = Selected data sets
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/addOrganisationUnitForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/addOrganisationUnitForm.vm 2011-03-16 16:52:50 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/addOrganisationUnitForm.vm 2011-03-17 10:20:34 +0000
@@ -46,19 +46,36 @@
</tr>
<tr>
<td><label for="contactPerson">$i18n.getString( "contact_person" ) </label></td>
- <td colspan="3"><input type="text" id="contactPerson" name="contactPerson" style="width:20em"></td>
+ <td><input type="text" id="contactPerson" name="contactPerson" style="width:20em"></td>
</tr>
<tr>
<td><label for="address">$i18n.getString( "address" ) </label></td>
- <td colspan="3"><input type="text" id="address" name="address" style="width:20em"></td>
+ <td><input type="text" id="address" name="address" style="width:20em"></td>
</tr>
<tr>
<td><label for="email">$i18n.getString( "email" )</label></td>
- <td colspan="3"><input type="text" id="email" name="email" style="width:20em"></td>
+ <td><input type="text" id="email" name="email" style="width:20em"></td>
</tr>
<tr>
<td><label for="phoneNumber">$i18n.getString( "phone_number" )</label></td>
- <td colspan="3"><input type="text" id="phoneNumber" name="phoneNumber" style="width:20em"></td>
+ <td><input type="text" id="phoneNumber" name="phoneNumber" style="width:20em"></td>
+ </tr>
+ <tr>
+ <td><label for="availableDataSets">$i18n.getString( "available_data_sets" )</label></td>
+ <td><select multiple id="availableDataSets" size="5" style="width:20em" ondblclick="moveSelectedById( 'availableDataSets', 'dataSets' )">
+ #foreach( $dataSet in $dataSets )
+ <option value="${dataSet.id}">$encoder.htmlEncode( $dataSet.name )</option>
+ #end
+ </select></td>
+ </tr>
+ <tr>
+ <td></td>
+ <td><input type="button" value="$i18n.getString( 'add' )" style="width:120px" onclick="moveSelectedById( 'availableDataSets', 'dataSets' )"><input
+ type="button" value="$i18n.getString( 'remove' )" style="width:120px" onclick="moveSelectedById( 'dataSets', 'availableDataSets' )"></td>
+ </tr>
+ <tr>
+ <td><label for="dataSets">$i18n.getString( "selected_data_sets" )</label></td>
+ <td><select multiple id="dataSets" name="dataSets" size="5" style="width:20em" ondblclick="moveSelectedById( 'dataSets', 'availableDataSets' )"></select></td>
</tr>
<tr>
<td></td>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/updateOrganisationUnitForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/updateOrganisationUnitForm.vm 2011-03-16 16:52:50 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/updateOrganisationUnitForm.vm 2011-03-17 10:20:34 +0000
@@ -77,19 +77,40 @@
</tr>
<tr>
<td><label for="contactPerson">$i18n.getString( "contact_person" ) </label></td>
- <td colspan="3"><input type="text" id="contactPerson" name="contactPerson" value="$!encoder.htmlEncode( $organisationUnit.contactPerson )" style="width:20em"></td>
+ <td><input type="text" id="contactPerson" name="contactPerson" value="$!encoder.htmlEncode( $organisationUnit.contactPerson )" style="width:20em"></td>
</tr>
<tr>
<td><label for="address">$i18n.getString( "address" ) </label></td>
- <td colspan="3"><input type="text" id="address" name="address" value="$!encoder.htmlEncode( $organisationUnit.address )" style="width:20em"></td>
+ <td><input type="text" id="address" name="address" value="$!encoder.htmlEncode( $organisationUnit.address )" style="width:20em"></td>
</tr>
<tr>
<td><label for="email">$i18n.getString( "email" )</label></td>
- <td colspan="3"><input type="text" id="email" name="email" value="$!encoder.htmlEncode( $organisationUnit.email )" style="width:20em"></td>
+ <td><input type="text" id="email" name="email" value="$!encoder.htmlEncode( $organisationUnit.email )" style="width:20em"></td>
</tr>
<tr>
<td><label for="phoneNumber">$i18n.getString( "phone_number" )</label></td>
- <td colspan="3"><input type="text" id="phoneNumber" name="phoneNumber" value="$!encoder.htmlEncode( $organisationUnit.phoneNumber )" style="width:20em"></td>
+ <td><input type="text" id="phoneNumber" name="phoneNumber" value="$!encoder.htmlEncode( $organisationUnit.phoneNumber )" style="width:20em"></td>
+ </tr>
+ <tr>
+ <td><label for="availableDataSets">$i18n.getString( "available_data_sets" )</label></td>
+ <td><select multiple id="availableDataSets" size="5" style="width:20em" ondblclick="moveSelectedById( 'availableDataSets', 'dataSets' )">
+ #foreach( $dataSet in $availableDataSets )
+ <option value="${dataSet.id}">$encoder.htmlEncode( $dataSet.name )</option>
+ #end
+ </select></td>
+ </tr>
+ <tr>
+ <td></td>
+ <td><input type="button" value="$i18n.getString( 'add' )" style="width:120px" onclick="moveSelectedById( 'availableDataSets', 'dataSets' )"><input
+ type="button" value="$i18n.getString( 'remove' )" style="width:120px" onclick="moveSelectedById( 'dataSets', 'availableDataSets' )"></td>
+ </tr>
+ <tr>
+ <td><label for="dataSets">$i18n.getString( "selected_data_sets" )</label></td>
+ <td><select multiple id="dataSets" name="dataSets" size="5" style="width:20em" ondblclick="moveSelectedById( 'dataSets', 'availableDataSets' )">
+ #foreach( $dataSet in $dataSets )
+ <option value="${dataSet.id}">$encoder.htmlEncode( $dataSet.name )</option>
+ #end
+ </select></td>
</tr>
<tr>
<td></td>