dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #03865
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1288: Work in progress on data merge.
------------------------------------------------------------
revno: 1288
committer: Lars Helge Oeverland <larshelge@xxxxxxxxx>
branch nick: trunk
timestamp: Fri 2009-12-25 19:41:08 +0100
message:
Work in progress on data merge.
modified:
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/datamerge/DefaultDataMergeService.java
dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml
--
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-services/dhis-service-administration/src/main/java/org/hisp/dhis/datamerge/DefaultDataMergeService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/datamerge/DefaultDataMergeService.java 2009-12-25 17:33:46 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/datamerge/DefaultDataMergeService.java 2009-12-25 18:41:08 +0000
@@ -29,9 +29,12 @@
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.datamerge.DataMergeService;
import org.hisp.dhis.datamerge.DataMergeStore;
+import org.hisp.dhis.hierarchy.HierarchyViolationException;
import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
/**
* @author Lars Helge Overland
@@ -39,21 +42,88 @@
public class DefaultDataMergeService
implements DataMergeService
{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
private DataMergeStore dataMergeStore;
public void setDataMergeStore( DataMergeStore dataMergeStore )
{
this.dataMergeStore = dataMergeStore;
}
+
+ private DataElementService dataElementService;
+
+ public void setDataElementService( DataElementService dataElementService )
+ {
+ this.dataElementService = dataElementService;
+ }
+
+ private OrganisationUnitService organisationUnitService;
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
+ // -------------------------------------------------------------------------
+ // DataMergeService implementation
+ // -------------------------------------------------------------------------
public void mergeDataElements( DataElement destDataElement, DataElementCategoryOptionCombo destCategoryOptionCombo,
DataElement sourceDataElemenet, DataElementCategoryOptionCombo sourceCategoryOptionCombo )
{
- dataMergeStore.mergeDataElements( destDataElement, destCategoryOptionCombo, sourceDataElemenet, sourceCategoryOptionCombo );
+ // ---------------------------------------------------------------------
+ // Eliminate duplicates
+ // ---------------------------------------------------------------------
+
+ dataMergeStore.mergeDataElements( destDataElement, destCategoryOptionCombo, sourceDataElemenet, sourceCategoryOptionCombo );
+
+ // ---------------------------------------------------------------------
+ // Delete source
+ // ---------------------------------------------------------------------
+
+ try
+ {
+ dataElementService.deleteDataElement( sourceDataElemenet );
+ }
+ catch ( HierarchyViolationException ex )
+ {
+ // Do nothing for now
+ }
}
public void mergeOrganisationUnits( OrganisationUnit dest, OrganisationUnit source )
{
- dataMergeStore.mergeOrganisationUnits( dest, source );
+ // ---------------------------------------------------------------------
+ // Merge source data with destination
+ // ---------------------------------------------------------------------
+
+ dataMergeStore.mergeOrganisationUnits( dest, source );
+
+ // ---------------------------------------------------------------------
+ // Set parent of children of destination to source
+ // ---------------------------------------------------------------------
+
+ for ( OrganisationUnit child : source.getChildren() )
+ {
+ child.setParent( dest );
+
+ organisationUnitService.updateOrganisationUnit( child );
+ }
+
+ // ---------------------------------------------------------------------
+ // Delete source
+ // ---------------------------------------------------------------------
+
+ try
+ {
+ organisationUnitService.deleteOrganisationUnit( source );
+ }
+ catch ( HierarchyViolationException ex )
+ {
+ // Do nothing for now
+ }
}
}
=== 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 2009-12-25 17:33:46 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml 2009-12-25 18:41:08 +0000
@@ -107,7 +107,12 @@
<bean id="org.hisp.dhis.datamerge.DataMergeService"
class="org.hisp.dhis.datamerge.DefaultDataMergeService">
- <property name="dataMergeStore" ref="org.hisp.dhis.datamerge.DataMergeStore"/>
+ <property name="dataMergeStore"
+ ref="org.hisp.dhis.datamerge.DataMergeStore"/>
+ <property name="dataElementService"
+ ref="org.hisp.dhis.dataelement.DataElementService"/>
+ <property name="organisationUnitService"
+ ref="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
</bean>
</beans>