dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20850
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9705: Added method for updating custom data entry forms through the web api
------------------------------------------------------------
revno: 9705
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-02-04 09:29:22 +0200
message:
Added method for updating custom data entry forms through the web api
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataSetController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.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-api/src/main/java/org/hisp/dhis/dataset/DataSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java 2013-02-03 10:44:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java 2013-02-04 07:29:22 +0000
@@ -68,7 +68,7 @@
public static final String TYPE_SECTION = "section";
public static final String TYPE_CUSTOM = "custom";
public static final String TYPE_SECTION_MULTIORG = "multiorg_section";
-
+
public static final int NO_EXPIRY = 0;
/**
@@ -150,7 +150,7 @@
* Indicating whether the user completing this data set should be sent a notification.
*/
private boolean notifyCompletingUser;
-
+
// -------------------------------------------------------------------------
// Form properties
// -------------------------------------------------------------------------
@@ -175,6 +175,11 @@
*/
private boolean skipOffline;
+ /**
+ * Indicating whether data element names should be prefixed with their codes.
+ */
+ private boolean codePrefixDataElements;
+
// -------------------------------------------------------------------------
// Contructors
// -------------------------------------------------------------------------
@@ -643,6 +648,19 @@
this.skipOffline = skipOffline;
}
+ @JsonProperty
+ @JsonView( {DetailedView.class, ExportView.class} )
+ @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
+ public boolean isCodePrefixDataElements()
+ {
+ return codePrefixDataElements;
+ }
+
+ public void setCodePrefixDataElements( boolean codePrefixDataElements )
+ {
+ this.codePrefixDataElements = codePrefixDataElements;
+ }
+
@Override
public void mergeWith( IdentifiableObject other )
{
@@ -663,6 +681,7 @@
fieldCombinationRequired = dataSet.isFieldCombinationRequired();
validCompleteOnly = dataSet.isValidCompleteOnly();
skipOffline = dataSet.isSkipOffline();
+ codePrefixDataElements = dataSet.isCodePrefixDataElements();
removeAllDataElements();
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataSetController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataSetController.java 2013-02-03 09:53:30 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataSetController.java 2013-02-04 07:29:22 +0000
@@ -27,13 +27,31 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
import org.hisp.dhis.api.utils.ContextUtils;
import org.hisp.dhis.api.utils.FormUtils;
import org.hisp.dhis.api.view.ClassPathUriResolver;
import org.hisp.dhis.api.webdomain.form.Form;
import org.hisp.dhis.common.view.ExportView;
+import org.hisp.dhis.dataentryform.DataEntryForm;
+import org.hisp.dhis.dataentryform.DataEntryFormService;
import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.dataset.Section;
+import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.datavalue.DataValue;
import org.hisp.dhis.datavalue.DataValueService;
import org.hisp.dhis.dxf2.metadata.ExportService;
@@ -45,27 +63,14 @@
import org.hisp.dhis.period.PeriodType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
+import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@@ -82,6 +87,12 @@
// -------------------------------------------------------------------------
@Autowired
+ private DataSetService dataSetService;
+
+ @Autowired
+ private DataEntryFormService dataEntryFormService;
+
+ @Autowired
private ExportService exportService;
@Autowired
@@ -186,10 +197,41 @@
{
}
+ @RequestMapping( value = "/{uid}/customDataEntryForm", method = { RequestMethod.PUT, RequestMethod.POST }, consumes = "text/html" )
+ @PreAuthorize( "hasRole('ALL')" )
+ public void updateCustomDataEntryForm( @PathVariable( "uid" ) String uid,
+ @RequestBody String formContent,
+ HttpServletResponse response ) throws Exception
+ {
+ DataSet dataSet = dataSetService.getDataSet( uid );
+
+ if ( dataSet == null )
+ {
+ ContextUtils.notFoundResponse( response, "Data set not found for identifier: " + uid );
+ return;
+ }
+
+ DataEntryForm form = dataSet.getDataEntryForm();
+
+ if ( form == null )
+ {
+ form = new DataEntryForm( dataSet.getName(), DataEntryForm.STYLE_REGULAR, formContent );
+ dataEntryFormService.addDataEntryForm( form );
+
+ dataSet.setDataEntryForm( form );
+ dataSetService.updateDataSet( dataSet );
+ }
+ else
+ {
+ form.setHtmlCode( formContent );
+ dataEntryFormService.updateDataEntryForm( form );
+ }
+ }
+
/**
- * select only the metadata required to describe form definitions
+ * Select only the meta-data required to describe form definitions.
*
- * @return the filtered options
+ * @return the filtered options.
*/
private WebOptions filterMetadataOptions()
{
@@ -200,5 +242,4 @@
options.addOption( "dataSets", "true" );
return options;
}
-
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportController.java 2012-10-14 14:39:23 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportController.java 2013-02-04 07:29:22 +0000
@@ -44,6 +44,7 @@
import org.hisp.dhis.report.ReportService;
import org.hisp.dhis.system.util.CodecUtils;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
@@ -104,6 +105,7 @@
}
@RequestMapping( value = "/{uid}/design", method = RequestMethod.PUT )
+ @PreAuthorize( "hasRole('ALL')" )
public void updateReportDesign( @PathVariable( "uid" ) String uid,
@RequestBody String designContent,
HttpServletResponse response ) throws Exception
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java 2013-02-03 09:53:30 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java 2013-02-04 07:29:22 +0000
@@ -27,6 +27,15 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.apache.commons.collections.CollectionUtils;
import org.hisp.dhis.api.utils.ContextUtils;
import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
@@ -40,7 +49,6 @@
import org.hisp.dhis.api.webdomain.user.UserAccount;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
-import org.hisp.dhis.dataset.Section;
import org.hisp.dhis.dxf2.utils.JacksonUtils;
import org.hisp.dhis.i18n.I18nService;
import org.hisp.dhis.interpretation.Interpretation;
@@ -60,14 +68,6 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Set;
-
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/