use of org.hisp.dhis.common.ValueType.COORDINATE in project dhis2-core by dhis2.
the class AbstractAnalyticsService method getGrid.
protected Grid getGrid(EventQueryParams params) {
// ---------------------------------------------------------------------
// Decide access, add constraints and validate
// ---------------------------------------------------------------------
securityManager.decideAccessEventQuery(params);
params = securityManager.withUserConstraints(params);
queryValidator.validate(params);
// keywords as well as their periods are removed in the next step,
// params object is modified
List<DimensionItemKeywords.Keyword> periodKeywords = params.getDimensions().stream().map(DimensionalObject::getDimensionItemKeywords).filter(dimensionItemKeywords -> dimensionItemKeywords != null && !dimensionItemKeywords.isEmpty()).flatMap(dk -> dk.getKeywords().stream()).collect(Collectors.toList());
params = new EventQueryParams.Builder(params).withStartEndDatesForPeriods().build();
// ---------------------------------------------------------------------
// Headers
// ---------------------------------------------------------------------
Grid grid = createGridWithHeaders(params);
for (DimensionalObject dimension : params.getDimensions()) {
grid.addHeader(new GridHeader(dimension.getDimension(), dimension.getDimensionDisplayName(), ValueType.TEXT, false, true));
}
for (QueryItem item : params.getItems()) {
/**
* Special case: If the request contains an item of Org Unit value
* type and the item UID is linked to coordinates (coordinateField),
* then create an Header of ValueType COORDINATE and type "Point"
*/
if (item.getValueType() == ValueType.ORGANISATION_UNIT && params.getCoordinateField().equals(item.getItem().getUid())) {
grid.addHeader(new GridHeader(item.getItem().getUid(), item.getItem().getDisplayProperty(params.getDisplayProperty()), COORDINATE, false, true, item.getOptionSet(), item.getLegendSet()));
} else if (hasNonDefaultRepeatableProgramStageOffset(item)) {
String column = item.getItem().getDisplayProperty(params.getDisplayProperty());
RepeatableStageParams repeatableStageParams = item.getRepeatableStageParams();
String name = repeatableStageParams.getDimension();
grid.addHeader(new GridHeader(name, column, repeatableStageParams.simpleStageValueExpected() ? item.getValueType() : ValueType.REFERENCE, false, true, item.getOptionSet(), item.getLegendSet(), item.getProgramStage().getUid(), item.getRepeatableStageParams()));
} else {
final String uid = getItemUid(item);
final String column = item.getItem().getDisplayProperty(params.getDisplayProperty());
grid.addHeader(new GridHeader(uid, column, item.getValueType(), false, true, item.getOptionSet(), item.getLegendSet()));
}
}
// ---------------------------------------------------------------------
// Data
// ---------------------------------------------------------------------
long count = 0;
if (!params.isSkipData() || params.analyzeOnly()) {
count = addEventData(grid, params);
}
// ---------------------------------------------------------------------
// Meta-data
// ---------------------------------------------------------------------
addMetadata(params, periodKeywords, grid);
if (params.hasDataIdScheme()) {
substituteData(grid);
}
if (params.isPaging()) {
Pager pager = new Pager(params.getPageWithDefault(), count, params.getPageSizeWithDefault());
grid.getMetaData().put(PAGER.getKey(), pager);
}
maybeApplyHeaders(params, grid);
return grid;
}
Aggregations