use of com.evolveum.midpoint.notifications.api.transports.Transport in project midpoint by Evolveum.
the class CustomNotifier method processEvent.
@Override
public boolean processEvent(Event event, EventHandlerType eventHandlerType, NotificationManager notificationManager, Task task, OperationResult parentResult) throws SchemaException {
OperationResult result = parentResult.createSubresult(CustomNotifier.class.getName() + ".processEvent");
logStart(getLogger(), event, eventHandlerType);
boolean applies = aggregatedEventHandler.processEvent(event, eventHandlerType, notificationManager, task, result);
if (applies) {
CustomNotifierType config = (CustomNotifierType) eventHandlerType;
ExpressionVariables variables = getDefaultVariables(event, result);
if (event instanceof ModelEvent) {
((ModelEvent) event).getModelContext().reportProgress(new ProgressInformation(NOTIFICATIONS, ENTERING));
}
List<String> transports = new ArrayList<>(config.getTransport());
if (transports.isEmpty()) {
transports.add(customTransport.getName());
}
try {
for (String transportName : config.getTransport()) {
variables.addVariableDefinition(SchemaConstants.C_TRANSPORT_NAME, transportName);
Transport transport = notificationManager.getTransport(transportName);
Message message = getMessageFromExpression(config, variables, task, result);
if (message != null) {
getLogger().trace("Sending notification via transport {}:\n{}", transportName, message);
transport.send(message, transportName, event, task, result);
} else {
getLogger().debug("No message for transport {}, won't send anything", transportName);
}
}
} finally {
if (event instanceof ModelEvent) {
((ModelEvent) event).getModelContext().reportProgress(new ProgressInformation(NOTIFICATIONS, result));
}
}
}
logEnd(getLogger(), event, eventHandlerType, applies);
result.computeStatusIfUnknown();
// not-applicable notifiers do not stop processing of other notifiers
return true;
}
use of com.evolveum.midpoint.notifications.api.transports.Transport in project midpoint by Evolveum.
the class GeneralNotifier method processEvent.
@Override
public boolean processEvent(Event event, EventHandlerType eventHandlerType, NotificationManager notificationManager, Task task, OperationResult parentResult) throws SchemaException {
OperationResult result = parentResult.createSubresult(GeneralNotifier.class.getName() + ".processEvent");
logStart(getLogger(), event, eventHandlerType);
boolean applies = aggregatedEventHandler.processEvent(event, eventHandlerType, notificationManager, task, result);
if (applies) {
GeneralNotifierType generalNotifierType = (GeneralNotifierType) eventHandlerType;
if (!quickCheckApplicability(event, generalNotifierType, result)) {
// nothing to do -- an appropriate message has to be logged in quickCheckApplicability method
} else {
if (!checkApplicability(event, generalNotifierType, result)) {
// nothing to do -- an appropriate message has to be logged in checkApplicability method
} else if (generalNotifierType.getTransport().isEmpty()) {
getLogger().warn("No transports for this notifier, exiting without sending any notifications.");
} else {
ExpressionVariables variables = getDefaultVariables(event, result);
if (event instanceof ModelEvent) {
((ModelEvent) event).getModelContext().reportProgress(new ProgressInformation(NOTIFICATIONS, ENTERING));
}
try {
for (String transportName : generalNotifierType.getTransport()) {
variables.addVariableDefinition(SchemaConstants.C_TRANSPORT_NAME, transportName);
Transport transport = notificationManager.getTransport(transportName);
List<String> recipientsAddresses = getRecipientsAddresses(event, generalNotifierType, variables, getDefaultRecipient(event, generalNotifierType, result), transportName, transport, task, result);
if (!recipientsAddresses.isEmpty()) {
String body = getBodyFromExpression(event, generalNotifierType, variables, task, result);
String subject = getSubjectFromExpression(event, generalNotifierType, variables, task, result);
String from = getFromFromExpression(event, generalNotifierType, variables, task, result);
String contentType = getContentTypeFromExpression(event, generalNotifierType, variables, task, result);
if (body == null) {
body = getBody(event, generalNotifierType, transportName, task, result);
}
if (subject == null) {
subject = generalNotifierType.getSubjectPrefix() != null ? generalNotifierType.getSubjectPrefix() : "";
subject += getSubject(event, generalNotifierType, transportName, task, result);
}
Message message = new Message();
message.setBody(body != null ? body : "");
if (contentType != null) {
message.setContentType(contentType);
} else if (generalNotifierType.getContentType() != null) {
message.setContentType(generalNotifierType.getContentType());
}
message.setSubject(subject);
if (from != null) {
message.setFrom(from);
}
message.setTo(recipientsAddresses);
message.setCc(getCcBccAddresses(generalNotifierType.getCcExpression(), variables, "notification cc-expression", task, result));
message.setBcc(getCcBccAddresses(generalNotifierType.getBccExpression(), variables, "notification bcc-expression", task, result));
getLogger().trace("Sending notification via transport {}:\n{}", transportName, message);
transport.send(message, transportName, event, task, result);
} else {
getLogger().info("No recipients addresses for transport " + transportName + ", message corresponding to event " + event.getId() + " will not be send.");
}
}
} finally {
if (event instanceof ModelEvent) {
((ModelEvent) event).getModelContext().reportProgress(new ProgressInformation(NOTIFICATIONS, result));
}
}
}
}
}
logEnd(getLogger(), event, eventHandlerType, applies);
result.computeStatusIfUnknown();
// not-applicable notifiers do not stop processing of other notifiers
return true;
}
use of com.evolveum.midpoint.notifications.api.transports.Transport in project midpoint by Evolveum.
the class NotificationManagerImpl method getTransport.
// accepts name:subname (e.g. dummy:accounts) - a primitive form of passing parameters (will be enhanced/replaced in the future)
@Override
public Transport getTransport(String name) {
String key = name.split(":")[0];
Transport transport = transports.get(key);
if (transport == null) {
throw new IllegalStateException("Unknown transport named " + key);
} else {
return transport;
}
}
Aggregations