Search in sources :

Example 11 with SqlView

use of org.hisp.dhis.sqlview.SqlView in project dhis2-core by dhis2.

the class SqlViewController method getViewPdf.

@RequestMapping(value = "/{uid}/data.pdf", method = RequestMethod.GET)
public void getViewPdf(@PathVariable("uid") String uid, @RequestParam(required = false) Set<String> criteria, @RequestParam(required = false) Set<String> var, HttpServletResponse response) throws Exception {
    SqlView sqlView = sqlViewService.getSqlViewByUid(uid);
    if (sqlView == null) {
        throw new WebMessageException(WebMessageUtils.notFound("SQL view does not exist: " + uid));
    }
    List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    Grid grid = sqlViewService.getSqlViewGrid(sqlView, SqlView.getCriteria(criteria), SqlView.getCriteria(var), filters, fields);
    contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_PDF, sqlView.getCacheStrategy());
    GridUtils.toPdf(grid, response.getOutputStream());
}
Also used : SqlView(org.hisp.dhis.sqlview.SqlView) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Grid(org.hisp.dhis.common.Grid) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with SqlView

use of org.hisp.dhis.sqlview.SqlView in project dhis2-core by dhis2.

the class SqlViewController method getViewXml.

@RequestMapping(value = "/{uid}/data.xml", method = RequestMethod.GET)
public void getViewXml(@PathVariable("uid") String uid, @RequestParam(required = false) Set<String> criteria, @RequestParam(required = false) Set<String> var, HttpServletResponse response) throws WebMessageException, IOException {
    SqlView sqlView = sqlViewService.getSqlViewByUid(uid);
    if (sqlView == null) {
        throw new WebMessageException(WebMessageUtils.notFound("SQL view does not exist: " + uid));
    }
    List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    Grid grid = sqlViewService.getSqlViewGrid(sqlView, SqlView.getCriteria(criteria), SqlView.getCriteria(var), filters, fields);
    contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_XML, sqlView.getCacheStrategy());
    GridUtils.toXml(grid, response.getOutputStream());
}
Also used : SqlView(org.hisp.dhis.sqlview.SqlView) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Grid(org.hisp.dhis.common.Grid) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with SqlView

use of org.hisp.dhis.sqlview.SqlView in project dhis2-core by dhis2.

the class SqlViewController method getViewJson.

// -------------------------------------------------------------------------
// Get
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/data", method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public Grid getViewJson(@PathVariable("uid") String uid, @RequestParam(required = false) Set<String> criteria, @RequestParam(required = false) Set<String> var, HttpServletResponse response) throws WebMessageException {
    SqlView sqlView = sqlViewService.getSqlViewByUid(uid);
    if (sqlView == null) {
        throw new WebMessageException(WebMessageUtils.notFound("SQL view does not exist: " + uid));
    }
    List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    Grid grid = sqlViewService.getSqlViewGrid(sqlView, SqlView.getCriteria(criteria), SqlView.getCriteria(var), filters, fields);
    contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_JSON, sqlView.getCacheStrategy());
    return grid;
}
Also used : SqlView(org.hisp.dhis.sqlview.SqlView) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Grid(org.hisp.dhis.common.Grid) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 14 with SqlView

use of org.hisp.dhis.sqlview.SqlView in project dhis2-core by dhis2.

the class SqlViewController method getViewCsv.

@RequestMapping(value = "/{uid}/data.csv", method = RequestMethod.GET)
public void getViewCsv(@PathVariable("uid") String uid, @RequestParam(required = false) Set<String> criteria, @RequestParam(required = false) Set<String> var, HttpServletResponse response) throws Exception {
    SqlView sqlView = sqlViewService.getSqlViewByUid(uid);
    if (sqlView == null) {
        throw new WebMessageException(WebMessageUtils.notFound("SQL view does not exist: " + uid));
    }
    List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    Grid grid = sqlViewService.getSqlViewGrid(sqlView, SqlView.getCriteria(criteria), SqlView.getCriteria(var), filters, fields);
    String filename = CodecUtils.filenameEncode(grid.getTitle()) + ".csv";
    contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_CSV, sqlView.getCacheStrategy(), filename, true);
    GridUtils.toCsv(grid, response.getWriter());
}
Also used : SqlView(org.hisp.dhis.sqlview.SqlView) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Grid(org.hisp.dhis.common.Grid) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with SqlView

use of org.hisp.dhis.sqlview.SqlView in project dhis2-core by dhis2.

the class SqlViewController method refreshMaterializedView.

@RequestMapping(value = "/{uid}/refresh", method = RequestMethod.POST)
public void refreshMaterializedView(@PathVariable("uid") String uid, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
    SqlView sqlView = sqlViewService.getSqlViewByUid(uid);
    if (sqlView == null) {
        throw new WebMessageException(WebMessageUtils.notFound("SQL view not found"));
    }
    boolean result = sqlViewService.refreshMaterializedView(sqlView);
    if (!result) {
        throw new WebMessageException(WebMessageUtils.conflict("View could not be refreshed"));
    } else {
        webMessageService.send(WebMessageUtils.ok("Materialized view refreshed"), response, request);
    }
}
Also used : SqlView(org.hisp.dhis.sqlview.SqlView) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SqlView (org.hisp.dhis.sqlview.SqlView)18 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 Grid (org.hisp.dhis.common.Grid)7 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)3 ArrayList (java.util.ArrayList)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1