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());
}
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());
}
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;
}
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());
}
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);
}
}
Aggregations