Search in sources :

Example 86 with RootNode

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

the class AuditController method getTrackedEntityAttributeValueAudit.

@GetMapping("trackedEntityAttributeValue")
@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) 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"));
    List<TrackedEntityAttribute> trackedEntityAttributes = getTrackedEntityAttributes(tea);
    List<TrackedEntityInstance> trackedEntityInstances = getTrackedEntityInstances(tei);
    List<TrackedEntityAttributeValueAudit> attributeValueAudits;
    Pager pager = null;
    if (PagerUtils.isSkipPaging(skipPaging, paging)) {
        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.toCollectionNode(TrackedEntityAttributeValueAudit.class, new FieldFilterParams(attributeValueAudits, fields)).getChildren());
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) CollectionNode(org.hisp.dhis.node.types.CollectionNode) Pager(org.hisp.dhis.common.Pager) TrackedEntityAttributeValueAudit(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAudit) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 87 with RootNode

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

the class AuditController method getTrackedEntityDataValueAudit.

@GetMapping("trackedEntityDataValue")
@ResponseBody
public RootNode getTrackedEntityDataValueAudit(@RequestParam(required = false, defaultValue = "") List<String> de, @RequestParam(required = false, defaultValue = "") List<String> psi, @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 = getDataElements(de);
    List<ProgramStageInstance> programStageInstances = getProgramStageInstances(psi);
    List<TrackedEntityDataValueAudit> dataValueAudits;
    Pager pager = null;
    if (PagerUtils.isSkipPaging(skipPaging, paging)) {
        dataValueAudits = trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType);
    } else {
        int total = trackedEntityDataValueAuditService.countTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType);
        pager = new Pager(page, total, pageSize);
        dataValueAudits = trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType, pager.getOffset(), pager.getPageSize());
    }
    RootNode rootNode = NodeUtils.createMetadata();
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild(new CollectionNode("trackedEntityDataValueAudits", true));
    trackedEntityAttributeValueAudits.addChildren(fieldFilterService.toCollectionNode(TrackedEntityDataValueAudit.class, new FieldFilterParams(dataValueAudits, fields)).getChildren());
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) DataElement(org.hisp.dhis.dataelement.DataElement) Pager(org.hisp.dhis.common.Pager) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) TrackedEntityDataValueAudit(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 88 with RootNode

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

the class DataApprovalController method getApproval.

@GetMapping(value = STATUS_PATH, produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getApproval(@RequestParam Set<String> ds, @RequestParam(required = false) String pe, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam Set<String> ou, @RequestParam(required = false) boolean children, HttpServletResponse response) throws WebMessageException, BadRequestException {
    List<String> fields = new ArrayList<>(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
        List<String> defaults = new ArrayList<>();
        defaults.add("period[id,name,code],organisationUnit[id,name,created,lastUpdated],dataSet[code,name,created,lastUpdated,id]");
        fields.addAll(defaults);
    }
    Set<DataSet> dataSets = parseDataSetsWithWorkflow(ds);
    Set<Period> periods = parsePeriods(pe, startDate, endDate);
    Set<OrganisationUnit> organisationUnits = new HashSet<>();
    if (children) {
        organisationUnits.addAll(organisationUnitService.getOrganisationUnitsWithChildren(ou));
    } else {
        organisationUnits.addAll(organisationUnitService.getOrganisationUnitsByUid(ou));
    }
    List<DataApprovalStateResponse> responses = new ArrayList<>();
    for (DataSet dataSet : dataSets) {
        for (OrganisationUnit organisationUnit : organisationUnits) {
            for (Period period : periods) {
                responses.add(getDataApprovalStateResponse(dataSet, organisationUnit, period));
            }
        }
    }
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.toCollectionNode(DataApprovalStateResponse.class, new FieldFilterParams(responses, fields)));
    return rootNode;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) RootNode(org.hisp.dhis.node.types.RootNode) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DataApprovalStateResponse(org.hisp.dhis.dataapproval.DataApprovalStateResponse) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) HashSet(java.util.HashSet) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 89 with RootNode

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

the class DataSetController method getCategoryCombinations.

@GetMapping("/{uid}/categoryCombos")
@ResponseBody
public RootNode getCategoryCombinations(@PathVariable("uid") String uid, HttpServletRequest request, TranslateParams translateParams, HttpServletResponse response) throws Exception {
    setUserContext(translateParams);
    DataSet dataSet = manager.get(DataSet.class, uid);
    if (dataSet == null) {
        throw new WebMessageException(conflict("Data set does not exist: " + uid));
    }
    List<CategoryCombo> categoryCombos = dataSet.getDataSetElements().stream().map(DataSetElement::getResolvedCategoryCombo).distinct().collect(Collectors.toList());
    Collections.sort(categoryCombos);
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.toCollectionNode(CategoryCombo.class, new FieldFilterParams(categoryCombos, fields)));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) CategoryCombo(org.hisp.dhis.category.CategoryCombo) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) DataSetElement(org.hisp.dhis.dataset.DataSetElement) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 90 with RootNode

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

the class DeletedObjectController method getDeletedObjects.

@GetMapping
@PreAuthorize("hasRole('ALL')")
public RootNode getDeletedObjects(DeletedObjectQuery query) {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    int totalDeletedObjects = deletedObjectService.countDeletedObjects(query);
    query.setTotal(totalDeletedObjects);
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    List<DeletedObject> deletedObjects = deletedObjectService.getDeletedObjects(query);
    RootNode rootNode = NodeUtils.createMetadata();
    if (!query.isSkipPaging()) {
        query.setTotal(totalDeletedObjects);
        rootNode.addChild(NodeUtils.createPager(query.getPager()));
    }
    rootNode.addChild(fieldFilterService.toCollectionNode(DeletedObject.class, new FieldFilterParams(deletedObjects, fields)));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) DeletedObject(org.hisp.dhis.deletedobject.DeletedObject) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

RootNode (org.hisp.dhis.node.types.RootNode)112 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)59 CollectionNode (org.hisp.dhis.node.types.CollectionNode)50 SimpleNode (org.hisp.dhis.node.types.SimpleNode)40 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)30 GetMapping (org.springframework.web.bind.annotation.GetMapping)29 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)27 Pager (org.hisp.dhis.common.Pager)26 User (org.hisp.dhis.user.User)25 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)24 ComplexNode (org.hisp.dhis.node.types.ComplexNode)20 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)17 Test (org.junit.jupiter.api.Test)16 ArrayList (java.util.ArrayList)15 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)13 Node (org.hisp.dhis.node.Node)11 WebMetadata (org.hisp.dhis.webapi.webdomain.WebMetadata)10 List (java.util.List)9 Query (org.hisp.dhis.query.Query)9 DataSet (org.hisp.dhis.dataset.DataSet)7