use of org.hisp.dhis.node.types.CollectionNode in project dhis2-core by dhis2.
the class DefaultMetadataVersionService method getMetadataVersionsAsNode.
@Override
public RootNode getMetadataVersionsAsNode(List<MetadataVersion> versions) {
RootNode rootNode = NodeUtils.createRootNode("metadataversions");
CollectionNode collectionNode = new CollectionNode("metadataversions", true);
rootNode.addChild(collectionNode);
for (MetadataVersion version : versions) {
ComplexNode complexNode = new ComplexNode("");
complexNode.addChild(new SimpleNode("name", version.getName()));
complexNode.addChild(new SimpleNode("type", version.getType()));
complexNode.addChild(new SimpleNode("created", version.getCreated()));
complexNode.addChild(new SimpleNode("id", version.getUid()));
complexNode.addChild(new SimpleNode("importdate", version.getImportDate()));
complexNode.addChild(new SimpleNode("hashCode", version.getHashCode()));
collectionNode.addChild(complexNode);
}
return rootNode;
}
use of org.hisp.dhis.node.types.CollectionNode in project dhis2-core by dhis2.
the class AuditController method getDataApprovalAudit.
@RequestMapping(value = "dataApproval", method = RequestMethod.GET)
@ResponseBody
public RootNode getDataApprovalAudit(@RequestParam(required = false, defaultValue = "") List<String> dal, @RequestParam(required = false, defaultValue = "") List<String> wf, @RequestParam(required = false, defaultValue = "") List<String> ou, @RequestParam(required = false, defaultValue = "") List<String> aoc, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) boolean skipPaging, @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());
}
DataApprovalAuditQueryParams params = new DataApprovalAuditQueryParams();
params.setLevels(new HashSet<>(getDataApprovalLevel(dal)));
params.setWorkflows(new HashSet<>(getDataApprovalWorkflow(wf)));
params.setOrganisationUnits(new HashSet<>(getOrganisationUnit(ou)));
params.setAttributeOptionCombos(new HashSet<>(getCategoryOptionCombo(aoc)));
params.setStartDate(startDate);
params.setEndDate(endDate);
List<DataApprovalAudit> audits = dataApprovalAuditService.getDataApprovalAudits(params);
Pager pager = null;
RootNode rootNode = NodeUtils.createMetadata();
if (!skipPaging) {
pager = new Pager(page, audits.size(), pageSize);
audits = audits.subList(pager.getOffset(), pager.getOffset() + pager.getPageSize() < audits.size() ? pager.getOffset() + pager.getPageSize() : audits.size());
rootNode.addChild(NodeUtils.createPager(pager));
}
CollectionNode dataApprovalAudits = rootNode.addChild(new CollectionNode("dataApprovalAudits", true));
dataApprovalAudits.addChildren(fieldFilterService.filter(DataApprovalAudit.class, audits, fields).getChildren());
return rootNode;
}
use of org.hisp.dhis.node.types.CollectionNode in project dhis2-core by dhis2.
the class AuditController method getAggregateDataValueAudit.
@RequestMapping(value = "dataValue", method = RequestMethod.GET)
@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, 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);
DataElementCategoryOptionCombo categoryOptionCombo = getCategoryOptionCombo(co);
DataElementCategoryOptionCombo attributeOptionCombo = getAttributeOptionCombo(cc);
List<DataValueAudit> dataValueAudits;
Pager pager = null;
if (skipPaging) {
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.filter(DataValueAudit.class, dataValueAudits, fields).getChildren());
return rootNode;
}
use of org.hisp.dhis.node.types.CollectionNode in project dhis2-core by dhis2.
the class AuditController method getTrackedEntityAttributeValueAudit.
@RequestMapping(value = "trackedEntityAttributeValue", method = RequestMethod.GET)
@ResponseBody
public RootNode getTrackedEntityAttributeValueAudit(@RequestParam(required = false, defaultValue = "") List<String> tea, @RequestParam(required = false, defaultValue = "") List<String> tei, @RequestParam(required = false) AuditType auditType, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) throws WebMessageException {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
List<TrackedEntityAttribute> trackedEntityAttributes = getTrackedEntityAttributes(tea);
List<TrackedEntityInstance> trackedEntityInstances = getTrackedEntityInstances(tei);
List<TrackedEntityAttributeValueAudit> attributeValueAudits;
Pager pager = null;
if (skipPaging) {
attributeValueAudits = trackedEntityAttributeValueAuditService.getTrackedEntityAttributeValueAudits(trackedEntityAttributes, trackedEntityInstances, auditType);
} else {
int total = trackedEntityAttributeValueAuditService.countTrackedEntityAttributeValueAudits(trackedEntityAttributes, trackedEntityInstances, auditType);
pager = new Pager(page, total, pageSize);
attributeValueAudits = trackedEntityAttributeValueAuditService.getTrackedEntityAttributeValueAudits(trackedEntityAttributes, trackedEntityInstances, auditType, pager.getOffset(), pager.getPageSize());
}
RootNode rootNode = NodeUtils.createMetadata();
if (pager != null) {
rootNode.addChild(NodeUtils.createPager(pager));
}
CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild(new CollectionNode("trackedEntityAttributeValueAudits", true));
trackedEntityAttributeValueAudits.addChildren(fieldFilterService.filter(TrackedEntityAttributeValueAudit.class, attributeValueAudits, fields).getChildren());
return rootNode;
}
use of org.hisp.dhis.node.types.CollectionNode in project dhis2-core by dhis2.
the class DefaultFieldFilterService method filter.
@Override
public ComplexNode filter(Object object, List<String> fieldList) {
Assert.notNull(object, "Object cannot be null");
CollectionNode collectionNode = filter(object.getClass(), Lists.newArrayList(object), fieldList);
if (collectionNode.getChildren().size() > 0) {
return (ComplexNode) collectionNode.getChildren().get(0);
}
return null;
}
Aggregations