Search in sources :

Example 26 with FieldFilterParams

use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.

the class EnrollmentController method getEnrollments.

// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@GetMapping
@ResponseBody
public RootNode getEnrollments(EnrollmentCriteria enrollmentCriteria) {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.add("enrollment,created,lastUpdated,trackedEntityType,trackedEntityInstance,program,status,orgUnit,orgUnitName,enrollmentDate,incidentDate,followup");
    }
    RootNode rootNode = NodeUtils.createMetadata();
    List<Enrollment> listEnrollments;
    if (enrollmentCriteria.getEnrollment() == null) {
        ProgramInstanceQueryParams params = enrollmentCriteriaMapper.getFromUrl(TextUtils.splitToArray(enrollmentCriteria.getOu(), TextUtils.SEMICOLON), enrollmentCriteria.getOuMode(), enrollmentCriteria.getLastUpdated(), enrollmentCriteria.getLastUpdatedDuration(), enrollmentCriteria.getProgram(), enrollmentCriteria.getProgramStatus(), enrollmentCriteria.getProgramStartDate(), enrollmentCriteria.getProgramEndDate(), enrollmentCriteria.getTrackedEntityType(), enrollmentCriteria.getTrackedEntityInstance(), enrollmentCriteria.getFollowUp(), enrollmentCriteria.getPage(), enrollmentCriteria.getPageSize(), enrollmentCriteria.isTotalPages(), PagerUtils.isSkipPaging(enrollmentCriteria.getSkipPaging(), enrollmentCriteria.getPaging()), enrollmentCriteria.isIncludeDeleted(), enrollmentCriteria.getOrder());
        Enrollments enrollments = enrollmentService.getEnrollments(params);
        if (enrollments.getPager() != null) {
            if (params.isTotalPages()) {
                rootNode.addChild(NodeUtils.createPager(enrollments.getPager()));
            } else {
                rootNode.addChild(NodeUtils.createSlimPager((SlimPager) enrollments.getPager()));
            }
        }
        listEnrollments = enrollments.getEnrollments();
    } else {
        Set<String> enrollmentIds = TextUtils.splitToArray(enrollmentCriteria.getEnrollment(), TextUtils.SEMICOLON);
        listEnrollments = enrollmentIds != null ? enrollmentIds.stream().map(enrollmentId -> enrollmentService.getEnrollment(enrollmentId)).collect(Collectors.toList()) : null;
    }
    rootNode.addChild(fieldFilterService.toCollectionNode(Enrollment.class, new FieldFilterParams(listEnrollments, fields)));
    return rootNode;
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) PathVariable(org.springframework.web.bind.annotation.PathVariable) APPLICATION_XML_VALUE(org.springframework.http.MediaType.APPLICATION_XML_VALUE) RequestParam(org.springframework.web.bind.annotation.RequestParam) Autowired(org.springframework.beans.factory.annotation.Autowired) NodeUtils(org.hisp.dhis.node.NodeUtils) Model(org.springframework.ui.Model) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PutMapping(org.springframework.web.bind.annotation.PutMapping) Map(java.util.Map) PagerUtils(org.hisp.dhis.common.PagerUtils) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) EnrollmentService(org.hisp.dhis.dxf2.events.enrollment.EnrollmentService) PostMapping(org.springframework.web.bind.annotation.PostMapping) ImportEnrollmentsTask(org.hisp.dhis.dxf2.events.enrollment.ImportEnrollmentsTask) ProgramInstanceQueryParams(org.hisp.dhis.program.ProgramInstanceQueryParams) ContextService(org.hisp.dhis.webapi.service.ContextService) FieldFilterService(org.hisp.dhis.fieldfilter.FieldFilterService) Set(java.util.Set) Collectors(java.util.stream.Collectors) Enrollments(org.hisp.dhis.dxf2.events.enrollment.Enrollments) EnrollmentCriteria(org.hisp.dhis.webapi.controller.event.webrequest.EnrollmentCriteria) List(java.util.List) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) ProgramInstanceService(org.hisp.dhis.program.ProgramInstanceService) AsyncTaskExecutor(org.hisp.dhis.common.AsyncTaskExecutor) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) RootNode(org.hisp.dhis.node.types.RootNode) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) WebMessageUtils.notFound(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.notFound) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ENROLLMENT_IMPORT(org.hisp.dhis.scheduling.JobType.ENROLLMENT_IMPORT) 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) SlimPager(org.hisp.dhis.common.SlimPager) WebMessageUtils.importSummaries(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.importSummaries) EnrollmentCriteriaMapper(org.hisp.dhis.webapi.controller.event.mapper.EnrollmentCriteriaMapper) WebMessageUtils.importSummary(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.importSummary) GetMapping(org.springframework.web.bind.annotation.GetMapping) WebMessageUtils.jobConfigurationReport(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.jobConfigurationReport) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) ContextUtils(org.hisp.dhis.webapi.utils.ContextUtils) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) IOException(java.io.IOException) APPLICATION_JSON_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_VALUE) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) HttpStatus(org.springframework.http.HttpStatus) CurrentUserService(org.hisp.dhis.user.CurrentUserService) InputStream(java.io.InputStream) TextUtils(org.hisp.dhis.commons.util.TextUtils) RootNode(org.hisp.dhis.node.types.RootNode) SlimPager(org.hisp.dhis.common.SlimPager) Enrollments(org.hisp.dhis.dxf2.events.enrollment.Enrollments) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) ProgramInstanceQueryParams(org.hisp.dhis.program.ProgramInstanceQueryParams) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 27 with FieldFilterParams

use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.

the class DimensionController method getItems.

@SuppressWarnings("unchecked")
@GetMapping("/{uid}/items")
@ResponseBody
public RootNode getItems(@PathVariable String uid, @RequestParam Map<String, String> parameters, OrderParams orderParams) throws QueryParserException {
    List<String> fields = newArrayList(contextService.getParameterValues("fields"));
    List<String> filters = newArrayList(contextService.getParameterValues("filter"));
    List<Order> orders = orderParams.getOrders(getSchema(DimensionalItemObject.class));
    WebOptions options = new WebOptions(parameters);
    if (fields.isEmpty()) {
        fields.addAll(Preset.defaultPreset().getFields());
    }
    // This is the base list used in this flow. It contains only items
    // allowed to the current user.
    List<DimensionalItemObject> readableItems = dimensionService.getCanReadDimensionItems(uid);
    // This is needed for two reasons:
    // 1) We are doing in-memory paging;
    // 2) We have to count all items respecting the filtering.
    Query queryForCount = queryService.getQueryFromUrl(DimensionalItemObject.class, filters, orders);
    queryForCount.setObjects(readableItems);
    List<DimensionalItemObject> forCountItems = (List<DimensionalItemObject>) queryService.query(queryForCount);
    Query query = queryService.getQueryFromUrl(DimensionalItemObject.class, filters, orders, getPaginationData(options));
    query.setObjects(readableItems);
    query.setDefaultOrder();
    List<DimensionalItemObject> paginatedItems = (List<DimensionalItemObject>) queryService.query(query);
    RootNode rootNode = NodeUtils.createMetadata();
    CollectionNode collectionNode = rootNode.addChild(fieldFilterService.toCollectionNode(DimensionalItemObject.class, new FieldFilterParams(paginatedItems, fields)));
    collectionNode.setName("items");
    for (Node node : collectionNode.getChildren()) {
        ((AbstractNode) node).setName("item");
    }
    // Adding pagination elements to the root node.
    final int totalOfItems = isNotEmpty(forCountItems) ? forCountItems.size() : 0;
    dimensionItemPageHandler.addPaginationToNodeIfEnabled(rootNode, options, uid, totalOfItems);
    return rootNode;
}
Also used : Order(org.hisp.dhis.query.Order) RootNode(org.hisp.dhis.node.types.RootNode) Query(org.hisp.dhis.query.Query) AbstractNode(org.hisp.dhis.node.AbstractNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) AbstractNode(org.hisp.dhis.node.AbstractNode) Node(org.hisp.dhis.node.Node) RootNode(org.hisp.dhis.node.types.RootNode) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) CollectionNode(org.hisp.dhis.node.types.CollectionNode) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 28 with FieldFilterParams

use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.

the class DimensionController method getDimensionsForDataSet.

@GetMapping("/dataSet/{uid}")
@ResponseBody
public RootNode getDimensionsForDataSet(@PathVariable String uid, @RequestParam(value = "links", defaultValue = "true", required = false) Boolean links, Model model, HttpServletResponse response) throws WebMessageException {
    WebMetadata metadata = new WebMetadata();
    List<String> fields = newArrayList(contextService.getParameterValues("fields"));
    DataSet dataSet = identifiableObjectManager.get(DataSet.class, uid);
    if (dataSet == null) {
        throw new WebMessageException(notFound("Data set not found: " + uid));
    }
    List<DimensionalObject> dimensions = new ArrayList<>();
    dimensions.addAll(dataSet.getCategoryCombo().getCategories().stream().filter(ca -> !ca.isDefault()).collect(toList()));
    dimensions.addAll(dataSet.getCategoryOptionGroupSets());
    dimensions = dimensionService.getCanReadObjects(dimensions);
    metadata.setDimensions(dimensions.stream().map(dim -> dimensionService.getDimensionalObjectCopy(dim.getUid(), true)).collect(toList()));
    if (links) {
        linkService.generateLinks(metadata, false);
    }
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.toCollectionNode(getEntityClass(), new FieldFilterParams(metadata.getDimensions(), 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) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) DimensionalObject(org.hisp.dhis.common.DimensionalObject) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 29 with FieldFilterParams

use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.

the class ResponseHandler method addResultsToNode.

/**
 * Appends the given dimensionalItemsFound (the collection of results) and
 * fields to the rootNode.
 *
 * @param rootNode the main response root node
 * @param dimensionalItemsFound the collection of results
 * @param fields the list of fields to be returned
 */
void addResultsToNode(final RootNode rootNode, final List<DataItem> dimensionalItemsFound, final Set<String> fields) {
    final CollectionNode collectionNode = fieldFilterService.toConcreteClassCollectionNode(DataItem.class, new FieldFilterParams(dimensionalItemsFound, newArrayList(fields)), "dataItems", DXF_2_0);
    rootNode.addChild(collectionNode);
}
Also used : FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) CollectionNode(org.hisp.dhis.node.types.CollectionNode)

Example 30 with FieldFilterParams

use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.

the class ValidationResultController method getObjectList.

@GetMapping
@ResponseBody
public RootNode getObjectList(ValidationResultQuery query, HttpServletResponse response) {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    List<ValidationResult> validationResults = validationResultService.getValidationResults(query);
    RootNode rootNode = NodeUtils.createMetadata();
    if (!query.isSkipPaging()) {
        query.setTotal(validationResultService.countValidationResults(query));
        rootNode.addChild(NodeUtils.createPager(query.getPager()));
    }
    rootNode.addChild(fieldFilterService.toCollectionNode(ValidationResult.class, new FieldFilterParams(validationResults, fields)));
    setNoStore(response);
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) ValidationResult(org.hisp.dhis.validation.ValidationResult) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)32 RootNode (org.hisp.dhis.node.types.RootNode)28 GetMapping (org.springframework.web.bind.annotation.GetMapping)25 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)23 Pager (org.hisp.dhis.common.Pager)10 CollectionNode (org.hisp.dhis.node.types.CollectionNode)10 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)8 ArrayList (java.util.ArrayList)7 Query (org.hisp.dhis.query.Query)6 WebMetadata (org.hisp.dhis.webapi.webdomain.WebMetadata)5 DataElement (org.hisp.dhis.dataelement.DataElement)4 DataSet (org.hisp.dhis.dataset.DataSet)4 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)4 Test (org.junit.jupiter.api.Test)4 List (java.util.List)3 Map (java.util.Map)3 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)3 Order (org.hisp.dhis.query.Order)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2