dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #18979
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8100: Added DataValueController class
------------------------------------------------------------
revno: 8100
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-09-15 23:52:33 +0200
message:
Added DataValueController class
added:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueController.java
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/FormDefinitionController.java
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.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
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueController.java 2012-09-15 21:52:33 +0000
@@ -0,0 +1,149 @@
+package org.hisp.dhis.api.controller;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Date;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.lang.StringUtils;
+import org.hisp.dhis.api.utils.ContextUtils;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.datavalue.DataValue;
+import org.hisp.dhis.datavalue.DataValueService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.user.CurrentUserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * @author Lars Helge Overland
+ */
+@Controller
+@RequestMapping( value = DataValueController.RESOURCE_PATH )
+public class DataValueController
+{
+ public static final String RESOURCE_PATH = "/dataValues";
+
+ @Autowired
+ private CurrentUserService currentUserService;
+
+ @Autowired
+ private DataElementService dataElementService;
+
+ @Autowired
+ private DataElementCategoryService categoryService;
+
+ @Autowired
+ private OrganisationUnitService organisationUnitService;
+
+ @Autowired
+ private DataValueService dataValueService;
+
+ @Autowired
+ private DataSetService dataSetService;
+
+ @RequestMapping( method = RequestMethod.POST, produces = "text/plain" )
+ public void saveDataValue( @RequestParam String de, @RequestParam String cc,
+ @RequestParam String pe, @RequestParam String ou, @RequestParam String value,
+ HttpServletResponse response )
+ {
+ DataElement dataElement = dataElementService.getDataElement( de );
+
+ if ( dataElement == null )
+ {
+ ContextUtils.conflictResponse( response, "Illegal data element identifier: " + de );
+ return;
+ }
+
+ DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo( cc );
+
+ if ( categoryOptionCombo == null )
+ {
+ ContextUtils.conflictResponse( response, "Illegal category option combo identifier: " + cc );
+ return;
+ }
+
+ Period period = PeriodType.createPeriodExternalId( pe ); //TODO change to ISO
+
+ 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;
+ }
+
+ if ( dataSetService.isLocked( dataElement, period, organisationUnit, null ) )
+ {
+ ContextUtils.conflictResponse( response, "Data set is locked" );
+ return;
+ }
+
+ value = StringUtils.trimToNull( value );
+
+ String storedBy = currentUserService.getCurrentUsername();
+
+ Date now = new Date();
+
+ DataValue dataValue = dataValueService.getDataValue( organisationUnit, dataElement, period, categoryOptionCombo );
+
+ if ( dataValue == null )
+ {
+ if ( value != null )
+ {
+ dataValue = new DataValue( dataElement, period, organisationUnit, value, storedBy, now, null, categoryOptionCombo );
+ dataValueService.addDataValue( dataValue );
+ }
+ }
+ else
+ {
+ dataValue.setValue( value );
+ dataValue.setTimestamp( now );
+ dataValue.setStoredBy( storedBy );
+
+ dataValueService.updateDataValue( dataValue );
+ }
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/FormDefinitionController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/FormDefinitionController.java 2012-09-12 15:57:11 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/FormDefinitionController.java 2012-09-15 21:52:33 +0000
@@ -31,9 +31,9 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+
import javax.servlet.http.HttpServletResponse;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+
import org.hisp.dhis.api.utils.ContextUtils;
import org.hisp.dhis.common.view.ExportView;
import org.hisp.dhis.dxf2.metadata.ExportService;
@@ -61,8 +61,6 @@
{
public static final String RESOURCE_PATH = "/forms";
- private static final Log log = LogFactory.getLog( FormDefinitionController.class );
-
@Autowired
private ExportService exportService;
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js 2012-06-29 15:40:58 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js 2012-09-15 21:52:33 +0000
@@ -97,7 +97,7 @@
organisationUnits = JSON.parse( localStorage["organisationUnits"] );
- if(sessionStorage["organisationUnits"] !== undefined)
+ if ( sessionStorage["organisationUnits"] !== undefined )
{
$.extend(organisationUnits, JSON.parse( sessionStorage["organisationUnits"] ))
}
@@ -118,7 +118,7 @@
return true;
}
- if(localRoots == null || localRoots.length == 0)
+ if ( localRoots == null || localRoots.length == 0 )
{
return true;
}
@@ -644,9 +644,9 @@
function getAndCreateChildren(parentTag, parent)
{
- if(parent.c !== undefined)
+ if ( parent.c !== undefined )
{
- if(organisationUnits[parent.c[0]] !== undefined)
+ if ( organisationUnits[parent.c[0]] !== undefined )
{
createChildren( parentTag, parent );
}
@@ -656,10 +656,12 @@
function ( data, textStatus, jqXHR )
{
// load additional organisationUnits into sessionStorage
- if(sessionStorage["organisationUnits"] === undefined)
+ if ( sessionStorage["organisationUnits"] === undefined )
{
sessionStorage["organisationUnits"] = JSON.stringify( data.organisationUnits );
- } else {
+ }
+ else
+ {
units = JSON.parse( sessionStorage["organisationUnits"] );
$.extend(units, data.organisationUnits);
sessionStorage["organisationUnits"] = JSON.stringify( units );
@@ -682,7 +684,7 @@
{
var ou = organisationUnits[item];
- if(ou !== undefined)
+ if ( ou !== undefined )
{
$childrenTag.append( createTreeElementTag( ou ) );
}