
com.obj.nc.functions.processors.messageBuilder.MessageByRecipientTokenizer Maven / Gradle / Ivy
/*
* Copyright (C) 2021 the original author or authors.
*
* This file is part of Notiflow
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
package com.obj.nc.functions.processors.messageBuilder;
import com.obj.nc.aspects.DocumentProcessingInfo;
import com.obj.nc.domain.content.MessageContent;
import com.obj.nc.domain.endpoints.ReceivingEndpoint;
import com.obj.nc.domain.message.Message;
import com.obj.nc.exceptions.PayloadValidationException;
import com.obj.nc.functions.processors.ProcessorFunctionAdapter;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Component
@AllArgsConstructor
@Slf4j
@DocumentProcessingInfo("MessageByRecipientTokenizer")
public class MessageByRecipientTokenizer extends ProcessorFunctionAdapter, List>> {
@Override
protected Optional checkPreCondition(Message notificationIntent) {
if (notificationIntent.getReceivingEndpoints().isEmpty()) {
return Optional.of(new PayloadValidationException(
String.format("Message %s has no receiving endpoints defined.", notificationIntent)));
}
return Optional.empty();
}
@Override
@SneakyThrows
protected List> execute(Message msg) {
log.debug("Tokenizing message {} for recipients", msg);
List> messages = new ArrayList<>();
for (ReceivingEndpoint receivingEndpoint: msg.getReceivingEndpoints()) {
Message msgClone = Message.newTypedMessageFrom(msg.getClass(), msg);
msgClone.addReceivingEndpoints(receivingEndpoint);
msgClone.setAttributes(msg.getAttributes());
msgClone.setBody(msg.getBody());
messages.add(msgClone);
}
return messages;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy