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;
}
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();
}
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;
}
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;
}
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;
}
Aggregations