use of org.hisp.dhis.webapi.webdomain.WebMetadata 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.webapi.webdomain.WebMetadata in project dhis2-core by dhis2.
the class DataElementGroupController method getOperandsByQuery.
@GetMapping("/{uid}/operands/query/{q}")
public String getOperandsByQuery(@PathVariable("uid") String uid, @PathVariable("q") String q, @RequestParam Map<String, String> parameters, TranslateParams translateParams, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
WebOptions options = new WebOptions(parameters);
setUserContext(translateParams);
List<DataElementGroup> dataElementGroups = getEntity(uid, NO_WEB_OPTIONS);
if (dataElementGroups.isEmpty()) {
throw new WebMessageException(notFound("DataElementGroup not found for uid: " + uid));
}
WebMetadata metadata = new WebMetadata();
List<DataElementOperand> dataElementOperands = Lists.newArrayList();
for (DataElementOperand dataElementOperand : dataElementCategoryService.getOperands(dataElementGroups.get(0).getMembers())) {
if (dataElementOperand.getDisplayName().toLowerCase().contains(q.toLowerCase())) {
dataElementOperands.add(dataElementOperand);
}
}
metadata.setDataElementOperands(dataElementOperands);
if (options.hasPaging()) {
Pager pager = new Pager(options.getPage(), dataElementOperands.size(), options.getPageSize());
metadata.setPager(pager);
dataElementOperands = PagerUtils.pageCollection(dataElementOperands, pager);
}
metadata.setDataElementOperands(dataElementOperands);
linkService.generateLinks(metadata, false);
model.addAttribute("model", metadata);
model.addAttribute("viewClass", options.getViewClass("basic"));
return StringUtils.uncapitalize(getEntitySimpleName());
}
use of org.hisp.dhis.webapi.webdomain.WebMetadata in project dhis2-core by dhis2.
the class AbstractGridView method renderMergedOutputModel.
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
Object object = model.get("model");
List<Grid> grids = new ArrayList<>();
if (WebMetadata.class.isAssignableFrom(object.getClass())) {
WebMetadata metadata = (WebMetadata) object;
Collection<Field> fields = ReflectionUtils.collectFields(WebMetadata.class, PredicateUtils.idObjectCollections);
for (Field field : fields) {
List<IdentifiableObject> identifiableObjects = ReflectionUtils.invokeGetterMethod(field.getName(), metadata);
if (identifiableObjects == null || identifiableObjects.isEmpty()) {
continue;
}
Grid grid = new ListGrid();
grid.setTitle(HibernateProxyUtils.getRealClass(identifiableObjects.get(0)).getSimpleName() + "s");
boolean nameable = false;
grid.addHeader(new GridHeader("UID", false, false));
grid.addHeader(new GridHeader("Name", false, false));
if (NameableObject.class.isAssignableFrom(HibernateProxyUtils.getRealClass(HibernateProxyUtils.getRealClass(object)))) {
grid.addHeader(new GridHeader("ShortName", false, false));
nameable = true;
}
grid.addHeader(new GridHeader("Code", false, false));
for (IdentifiableObject identifiableObject : identifiableObjects) {
grid.addRow();
grid.addValue(identifiableObject.getUid());
grid.addValue(identifiableObject.getName());
if (nameable) {
grid.addValue(((NameableObject) identifiableObject).getShortName());
}
grid.addValue(identifiableObject.getCode());
}
grids.add(grid);
}
} else {
IdentifiableObject identifiableObject = (IdentifiableObject) object;
Grid grid = new ListGrid();
grid.setTitle(HibernateProxyUtils.getRealClass(identifiableObject).getSimpleName());
grid.addEmptyHeaders(2);
grid.addRow().addValue("UID").addValue(identifiableObject.getUid());
grid.addRow().addValue("Name").addValue(identifiableObject.getName());
if (NameableObject.class.isAssignableFrom(HibernateProxyUtils.getRealClass(identifiableObject))) {
grid.addRow().addValue("ShortName").addValue(((NameableObject) identifiableObject).getShortName());
grid.addRow().addValue("Description").addValue(((NameableObject) identifiableObject).getDescription());
}
grid.addRow().addValue("Code").addValue(identifiableObject.getCode());
grids.add(grid);
}
renderGrids(grids, response);
}
Aggregations