Search in sources :

Example 1 with CollectionNode

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;
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) RootNode(org.hisp.dhis.node.types.RootNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Example 2 with CollectionNode

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;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) DataApprovalAuditQueryParams(org.hisp.dhis.dataapproval.DataApprovalAuditQueryParams) Pager(org.hisp.dhis.common.Pager) DataApprovalAudit(org.hisp.dhis.dataapproval.DataApprovalAudit) CollectionNode(org.hisp.dhis.node.types.CollectionNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with CollectionNode

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) RootNode(org.hisp.dhis.node.types.RootNode) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) CollectionNode(org.hisp.dhis.node.types.CollectionNode) DataElement(org.hisp.dhis.dataelement.DataElement) Pager(org.hisp.dhis.common.Pager) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) TrackedEntityDataValueAudit(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with CollectionNode

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;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Pager(org.hisp.dhis.common.Pager) TrackedEntityAttributeValueAudit(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAudit) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) CollectionNode(org.hisp.dhis.node.types.CollectionNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with CollectionNode

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;
}
Also used : ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode)

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