Search in sources :

Example 21 with ComplexNode

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

the class DataElementOperandControllerTest method buildResponse.

private CollectionNode buildResponse(List<DataElementOperand> dataElementOperands) {
    CollectionNode collectionNode = new CollectionNode("dataElementOperands");
    collectionNode.setWrapping(true);
    collectionNode.setNamespace("http://dhis2.org/schema/dxf/2.0");
    for (DataElementOperand dataElementOperand : dataElementOperands) {
        ComplexNode complexNode = new ComplexNode("dataElementOperand");
        complexNode.setNamespace(collectionNode.getNamespace());
        complexNode.addChild(new SimpleNode("displayName", dataElementOperand.getDisplayName(), false));
        complexNode.addChild(new SimpleNode("id", dataElementOperand.getDimensionItem(), true));
        collectionNode.addChild(complexNode);
    }
    return collectionNode;
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Example 22 with ComplexNode

use of org.hisp.dhis.node.types.ComplexNode 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 23 with ComplexNode

use of org.hisp.dhis.node.types.ComplexNode 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 24 with ComplexNode

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

the class AbstractCrudController method getObjectInternal.

@SuppressWarnings("unchecked")
private RootNode getObjectInternal(String uid, Map<String, String> parameters, List<String> filters, List<String> fields, User user) throws Exception {
    WebOptions options = new WebOptions(parameters);
    List<T> entities = getEntity(uid, options);
    if (entities.isEmpty()) {
        throw new WebMessageException(WebMessageUtils.notFound(getEntityClass(), uid));
    }
    Query query = queryService.getQueryFromUrl(getEntityClass(), filters, new ArrayList<>(), options.getRootJunction());
    query.setUser(user);
    query.setObjects(entities);
    entities = (List<T>) queryService.query(query);
    handleLinksAndAccess(entities, fields, true, user);
    for (T entity : entities) {
        postProcessEntity(entity);
        postProcessEntity(entity, options, parameters);
    }
    CollectionNode collectionNode = fieldFilterService.filter(getEntityClass(), entities, fields);
    if (options.isTrue("useWrapper") || entities.size() > 1) {
        RootNode rootNode = NodeUtils.createMetadata(collectionNode);
        rootNode.getConfig().setInclusionStrategy(getInclusionStrategy(parameters.get("inclusionStrategy")));
        return rootNode;
    } else {
        List<Node> children = collectionNode.getChildren();
        RootNode rootNode;
        if (!children.isEmpty()) {
            rootNode = NodeUtils.createRootNode(children.get(0));
        } else {
            rootNode = NodeUtils.createRootNode(new ComplexNode(getSchema().getSingular()));
        }
        rootNode.getConfig().setInclusionStrategy(getInclusionStrategy(parameters.get("inclusionStrategy")));
        return rootNode;
    }
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) Query(org.hisp.dhis.query.Query) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ComplexNode(org.hisp.dhis.node.types.ComplexNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) RootNode(org.hisp.dhis.node.types.RootNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) Node(org.hisp.dhis.node.Node) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) CollectionNode(org.hisp.dhis.node.types.CollectionNode)

Example 25 with ComplexNode

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

the class DefaultMetadataVersionServiceTest method testShouldCreateAValidVersionsNodeTree.

@Test
public void testShouldCreateAValidVersionsNodeTree() throws Exception {
    List<MetadataVersion> versions = new ArrayList<>();
    versions.add(new MetadataVersion("test_version1", VersionType.ATOMIC));
    versions.add(new MetadataVersion("test_version2", VersionType.BEST_EFFORT));
    versions.add(new MetadataVersion("test_version3", VersionType.BEST_EFFORT));
    RootNode root = versionService.getMetadataVersionsAsNode(versions);
    ComplexNode[] versionNodes = getVersionFromNodeTree(root);
    for (int i = 0; i < versionNodes.length; i++) {
        assertEquals(versions.get(i).getName(), ((SimpleNode) versionNodes[i].getChildren().get(0)).getValue());
        assertEquals(versions.get(i).getType(), ((SimpleNode) versionNodes[i].getChildren().get(1)).getValue());
    }
    assertEquals(versions.size(), versionNodes.length);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) RootNode(org.hisp.dhis.node.types.RootNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) ArrayList(java.util.ArrayList) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

ComplexNode (org.hisp.dhis.node.types.ComplexNode)33 SimpleNode (org.hisp.dhis.node.types.SimpleNode)23 CollectionNode (org.hisp.dhis.node.types.CollectionNode)21 RootNode (org.hisp.dhis.node.types.RootNode)15 Test (org.junit.jupiter.api.Test)9 ArrayList (java.util.ArrayList)7 DhisSpringTest (org.hisp.dhis.DhisSpringTest)5 EmbeddedObject (org.hisp.dhis.common.EmbeddedObject)5 Node (org.hisp.dhis.node.Node)5 CategoryOption (org.hisp.dhis.category.CategoryOption)4 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)4 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)4 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)4 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)4 Schema (org.hisp.dhis.schema.Schema)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)3 Property (org.hisp.dhis.schema.Property)3 Collection (java.util.Collection)2 Category (org.hisp.dhis.category.Category)2