Search in sources :

Example 31 with DataApprovalWorkflow

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

the class DataApprovalController method unacceptApproval.

@PreAuthorize("hasRole('ALL') or hasRole('F_ACCEPT_DATA_LOWER_LEVELS')")
@DeleteMapping(ACCEPTANCES_PATH)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void unacceptApproval(@RequestParam(required = false) String ds, @RequestParam(required = false) String wf, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) String aoc) throws WebMessageException {
    DataApprovalWorkflow workflow = getAndValidateWorkflow(ds, wf);
    Period period = getAndValidatePeriod(pe);
    OrganisationUnit organisationUnit = getAndValidateOrgUnit(ou);
    DataApprovalLevel dataApprovalLevel = getAndValidateApprovalLevel(organisationUnit);
    CategoryOptionCombo optionCombo = getAndValidateAttributeOptionCombo(aoc);
    User user = currentUserService.getCurrentUser();
    List<DataApproval> dataApprovalList = getApprovalsAsList(dataApprovalLevel, workflow, period, organisationUnit, optionCombo, false, new Date(), user);
    dataApprovalService.unacceptData(dataApprovalList);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) DataApproval(org.hisp.dhis.dataapproval.DataApproval) User(org.hisp.dhis.user.User) Period(org.hisp.dhis.period.Period) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Date(java.util.Date) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 32 with DataApprovalWorkflow

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

the class UserControllerUtils method getUserDataApprovalWorkflows.

/**
 * Gets the data approval workflows a user can see, including the workflow
 * levels accessible to the user and the actions (if any) they can take at
 * those levels to approve (and accept if configured) data.
 *
 * @param user the user
 * @throws Exception if an error occurs
 */
public RootNode getUserDataApprovalWorkflows(User user) throws Exception {
    CollectionNode collectionNode = new CollectionNode("dataApprovalWorkflows", true);
    for (DataApprovalWorkflow workflow : dataApprovalService.getAllWorkflows()) {
        if (!aclService.canRead(user, workflow)) {
            continue;
        }
        ComplexNode workflowNode = new ComplexNode("dataApprovalWorkflow");
        workflowNode.addChild(new SimpleNode("name", workflow.getName()));
        workflowNode.addChild(new SimpleNode("id", workflow.getUid()));
        workflowNode.addChild(getWorkflowLevelNodes(user, workflow));
        collectionNode.addChild(workflowNode);
    }
    collectionNode.getUnorderedChildren().sort(Comparator.comparing(c -> (String) ((SimpleNode) c.getUnorderedChildren().get(0)).getValue()));
    RootNode rootNode = NodeUtils.createRootNode("dataApprovalWorkflows");
    rootNode.addChild(collectionNode);
    return rootNode;
}
Also used : DataApprovalLevelService(org.hisp.dhis.dataapproval.DataApprovalLevelService) AUTH_APPROVE(org.hisp.dhis.dataapproval.DataApproval.AUTH_APPROVE) AUTH_ACCEPT_LOWER_LEVELS(org.hisp.dhis.dataapproval.DataApproval.AUTH_ACCEPT_LOWER_LEVELS) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) CollectionNode(org.hisp.dhis.node.types.CollectionNode) DataApprovalService(org.hisp.dhis.dataapproval.DataApprovalService) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) SimpleNode(org.hisp.dhis.node.types.SimpleNode) AUTHORITY_ALL(org.hisp.dhis.user.UserAuthorityGroup.AUTHORITY_ALL) NodeUtils(org.hisp.dhis.node.NodeUtils) Component(org.springframework.stereotype.Component) ComplexNode(org.hisp.dhis.node.types.ComplexNode) AUTH_APPROVE_LOWER_LEVELS(org.hisp.dhis.dataapproval.DataApproval.AUTH_APPROVE_LOWER_LEVELS) AclService(org.hisp.dhis.security.acl.AclService) User(org.hisp.dhis.user.User) SettingKey(org.hisp.dhis.setting.SettingKey) Comparator(java.util.Comparator) DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) RootNode(org.hisp.dhis.node.types.RootNode) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) RootNode(org.hisp.dhis.node.types.RootNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Aggregations

DataApprovalWorkflow (org.hisp.dhis.dataapproval.DataApprovalWorkflow)32 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)20 Period (org.hisp.dhis.period.Period)19 DataApprovalLevel (org.hisp.dhis.dataapproval.DataApprovalLevel)18 DataApproval (org.hisp.dhis.dataapproval.DataApproval)16 User (org.hisp.dhis.user.User)15 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)13 Date (java.util.Date)11 ArrayList (java.util.ArrayList)10 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 DataSet (org.hisp.dhis.dataset.DataSet)9 DataApprovalStatus (org.hisp.dhis.dataapproval.DataApprovalStatus)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 Map (java.util.Map)6 Set (java.util.Set)5 CategoryCombo (org.hisp.dhis.category.CategoryCombo)5 Test (org.junit.jupiter.api.Test)5 Collection (java.util.Collection)4 List (java.util.List)4