Search in sources :

Example 16 with CollectionNode

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

the class DefaultDataValueSetService method getDataValueSetTemplate.

// -------------------------------------------------------------------------
// Template
// -------------------------------------------------------------------------
@Override
public RootNode getDataValueSetTemplate(DataSet dataSet, Period period, List<String> orgUnits, boolean writeComments, String ouScheme, String deScheme) {
    RootNode rootNode = new RootNode("dataValueSet");
    rootNode.setNamespace(DxfNamespaces.DXF_2_0);
    rootNode.setComment("Data set: " + dataSet.getDisplayName() + " (" + dataSet.getUid() + ")");
    CollectionNode collectionNode = rootNode.addChild(new CollectionNode("dataValues"));
    collectionNode.setWrapping(false);
    if (orgUnits.isEmpty()) {
        for (DataElement dataElement : dataSet.getDataElements()) {
            CollectionNode collection = getDataValueTemplate(dataElement, deScheme, null, ouScheme, period, writeComments);
            collectionNode.addChildren(collection.getChildren());
        }
    } else {
        for (String orgUnit : orgUnits) {
            OrganisationUnit organisationUnit = identifiableObjectManager.search(OrganisationUnit.class, orgUnit);
            if (organisationUnit == null) {
                continue;
            }
            for (DataElement dataElement : dataSet.getDataElements()) {
                CollectionNode collection = getDataValueTemplate(dataElement, deScheme, organisationUnit, ouScheme, period, writeComments);
                collectionNode.addChildren(collection.getChildren());
            }
        }
    }
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) CollectionNode(org.hisp.dhis.node.types.CollectionNode)

Example 17 with CollectionNode

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

the class MeController method getCurrentUser.

@RequestMapping(value = "", method = RequestMethod.GET)
public void getCurrentUser(HttpServletResponse response) throws Exception {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    User currentUser = currentUserService.getCurrentUser();
    if (currentUser == null) {
        throw new NotAuthenticatedException();
    }
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    CollectionNode collectionNode = fieldFilterService.filter(User.class, Collections.singletonList(currentUser), fields);
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    RootNode rootNode = NodeUtils.createRootNode(collectionNode.getChildren().get(0));
    if (fieldsContains("settings", fields)) {
        rootNode.addChild(new ComplexNode("settings")).addChildren(NodeUtils.createSimples(userSettingService.getUserSettingsWithFallbackByUserAsMap(currentUser, USER_SETTING_NAMES, true)));
    }
    if (fieldsContains("authorities", fields)) {
        rootNode.addChild(new CollectionNode("authorities")).addChildren(NodeUtils.createSimples(currentUser.getUserCredentials().getAllAuthorities()));
    }
    nodeService.serialize(rootNode, "application/json", response.getOutputStream());
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) NotAuthenticatedException(org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException) ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode)

Example 18 with CollectionNode

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

Example 19 with CollectionNode

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

the class SchemaController method getSchemas.

@RequestMapping
@ResponseBody
public RootNode getSchemas() {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.add("*");
    }
    Schemas schemas = new Schemas(schemaService.getSortedSchemas());
    linkService.generateSchemaLinks(schemas.getSchemas());
    RootNode rootNode = NodeUtils.createRootNode("schemas");
    CollectionNode collectionNode = fieldFilterService.filter(Schema.class, schemas.getSchemas(), fields);
    collectionNode.setWrapping(false);
    rootNode.addChild(collectionNode);
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) Schemas(org.hisp.dhis.schema.Schemas) CollectionNode(org.hisp.dhis.node.types.CollectionNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 20 with CollectionNode

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

the class SchemaController method getSchema.

@RequestMapping(value = "/{type}", method = RequestMethod.GET)
@ResponseBody
public RootNode getSchema(@PathVariable String type) {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.add("*");
    }
    Schema schema = getSchemaFromType(type);
    if (schema != null) {
        linkService.generateSchemaLinks(schema);
        CollectionNode collectionNode = fieldFilterService.filter(Schema.class, Collections.singletonList(schema), fields);
        return NodeUtils.createRootNode(collectionNode.getChildren().get(0));
    }
    throw new HttpClientErrorException(HttpStatus.NOT_FOUND, "Type " + type + " does not exist.");
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) Schema(org.hisp.dhis.schema.Schema) CollectionNode(org.hisp.dhis.node.types.CollectionNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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