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