dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31712
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16208: Forms, centralized code
------------------------------------------------------------
revno: 16208
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-07-21 17:28:57 +0200
message:
Forms, centralized code
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/controller/user/CurrentUserController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/FormUtils.java
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/Group.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/form/InputType.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-21 14:26:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/NameableObjectUtils.java 2014-07-21 15:28:57 +0000
@@ -31,7 +31,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -137,14 +137,15 @@
}
/**
- * Returns a mapping between the uid and the nameable objects.
+ * Returns a mapping between the uid and the nameable objects. The order of
+ * the objects are preserved.
*
* @param objects the nameable objects.
- * @return mapping between the uid and the nameable objects.
+ * @return ordered mapping between the uid and the nameable objects.
*/
- public static Map<String, NameableObject> getUidObjectMap( Collection<? extends NameableObject> objects )
+ public static Map<String, NameableObject> getUidObjectMap( List<? extends NameableObject> objects )
{
- Map<String, NameableObject> map = new HashMap<String, NameableObject>();
+ Map<String, NameableObject> map = new LinkedHashMap<String, NameableObject>();
if ( objects != null )
{
=== 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:26:12 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataSetController.java 2014-07-21 15:28:57 +0000
@@ -43,7 +43,6 @@
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;
@@ -236,7 +235,7 @@
i18nService.internationalise( dataSet.getDataElements() );
i18nService.internationalise( dataSet.getSections() );
- Form form = FormUtils.fromDataSet( dataSets.get( 0 ) );
+ Form form = FormUtils.fromDataSet( dataSets.get( 0 ), metaData );
if ( ou != null && pe != null )
{
@@ -247,11 +246,6 @@
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/controller/user/CurrentUserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/CurrentUserController.java 2014-07-01 10:10:50 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/CurrentUserController.java 2014-07-21 15:28:57 +0000
@@ -569,7 +569,7 @@
formDataSet.setId( uid );
formDataSet.setLabel( dataSet.getDisplayName() );
- forms.getForms().put( uid, FormUtils.fromDataSet( dataSet ) );
+ forms.getForms().put( uid, FormUtils.fromDataSet( dataSet, false ) );
formOrganisationUnit.getDataSets().add( formDataSet );
if ( optionSets )
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/FormUtils.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/FormUtils.java 2014-07-21 12:05:04 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/FormUtils.java 2014-07-21 15:28:57 +0000
@@ -28,10 +28,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import org.hisp.dhis.webapi.webdomain.form.Field;
-import org.hisp.dhis.webapi.webdomain.form.Form;
-import org.hisp.dhis.webapi.webdomain.form.Group;
-import org.hisp.dhis.webapi.webdomain.form.InputType;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.hisp.dhis.common.NameableObjectUtils;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
@@ -44,22 +48,19 @@
import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.program.ProgramStageDataElement;
import org.hisp.dhis.program.ProgramStageSection;
+import org.hisp.dhis.webapi.webdomain.form.Field;
+import org.hisp.dhis.webapi.webdomain.form.Form;
+import org.hisp.dhis.webapi.webdomain.form.Group;
+import org.hisp.dhis.webapi.webdomain.form.InputType;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
-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 Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
public class FormUtils
{
- public static Form fromDataSet( DataSet dataSet )
+ public static Form fromDataSet( DataSet dataSet, boolean metaData )
{
Form form = new Form();
form.setLabel( dataSet.getDisplayName() );
@@ -77,24 +78,36 @@
{
List<Field> fields = inputsFromDataElements( new ArrayList<DataElement>( section.getDataElements() ), new ArrayList<DataElementOperand>( section.getGreyedFields() ) );
- Group s = new Group();
- s.setLabel( section.getDisplayName() );
- s.setDescription( section.getDescription() );
- s.setDataElementCount( section.getDataElements().size() );
- s.setFields( fields );
- form.getGroups().add( s );
+ Group group = new Group();
+ group.setLabel( section.getDisplayName() );
+ group.setDescription( section.getDescription() );
+ group.setDataElementCount( section.getDataElements().size() );
+ group.setFields( fields );
+
+ if ( metaData )
+ {
+ group.setMetaData( NameableObjectUtils.getUidObjectMap( section.getDataElements() ) );
+ }
+
+ form.getGroups().add( group );
}
}
else
{
List<Field> fields = inputsFromDataElements( new ArrayList<DataElement>( dataSet.getDataElements() ) );
- Group s = new Group();
- s.setLabel( DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME );
- s.setDescription( DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME );
- s.setDataElementCount( dataSet.getDataElements().size() );
- s.setFields( fields );
- form.getGroups().add( s );
+ Group group = new Group();
+ group.setLabel( DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME );
+ group.setDescription( DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME );
+ group.setDataElementCount( dataSet.getDataElements().size() );
+ group.setFields( fields );
+
+ if ( metaData )
+ {
+ group.setMetaData( NameableObjectUtils.getUidObjectMap( new ArrayList<DataElement>( dataSet.getDataElements() ) ) );
+ }
+
+ form.getGroups().add( group );
}
return form;
@@ -148,10 +161,10 @@
{
List<Field> fields = inputsFromProgramStageDataElements( section.getProgramStageDataElements() );
- Group s = new Group();
- s.setLabel( section.getDisplayName() );
- s.setFields( fields );
- form.getGroups().add( s );
+ Group group = new Group();
+ group.setLabel( section.getDisplayName() );
+ group.setFields( fields );
+ form.getGroups().add( group );
}
}
else
@@ -159,10 +172,10 @@
List<Field> fields = inputsFromProgramStageDataElements(
new ArrayList<ProgramStageDataElement>( programStage.getProgramStageDataElements() ) );
- Group s = new Group();
- s.setLabel( "default" );
- s.setFields( fields );
- form.getGroups().add( s );
+ Group group = new Group();
+ group.setLabel( "default" );
+ group.setFields( fields );
+ form.getGroups().add( group );
}
return form;
@@ -240,6 +253,8 @@
private static InputType inputTypeFromDataElement( DataElement dataElement )
{
+ //TODO harmonize / use map
+
if ( DataElement.VALUE_TYPE_STRING.equals( dataElement.getType() ) )
{
if ( DataElement.VALUE_TYPE_TEXT.equals( dataElement.getTextType() ) )
@@ -273,6 +288,14 @@
{
return InputType.INTEGER_NEGATIVE;
}
+ else if ( DataElement.VALUE_TYPE_UNIT_INTERVAL.equals( dataElement.getNumberType() ) )
+ {
+ return InputType.UNIT_INTERVAL;
+ }
+ else if ( DataElement.VALUE_TYPE_PERCENTAGE.equals( dataElement.getNumberType() ) )
+ {
+ return InputType.PERCENTAGE;
+ }
}
else if ( DataElement.VALUE_TYPE_BOOL.equals( dataElement.getType() ) )
{
=== 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-21 14:26:12 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/form/Form.java 2014-07-21 15:28:57 +0000
@@ -28,21 +28,18 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.hisp.dhis.common.DxfNamespaces;
+
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;
-import java.util.List;
-import java.util.Map;
-
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@@ -57,8 +54,6 @@
private Map<String, Object> options = new HashMap<String, Object>();
- private Map<String, NameableObject> metaData = new HashMap<String, NameableObject>();
-
public Form()
{
}
@@ -111,20 +106,6 @@
{
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()
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/form/Group.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/form/Group.java 2014-07-21 12:05:04 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/form/Group.java 2014-07-21 15:28:57 +0000
@@ -28,14 +28,19 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.hisp.dhis.common.BaseNameableObject;
+import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.NameableObject;
+
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.DxfNamespaces;
-
-import java.util.ArrayList;
-import java.util.List;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -51,6 +56,8 @@
private List<Field> fields = new ArrayList<Field>();
+ private Map<String, NameableObject> metaData;
+
public Group()
{
}
@@ -103,4 +110,18 @@
{
this.fields = fields;
}
+
+ @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;
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/form/InputType.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/form/InputType.java 2014-05-22 12:40:24 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/form/InputType.java 2014-07-21 15:28:57 +0000
@@ -43,5 +43,7 @@
INTEGER_POSITIVE,
INTEGER_NEGATIVE,
INTEGER_ZERO_OR_POSITIVE,
- NEGATIVE_INTEGER
+ NEGATIVE_INTEGER,
+ UNIT_INTERVAL,
+ PERCENTAGE
}