use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class TrackedEntityInstanceController method getTrackedEntityInstanceById.
@GetMapping(value = "/{id}")
@ResponseBody
public RootNode getTrackedEntityInstanceById(@PathVariable("id") String pvId, @RequestParam(required = false) String program) {
List<String> fields = contextService.getFieldsFromRequestOrAll();
CollectionNode collectionNode = fieldFilterService.toCollectionNode(TrackedEntityInstance.class, new FieldFilterParams(Lists.newArrayList(trackedEntityInstanceSupportService.getTrackedEntityInstance(pvId, program, fields)), fields));
RootNode rootNode = new RootNode(collectionNode.getChildren().get(0));
rootNode.setDefaultNamespace(DxfNamespaces.DXF_2_0);
rootNode.setNamespace(DxfNamespaces.DXF_2_0);
return rootNode;
}
use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class TrackedEntityInstanceController method getTrackedEntityInstances.
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@GetMapping(produces = { ContextUtils.CONTENT_TYPE_JSON, ContextUtils.CONTENT_TYPE_XML, ContextUtils.CONTENT_TYPE_CSV })
@ResponseBody
public RootNode getTrackedEntityInstances(TrackedEntityInstanceCriteria criteria, HttpServletResponse response) {
List<String> fields = contextService.getFieldsFromRequestOrAll();
TrackedEntityInstanceQueryParams queryParams = criteriaMapper.map(criteria);
List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, getTrackedEntityInstanceParams(fields), false, false);
RootNode rootNode = NodeUtils.createMetadata();
if (queryParams.isPaging() && queryParams.isTotalPages()) {
int count = trackedEntityInstanceService.getTrackedEntityInstanceCount(queryParams, true, true);
Pager pager = new Pager(queryParams.getPageWithDefault(), count, queryParams.getPageSizeWithDefault());
rootNode.addChild(NodeUtils.createPager(pager));
}
if (!StringUtils.isEmpty(criteria.getAttachment())) {
response.addHeader(ContextUtils.HEADER_CONTENT_DISPOSITION, "attachment; filename=" + criteria.getAttachment());
response.addHeader(ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary");
}
rootNode.addChild(fieldFilterService.toCollectionNode(TrackedEntityInstance.class, new FieldFilterParams(trackedEntityInstances, fields)));
return rootNode;
}
use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class ProgramDataElementController method getObjectList.
@GetMapping
@SuppressWarnings("unchecked")
@ResponseBody
public RootNode getObjectList(@RequestParam Map<String, String> rpParameters, OrderParams orderParams) throws QueryParserException {
Schema schema = schemaService.getDynamicSchema(ProgramDataElementDimensionItem.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<ProgramDataElementDimensionItem> programDataElements;
Query query = queryService.getQueryFromUrl(ProgramDataElementDimensionItem.class, filters, orders, PaginationUtils.getPaginationData(options), options.getRootJunction());
query.setDefaultOrder();
if (options.contains("program")) {
String programUid = options.get("program");
programDataElements = programService.getGeneratedProgramDataElements(programUid);
query.setObjects(programDataElements);
}
programDataElements = (List<ProgramDataElementDimensionItem>) queryService.query(query);
Pager pager = metadata.getPager();
if (options.hasPaging() && pager == null) {
pager = new Pager(options.getPage(), programDataElements.size(), options.getPageSize());
programDataElements = PagerUtils.pageCollection(programDataElements, pager);
}
RootNode rootNode = NodeUtils.createMetadata();
if (pager != null) {
rootNode.addChild(NodeUtils.createPager(pager));
}
rootNode.addChild(fieldFilterService.toCollectionNode(ProgramDataElementDimensionItem.class, new FieldFilterParams(programDataElements, fields)));
return rootNode;
}
use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class UserPropertyTransformerTest method testFieldNodeServiceSerializerPresetStar.
@Test
void testFieldNodeServiceSerializerPresetStar() 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[*],users[*]"));
fieldFilterService.toComplexNode(params);
}
use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class DefaultNodeService method toNode.
@Override
public CollectionNode toNode(List<Object> objects) {
Assert.notNull(objects, "objects can not be null");
Assert.isTrue(objects.size() > 0, "objects list must be larger than 0");
return fieldFilterService.toCollectionNode(HibernateProxyUtils.getRealClass(objects.get(0)), new FieldFilterParams(objects, new ArrayList<>()));
}
Aggregations