});
}
@Override
protected AlertCriteria getFetchCriteria(DSRequest request) {
AlertCriteria criteria = new AlertCriteria();
//retrieve previous settings from portlet config
if ((portlet != null) && (this.portlet instanceof DashboardPortlet)) {
Configuration portletConfig = configuration;
//filter priority, if null or empty then no priority filtering
String currentSetting = portletConfig.getSimpleValue(Constant.ALERT_PRIORITY,
Constant.ALERT_PRIORITY_DEFAULT);
if (!currentSetting.trim().isEmpty()) {
String[] parsedValues = currentSetting.trim().split(",");
if (parsedValues.length < AlertPriority.values().length) {
AlertPriority[] filterPriorities = new AlertPriority[parsedValues.length];
int indx = 0;
for (String priority : parsedValues) {
AlertPriority p = AlertPriority.valueOf(priority);
filterPriorities[indx++] = p;
}
criteria.addFilterPriorities(filterPriorities);
}
}
PageControl pc = new PageControl();
//result sort order
currentSetting = portletConfig.getSimpleValue(Constant.RESULT_SORT_ORDER,
Constant.RESULT_SORT_ORDER_DEFAULT);
if (currentSetting.trim().isEmpty()) {
pc.setPrimarySortOrder(PageOrdering.valueOf(Constant.RESULT_SORT_ORDER_DEFAULT));
} else {
pc.setPrimarySortOrder(PageOrdering.valueOf(currentSetting));
}
//result timeframe if enabled
PropertySimple property = portletConfig.getSimple(Constant.METRIC_RANGE_ENABLE);
if (null != property && Boolean.valueOf(property.getBooleanValue())) {//then proceed setting
boolean isAdvanced = Boolean.valueOf(portletConfig.getSimpleValue(Constant.METRIC_RANGE_BEGIN_END_FLAG,
Constant.METRIC_RANGE_BEGIN_END_FLAG_DEFAULT));
if (isAdvanced) {
//Advanced time settings
currentSetting = portletConfig.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 = portletConfig.getSimple(Constant.METRIC_RANGE_LASTN);
if (property != null) {
Integer lastN = Integer.valueOf(portletConfig.getSimpleValue(Constant.METRIC_RANGE_LASTN,
Constant.METRIC_RANGE_LASTN_DEFAULT));
Integer units = Integer.valueOf(portletConfig.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)));
}
}
}
//result count
currentSetting = portletConfig.getSimpleValue(Constant.RESULT_COUNT, Constant.RESULT_COUNT_DEFAULT);
if (currentSetting.trim().isEmpty()) {
pc.setPageSize(Integer.valueOf(Constant.RESULT_COUNT_DEFAULT));
} else {
pc.setPageSize(Integer.valueOf(currentSetting));
}
criteria.setPageControl(pc);
if (groupId != null) {
criteria.addFilterResourceGroupIds(groupId);
}
if ((resourceIds != null) && (resourceIds.length > 0)) {
criteria.addFilterResourceIds(resourceIds);
}
}
criteria.fetchAlertDefinition(true);
criteria.fetchRecoveryAlertDefinition(true);
criteria.fetchConditionLogs(true);
return criteria;
}