Search in sources :

Example 6 with FieldFilterParams

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

the class DimensionController method getDimensionConstraints.

@GetMapping("/constraints")
@ResponseBody
public RootNode getDimensionConstraints(@RequestParam(value = "links", defaultValue = "true", required = false) Boolean links) {
    List<String> fields = newArrayList(contextService.getParameterValues("fields"));
    List<DimensionalObject> dimensionConstraints = dimensionService.getDimensionConstraints();
    if (links) {
        linkService.generateLinks(dimensionConstraints, false);
    }
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.toCollectionNode(getEntityClass(), new FieldFilterParams(dimensionConstraints, fields)));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) DimensionalObject(org.hisp.dhis.common.DimensionalObject) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with FieldFilterParams

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

the class AbstractFullReadOnlyController method getObjectList.

// --------------------------------------------------------------------------
// GET Full
// --------------------------------------------------------------------------
@GetMapping
@ResponseBody
public RootNode getObjectList(@RequestParam Map<String, String> rpParameters, OrderParams orderParams, HttpServletResponse response, @CurrentUser User currentUser) throws QueryParserException {
    List<Order> orders = orderParams.getOrders(getSchema());
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
    forceFiltering(filters);
    if (fields.isEmpty()) {
        fields.addAll(Preset.defaultPreset().getFields());
    }
    WebOptions options = new WebOptions(rpParameters);
    WebMetadata metadata = new WebMetadata();
    if (!aclService.canRead(currentUser, getEntityClass())) {
        throw new ReadAccessDeniedException("You don't have the proper permissions to read objects of this type.");
    }
    List<T> entities = getEntityList(metadata, options, filters, orders);
    Pager pager = metadata.getPager();
    if (options.hasPaging() && pager == null) {
        long totalCount;
        if (options.getOptions().containsKey("query")) {
            totalCount = entities.size();
            long skip = (long) (options.getPage() - 1) * options.getPageSize();
            entities = entities.stream().skip(skip).limit(options.getPageSize()).collect(toList());
        } else {
            totalCount = countTotal(options, filters, orders);
        }
        pager = new Pager(options.getPage(), totalCount, options.getPageSize());
    }
    postProcessResponseEntities(entities, options, rpParameters);
    handleLinksAndAccess(entities, fields, false);
    handleAttributeValues(entities, fields);
    linkService.generatePagerLinks(pager, getEntityClass());
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.getConfig().setInclusionStrategy(getInclusionStrategy(rpParameters.get("inclusionStrategy")));
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    FieldFilterParams defaults1 = new FieldFilterParams(entities, fields, Defaults.valueOf(options.get("defaults", DEFAULTS)));
    CollectionNode defaults = fieldFilterService.toCollectionNode(getEntityClass(), defaults1);
    rootNode.addChild(defaults);
    cachePrivate(response);
    return rootNode;
}
Also used : Order(org.hisp.dhis.query.Order) RootNode(org.hisp.dhis.node.types.RootNode) ReadAccessDeniedException(org.hisp.dhis.hibernate.exception.ReadAccessDeniedException) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) CollectionNode(org.hisp.dhis.node.types.CollectionNode) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) Pager(org.hisp.dhis.common.Pager) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with FieldFilterParams

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

the class AbstractFullReadOnlyController method getObjectInternal.

@SuppressWarnings("unchecked")
private RootNode getObjectInternal(String uid, Map<String, String> parameters, List<String> filters, List<String> fields, User currentUser) throws Exception {
    WebOptions options = new WebOptions(parameters);
    List<T> entities = getEntity(uid, options);
    if (entities.isEmpty()) {
        throw new WebMessageException(notFound(getEntityClass(), uid));
    }
    Query query = queryService.getQueryFromUrl(getEntityClass(), filters, new ArrayList<>(), getPaginationData(options), options.getRootJunction());
    query.setUser(currentUser);
    query.setObjects(entities);
    query.setDefaults(Defaults.valueOf(options.get("defaults", DEFAULTS)));
    entities = (List<T>) queryService.query(query);
    handleLinksAndAccess(entities, fields, true);
    handleAttributeValues(entities, fields);
    for (T entity : entities) {
        postProcessResponseEntity(entity, options, parameters);
    }
    CollectionNode collectionNode = fieldFilterService.toCollectionNode(getEntityClass(), new FieldFilterParams(entities, fields, Defaults.valueOf(options.get("defaults", DEFAULTS))).setUser(currentUser));
    if (options.isTrue("useWrapper") || entities.size() > 1) {
        RootNode rootNode = NodeUtils.createMetadata(collectionNode);
        rootNode.getConfig().setInclusionStrategy(getInclusionStrategy(parameters.get("inclusionStrategy")));
        return rootNode;
    } else {
        List<Node> children = collectionNode.getChildren();
        RootNode rootNode;
        if (!children.isEmpty()) {
            rootNode = NodeUtils.createRootNode(children.get(0));
        } else {
            rootNode = NodeUtils.createRootNode(new ComplexNode(getSchema().getSingular()));
        }
        rootNode.getConfig().setInclusionStrategy(getInclusionStrategy(parameters.get("inclusionStrategy")));
        return rootNode;
    }
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) Query(org.hisp.dhis.query.Query) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ComplexNode(org.hisp.dhis.node.types.ComplexNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) RootNode(org.hisp.dhis.node.types.RootNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) Node(org.hisp.dhis.node.Node) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) CollectionNode(org.hisp.dhis.node.types.CollectionNode)

Example 9 with FieldFilterParams

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

the class AuditController method getDataApprovalAudit.

@GetMapping("dataApproval")
@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) Boolean paging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) {
    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;
    RootNode rootNode = NodeUtils.createMetadata();
    if (!PagerUtils.isSkipPaging(skipPaging, paging)) {
        pager = new Pager(page, audits.size(), pageSize);
        audits = audits.subList(pager.getOffset(), Math.min(pager.getOffset() + pager.getPageSize(), audits.size()));
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    CollectionNode dataApprovalAudits = rootNode.addChild(new CollectionNode("dataApprovalAudits", true));
    dataApprovalAudits.addChildren(fieldFilterService.toCollectionNode(DataApprovalAudit.class, new FieldFilterParams(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) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) DataApprovalAudit(org.hisp.dhis.dataapproval.DataApprovalAudit) CollectionNode(org.hisp.dhis.node.types.CollectionNode) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 10 with FieldFilterParams

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

the class AuditController method getTrackedEnityInstanceAudit.

@GetMapping("trackedEntityInstance")
@ResponseBody
public RootNode getTrackedEnityInstanceAudit(@RequestParam(required = false, defaultValue = "") List<String> tei, @RequestParam(required = false, defaultValue = "") List<String> user, @RequestParam(required = false) AuditType auditType, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) Boolean skipPaging, @RequestParam(required = false) Boolean paging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    TrackedEntityInstanceAuditQueryParams params = new TrackedEntityInstanceAuditQueryParams();
    params.setTrackedEntityInstances(new HashSet<>(tei));
    params.setUsers(new HashSet<>(user));
    params.setAuditType(auditType);
    params.setStartDate(startDate);
    params.setEndDate(endDate);
    params.setSkipPaging(PagerUtils.isSkipPaging(skipPaging, paging));
    List<TrackedEntityInstanceAudit> teiAudits;
    Pager pager = null;
    if (!params.isSkipPaging()) {
        int total = trackedEntityInstanceAuditService.getTrackedEntityInstanceAuditsCount(params);
        pager = new Pager(page, total, pageSize);
        params.setFirst(pager.getOffset());
        params.setMax(pager.getPageSize());
    }
    teiAudits = trackedEntityInstanceAuditService.getTrackedEntityInstanceAudits(params);
    RootNode rootNode = NodeUtils.createMetadata();
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    CollectionNode trackedEntityInstanceAudits = rootNode.addChild(new CollectionNode("trackedEntityInstanceAudits", true));
    trackedEntityInstanceAudits.addChildren(fieldFilterService.toCollectionNode(TrackedEntityInstanceAudit.class, new FieldFilterParams(teiAudits, fields)).getChildren());
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) Pager(org.hisp.dhis.common.Pager) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) TrackedEntityInstanceAuditQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceAuditQueryParams) CollectionNode(org.hisp.dhis.node.types.CollectionNode) TrackedEntityInstanceAudit(org.hisp.dhis.audit.payloads.TrackedEntityInstanceAudit) 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