use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class EnrollmentController method getEnrollments.
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@GetMapping
@ResponseBody
public RootNode getEnrollments(EnrollmentCriteria enrollmentCriteria) {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.add("enrollment,created,lastUpdated,trackedEntityType,trackedEntityInstance,program,status,orgUnit,orgUnitName,enrollmentDate,incidentDate,followup");
}
RootNode rootNode = NodeUtils.createMetadata();
List<Enrollment> listEnrollments;
if (enrollmentCriteria.getEnrollment() == null) {
ProgramInstanceQueryParams params = enrollmentCriteriaMapper.getFromUrl(TextUtils.splitToArray(enrollmentCriteria.getOu(), TextUtils.SEMICOLON), enrollmentCriteria.getOuMode(), enrollmentCriteria.getLastUpdated(), enrollmentCriteria.getLastUpdatedDuration(), enrollmentCriteria.getProgram(), enrollmentCriteria.getProgramStatus(), enrollmentCriteria.getProgramStartDate(), enrollmentCriteria.getProgramEndDate(), enrollmentCriteria.getTrackedEntityType(), enrollmentCriteria.getTrackedEntityInstance(), enrollmentCriteria.getFollowUp(), enrollmentCriteria.getPage(), enrollmentCriteria.getPageSize(), enrollmentCriteria.isTotalPages(), PagerUtils.isSkipPaging(enrollmentCriteria.getSkipPaging(), enrollmentCriteria.getPaging()), enrollmentCriteria.isIncludeDeleted(), enrollmentCriteria.getOrder());
Enrollments enrollments = enrollmentService.getEnrollments(params);
if (enrollments.getPager() != null) {
if (params.isTotalPages()) {
rootNode.addChild(NodeUtils.createPager(enrollments.getPager()));
} else {
rootNode.addChild(NodeUtils.createSlimPager((SlimPager) enrollments.getPager()));
}
}
listEnrollments = enrollments.getEnrollments();
} else {
Set<String> enrollmentIds = TextUtils.splitToArray(enrollmentCriteria.getEnrollment(), TextUtils.SEMICOLON);
listEnrollments = enrollmentIds != null ? enrollmentIds.stream().map(enrollmentId -> enrollmentService.getEnrollment(enrollmentId)).collect(Collectors.toList()) : null;
}
rootNode.addChild(fieldFilterService.toCollectionNode(Enrollment.class, new FieldFilterParams(listEnrollments, fields)));
return rootNode;
}
use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class DimensionController method getItems.
@SuppressWarnings("unchecked")
@GetMapping("/{uid}/items")
@ResponseBody
public RootNode getItems(@PathVariable String uid, @RequestParam Map<String, String> parameters, OrderParams orderParams) throws QueryParserException {
List<String> fields = newArrayList(contextService.getParameterValues("fields"));
List<String> filters = newArrayList(contextService.getParameterValues("filter"));
List<Order> orders = orderParams.getOrders(getSchema(DimensionalItemObject.class));
WebOptions options = new WebOptions(parameters);
if (fields.isEmpty()) {
fields.addAll(Preset.defaultPreset().getFields());
}
// This is the base list used in this flow. It contains only items
// allowed to the current user.
List<DimensionalItemObject> readableItems = dimensionService.getCanReadDimensionItems(uid);
// This is needed for two reasons:
// 1) We are doing in-memory paging;
// 2) We have to count all items respecting the filtering.
Query queryForCount = queryService.getQueryFromUrl(DimensionalItemObject.class, filters, orders);
queryForCount.setObjects(readableItems);
List<DimensionalItemObject> forCountItems = (List<DimensionalItemObject>) queryService.query(queryForCount);
Query query = queryService.getQueryFromUrl(DimensionalItemObject.class, filters, orders, getPaginationData(options));
query.setObjects(readableItems);
query.setDefaultOrder();
List<DimensionalItemObject> paginatedItems = (List<DimensionalItemObject>) queryService.query(query);
RootNode rootNode = NodeUtils.createMetadata();
CollectionNode collectionNode = rootNode.addChild(fieldFilterService.toCollectionNode(DimensionalItemObject.class, new FieldFilterParams(paginatedItems, fields)));
collectionNode.setName("items");
for (Node node : collectionNode.getChildren()) {
((AbstractNode) node).setName("item");
}
// Adding pagination elements to the root node.
final int totalOfItems = isNotEmpty(forCountItems) ? forCountItems.size() : 0;
dimensionItemPageHandler.addPaginationToNodeIfEnabled(rootNode, options, uid, totalOfItems);
return rootNode;
}
use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class DimensionController method getDimensionsForDataSet.
@GetMapping("/dataSet/{uid}")
@ResponseBody
public RootNode getDimensionsForDataSet(@PathVariable String uid, @RequestParam(value = "links", defaultValue = "true", required = false) Boolean links, Model model, HttpServletResponse response) throws WebMessageException {
WebMetadata metadata = new WebMetadata();
List<String> fields = newArrayList(contextService.getParameterValues("fields"));
DataSet dataSet = identifiableObjectManager.get(DataSet.class, uid);
if (dataSet == null) {
throw new WebMessageException(notFound("Data set not found: " + uid));
}
List<DimensionalObject> dimensions = new ArrayList<>();
dimensions.addAll(dataSet.getCategoryCombo().getCategories().stream().filter(ca -> !ca.isDefault()).collect(toList()));
dimensions.addAll(dataSet.getCategoryOptionGroupSets());
dimensions = dimensionService.getCanReadObjects(dimensions);
metadata.setDimensions(dimensions.stream().map(dim -> dimensionService.getDimensionalObjectCopy(dim.getUid(), true)).collect(toList()));
if (links) {
linkService.generateLinks(metadata, false);
}
RootNode rootNode = NodeUtils.createMetadata();
rootNode.addChild(fieldFilterService.toCollectionNode(getEntityClass(), new FieldFilterParams(metadata.getDimensions(), fields)));
return rootNode;
}
use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class ResponseHandler method addResultsToNode.
/**
* Appends the given dimensionalItemsFound (the collection of results) and
* fields to the rootNode.
*
* @param rootNode the main response root node
* @param dimensionalItemsFound the collection of results
* @param fields the list of fields to be returned
*/
void addResultsToNode(final RootNode rootNode, final List<DataItem> dimensionalItemsFound, final Set<String> fields) {
final CollectionNode collectionNode = fieldFilterService.toConcreteClassCollectionNode(DataItem.class, new FieldFilterParams(dimensionalItemsFound, newArrayList(fields)), "dataItems", DXF_2_0);
rootNode.addChild(collectionNode);
}
use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class ValidationResultController method getObjectList.
@GetMapping
@ResponseBody
public RootNode getObjectList(ValidationResultQuery query, HttpServletResponse response) {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
List<ValidationResult> validationResults = validationResultService.getValidationResults(query);
RootNode rootNode = NodeUtils.createMetadata();
if (!query.isSkipPaging()) {
query.setTotal(validationResultService.countValidationResults(query));
rootNode.addChild(NodeUtils.createPager(query.getPager()));
}
rootNode.addChild(fieldFilterService.toCollectionNode(ValidationResult.class, new FieldFilterParams(validationResults, fields)));
setNoStore(response);
return rootNode;
}
Aggregations