use of org.hisp.dhis.common.DataQueryRequest in project dhis2-core by dhis2.
the class DataQueryServiceTest method testGetFromUrlWithCodeA.
@Test
@Disabled("Not working for composite identifiers with non-UID identifier schemes")
void testGetFromUrlWithCodeA() {
Set<String> dimensionParams = new HashSet<>();
dimensionParams.add("dx:" + deA.getCode() + ";" + deB.getCode() + ";" + patA.getDimensionItem(IdScheme.CODE) + ";" + patB.getDimensionItem(IdScheme.CODE));
Set<String> filterParams = new HashSet<>();
filterParams.add("ou:" + ouA.getCode());
DataQueryRequest dataQueryRequest = DataQueryRequest.newBuilder().dimension(dimensionParams).filter(filterParams).inputIdScheme(IdScheme.CODE).build();
DataQueryParams params = dataQueryService.getFromRequest(dataQueryRequest);
assertEquals(2, params.getDataElements().size());
assertEquals(2, params.getProgramAttributes().size());
assertEquals(1, params.getFilterOrganisationUnits().size());
}
use of org.hisp.dhis.common.DataQueryRequest in project dhis2-core by dhis2.
the class DataQueryServiceTest method testGetFromUrlNoPeriodsAllowAllPeriods.
@Test
void testGetFromUrlNoPeriodsAllowAllPeriods() {
Set<String> dimensionParams = new HashSet<>();
dimensionParams.add("dx:" + deA.getUid() + ";" + deB.getUid() + ";" + deC.getUid() + ";" + deD.getUid());
dimensionParams.add("pe");
DataQueryRequest dataQueryRequest = DataQueryRequest.newBuilder().dimension(dimensionParams).allowAllPeriods(true).build();
DataQueryParams params = dataQueryService.getFromRequest(dataQueryRequest);
assertEquals(0, params.getPeriods().size());
}
use of org.hisp.dhis.common.DataQueryRequest in project dhis2-core by dhis2.
the class AnalyticsController method getJrxml.
@GetMapping(value = RESOURCE_PATH + ".jrxml")
public void getJrxml(AggregateAnalyticsQueryCriteria criteria, DhisApiVersion apiVersion, HttpServletResponse response) throws Exception {
final DataQueryRequest request = DataQueryRequest.newBuilder().fromCriteria(criteria).apiVersion(apiVersion).skipMeta(true).build();
DataQueryParams params = dataQueryService.getFromRequest(request);
contextUtils.configureAnalyticsResponse(response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.RESPECT_SYSTEM_SETTING, "data.jrxml", false, params.getLatestEndDate());
Grid grid = analyticsService.getAggregatedDataValues(params);
GridUtils.toJrxml(grid, null, response.getWriter());
}
use of org.hisp.dhis.common.DataQueryRequest in project dhis2-core by dhis2.
the class AnalyticsController method getRawDataJson.
// -------------------------------------------------------------------------
// Raw data
// -------------------------------------------------------------------------
@GetMapping(value = RESOURCE_PATH + RAW_DATA_PATH + ".json")
@ResponseBody
public Grid getRawDataJson(AggregateAnalyticsQueryCriteria criteria, DhisApiVersion apiVersion, HttpServletResponse response) {
final DataQueryRequest request = DataQueryRequest.newBuilder().fromCriteria(criteria).apiVersion(apiVersion).allowAllPeriods(true).build();
DataQueryParams params = dataQueryService.getFromRequest(request);
contextUtils.configureAnalyticsResponse(response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.RESPECT_SYSTEM_SETTING, null, false, params.getLatestEndDate());
return analyticsService.getRawDataValues(params);
}
use of org.hisp.dhis.common.DataQueryRequest in project dhis2-core by dhis2.
the class GeoFeatureService method getGeoFeatures.
/**
* Returns a list of {@link GeoFeature}. Returns null if not modified based
* on the request.
*
* @param parameters the {@link Parameters} passing from controller.
* @return a list of geo features or null.
*/
public List<GeoFeature> getGeoFeatures(Parameters parameters) {
Attribute geoJsonAttribute = validateCoordinateField(parameters.getCoordinateField());
Set<String> dimensionParams = new HashSet<>();
dimensionParams.add(parameters.getOrganisationUnit());
dimensionParams.add(parameters.getOrganisationUnitGroupId());
DataQueryRequest dataQueryRequest = DataQueryRequest.newBuilder().dimension(dimensionParams).aggregationType(AggregationType.SUM).displayProperty(parameters.getDisplayProperty()).relativePeriodDate(parameters.getRelativePeriodDate()).userOrgUnit(parameters.getUserOrgUnit()).apiVersion(parameters.getApiVersion()).build();
DataQueryParams params = dataQueryService.getFromRequest(dataQueryRequest);
boolean useOrgUnitGroup = parameters.getOrganisationUnit() == null;
DimensionalObject dimensionalObject = params.getDimension(useOrgUnitGroup ? ORGUNIT_GROUP_DIM_ID : ORGUNIT_DIM_ID);
if (dimensionalObject == null) {
throw new IllegalArgumentException("Dimension is present in query without any valid dimension options");
}
List<DimensionalItemObject> dimensionalItemObjects = DimensionalObjectUtils.asTypedList(dimensionalObject.getItems());
dimensionalItemObjects = dimensionalItemObjects.stream().filter(object -> validateDimensionalItemObject(object, geoJsonAttribute)).collect(Collectors.toList());
boolean modified = !ContextUtils.clearIfNotModified(parameters.getRequest(), parameters.getResponse(), dimensionalItemObjects);
if (!modified) {
return null;
}
return getGeoFeatures(params, dimensionalItemObjects, parameters.isIncludeGroupSets(), useOrgUnitGroup, geoJsonAttribute);
}
Aggregations