return result.size();
}
@Override
protected EventCriteria getFetchCriteria(DSRequest request) {
EventCriteria criteria = new EventCriteria();
// event source filter
String currentSetting = this.configuration.getSimpleValue(Constant.EVENT_SOURCE, "");
criteria.addFilterSourceName(currentSetting);
// result count
currentSetting = this.configuration.getSimpleValue(Constant.RESULT_COUNT,
Constant.RESULT_COUNT_DEFAULT);
int pageNumber = 0;
int pageSize = Integer.valueOf(currentSetting);
OrderingField orderingField = new OrderingField("timestamp", PageOrdering.DESC);
criteria.setPageControl(new PageControl(pageNumber, pageSize, orderingField));
// filter severity
currentSetting = this.configuration
.getSimpleValue(Constant.EVENT_SEVERITY, Constant.EVENT_SEVERITY_DEFAULT);
String[] parsedValues = currentSetting.trim().split(",");
if (!(currentSetting.trim().isEmpty() || parsedValues.length == EventSeverity.values().length)) {
EventSeverity[] filterSeverities = new EventSeverity[parsedValues.length];
int index = 0;
for (String severity : parsedValues) {
EventSeverity p = EventSeverity.valueOf(severity);
filterSeverities[index++] = p;
}
criteria.addFilterSeverities(filterSeverities);
}
//result timeframe if enabled
PropertySimple property = configuration.getSimple(Constant.METRIC_RANGE_ENABLE);
if (null != property && Boolean.valueOf(property.getBooleanValue())) { //then proceed setting
boolean isAdvanced = Boolean.valueOf(configuration.getSimpleValue(Constant.METRIC_RANGE_BEGIN_END_FLAG,
Constant.METRIC_RANGE_BEGIN_END_FLAG_DEFAULT));
if (isAdvanced) {
//Advanced time settings
currentSetting = configuration.getSimpleValue(Constant.METRIC_RANGE, Constant.METRIC_RANGE_DEFAULT);
String[] range = currentSetting.split(",");
if (range.length == 2) {
criteria.addFilterStartTime(Long.valueOf(range[0]));
criteria.addFilterEndTime(Long.valueOf(range[1]));
}
} else {
//Simple time settings
property = configuration.getSimple(Constant.METRIC_RANGE_LASTN);
if (property != null) {
Integer lastN = Integer.valueOf(configuration.getSimpleValue(Constant.METRIC_RANGE_LASTN,
Constant.METRIC_RANGE_LASTN_DEFAULT));
Integer units = Integer.valueOf(configuration.getSimpleValue(Constant.METRIC_RANGE_UNIT,
Constant.METRIC_RANGE_UNIT_DEFAULT));
ArrayList<Long> beginEnd = MeasurementUtility.calculateTimeFrame(lastN, units);
criteria.addFilterStartTime(Long.valueOf(beginEnd.get(0)));
criteria.addFilterEndTime(Long.valueOf(beginEnd.get(1)));
}
}
}
// add any context related filters
switch (getEntityContext().type) {
case Resource:
criteria.addFilterResourceId(getEntityContext().getResourceId());
break;
case ResourceGroup:
criteria.addFilterResourceGroupId(getEntityContext().getGroupId());
case SubsystemView:
// event resource name filter
currentSetting = this.configuration.getSimpleValue(Constant.EVENT_RESOURCE, "");
criteria.addFilterResourceName(currentSetting);
break;
default:
// no default
break;
}
criteria.fetchSource(true);
return criteria;
}