=== 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-31 22:31:59 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/Interpretation.java 2012-08-31 15:35:59 +0000 @@ -38,8 +38,10 @@ 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.dataset.DataSet; import org.hisp.dhis.mapping.MapView; import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.period.Period; import org.hisp.dhis.reporttable.ReportTable; import org.hisp.dhis.user.User; @@ -60,7 +62,11 @@ private ReportTable reportTable; - private OrganisationUnit organisationUnit; // Applicable to report table only + private DataSet dataSet; + + private Period period; // Applicable to data set report + + private OrganisationUnit organisationUnit; // Applicable to report table and data set report private String text; @@ -101,6 +107,15 @@ this.text = text; this.created = new Date(); } + + public Interpretation( DataSet dataSet, Period period, OrganisationUnit organisationUnit, String text ) + { + this.dataSet = dataSet; + this.period = period; + this.organisationUnit = organisationUnit; + this.text = text; + this.created = new Date(); + } // ------------------------------------------------------------------------- // Logic @@ -125,6 +140,11 @@ { return reportTable != null; } + + public boolean isDataSetReportInterpretation() + { + return dataSet != null; + } // ------------------------------------------------------------------------- // Get and set methods @@ -176,6 +196,34 @@ @JsonDeserialize( as = BaseIdentifiableObject.class ) @JsonView( { DetailedView.class, ExportView.class } ) @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE ) + public DataSet getDataSet() + { + return dataSet; + } + + public void setDataSet( DataSet dataSet ) + { + this.dataSet = dataSet; + } + + @JsonProperty + @JsonDeserialize( as = BaseIdentifiableObject.class ) + @JsonView( { DetailedView.class, ExportView.class } ) + @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE ) + public Period getPeriod() + { + return period; + } + + public void setPeriod( Period period ) + { + this.period = period; + } + + @JsonProperty + @JsonDeserialize( as = BaseIdentifiableObject.class ) + @JsonView( { DetailedView.class, ExportView.class } ) + @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE ) public OrganisationUnit getOrganisationUnit() { return organisationUnit; === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/impl/DefaultInterpretationService.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/impl/DefaultInterpretationService.java 2012-05-30 09:51:59 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/impl/DefaultInterpretationService.java 2012-08-31 15:35:59 +0000 @@ -35,6 +35,7 @@ import org.hisp.dhis.interpretation.Interpretation; import org.hisp.dhis.interpretation.InterpretationComment; import org.hisp.dhis.interpretation.InterpretationService; +import org.hisp.dhis.period.PeriodService; import org.hisp.dhis.user.CurrentUserService; import org.hisp.dhis.user.User; import org.hisp.dhis.user.UserService; @@ -71,6 +72,13 @@ { this.userService = userService; } + + private PeriodService periodService; + + public void setPeriodService( PeriodService periodService ) + { + this.periodService = periodService; + } // ------------------------------------------------------------------------- // InterpretationService implementation @@ -85,6 +93,11 @@ interpretation.setUser( user ); } + if ( interpretation != null && interpretation.getPeriod() != null ) + { + interpretation.setPeriod( periodService.reloadPeriod( interpretation.getPeriod() ) ); + } + return interpretationStore.save( interpretation ); } === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml 2012-07-24 07:11:35 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml 2012-08-31 15:35:59 +0000 @@ -249,7 +249,8 @@ - + + === 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-31 22:31:59 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/interpretation/hibernate/Interpretation.hbm.xml 2012-08-31 15:35:59 +0000 @@ -24,6 +24,12 @@ + + + + === 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-06-15 10:19:42 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/InterpretationController.java 2012-08-31 15:35:59 +0000 @@ -38,12 +38,16 @@ import org.hisp.dhis.chart.Chart; import org.hisp.dhis.chart.ChartService; import org.hisp.dhis.common.Pager; +import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.dataset.DataSetService; import org.hisp.dhis.interpretation.Interpretation; import org.hisp.dhis.interpretation.InterpretationService; import org.hisp.dhis.mapping.MapView; import org.hisp.dhis.mapping.MappingService; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.period.PeriodType; import org.hisp.dhis.reporttable.ReportTable; import org.hisp.dhis.reporttable.ReportTableService; import org.springframework.beans.factory.annotation.Autowired; @@ -74,6 +78,9 @@ private ReportTableService reportTableService; @Autowired + private DataSetService dataSetService; + + @Autowired private OrganisationUnitService organisationUnitService; @Autowired @@ -184,7 +191,46 @@ response.setStatus( HttpServletResponse.SC_CREATED ); response.setHeader( "Location", InterpretationController.RESOURCE_PATH + "/" + interpretation.getUid() ); } - + + @RequestMapping( value = "/dataSetReport/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" } ) + public void shareDataSetReportInterpretation( + @PathVariable( "uid" ) String dataSetUid, + @RequestParam( "pe" ) String isoPeriod, + @RequestParam( "ou" ) String orgUnitUid, + @RequestBody String text, HttpServletResponse response ) throws IOException + { + DataSet dataSet = dataSetService.getDataSet( dataSetUid ); + + if ( dataSet == null ) + { + ContextUtils.conflictResponse( response, "Data set identifier not valid: " + dataSetUid ); + return; + } + + Period period = PeriodType.getPeriodFromIsoString( isoPeriod ); + + if ( period == null ) + { + ContextUtils.conflictResponse( response, "Period identifier not valid: " + isoPeriod ); + return; + } + + OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( orgUnitUid ); + + if ( orgUnit == null ) + { + ContextUtils.conflictResponse( response, "Organisation unit identifier not valid: " + orgUnitUid ); + return; + } + + Interpretation interpretation = new Interpretation( dataSet, period, orgUnit, text ); + + interpretationService.saveInterpretation( interpretation ); + + response.setStatus( HttpServletResponse.SC_CREATED ); + response.setHeader( "Location", InterpretationController.RESOURCE_PATH + "/" + interpretation.getUid() ); + } + @RequestMapping( value = "/{uid}/comment", method = RequestMethod.POST, consumes = { "text/html", "text/plain" } ) public void postComment( @PathVariable( "uid" ) String uid,