/*
* creating an alert via an alertDefinition automatically creates the needed auditing data structures such as
* alertConditionLogs and alertNotificationLogs
*/
Alert newAlert = new Alert(alertDefinition, System.currentTimeMillis());
/*
* the AlertConditionLog children objects are already in the database, we need to persist the alert first
* to prevent:
*
* "TransientObjectException: object references an unsaved transient instance - save the transient instance before
* flushing org.jboss.on.domain.event.alert.AlertConditionLog.alert -> org.jboss.on.domain.event.alert.Alert"
*/
entityManager.persist(newAlert);
if (log.isDebugEnabled()) {
log.debug("New alert identifier=" + newAlert.getId());
}
// AlertNotificationLog alertNotifLog = new AlertNotificationLog(newAlert); TODO - is that all?
// entityManager.persist(alertNotifLog);
List<AlertConditionLog> unmatchedConditionLogs = alertConditionLogManager
.getUnmatchedLogsByAlertDefinitionId(alertDefinitionId);
for (AlertConditionLog unmatchedLog : unmatchedConditionLogs) {
if (log.isDebugEnabled()) {
log.debug("Matched alert condition log for alertId=" + newAlert.getId() + ": " + unmatchedLog);
}
newAlert.addConditionLog(unmatchedLog); // adds both relationships
}
// process recovery actions
processRecovery(alertDefinition);