dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21111
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9911: Web API, impl POST of report table
------------------------------------------------------------
revno: 9911
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-02-26 21:18:51 +0100
message:
Web API, impl POST of report table
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.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/dataelement/DataElementService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2013-01-11 13:12:31 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2013-02-26 20:18:51 +0000
@@ -347,7 +347,7 @@
* @param uids the uid collection.
* @return the data element groups with the given uids.
*/
- Collection<DataElementGroup> getDataElementGroupsByUid( Collection<String> uids );
+ List<DataElementGroup> getDataElementGroupsByUid( Collection<String> uids );
/**
* Returns the DataElementGroup with the given UID.
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2013-02-04 04:14:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2013-02-26 20:18:51 +0000
@@ -413,7 +413,7 @@
} );
}
- public Collection<DataElementGroup> getDataElementGroupsByUid( Collection<String> uids )
+ public List<DataElementGroup> getDataElementGroupsByUid( Collection<String> uids )
{
return dataElementGroupStore.getByUid( uids );
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java 2013-02-26 17:45:20 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java 2013-02-26 20:18:51 +0000
@@ -27,6 +27,18 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
+import static org.hisp.dhis.system.util.CodecUtils.filenameEncode;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.hisp.dhis.api.utils.ContextUtils;
import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
import org.hisp.dhis.common.Grid;
@@ -34,17 +46,21 @@
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.dxf2.utils.JacksonUtils;
import org.hisp.dhis.i18n.I18nManager;
import org.hisp.dhis.indicator.Indicator;
import org.hisp.dhis.indicator.IndicatorService;
import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.Cal;
+import org.hisp.dhis.period.PeriodService;
import org.hisp.dhis.period.RelativePeriods;
import org.hisp.dhis.reporttable.ReportTable;
import org.hisp.dhis.reporttable.ReportTableService;
import org.hisp.dhis.system.grid.GridUtils;
import org.hisp.dhis.system.util.DateUtils;
+import org.hisp.dhis.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@@ -53,14 +69,6 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
-import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-
-import static org.hisp.dhis.system.util.CodecUtils.filenameEncode;
-
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
* @author Lars Helge Overland
@@ -79,6 +87,9 @@
@Autowired
private OrganisationUnitService organisationUnitService;
+
+ @Autowired
+ private OrganisationUnitGroupService organisationUnitGroupService;
@Autowired
private IndicatorService indicatorService;
@@ -90,12 +101,42 @@
private DataSetService dataSetService;
@Autowired
+ private PeriodService periodService;
+
+ @Autowired
+ private UserService userService;
+
+ @Autowired
private I18nManager i18nManager;
@Autowired
private ContextUtils contextUtils;
//--------------------------------------------------------------------------
+ // CRUD
+ //--------------------------------------------------------------------------
+
+ @RequestMapping( method = RequestMethod.POST, consumes = "application/json" )
+ public void postJsonObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
+ {
+ ReportTable reportTable = JacksonUtils.fromJson( input, ReportTable.class );
+
+ reportTable.readPresentationProps();
+
+ mergeReportTable( reportTable );
+
+ reportTableService.saveReportTable( reportTable );
+
+ ContextUtils.createdResponse( response, "Report table created", RESOURCE_PATH + "/" + reportTable.getUid() );
+ }
+
+ @Override
+ protected void postProcessEntity( ReportTable reportTable )
+ {
+ reportTable.populatePresentationProps();
+ }
+
+ //--------------------------------------------------------------------------
// GET - Dynamic data
//--------------------------------------------------------------------------
@@ -368,4 +409,26 @@
return reportTableService.getReportTableGrid( uid, i18nManager.getI18nFormat(), date, organisationUnitUid );
}
+
+ //--------------------------------------------------------------------------
+ // Supportive methods
+ //--------------------------------------------------------------------------
+
+ // TODO use generic import service
+
+ private void mergeReportTable( ReportTable reportTable )
+ {
+ reportTable.setDataElements( dataElementService.getDataElementsByUid( getUids( reportTable.getDataElements() ) ) );
+ reportTable.setIndicators( indicatorService.getIndicatorsByUid( getUids( reportTable.getIndicators() ) ) );
+ reportTable.setDataSets( dataSetService.getDataSetsByUid( getUids( reportTable.getDataSets() ) ) );
+ reportTable.setOrganisationUnits( organisationUnitService.getOrganisationUnitsByUid( getUids( reportTable.getOrganisationUnits() ) ) );
+ reportTable.setPeriods( periodService.reloadPeriods( reportTable.getPeriods() ) );
+ reportTable.setDataElementGroups( dataElementService.getDataElementGroupsByUid( getUids( reportTable.getDataElementGroups() ) ) );
+ reportTable.setOrganisationUnitGroups( organisationUnitGroupService.getOrganisationUnitGroupsByUid( getUids( reportTable.getOrganisationUnitGroups() ) ) );
+
+ if ( reportTable.getUser() != null )
+ {
+ reportTable.setUser( userService.getUser( reportTable.getUser().getUid() ) );
+ }
+ }
}