← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17861: add created/lastUpdated properties to AttributeValue

 

------------------------------------------------------------
revno: 17861
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-01-02 15:06:24 +0100
message:
  add created/lastUpdated properties to AttributeValue
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValue.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/AttributeValue.hbm.xml
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeValueServiceTest.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/attribute/AttributeService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeService.java	2014-12-23 18:03:44 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeService.java	2015-01-02 14:06:24 +0000
@@ -31,7 +31,7 @@
 import java.util.Set;
 
 /**
- * @author mortenoh
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 public interface AttributeService
 {

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValue.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValue.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValue.java	2015-01-02 14:06:24 +0000
@@ -40,11 +40,12 @@
 import org.hisp.dhis.common.view.ExportView;
 
 import java.io.Serializable;
+import java.util.Date;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
-@JacksonXmlRootElement( localName = "attributeValue", namespace = DxfNamespaces.DXF_2_0)
+@JacksonXmlRootElement( localName = "attributeValue", namespace = DxfNamespaces.DXF_2_0 )
 public class AttributeValue
     implements Serializable
 {
@@ -55,20 +56,42 @@
 
     private int id;
 
+    /**
+     * The date this object was created.
+     */
+    private Date created;
+
+    /**
+     * The date this object was last updated.
+     */
+    private Date lastUpdated;
+
     private Attribute attribute;
 
     private String value;
 
     public AttributeValue()
     {
-
+        this.created = new Date();
+        this.lastUpdated = new Date();
     }
 
     public AttributeValue( String value )
     {
+        this();
         this.value = value;
     }
 
+    public void setAutoFields()
+    {
+        if ( created == null )
+        {
+            created = new Date();
+        }
+
+        lastUpdated = new Date();
+    }
+
     @Override
     public boolean equals( Object o )
     {
@@ -115,9 +138,35 @@
     }
 
     @JsonProperty
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( isAttribute = true )
+    public Date getCreated()
+    {
+        return created;
+    }
+
+    public void setCreated( Date created )
+    {
+        this.created = created;
+    }
+
+    @JsonProperty
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( isAttribute = true )
+    public Date getLastUpdated()
+    {
+        return lastUpdated;
+    }
+
+    public void setLastUpdated( Date lastUpdated )
+    {
+        this.lastUpdated = lastUpdated;
+    }
+
+    @JsonProperty
     @JsonSerialize( as = BaseIdentifiableObject.class )
-    @JsonView( {DetailedView.class, ExportView.class} )
-    @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public Attribute getAttribute()
     {
         return attribute;
@@ -129,8 +178,8 @@
     }
 
     @JsonProperty
-    @JsonView( {DetailedView.class, ExportView.class} )
-    @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public String getValue()
     {
         return value;

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java	2014-12-23 18:03:44 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java	2015-01-02 14:06:24 +0000
@@ -217,12 +217,14 @@
     @Override
     public void addAttributeValue( AttributeValue attributeValue )
     {
+        attributeValue.setAutoFields();
         attributeValueStore.save( attributeValue );
     }
 
     @Override
     public void updateAttributeValue( AttributeValue attributeValue )
     {
+        attributeValue.setAutoFields();
         attributeValueStore.update( attributeValue );
     }
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2014-12-23 17:19:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2015-01-02 14:06:24 +0000
@@ -779,7 +779,11 @@
         executeSql( "alter table datavalueaudit alter column attributeoptioncomboid set not null;" );
         
         executeSql( "update dataelementcategoryoption set shortname = substring(name,0,50) where shortname is null" );
-        
+
+        // AttributeValue
+        executeSql( "UPDATE attributevalue SET created=now() WHERE created IS NULL" );
+        executeSql( "UPDATE attributevalue SET lastupdated=now() WHERE lastupdated IS NULL" );
+
         upgradeDataValuesWithAttributeOptionCombo();
         upgradeCompleteDataSetRegistrationsWithAttributeOptionCombo();
         upgradeMapViewsToAnalyticalObject();

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/AttributeValue.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/AttributeValue.hbm.xml	2011-09-21 14:43:36 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/AttributeValue.hbm.xml	2015-01-02 14:06:24 +0000
@@ -12,6 +12,10 @@
       <generator class="native" />
     </id>
 
+    <property name="created" />
+
+    <property name="lastUpdated" />
+
     <property name="value" />
 
     <many-to-one name="attribute" class="org.hisp.dhis.attribute.Attribute" column="attributeid"

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeValueServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeValueServiceTest.java	2014-10-07 13:46:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeValueServiceTest.java	2015-01-02 14:06:24 +0000
@@ -36,7 +36,7 @@
 import org.hisp.dhis.DhisSpringTest;
 
 /**
- * @author mortenoh
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 public class AttributeValueServiceTest
     extends DhisSpringTest