use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict in project dhis2-core by dhis2.
the class FileResourceController method saveFileResource.
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public WebMessage saveFileResource(@RequestParam MultipartFile file) throws WebMessageException, IOException {
String filename = StringUtils.defaultIfBlank(FilenameUtils.getName(file.getOriginalFilename()), DEFAULT_FILENAME);
String contentType = file.getContentType();
contentType = isValidContentType(contentType) ? contentType : DEFAULT_CONTENT_TYPE;
long contentLength = file.getSize();
if (contentLength <= 0) {
throw new WebMessageException(WebMessageUtils.conflict("Could not read file or file is empty."));
}
ByteSource bytes = new MultipartFileByteSource(file);
String contentMd5 = bytes.hash(Hashing.md5()).toString();
FileResource fileResource = new FileResource(filename, contentType, contentLength, contentMd5, FileResourceDomain.DATA_VALUE);
fileResource.setAssigned(false);
fileResource.setCreated(new Date());
fileResource.setUser(currentUserService.getCurrentUser());
File tmpFile = toTempFile(file);
String uid = fileResourceService.saveFileResource(fileResource, tmpFile);
if (uid == null) {
throw new WebMessageException(WebMessageUtils.error("Saving the file failed."));
}
WebMessage webMessage = new WebMessage(Status.OK, HttpStatus.ACCEPTED);
webMessage.setResponse(new FileResourceWebMessageResponse(fileResource));
return webMessage;
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict in project dhis2-core by dhis2.
the class InterpretationController method writeChartInterpretation.
@RequestMapping(value = "/chart/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" })
public void writeChartInterpretation(@PathVariable("uid") String uid, @RequestParam(value = "ou", required = false) String orgUnitUid, @RequestBody String text, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
Chart chart = idObjectManager.get(Chart.class, uid);
if (chart == null) {
throw new WebMessageException(WebMessageUtils.conflict("Chart does not exist or is not accessible: " + uid));
}
OrganisationUnit orgUnit = getUserOrganisationUnit(orgUnitUid, chart, currentUserService.getCurrentUser());
createIntepretation(new Interpretation(chart, orgUnit, text), request, response);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict in project dhis2-core by dhis2.
the class InterpretationController method like.
// -------------------------------------------------------------------------
// Likes
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/like", method = RequestMethod.POST)
public void like(@PathVariable("uid") String uid, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
Interpretation interpretation = interpretationService.getInterpretation(uid);
if (interpretation == null) {
throw new WebMessageException(WebMessageUtils.conflict("Interpretation does not exist: " + uid));
}
boolean like = interpretationService.likeInterpretation(interpretation.getId());
if (like) {
webMessageService.send(WebMessageUtils.created("Like added to interpretation"), response, request);
} else {
webMessageService.send(WebMessageUtils.conflict("Could not add like, user had already liked interpretation"), response, request);
}
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict in project dhis2-core by dhis2.
the class DataApprovalController method getApprovalByCategoryOptionCombos.
@RequestMapping(value = APPROVALS_PATH + "/categoryOptionCombos", method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
public void getApprovalByCategoryOptionCombos(@RequestParam Set<String> ds, @RequestParam String pe, @RequestParam(required = false) String ou, HttpServletResponse response) throws IOException, WebMessageException {
Set<DataSet> dataSets = parseDataSetsWithWorkflow(ds);
Period period = PeriodType.getPeriodFromIsoString(pe);
if (period == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal period identifier: " + pe));
}
OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(ou);
if (orgUnit != null && orgUnit.isRoot()) {
// Look for all org units.
orgUnit = null;
}
SetMap<DataApprovalWorkflow, DataElementCategoryCombo> workflowCategoryComboMap = new SetMap<>();
for (DataSet dataSet : dataSets) {
workflowCategoryComboMap.putValue(dataSet.getWorkflow(), dataSet.getCategoryCombo());
}
List<DataApprovalStatus> statusList = new ArrayList<>();
for (DataApprovalWorkflow workflow : workflowCategoryComboMap.keySet()) {
for (DataElementCategoryCombo attributeCombo : workflowCategoryComboMap.get(workflow)) {
statusList.addAll(dataApprovalService.getUserDataApprovalsAndPermissions(workflow, period, orgUnit, attributeCombo));
}
}
List<Map<String, Object>> list = new ArrayList<>();
for (DataApprovalStatus status : statusList) {
Map<String, Object> item = new HashMap<>();
Map<String, String> approvalLevel = new HashMap<>();
if (status.getApprovedLevel() != null) {
approvalLevel.put("id", status.getApprovedLevel().getUid());
approvalLevel.put("level", String.valueOf(status.getApprovedLevel().getLevel()));
}
item.put("id", status.getAttributeOptionComboUid());
item.put("level", approvalLevel);
item.put("ou", status.getOrganisationUnitUid());
item.put("ouName", status.getOrganisationUnitName());
item.put("accepted", status.isAccepted());
item.put("permissions", status.getPermissions());
list.add(item);
}
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
renderService.toJson(response.getOutputStream(), list);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict in project dhis2-core by dhis2.
the class InterpretationController method updateComment.
@RequestMapping(value = "/{uid}/comments/{cuid}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void updateComment(@PathVariable("uid") String uid, @PathVariable("cuid") String cuid, HttpServletResponse response, @RequestBody String content) throws WebMessageException {
Interpretation interpretation = interpretationService.getInterpretation(uid);
if (interpretation == null) {
throw new WebMessageException(WebMessageUtils.conflict("Interpretation does not exist: " + uid));
}
for (InterpretationComment comment : interpretation.getComments()) {
if (comment.getUid().equals(cuid)) {
if (!currentUserService.getCurrentUser().equals(comment.getUser()) && !currentUserService.currentUserIsSuper()) {
throw new AccessDeniedException("You are not allowed to update this comment.");
}
comment.setText(content);
}
}
interpretationService.updateInterpretation(interpretation);
}
Aggregations