dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #05406
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1770: Commit OrganisationUnit pruning function. Still working on.
------------------------------------------------------------
revno: 1770
committer: Quang <Quang@Quang-PC>
branch nick: trunk
timestamp: Mon 2010-04-12 23:35:57 +0700
message:
Commit OrganisationUnit pruning function. Still working on.
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataprune/
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataprune/DataPruneService.java
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/DefaultDataPruneService.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/dataprune/
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/dataprune/PruneOrganisationUnitAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/pruneOrganisationUnit.js
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/pruneOrganisationUnitForm.vm
modified:
dhis-2/dhis-services/dhis-service-administration/pom.xml
dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateCompleteDataSetRegistrationStore.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/menu.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
=== added directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataprune'
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataprune/DataPruneService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataprune/DataPruneService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataprune/DataPruneService.java 2010-04-12 16:35:57 +0000
@@ -0,0 +1,41 @@
+package org.hisp.dhis.dataprune;
+
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+
+
+/**
+ * @author Quang Nguyen
+ * @version Apr 6, 2010 5:44:47 PM
+ */
+
+public interface DataPruneService
+{
+ void pruneOrganisationUnit( OrganisationUnit organisationUnit );
+}
=== modified file 'dhis-2/dhis-services/dhis-service-administration/pom.xml'
--- dhis-2/dhis-services/dhis-service-administration/pom.xml 2010-04-08 16:55:35 +0000
+++ dhis-2/dhis-services/dhis-service-administration/pom.xml 2010-04-12 16:35:57 +0000
@@ -33,6 +33,14 @@
<groupId>org.hisp.dhis</groupId>
<artifactId>dhis-options</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-service-patient</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-service-reporting</artifactId>
+ </dependency>
<!-- Other -->
=== added directory 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune'
=== added file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/DefaultDataPruneService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/DefaultDataPruneService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/DefaultDataPruneService.java 2010-04-12 16:35:57 +0000
@@ -0,0 +1,305 @@
+package org.hisp.dhis.dataprune;
+
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.chart.Chart;
+import org.hisp.dhis.chart.ChartService;
+import org.hisp.dhis.dataset.CompleteDataSetRegistration;
+import org.hisp.dhis.dataset.CompleteDataSetRegistrationService;
+import org.hisp.dhis.datavalue.DataValueService;
+import org.hisp.dhis.hierarchy.HierarchyViolationException;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.patient.PatientIdentifier;
+import org.hisp.dhis.patient.PatientIdentifierService;
+import org.hisp.dhis.reportexcel.ReportExcel;
+import org.hisp.dhis.reportexcel.ReportExcelService;
+import org.hisp.dhis.reportexcel.excelitem.ExcelItemGroup;
+import org.hisp.dhis.reportexcel.excelitem.ExcelItemService;
+import org.hisp.dhis.reporttable.ReportTable;
+import org.hisp.dhis.reporttable.ReportTableService;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserStore;
+import org.springframework.transaction.annotation.Transactional;
+
+import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArrayList;
+
+/**
+ * @author Quang Nguyen
+ * @version Apr 6, 2010 5:48:15 PM
+ */
+
+public class DefaultDataPruneService
+ implements DataPruneService
+{
+ private static final Log log = LogFactory.getLog( DefaultDataPruneService.class );
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private OrganisationUnitService organisationUnitService;
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
+ private ReportTableService reportTableService;
+
+ public void setReportTableService( ReportTableService reportTableService )
+ {
+ this.reportTableService = reportTableService;
+ }
+
+ private ReportExcelService reportExcelService;
+
+ public void setReportExcelService( ReportExcelService reportExcelService )
+ {
+ this.reportExcelService = reportExcelService;
+ }
+
+ private ExcelItemService excelItemService;
+
+ public void setExcelItemService( ExcelItemService excelItemService )
+ {
+ this.excelItemService = excelItemService;
+ }
+
+ private CompleteDataSetRegistrationService completeDataSetRegistrationService;
+
+ public void setCompleteDataSetRegistrationService( CompleteDataSetRegistrationService completeDataSetRegistrationService )
+ {
+ this.completeDataSetRegistrationService = completeDataSetRegistrationService;
+ }
+
+ private DataValueService dataValueService;
+
+ public void setDataValueService( DataValueService dataValueService )
+ {
+ this.dataValueService = dataValueService;
+ }
+
+ private OrganisationUnitGroupService organisationUnitGroupService;
+
+ public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
+ {
+ this.organisationUnitGroupService = organisationUnitGroupService;
+ }
+
+ private UserStore userStore;
+
+ public void setUserStore( UserStore userStore )
+ {
+ this.userStore = userStore;
+ }
+
+ private PatientIdentifierService patientIdentifierService;
+
+ public void setPatientIdentifierService( PatientIdentifierService patientIdentifierService )
+ {
+ this.patientIdentifierService = patientIdentifierService;
+ }
+
+ private ChartService chartService;
+
+ public void setChartService( ChartService chartService )
+ {
+ this.chartService = chartService;
+ }
+
+ // -------------------------------------------------------------------------
+ // DataPruneService implementation
+ // -------------------------------------------------------------------------
+
+ @Transactional
+ public void pruneOrganisationUnit( OrganisationUnit organisationUnit )
+ {
+ if(organisationUnit.getParent() != null) {
+ deleteSiblings(organisationUnit);
+
+ deleteParents(organisationUnit);
+ }
+ }
+
+ private void deleteParents( OrganisationUnit organisationUnit )
+ {
+ /*
+ * Not implemented yet.
+ */
+ }
+
+ @SuppressWarnings( "unchecked" )
+ private void deleteSiblings( OrganisationUnit organisationUnit )
+ {
+ List<OrganisationUnit> copiedSiblingList = new CopyOnWriteArrayList(organisationUnit.getParent().getChildren());
+
+ for ( OrganisationUnit sibling : copiedSiblingList )
+ {
+ if ( !sibling.equals( organisationUnit ) )
+ //if ( sibling.getId() == 988 )
+ {
+ System.out.println("delete sibling: " + sibling.getName());
+ deleteABranch( sibling );
+ }
+ }
+
+ }
+
+ private void deleteABranch(OrganisationUnit organisationUnit) {
+ if(!organisationUnit.getChildren().isEmpty()) {
+ Set<OrganisationUnit> tmp = organisationUnit.getChildren();
+ Object[] childrenAsArray = tmp.toArray();
+
+ for ( Object eachChild : childrenAsArray )
+ {
+ deleteABranch( (OrganisationUnit)eachChild );
+ }
+ }
+ try
+ {
+ removeOrganisationUnitAndBelonging( organisationUnit );
+ }
+ catch ( HierarchyViolationException e )
+ {
+ System.err.println(e.getMessage());
+ }
+ }
+
+ private void removeOrganisationUnitAndBelonging( OrganisationUnit organisationUnit )
+ throws HierarchyViolationException
+ {
+ removeOganisationUnitFromReportTable( organisationUnit );
+ removeOrganisationUnitFromReportExcel( organisationUnit );
+ removeOrganisationUnitFromExcelItemGroup( organisationUnit );
+ removeCompleteDataSetRegistrationByOganisationUnit( organisationUnit );
+ removeOrganisationUnitFromOrganisationUnitGroup( organisationUnit );
+ removeOrganisationUnitFromUser( organisationUnit );
+ removePatientIdentifierByOrganisationUnit( organisationUnit );
+ removeOrganisationUnitFromChart( organisationUnit );
+ dataValueService.deleteDataValuesBySource( organisationUnit );
+ organisationUnitService.deleteOrganisationUnit( organisationUnit );
+ }
+
+ private void removeCompleteDataSetRegistrationByOganisationUnit( OrganisationUnit organisationUnit )
+ {
+ for ( CompleteDataSetRegistration each : completeDataSetRegistrationService.getAllCompleteDataSetRegistrations())
+ {
+ if(each.getSource().getId() == organisationUnit.getId())
+ {
+ completeDataSetRegistrationService.deleteCompleteDataSetRegistration( each );
+ }
+ }
+
+ }
+
+ private void removeOganisationUnitFromReportTable( OrganisationUnit organisationUnit )
+ {
+ for ( ReportTable each : reportTableService.getAllReportTables() )
+ {
+ if(each.getUnits().contains( organisationUnit )) {
+ each.getAllUnits().remove( organisationUnit );
+ reportTableService.saveReportTable( each );
+ }
+ }
+
+ }
+
+ private void removeOrganisationUnitFromReportExcel( OrganisationUnit organisationUnit )
+ {
+ for(ReportExcel each : reportExcelService.getALLReportExcel())
+ {
+ if(each.getOrganisationAssocitions().contains( organisationUnit ))
+ {
+ each.getOrganisationAssocitions().remove( organisationUnit );
+ reportExcelService.updateReportExcel( each );
+ }
+ }
+ }
+
+ private void removeOrganisationUnitFromExcelItemGroup( OrganisationUnit organisationUnit )
+ {
+ for(ExcelItemGroup each : excelItemService.getAllExcelItemGroup())
+ {
+ if(each.getOrganisationAssocitions().contains( organisationUnit ))
+ {
+ each.getOrganisationAssocitions().remove( organisationUnit );
+ excelItemService.updateExcelItemGroup( each );
+ }
+ }
+ }
+
+ private void removeOrganisationUnitFromOrganisationUnitGroup( OrganisationUnit organisationUnit )
+ {
+ for(OrganisationUnitGroup each : organisationUnitGroupService.getAllOrganisationUnitGroups())
+ {
+ if(each.getMembers().contains( organisationUnit ))
+ {
+ each.getMembers().remove( organisationUnit );
+ organisationUnitGroupService.updateOrganisationUnitGroup( each );
+ }
+ }
+ }
+
+ private void removeOrganisationUnitFromUser( OrganisationUnit organisationUnit )
+ {
+ for(User each : userStore.getAllUsers())
+ {
+ if(each.getOrganisationUnits().contains( organisationUnit ))
+ {
+ each.getOrganisationUnits().remove( organisationUnit );
+ userStore.updateUser( each );
+ }
+ }
+ }
+
+ private void removePatientIdentifierByOrganisationUnit( OrganisationUnit organisationUnit ) {
+ for(PatientIdentifier each : patientIdentifierService.getPatientIdentifiersByOrgUnit( organisationUnit ))
+ {
+ patientIdentifierService.deletePatientIdentifier( each );
+ }
+ }
+
+ private void removeOrganisationUnitFromChart( OrganisationUnit organisationUnit ) {
+ for(Chart each : chartService.getAllCharts())
+ {
+ if(each.getOrganisationUnits().contains( organisationUnit ))
+ {
+ each.getOrganisationUnits().remove( organisationUnit );
+ chartService.saveChart( each );
+ }
+ }
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml 2010-03-31 16:44:55 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml 2010-04-12 16:35:57 +0000
@@ -120,6 +120,32 @@
ref="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
</bean>
+ <!-- Data prune -->
+
+ <bean id="org.hisp.dhis.dataprune.DataPruneService"
+ class="org.hisp.dhis.dataprune.DefaultDataPruneService">
+ <property name="organisationUnitService"
+ ref="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
+ <property name="reportTableService"
+ ref="org.hisp.dhis.reporttable.ReportTableService"/>
+ <property name="reportExcelService"
+ ref="org.hisp.dhis.reportexcel.ReportExcelService"/>
+ <property name="excelItemService"
+ ref="org.hisp.dhis.reportexcel.excelitem.ExcelItemService"/>
+ <property name="completeDataSetRegistrationService"
+ ref="org.hisp.dhis.dataset.CompleteDataSetRegistrationService"/>
+ <property name="dataValueService"
+ ref="org.hisp.dhis.datavalue.DataValueService"/>
+ <property name="userStore"
+ ref="org.hisp.dhis.user.UserStore"/>
+ <property name="organisationUnitGroupService"
+ ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService"/>
+ <property name="patientIdentifierService"
+ ref="org.hisp.dhis.patient.PatientIdentifierService"/>
+ <property name="chartService"
+ ref="org.hisp.dhis.chart.ChartService"/>
+ </bean>
+
<!-- Data archive -->
<bean id="org.hisp.dhis.dataarchive.DataArchiveStore"
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateCompleteDataSetRegistrationStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateCompleteDataSetRegistrationStore.java 2009-06-10 22:25:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateCompleteDataSetRegistrationStore.java 2010-04-12 16:35:57 +0000
@@ -108,6 +108,8 @@
public void deleteCompleteDataSetRegistration( CompleteDataSetRegistration registration )
{
sessionFactory.getCurrentSession().delete( registration );
+
+ sessionFactory.getCurrentSession().flush();
}
@SuppressWarnings( "unchecked" )
=== added directory 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/dataprune'
=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/dataprune/PruneOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/dataprune/PruneOrganisationUnitAction.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/dataprune/PruneOrganisationUnitAction.java 2010-04-12 16:35:57 +0000
@@ -0,0 +1,92 @@
+package org.hisp.dhis.dataadmin.action.dataprune;
+
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.dataprune.DataPruneService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+
+import com.opensymphony.xwork2.ActionSupport;
+
+/**
+ * @author Quang Nguyen
+ * @version Apr 6, 2010 6:27:10 PM
+ */
+
+public class PruneOrganisationUnitAction
+ extends ActionSupport
+{
+ private static final Log log = LogFactory.getLog( PruneOrganisationUnitAction.class );
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private DataPruneService dataPruneService;
+
+ public void setDataPruneService( DataPruneService dataPruneService )
+ {
+ this.dataPruneService = dataPruneService;
+ }
+
+ private OrganisationUnitService organisationUnitService;
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
+ // -------------------------------------------------------------------------
+ // Input
+ // -------------------------------------------------------------------------
+
+ private Integer organisationUnitSelected;
+
+ public void setOrganisationUnitSelected( Integer organisationUnitSelected )
+ {
+ this.organisationUnitSelected = organisationUnitSelected;
+ }
+
+ // Action implementation
+ // -------------------------------------------------------------------------
+
+ public String execute()
+ {
+ OrganisationUnit kept = organisationUnitService.getOrganisationUnit( organisationUnitSelected );
+
+ log.info( "Pruning Organisation Unit, " + kept + " is kept");
+
+ dataPruneService.pruneOrganisationUnit( kept );
+
+ log.info( "Pruning complete" );
+
+ return SUCCESS;
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml 2010-04-12 08:22:54 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml 2010-04-12 16:35:57 +0000
@@ -268,6 +268,17 @@
ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
</bean>
+ <!-- Prune Organisation unit -->
+
+ <bean
+ id="org.hisp.dhis.dataadmin.action.dataprune.PruneOrganisationUnitAction"
+ class="org.hisp.dhis.dataadmin.action.dataprune.PruneOrganisationUnitAction"
+ scope="prototype">
+ <property name="dataPruneService" ref="org.hisp.dhis.dataprune.DataPruneService" />
+ <property name="organisationUnitService"
+ ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+ </bean>
+
<!-- Duplicate data elimination -->
<bean
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties 2010-04-07 12:27:42 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties 2010-04-12 16:35:57 +0000
@@ -195,4 +195,10 @@
generate_values_success = Generate values successfully.
set_factor = Set Factor
factor = Factor
-save_factory_success = Save factory successfully
\ No newline at end of file
+save_factory_success = Save factory successfully
+prune_organisation_unit = Prune Organisation Unit
+prune = Prune
+select_the_org_unit_to_be_kept = Select the Organisation Unit to be kept
+prune_organisation_unit_confirmation = Are you sure to prune Organisation Unit?
+pruning = Pruning
+pruning_done = Pruning done!
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml 2010-04-12 03:47:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml 2010-04-12 16:35:57 +0000
@@ -212,6 +212,21 @@
/dhis-web-maintenance-dataadmin/responseDataIntegrity.vm</result>
</action>
+ <!-- Prune Organisation unit -->
+
+ <action name="displayPruneOrganisationUnitForm" class="org.hisp.dhis.dataadmin.action.NoAction">
+ <result name="success" type="velocity">/main.vm</result>
+ <param name="page">/dhis-web-maintenance-dataadmin/pruneOrganisationUnitForm.vm</param>
+ <param name="menu">/dhis-web-maintenance-dataadmin/menu.vm</param>
+ <param name="javascripts">../dhis-web-commons/oust/oust.js,javascript/pruneOrganisationUnit.js</param>
+ </action>
+
+ <action name="pruneOrganisationUnit"
+ class="org.hisp.dhis.dataadmin.action.dataprune.PruneOrganisationUnitAction">
+ <result name="success" type="redirect">
+ displayPruneOrganisationUnitForm.action</result>
+ </action>
+
<!-- Statistics -->
<action name="viewStatistics"
=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/pruneOrganisationUnit.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/pruneOrganisationUnit.js 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/pruneOrganisationUnit.js 2010-04-12 16:35:57 +0000
@@ -0,0 +1,41 @@
+
+var organisationUnitSelected = 0;
+
+function treeSelected( unitIds )
+{
+ organisationUnitSelected = unitIds[0];
+
+ if ( organisationUnitSelected != null && organisationUnitSelected != 0 )
+ {
+ $.getJSON(
+ "../dhis-web-commons-ajax-json/getOrganisationUnit.action",
+ {
+ "id": organisationUnitSelected
+ },
+ function( json )
+ {
+ document.getElementById( "keepNameField" ).innerHTML = json.organisationUnit.name;
+ document.getElementById( "pruneButton" ).disabled = false;
+ }
+ );
+ }
+}
+
+function pruneOrganisationUnit() {
+ // itemId, itemName, confirmation, action
+ var result = window.confirm(i18n_confirmation);
+
+ if (result) {
+ setWaitMessage(i18n_pruning + "...");
+
+ $.ajax( {
+ "url" : "pruneOrganisationUnit.action",
+ "data" : {
+ "organisationUnitSelected" : organisationUnitSelected
+ },
+ "success" : function() {
+ setMessage(i18n_pruning_done);
+ }
+ });
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/menu.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/menu.vm 2010-04-07 12:27:42 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/menu.vm 2010-04-12 16:35:57 +0000
@@ -11,7 +11,8 @@
<li><a href="viewStatistics.action">$i18n.getString( "data_statistics" ) </a></li>
<li><a href="displayLockingForm.action">$i18n.getString( "data_locking" ) </a></li>
<li><a href="zeroValueStorageManagement.action">$i18n.getString( "zero_storage_management" ) </a></li>
- </ul>
+ <li><a href="displayPruneOrganisationUnitForm.action">$i18n.getString( "prune_organisation_unit" ) </a></li>
+ </ul>
<h2>$i18n.getString( "min_max_validation" ) </h2>
<ul>
=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/pruneOrganisationUnitForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/pruneOrganisationUnitForm.vm 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/pruneOrganisationUnitForm.vm 2010-04-12 16:35:57 +0000
@@ -0,0 +1,35 @@
+
+<h3>$i18n.getString( "prune_organisation_unit" ) #openHelp( "pruneOrganisationUnit" )</h3>
+
+<div id="selectionTree" style="width:500px; height:200px"></div>
+
+<script type="text/javascript">
+ selectionTreeSelection.setMultipleSelectionAllowed( false );
+ selectionTreeSelection.setListenerFunction( treeSelected );
+ selectionTree.buildSelectionTree();
+</script>
+
+<br>
+
+<table>
+ <col style="width:2em">
+ <col>
+ <tr>
+ <td rowspan="3" style="text-align:center;background-color:#ccffcc"></td>
+ <th>$i18n.getString( "select_the_org_unit_to_be_kept" )</th>
+ </tr>
+ <tr>
+ <td><span id="keepNameField">[$i18n.getString( "not_selected" )]</span></td>
+ </tr>
+ <tr>
+ <td><input id="pruneButton" type="button" value="$i18n.getString( "prune" )" onclick="pruneOrganisationUnit()" style="width:10em" disabled="disabled"></td>
+ </tr>
+</table>
+
+<p><span id="message"></span></p>
+
+<script type="text/javascript">
+ var i18n_confirmation = '$encoder.jsEscape( $i18n.getString( "prune_organisation_unit_confirmation" ), "'" )';
+ var i18n_pruning = '$encoder.jsEscape( $i18n.getString( "pruning" ), "'" )';
+ var i18n_pruning_done = '$encoder.jsEscape( $i18n.getString( "pruning_done" ), "'" )';
+</script>