use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class UserSettingController method getUserSetting.
@RequestMapping(value = "/{key}", method = RequestMethod.GET)
@ResponseBody
public String getUserSetting(@PathVariable("key") String key, @RequestParam(value = "user", required = false) String username, HttpServletRequest request, HttpServletResponse response) throws IOException, WebMessageException {
Optional<UserSettingKey> keyEnum = UserSettingKey.getByName(key);
if (!keyEnum.isPresent()) {
throw new WebMessageException(WebMessageUtils.conflict("Key is not supported: " + key));
}
User user = null;
if (username != null) {
UserCredentials credentials = userService.getUserCredentialsByUsername(username);
if (credentials != null) {
user = credentials.getUserInfo();
} else {
throw new WebMessageException(WebMessageUtils.conflict("User does not exist: " + username));
}
}
Serializable value = userSettingService.getUserSetting(keyEnum.get(), user);
if (value == null) {
throw new WebMessageException(WebMessageUtils.notFound("User setting not found for key: " + key));
}
return String.valueOf(value);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class DataElementGroupController method getOperands.
@RequestMapping(value = "/{uid}/operands", method = RequestMethod.GET)
public String getOperands(@PathVariable("uid") String uid, @RequestParam Map<String, String> parameters, Model model, TranslateParams translateParams, HttpServletRequest request, HttpServletResponse response) throws Exception {
WebOptions options = new WebOptions(parameters);
setUserContext(translateParams);
List<DataElementGroup> dataElementGroups = getEntity(uid, NO_WEB_OPTIONS);
if (dataElementGroups.isEmpty()) {
throw new WebMessageException(WebMessageUtils.notFound("DataElementGroup not found for uid: " + uid));
}
WebMetadata metadata = new WebMetadata();
List<DataElementOperand> dataElementOperands = Lists.newArrayList(dataElementCategoryService.getOperands(dataElementGroups.get(0).getMembers()));
Collections.sort(dataElementOperands);
metadata.setDataElementOperands(dataElementOperands);
if (options.hasPaging()) {
Pager pager = new Pager(options.getPage(), dataElementOperands.size(), options.getPageSize());
metadata.setPager(pager);
dataElementOperands = PagerUtils.pageCollection(dataElementOperands, pager);
}
metadata.setDataElementOperands(dataElementOperands);
linkService.generateLinks(metadata, false);
model.addAttribute("model", metadata);
model.addAttribute("viewClass", options.getViewClass("basic"));
return StringUtils.uncapitalize(getEntitySimpleName());
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class MapController method getMapData.
//--------------------------------------------------------------------------
// Get data
//--------------------------------------------------------------------------
@RequestMapping(value = { "/{uid}/data", "/{uid}/data.png" }, method = RequestMethod.GET)
public void getMapData(@PathVariable String uid, @RequestParam(value = "date", required = false) Date date, @RequestParam(value = "ou", required = false) String ou, @RequestParam(required = false) Integer width, @RequestParam(required = false) Integer height, @RequestParam(value = "attachment", required = false) boolean attachment, HttpServletResponse response) throws Exception {
Map map = mappingService.getMapNoAcl(uid);
if (map == null) {
throw new WebMessageException(WebMessageUtils.notFound("Map does not exist: " + uid));
}
if (width != null && width < MAP_MIN_WIDTH) {
throw new WebMessageException(WebMessageUtils.conflict("Min map width is " + MAP_MIN_WIDTH + ": " + width));
}
if (height != null && height < MAP_MIN_HEIGHT) {
throw new WebMessageException(WebMessageUtils.conflict("Min map height is " + MAP_MIN_HEIGHT + ": " + height));
}
OrganisationUnit unit = ou != null ? organisationUnitService.getOrganisationUnit(ou) : null;
renderMapViewPng(map, date, unit, width, height, attachment, response);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class ProgramMessageController method getProgramMessages.
// -------------------------------------------------------------------------
// GET
// -------------------------------------------------------------------------
@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public void getProgramMessages(@RequestParam(required = false) Set<String> ou, @RequestParam(required = false) String programInstance, @RequestParam(required = false) String programStageInstance, @RequestParam(required = false) ProgramMessageStatus messageStatus, @RequestParam(required = false) Date afterDate, @RequestParam(required = false) Date beforeDate, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize, HttpServletRequest request, HttpServletResponse response) throws IOException, WebMessageException {
ProgramMessageQueryParams params = programMessageService.getFromUrl(ou, programInstance, programStageInstance, messageStatus, page, pageSize, afterDate, beforeDate);
if (programInstance == null && programStageInstance == null) {
throw new WebMessageException(WebMessageUtils.conflict("ProgramInstance or ProgramStageInstance must be specified."));
}
List<ProgramMessage> programMessages = programMessageService.getProgramMessages(params);
renderService.toJson(response.getOutputStream(), programMessages);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class EnrollmentController method deleteEnrollment.
// -------------------------------------------------------------------------
// DELETE
// -------------------------------------------------------------------------
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
@PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_UNENROLLMENT')")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteEnrollment(@PathVariable String id, HttpServletRequest request, HttpServletResponse response) throws WebMessageException {
if (!programInstanceService.programInstanceExists(id)) {
throw new WebMessageException(WebMessageUtils.notFound("Enrollment not found for ID " + id));
}
response.setStatus(HttpServletResponse.SC_OK);
ImportSummary importSummary = enrollmentService.deleteEnrollment(id);
webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
Aggregations