dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #28069
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13989: Web api, datavaluecontroller, impl delete of data value
------------------------------------------------------------
revno: 13989
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-02-11 16:34:53 +0100
message:
Web api, datavaluecontroller, impl delete of data value
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueController.java
dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js
--
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-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueController.java 2014-02-03 11:42:39 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueController.java 2014-02-11 15:34:53 +0000
@@ -234,4 +234,99 @@
dataValueService.updateDataValue( dataValue );
}
}
+
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_DATAVALUE_DELETE')" )
+ @RequestMapping( method = RequestMethod.DELETE, produces = "text/plain" )
+ public void deleteDataValue(
+ @RequestParam String de,
+ @RequestParam( required = false ) String co,
+ @RequestParam( required = false ) String cc,
+ @RequestParam( required = false ) String cp,
+ @RequestParam String pe,
+ @RequestParam String ou, HttpServletResponse response )
+ {
+ // ---------------------------------------------------------------------
+ // Input validation
+ // ---------------------------------------------------------------------
+
+ DataElement dataElement = dataElementService.getDataElement( de );
+
+ if ( dataElement == null )
+ {
+ ContextUtils.conflictResponse( response, "Illegal data element identifier: " + de );
+ return;
+ }
+
+ DataElementCategoryOptionCombo categoryOptionCombo = null;
+
+ if ( co != null )
+ {
+ categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo( co );
+ }
+ else
+ {
+ categoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
+ }
+
+ if ( categoryOptionCombo == null )
+ {
+ ContextUtils.conflictResponse( response, "Illegal category option combo identifier: " + co );
+ return;
+ }
+
+ DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo( response, cc, cp );
+
+ if ( attributeOptionCombo == null )
+ {
+ return;
+ }
+
+ Period period = PeriodType.getPeriodFromIsoString( pe );
+
+ if ( period == null )
+ {
+ ContextUtils.conflictResponse( response, "Illegal period identifier: " + pe );
+ return;
+ }
+
+ OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( ou );
+
+ if ( organisationUnit == null )
+ {
+ ContextUtils.conflictResponse( response, "Illegal organisation unit identifier: " + ou );
+ return;
+ }
+
+ boolean isInHierarchy = organisationUnitService.isInUserHierarchy( organisationUnit );
+
+ if ( !isInHierarchy )
+ {
+ ContextUtils.conflictResponse( response, "Organisation unit is not in the hierarchy of the current user: " + ou );
+ return;
+ }
+
+ // ---------------------------------------------------------------------
+ // Locking validation
+ // ---------------------------------------------------------------------
+
+ if ( dataSetService.isLocked( dataElement, period, organisationUnit, null ) )
+ {
+ ContextUtils.conflictResponse( response, "Data set is locked" );
+ return;
+ }
+
+ // ---------------------------------------------------------------------
+ // Delete data value
+ // ---------------------------------------------------------------------
+
+ DataValue dataValue = dataValueService.getDataValue( dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo );
+
+ if ( dataValue == null )
+ {
+ ContextUtils.conflictResponse( response, "Data value cannot be deleted because it does not exist" );
+ return;
+ }
+
+ dataValueService.deleteDataValue( dataValue );
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml 2014-01-23 09:31:23 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml 2014-02-11 15:34:53 +0000
@@ -37,6 +37,10 @@
<param name="requiredAuthorities">F_DATAVALUE_ADD</param>
</action>
+ <action name="deleteValue" class="org.hisp.dhis.commons.action.NoAction">
+ <param name="requiredAuthorities">F_DATAVALUE_DELETE</param>
+ </action>
+
<action name="saveMinMaxLimits" class="org.hisp.dhis.de.action.SaveMinMaxLimitsAction">
<result name="success" type="velocity-json">/dhis-web-dataentry/status.vm</result>
<param name="onExceptionReturn">plainTextError</param>
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js 2014-01-23 15:36:54 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js 2014-02-11 15:34:53 +0000
@@ -309,11 +309,12 @@
url: '../api/dataValues',
data: dataValue,
dataType: 'json',
+ type: 'post',
success: handleSuccess,
error: handleError
} );
};
-
+
function handleSuccess()
{
dhis2.de.storageManager.clearDataValueJSON( dataValue );
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2014-01-24 15:20:17 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2014-02-11 15:34:53 +0000
@@ -344,6 +344,7 @@
url: '../api/dataValues',
data: value,
dataType: 'json',
+ type: 'post',
success: function( data, textStatus, xhr )
{
dhis2.de.storageManager.clearDataValueJSON( value );