use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class NodeUtils method createRootNode.
public static RootNode createRootNode(String name) {
RootNode rootNode = new RootNode(name);
rootNode.setDefaultNamespace(DxfNamespaces.DXF_2_0);
rootNode.setNamespace(DxfNamespaces.DXF_2_0);
return rootNode;
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class MetadataExportControllerUtilsTest method createResponseEntityAsDownload.
@Test
void createResponseEntityAsDownload() {
final RootNode rootNode = new RootNode("test");
final ResponseEntity<RootNode> responseEntity = MetadataExportControllerUtils.createResponseEntity(rootNode, true);
Assertions.assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
Assertions.assertSame(rootNode, responseEntity.getBody());
Assertions.assertEquals("attachment; filename=metadata", responseEntity.getHeaders().getFirst(HttpHeaders.CONTENT_DISPOSITION));
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class MetadataExportControllerUtilsTest method createResponseEntity.
@Test
void createResponseEntity() {
final RootNode rootNode = new RootNode("test");
final ResponseEntity<RootNode> responseEntity = MetadataExportControllerUtils.createResponseEntity(rootNode, false);
Assertions.assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
Assertions.assertSame(rootNode, responseEntity.getBody());
Assertions.assertFalse(responseEntity.getHeaders().containsKey(HttpHeaders.CONTENT_DISPOSITION));
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class AbstractFullReadOnlyController method getCollectionItem.
@GetMapping("/{uid}/{property}/{itemId}")
@ResponseBody
public RootNode getCollectionItem(@PathVariable("uid") String pvUid, @PathVariable("property") String pvProperty, @PathVariable("itemId") String pvItemId, @RequestParam Map<String, String> parameters, TranslateParams translateParams, HttpServletResponse response, @CurrentUser User currentUser) throws Exception {
setUserContext(currentUser, translateParams);
try {
if (!aclService.canRead(currentUser, getEntityClass())) {
throw new ReadAccessDeniedException("You don't have the proper permissions to read objects of this type.");
}
RootNode rootNode = getObjectInternal(pvUid, parameters, Lists.newArrayList(), Lists.newArrayList(pvProperty + "[:all]"), currentUser);
// TODO optimize this using field filter (collection filtering)
if (!rootNode.getChildren().isEmpty() && rootNode.getChildren().get(0).isCollection()) {
rootNode.getChildren().get(0).getChildren().stream().filter(Node::isComplex).forEach(node -> {
node.getChildren().stream().filter(child -> child.isSimple() && child.getName().equals("id") && !((SimpleNode) child).getValue().equals(pvItemId)).forEach(child -> rootNode.getChildren().get(0).removeChild(node));
});
}
if (rootNode.getChildren().isEmpty() || rootNode.getChildren().get(0).getChildren().isEmpty()) {
throw new WebMessageException(notFound(pvProperty + " with ID " + pvItemId + " could not be found."));
}
cachePrivate(response);
return rootNode;
} finally {
UserContext.reset();
}
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class AuditController method getAggregateDataValueAudit.
@GetMapping("dataValue")
@ResponseBody
public RootNode getAggregateDataValueAudit(@RequestParam(required = false, defaultValue = "") List<String> ds, @RequestParam(required = false, defaultValue = "") List<String> de, @RequestParam(required = false, defaultValue = "") List<String> pe, @RequestParam(required = false, defaultValue = "") List<String> ou, @RequestParam(required = false) String co, @RequestParam(required = false) String cc, @RequestParam(required = false) AuditType auditType, @RequestParam(required = false) Boolean skipPaging, @RequestParam(required = false) Boolean paging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) throws WebMessageException {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
List<DataElement> dataElements = new ArrayList<>();
dataElements.addAll(getDataElements(de));
dataElements.addAll(getDataElementsByDataSet(ds));
List<Period> periods = getPeriods(pe);
List<OrganisationUnit> organisationUnits = getOrganisationUnit(ou);
CategoryOptionCombo categoryOptionCombo = getCategoryOptionCombo(co);
CategoryOptionCombo attributeOptionCombo = getAttributeOptionCombo(cc);
List<DataValueAudit> dataValueAudits;
Pager pager = null;
if (PagerUtils.isSkipPaging(skipPaging, paging)) {
dataValueAudits = dataValueAuditService.getDataValueAudits(dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType);
} else {
int total = dataValueAuditService.countDataValueAudits(dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType);
pager = new Pager(page, total, pageSize);
dataValueAudits = dataValueAuditService.getDataValueAudits(dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType, pager.getOffset(), pager.getPageSize());
}
RootNode rootNode = NodeUtils.createMetadata();
if (pager != null) {
rootNode.addChild(NodeUtils.createPager(pager));
}
CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild(new CollectionNode("dataValueAudits", true));
trackedEntityAttributeValueAudits.addChildren(fieldFilterService.toCollectionNode(DataValueAudit.class, new FieldFilterParams(dataValueAudits, fields)).getChildren());
return rootNode;
}
Aggregations