use of org.hisp.dhis.fieldfilter.FieldFilterParams 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.fieldfilter.FieldFilterParams 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;
}
use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class AbstractFullReadOnlyController method getObjectInternal.
@SuppressWarnings("unchecked")
private RootNode getObjectInternal(String uid, Map<String, String> parameters, List<String> filters, List<String> fields, User currentUser) throws Exception {
WebOptions options = new WebOptions(parameters);
List<T> entities = getEntity(uid, options);
if (entities.isEmpty()) {
throw new WebMessageException(notFound(getEntityClass(), uid));
}
Query query = queryService.getQueryFromUrl(getEntityClass(), filters, new ArrayList<>(), getPaginationData(options), options.getRootJunction());
query.setUser(currentUser);
query.setObjects(entities);
query.setDefaults(Defaults.valueOf(options.get("defaults", DEFAULTS)));
entities = (List<T>) queryService.query(query);
handleLinksAndAccess(entities, fields, true);
handleAttributeValues(entities, fields);
for (T entity : entities) {
postProcessResponseEntity(entity, options, parameters);
}
CollectionNode collectionNode = fieldFilterService.toCollectionNode(getEntityClass(), new FieldFilterParams(entities, fields, Defaults.valueOf(options.get("defaults", DEFAULTS))).setUser(currentUser));
if (options.isTrue("useWrapper") || entities.size() > 1) {
RootNode rootNode = NodeUtils.createMetadata(collectionNode);
rootNode.getConfig().setInclusionStrategy(getInclusionStrategy(parameters.get("inclusionStrategy")));
return rootNode;
} else {
List<Node> children = collectionNode.getChildren();
RootNode rootNode;
if (!children.isEmpty()) {
rootNode = NodeUtils.createRootNode(children.get(0));
} else {
rootNode = NodeUtils.createRootNode(new ComplexNode(getSchema().getSingular()));
}
rootNode.getConfig().setInclusionStrategy(getInclusionStrategy(parameters.get("inclusionStrategy")));
return rootNode;
}
}
use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class AuditController method getDataApprovalAudit.
@GetMapping("dataApproval")
@ResponseBody
public RootNode getDataApprovalAudit(@RequestParam(required = false, defaultValue = "") List<String> dal, @RequestParam(required = false, defaultValue = "") List<String> wf, @RequestParam(required = false, defaultValue = "") List<String> ou, @RequestParam(required = false, defaultValue = "") List<String> aoc, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) Boolean skipPaging, @RequestParam(required = false) Boolean paging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
DataApprovalAuditQueryParams params = new DataApprovalAuditQueryParams();
params.setLevels(new HashSet<>(getDataApprovalLevel(dal)));
params.setWorkflows(new HashSet<>(getDataApprovalWorkflow(wf)));
params.setOrganisationUnits(new HashSet<>(getOrganisationUnit(ou)));
params.setAttributeOptionCombos(new HashSet<>(getCategoryOptionCombo(aoc)));
params.setStartDate(startDate);
params.setEndDate(endDate);
List<DataApprovalAudit> audits = dataApprovalAuditService.getDataApprovalAudits(params);
Pager pager;
RootNode rootNode = NodeUtils.createMetadata();
if (!PagerUtils.isSkipPaging(skipPaging, paging)) {
pager = new Pager(page, audits.size(), pageSize);
audits = audits.subList(pager.getOffset(), Math.min(pager.getOffset() + pager.getPageSize(), audits.size()));
rootNode.addChild(NodeUtils.createPager(pager));
}
CollectionNode dataApprovalAudits = rootNode.addChild(new CollectionNode("dataApprovalAudits", true));
dataApprovalAudits.addChildren(fieldFilterService.toCollectionNode(DataApprovalAudit.class, new FieldFilterParams(audits, fields)).getChildren());
return rootNode;
}
use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class AuditController method getTrackedEnityInstanceAudit.
@GetMapping("trackedEntityInstance")
@ResponseBody
public RootNode getTrackedEnityInstanceAudit(@RequestParam(required = false, defaultValue = "") List<String> tei, @RequestParam(required = false, defaultValue = "") List<String> user, @RequestParam(required = false) AuditType auditType, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) Boolean skipPaging, @RequestParam(required = false) Boolean paging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
TrackedEntityInstanceAuditQueryParams params = new TrackedEntityInstanceAuditQueryParams();
params.setTrackedEntityInstances(new HashSet<>(tei));
params.setUsers(new HashSet<>(user));
params.setAuditType(auditType);
params.setStartDate(startDate);
params.setEndDate(endDate);
params.setSkipPaging(PagerUtils.isSkipPaging(skipPaging, paging));
List<TrackedEntityInstanceAudit> teiAudits;
Pager pager = null;
if (!params.isSkipPaging()) {
int total = trackedEntityInstanceAuditService.getTrackedEntityInstanceAuditsCount(params);
pager = new Pager(page, total, pageSize);
params.setFirst(pager.getOffset());
params.setMax(pager.getPageSize());
}
teiAudits = trackedEntityInstanceAuditService.getTrackedEntityInstanceAudits(params);
RootNode rootNode = NodeUtils.createMetadata();
if (pager != null) {
rootNode.addChild(NodeUtils.createPager(pager));
}
CollectionNode trackedEntityInstanceAudits = rootNode.addChild(new CollectionNode("trackedEntityInstanceAudits", true));
trackedEntityInstanceAudits.addChildren(fieldFilterService.toCollectionNode(TrackedEntityInstanceAudit.class, new FieldFilterParams(teiAudits, fields)).getChildren());
return rootNode;
}
Aggregations