dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #41676
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21251: delete associated file resource when event data value is deleted
------------------------------------------------------------
revno: 21251
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-12-01 14:29:32 +0100
message:
delete associated file resource when event data value is deleted
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java
--
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-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2015-11-23 13:50:52 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2015-12-01 13:29:32 +0000
@@ -30,6 +30,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -59,6 +60,7 @@
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
import org.hisp.dhis.dxf2.utils.InputUtils;
import org.hisp.dhis.event.EventStatus;
+import org.hisp.dhis.fileresource.FileResourceService;
import org.hisp.dhis.i18n.I18nManager;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -169,6 +171,9 @@
@Autowired
protected InputUtils inputUtils;
+ @Autowired
+ protected FileResourceService fileResourceService;
+
protected static final int FLUSH_FREQUENCY = 20;
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
@@ -732,9 +737,9 @@
Set<TrackedEntityDataValue> dataValues = new HashSet<>( dataValueService.getTrackedEntityDataValues( programStageInstance ) );
Map<String, TrackedEntityDataValue> existingDataValues = getDataElementDataValueMap( dataValues );
-
+
for ( DataValue value : event.getDataValues() )
- {
+ {
DataElement dataElement = getDataElement( value.getDataElement() );
TrackedEntityDataValue dataValue = dataValueService.getTrackedEntityDataValue( programStageInstance, dataElement );
@@ -745,6 +750,11 @@
if ( dataValue != null )
{
+ if ( StringUtils.isEmpty( value.getValue() ) && dataElement.isFileType() && !StringUtils.isEmpty( dataValue.getValue() ) )
+ {
+ fileResourceService.deleteFileResource( dataValue.getValue() );
+ }
+
dataValue.setValue( value.getValue() );
dataValue.setProvidedElsewhere( value.getProvidedElsewhere() );
dataValueService.updateTrackedEntityDataValue( dataValue );