Search in sources :

Example 26 with SimpleNode

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

the class MetadataVersionController method getMetadataVersionsAsNode.

private RootNode getMetadataVersionsAsNode(List<MetadataVersion> versions) {
    RootNode rootNode = NodeUtils.createRootNode("metadataversions");
    CollectionNode collectionNode = new CollectionNode("metadataversions", true);
    rootNode.addChild(collectionNode);
    for (MetadataVersion version : versions) {
        ComplexNode complexNode = new ComplexNode("");
        complexNode.addChild(new SimpleNode("name", version.getName()));
        complexNode.addChild(new SimpleNode("type", version.getType()));
        complexNode.addChild(new SimpleNode("created", version.getCreated()));
        complexNode.addChild(new SimpleNode("id", version.getUid()));
        complexNode.addChild(new SimpleNode("importdate", version.getImportDate()));
        complexNode.addChild(new SimpleNode("hashCode", version.getHashCode()));
        collectionNode.addChild(complexNode);
    }
    return rootNode;
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) RootNode(org.hisp.dhis.node.types.RootNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Example 27 with SimpleNode

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

the class UserControllerUtils method getWorkflowLevelNodes.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
 * For a user and workflow, returns a list of levels accessible to the user
 * user and the actions (if any) they can take at those levels to approve
 * (and accept if configured) data.
 *
 * @param user the user
 * @param workflow the approval workflow for which to fetch the levels
 * @return a node with the ordered list of data approval levels
 */
private CollectionNode getWorkflowLevelNodes(User user, DataApprovalWorkflow workflow) {
    Set<String> authorities = user.getAllAuthorities();
    boolean canApprove = authorities.contains(AUTHORITY_ALL) || authorities.contains(AUTH_APPROVE);
    boolean canApproveLowerLevels = authorities.contains(AUTHORITY_ALL) || authorities.contains(AUTH_APPROVE_LOWER_LEVELS);
    boolean canAccept = authorities.contains(AUTHORITY_ALL) || authorities.contains(AUTH_ACCEPT_LOWER_LEVELS);
    boolean acceptConfigured = systemSettingManager.getBoolSetting(SettingKey.ACCEPTANCE_REQUIRED_FOR_APPROVAL);
    int lowestUserOrgUnitLevel = getLowsetUserOrgUnitLevel(user);
    CollectionNode levelNodes = new CollectionNode("dataApprovalLevels", true);
    boolean highestLevelInWorkflow = true;
    for (DataApprovalLevel level : dataApprovalLevelService.getUserDataApprovalLevels(user, workflow)) {
        if (level.getOrgUnitLevel() < lowestUserOrgUnitLevel) {
            continue;
        }
        ComplexNode levelNode = new ComplexNode("dataApprovalLevel");
        levelNode.addChild(new SimpleNode("name", level.getName()));
        levelNode.addChild(new SimpleNode("id", level.getUid()));
        levelNode.addChild(new SimpleNode("level", level.getLevel()));
        levelNode.addChild(new SimpleNode("approve", (canApprove && highestLevelInWorkflow) || canApproveLowerLevels));
        if (acceptConfigured) {
            levelNode.addChild(new SimpleNode("accept", canAccept && !highestLevelInWorkflow));
        }
        levelNodes.addChild(levelNode);
        highestLevelInWorkflow = false;
    }
    return levelNodes;
}
Also used : DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Example 28 with SimpleNode

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

the class MeController method validatePasswordInternal.

private RootNode validatePasswordInternal(String password, User currentUser) throws WebMessageException {
    if (password == null) {
        throw new WebMessageException(conflict("Required attribute 'password' missing or null."));
    }
    CredentialsInfo credentialsInfo = new CredentialsInfo(currentUser.getUsername(), password, currentUser.getEmail(), false);
    PasswordValidationResult result = passwordValidationService.validate(credentialsInfo);
    RootNode rootNode = NodeUtils.createRootNode("response");
    rootNode.addChild(new SimpleNode("isValidPassword", result.isValid()));
    if (!result.isValid()) {
        rootNode.addChild(new SimpleNode("errorMessage", result.getErrorMessage()));
    }
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) CredentialsInfo(org.hisp.dhis.user.CredentialsInfo) PasswordValidationResult(org.hisp.dhis.user.PasswordValidationResult) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Example 29 with SimpleNode

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

the class MessageConversationController method removeUserFromMessageConversation.

// --------------------------------------------------------------------------
// Remove a user from a MessageConversation
// In practice a DELETE on MessageConversation <-> User relationship
// --------------------------------------------------------------------------
@DeleteMapping(value = "/{mc-uid}/{user-uid}", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode removeUserFromMessageConversation(@PathVariable(value = "mc-uid") String mcUid, @PathVariable(value = "user-uid") String userUid, @CurrentUser User currentUser, HttpServletResponse response) throws DeleteAccessDeniedException {
    RootNode responseNode = new RootNode("reply");
    User user = userService.getUser(userUid);
    if (user == null) {
        responseNode.addChild(new SimpleNode("message", "No user with uid: " + userUid));
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return responseNode;
    }
    if (!canModifyUserConversation(currentUser, user)) {
        throw new DeleteAccessDeniedException("Not authorized to modify user: " + user.getUid());
    }
    org.hisp.dhis.message.MessageConversation messageConversation = messageService.getMessageConversation(mcUid);
    if (messageConversation == null) {
        responseNode.addChild(new SimpleNode("message", "No messageConversation with uid: " + mcUid));
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return responseNode;
    }
    CollectionNode removed = responseNode.addChild(new CollectionNode("removed"));
    if (messageConversation.remove(user)) {
        messageService.updateMessageConversation(messageConversation);
        removed.addChild(new SimpleNode("uid", messageConversation.getUid()));
    }
    response.setStatus(HttpServletResponse.SC_OK);
    return responseNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) CurrentUser(org.hisp.dhis.user.CurrentUser) User(org.hisp.dhis.user.User) DeleteAccessDeniedException(org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 30 with SimpleNode

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

the class MessageConversationController method unmarkMessageConversationFollowup.

// --------------------------------------------------------------------------
// Clear follow up
// --------------------------------------------------------------------------
@PostMapping(value = "unfollowup", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode unmarkMessageConversationFollowup(@RequestParam(value = "user", required = false) String userUid, @RequestBody List<String> uids, HttpServletResponse response, @CurrentUser User currentUser) {
    RootNode responseNode = new RootNode("response");
    User user = userUid != null ? userService.getUser(userUid) : currentUser;
    if (user == null) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        responseNode.addChild(new SimpleNode("message", "No user with uid: " + userUid));
        return responseNode;
    }
    if (!canModifyUserConversation(currentUser, user)) {
        throw new UpdateAccessDeniedException("Not authorized to modify this object.");
    }
    Collection<org.hisp.dhis.message.MessageConversation> messageConversations = messageService.getMessageConversations(user, uids);
    if (messageConversations.isEmpty()) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        responseNode.addChild(new SimpleNode("message", "No MessageConversations found for the given UIDs"));
        return responseNode;
    }
    CollectionNode marked = responseNode.addChild(new CollectionNode("unmarkedFollowup"));
    marked.setWrapping(false);
    for (org.hisp.dhis.message.MessageConversation conversation : messageConversations) {
        if (conversation.isFollowUp()) {
            conversation.toggleFollowUp(user);
            messageService.updateMessageConversation(conversation);
        }
        marked.addChild(new SimpleNode("uid", conversation.getUid()));
    }
    response.setStatus(HttpServletResponse.SC_OK);
    return responseNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) CurrentUser(org.hisp.dhis.user.CurrentUser) User(org.hisp.dhis.user.User) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) MessageConversation(org.hisp.dhis.webapi.webdomain.MessageConversation) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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