@Override
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public List<List<MeasurementDataNumericHighLowComposite>> findDataForContext(Subject subject,
EntityContext context, int definitionId, long beginTime, long endTime, int numDataPoints) {
MetricsServer metricsServer = storageClientManager.getMetricsServer();
if (context.type == EntityContext.Type.Resource) {
if (!authorizationManager.canViewResource(subject, context.resourceId)) {
throw new PermissionException("User [" + subject.getName()
+ "] does not have permission to view measurement data for resource[id=" + context.resourceId + "]");
}
MeasurementSchedule schedule = measurementScheduleManager.getSchedule(subject, context.getResourceId(),
definitionId, false);
List<List<MeasurementDataNumericHighLowComposite>> data =
new ArrayList<List<MeasurementDataNumericHighLowComposite>>();
List<MeasurementDataNumericHighLowComposite> tempList = new ArrayList<MeasurementDataNumericHighLowComposite>();
for (MeasurementDataNumericHighLowComposite object : metricsServer.findDataForResource(schedule.getId(),
beginTime, endTime, numDataPoints)) {
tempList.add(object);
}
data.add(tempList);
return data;
} else if (context.type == EntityContext.Type.ResourceGroup) {
if (!authorizationManager.canViewGroup(subject, context.groupId)) {
throw new PermissionException("User [" + subject.getName()
+ "] does not have permission to view measurement data for resourceGroup[id=" + context.groupId
+ "]");
}
MeasurementScheduleCriteria criteria = new MeasurementScheduleCriteria();
criteria.addFilterResourceGroupId(context.getGroupId());
criteria.addFilterDefinitionIds(definitionId);
criteria.setPageControl(PageControl.getUnlimitedInstance());
PageList<MeasurementSchedule> schedules = measurementScheduleManager.findSchedulesByCriteria(subject,
criteria);
List<List<MeasurementDataNumericHighLowComposite>> data =
new ArrayList<List<MeasurementDataNumericHighLowComposite>>();
List<MeasurementDataNumericHighLowComposite> tempList = new ArrayList<MeasurementDataNumericHighLowComposite>();
for (MeasurementDataNumericHighLowComposite object : metricsServer.findDataForGroup(map(schedules),
beginTime, endTime,numDataPoints)) {
tempList.add(object);
}
data.add(tempList);