Search in sources :

Example 11 with DataApproval

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

DataApproval (org.hisp.dhis.dataapproval.DataApproval)11 Period (org.hisp.dhis.period.Period)9 Date (java.util.Date)8 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)8 User (org.hisp.dhis.user.User)8 DataApprovalLevel (org.hisp.dhis.dataapproval.DataApprovalLevel)7 DataApprovalWorkflow (org.hisp.dhis.dataapproval.DataApprovalWorkflow)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)6 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)4 ArrayList (java.util.ArrayList)4 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)3 DataSet (org.hisp.dhis.dataset.DataSet)3 DataApprovalStateRequest (org.hisp.dhis.dataapproval.DataApprovalStateRequest)2 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)2 HashSet (java.util.HashSet)1 Criteria (org.hibernate.Criteria)1 CachingMap (org.hisp.dhis.commons.collection.CachingMap)1 DataElement (org.hisp.dhis.dataelement.DataElement)1