Search in sources :

Example 31 with RootNode

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

the class NodeUtils method createMetadata.

public static RootNode createMetadata(Node child) {
    RootNode rootNode = createMetadata();
    rootNode.addChild(child);
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode)

Example 32 with RootNode

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

the class AbstractNodeSerializer method writeRootNode.

protected void writeRootNode(RootNode rootNode) throws Exception {
    startWriteRootNode(rootNode);
    for (Node node : rootNode.getChildren()) {
        dispatcher(node);
        flushStream();
    }
    endWriteRootNode(rootNode);
    flushStream();
}
Also used : SimpleNode(org.hisp.dhis.node.types.SimpleNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) RootNode(org.hisp.dhis.node.types.RootNode)

Example 33 with RootNode

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

the class NodeUtils method createRootNode.

public static RootNode createRootNode(Node node) {
    RootNode rootNode = new RootNode(node);
    rootNode.setDefaultNamespace(DxfNamespaces.DXF_2_0);
    rootNode.setNamespace(DxfNamespaces.DXF_2_0);
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode)

Example 34 with RootNode

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

the class DataElementOperandController method getObjectList.

@GetMapping
@SuppressWarnings("unchecked")
@ResponseBody
public RootNode getObjectList(@RequestParam Map<String, String> rpParameters, OrderParams orderParams, @CurrentUser User currentUser) throws QueryParserException {
    Schema schema = schemaService.getDynamicSchema(DataElementOperand.class);
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
    List<Order> orders = orderParams.getOrders(schema);
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    WebOptions options = new WebOptions(rpParameters);
    WebMetadata metadata = new WebMetadata();
    List<DataElementOperand> dataElementOperands;
    if (options.isTrue("persisted")) {
        dataElementOperands = Lists.newArrayList(manager.getAll(DataElementOperand.class));
    } else {
        boolean totals = options.isTrue("totals");
        String deg = CollectionUtils.popStartsWith(filters, "dataElement.dataElementGroups.id:eq:");
        deg = deg != null ? deg.substring("dataElement.dataElementGroups.id:eq:".length()) : null;
        String ds = options.get("dataSet");
        if (deg != null) {
            DataElementGroup dataElementGroup = manager.get(DataElementGroup.class, deg);
            dataElementOperands = dataElementCategoryService.getOperands(dataElementGroup.getMembers(), totals);
        } else if (ds != null) {
            DataSet dataSet = manager.get(DataSet.class, ds);
            dataElementOperands = dataElementCategoryService.getOperands(dataSet, totals);
        } else {
            List<DataElement> dataElements = new ArrayList<>(manager.getAllSorted(DataElement.class));
            dataElementOperands = dataElementCategoryService.getOperands(dataElements, totals);
        }
    }
    // This is needed for two reasons:
    // 1) We are doing in-memory paging;
    // 2) We have to count all items respecting the filtering and the
    // initial universe of elements. In this case, the variable
    // "dataElementOperands".
    Query queryForCount = queryService.getQueryFromUrl(DataElementOperand.class, filters, orders);
    queryForCount.setObjects(dataElementOperands);
    List<DataElementOperand> totalOfItems = (List<DataElementOperand>) queryService.query(queryForCount);
    Query query = queryService.getQueryFromUrl(DataElementOperand.class, filters, orders, PaginationUtils.getPaginationData(options), options.getRootJunction());
    query.setDefaultOrder();
    query.setObjects(dataElementOperands);
    dataElementOperands = (List<DataElementOperand>) queryService.query(query);
    Pager pager = metadata.getPager();
    if (options.hasPaging() && pager == null) {
        final long countTotal = isNotEmpty(totalOfItems) ? totalOfItems.size() : 0;
        // fetch the count for the current query from a short-lived cache
        long cachedCountTotal = paginationCountCache.computeIfAbsent(calculatePaginationCountKey(currentUser, filters, options), () -> countTotal);
        pager = new Pager(options.getPage(), cachedCountTotal, options.getPageSize());
        linkService.generatePagerLinks(pager, DataElementOperand.class);
    }
    RootNode rootNode = NodeUtils.createMetadata();
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    rootNode.addChild(fieldFilterService.toCollectionNode(DataElementOperand.class, new FieldFilterParams(dataElementOperands, fields)));
    return rootNode;
}
Also used : Order(org.hisp.dhis.query.Order) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) RootNode(org.hisp.dhis.node.types.RootNode) Query(org.hisp.dhis.query.Query) DataSet(org.hisp.dhis.dataset.DataSet) Schema(org.hisp.dhis.schema.Schema) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) Pager(org.hisp.dhis.common.Pager) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) ArrayList(java.util.ArrayList) List(java.util.List) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 35 with RootNode

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

the class EventController method getXmlEvents.

@GetMapping(produces = { APPLICATION_XML_VALUE, "application/xml+gzip", TEXT_XML_VALUE })
@ResponseBody
public RootNode getXmlEvents(EventCriteria eventCriteria, @RequestParam Map<String, String> parameters, Model model, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
    WebOptions options = new WebOptions(parameters);
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    EventSearchParams params = requestToSearchParamsMapper.map(eventCriteria);
    Events events = eventService.getEvents(params);
    if (hasHref(fields, eventCriteria.getSkipEventId())) {
        events.getEvents().forEach(e -> e.setHref(ContextUtils.getRootPath(request) + RESOURCE_PATH + "/" + e.getEvent()));
    }
    if (!eventCriteria.isSkipMeta() && params.getProgram() != null) {
        events.setMetaData(getMetaData(params.getProgram()));
    }
    model.addAttribute("model", events);
    model.addAttribute("viewClass", options.getViewClass("detailed"));
    RootNode rootNode = NodeUtils.createEvents();
    addPager(params, events, rootNode);
    if (!StringUtils.isEmpty(eventCriteria.getAttachment())) {
        response.addHeader(ContextUtils.HEADER_CONTENT_DISPOSITION, "attachment; filename=" + eventCriteria.getAttachment());
        response.addHeader(ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary");
    }
    rootNode.addChildren(fieldFilterService.toCollectionNode(Event.class, new FieldFilterParams(events.getEvents(), fields)).getChildren());
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) Events(org.hisp.dhis.dxf2.events.event.Events) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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