use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict in project dhis2-core by dhis2.
the class ChartController method getHistoryChart.
@RequestMapping(value = { "/history/data", "/history/data.png" }, method = RequestMethod.GET)
public void getHistoryChart(@RequestParam String de, @RequestParam String co, @RequestParam String cp, @RequestParam String pe, @RequestParam String ou, @RequestParam(defaultValue = "525", required = false) int width, @RequestParam(defaultValue = "300", required = false) int height, HttpServletResponse response) throws IOException, WebMessageException {
DataElement dataElement = dataElementService.getDataElement(de);
if (dataElement == null) {
throw new WebMessageException(WebMessageUtils.conflict("Data element does not exist: " + de));
}
DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo(co);
if (categoryOptionCombo == null) {
throw new WebMessageException(WebMessageUtils.conflict("Category option combo does not exist: " + co));
}
DataElementCategoryOptionCombo attributeOptionCombo = categoryService.getDataElementCategoryOptionCombo(cp);
if (attributeOptionCombo == null) {
throw new WebMessageException(WebMessageUtils.conflict("Category option combo does not exist: " + cp));
}
Period period = PeriodType.getPeriodFromIsoString(pe);
if (period == null) {
throw new WebMessageException(WebMessageUtils.conflict("Period does not exist: " + pe));
}
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou);
if (organisationUnit == null) {
throw new WebMessageException(WebMessageUtils.conflict("Organisation unit does not exist: " + ou));
}
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_PNG, CacheStrategy.RESPECT_SYSTEM_SETTING, "chart.png", false);
JFreeChart chart = chartService.getJFreeChartHistory(dataElement, categoryOptionCombo, attributeOptionCombo, period, organisationUnit, 13, i18nManager.getI18nFormat());
ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, width, height);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict in project dhis2-core by dhis2.
the class CrudControllerAdvice method handleMetadataImportConflictException.
@ExceptionHandler(MetadataImportConflictException.class)
public void handleMetadataImportConflictException(MetadataImportConflictException conflictException, HttpServletResponse response, HttpServletRequest request) {
if (conflictException.getMetadataSyncSummary() == null) {
webMessageService.send(WebMessageUtils.conflict(conflictException.getMessage()), response, request);
} else {
WebMessage message = new WebMessage(Status.ERROR, HttpStatus.CONFLICT);
message.setResponse(conflictException.getMetadataSyncSummary());
webMessageService.send(message, response, request);
}
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict in project dhis2-core by dhis2.
the class CompleteDataSetRegistrationController method saveCompleteDataSetRegistration.
@ApiVersion({ DhisApiVersion.V23, DhisApiVersion.V24, DhisApiVersion.V25 })
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", value = MULTIPLE_SAVE_RESOURCE_PATH)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void saveCompleteDataSetRegistration(@RequestBody CompleteDataSetRegistrationRequests completeDataSetRegistrationRequests, HttpServletResponse response) throws WebMessageException {
List<CompleteDataSetRegistration> registrations = new ArrayList<>();
for (CompleteDataSetRegistrationRequest completeDataSetRegistrationRequest : completeDataSetRegistrationRequests) {
String ds = completeDataSetRegistrationRequest.getDs();
DataSet dataSet = dataSetService.getDataSet(ds);
if (dataSet == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal data set identifier: " + ds));
}
String pe = completeDataSetRegistrationRequest.getPe();
Period period = PeriodType.getPeriodFromIsoString(pe);
if (period == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal period identifier: " + pe));
}
String ou = completeDataSetRegistrationRequest.getOu();
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou);
if (organisationUnit == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal organisation unit identifier: " + ou));
}
String cc = completeDataSetRegistrationRequest.getCc();
String cp = completeDataSetRegistrationRequest.getCp();
DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
if (attributeOptionCombo == null) {
return;
}
// ---------------------------------------------------------------------
// Check locked status
// ---------------------------------------------------------------------
boolean multiOu = completeDataSetRegistrationRequest.isMultiOu();
if (dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null, multiOu)) {
throw new WebMessageException(WebMessageUtils.conflict("Data set is locked: " + ds));
}
// ---------------------------------------------------------------------
// Register as completed data set
// ---------------------------------------------------------------------
String sb = completeDataSetRegistrationRequest.getSb();
String storedBy = (sb == null) ? currentUserService.getCurrentUsername() : sb;
Date cd = completeDataSetRegistrationRequest.getCd();
Date completionDate = (cd == null) ? new Date() : cd;
Set<OrganisationUnit> orgUnits = new HashSet<>();
orgUnits.add(organisationUnit);
if (multiOu) {
orgUnits.addAll(organisationUnit.getChildren());
}
addRegistrationsForOrgUnits(registrations, orgUnits, dataSet, period, attributeOptionCombo, storedBy, completionDate);
}
registrationService.saveCompleteDataSetRegistrations(registrations, true);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict in project dhis2-core by dhis2.
the class DashboardController method postJsonItemContent.
@RequestMapping(value = "/{dashboardUid}/items/content", method = RequestMethod.POST)
public void postJsonItemContent(HttpServletResponse response, HttpServletRequest request, @PathVariable String dashboardUid, @RequestParam DashboardItemType type, @RequestParam("id") String contentUid) throws Exception {
Dashboard dashboard = dashboardService.getDashboard(dashboardUid);
if (dashboard == null) {
throw new WebMessageException(WebMessageUtils.notFound("Dashboard does not exist: " + dashboardUid));
}
if (!aclService.canUpdate(currentUserService.getCurrentUser(), dashboard)) {
throw new UpdateAccessDeniedException("You don't have the proper permissions to update this dashboard.");
}
DashboardItem item = dashboardService.addItemContent(dashboardUid, type, contentUid);
if (item == null) {
throw new WebMessageException(WebMessageUtils.conflict("Max number of dashboard items reached: " + MAX_ITEMS));
} else {
response.addHeader("Location", DashboardItemSchemaDescriptor.API_ENDPOINT + "/" + item.getUid());
webMessageService.send(WebMessageUtils.created("Dashboard item created"), response, request);
}
}
Aggregations