Search in sources :

Example 11 with WebMetadata

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;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) DimensionalObject(org.hisp.dhis.common.DimensionalObject) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 12 with WebMetadata

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());
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Pager(org.hisp.dhis.common.Pager) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 13 with WebMetadata

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);
}
Also used : Field(java.lang.reflect.Field) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) NameableObject(org.hisp.dhis.common.NameableObject) ListGrid(org.hisp.dhis.system.grid.ListGrid) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) GridHeader(org.hisp.dhis.common.GridHeader)

Aggregations

WebMetadata (org.hisp.dhis.webapi.webdomain.WebMetadata)13 GetMapping (org.springframework.web.bind.annotation.GetMapping)10 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)10 Pager (org.hisp.dhis.common.Pager)9 RootNode (org.hisp.dhis.node.types.RootNode)9 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)9 ArrayList (java.util.ArrayList)7 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)6 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)6 Order (org.hisp.dhis.query.Order)5 DataElementGroup (org.hisp.dhis.dataelement.DataElementGroup)4 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)4 DataSet (org.hisp.dhis.dataset.DataSet)4 List (java.util.List)3 Query (org.hisp.dhis.query.Query)3 Schema (org.hisp.dhis.schema.Schema)3 DimensionalObject (org.hisp.dhis.common.DimensionalObject)2 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)2 ReadAccessDeniedException (org.hisp.dhis.hibernate.exception.ReadAccessDeniedException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2