← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21477: implemented attributes for options

 

------------------------------------------------------------
revno: 21477
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-12-17 13:56:47 +0100
message:
  implemented attributes for options
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/Attribute.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/option/hibernate/Option.hbm.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/AddOptionAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/GetOptionAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/GetOptionSetAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/UpdateOptionAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addOptionForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateOptionForm.vm


--
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/attribute/Attribute.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/Attribute.java	2015-12-17 11:44:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/Attribute.java	2015-12-17 12:56:47 +0000
@@ -48,6 +48,7 @@
 import org.hisp.dhis.document.Document;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.indicator.IndicatorGroup;
+import org.hisp.dhis.option.Option;
 import org.hisp.dhis.option.OptionSet;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
@@ -495,6 +496,7 @@
         if ( trackedEntityAttribute ) klasses.add( TrackedEntity.class );
         if ( trackedEntityAttributeAttribute ) klasses.add( TrackedEntityAttribute.class );
         if ( documentAttribute ) klasses.add( Document.class );
+        if ( optionAttribute ) klasses.add( Option.class );
 
         return klasses;
     }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/option/hibernate/Option.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/option/hibernate/Option.hbm.xml	2014-08-29 12:48:40 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/option/hibernate/Option.hbm.xml	2015-12-17 12:56:47 +0000
@@ -13,13 +13,22 @@
     <id name="id" column="optionvalueid">
       <generator class="native" />
     </id>
-    
+
     <property name="uid" column="uid" unique="true" length="11" />
-    <property name="code" column="code" not-null="false" unique="false" length="230" /> <!-- Length for legacy support -->
-    <property name="created" type="timestamp"/>
-    <property name="lastUpdated" type="timestamp"/>
+    <property name="code" column="code" not-null="false" unique="false" length="230" />
+
+    <!-- Length for legacy support -->
+    <property name="created" type="timestamp" />
+    <property name="lastUpdated" type="timestamp" />
 
     <property name="name" column="name" not-null="true" length="230" />
-	
+
+    <!-- Dynamic attribute values -->
+    <set name="attributeValues" table="optionattributevalues" cascade="delete-orphan">
+      <cache usage="read-write" />
+      <key column="optionvalueid" />
+      <many-to-many class="org.hisp.dhis.attribute.AttributeValue" column="attributevalueid" unique="true" />
+    </set>
+
   </class>
 </hibernate-mapping>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/AddOptionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/AddOptionAction.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/AddOptionAction.java	2015-12-17 12:56:47 +0000
@@ -28,16 +28,18 @@
  * 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.attribute.AttributeService;
 import org.hisp.dhis.option.Option;
 import org.hisp.dhis.option.OptionService;
 import org.hisp.dhis.option.OptionSet;
+import org.springframework.beans.factory.annotation.Autowired;
 
-import com.opensymphony.xwork2.Action;
+import java.util.List;
 
 /**
  * @author Chau Thu Tran
- *
  * @version $ AddOptionAction.java Jul 28, 2014 8:41:52 PM $
  */
 public class AddOptionAction
@@ -54,6 +56,9 @@
         this.optionService = optionService;
     }
 
+    @Autowired
+    private AttributeService attributeService;
+
     // -------------------------------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------------------------------
@@ -84,6 +89,13 @@
         this.code = code;
     }
 
+    private List<String> jsonAttributeValues;
+
+    public void setJsonAttributeValues( List<String> jsonAttributeValues )
+    {
+        this.jsonAttributeValues = jsonAttributeValues;
+    }
+
     // -------------------------------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------------------------------
@@ -99,6 +111,11 @@
         option.setCode( StringUtils.trimToNull( code ) );
         optionSet.getOptions().add( option );
 
+        if ( jsonAttributeValues != null )
+        {
+            attributeService.updateAttributeValues( option, jsonAttributeValues );
+        }
+
         optionService.updateOptionSet( optionSet );
 
         return SUCCESS;

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/GetOptionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/GetOptionAction.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/GetOptionAction.java	2015-12-17 12:56:47 +0000
@@ -28,16 +28,24 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.opensymphony.xwork2.Action;
+import org.hisp.dhis.attribute.Attribute;
+import org.hisp.dhis.attribute.AttributeService;
+import org.hisp.dhis.attribute.comparator.AttributeSortOrderComparator;
 import org.hisp.dhis.option.Option;
 import org.hisp.dhis.option.OptionService;
 import org.hisp.dhis.option.OptionSet;
+import org.hisp.dhis.system.util.AttributeUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 
-import com.opensymphony.xwork2.Action;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author Chau Thu Tran
- *
- * @version $ GetOptionAction.java Jul 28, 2014 8:41:52 PM $
  */
 public class GetOptionAction
     implements Action
@@ -53,6 +61,9 @@
         this.optionService = optionService;
     }
 
+    @Autowired
+    private AttributeService attributeService;
+
     // -------------------------------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------------------------------
@@ -85,6 +96,20 @@
         return option;
     }
 
+    private List<Attribute> attributes;
+
+    public List<Attribute> getAttributes()
+    {
+        return attributes;
+    }
+
+    private Map<Integer, String> attributeValues = new HashMap<>();
+
+    public Map<Integer, String> getAttributeValues()
+    {
+        return attributeValues;
+    }
+
     // -------------------------------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------------------------------
@@ -97,6 +122,11 @@
 
         option = optionService.getOption( optionId );
 
+        attributeValues = AttributeUtils.getAttributeValueMap( option.getAttributeValues() );
+
+        attributes = new ArrayList<>( attributeService.getAttributes( Option.class ) );
+        Collections.sort( attributes, AttributeSortOrderComparator.INSTANCE );
+
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/GetOptionSetAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/GetOptionSetAction.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/GetOptionSetAction.java	2015-12-17 12:56:47 +0000
@@ -29,12 +29,22 @@
  */
 
 import com.opensymphony.xwork2.Action;
+import org.hisp.dhis.attribute.Attribute;
+import org.hisp.dhis.attribute.AttributeService;
+import org.hisp.dhis.attribute.comparator.AttributeSortOrderComparator;
+import org.hisp.dhis.option.Option;
 import org.hisp.dhis.option.OptionService;
 import org.hisp.dhis.option.OptionSet;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author Chau Thu Tran
- * @version $GetOptionSetAction.java Feb 3, 2012 9:28:11 PM$
  */
 public class GetOptionSetAction
     implements Action
@@ -45,6 +55,9 @@
 
     private OptionService optionService;
 
+    @Autowired
+    private AttributeService attributeService;
+
     // -------------------------------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------------------------------
@@ -53,6 +66,10 @@
 
     private OptionSet optionSet;
 
+    private List<Attribute> attributes;
+
+    private Map<Integer, String> attributeValues = new HashMap<>();
+
     // -------------------------------------------------------------------------------------------------
     // Getters && Setters
     // -------------------------------------------------------------------------------------------------
@@ -72,6 +89,16 @@
         this.id = id;
     }
 
+    public List<Attribute> getAttributes()
+    {
+        return attributes;
+    }
+
+    public Map<Integer, String> getAttributeValues()
+    {
+        return attributeValues;
+    }
+
     // -------------------------------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------------------------------
@@ -82,7 +109,9 @@
     {
         optionSet = optionService.getOptionSet( id );
 
+        attributes = new ArrayList<>( attributeService.getAttributes( Option.class ) );
+        Collections.sort( attributes, AttributeSortOrderComparator.INSTANCE );
+
         return SUCCESS;
     }
-
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/UpdateOptionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/UpdateOptionAction.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/UpdateOptionAction.java	2015-12-17 12:56:47 +0000
@@ -28,15 +28,17 @@
  * 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.attribute.AttributeService;
 import org.hisp.dhis.option.Option;
 import org.hisp.dhis.option.OptionService;
+import org.springframework.beans.factory.annotation.Autowired;
 
-import com.opensymphony.xwork2.Action;
+import java.util.List;
 
 /**
  * @author Chau Thu Tran
- *
  * @version $ UpdateOptionAction.java Jul 28, 2014 8:41:52 PM $
  */
 public class UpdateOptionAction
@@ -53,6 +55,9 @@
         this.optionService = optionService;
     }
 
+    @Autowired
+    private AttributeService attributeService;
+
     // -------------------------------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------------------------------
@@ -83,6 +88,13 @@
         this.name = name;
     }
 
+    private List<String> jsonAttributeValues;
+
+    public void setJsonAttributeValues( List<String> jsonAttributeValues )
+    {
+        this.jsonAttributeValues = jsonAttributeValues;
+    }
+
     // -------------------------------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------------------------------
@@ -93,6 +105,12 @@
     {
         Option option = optionService.getOption( optionId );
         option.setName( StringUtils.trimToNull( name ) );
+
+        if ( jsonAttributeValues != null )
+        {
+            attributeService.updateAttributeValues( option, jsonAttributeValues );
+        }
+
         optionService.updateOption( option );
 
         return SUCCESS;

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addOptionForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addOptionForm.vm	2015-12-09 11:01:09 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addOptionForm.vm	2015-12-17 12:56:47 +0000
@@ -15,6 +15,7 @@
       var valueType = '$optionSet.valueType';
 
       if( dhis2.validation.isValidValueType(value, valueType) ) {
+        #tblDynamicAttributesJavascript()
         form.submit();
       }
     });
@@ -45,6 +46,11 @@
       <td><label for='code'>$i18n.getString( "code" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
       <td><input type="text" id="code" name="code" class="{validate:{required:true}}"/></td>
     </tr>
+  </table>
+
+  #tblDynamicAttributes( { "attributes": $attributes, "attributeValues": $attributeValues } )
+
+  <table>
     <tr>
       <td></td>
       <td colspan="2">

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateOptionForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateOptionForm.vm	2015-12-09 11:01:09 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateOptionForm.vm	2015-12-17 12:56:47 +0000
@@ -6,6 +6,7 @@
       var valueType = '$optionSet.valueType';
 
       if( dhis2.validation.isValidValueType(value, valueType) ) {
+        #tblDynamicAttributesJavascript()
         form.submit();
       }
     });
@@ -38,12 +39,17 @@
       <td><label for='code'>$i18n.getString( "code" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
       <td><input type="text" id="code" name="code" style="background-color: lightgrey;" readonly disabled value='$option.code' class="{validate:{required:true}}"/></td>
     </tr>
-    <tr>
-      <td></td>
-      <td colspan="2">
-        <input type="submit" value="$i18n.getString( 'update' )" style="width:10em">
-        <input type="button" onclick="window.location.href='option.action?optionSetId=$optionSet.id'" value="$i18n.getString( 'cancel' )" style="width:10em"/></p>
-      </td>
-    </tr>
+  </table>
+
+  #tblDynamicAttributes( { "attributes": $attributes, "attributeValues": $attributeValues } )
+
+  <table
+  <tr>
+    <td></td>
+    <td colspan="2">
+      <input type="submit" value="$i18n.getString( 'update' )" style="width:10em">
+      <input type="button" onclick="window.location.href='option.action?optionSetId=$optionSet.id'" value="$i18n.getString( 'cancel' )" style="width:10em"/></p>
+    </td>
+  </tr>
   </table>
 </form>