use of org.hisp.dhis.node.types.RootNode 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.node.types.RootNode 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;
}
use of org.hisp.dhis.node.types.RootNode 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;
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class ResponseHandler method addPaginationToNode.
/**
* This method takes care of the pagination link and their respective
* attributes. It will count the number of results available and base on the
* WebOptions will calculate the pagination output.
*
* @param rootNode the node where the the pagination will be attached to
* @param targetEntities the list of classes which requires pagination
* @param currentUser the current logged user
* @param options holds the pagination definitions
* @param filters the query filters used in the count query
*/
void addPaginationToNode(final RootNode rootNode, final Set<Class<? extends BaseIdentifiableObject>> targetEntities, final User currentUser, final WebOptions options, final Set<String> filters) {
if (options.hasPaging() && isNotEmpty(targetEntities)) {
// Defining query params map and setting common params.
final MapSqlParameterSource paramsMap = new MapSqlParameterSource().addValue(QueryParam.USER_UID, currentUser.getUid());
setFilteringParams(filters, options, paramsMap, currentUser);
final AtomicLong count = new AtomicLong();
// Counting and summing up the results for each entity.
count.addAndGet(pageCountingCache.get(createPageCountingCacheKey(currentUser, targetEntities, filters, options), p -> countEntityRowsTotal(targetEntities, options, paramsMap)));
final Pager pager = new Pager(options.getPage(), count.get(), options.getPageSize());
linkService.generatePagerLinks(pager, API_RESOURCE_PATH);
rootNode.addChild(createPager(pager));
}
}
use of org.hisp.dhis.node.types.RootNode 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;
}
Aggregations