Search in sources :

Example 6 with SimpleNode

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

the class IndexController method createRootNode.

private RootNode createRootNode() {
    RootNode rootNode = NodeUtils.createMetadata();
    CollectionNode collectionNode = rootNode.addChild(new CollectionNode("resources"));
    for (Schema schema : schemaService.getSchemas()) {
        if (schema.haveApiEndpoint()) {
            ComplexNode complexNode = collectionNode.addChild(new ComplexNode("resource"));
            // TODO add i18n to this
            complexNode.addChild(new SimpleNode("displayName", beautify(schema.getPlural())));
            complexNode.addChild(new SimpleNode("singular", schema.getSingular()));
            complexNode.addChild(new SimpleNode("plural", schema.getPlural()));
            complexNode.addChild(new SimpleNode("href", contextService.getApiPath() + schema.getRelativeApiEndpoint()));
        }
    }
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) Schema(org.hisp.dhis.schema.Schema) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Example 7 with SimpleNode

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

the class CsvNodeSerializer method startWriteRootNode.

@Override
protected void startWriteRootNode(RootNode rootNode) throws Exception {
    for (Node child : rootNode.getChildren()) {
        if (child.isCollection()) {
            for (Node node : child.getChildren()) {
                csvGenerator.writeStartObject();
                for (Node property : node.getChildren()) {
                    if (property.isSimple()) {
                        writeSimpleNode((SimpleNode) property);
                    }
                }
                csvGenerator.writeEndObject();
            }
        }
    }
}
Also used : CollectionNode(org.hisp.dhis.node.types.CollectionNode) Node(org.hisp.dhis.node.Node) SimpleNode(org.hisp.dhis.node.types.SimpleNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) RootNode(org.hisp.dhis.node.types.RootNode)

Example 8 with SimpleNode

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

the class ExcelNodeSerializer method startWriteRootNode.

@Override
protected void startWriteRootNode(RootNode rootNode) throws Exception {
    XSSFCreationHelper creationHelper = workbook.getCreationHelper();
    int rowIdx = 1;
    for (Node collectionNode : rootNode.getChildren()) {
        if (collectionNode.isCollection()) {
            for (Node complexNode : collectionNode.getChildren()) {
                XSSFRow row = sheet.createRow(rowIdx++);
                int cellIdx = 0;
                for (Node node : complexNode.getChildren()) {
                    if (node.isSimple()) {
                        XSSFCell cell = row.createCell(cellIdx++);
                        cell.setCellValue(getValue((SimpleNode) node));
                        if (node.haveProperty() && PropertyType.URL.equals(node.getProperty().getPropertyType())) {
                            XSSFHyperlink hyperlink = creationHelper.createHyperlink(HyperlinkType.URL);
                            hyperlink.setAddress(getValue((SimpleNode) node));
                            hyperlink.setLabel(getValue((SimpleNode) node));
                            cell.setHyperlink(hyperlink);
                        } else if (node.haveProperty() && PropertyType.EMAIL.equals(node.getProperty().getPropertyType())) {
                            XSSFHyperlink hyperlink = creationHelper.createHyperlink(HyperlinkType.EMAIL);
                            hyperlink.setAddress(getValue((SimpleNode) node));
                            hyperlink.setLabel(getValue((SimpleNode) node));
                            cell.setHyperlink(hyperlink);
                        }
                    }
                }
            }
        }
    }
}
Also used : XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) XSSFCreationHelper(org.apache.poi.xssf.usermodel.XSSFCreationHelper) CollectionNode(org.hisp.dhis.node.types.CollectionNode) Node(org.hisp.dhis.node.Node) SimpleNode(org.hisp.dhis.node.types.SimpleNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) RootNode(org.hisp.dhis.node.types.RootNode) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell) SimpleNode(org.hisp.dhis.node.types.SimpleNode) XSSFHyperlink(org.apache.poi.xssf.usermodel.XSSFHyperlink)

Example 9 with SimpleNode

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

the class DefaultMetadataVersionService method getMetadataVersionsAsNode.

@Override
public 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 10 with SimpleNode

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

the class SystemController method getUuid.

@RequestMapping(value = "/uuid", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode getUuid(@RequestParam(required = false, defaultValue = "1") Integer limit) throws IOException, InvalidTypeException {
    limit = Math.min(limit, 10000);
    RootNode rootNode = new RootNode("codes");
    CollectionNode collectionNode = rootNode.addChild(new CollectionNode("codes"));
    collectionNode.setWrapping(false);
    for (int i = 0; i < limit; i++) {
        collectionNode.addChild(new SimpleNode("code", UUID.randomUUID().toString()));
    }
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) 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