Search in sources :

Example 56 with RootNode

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

the class TrackedEntityInstanceController method getTrackedEntityInstances.

// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseBody
public RootNode getTrackedEntityInstances(@RequestParam(required = false) String query, @RequestParam(required = false) Set<String> attribute, @RequestParam(required = false) Set<String> filter, @RequestParam(required = false) String ou, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) String program, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) Boolean followUp, @RequestParam(required = false) Date lastUpdatedStartDate, @RequestParam(required = false) Date lastUpdatedEndDate, @RequestParam(required = false) Date programStartDate, @RequestParam(required = false) Date programEnrollmentStartDate, @RequestParam(required = false) Date programEndDate, @RequestParam(required = false) Date programEnrollmentEndDate, @RequestParam(required = false) Date programIncidentStartDate, @RequestParam(required = false) Date programIncidentEndDate, @RequestParam(required = false) String trackedEntity, @RequestParam(required = false) String trackedEntityInstance, @RequestParam(required = false) EventStatus eventStatus, @RequestParam(required = false) Date eventStartDate, @RequestParam(required = false) Date eventEndDate, @RequestParam(required = false) boolean skipMeta, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) boolean totalPages, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false) boolean includeDeleted, @RequestParam(required = false) String order) throws Exception {
    programEnrollmentStartDate = ObjectUtils.firstNonNull(programEnrollmentStartDate, programStartDate);
    programEnrollmentEndDate = ObjectUtils.firstNonNull(programEnrollmentEndDate, programEndDate);
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.add(":all");
    }
    Set<String> orgUnits = TextUtils.splitToArray(ou, TextUtils.SEMICOLON);
    RootNode rootNode = NodeUtils.createMetadata();
    List<TrackedEntityInstance> trackedEntityInstances;
    TrackedEntityInstanceQueryParams queryParams = instanceService.getFromUrl(query, attribute, filter, orgUnits, ouMode, program, programStatus, followUp, lastUpdatedStartDate, lastUpdatedEndDate, programEnrollmentStartDate, programEnrollmentEndDate, programIncidentStartDate, programIncidentEndDate, trackedEntity, eventStatus, eventStartDate, eventEndDate, skipMeta, page, pageSize, totalPages, skipPaging, includeDeleted, getOrderParams(order));
    if (trackedEntityInstance == null) {
        trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, getTrackedEntityInstanceParams(fields));
    } else {
        Set<String> trackedEntityInstanceIds = TextUtils.splitToArray(trackedEntityInstance, TextUtils.SEMICOLON);
        trackedEntityInstances = trackedEntityInstanceIds != null ? trackedEntityInstanceIds.stream().map(id -> trackedEntityInstanceService.getTrackedEntityInstance(id, getTrackedEntityInstanceParams(fields))).collect(Collectors.toList()) : null;
    }
    if (queryParams.isPaging() && queryParams.isTotalPages()) {
        int count = trackedEntityInstanceService.getTrackedEntityInstanceCount(queryParams);
        Pager pager = new Pager(queryParams.getPageWithDefault(), count, queryParams.getPageSizeWithDefault());
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    rootNode.addChild(fieldFilterService.filter(TrackedEntityInstance.class, trackedEntityInstances, fields));
    return rootNode;
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) Arrays(java.util.Arrays) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) WebMessageService(org.hisp.dhis.webapi.service.WebMessageService) StringUtils(org.apache.commons.lang3.StringUtils) NodeUtils(org.hisp.dhis.node.NodeUtils) Model(org.springframework.ui.Model) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) GridUtils(org.hisp.dhis.system.grid.GridUtils) ContextService(org.hisp.dhis.webapi.service.ContextService) DxfNamespaces(org.hisp.dhis.common.DxfNamespaces) OrganisationUnitSelectionMode(org.hisp.dhis.common.OrganisationUnitSelectionMode) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) FieldFilterService(org.hisp.dhis.fieldfilter.FieldFilterService) MediaType(org.springframework.http.MediaType) CacheStrategy(org.hisp.dhis.common.cache.CacheStrategy) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Set(java.util.Set) EventStatus(org.hisp.dhis.event.EventStatus) TrackedEntityInstanceSchemaDescriptor(org.hisp.dhis.schema.descriptors.TrackedEntityInstanceSchemaDescriptor) Collectors(java.util.stream.Collectors) List(java.util.List) RootNode(org.hisp.dhis.node.types.RootNode) Joiner(com.google.common.base.Joiner) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) CollectionNode(org.hisp.dhis.node.types.CollectionNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Controller(org.springframework.stereotype.Controller) StreamUtils(org.hisp.dhis.commons.util.StreamUtils) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) HttpServletRequest(javax.servlet.http.HttpServletRequest) Lists(com.google.common.collect.Lists) ObjectUtils(org.apache.commons.lang3.ObjectUtils) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) WebMessageUtils(org.hisp.dhis.dxf2.webmessage.WebMessageUtils) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TrackedEntityInstanceService(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstanceService) ContextUtils(org.hisp.dhis.webapi.utils.ContextUtils) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) Pager(org.hisp.dhis.common.Pager) TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Grid(org.hisp.dhis.common.Grid) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) ProgramStatus(org.hisp.dhis.program.ProgramStatus) HttpStatus(org.springframework.http.HttpStatus) TextUtils(org.hisp.dhis.commons.util.TextUtils) InputStream(java.io.InputStream) RootNode(org.hisp.dhis.node.types.RootNode) Pager(org.hisp.dhis.common.Pager) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 57 with RootNode

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

the class DefaultMetadataVersionServiceTest method testShouldCreateAValidVersionsNodeTree.

@Test
public void testShouldCreateAValidVersionsNodeTree() throws Exception {
    List<MetadataVersion> versions = new ArrayList<>();
    versions.add(new MetadataVersion("test_version1", VersionType.ATOMIC));
    versions.add(new MetadataVersion("test_version2", VersionType.BEST_EFFORT));
    versions.add(new MetadataVersion("test_version3", VersionType.BEST_EFFORT));
    RootNode root = versionService.getMetadataVersionsAsNode(versions);
    ComplexNode[] versionNodes = getVersionFromNodeTree(root);
    for (int i = 0; i < versionNodes.length; i++) {
        assertEquals(versions.get(i).getName(), ((SimpleNode) versionNodes[i].getChildren().get(0)).getValue());
        assertEquals(versions.get(i).getType(), ((SimpleNode) versionNodes[i].getChildren().get(1)).getValue());
    }
    assertEquals(versions.size(), versionNodes.length);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) RootNode(org.hisp.dhis.node.types.RootNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) ArrayList(java.util.ArrayList) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 58 with RootNode

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

the class DefaultMetadataVersionServiceTest method testShouldCreateNodesWith_Name_Type_CreatedId_ImportDate.

@Test
public void testShouldCreateNodesWith_Name_Type_CreatedId_ImportDate() throws Exception {
    MetadataVersion version = new MetadataVersion("test_version1", VersionType.ATOMIC);
    version.setUid("myId");
    Date date = new Date();
    version.setImportDate(date);
    version.setCreated(date);
    version.setHashCode("2asda2d31asd3ads3dadasd");
    List<MetadataVersion> versions = new ArrayList<>();
    versions.add(version);
    RootNode root = versionService.getMetadataVersionsAsNode(versions);
    ComplexNode[] versionNodes = getVersionFromNodeTree(root);
    assertEquals(version.getName(), ((SimpleNode) versionNodes[0].getChildren().get(0)).getValue());
    assertEquals(version.getType(), ((SimpleNode) versionNodes[0].getChildren().get(1)).getValue());
    assertEquals(version.getCreated(), ((SimpleNode) versionNodes[0].getChildren().get(2)).getValue());
    assertEquals(version.getUid(), ((SimpleNode) versionNodes[0].getChildren().get(3)).getValue());
    assertEquals(version.getImportDate(), ((SimpleNode) versionNodes[0].getChildren().get(4)).getValue());
    assertEquals(version.getHashCode(), ((SimpleNode) versionNodes[0].getChildren().get(5)).getValue());
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) RootNode(org.hisp.dhis.node.types.RootNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 59 with RootNode

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

the class AuditController method getTrackedEntityDataValueAudit.

@RequestMapping(value = "trackedEntityDataValue", method = RequestMethod.GET)
@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, 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 (skipPaging) {
        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.filter(TrackedEntityDataValueAudit.class, dataValueAudits, fields).getChildren());
    return rootNode;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) RootNode(org.hisp.dhis.node.types.RootNode) Pager(org.hisp.dhis.common.Pager) TrackedEntityDataValueAudit(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit) CollectionNode(org.hisp.dhis.node.types.CollectionNode) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 60 with RootNode

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

the class DataApprovalController method getApproval.

@RequestMapping(value = STATUS_PATH, method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getApproval(@RequestParam Set<String> ds, @RequestParam(required = false) String pe, @RequestParam Date startDate, @RequestParam Date endDate, @RequestParam Set<String> ou, @RequestParam(required = false) boolean children, HttpServletResponse response) throws IOException, WebMessageException {
    List<String> fields = Lists.newArrayList(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 = new HashSet<>();
    PeriodType periodType = periodService.getPeriodTypeByName(pe);
    if (periodType != null) {
        periods.addAll(periodService.getPeriodsBetweenDates(periodType, startDate, endDate));
    } else {
        periods.addAll(periodService.getPeriodsBetweenDates(startDate, endDate));
    }
    Set<OrganisationUnit> organisationUnits = new HashSet<>();
    if (children) {
        organisationUnits.addAll(organisationUnitService.getOrganisationUnitsWithChildren(ou));
    } else {
        organisationUnits.addAll(organisationUnitService.getOrganisationUnitsByUid(ou));
    }
    DataApprovalStateResponses dataApprovalStateResponses = new DataApprovalStateResponses();
    for (DataSet dataSet : dataSets) {
        for (OrganisationUnit organisationUnit : organisationUnits) {
            for (Period period : periods) {
                dataApprovalStateResponses.add(getDataApprovalStateResponse(dataSet, organisationUnit, period));
            }
        }
    }
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.filter(DataApprovalStateResponse.class, dataApprovalStateResponses.getDataApprovalStateResponses(), fields));
    return rootNode;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) RootNode(org.hisp.dhis.node.types.RootNode) DataSet(org.hisp.dhis.dataset.DataSet) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) DataApprovalStateResponses(org.hisp.dhis.dataapproval.DataApprovalStateResponses) Period(org.hisp.dhis.period.Period) DataApprovalStateResponse(org.hisp.dhis.dataapproval.DataApprovalStateResponse) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

RootNode (org.hisp.dhis.node.types.RootNode)60 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)33 CollectionNode (org.hisp.dhis.node.types.CollectionNode)30 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)30 SimpleNode (org.hisp.dhis.node.types.SimpleNode)27 ComplexNode (org.hisp.dhis.node.types.ComplexNode)14 ArrayList (java.util.ArrayList)12 User (org.hisp.dhis.user.User)11 Pager (org.hisp.dhis.common.Pager)10 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)10 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)9 Node (org.hisp.dhis.node.Node)8 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)7 List (java.util.List)5 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 Date (java.util.Date)4 DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)4 WebMetadata (org.hisp.dhis.webapi.webdomain.WebMetadata)4 Lists (com.google.common.collect.Lists)3 IOException (java.io.IOException)3