use of org.springframework.web.bind.annotation.ResponseStatus in project dhis2-core by dhis2.
the class MapController method putJsonObject.
@Override
@RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void putJsonObject(@PathVariable String uid, HttpServletRequest request, HttpServletResponse response) throws Exception {
Map map = mappingService.getMap(uid);
if (map == null) {
throw new WebMessageException(WebMessageUtils.notFound("Map does not exist: " + uid));
}
MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap());
Map newMap = deserializeJsonEntity(request, response);
newMap.setUid(uid);
mergeService.merge(new MergeParams<>(newMap, map).setMergeMode(params.getMergeMode()));
mappingService.updateMap(map);
}
use of org.springframework.web.bind.annotation.ResponseStatus in project dhis2-core by dhis2.
the class FilledOrganisationUnitLevelController method setList.
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public void setList(HttpServletRequest request, HttpServletResponse response) throws Exception {
Metadata metadata = DefaultRenderService.getJsonMapper().readValue(request.getInputStream(), Metadata.class);
List<OrganisationUnitLevel> levels = metadata.getOrganisationUnitLevels();
for (OrganisationUnitLevel level : levels) {
if (level.getLevel() <= 0) {
throw new WebMessageException(WebMessageUtils.conflict("Level must be greater than zero"));
}
if (StringUtils.isBlank(level.getName())) {
throw new WebMessageException(WebMessageUtils.conflict("Name must be specified"));
}
organisationUnitService.addOrUpdateOrganisationUnitLevel(new OrganisationUnitLevel(level.getLevel(), level.getName(), level.getOfflineLevels()));
}
}
use of org.springframework.web.bind.annotation.ResponseStatus in project dhis2-core by dhis2.
the class MapController method postJsonObject.
//--------------------------------------------------------------------------
// CRUD
//--------------------------------------------------------------------------
@Override
@RequestMapping(method = RequestMethod.POST, consumes = "application/json")
@ResponseStatus(HttpStatus.CREATED)
public void postJsonObject(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map map = deserializeJsonEntity(request, response);
map.getTranslations().clear();
mappingService.addMap(map);
response.addHeader("Location", MapSchemaDescriptor.API_ENDPOINT + "/" + map.getUid());
webMessageService.send(WebMessageUtils.created("Map created"), response, request);
}
use of org.springframework.web.bind.annotation.ResponseStatus in project dhis2-core by dhis2.
the class DataStatisticsController method saveEvent.
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public void saveEvent(@RequestParam DataStatisticsEventType eventType, String favorite) {
Date timestamp = new Date();
String username = currentUserService.getCurrentUsername();
DataStatisticsEvent event = new DataStatisticsEvent(eventType, timestamp, username, favorite);
dataStatisticsService.addEvent(event);
}
use of org.springframework.web.bind.annotation.ResponseStatus 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