Search in sources :

Example 11 with CollectionNode

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

the class MessageConversationController method unmarkMessageConversationFollowup.

//--------------------------------------------------------------------------
// Clear follow up
//--------------------------------------------------------------------------
@RequestMapping(value = "unfollowup", method = RequestMethod.POST, 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) {
    RootNode responseNode = new RootNode("response");
    User currentUser = currentUserService.getCurrentUser();
    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) 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) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 12 with CollectionNode

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

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

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

the class AbstractNodeSerializer method writeCollectionNode.

protected void writeCollectionNode(CollectionNode collectionNode) throws Exception {
    if (!config.getInclusionStrategy().include(collectionNode.getChildren())) {
        return;
    }
    startWriteCollectionNode(collectionNode);
    for (Node node : collectionNode.getChildren()) {
        dispatcher(node);
        flushStream();
    }
    endWriteCollectionNode(collectionNode);
}
Also used : SimpleNode(org.hisp.dhis.node.types.SimpleNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) RootNode(org.hisp.dhis.node.types.RootNode)

Example 15 with CollectionNode

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

the class DefaultDataValueSetService method getDataValueTemplate.

private CollectionNode getDataValueTemplate(DataElement dataElement, String deScheme, OrganisationUnit organisationUnit, String ouScheme, Period period, boolean comment) {
    CollectionNode collectionNode = new CollectionNode("dataValues");
    collectionNode.setWrapping(false);
    for (DataElementCategoryOptionCombo categoryOptionCombo : dataElement.getSortedCategoryOptionCombos()) {
        ComplexNode complexNode = collectionNode.addChild(new ComplexNode("dataValue"));
        String label = dataElement.getDisplayName();
        if (!categoryOptionCombo.isDefault()) {
            label += " " + categoryOptionCombo.getDisplayName();
        }
        if (comment) {
            complexNode.setComment("Data element: " + label);
        }
        if (IdentifiableProperty.CODE.toString().toLowerCase().equals(deScheme.toLowerCase())) {
            SimpleNode simpleNode = complexNode.addChild(new SimpleNode("dataElement", dataElement.getCode()));
            simpleNode.setAttribute(true);
        } else {
            SimpleNode simpleNode = complexNode.addChild(new SimpleNode("dataElement", dataElement.getUid()));
            simpleNode.setAttribute(true);
        }
        SimpleNode simpleNode = complexNode.addChild(new SimpleNode("categoryOptionCombo", categoryOptionCombo.getUid()));
        simpleNode.setAttribute(true);
        simpleNode = complexNode.addChild(new SimpleNode("period", period != null ? period.getIsoDate() : ""));
        simpleNode.setAttribute(true);
        if (organisationUnit != null) {
            if (IdentifiableProperty.CODE.toString().toLowerCase().equals(ouScheme.toLowerCase())) {
                simpleNode = complexNode.addChild(new SimpleNode("orgUnit", organisationUnit.getCode() == null ? "" : organisationUnit.getCode()));
                simpleNode.setAttribute(true);
            } else {
                simpleNode = complexNode.addChild(new SimpleNode("orgUnit", organisationUnit.getUid() == null ? "" : organisationUnit.getUid()));
                simpleNode.setAttribute(true);
            }
        }
        simpleNode = complexNode.addChild(new SimpleNode("value", ""));
        simpleNode.setAttribute(true);
    }
    return collectionNode;
}
Also used : ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Aggregations

CollectionNode (org.hisp.dhis.node.types.CollectionNode)30 RootNode (org.hisp.dhis.node.types.RootNode)24 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)17 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)17 SimpleNode (org.hisp.dhis.node.types.SimpleNode)16 ComplexNode (org.hisp.dhis.node.types.ComplexNode)9 User (org.hisp.dhis.user.User)8 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)5 Pager (org.hisp.dhis.common.Pager)4 Node (org.hisp.dhis.node.Node)4 Schema (org.hisp.dhis.schema.Schema)4 MessageConversation (org.hisp.dhis.webapi.webdomain.MessageConversation)4 DataElement (org.hisp.dhis.dataelement.DataElement)3 NotAuthenticatedException (org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException)3 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)2 DeleteAccessDeniedException (org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException)2 AbstractNode (org.hisp.dhis.node.AbstractNode)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 Query (org.hisp.dhis.query.Query)2 Property (org.hisp.dhis.schema.Property)2