Search in sources :

Example 1 with ApprovalsDto

use of org.hisp.dhis.webapi.webdomain.approval.ApprovalsDto in project dhis2-core by dhis2.

the class DataApprovalController method getDataApprovalList.

private List<DataApproval> getDataApprovalList(ApprovalsDto approvals) throws WebMessageException {
    Set<DataApprovalWorkflow> workflows = getAndValidateWorkflows(approvals.getDs(), approvals.getWf());
    List<Period> periods = PeriodType.getPeriodsFromIsoStrings(approvals.getPe());
    periods = periodService.reloadPeriods(periods);
    if (periods.isEmpty()) {
        throw new WebMessageException(conflict("Approvals must have periods"));
    }
    User user = currentUserService.getCurrentUser();
    CategoryOptionCombo defaultOptionCombo = categoryService.getDefaultCategoryOptionCombo();
    Date date = new Date();
    List<DataApproval> dataApprovals = new ArrayList<>();
    List<CategoryOptionCombo> optionCombos = categoryService.getAllCategoryOptionCombos();
    Map<String, CategoryOptionCombo> comboMap = optionCombos.stream().collect(Collectors.toMap(CategoryOptionCombo::getUid, c -> c));
    Map<String, OrganisationUnit> ouCache = new HashMap<>();
    for (ApprovalDto approval : approvals.getApprovals()) {
        CategoryOptionCombo atributeOptionCombo = comboMap.get(approval.getAoc());
        atributeOptionCombo = ObjectUtils.firstNonNull(atributeOptionCombo, defaultOptionCombo);
        OrganisationUnit unit = ouCache.get(approval.getOu());
        if (unit == null) {
            unit = getAndValidateOrgUnit(approval.getOu());
            ouCache.put(approval.getOu(), unit);
        }
        for (DataApprovalWorkflow workflow : workflows) {
            for (Period period : periods) {
                dataApprovals.add(new DataApproval(null, workflow, period, unit, atributeOptionCombo, false, date, user));
            }
        }
    }
    return dataApprovals;
}
Also used : CategoryService(org.hisp.dhis.category.CategoryService) RequestParam(org.springframework.web.bind.annotation.RequestParam) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) DataApprovalService(org.hisp.dhis.dataapproval.DataApprovalService) Date(java.util.Date) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) PeriodService(org.hisp.dhis.period.PeriodService) Autowired(org.springframework.beans.factory.annotation.Autowired) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) NodeUtils(org.hisp.dhis.node.NodeUtils) Collections.singleton(java.util.Collections.singleton) Map(java.util.Map) Preset(org.hisp.dhis.node.Preset) ApprovalDto(org.hisp.dhis.webapi.webdomain.approval.ApprovalDto) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) Period(org.hisp.dhis.period.Period) PostMapping(org.springframework.web.bind.annotation.PostMapping) ContextService(org.hisp.dhis.webapi.service.ContextService) Collection(java.util.Collection) FieldFilterService(org.hisp.dhis.fieldfilter.FieldFilterService) MediaType(org.springframework.http.MediaType) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) WebMessageUtils.conflict(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict) DataApprovalStateResponse(org.hisp.dhis.dataapproval.DataApprovalStateResponse) CategoryCombo(org.hisp.dhis.category.CategoryCombo) DataApproval(org.hisp.dhis.dataapproval.DataApproval) DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) RootNode(org.hisp.dhis.node.types.RootNode) ApprovalsDto(org.hisp.dhis.webapi.webdomain.approval.ApprovalsDto) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) DataApprovalStatus(org.hisp.dhis.dataapproval.DataApprovalStatus) DataSet(org.hisp.dhis.dataset.DataSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) ApprovalStatusDto(org.hisp.dhis.webapi.webdomain.approval.ApprovalStatusDto) Controller(org.springframework.stereotype.Controller) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RequestBody(org.springframework.web.bind.annotation.RequestBody) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) User(org.hisp.dhis.user.User) GetMapping(org.springframework.web.bind.annotation.GetMapping) BadRequestException(org.hisp.dhis.webapi.controller.exception.BadRequestException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) DataApprovalLevelService(org.hisp.dhis.dataapproval.DataApprovalLevelService) ContextUtils(org.hisp.dhis.webapi.utils.ContextUtils) DataApprovalPermissions(org.hisp.dhis.dataapproval.DataApprovalPermissions) HttpServletResponse(javax.servlet.http.HttpServletResponse) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ObjectUtils(org.hisp.dhis.util.ObjectUtils) HttpStatus(org.springframework.http.HttpStatus) Collectors.toList(java.util.stream.Collectors.toList) CurrentUserService(org.hisp.dhis.user.CurrentUserService) PeriodType(org.hisp.dhis.period.PeriodType) DataSetService(org.hisp.dhis.dataset.DataSetService) DataApproval(org.hisp.dhis.dataapproval.DataApproval) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) Date(java.util.Date) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) ApprovalDto(org.hisp.dhis.webapi.webdomain.approval.ApprovalDto)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections.singleton (java.util.Collections.singleton)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 CategoryCombo (org.hisp.dhis.category.CategoryCombo)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 CategoryService (org.hisp.dhis.category.CategoryService)1 DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)1 IdentifiableObjectManager (org.hisp.dhis.common.IdentifiableObjectManager)1 DataApproval (org.hisp.dhis.dataapproval.DataApproval)1 DataApprovalLevel (org.hisp.dhis.dataapproval.DataApprovalLevel)1 DataApprovalLevelService (org.hisp.dhis.dataapproval.DataApprovalLevelService)1