}
@Override
protected ResourceConfigurationUpdateCriteria getFetchCriteria(final DSRequest request) {
//initialize criteria
ResourceConfigurationUpdateCriteria criteria = new ResourceConfigurationUpdateCriteria();
criteria.addFilterResourceIds(resourceId);
//initialize to only five for quick queries.
PageControl pageControl = new PageControl(0, Integer.valueOf(Constant.RESULT_COUNT_DEFAULT));
//customize query with latest configuration selections
//retrieve previous settings from portlet config
if (portletConfig != null) {
// //result sort order
// PropertySimple property = portletConfig.getSimple(Constant.RESULT_SORT_ORDER);
// if (property != null) {
// String currentSetting = property.getStringValue();
// if (currentSetting.trim().isEmpty() || currentSetting.equalsIgnoreCase(PageOrdering.DESC.name())) {
// criteria.addSortStatus(PageOrdering.DESC);
// } else {
// criteria.addSortStatus(PageOrdering.ASC);
// }
// }
//result timeframe if enabled
PropertySimple property = portletConfig.getSimple(Constant.METRIC_RANGE_ENABLE);
if (null != property && Boolean.valueOf(property.getBooleanValue())) {//then proceed setting
//detect type of widget[Simple|Advanced]
boolean isAdvanced = Boolean.valueOf(portletConfig.getSimpleValue(
Constant.METRIC_RANGE_BEGIN_END_FLAG, Constant.METRIC_RANGE_BEGIN_END_FLAG_DEFAULT));
if (isAdvanced) {
//Advanced time settings
String 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
String currentSetting = portletConfig.getSimpleValue(Constant.RESULT_COUNT,
Constant.RESULT_COUNT_DEFAULT);
if (currentSetting.trim().isEmpty()) {
pageControl.setPageSize(Integer.valueOf(Constant.RESULT_COUNT_DEFAULT));
} else {
pageControl.setPageSize(Integer.valueOf(currentSetting));
}
criteria.setPageControl(pageControl);
//detect operation status filter
String configUpdateStatus = portletConfig.getSimpleValue(Constant.CONFIG_UPDATE_STATUS,
Constant.CONFIG_UPDATE_STATUS_DEFAULT);
String[] parsedValues = configUpdateStatus.trim().split(",");
if (configUpdateStatus.trim().isEmpty()
|| parsedValues.length == ConfigurationUpdateStatus.values().length) {
//all operation stati assumed
} else {
ConfigurationUpdateStatus[] updateStatus = new ConfigurationUpdateStatus[parsedValues.length];
int indx = 0;
for (String priority : parsedValues) {
ConfigurationUpdateStatus s = ConfigurationUpdateStatus.valueOf(priority);
updateStatus[indx++] = s;
}
criteria.addFilterStatuses(updateStatus);
}
}
return criteria;
}