Search in sources :

Example 16 with DimensionalObject

use of org.hisp.dhis.common.DimensionalObject in project dhis2-core by dhis2.

the class DefaultDimensionService method getCanReadDimensionItems.

//--------------------------------------------------------------------------
// DimensionService implementation
//--------------------------------------------------------------------------
public List<DimensionalItemObject> getCanReadDimensionItems(String uid) {
    DimensionalObject dimension = idObjectManager.get(DimensionalObject.DYNAMIC_DIMENSION_CLASSES, uid);
    List<DimensionalItemObject> items = new ArrayList<>();
    if (dimension != null && dimension.hasItems()) {
        User user = currentUserService.getCurrentUser();
        items.addAll(getCanReadObjects(user, dimension.getItems()));
    }
    return items;
}
Also used : User(org.hisp.dhis.user.User) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) ArrayList(java.util.ArrayList) DimensionalObject(org.hisp.dhis.common.DimensionalObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject)

Example 17 with DimensionalObject

use of org.hisp.dhis.common.DimensionalObject in project dhis2-core by dhis2.

the class DimensionController method getDimensionsForDataSet.

@RequestMapping(value = "/dataSet/{uid}", method = RequestMethod.GET)
@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 = Lists.newArrayList(contextService.getParameterValues("fields"));
    DataSet dataSet = identifiableObjectManager.get(DataSet.class, uid);
    if (dataSet == null) {
        throw new WebMessageException(WebMessageUtils.notFound("DataSet not found for uid: " + uid));
    }
    if (!dataSet.hasCategoryCombo()) {
        throw new WebMessageException(WebMessageUtils.conflict("Data set does not have a category combination: " + uid));
    }
    List<DimensionalObject> dimensions = new ArrayList<>();
    dimensions.addAll(dataSet.getCategoryCombo().getCategories());
    dimensions.addAll(dataSet.getCategoryOptionGroupSets());
    dimensions = dimensionService.getCanReadObjects(dimensions);
    for (DimensionalObject dim : dimensions) {
        metadata.getDimensions().add(dimensionService.getDimensionalObjectCopy(dim.getUid(), true));
    }
    if (links) {
        linkService.generateLinks(metadata, false);
    }
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.filter(getEntityClass(), 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) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) DimensionalObject(org.hisp.dhis.common.DimensionalObject) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 18 with DimensionalObject

use of org.hisp.dhis.common.DimensionalObject in project dhis2-core by dhis2.

the class DimensionController method getDimensionConstraints.

@RequestMapping(value = "/constraints", method = RequestMethod.GET)
@ResponseBody
public RootNode getDimensionConstraints(@RequestParam(value = "links", defaultValue = "true", required = false) Boolean links) {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    List<DimensionalObject> dimensionConstraints = dimensionService.getDimensionConstraints();
    if (links) {
        linkService.generateLinks(dimensionConstraints, false);
    }
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.filter(getEntityClass(), dimensionConstraints, fields));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) DimensionalObject(org.hisp.dhis.common.DimensionalObject) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 19 with DimensionalObject

use of org.hisp.dhis.common.DimensionalObject in project dhis2-core by dhis2.

the class DimensionController method getEntityList.

// -------------------------------------------------------------------------
// Controller
// -------------------------------------------------------------------------
@Override
@SuppressWarnings("unchecked")
@ResponseBody
protected List<DimensionalObject> getEntityList(WebMetadata metadata, WebOptions options, List<String> filters, List<Order> orders) throws QueryParserException {
    List<DimensionalObject> dimensionalObjects;
    Query query = queryService.getQueryFromUrl(DimensionalObject.class, filters, orders, options.getRootJunction());
    query.setDefaultOrder();
    query.setObjects(dimensionService.getAllDimensions());
    dimensionalObjects = (List<DimensionalObject>) queryService.query(query);
    return dimensionalObjects;
}
Also used : Query(org.hisp.dhis.query.Query) DimensionalObject(org.hisp.dhis.common.DimensionalObject) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 20 with DimensionalObject

use of org.hisp.dhis.common.DimensionalObject in project dhis2-core by dhis2.

the class DefaultAnalyticsService method getAggregatedDataValueMap.

/**
     * Returns a mapping between dimension items and values for the given data
     * query and list of indicators. The dimensional items part of the indicator
     * numerators and denominators are used as dimensional item for the aggregated
     * values being retrieved.
     *
     * @param params the {@link DataQueryParams}.
     * @param indicators the list of indicators.
     * @return a dimensional items to aggregate values map.
     */
private Map<String, Double> getAggregatedDataValueMap(DataQueryParams params, List<Indicator> indicators) {
    List<DimensionalItemObject> items = Lists.newArrayList(expressionService.getDimensionalItemObjectsInIndicators(indicators));
    items = DimensionalObjectUtils.replaceOperandTotalsWithDataElements(items);
    DimensionalObject dimension = new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, null, DISPLAY_NAME_DATA_X, items);
    DataQueryParams dataSourceParams = DataQueryParams.newBuilder(params).replaceDimension(dimension).withIncludeNumDen(false).withSkipHeaders(true).withSkipMeta(true).build();
    Grid grid = getAggregatedDataValueGridInternal(dataSourceParams);
    return grid.getAsMap(grid.getWidth() - 1, DimensionalObject.DIMENSION_SEP);
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) DimensionalObject(org.hisp.dhis.common.DimensionalObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject)

Aggregations

DimensionalObject (org.hisp.dhis.common.DimensionalObject)44 ArrayList (java.util.ArrayList)14 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)14 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)13 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)11 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)10 Test (org.junit.Test)8 List (java.util.List)6 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)5 Grid (org.hisp.dhis.common.Grid)5 DataElement (org.hisp.dhis.dataelement.DataElement)5 Period (org.hisp.dhis.period.Period)5 DateUtils.getMediumDateString (org.hisp.dhis.system.util.DateUtils.getMediumDateString)5 Calendar (org.hisp.dhis.calendar.Calendar)4 User (org.hisp.dhis.user.User)4 CategoryOptionGroupSet (org.hisp.dhis.dataelement.CategoryOptionGroupSet)3 DataSet (org.hisp.dhis.dataset.DataSet)3 Indicator (org.hisp.dhis.indicator.Indicator)3 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)3 ListGrid (org.hisp.dhis.system.grid.ListGrid)3