use of org.springframework.web.bind.annotation.ResponseStatus 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.springframework.web.bind.annotation.ResponseStatus in project dhis2-core by dhis2.
the class UserController method postXmlInvites.
@RequestMapping(value = BULK_INVITE_PATH, method = RequestMethod.POST, consumes = { "application/xml", "text/xml" })
@ResponseStatus(HttpStatus.NO_CONTENT)
public void postXmlInvites(HttpServletRequest request, HttpServletResponse response) throws Exception {
Users users = renderService.fromXml(request.getInputStream(), Users.class);
User currentUser = currentUserService.getCurrentUser();
for (User user : users.getUsers()) {
if (!validateInviteUser(user, currentUser)) {
return;
}
}
for (User user : users.getUsers()) {
inviteUser(user, currentUser, request);
}
}
use of org.springframework.web.bind.annotation.ResponseStatus in project dhis2-core by dhis2.
the class UserController method postJsonInvites.
@RequestMapping(value = BULK_INVITE_PATH, method = RequestMethod.POST, consumes = "application/json")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void postJsonInvites(HttpServletRequest request, HttpServletResponse response) throws Exception {
Users users = renderService.fromJson(request.getInputStream(), Users.class);
User currentUser = currentUserService.getCurrentUser();
for (User user : users.getUsers()) {
if (!validateInviteUser(user, currentUser)) {
return;
}
}
for (User user : users.getUsers()) {
inviteUser(user, currentUser, request);
}
}
use of org.springframework.web.bind.annotation.ResponseStatus in project dhis2-core by dhis2.
the class CompleteDataSetRegistrationController method deleteCompleteDataSetRegistration.
// -------------------------------------------------------------------------
// DELETE
// -------------------------------------------------------------------------
@ApiVersion({ DhisApiVersion.ALL, DhisApiVersion.DEFAULT })
@RequestMapping(method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteCompleteDataSetRegistration(@RequestParam Set<String> ds, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) String cc, @RequestParam(required = false) String cp, @RequestParam(required = false) boolean multiOu, HttpServletResponse response) throws WebMessageException {
Set<DataSet> dataSets = new HashSet<>(manager.getByUid(DataSet.class, ds));
if (dataSets.size() != ds.size()) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal data set identifier in this list: " + ds));
}
Period period = PeriodType.getPeriodFromIsoString(pe);
if (period == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal period identifier: " + pe));
}
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou);
if (organisationUnit == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal organisation unit identifier: " + ou));
}
DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
if (attributeOptionCombo == null) {
return;
}
// ---------------------------------------------------------------------
// Check locked status
// ---------------------------------------------------------------------
List<String> lockedDataSets = new ArrayList<>();
for (DataSet dataSet : dataSets) {
if (dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null, multiOu)) {
lockedDataSets.add(dataSet.getUid());
}
}
if (lockedDataSets.size() != 0) {
throw new WebMessageException(WebMessageUtils.conflict("Locked Data set(s) : " + StringUtils.join(lockedDataSets, ", ")));
}
// ---------------------------------------------------------------------
// Un-register as completed data set
// ---------------------------------------------------------------------
Set<OrganisationUnit> orgUnits = new HashSet<>();
orgUnits.add(organisationUnit);
if (multiOu) {
orgUnits.addAll(organisationUnit.getChildren());
}
unRegisterCompleteDataSet(dataSets, period, orgUnits, attributeOptionCombo);
}
use of org.springframework.web.bind.annotation.ResponseStatus in project dhis2-core by dhis2.
the class DataApprovalController method acceptApprovalMultiple.
@PreAuthorize("hasRole('ALL') or hasRole('F_ACCEPT_DATA_LOWER_LEVELS')")
@RequestMapping(value = MULTIPLE_ACCEPTANCES_RESOURCE_PATH, method = RequestMethod.POST)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void acceptApprovalMultiple(@RequestBody DataApprovalStateRequests dataApprovalStateRequests, HttpServletResponse response) throws WebMessageException {
List<DataApproval> dataApprovalList = new ArrayList<>();
for (DataApprovalStateRequest approvalStateRequest : dataApprovalStateRequests) {
DataApprovalWorkflow workflow = getAndValidateWorkflow(approvalStateRequest.getDs(), null);
Period period = getAndValidatePeriod(approvalStateRequest.getPe());
OrganisationUnit organisationUnit = getAndValidateOrgUnit(approvalStateRequest.getOu());
DataApprovalLevel dataApprovalLevel = getAndValidateApprovalLevel(organisationUnit);
User user = approvalStateRequest.getAb() == null ? currentUserService.getCurrentUser() : userService.getUserCredentialsByUsername(approvalStateRequest.getAb()).getUserInfo();
Date approvalDate = (approvalStateRequest.getAd() == null) ? new Date() : approvalStateRequest.getAd();
dataApprovalList.addAll(getApprovalsAsList(dataApprovalLevel, workflow, period, organisationUnit, false, approvalDate, user));
}
dataApprovalService.acceptData(dataApprovalList);
}
Aggregations