Search in sources :

Example 81 with ResponseStatus

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());
    }
}
Also used : User(org.hisp.dhis.user.User) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 82 with ResponseStatus

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);
    }
}
Also used : User(org.hisp.dhis.user.User) Users(org.hisp.dhis.user.Users) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 83 with ResponseStatus

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);
    }
}
Also used : User(org.hisp.dhis.user.User) Users(org.hisp.dhis.user.Users) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 84 with ResponseStatus

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) HashSet(java.util.HashSet) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 85 with ResponseStatus

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);
}
Also used : DataApproval(org.hisp.dhis.dataapproval.DataApproval) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) User(org.hisp.dhis.user.User) DataApprovalStateRequest(org.hisp.dhis.dataapproval.DataApprovalStateRequest) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) Date(java.util.Date) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)93 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)69 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)35 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)26 GetMapping (org.springframework.web.bind.annotation.GetMapping)17 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)16 User (org.hisp.dhis.user.User)14 Date (java.util.Date)13 Configuration (org.hisp.dhis.configuration.Configuration)12 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 Period (org.hisp.dhis.period.Period)11 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)9 Calendar (java.util.Calendar)9 DataSet (org.hisp.dhis.dataset.DataSet)7 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)7 ArrayList (java.util.ArrayList)6 DataApproval (org.hisp.dhis.dataapproval.DataApproval)6 DataApprovalLevel (org.hisp.dhis.dataapproval.DataApprovalLevel)6 NotFoundException (org.hisp.dhis.webapi.controller.exception.NotFoundException)6 Proveedor (sic.modelo.Proveedor)6