if (LOG.isDebugEnabled()) {
LOG.debug("updateAlertTemplate: " + alertTemplate);
}
// first update the actual alert template
AlertDefinition updated = null;
try {
updated = alertDefinitionManager.updateAlertDefinition(user, alertTemplate.getId(), alertTemplate,
resetMatching); // do not allow direct undeletes of an alert definition
} catch (Throwable t) {
throw new AlertDefinitionUpdateException("Failed to update an AlertTemplate "
+ alertTemplate.toSimpleString(), t);
}
// overlord will be used for all system-side effects as a result of updating this alert template
Subject overlord = subjectManager.getOverlord();
Throwable firstThrowable = null;
// update all of the definitions that were spawned from alert templates
List<Integer> alertDefinitions = getChildrenAlertDefinitionIds(overlord, alertTemplate.getId());
if (LOG.isDebugEnabled()) {
LOG.debug("Need to update the following children alert definition ids: " + alertDefinitions);
}
List<Integer> alertDefinitionIdsInError = new ArrayList<Integer>();
for (Integer alertDefinitionId : alertDefinitions) {
try {
alertDefinitionManager.updateDependentAlertDefinition(user, alertDefinitionId, updated, resetMatching);
} catch (Throwable t) {
// continue on error, update as many as possible
if (firstThrowable == null) {
firstThrowable = t;
}
alertDefinitionIdsInError.add(alertDefinitionId);
}
}
// if the user deleted the alert definition spawned from a template, a cascade update will recreate it
List<Integer> resourceIds = getCommittedResourceIdsNeedingTemplateApplication(overlord, alertTemplate.getId(),
getResourceTypeIdForAlertTemplateId(alertTemplate.getId()));
if (LOG.isDebugEnabled()) {
LOG.debug("Need to re-create alert definitions for the following resource ids: " + resourceIds);
}
List<Integer> resourceIdsInError = new ArrayList<Integer>();
for (Integer resourceId : resourceIds) {
try {
// construct the child
AlertDefinition childAlertDefinition = new AlertDefinition(updated);
childAlertDefinition.setParentId(alertTemplate.getId());
// persist the child
alertDefinitionManager.createAlertDefinitionInNewTransaction(overlord, childAlertDefinition,
resourceId, false);
} catch (Throwable t) {