Search in sources :

Example 56 with SimpleNode

use of org.hisp.dhis.node.types.SimpleNode 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)

Example 57 with SimpleNode

use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.

the class MeController method verifyPasswordInternal.

// ------------------------------------------------------------------------------------------------
// Supportive methods
// ------------------------------------------------------------------------------------------------
private RootNode verifyPasswordInternal(String password, User currentUser) throws WebMessageException {
    if (password == null) {
        throw new WebMessageException(conflict("Required attribute 'password' missing or null."));
    }
    boolean valid = passwordManager.matches(password, currentUser.getPassword());
    RootNode rootNode = NodeUtils.createRootNode("response");
    rootNode.addChild(new SimpleNode("isCorrectPassword", valid));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Aggregations

SimpleNode (org.hisp.dhis.node.types.SimpleNode)57 CollectionNode (org.hisp.dhis.node.types.CollectionNode)38 RootNode (org.hisp.dhis.node.types.RootNode)36 ComplexNode (org.hisp.dhis.node.types.ComplexNode)26 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)21 User (org.hisp.dhis.user.User)18 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Node (org.hisp.dhis.node.Node)10 Property (org.hisp.dhis.schema.Property)10 MessageConversation (org.hisp.dhis.webapi.webdomain.MessageConversation)8 ArrayList (java.util.ArrayList)7 DeleteAccessDeniedException (org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException)7 CurrentUser (org.hisp.dhis.user.CurrentUser)7 Test (org.junit.jupiter.api.Test)7 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)6 PostMapping (org.springframework.web.bind.annotation.PostMapping)5 CategoryOption (org.hisp.dhis.category.CategoryOption)4 EmbeddedObject (org.hisp.dhis.common.EmbeddedObject)4 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)4