use of org.hisp.dhis.analytics.DataType in project dhis2-core by dhis2.
the class QueryPlannerUtils method getDataTypeDataElementMap.
/**
* Creates a mapping between data type and data element for the given data
* elements.
*
* @param dataElements list of data elements.
*/
public static ListMap<DataType, DimensionalItemObject> getDataTypeDataElementMap(List<DimensionalItemObject> dataElements) {
ListMap<DataType, DimensionalItemObject> map = new ListMap<>();
for (DimensionalItemObject element : dataElements) {
DataElement dataElement = (DataElement) element;
ValueType valueType = dataElement.getValueType();
// Both Text and Date types are recognized as TEXT
DataType dataType = (valueType.isText() || valueType.isDate()) ? DataType.TEXT : DataType.NUMERIC;
map.putValue(dataType, dataElement);
}
return map;
}
use of org.hisp.dhis.analytics.DataType in project dhis2-core by dhis2.
the class DefaultQueryPlanner method groupByDataType.
/**
* Groups queries by their data type.
*
* @param params the data query parameters.
* @return a list of {@link DataQueryParams}.
*/
private List<DataQueryParams> groupByDataType(DataQueryParams params) {
List<DataQueryParams> queries = new ArrayList<>();
if (!params.getDataElements().isEmpty()) {
ListMap<DataType, DimensionalItemObject> dataTypeDataElementMap = QueryPlannerUtils.getDataTypeDataElementMap(params.getDataElements());
for (DataType dataType : dataTypeDataElementMap.keySet()) {
DataQueryParams query = DataQueryParams.newBuilder(params).withDataElements(dataTypeDataElementMap.get(dataType)).withDataType(dataType).build();
queries.add(query);
}
} else {
DataQueryParams query = DataQueryParams.newBuilder(params).withDataType(DataType.NUMERIC).build();
queries.add(query);
}
if (queries.size() > 1) {
log.debug(String.format("Split on data type: %d", queries.size()));
}
return queries;
}
Aggregations