} else {
calltimeCategory = false;
category = AlertConditionCategory.valueOf(selectedCategory);
}
AlertCondition newCondition = new AlertCondition();
newCondition.setCategory(category);
switch (category) {
case AVAILABILITY: {
newCondition.setName(form.getValueAsString(AVAILABILITY_ITEMNAME));
newCondition.setComparator(null);
newCondition.setThreshold(null);
newCondition.setOption(null);
newCondition.setMeasurementDefinition(null);
break;
}
case AVAIL_DURATION: {
newCondition.setName(form.getValueAsString(AVAILABILITY_DURATION_ITEMNAME));
newCondition.setComparator(null);
newCondition.setThreshold(null);
// entered in minutes, converted to seconds by DurationItem, and stored in seconds
int duration = Integer.valueOf(form.getValueAsString(AVAILABILITY_DURATION_VAL_ITEMNAME));
newCondition.setOption(String.valueOf(duration));
newCondition.setMeasurementDefinition(null);
break;
}
case THRESHOLD: {
if (!calltimeCategory) {
MeasurementDefinition measDef = getMeasurementDefinition(form
.getValueAsString(THRESHOLD_METRIC_ITEMNAME));
newCondition.setName(measDef.getDisplayName());
newCondition.setThreshold(getMeasurementValue(measDef,
form.getValueAsString(THRESHOLD_ABSVALUE_ITEMNAME)));
newCondition.setComparator(form.getValueAsString(THRESHOLD_COMPARATOR_ITEMNAME));
newCondition.setOption(null);
newCondition.setMeasurementDefinition(measDef);
} else {
MeasurementDefinition measDef = getMeasurementDefinition(form
.getValueAsString(CALLTIME_THRESHOLD_METRIC_ITEMNAME));
newCondition.setName(form.getValueAsString(CALLTIME_THRESHOLD_REGEX_ITEMNAME));
newCondition.setThreshold(getMeasurementValue(measDef,
form.getValueAsString(CALLTIME_THRESHOLD_ABSVALUE_ITEMNAME)));
newCondition.setComparator(form.getValueAsString(CALLTIME_THRESHOLD_COMPARATOR_ITEMNAME));
newCondition.setOption(form.getValueAsString(CALLTIME_THRESHOLD_MINMAXAVG_ITEMNAME));
newCondition.setMeasurementDefinition(measDef);
}
break;
}
case BASELINE: {
MeasurementDefinition measDef = getMeasurementDefinition(form
.getValueAsString(BASELINE_METRIC_ITEMNAME));
newCondition.setName(measDef.getDisplayName());
newCondition.setThreshold(getMeasurementValueByUnits(MeasurementUnits.PERCENTAGE,
form.getValueAsString(BASELINE_PERCENTAGE_ITEMNAME)));
newCondition.setComparator(form.getValueAsString(BASELINE_COMPARATOR_ITEMNAME));
newCondition.setOption(form.getValueAsString(BASELINE_SELECTION_ITEMNAME));
newCondition.setMeasurementDefinition(measDef);
break;
}
case CHANGE: {
if (!calltimeCategory) {
MeasurementDefinition measDef = getMeasurementDefinition(form
.getValueAsString(CHANGE_METRIC_ITEMNAME));
newCondition.setName(measDef.getDisplayName());
newCondition.setComparator(null);
newCondition.setThreshold(null);
newCondition.setOption(null);
newCondition.setMeasurementDefinition(measDef);
} else {
MeasurementDefinition measDef = getMeasurementDefinition(form
.getValueAsString(CALLTIME_CHANGE_METRIC_ITEMNAME));
newCondition.setName(form.getValueAsString(CALLTIME_CHANGE_REGEX_ITEMNAME));
newCondition.setThreshold(getMeasurementValueByUnits(MeasurementUnits.PERCENTAGE,
form.getValueAsString(CALLTIME_CHANGE_PERCENTAGE_ITEMNAME)));
newCondition.setComparator(form.getValueAsString(CALLTIME_CHANGE_COMPARATOR_ITEMNAME));
newCondition.setOption(form.getValueAsString(CALLTIME_CHANGE_MINMAXAVG_ITEMNAME));
newCondition.setMeasurementDefinition(measDef);
}
break;
}
case TRAIT: {
MeasurementDefinition measDef = getMeasurementDefinition(form.getValueAsString(TRAIT_METRIC_ITEMNAME));
newCondition.setName(measDef.getDisplayName());
newCondition.setComparator(null);
newCondition.setThreshold(null);
newCondition.setOption(form.getValueAsString(TRAIT_REGEX_ITEMNAME));
newCondition.setMeasurementDefinition(measDef);
break;
}
case CONTROL: {
newCondition.setName(form.getValueAsString(OPERATION_NAME_ITEMNAME));
newCondition.setComparator(null);
newCondition.setThreshold(null);
newCondition.setOption(form.getValueAsString(OPERATION_RESULTS_ITEMNAME));
newCondition.setMeasurementDefinition(null);
break;
}
case EVENT: {
newCondition.setName(form.getValueAsString(EVENT_SEVERITY_ITEMNAME));
newCondition.setComparator(null);
newCondition.setThreshold(null);
Object regex1 = form.getValue(EVENT_REGEX_ITEMNAME);
Object regex2 = form.getValue(EVENT_SOURCE_PATH_REGEX_ITEMNAME);
newCondition.setOption((regex1 == null ? "" : regex1) + AlertCondition.ADHOC_SEPARATOR
+ (regex2 == null ? "" : regex2));
newCondition.setMeasurementDefinition(null);
break;
}
case RESOURCE_CONFIG: {
newCondition.setName(null);
newCondition.setComparator(null);
newCondition.setThreshold(null);
newCondition.setOption(null);
newCondition.setMeasurementDefinition(null);
break;
}
case DRIFT: {
newCondition.setName(form.getValueAsString(DRIFT_DEFNAME_REGEX_ITEMNAME));
newCondition.setComparator(null);
newCondition.setThreshold(null);
newCondition.setOption(form.getValueAsString(DRIFT_PATHNAME_REGEX_ITEMNAME));
newCondition.setMeasurementDefinition(null);
break;
}
case RANGE: {
MeasurementDefinition measDef = getMeasurementDefinition(form.getValueAsString(RANGE_METRIC_ITEMNAME));
newCondition.setName(measDef.getDisplayName());
newCondition.setThreshold(getMeasurementValue(measDef,
form.getValueAsString(RANGE_LO_ABSVALUE_ITEMNAME)));
newCondition.setComparator(form.getValueAsString(RANGE_COMPARATOR_ITEMNAME));
newCondition.setOption(getMeasurementValue(measDef, form.getValueAsString(RANGE_HI_ABSVALUE_ITEMNAME))
.toString());
newCondition.setMeasurementDefinition(measDef);
break;
}
default: {
CoreGUI.getErrorHandler().handleError(
MSG.view_alert_common_tab_invalid_condition_category(category.name())); // should never happen
break;
}
}
if (editMode) {
if (existingCondition.getId() != 0) {
// get rid of the id, because of the equals method
AlertCondition conditionWithoutId = new AlertCondition(existingCondition);
if (!conditionWithoutId.equals(newCondition)) {
// there was a change
this.modifiedConditions.put(existingCondition.getId(), newCondition);
existingCondition.setMeasurementDefinition(newCondition.getMeasurementDefinition());
existingCondition.setName(newCondition.getName());
existingCondition.setComparator(newCondition.getComparator());