dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31709
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16207: Forms, impl support for including meta-data about the form when metaData=true is provided with th...
------------------------------------------------------------
revno: 16207
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-07-21 16:26:12 +0200
message:
Forms, impl support for including meta-data about the form when metaData=true is provided with the request
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/NameableObjectUtils.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataSetController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/form/Form.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/common/NameableObjectUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/NameableObjectUtils.java 2014-07-13 13:53:40 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/NameableObjectUtils.java 2014-07-21 14:26:12 +0000
@@ -31,7 +31,9 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* @author Lars Helge Overland
@@ -133,4 +135,25 @@
return objects;
}
+
+ /**
+ * Returns a mapping between the uid and the nameable objects.
+ *
+ * @param objects the nameable objects.
+ * @return mapping between the uid and the nameable objects.
+ */
+ public static Map<String, NameableObject> getUidObjectMap( Collection<? extends NameableObject> objects )
+ {
+ Map<String, NameableObject> map = new HashMap<String, NameableObject>();
+
+ if ( objects != null )
+ {
+ for ( NameableObject object : objects )
+ {
+ map.put( object.getUid(), object );
+ }
+ }
+
+ return map;
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataSetController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataSetController.java 2014-07-21 14:01:10 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataSetController.java 2014-07-21 14:26:12 +0000
@@ -28,6 +28,22 @@
* 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.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.transform.Transformer;
+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.common.NameableObjectUtils;
import org.hisp.dhis.common.view.ExportView;
import org.hisp.dhis.dataentryform.DataEntryForm;
import org.hisp.dhis.dataentryform.DataEntryFormService;
@@ -62,20 +78,6 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
-import javax.servlet.http.HttpServletResponse;
-import javax.xml.transform.Transformer;
-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.List;
-import java.util.Map;
-
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@@ -171,7 +173,7 @@
@PathVariable( "uid" ) String uid,
@RequestParam( value = "ou", required = false ) String orgUnit,
@RequestParam( value = "pe", required = false ) String period,
- HttpServletResponse response ) throws IOException
+ @RequestParam( required = false ) boolean metaData, HttpServletResponse response ) throws IOException
{
List<DataSet> dataSets = getEntity( uid );
@@ -191,7 +193,7 @@
Period pe = PeriodType.getPeriodFromIsoString( period );
- Form form = getForm( dataSets, ou, pe );
+ Form form = getForm( dataSets, ou, pe, metaData );
JacksonUtils.toJson( response.getOutputStream(), form );
}
@@ -201,7 +203,7 @@
@PathVariable( "uid" ) String uid,
@RequestParam( value = "ou", required = false ) String orgUnit,
@RequestParam( value = "pe", required = false ) String period,
- HttpServletResponse response ) throws IOException
+ @RequestParam( required = false ) boolean metaData, HttpServletResponse response ) throws IOException
{
List<DataSet> dataSets = getEntity( uid );
@@ -221,16 +223,18 @@
Period pe = PeriodType.getPeriodFromIsoString( period );
- Form form = getForm( dataSets, ou, pe );
+ Form form = getForm( dataSets, ou, pe, metaData );
JacksonUtils.toXml( response.getOutputStream(), form );
}
- private Form getForm( List<DataSet> dataSets, OrganisationUnit ou, Period pe )
+ private Form getForm( List<DataSet> dataSets, OrganisationUnit ou, Period pe, boolean metaData )
{
- i18nService.internationalise( dataSets.get( 0 ) );
- i18nService.internationalise( dataSets.get( 0 ).getDataElements() );
- i18nService.internationalise( dataSets.get( 0 ).getSections() );
+ DataSet dataSet = dataSets.get( 0 );
+
+ i18nService.internationalise( dataSet );
+ i18nService.internationalise( dataSet.getDataElements() );
+ i18nService.internationalise( dataSet.getSections() );
Form form = FormUtils.fromDataSet( dataSets.get( 0 ) );
@@ -243,6 +247,11 @@
FormUtils.fillWithDataValues( form, dataValues );
}
+ if ( metaData )
+ {
+ form.getMetaData().putAll( NameableObjectUtils.getUidObjectMap( dataSet.getDataElements() ) );
+ }
+
return form;
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/form/Form.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/form/Form.java 2014-07-09 01:44:58 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/form/Form.java 2014-07-21 14:26:12 +0000
@@ -29,10 +29,14 @@
*/
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
+import org.hisp.dhis.common.BaseNameableObject;
import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.NameableObject;
import java.util.ArrayList;
import java.util.HashMap;
@@ -52,6 +56,8 @@
private List<Group> groups = new ArrayList<Group>();
private Map<String, Object> options = new HashMap<String, Object>();
+
+ private Map<String, NameableObject> metaData = new HashMap<String, NameableObject>();
public Form()
{
@@ -106,6 +112,20 @@
this.options = options;
}
+ @JsonProperty
+ @JsonSerialize( contentAs = BaseNameableObject.class )
+ @JacksonXmlElementWrapper( localName = "metaData", namespace = DxfNamespaces.DXF_2_0 )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public Map<String, NameableObject> getMetaData()
+ {
+ return metaData;
+ }
+
+ public void setMetaData( Map<String, NameableObject> metaData )
+ {
+ this.metaData = metaData;
+ }
+
@Override
public String toString()
{