Search in sources :

Example 1 with RootNode

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

the class DimensionController method getItems.

@SuppressWarnings("unchecked")
@RequestMapping(value = "/{uid}/items", method = RequestMethod.GET)
@ResponseBody
public RootNode getItems(@PathVariable String uid, @RequestParam Map<String, String> parameters, Model model, HttpServletRequest request, HttpServletResponse response) throws QueryParserException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.defaultPreset().getFields());
    }
    List<DimensionalItemObject> items = dimensionService.getCanReadDimensionItems(uid);
    Query query = queryService.getQueryFromUrl(getEntityClass(), filters, new ArrayList<>());
    query.setObjects(items);
    query.setDefaultOrder();
    items = (List<DimensionalItemObject>) queryService.query(query);
    RootNode rootNode = NodeUtils.createMetadata();
    CollectionNode collectionNode = rootNode.addChild(fieldFilterService.filter(getEntityClass(), items, fields));
    collectionNode.setName("items");
    for (Node node : collectionNode.getChildren()) {
        ((AbstractNode) node).setName("item");
    }
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Query(org.hisp.dhis.query.Query) AbstractNode(org.hisp.dhis.node.AbstractNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) AbstractNode(org.hisp.dhis.node.AbstractNode) Node(org.hisp.dhis.node.Node) RootNode(org.hisp.dhis.node.types.RootNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with RootNode

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

the class DimensionController method getDimensionsForDataSet.

@RequestMapping(value = "/dataSet/{uid}", method = RequestMethod.GET)
@ResponseBody
public RootNode getDimensionsForDataSet(@PathVariable String uid, @RequestParam(value = "links", defaultValue = "true", required = false) Boolean links, Model model, HttpServletResponse response) throws WebMessageException {
    WebMetadata metadata = new WebMetadata();
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    DataSet dataSet = identifiableObjectManager.get(DataSet.class, uid);
    if (dataSet == null) {
        throw new WebMessageException(WebMessageUtils.notFound("DataSet not found for uid: " + uid));
    }
    if (!dataSet.hasCategoryCombo()) {
        throw new WebMessageException(WebMessageUtils.conflict("Data set does not have a category combination: " + uid));
    }
    List<DimensionalObject> dimensions = new ArrayList<>();
    dimensions.addAll(dataSet.getCategoryCombo().getCategories());
    dimensions.addAll(dataSet.getCategoryOptionGroupSets());
    dimensions = dimensionService.getCanReadObjects(dimensions);
    for (DimensionalObject dim : dimensions) {
        metadata.getDimensions().add(dimensionService.getDimensionalObjectCopy(dim.getUid(), true));
    }
    if (links) {
        linkService.generateLinks(metadata, false);
    }
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.filter(getEntityClass(), metadata.getDimensions(), fields));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ArrayList(java.util.ArrayList) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) DimensionalObject(org.hisp.dhis.common.DimensionalObject) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with RootNode

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

the class DimensionController method getDimensionConstraints.

@RequestMapping(value = "/constraints", method = RequestMethod.GET)
@ResponseBody
public RootNode getDimensionConstraints(@RequestParam(value = "links", defaultValue = "true", required = false) Boolean links) {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    List<DimensionalObject> dimensionConstraints = dimensionService.getDimensionConstraints();
    if (links) {
        linkService.generateLinks(dimensionConstraints, false);
    }
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.filter(getEntityClass(), dimensionConstraints, fields));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) DimensionalObject(org.hisp.dhis.common.DimensionalObject) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with RootNode

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

the class MessageConversationController method removeUserFromMessageConversations.

//--------------------------------------------------------------------------
// Remove a user from one or more MessageConversations (batch operation)
//--------------------------------------------------------------------------
@RequestMapping(method = RequestMethod.DELETE, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode removeUserFromMessageConversations(@RequestParam("mc") List<String> mcUids, @RequestParam(value = "user", required = false) String userUid, HttpServletResponse response) throws DeleteAccessDeniedException {
    RootNode responseNode = new RootNode("response");
    User currentUser = currentUserService.getCurrentUser();
    User user = userUid == null ? currentUser : userService.getUser(userUid);
    if (user == null) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        responseNode.addChild(new SimpleNode("message", "User does not exist: " + userUid));
        return responseNode;
    }
    if (!canModifyUserConversation(currentUser, user)) {
        throw new DeleteAccessDeniedException("Not authorized to modify user: " + user.getUid());
    }
    Collection<org.hisp.dhis.message.MessageConversation> messageConversations = messageService.getMessageConversations(user, mcUids);
    if (messageConversations.isEmpty()) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        responseNode.addChild(new SimpleNode("message", "No MessageConversations found for the given UIDs."));
        return responseNode;
    }
    CollectionNode removed = responseNode.addChild(new CollectionNode("removed"));
    for (org.hisp.dhis.message.MessageConversation mc : messageConversations) {
        if (mc.remove(user)) {
            messageService.updateMessageConversation(mc);
            removed.addChild(new SimpleNode("uid", mc.getUid()));
        }
    }
    response.setStatus(HttpServletResponse.SC_OK);
    return responseNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) User(org.hisp.dhis.user.User) DeleteAccessDeniedException(org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException) 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 5 with RootNode

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

the class MessageConversationController method markMessageConversationFollowup.

//--------------------------------------------------------------------------
// Mark conversations for follow up
//--------------------------------------------------------------------------
@RequestMapping(value = "followup", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode markMessageConversationFollowup(@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("markedFollowup"));
    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)

Aggregations

RootNode (org.hisp.dhis.node.types.RootNode)112 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)59 CollectionNode (org.hisp.dhis.node.types.CollectionNode)50 SimpleNode (org.hisp.dhis.node.types.SimpleNode)40 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)30 GetMapping (org.springframework.web.bind.annotation.GetMapping)29 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)27 Pager (org.hisp.dhis.common.Pager)26 User (org.hisp.dhis.user.User)25 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)24 ComplexNode (org.hisp.dhis.node.types.ComplexNode)20 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)17 Test (org.junit.jupiter.api.Test)16 ArrayList (java.util.ArrayList)15 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)13 Node (org.hisp.dhis.node.Node)11 WebMetadata (org.hisp.dhis.webapi.webdomain.WebMetadata)10 List (java.util.List)9 Query (org.hisp.dhis.query.Query)9 DataSet (org.hisp.dhis.dataset.DataSet)7