Search in sources :

Example 1 with CustomTransportConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CustomTransportConfigurationType in project midpoint by Evolveum.

the class CustomTransport method send.

@Override
public void send(Message message, String transportName, Event event, Task task, OperationResult parentResult) {
    OperationResult result = parentResult.createSubresult(DOT_CLASS + "send");
    result.addCollectionOfSerializablesAsParam("message recipient(s)", message.getTo());
    result.addParam("message subject", message.getSubject());
    SystemConfigurationType systemConfiguration = NotificationFunctionsImpl.getSystemConfiguration(cacheRepositoryService, result);
    if (systemConfiguration == null || systemConfiguration.getNotificationConfiguration() == null) {
        String msg = "No notifications are configured. Custom notification to " + message.getTo() + " will not be sent.";
        LOGGER.warn(msg);
        result.recordWarning(msg);
        return;
    }
    // after "sms:"
    String configName = transportName.length() > NAME.length() ? transportName.substring(NAME.length() + 1) : null;
    CustomTransportConfigurationType configuration = systemConfiguration.getNotificationConfiguration().getCustomTransport().stream().filter(transportConfigurationType -> java.util.Objects.equals(configName, transportConfigurationType.getName())).findFirst().orElse(null);
    if (configuration == null) {
        String msg = "Custom configuration '" + configName + "' not found. Custom notification to " + message.getTo() + " will not be sent.";
        LOGGER.warn(msg);
        result.recordWarning(msg);
        return;
    }
    String file = configuration.getRedirectToFile();
    if (file != null) {
        writeToFile(message, file, result);
        return;
    }
    try {
        evaluateExpression(configuration.getExpression(), getDefaultVariables(message, event), "custom transport expression", task, result);
        LOGGER.trace("Custom transport expression execution finished");
        result.recordSuccess();
    } catch (Throwable t) {
        String msg = "Couldn't execute custom transport expression";
        LoggingUtils.logException(LOGGER, msg, t);
        result.recordFatalError(msg + ": " + t.getMessage(), t);
    }
}
Also used : CustomTransportConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.CustomTransportConfigurationType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 CustomTransportConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.CustomTransportConfigurationType)1 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)1