← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7122: Implemented post of interpretation in web api

 

------------------------------------------------------------
revno: 7122
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-05-31 20:16:45 +0200
message:
  Implemented post of interpretation in web api
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/Interpretation.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/interpretation/hibernate/Interpretation.hbm.xml
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.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-30 11:35:01 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/Interpretation.java	2012-05-31 18:16:45 +0000
@@ -38,6 +38,7 @@
 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.reporttable.ReportTable;
 import org.hisp.dhis.user.User;
 
 import java.util.ArrayList;
@@ -53,6 +54,8 @@
 {
     private Chart chart;
 
+    private ReportTable reportTable;
+    
     private String text;
 
     private User user;
@@ -78,6 +81,13 @@
         this.created = new Date();
     }
 
+    public Interpretation( ReportTable reportTable, String text )
+    {
+        this.reportTable = reportTable;
+        this.text = text;
+        this.created = new Date();
+    }
+
     // -------------------------------------------------------------------------
     // Logic
     // -------------------------------------------------------------------------
@@ -106,6 +116,20 @@
     }
 
     @JsonProperty
+    @JsonDeserialize( as = BaseIdentifiableObject.class )
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
+    public ReportTable getReportTable()
+    {
+        return reportTable;
+    }
+
+    public void setReportTable( ReportTable reportTable )
+    {
+        this.reportTable = reportTable;
+    }
+
+    @JsonProperty
     @JsonView( { DetailedView.class, ExportView.class } )
     @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
     public String getText()

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/interpretation/hibernate/Interpretation.hbm.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/interpretation/hibernate/Interpretation.hbm.xml	2012-05-29 20:06:58 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/interpretation/hibernate/Interpretation.hbm.xml	2012-05-31 18:16:45 +0000
@@ -15,11 +15,14 @@
     <property name="uid" column="uid" length="11" />
     <property name="lastUpdated" type="timestamp"/>
 	
+    <many-to-one name="chart" class="org.hisp.dhis.chart.Chart" column="chartid"
+        foreign-key="fk_interpretation_chartid" />
+
+	<many-to-one name="reportTable" class="org.hisp.dhis.reporttable.ReportTable" column="reporttableid"
+		foreign-key="fk_interpretation_reporttableid" />
+		
     <property name="text" column="interpretationtext" type="text" />
-
-    <many-to-one name="chart" class="org.hisp.dhis.chart.Chart" column="chartid"
-        foreign-key="fk_interpretation_chartid" not-null="true" />
-
+			
     <many-to-one name="user" class="org.hisp.dhis.user.User" column="userid"
 		foreign-key="fk_interpretation_userid" not-null="true" />
 	

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java	2012-05-31 17:02:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java	2012-05-31 18:16:45 +0000
@@ -55,16 +55,16 @@
  */
 public abstract class AbstractCrudController<T extends IdentifiableObject>
 {
-    //-------------------------------------------------------------------------------------------------------
+    //--------------------------------------------------------------------------
     // Dependencies
-    //-------------------------------------------------------------------------------------------------------
+    //--------------------------------------------------------------------------
 
     @Autowired
     protected IdentifiableObjectManager manager;
 
-    //-------------------------------------------------------------------------------------------------------
+    //--------------------------------------------------------------------------
     // GET
-    //-------------------------------------------------------------------------------------------------------
+    //--------------------------------------------------------------------------
 
     @RequestMapping( method = RequestMethod.GET )
     public String getObjectList( @RequestParam Map<String, String> parameters, Model model, HttpServletRequest request ) throws Exception
@@ -103,9 +103,9 @@
         return StringUtils.uncapitalize( getEntitySimpleName() );
     }
 
-    //-------------------------------------------------------------------------------------------------------
+    //--------------------------------------------------------------------------
     // POST
-    //-------------------------------------------------------------------------------------------------------
+    //--------------------------------------------------------------------------
 
     @RequestMapping( method = RequestMethod.POST, headers = { "Content-Type=application/xml, text/xml" } )
     public void postXmlObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
@@ -119,9 +119,9 @@
         throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() );
     }
 
-    //-------------------------------------------------------------------------------------------------------
+    //--------------------------------------------------------------------------
     // PUT
-    //-------------------------------------------------------------------------------------------------------
+    //--------------------------------------------------------------------------
 
     @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, headers = { "Content-Type=application/xml, text/xml" } )
     @ResponseStatus( value = HttpStatus.NO_CONTENT )
@@ -137,9 +137,9 @@
         throw new HttpRequestMethodNotSupportedException( RequestMethod.PUT.toString() );
     }
 
-    //-------------------------------------------------------------------------------------------------------
+    //--------------------------------------------------------------------------
     // DELETE
-    //-------------------------------------------------------------------------------------------------------
+    //--------------------------------------------------------------------------
 
     @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE )
     @ResponseStatus( value = HttpStatus.NO_CONTENT )
@@ -148,9 +148,9 @@
         throw new HttpRequestMethodNotSupportedException( RequestMethod.DELETE.toString() );
     }
 
-    //-------------------------------------------------------------------------------------------------------
+    //--------------------------------------------------------------------------
     // Helpers
-    //-------------------------------------------------------------------------------------------------------
+    //--------------------------------------------------------------------------
 
     protected List<T> getEntityList( WebMetaData metaData, WebOptions options )
     {
@@ -184,9 +184,9 @@
         return manager.get( getEntityClass(), uid );
     }
 
-    //-------------------------------------------------------------------------------------------------------
+    //--------------------------------------------------------------------------
     // Reflection helpers
-    //-------------------------------------------------------------------------------------------------------
+    //--------------------------------------------------------------------------
 
     private Class<T> entityClass;
 

=== 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-30 11:35:01 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/InterpretationController.java	2012-05-31 18:16:45 +0000
@@ -28,9 +28,13 @@
  */
 
 import org.hisp.dhis.api.utils.ContextUtils;
+import org.hisp.dhis.chart.Chart;
+import org.hisp.dhis.chart.ChartService;
 import org.hisp.dhis.common.Pager;
 import org.hisp.dhis.interpretation.Interpretation;
 import org.hisp.dhis.interpretation.InterpretationService;
+import org.hisp.dhis.reporttable.ReportTable;
+import org.hisp.dhis.reporttable.ReportTableService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.PathVariable;
@@ -57,6 +61,12 @@
     @Autowired
     private InterpretationService interpretationService;
 
+    @Autowired
+    private ChartService chartService;
+    
+    @Autowired
+    private ReportTableService reportTableService;
+    
     @Override
     protected List<Interpretation> getEntityList( WebMetaData metaData, WebOptions options )
     {
@@ -86,11 +96,46 @@
         return entityList;
     }
 
-    @RequestMapping( value = "/{uid}/comment", method = RequestMethod.POST )
+    @RequestMapping( value = "/chart/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" } )
+    public void shareChartInterpretation( @PathVariable( "uid" ) String chartUid, @RequestBody String text, HttpServletResponse response ) throws IOException
+    {
+        Chart chart = chartService.getChart( chartUid );
+        
+        if ( chart == null )
+        {
+            ContextUtils.conflictResponse( response, "Chart identifier not valid" );
+        }
+        
+        Interpretation interpretation = new Interpretation( chart, text );
+        
+        interpretationService.saveInterpretation( interpretation );
+        
+        ContextUtils.okResponse( response, "Chart interpretation created" );
+    }
+
+    @RequestMapping( value = "/reportTable/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" } )
+    public void shareReportTableInterpretation( @PathVariable( "uid" ) String reportTableUid, @RequestBody String text, HttpServletResponse response ) throws IOException
+    {
+        ReportTable reportTable = reportTableService.getReportTable( reportTableUid );
+        
+        if ( reportTable == null )
+        {
+            ContextUtils.conflictResponse( response, "Report table identifier not valid" );
+        }
+        
+        Interpretation interpretation = new Interpretation( reportTable, text );
+        
+        interpretationService.saveInterpretation( interpretation );
+        
+        ContextUtils.okResponse( response, "Report table interpretation created" );
+    }
+    
+    @RequestMapping( value = "/{uid}/comment", method = RequestMethod.POST, consumes = { "text/html", "text/plain" } )
     public void postComment( @PathVariable( "uid" ) String uid, @RequestBody String text, HttpServletResponse response ) throws IOException
     {
         interpretationService.addInterpretationComment( uid, text );
 
         ContextUtils.okResponse( response, "Comment created" );
     }
+    
 }