use of org.hisp.dhis.dxf2.webmessage.WebMessageException 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.dxf2.webmessage.WebMessageException 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);
}
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class SqlViewController method executeView.
// -------------------------------------------------------------------------
// Post
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/execute", method = RequestMethod.POST)
public void executeView(@PathVariable("uid") String uid, @RequestParam(required = false) Set<String> var, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
SqlView sqlView = sqlViewService.getSqlViewByUid(uid);
if (sqlView == null) {
throw new WebMessageException(WebMessageUtils.notFound("SQL view not found"));
}
if (sqlView.isQuery()) {
throw new WebMessageException(WebMessageUtils.conflict("SQL view is a query, no view to create"));
}
String result = sqlViewService.createViewTable(sqlView);
if (result != null) {
throw new WebMessageException(WebMessageUtils.conflict(result));
} else {
response.addHeader("Location", SqlViewSchemaDescriptor.API_ENDPOINT + "/" + sqlView.getUid());
webMessageService.send(WebMessageUtils.created("SQL view created"), response, request);
}
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class DataValueController method deleteDataValue.
// ---------------------------------------------------------------------
// DELETE
// ---------------------------------------------------------------------
@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_DELETE')")
@RequestMapping(method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteDataValue(@RequestParam String de, @RequestParam(required = false) String co, @RequestParam(required = false) String cc, @RequestParam(required = false) String cp, @RequestParam String pe, @RequestParam String ou, HttpServletResponse response) throws WebMessageException {
// ---------------------------------------------------------------------
// Input validation
// ---------------------------------------------------------------------
DataElement dataElement = getAndValidateDataElement(de);
DataElementCategoryOptionCombo categoryOptionCombo = getAndValidateCategoryOptionCombo(co, false);
DataElementCategoryOptionCombo attributeOptionCombo = getAndValidateAttributeOptionCombo(cc, cp);
Period period = getAndValidatePeriod(pe);
OrganisationUnit organisationUnit = getAndValidateOrganisationUnit(ou);
// ---------------------------------------------------------------------
// Locking validation
// ---------------------------------------------------------------------
validateDataSetNotLocked(dataElement, period, organisationUnit, attributeOptionCombo);
// ---------------------------------------------------------------------
// Period validation
// ---------------------------------------------------------------------
validateDataInputPeriodForDataElementAndPeriod(dataElement, period);
// ---------------------------------------------------------------------
// Delete data value
// ---------------------------------------------------------------------
DataValue dataValue = dataValueService.getDataValue(dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo);
if (dataValue == null) {
throw new WebMessageException(WebMessageUtils.conflict("Data value cannot be deleted because it does not exist"));
}
dataValueService.deleteDataValue(dataValue);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class DataValueController method getDataValue.
// ---------------------------------------------------------------------
// GET
// ---------------------------------------------------------------------
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public List<String> getDataValue(@RequestParam String de, @RequestParam(required = false) String co, @RequestParam(required = false) String cc, @RequestParam(required = false) String cp, @RequestParam String pe, @RequestParam String ou, Model model, HttpServletResponse response) throws WebMessageException {
// ---------------------------------------------------------------------
// Input validation
// ---------------------------------------------------------------------
DataElement dataElement = getAndValidateDataElement(de);
DataElementCategoryOptionCombo categoryOptionCombo = getAndValidateCategoryOptionCombo(co, false);
DataElementCategoryOptionCombo attributeOptionCombo = getAndValidateAttributeOptionCombo(cc, cp);
Period period = getAndValidatePeriod(pe);
OrganisationUnit organisationUnit = getAndValidateOrganisationUnit(ou);
// ---------------------------------------------------------------------
// Get data value
// ---------------------------------------------------------------------
DataValue dataValue = dataValueService.getDataValue(dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo);
if (dataValue == null) {
throw new WebMessageException(WebMessageUtils.conflict("Data value does not exist"));
}
List<String> value = new ArrayList<>();
value.add(dataValue.getValue());
return value;
}
Aggregations