← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7107: wip, interpretationcontroller

 

------------------------------------------------------------
revno: 7107
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-05-30 13:35:01 +0200
message:
  wip, interpretationcontroller
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/Interpretation.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/InterpretationComment.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/InterpretationController.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/interpretation/Interpretation.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/Interpretation.java	2012-05-29 19:08:34 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/Interpretation.java	2012-05-30 11:35:01 +0000
@@ -27,28 +27,39 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonView;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.chart.Chart;
+import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.common.Dxf2Namespace;
+import org.hisp.dhis.common.annotation.Scanned;
+import org.hisp.dhis.common.view.DetailedView;
+import org.hisp.dhis.common.view.ExportView;
+import org.hisp.dhis.user.User;
+
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
-import org.hisp.dhis.chart.Chart;
-import org.hisp.dhis.common.BaseIdentifiableObject;
-import org.hisp.dhis.user.User;
-
 /**
  * @author Lars Helge Overland
  */
+@JacksonXmlRootElement( localName = "interpretation", namespace = Dxf2Namespace.NAMESPACE )
 public class Interpretation
     extends BaseIdentifiableObject
 {
     private Chart chart;
-    
+
     private String text;
 
     private User user;
-    
+
     private Date created;
-    
+
+    @Scanned
     private List<InterpretationComment> comments = new ArrayList<InterpretationComment>();
 
     // -------------------------------------------------------------------------
@@ -75,11 +86,15 @@
     {
         this.comments.add( comment );
     }
-    
+
     // -------------------------------------------------------------------------
     // Get and set methods
     // -------------------------------------------------------------------------
 
+    @JsonProperty
+    @JsonDeserialize( as = BaseIdentifiableObject.class )
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
     public Chart getChart()
     {
         return chart;
@@ -90,6 +105,9 @@
         this.chart = chart;
     }
 
+    @JsonProperty
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
     public String getText()
     {
         return text;
@@ -100,6 +118,10 @@
         this.text = text;
     }
 
+    @JsonProperty
+    @JsonDeserialize( as = BaseIdentifiableObject.class )
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
     public User getUser()
     {
         return user;
@@ -110,6 +132,9 @@
         this.user = user;
     }
 
+    @JsonProperty
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
     public Date getCreated()
     {
         return created;
@@ -120,6 +145,10 @@
         this.created = created;
     }
 
+    @JsonProperty
+    @JsonDeserialize( contentAs = BaseIdentifiableObject.class )
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
     public List<InterpretationComment> getComments()
     {
         return comments;

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/InterpretationComment.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/InterpretationComment.java	2012-05-29 19:08:34 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/InterpretationComment.java	2012-05-30 11:35:01 +0000
@@ -27,34 +27,46 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.Date;
-
+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.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
 import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.common.Dxf2Namespace;
+import org.hisp.dhis.common.view.DetailedView;
+import org.hisp.dhis.common.view.ExportView;
 import org.hisp.dhis.user.User;
 
+import java.util.Date;
+
 /**
  * @author Lars Helge Overland
  */
+@JacksonXmlRootElement( localName = "interpretationComment", namespace = Dxf2Namespace.NAMESPACE )
 public class InterpretationComment
     extends BaseIdentifiableObject
 {
     private String text;
-    
+
     private User user;
-    
+
     private Date created;
-    
+
     public InterpretationComment()
     {
         this.created = new Date();
     }
-    
+
     public InterpretationComment( String text )
     {
         this.text = text;
         this.created = new Date();
     }
 
+    @JsonProperty
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
     public String getText()
     {
         return text;
@@ -65,6 +77,10 @@
         this.text = text;
     }
 
+    @JsonProperty
+    @JsonSerialize( as = BaseIdentifiableObject.class )
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
     public User getUser()
     {
         return user;
@@ -75,6 +91,9 @@
         this.user = user;
     }
 
+    @JsonProperty
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
     public Date getCreated()
     {
         return created;

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java	2012-05-30 10:54:11 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java	2012-05-30 11:35:01 +0000
@@ -41,6 +41,7 @@
 import org.hisp.dhis.indicator.IndicatorGroup;
 import org.hisp.dhis.indicator.IndicatorGroupSet;
 import org.hisp.dhis.indicator.IndicatorType;
+import org.hisp.dhis.interpretation.Interpretation;
 import org.hisp.dhis.mapping.MapLayer;
 import org.hisp.dhis.mapping.MapLegend;
 import org.hisp.dhis.mapping.MapLegendSet;
@@ -123,6 +124,7 @@
         exportClasses.put( UserAuthorityGroup.class, "userRoles" );
 
         exportClasses.put( MessageConversation.class, "messageConversations" );
+        exportClasses.put( Interpretation.class, "interpretations" );
 
         importClasses = exportClasses;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/InterpretationController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/InterpretationController.java	2012-05-29 19:08:34 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/InterpretationController.java	2012-05-30 11:35:01 +0000
@@ -27,11 +27,9 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.io.IOException;
-
-import javax.servlet.http.HttpServletResponse;
-
 import org.hisp.dhis.api.utils.ContextUtils;
+import org.hisp.dhis.common.Pager;
+import org.hisp.dhis.interpretation.Interpretation;
 import org.hisp.dhis.interpretation.InterpretationService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
@@ -40,23 +38,59 @@
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
 /**
  * @author Lars Helge Overland
  */
 @Controller
 @RequestMapping( value = InterpretationController.RESOURCE_PATH )
 public class InterpretationController
+    extends AbstractCrudController<Interpretation>
 {
     public static final String RESOURCE_PATH = "/interpretations";
-    
+
     @Autowired
     private InterpretationService interpretationService;
-    
+
+    @Override
+    protected List<Interpretation> getEntityList( WebMetaData metaData, WebOptions options )
+    {
+        List<Interpretation> entityList;
+
+        Date lastUpdated = options.getLastUpdated();
+
+        if ( lastUpdated != null )
+        {
+            entityList = new ArrayList<Interpretation>( manager.getByLastUpdated( getEntityClass(), lastUpdated ) );
+        }
+        else if ( options.hasPaging() )
+        {
+            int count = manager.getCount( getEntityClass() );
+
+            Pager pager = new Pager( options.getPage(), count );
+            metaData.setPager( pager );
+
+            entityList = new ArrayList<Interpretation>( interpretationService.getInterpretations( pager.getOffset(), pager.getPageSize() ) );
+
+        }
+        else
+        {
+            entityList = new ArrayList<Interpretation>( manager.getAll( getEntityClass() ) );
+        }
+
+        return entityList;
+    }
+
     @RequestMapping( value = "/{uid}/comment", method = RequestMethod.POST )
     public void postComment( @PathVariable( "uid" ) String uid, @RequestBody String text, HttpServletResponse response ) throws IOException
     {
         interpretationService.addInterpretationComment( uid, text );
-        
-        ContextUtils.okResponse( response, "Comment created" );        
+
+        ContextUtils.okResponse( response, "Comment created" );
     }
 }