dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #02091
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 709: Implemented data locking on import.
------------------------------------------------------------
revno: 709
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Mon 2009-09-14 19:32:37 +0200
message:
Implemented data locking on import.
modified:
dhis-2/dhis-services/dhis-service-importexport/pom.xml
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/importer/DefaultDXFImportService.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/locking/DefaultLockingManager.java
dhis-2/dhis-services/dhis-service-importexport/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-importexport/pom.xml'
--- dhis-2/dhis-services/dhis-service-importexport/pom.xml 2009-09-06 15:51:11 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/pom.xml 2009-09-14 17:32:37 +0000
@@ -35,6 +35,10 @@
</dependency>
<dependency>
<groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-service-administration</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hisp.dhis</groupId>
<artifactId>dhis-service-jdbc</artifactId>
</dependency>
<dependency>
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/importer/DefaultDXFImportService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/importer/DefaultDXFImportService.java 2009-08-12 21:06:37 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/importer/DefaultDXFImportService.java 2009-09-14 17:32:37 +0000
@@ -1082,7 +1082,7 @@
{
//setMessage( "import_contains_data_for_locked_periods" );
- log.warn( "Import file contained DataValues for locked periods" );
+ log.warn( "Skipped DataValues because import file contained DataValues for locked Period, Organisation Unit and DataSet combinations" );
}
else
{
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/locking/DefaultLockingManager.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/locking/DefaultLockingManager.java 2009-06-10 22:25:07 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/locking/DefaultLockingManager.java 2009-09-14 17:32:37 +0000
@@ -33,9 +33,12 @@
import org.apache.commons.collections.CollectionUtils;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.datalock.DataSetLockService;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.importexport.mapping.ObjectMappingGenerator;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodService;
import org.springframework.transaction.annotation.Transactional;
@@ -78,6 +81,20 @@
{
this.periodService = periodService;
}
+
+ private OrganisationUnitService organisationUnitService;
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
+ private DataSetLockService dataSetLockService;
+
+ public void setDataSetLockService( DataSetLockService dataSetLockService )
+ {
+ this.dataSetLockService = dataSetLockService;
+ }
// -------------------------------------------------------------------------
// LockingManager implementation
@@ -86,9 +103,46 @@
@Transactional
public boolean currentImportContainsLockedData()
{
- Collection<DataElement> dataElements = getDataElements( objectMappingGenerator.getDataElementMapping( false ).values() );
- Collection<Period> periods = getPeriods( objectMappingGenerator.getPeriodMapping( false ).values() );
+ Collection<Period> periods =
+ periodService.getPeriods( objectMappingGenerator.getPeriodMapping( false ).values() );
+
+ Collection<OrganisationUnit> organisationUnits =
+ organisationUnitService.getOrganisationUnits( objectMappingGenerator.getOrganisationUnitMapping( false ).values() );
+
+ Collection<DataSet> dataSets = getRelevantDataSets();
+
+ // TODO improve performance by using direct JDBC or load Maps into memory
+
+ for ( DataSet dataSet : dataSets )
+ {
+ for ( Period period : periods )
+ {
+ for ( OrganisationUnit unit : organisationUnits )
+ {
+ if ( dataSetLockService.getDataSetLockByDataSetPeriodAndSource( dataSet, period, unit ) != null )
+ {
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+ // -------------------------------------------------------------------------
+ // Supportive methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Returns a Collection of DataSets where the relevant DataElements
+ * has intersecting elements.
+ */
+ private Collection<DataSet> getRelevantDataSets()
+ {
+ Collection<DataElement> dataElements =
+ dataElementService.getDataElements( objectMappingGenerator.getDataElementMapping( false ).values() );
+
Collection<DataSet> dataSets = new ArrayList<DataSet>();
for ( DataSet dataSet : dataSetService.getAllDataSets() )
@@ -99,47 +153,15 @@
}
}
- for ( DataSet dataSet : dataSets )
- {
- if ( intersects( dataSet.getLockedPeriods(), periods ) )
- {
- return true;
- }
- }
-
- return false;
+ return dataSets;
}
-
- // -------------------------------------------------------------------------
- // Supportive methods
- // -------------------------------------------------------------------------
-
- public boolean intersects( Collection<?> collection1, Collection<?> collection2 )
+
+ /**
+ * Tests whether the first Collection has intersecting elements with the
+ * second Collection.
+ */
+ private boolean intersects( Collection<?> collection1, Collection<?> collection2 )
{
return CollectionUtils.intersection( collection1, collection2 ).size() > 0;
}
-
- public Collection<DataElement> getDataElements( Collection<Integer> identifiers )
- {
- Collection<DataElement> dataElements = new ArrayList<DataElement>();
-
- for ( Integer id : identifiers )
- {
- dataElements.add( dataElementService.getDataElement( id ) );
- }
-
- return dataElements;
- }
-
- public Collection<Period> getPeriods( Collection<Integer> identifiers )
- {
- Collection<Period> periods = new ArrayList<Period>();
-
- for ( Integer id : identifiers )
- {
- periods.add( periodService.getPeriod( id ) );
- }
-
- return periods;
- }
}
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml 2009-08-31 15:37:16 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml 2009-09-14 17:32:37 +0000
@@ -524,14 +524,18 @@
<bean id="org.hisp.dhis.importexport.locking.LockingManager"
class="org.hisp.dhis.importexport.locking.DefaultLockingManager">
+ <property name="objectMappingGenerator"
+ ref="org.hisp.dhis.importexport.mapping.ObjectMappingGenerator"/>
<property name="dataElementService"
ref="org.hisp.dhis.dataelement.DataElementService"/>
<property name="dataSetService"
ref="org.hisp.dhis.dataset.DataSetService"/>
<property name="periodService"
ref="org.hisp.dhis.period.PeriodService"/>
- <property name="objectMappingGenerator"
- ref="org.hisp.dhis.importexport.mapping.ObjectMappingGenerator"/>
+ <property name="organisationUnitService"
+ ref="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
+ <property name="dataSetLockService"
+ ref="org.hisp.dhis.datalock.DataSetLockService"/>
</bean>
</beans>