}
@Override
protected GroupOperationHistoryCriteria getFetchCriteria(final DSRequest request) {
//initialize criteria
GroupOperationHistoryCriteria criteria = new GroupOperationHistoryCriteria();
//retrieve group identifier
if (request.getCriteria().getValues().containsKey(CriteriaField.GROUP_ID)) {
int groupId = Integer.parseInt((String) request.getCriteria().getValues().get(CriteriaField.GROUP_ID));
criteria.addFilterResourceGroupIds(Arrays.asList(groupId));
}
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
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
property = portletConfig.getSimple(Constant.OPERATION_STATUS);
if (property != null) {
currentSetting = portletConfig.getSimpleValue(Constant.OPERATION_STATUS,
Constant.OPERATION_STATUS_DEFAULT);
String[] parsedValues = currentSetting.trim().split(",");
if (currentSetting.trim().isEmpty() || parsedValues.length == OperationRequestStatus.values().length) {
//all operation stati assumed
} else {
OperationRequestStatus[] operationStati = new OperationRequestStatus[parsedValues.length];
int indx = 0;
for (String priority : parsedValues) {
OperationRequestStatus s = OperationRequestStatus.valueOf(priority);
operationStati[indx++] = s;
}
criteria.addFilterStatuses(operationStati);
}
}
}
return criteria;
}