Search in sources :

Example 21 with FieldFilterParams

use of org.hisp.dhis.fieldfilter.FieldFilterParams 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)

Example 22 with FieldFilterParams

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

the class LockExceptionController method getLockExceptions.

// -------------------------------------------------------------------------
// Resources
// -------------------------------------------------------------------------
@GetMapping(produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getLockExceptions(@RequestParam(required = false) String key, @RequestParam Map<String, String> rpParameters, HttpServletRequest request, HttpServletResponse response) throws WebMessageException {
    List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    List<LockException> lockExceptions = new ArrayList<>();
    if (key != null) {
        LockException lockException = dataSetService.getLockException(MathUtils.parseInt(key));
        if (lockException == null) {
            throw new WebMessageException(notFound("Cannot find LockException with key: " + key));
        }
        lockExceptions.add(lockException);
    } else if (!filters.isEmpty()) {
        lockExceptions = dataSetService.filterLockExceptions(filters);
    } else {
        lockExceptions = dataSetService.getAllLockExceptions();
    }
    WebOptions options = new WebOptions(rpParameters);
    WebMetadata metadata = new WebMetadata();
    Pager pager = metadata.getPager();
    if (options.hasPaging() && pager == null) {
        pager = new Pager(options.getPage(), lockExceptions.size(), options.getPageSize());
        lockExceptions = PagerUtils.pageCollection(lockExceptions, pager);
    }
    RootNode rootNode = NodeUtils.createMetadata();
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    I18nFormat format = this.i18nManager.getI18nFormat();
    for (LockException lockException : lockExceptions) {
        lockException.getPeriod().setName(format.formatPeriod(lockException.getPeriod()));
    }
    rootNode.addChild(fieldFilterService.toCollectionNode(LockException.class, new FieldFilterParams(lockExceptions, fields)));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) LockException(org.hisp.dhis.dataset.LockException) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Pager(org.hisp.dhis.common.Pager) ArrayList(java.util.ArrayList) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) I18nFormat(org.hisp.dhis.i18n.I18nFormat) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 23 with FieldFilterParams

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

the class LockExceptionController method getLockExceptionCombinations.

@GetMapping(value = "/combinations", produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getLockExceptionCombinations() {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    List<LockException> lockExceptions = this.dataSetService.getLockExceptionCombinations();
    I18nFormat format = this.i18nManager.getI18nFormat();
    for (LockException lockException : lockExceptions) {
        lockException.getPeriod().setName(format.formatPeriod(lockException.getPeriod()));
    }
    Collections.sort(lockExceptions, new LockExceptionNameComparator());
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.toCollectionNode(LockException.class, new FieldFilterParams(lockExceptions, fields)));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) LockExceptionNameComparator(org.hisp.dhis.dataset.comparator.LockExceptionNameComparator) LockException(org.hisp.dhis.dataset.LockException) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) I18nFormat(org.hisp.dhis.i18n.I18nFormat) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 24 with FieldFilterParams

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

the class MinMaxDataElementController method getObjectList.

// --------------------------------------------------------------------------
// GET
// --------------------------------------------------------------------------
@GetMapping
@ResponseBody
public RootNode getObjectList(MinMaxDataElementQueryParams query) throws QueryParserException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
    query.setFilters(filters);
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    List<MinMaxDataElement> minMaxDataElements = minMaxService.getMinMaxDataElements(query);
    RootNode rootNode = NodeUtils.createMetadata();
    if (!query.isSkipPaging()) {
        query.setTotal(minMaxService.countMinMaxDataElements(query));
        rootNode.addChild(NodeUtils.createPager(query.getPager()));
    }
    rootNode.addChild(fieldFilterService.toCollectionNode(MinMaxDataElement.class, new FieldFilterParams(minMaxDataElements, fields)));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) MinMaxDataElement(org.hisp.dhis.minmax.MinMaxDataElement) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 25 with FieldFilterParams

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

the class DeduplicationController method getAllByQuery.

@GetMapping
public Node getAllByQuery(PotentialDuplicateQuery query, HttpServletResponse response) throws BadRequestException {
    checkDeduplicationStatusRequestParam(Optional.ofNullable(query.getStatus()).map(Enum::name).orElse(null));
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    List<PotentialDuplicate> potentialDuplicates = deduplicationService.getAllPotentialDuplicatesBy(query);
    RootNode rootNode = NodeUtils.createMetadata();
    if (!query.isSkipPaging()) {
        query.setTotal(deduplicationService.countPotentialDuplicates(query));
        rootNode.addChild(NodeUtils.createPager(query.getPager()));
    }
    rootNode.addChild(fieldFilterService.toCollectionNode(PotentialDuplicate.class, new FieldFilterParams(potentialDuplicates, fields)));
    setNoStore(response);
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) GetMapping(org.springframework.web.bind.annotation.GetMapping)

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