use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class UserPropertyTransformerTest method testFieldNodeServiceSerializer.
@Test
void testFieldNodeServiceSerializer() throws JsonProcessingException {
Simple simple = new Simple(1, "Simple1");
simple.setUser(createUser('a'));
simple.getUser().setUuid(uuid);
simple.getUsers().add(createUser('A'));
simple.getUsers().add(createUser('B'));
simple.getUsers().add(createUser('C'));
simple.getUsers().add(createUser('D'));
ComplexNode complexNode = nodeService.toNode(simple);
RootNode rootNode = NodeUtils.createRootNode(complexNode);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
nodeService.serialize(rootNode, "application/json", outputStream);
String jsonSource = outputStream.toString();
verifyJsonSource(jsonSource);
Simple simpleFromJson = jsonMapper.readValue(jsonSource, Simple.class);
assertEquals(1, simpleFromJson.getId());
assertEquals("Simple1", simpleFromJson.getName());
assertNotNull(simple.getUser());
assertEquals("usernamea", simple.getUser().getUsername());
assertEquals(uuid, simple.getUser().getUuid());
assertNotNull(simple.getUsers());
assertEquals(4, simple.getUsers().size());
FieldFilterParams params = new FieldFilterParams(Collections.singletonList(simple), Collections.singletonList("id,name,user[id,code],users[id,code]"));
fieldFilterService.toComplexNode(params);
}
use of org.hisp.dhis.fieldfilter.FieldFilterParams 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.fieldfilter.FieldFilterParams 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;
}
use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class EventController method getEvents.
// -------------------------------------------------------------------------
// Object Read
// -------------------------------------------------------------------------
@GetMapping
@ResponseBody
public RootNode getEvents(EventCriteria eventCriteria, @RequestParam Map<String, String> parameters, Model model, HttpServletResponse response, HttpServletRequest request) {
WebOptions options = new WebOptions(parameters);
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.add("event,uid,program,programType,status,assignedUser,orgUnit,orgUnitName,eventDate,orgUnit,orgUnitName,created,lastUpdated,followup");
}
EventSearchParams params = requestToSearchParamsMapper.map(eventCriteria);
setParamBasedOnFieldParameters(params, fields);
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.createMetadata();
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.addChild(fieldFilterService.toCollectionNode(Event.class, new FieldFilterParams(events.getEvents(), fields)));
return rootNode;
}
use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class DimensionController method getRecommendedDimensions.
@GetMapping("/recommendations")
@ResponseBody
public RootNode getRecommendedDimensions(@RequestParam Set<String> dimension) {
List<String> fields = newArrayList(contextService.getParameterValues("fields"));
DataQueryRequest request = DataQueryRequest.newBuilder().dimension(dimension).build();
if (fields.isEmpty()) {
fields.addAll(Preset.defaultPreset().getFields());
}
List<DimensionalObject> dimensions = analyticsDimensionService.getRecommendedDimensions(request);
RootNode rootNode = NodeUtils.createMetadata();
rootNode.addChild(fieldFilterService.toCollectionNode(getEntityClass(), new FieldFilterParams(dimensions, fields)));
return rootNode;
}
Aggregations