use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class AppController method installApp.
@RequestMapping(method = RequestMethod.POST)
@PreAuthorize("hasRole('ALL') or hasRole('M_dhis-web-app-management')")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void installApp(@RequestParam("file") MultipartFile file) throws IOException, WebMessageException {
File tempFile = File.createTempFile("IMPORT_", "_ZIP");
file.transferTo(tempFile);
AppStatus status = appManager.installApp(tempFile, file.getOriginalFilename());
if (!status.ok()) {
String message = i18nManager.getI18n().getString(status.getMessage());
throw new WebMessageException(WebMessageUtils.conflict(message));
}
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class AbstractCrudController method putXmlObject.
@RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE })
public void putXmlObject(@PathVariable("uid") String pvUid, HttpServletRequest request, HttpServletResponse response) throws Exception {
List<T> objects = getEntity(pvUid);
if (objects.isEmpty()) {
throw new WebMessageException(WebMessageUtils.notFound(getEntityClass(), pvUid));
}
User user = currentUserService.getCurrentUser();
if (!aclService.canUpdate(user, objects.get(0))) {
throw new UpdateAccessDeniedException("You don't have the proper permissions to update this object.");
}
T parsed = deserializeXmlEntity(request, response);
((BaseIdentifiableObject) parsed).setUid(pvUid);
preUpdateEntity(objects.get(0), parsed);
MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap()).setImportReportMode(ImportReportMode.FULL).setUser(user).setImportStrategy(ImportStrategy.UPDATE).addObject(parsed);
ImportReport importReport = importService.importMetadata(params);
WebMessage webMessage = WebMessageUtils.objectReport(importReport);
if (importReport.getStatus() == Status.OK) {
T entity = manager.get(getEntityClass(), pvUid);
postUpdateEntity(entity);
} else {
webMessage.setStatus(Status.ERROR);
}
webMessageService.send(webMessage, response, request);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class UserRoleController method addUserToRole.
@RequestMapping(value = "/{id}/users/{userId}", method = { RequestMethod.POST, RequestMethod.PUT })
@ResponseStatus(HttpStatus.NO_CONTENT)
public void addUserToRole(@PathVariable(value = "id") String pvId, @PathVariable("userId") String pvUserId, HttpServletResponse response) throws WebMessageException {
UserAuthorityGroup userAuthorityGroup = userService.getUserAuthorityGroup(pvId);
if (userAuthorityGroup == null) {
throw new WebMessageException(WebMessageUtils.notFound("UserRole does not exist: " + pvId));
}
User user = userService.getUser(pvUserId);
if (user == null) {
throw new WebMessageException(WebMessageUtils.notFound("User does not exist: " + pvId));
}
if (!aclService.canUpdate(currentUserService.getCurrentUser(), userAuthorityGroup)) {
throw new UpdateAccessDeniedException("You don't have the proper permissions to update this object.");
}
if (!user.getUserCredentials().getUserAuthorityGroups().contains(userAuthorityGroup)) {
user.getUserCredentials().getUserAuthorityGroups().add(userAuthorityGroup);
userService.updateUserCredentials(user.getUserCredentials());
}
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class ValidationController method validate.
@RequestMapping(value = "/dataSet/{ds}", method = RequestMethod.GET)
@ResponseBody
public ValidationSummary validate(@PathVariable String ds, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) String aoc, HttpServletResponse response, Model model) throws WebMessageException {
DataSet dataSet = dataSetService.getDataSet(ds);
if (dataSet == null) {
throw new WebMessageException(WebMessageUtils.conflict("Data set does not exist: " + ds));
}
Period period = PeriodType.getPeriodFromIsoString(pe);
if (period == null) {
throw new WebMessageException(WebMessageUtils.conflict("Period does not exist: " + pe));
}
OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(ou);
if (orgUnit == null) {
throw new WebMessageException(WebMessageUtils.conflict("Organisation unit does not exist: " + ou));
}
DataElementCategoryOptionCombo attributeOptionCombo = categoryService.getDataElementCategoryOptionCombo(aoc);
if (attributeOptionCombo == null) {
attributeOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
}
ValidationSummary summary = new ValidationSummary();
summary.setValidationRuleViolations(new ArrayList<>(validationService.startInteractiveValidationAnalysis(dataSet, period, orgUnit, attributeOptionCombo)));
summary.setCommentRequiredViolations(validationService.validateRequiredComments(dataSet, period, orgUnit, attributeOptionCombo));
return summary;
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class MeController method verifyPasswordInternal.
//------------------------------------------------------------------------------------------------
// Supportive methods
//------------------------------------------------------------------------------------------------
private RootNode verifyPasswordInternal(String password, User currentUser) throws WebMessageException {
if (password == null) {
throw new WebMessageException(WebMessageUtils.conflict("Required attribute 'password' missing or null."));
}
boolean valid = passwordManager.matches(password, currentUser.getUserCredentials().getPassword());
RootNode rootNode = NodeUtils.createRootNode("response");
rootNode.addChild(new SimpleNode("isCorrectPassword", valid));
return rootNode;
}
Aggregations