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;
}
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;
}
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;
}
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;
}
}
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);
}
Aggregations