//Set used capabilities in login environment
loginEnv.getUsedCapabilities().add(AISClientCapability.DATA_SERVICE);
loginEnv.getUsedCapabilities().add(AISClientCapability.DATA_SERVICE_AGGREGATION);
//create a new data request for V0101
DataRequest dataAggregation = new DataRequest(loginEnv);
//set type to aggregation
dataAggregation.setDataServiceType(DataRequest.TYPE_AGGREGATION);
dataAggregation.setTargetName("V0101");
dataAggregation.setTargetType(DataRequest.TARGET_VIEW);
//create aggergation info object
AggregationInfo aggregation = new AggregationInfo(loginEnv);
//add desired aggregations
aggregation.addAggrigationColumn("AN8", AggregationType.AGG_TYPE_SUM());
aggregation.addAggrigationColumn("AN8", AggregationType.AGG_TYPE_AVG());
aggregation.addAggrigationColumn("AT1", AggregationType.AGG_TYPE_COUNT_DISTINCT());
aggregation.addCount(); //this is for COUNT *
//add aggregation to request
dataAggregation.setAggregation(aggregation);
//query can be combined with aggregation
Query an8Query = new Query(loginEnv);
an8Query.setAutoFind(true);
an8Query.setMatchType(Query.MATCH_ALL);
an8Query.addNumberCondition("F0101.AN8", NumericOperator.LESS(), 6001);
dataAggregation.setQuery(an8Query);
//create a second datat request for F060116 aggregatoin
DataRequest dataAggregation2 = new DataRequest(loginEnv);
dataAggregation2.setFindOnEntry(true);
dataAggregation2.setDataServiceType(DataRequest.TYPE_AGGREGATION);
dataAggregation2.setTargetName("F060116");
dataAggregation2.setTargetType(DataRequest.TARGET_TABLE);
//create aggregation info object and add desired aggredgations
AggregationInfo aggregation2 = new AggregationInfo(loginEnv);
aggregation2.addAggrigationColumn("SAL", AggregationType.AGG_TYPE_SUM());
aggregation2.addAggrigationColumn("SAL", AggregationType.AGG_TYPE_AVG());
aggregation2.addAggrigationColumn("SAL", AggregationType.AGG_TYPE_AVG_DISTINCT());
aggregation2.addAggrigationColumn("SAL", AggregationType.AGG_TYPE_MAX());
aggregation2.addAggrigationColumn("SAL", AggregationType.AGG_TYPE_MIN());
aggregation2.addAggrigationColumn("SAL", AggregationType.AGG_TYPE_SUM_DISTINCT());
aggregation2.addCount();
aggregation2.addAggrigationColumn("AN8", AggregationType.AGG_TYPE_COUNT_DISTINCT());
//add desired group by columnst
aggregation2.addAggrigationGroupBy("HMCO");
aggregation2.addAggrigationGroupBy("HMCU");
//add desired order by with direction
aggregation2.addAggrigationOrderBy("HMCO", OrderByDirection.ORDER_DIRECT_DESCENDING());
//set the aggregation info in the request
dataAggregation2.setAggregation(aggregation2);
//add these two requests to a batch data request
BatchDataRequest batchDataRequest = new BatchDataRequest(loginEnv);
batchDataRequest.getDataRequests().add(dataAggregation);
batchDataRequest.getDataRequests().add(dataAggregation2);
//call the service
String response = JDERestServiceProvider.jdeRestServiceCall(loginEnv, batchDataRequest, JDERestServiceProvider.POST_METHOD, JDERestServiceProvider.DATA_SERVICE_URI);
//get the number of distinct AT1 values
JsonNode distinct = AggregationResponseHelper.getSimpleAggregateValueBatch(response, "V0101", 0, AggregationType.AGG_TYPE_COUNT_DISTINCT(), "AT1");
if (distinct != null)
{
System.out.println("AT1 Distinct: " + distinct.asInt());
}
//get the count *
System.out.println("Count: " +AggregationResponseHelper.getCountBatch(response, "V0101", 0));
//get the grouped aggregations from the F060116 response, loop trhough and add the specific one (average to a hash map by group by)
ArrayNode array = AggregationResponseHelper.getAggregateValuesArrayBtach(response, "F060116", 1);
HashMap<String, Object> chartMap = new HashMap<String, Object>();
for (Iterator groups = array.iterator(); groups.hasNext();)
{
JsonNode aGroup = (JsonNode) groups.next();
JsonNode groupByInfo = aGroup.get(AggregationResponseHelper.GROUP_BY);
JsonNode average = aGroup.get("SAL_SUM");
chartMap.put(groupByInfo.get("HMCO").asText().trim() + "-" + groupByInfo.get("HMCU").asText().trim(), average.asDouble());
}
//print the map
System.out.println("SAL SUM by HMCO/HMCU Map: " + chartMap);