request.setAttribute("noneDeleted", Constants.ALERT_CONDITION_NONE_DELETED);
MeasurementScheduleManagerLocal scheduleManager = LookupUtil.getMeasurementScheduleManager();
MeasurementDefinitionManagerLocal definitionManager = LookupUtil.getMeasurementDefinitionManager();
ConfigurationManagerLocal configurationManager = LookupUtil.getConfigurationManager();
Subject subject = RequestUtils.getSubject(request);
Resource resource = RequestUtils.getResource(request);
ResourceGroup group = RequestUtils.getResourceGroupIfExists(request);
ResourceType type = null;
if (resource != null) {
// resource alert definition
type = resource.getResourceType();
} else if (group != null) {
// group alert definition
type = group.getResourceType();
} else {
// template alert definition
type = RequestUtils.getResourceType(request);
}
defForm.setResourceType(type.getId());
List<MeasurementDefinition> dataDefinitions = definitionManager.findMeasurementDefinitionsByResourceType(
subject, type.getId(), DataType.MEASUREMENT, null);
List<MeasurementDefinition> calltimeDefinitions = definitionManager.findMeasurementDefinitionsByResourceType(
subject, type.getId(), DataType.CALLTIME, null);
List<MeasurementDefinition> traitDefinitions = definitionManager.findMeasurementDefinitionsByResourceType(
subject, type.getId(), DataType.TRAIT, null);
List<RelatedOptionBean> baselines = new ArrayList<RelatedOptionBean>();
if (resource != null) {
for (MeasurementDefinition definition : dataDefinitions) {
MeasurementSchedule schedule = scheduleManager.getSchedule(subject, resource.getId(), definition
.getId(), false);
RelatedOptionBean rob = new RelatedOptionBean(definition.getName(), String.valueOf(definition.getId()),
getBaselineList(schedule));
baselines.add(rob);
setDisabledName(schedule, definition);
}
for (MeasurementDefinition definition : traitDefinitions) {
MeasurementSchedule schedule = scheduleManager.getSchedule(subject, resource.getId(), definition
.getId(), false);
setDisabledName(schedule, definition);
}
} else {
List<LabelValueBean> defaultBaselineLabels = getBaselineList(null);
for (MeasurementDefinition definition : dataDefinitions) {
RelatedOptionBean rob = new RelatedOptionBean(definition.getName(), String.valueOf(definition.getId()),
defaultBaselineLabels);
baselines.add(rob);
}
}
defForm.setMetrics(dataDefinitions);
defForm.setCalltimeMetrics(calltimeDefinitions);
defForm.setTraits(traitDefinitions);
defForm.setBaselines(baselines);
request.setAttribute("baselines", baselines); // need to duplicate this for the JavaScript on the page
List<OptionItem> controlActions = new ArrayList<OptionItem>();
OperationManagerLocal operationManager = LookupUtil.getOperationManager();
// do not need to eagerly load the definitions because only name and displayName are needed
for (OperationDefinition action : operationManager.findSupportedResourceTypeOperations(subject, type.getId(),
false)) {
OptionItem actionItem = new OptionItem(action.getDisplayName(), action.getName());
controlActions.add(actionItem);
}
defForm.setControlActions(controlActions);
ConfigurationDefinition configurationDefinition = configurationManager
.getResourceConfigurationDefinitionForResourceType(subject, type.getId());
defForm.setResourceConfigurationSupported(configurationDefinition != null);
}