dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #26763
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13232: Data entry, using web api for storing comments
------------------------------------------------------------
revno: 13232
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2013-12-14 15:14:40 +0100
message:
Data entry, using web api for storing comments
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/java/org/hisp/dhis/de/action/HistoryAction.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/history.js
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/multiOrgSectionForm.vm
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.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
=== 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 2013-12-14 13:35:23 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueController.java 2013-12-14 14:14:40 +0000
@@ -48,6 +48,7 @@
import org.hisp.dhis.system.util.ValidationUtils;
import org.hisp.dhis.user.CurrentUserService;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -79,10 +80,12 @@
@Autowired
private DataSetService dataSetService;
-
+
+ @PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
@RequestMapping( method = RequestMethod.POST, produces = "text/plain" )
public void saveDataValue( @RequestParam String de, @RequestParam String co,
- @RequestParam String pe, @RequestParam String ou, @RequestParam String value,
+ @RequestParam String pe, @RequestParam String ou,
+ @RequestParam(required=false) String value, @RequestParam(required=false) String comment,
HttpServletResponse response )
{
DataElement dataElement = dataElementService.getDataElement( de );
@@ -123,8 +126,6 @@
return;
}
- value = StringUtils.trimToNull( value );
-
String valid = ValidationUtils.dataValueIsValid( value, dataElement );
if ( valid != null )
@@ -133,6 +134,14 @@
return;
}
+ valid = ValidationUtils.commentIsValid( comment );
+
+ if ( valid != null )
+ {
+ ContextUtils.conflictResponse( response, "Invalid comment: " + comment );
+ return;
+ }
+
String storedBy = currentUserService.getCurrentUsername();
Date now = new Date();
@@ -141,15 +150,32 @@
if ( dataValue == null )
{
+ dataValue = new DataValue( dataElement, period, organisationUnit, null, storedBy, now, null, categoryOptionCombo );
+
if ( value != null )
{
- dataValue = new DataValue( dataElement, period, organisationUnit, value, storedBy, now, null, categoryOptionCombo );
- dataValueService.addDataValue( dataValue );
- }
+ dataValue.setValue( StringUtils.trimToNull( value ) );
+ }
+
+ if ( comment != null )
+ {
+ dataValue.setComment( StringUtils.trimToNull( comment ) );
+ }
+
+ dataValueService.addDataValue( dataValue );
}
else
{
- dataValue.setValue( value );
+ if ( value != null )
+ {
+ dataValue.setValue( StringUtils.trimToNull( value ) );
+ }
+
+ if ( comment != null )
+ {
+ dataValue.setComment( StringUtils.trimToNull( comment ) );
+ }
+
dataValue.setTimestamp( now );
dataValue.setStoredBy( storedBy );
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/HistoryAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/HistoryAction.java 2013-09-27 12:55:38 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/HistoryAction.java 2013-12-14 14:14:40 +0000
@@ -150,9 +150,9 @@
this.periodId = periodId;
}
- private Integer organisationUnitId;
+ private String organisationUnitId;
- public void setOrganisationUnitId( Integer organisationUnitId )
+ public void setOrganisationUnitId( String organisationUnitId )
{
this.organisationUnitId = organisationUnitId;
}
=== 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 2013-12-13 18:42:05 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml 2013-12-14 14:14:40 +0000
@@ -38,10 +38,8 @@
<result name="input" type="velocity">/dhis-web-dataentry/responseVoid.vm</result>
</action>
- <action name="saveComment" class="org.hisp.dhis.de.action.SaveCommentAction">
- <result name="success" type="velocity-json">/dhis-web-dataentry/status.vm</result>
- <param name="onExceptionReturn">plainTextError</param>
- <param name="requiredAuthorities">F_DATAVALUE_ADD,F_DATAVALUE_DELETE</param>
+ <action name="saveValue" class="org.hisp.dhis.commons.action.NoAction">
+ <param name="requiredAuthorities">F_DATAVALUE_ADD</param>
</action>
<action name="saveMinMaxLimits" class="org.hisp.dhis.de.action.SaveMinMaxLimitsAction">
@@ -70,7 +68,7 @@
<action name="undoCompleteDataSet" class="org.hisp.dhis.de.action.UndoCompleteDataSetAction">
<result name="success" type="velocity-json">../dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
- <param name="requiredAuthorities">F_DATAVALUE_DELETE</param>
+ <param name="requiredAuthorities">F_DATAVALUE_ADD</param>
</action>
<action name="getValidationViolations" class="org.hisp.dhis.de.action.ValidationAction">
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js 2012-09-16 15:21:25 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js 2013-12-14 14:14:40 +0000
@@ -21,53 +21,38 @@
commentSaver.save();
}
-function CommentSaver( dataElementId_, optionComboId_, organisationUnitId_, periodId_, commentValue_ )
+function CommentSaver( de, co, ou, pe, comment )
{
- var dataElementId = dataElementId_;
- var optionComboId = optionComboId_;
- var organisationUnitId = organisationUnitId_;
- var periodId = periodId_;
- var commentValue = commentValue_;
-
+ var dataValue = {
+ 'de' : de,
+ 'co' : co,
+ 'ou' : ou,
+ 'pe' : pe,
+ 'comment' : comment
+ };
+
this.save = function()
{
markComment( COLOR_YELLOW );
$.ajax( {
- url: 'saveComment.action',
- data:
- {
- organisationUnitId: organisationUnitId,
- dataElementId: dataElementId,
- optionComboId: optionComboId,
- periodId: periodId,
- commentValue: commentValue
- },
+ url: '../api/dataValues',
+ data: dataValue,
dataType: 'json',
- success: handleResponse,
+ success: handleSuccess,
error: handleError
} );
};
- function handleResponse( json )
+ function handleSuccess( json )
{
- var code = json.c;
-
- if ( code == 0 )
- {
- markComment( COLOR_GREEN );
- }
- else
- {
- markComment( COLOR_RED );
- window.alert( i18n_saving_comment_failed_status_code + '\n\n' + code );
- }
+ markComment( COLOR_GREEN );
}
- function handleError( jqXHR, textStatus, errorThrown )
+ function handleError( xhr, textStatus, errorThrown )
{
markComment( COLOR_RED );
- window.alert( i18n_saving_comment_failed_error_code + '\n\n' + textStatus );
+ window.alert( i18n_saving_comment_failed_error_code + '\n\n' + xhr.responseText );
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/multiOrgSectionForm.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/multiOrgSectionForm.vm 2013-12-13 18:42:05 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/multiOrgSectionForm.vm 2013-12-14 14:14:40 +0000
@@ -1,6 +1,6 @@
#set( $marker = 0 )
#set( $tabIndex = 1 )
-#set( $hasAccess = $auth.hasAccess( "dhis-web-dataentry", "saveComment" ) )
+#set( $hasAccess = $auth.hasAccess( "dhis-web-dataentry", "saveValue" ) )
#foreach( $section in $sections )
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm 2013-12-13 18:42:05 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm 2013-12-14 14:14:40 +0000
@@ -1,6 +1,6 @@
#set( $tabIndex = 1 )
-#set( $hasAccess = $auth.hasAccess( "dhis-web-dataentry", "saveComment" ) )
+#set( $hasAccess = $auth.hasAccess( "dhis-web-dataentry", "saveValue" ) )
#set( $decoration = $dataSet.dataElementDecoration )
#if( $dataSet.renderAsTabs )