← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20057: Add optionSet.valueType, wip

 

------------------------------------------------------------
revno: 20057
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-09-09 16:01:21 +0700
message:
  Add optionSet.valueType, wip
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionSet.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/option/hibernate/OptionSet.hbm.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/AddOptionSetAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/UpdateOptionSetAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addOptionSetForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateOptionSetForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties


--
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/option/OptionSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionSet.java	2015-07-15 09:45:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionSet.java	2015-09-09 09:01:21 +0000
@@ -28,24 +28,25 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.List;
-
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonView;
+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.BaseIdentifiableObject;
 import org.hisp.dhis.common.DxfNamespaces;
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.MergeStrategy;
+import org.hisp.dhis.common.ValueType;
 import org.hisp.dhis.common.VersionedObject;
 import org.hisp.dhis.common.annotation.Scanned;
 import org.hisp.dhis.common.view.DetailedView;
 import org.hisp.dhis.common.view.ExportView;
 
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonView;
-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 java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * @author Lars Helge Overland
@@ -58,6 +59,8 @@
     @Scanned
     private List<Option> options = new ArrayList<>();
 
+    private ValueType valueType;
+
     private int version;
 
     // -------------------------------------------------------------------------
@@ -90,28 +93,14 @@
 
     public List<String> getOptionValues()
     {
-        List<String> result = new ArrayList<>();
-
-        for ( Option option : options )
-        {
-            result.add( option.getName() );
-        }
-
-        return result;
+        return options.stream().map( Option::getName ).collect( Collectors.toList() );
     }
 
     public List<String> getOptionCodes()
     {
-        List<String> codes = new ArrayList<>();
-        
-        for ( Option option : options )
-        {
-            codes.add( option.getCode() );
-        }
-        
-        return codes;
+        return options.stream().map( Option::getCode ).collect( Collectors.toList() );
     }
-    
+
     public Option getOptionByCode( String code )
     {
         for ( Option option : options )
@@ -121,10 +110,10 @@
                 return option;
             }
         }
-        
+
         return null;
     }
-    
+
     // -------------------------------------------------------------------------
     // Getters and setters
     // -------------------------------------------------------------------------
@@ -144,6 +133,18 @@
         this.options = options;
     }
 
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public ValueType getValueType()
+    {
+        return valueType;
+    }
+
+    public void setValueType( ValueType valueType )
+    {
+        this.valueType = valueType;
+    }
+
     @Override
     @JsonProperty
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
@@ -171,8 +172,17 @@
         {
             OptionSet optionSet = (OptionSet) other;
 
+            if ( strategy.isReplace() )
+            {
+                valueType = optionSet.getValueType();
+            }
+            else if ( strategy.isMerge() )
+            {
+                valueType = optionSet.getValueType() == null ? valueType : optionSet.getValueType();
+            }
+
             version = optionSet.getVersion();
-            
+
             removeAllOptions();
             options.addAll( optionSet.getOptions() );
         }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties	2015-09-08 17:39:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties	2015-09-09 09:01:21 +0000
@@ -551,6 +551,11 @@
 string=String
 int=Number
 number=Number
+positive_integer=Positive Integer
+zero_positive_int=Positive or Zero Integer
+negative_integer=Negative Integer
+unit_interval=Unit interval
+percentage=Percentage
 date=Date
 date_time=Date & Time
 yes_no=Yes/No

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/option/hibernate/OptionSet.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/option/hibernate/OptionSet.hbm.xml	2014-07-29 07:52:47 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/option/hibernate/OptionSet.hbm.xml	2015-09-09 09:01:21 +0000
@@ -17,8 +17,16 @@
 
     <property name="name" column="name" not-null="true" unique="true" length="230" />
 
+    <property name="valueType" length="50">
+      <type name="org.hibernate.type.EnumType">
+        <param name="enumClass">org.hisp.dhis.common.ValueType</param>
+        <param name="useNamed">true</param>
+        <param name="type">12</param>
+      </type>
+    </property>
+
     <property name="version" />
-    
+
     <list name="options" cascade="all">
       <cache usage="read-write" />
       <key column="optionsetid" foreign-key="fk_optionsetmembers_optionsetid" />

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/AddOptionSetAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/AddOptionSetAction.java	2015-08-06 12:24:02 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/AddOptionSetAction.java	2015-09-09 09:01:21 +0000
@@ -28,12 +28,12 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.opensymphony.xwork2.Action;
 import org.apache.commons.lang3.StringUtils;
+import org.hisp.dhis.common.ValueType;
 import org.hisp.dhis.option.OptionService;
 import org.hisp.dhis.option.OptionSet;
 
-import com.opensymphony.xwork2.Action;
-
 /**
  * @author Chau Thu Tran
  */
@@ -61,7 +61,7 @@
     {
         this.name = name;
     }
-    
+
     private String code;
 
     public void setCode( String code )
@@ -69,6 +69,13 @@
         this.code = code;
     }
 
+    private String valueType;
+
+    public void setValueType( String valueType )
+    {
+        this.valueType = valueType;
+    }
+
     // -------------------------------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------------------------------
@@ -79,6 +86,7 @@
     {
         OptionSet optionSet = new OptionSet( StringUtils.trimToNull( name ) );
         optionSet.setCode( StringUtils.trimToNull( code ) );
+        optionSet.setValueType( ValueType.valueOf( valueType ) );
         optionSet.setVersion( 1 );
 
         optionService.saveOptionSet( optionSet );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/UpdateOptionSetAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/UpdateOptionSetAction.java	2015-08-06 12:24:02 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/UpdateOptionSetAction.java	2015-09-09 09:01:21 +0000
@@ -28,12 +28,12 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.opensymphony.xwork2.Action;
 import org.apache.commons.lang3.StringUtils;
+import org.hisp.dhis.common.ValueType;
 import org.hisp.dhis.option.OptionService;
 import org.hisp.dhis.option.OptionSet;
 
-import com.opensymphony.xwork2.Action;
-
 /**
  * @author Chau Thu Tran
  * @version $UpdateOptionSetAction.java Feb 3, 2012 9:28:11 PM$
@@ -77,6 +77,13 @@
         this.code = code;
     }
 
+    private String valueType;
+
+    public void setValueType( String valueType )
+    {
+        this.valueType = valueType;
+    }
+
     // -------------------------------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------------------------------
@@ -88,6 +95,7 @@
         OptionSet optionSet = optionService.getOptionSet( id );
         optionSet.setName( StringUtils.trimToNull( name ) );
         optionSet.setCode( StringUtils.trimToNull( code ) );
+        optionSet.setValueType( ValueType.valueOf( valueType ) );
 
         optionService.updateOptionSet( optionSet );
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addOptionSetForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addOptionSetForm.vm	2015-03-27 11:01:54 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addOptionSetForm.vm	2015-09-09 09:01:21 +0000
@@ -34,6 +34,26 @@
       <td><label>$i18n.getString( "code" )</label></td>
       <td colspan="3"><input type="text" id="code" name="code" class="{validate:{minlength:2}}"></td>
     </tr>
+    <tr>
+   		<td><label for="valueType">$i18n.getString( "value_type" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
+   		<td>
+         <select id="valueType" name="valueType">
+           <option value="INTEGER">$i18n.getString( "int" )</option>
+           <option value="INTEGER_POSITIVE">$i18n.getString( "positive_integer" )</option>
+           <option value="INTEGER_NEGATIVE">$i18n.getString( "negative_integer" )</option>
+           <option value="INTEGER_ZERO_OR_POSITIVE">$i18n.getString( "zero_positive_int" )</option>
+           <option value="NUMBER">$i18n.getString( "number" )</option>
+           <option value="UNIT_INTERVAL">$i18n.getString( "unit_interval" )</option>
+           <option value="PERCENTAGE">$i18n.getString( "percentage" )</option>
+           <option value="TEXT">$i18n.getString( "text" )</option>
+           <option value="LONG_TEXT">$i18n.getString( "long_text" )</option>
+           <option value="DATE">$i18n.getString( "date" )</option>
+           <option value="USERNAME">$i18n.getString( "user_name" )</option>
+           <option value="BOOLEAN">$i18n.getString( "yes_no" )</option>
+           <option value="TRUE_ONLY">$i18n.getString( "yes_only" )</option>
+         </select>
+   		</td>
+   	</tr>
 	<tr>
 	  <td></td>
 	  <td colspan="3">

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateOptionSetForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateOptionSetForm.vm	2015-03-27 11:01:54 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateOptionSetForm.vm	2015-09-09 09:01:21 +0000
@@ -29,6 +29,26 @@
       <td><label>$i18n.getString( "code" )</label></td>
       <td ><input type="text" id="code" name="code" value='$!optionSet.code' class="{validate:{minlength:2}}" /></td>
     </tr>
+    <tr>
+   		<td><label for="valueType">$i18n.getString( "value_type" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
+   		<td>
+         <select id="valueType" name="valueType">
+           <option value="INTEGER" #if( $!optionSet.valueType == 'INTEGER' ) selected="selected" #end >$i18n.getString( "int" )</option>
+           <option value="INTEGER_POSITIVE" #if( $!optionSet.valueType == 'INTEGER_POSITIVE' ) selected="selected" #end >$i18n.getString( "positive_integer" )</option>
+           <option value="INTEGER_NEGATIVE" #if( $!optionSet.valueType == 'INTEGER_NEGATIVE' ) selected="selected" #end >$i18n.getString( "negative_integer" )</option>
+           <option value="INTEGER_ZERO_OR_POSITIVE" #if( $!optionSet.valueType == 'INTEGER_ZERO_OR_POSITIVE' ) selected="selected" #end >$i18n.getString( "zero_positive_int" )</option>
+           <option value="NUMBER" #if( $!optionSet.optionSet == 'NUMBER' ) selected="selected" #end >$i18n.getString( "number" )</option>
+           <option value="UNIT_INTERVAL" #if( $!optionSet.valueType == 'UNIT_INTERVAL' ) selected="selected" #end >$i18n.getString( "unit_interval" )</option>
+           <option value="PERCENTAGE" #if( $!optionSet.valueType == 'PERCENTAGE' ) selected="selected" #end >$i18n.getString( "percentage" )</option>
+           <option value="TEXT" #if( $!optionSet.valueType == 'TEXT' ) selected="selected" #end >$i18n.getString( "text" )</option>
+           <option value="LONG_TEXT" #if( $!optionSet.valueType == 'LONG_TEXT' ) selected="selected" #end >$i18n.getString( "long_text" )</option>
+           <option value="DATE" #if( $!optionSet.valueType == 'DATE' ) selected="selected" #end >$i18n.getString( "date" )</option>
+           <option value="USERNAME" #if( $!optionSet.valueType == 'USERNAME' ) selected="selected" #end >$i18n.getString( "user_name" )</option>
+           <option value="BOOLEAN" #if( $!optionSet.valueType == 'BOOLEAN' ) selected="selected" #end >$i18n.getString( "yes_no" )</option>
+           <option value="TRUE_ONLY" #if( $!optionSet.valueType == 'TRUE_ONLY' ) selected="selected" #end >$i18n.getString( "yes_only" )</option>
+         </select>
+   		</td>
+   	</tr>
 	<tr>
 	  <td></td>
 	  <td colspan="2">

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties	2015-09-04 08:14:19 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties	2015-09-09 09:01:21 +0000
@@ -23,8 +23,6 @@
 data_element_category=Data Element Category
 data_element_category_combo=Data Element Category Combination
 select=Select
-unit_interval=Unit interval
-percentage=Percentage
 data_element=Data Element
 data_element_group=Data Element Group
 data_element_groups=Data Element Groups
@@ -34,7 +32,6 @@
 indicator_groups=Indicator Groups
 create_new_data_element=Create new data element
 domain_type=Domain Type
-date=Date
 create_new_data_element_group=Create new data element group
 group_members=Group members
 available_data_elements=Available data elements
@@ -174,9 +171,6 @@
 number_value_type=Number type
 number=Number
 int=Integer
-positive_integer=Positive Integer
-zero_positive_int=Positive or Zero Integer
-negative_integer=Negative Integer
 view_1=View 1
 view_2=View 2
 store_zero_data_values=Store zero data values
@@ -187,8 +181,6 @@
 option_set=Option set
 please_select=Please select
 formula=Formula
-long_text = Long text
-text_type = Text type
 legend_set=Legend set
 skip_total_in_reports=Skip category total in reports
 data_element_category_option = Data Element Category Option