Search in sources :

Example 1 with DataApprovalStateRequest

use of org.hisp.dhis.dataapproval.DataApprovalStateRequest 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)

Example 2 with DataApprovalStateRequest

use of org.hisp.dhis.dataapproval.DataApprovalStateRequest in project dhis2-core by dhis2.

the class DataApprovalController method saveApprovalMultiple.

@PreAuthorize("hasRole('ALL') or hasRole('F_APPROVE_DATA') or hasRole('F_APPROVE_DATA_LOWER_LEVELS')")
@RequestMapping(value = MULTIPLE_SAVE_RESOURCE_PATH, method = RequestMethod.POST)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void saveApprovalMultiple(@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.approveData(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

Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 DataApproval (org.hisp.dhis.dataapproval.DataApproval)2 DataApprovalLevel (org.hisp.dhis.dataapproval.DataApprovalLevel)2 DataApprovalStateRequest (org.hisp.dhis.dataapproval.DataApprovalStateRequest)2 DataApprovalWorkflow (org.hisp.dhis.dataapproval.DataApprovalWorkflow)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 Period (org.hisp.dhis.period.Period)2 User (org.hisp.dhis.user.User)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2