use of org.finra.herd.model.dto.MessageHeader in project herd by FINRAOS.
the class DefaultNotificationMessageBuilder method buildBusinessObjectFormatVersionChangeMessages.
@Override
public List<NotificationMessage> buildBusinessObjectFormatVersionChangeMessages(BusinessObjectFormatKey businessObjectFormatKey, String oldBusinessObjectFormatVersion) {
// Create a result list.
List<NotificationMessage> notificationMessages = new ArrayList<>();
// Get notification message definitions.
NotificationMessageDefinitions notificationMessageDefinitions = configurationDaoHelper.getXmlClobPropertyAndUnmarshallToObject(NotificationMessageDefinitions.class, ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_FORMAT_VERSION_CHANGE_MESSAGE_DEFINITIONS.getKey());
// Continue processing if notification message definitions are configured.
if (notificationMessageDefinitions != null && CollectionUtils.isNotEmpty(notificationMessageDefinitions.getNotificationMessageDefinitions())) {
// Create a context map of values that can be used when building the message.
Map<String, Object> velocityContextMap = getBusinessObjectFormatVersionChangeMessageVelocityContextMap(businessObjectFormatKey, oldBusinessObjectFormatVersion);
// Generate notification message for each notification message definition.
for (NotificationMessageDefinition notificationMessageDefinition : notificationMessageDefinitions.getNotificationMessageDefinitions()) {
// Validate the notification message type.
if (StringUtils.isBlank(notificationMessageDefinition.getMessageType())) {
throw new IllegalStateException(String.format("Notification message type must be specified. Please update \"%s\" configuration entry.", ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_FORMAT_VERSION_CHANGE_MESSAGE_DEFINITIONS.getKey()));
}
// Validate the notification message destination.
if (StringUtils.isBlank(notificationMessageDefinition.getMessageDestination())) {
throw new IllegalStateException(String.format("Notification message destination must be specified. Please update \"%s\" configuration entry.", ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_FORMAT_VERSION_CHANGE_MESSAGE_DEFINITIONS.getKey()));
}
// Evaluate the template to generate the message text.
String messageText = evaluateVelocityTemplate(notificationMessageDefinition.getMessageVelocityTemplate(), velocityContextMap, "businessObjectFormatVersionChangeEvent");
// Build a list of optional message headers.
List<MessageHeader> messageHeaders = new ArrayList<>();
if (CollectionUtils.isNotEmpty(notificationMessageDefinition.getMessageHeaderDefinitions())) {
for (MessageHeaderDefinition messageHeaderDefinition : notificationMessageDefinition.getMessageHeaderDefinitions()) {
messageHeaders.add(new MessageHeader(messageHeaderDefinition.getKey(), evaluateVelocityTemplate(messageHeaderDefinition.getValueVelocityTemplate(), velocityContextMap, String.format("businessObjectFormatVersionChangeEvent_messageHeader_%s", messageHeaderDefinition.getKey()))));
}
}
// Create a notification message and add it to the result list.
notificationMessages.add(new NotificationMessage(notificationMessageDefinition.getMessageType(), notificationMessageDefinition.getMessageDestination(), messageText, messageHeaders));
}
}
// Return the results.
return notificationMessages;
}
use of org.finra.herd.model.dto.MessageHeader in project herd by FINRAOS.
the class DefaultNotificationMessageBuilder method buildStorageUnitStatusChangeMessages.
@Override
public List<NotificationMessage> buildStorageUnitStatusChangeMessages(BusinessObjectDataKey businessObjectDataKey, String storageName, String newStorageUnitStatus, String oldStorageUnitStatus) {
// Create a result list.
List<NotificationMessage> notificationMessages = new ArrayList<>();
// Get notification message definitions.
NotificationMessageDefinitions notificationMessageDefinitions = configurationDaoHelper.getXmlClobPropertyAndUnmarshallToObject(NotificationMessageDefinitions.class, ConfigurationValue.HERD_NOTIFICATION_STORAGE_UNIT_STATUS_CHANGE_MESSAGE_DEFINITIONS.getKey());
// Continue processing if notification message definitions are configured.
if (notificationMessageDefinitions != null && CollectionUtils.isNotEmpty(notificationMessageDefinitions.getNotificationMessageDefinitions())) {
// Create a context map of values that can be used when building the message.
Map<String, Object> velocityContextMap = getStorageUnitStatusChangeMessageVelocityContextMap(businessObjectDataKey, storageName, newStorageUnitStatus, oldStorageUnitStatus);
// Generate notification message for each notification message definition.
for (NotificationMessageDefinition notificationMessageDefinition : notificationMessageDefinitions.getNotificationMessageDefinitions()) {
// Validate the notification message type.
if (StringUtils.isBlank(notificationMessageDefinition.getMessageType())) {
throw new IllegalStateException(String.format("Notification message type must be specified. Please update \"%s\" configuration entry.", ConfigurationValue.HERD_NOTIFICATION_STORAGE_UNIT_STATUS_CHANGE_MESSAGE_DEFINITIONS.getKey()));
}
// Validate the notification message destination.
if (StringUtils.isBlank(notificationMessageDefinition.getMessageDestination())) {
throw new IllegalStateException(String.format("Notification message destination must be specified. Please update \"%s\" configuration entry.", ConfigurationValue.HERD_NOTIFICATION_STORAGE_UNIT_STATUS_CHANGE_MESSAGE_DEFINITIONS.getKey()));
}
// Evaluate the template to generate the message text.
String messageText = evaluateVelocityTemplate(notificationMessageDefinition.getMessageVelocityTemplate(), velocityContextMap, "storageUnitStatusChangeEvent");
// Build a list of optional message headers.
List<MessageHeader> messageHeaders = new ArrayList<>();
if (CollectionUtils.isNotEmpty(notificationMessageDefinition.getMessageHeaderDefinitions())) {
for (MessageHeaderDefinition messageHeaderDefinition : notificationMessageDefinition.getMessageHeaderDefinitions()) {
messageHeaders.add(new MessageHeader(messageHeaderDefinition.getKey(), evaluateVelocityTemplate(messageHeaderDefinition.getValueVelocityTemplate(), velocityContextMap, String.format("storageUnitStatusChangeEvent_messageHeader_%s", messageHeaderDefinition.getKey()))));
}
}
// Create a notification message and add it to the result list.
notificationMessages.add(new NotificationMessage(notificationMessageDefinition.getMessageType(), notificationMessageDefinition.getMessageDestination(), messageText, messageHeaders));
}
}
// Return the results.
return notificationMessages;
}
use of org.finra.herd.model.dto.MessageHeader in project herd by FINRAOS.
the class NotificationMessagePublishingServiceImpl method publishOldestNotificationMessageFromDatabaseQueueImpl.
/**
* Publishes and removes from the database queue the oldest notification message.
*
* @return true if notification message was successfully published and false otherwise
*/
@SuppressWarnings("unchecked")
protected boolean publishOldestNotificationMessageFromDatabaseQueueImpl() {
// Initialize the result flag to false.
boolean result = false;
// Retrieve the oldest notification message from the database queue, unless the queue is empty.
NotificationMessageEntity notificationMessageEntity = notificationMessageDao.getOldestNotificationMessage();
// If message is retrieved, publish and remove it from the queue.
if (notificationMessageEntity != null) {
// Get the message headers from the entity.
List<MessageHeader> messageHeaders = null;
if (StringUtils.isNotBlank(notificationMessageEntity.getMessageHeaders())) {
try {
messageHeaders = jsonHelper.unmarshallJsonToListOfObjects(MessageHeader.class, notificationMessageEntity.getMessageHeaders());
} catch (IOException e) {
throw new IllegalStateException(String.format("Failed to unmarshall notification message headers. " + "messageId=%d messageType=%s messageDestination=%s messageText=%s messageHeaders=%s", notificationMessageEntity.getId(), notificationMessageEntity.getMessageType().getCode(), notificationMessageEntity.getMessageDestination(), notificationMessageEntity.getMessageText(), notificationMessageEntity.getMessageHeaders()), e);
}
}
// Publish notification message.
publishNotificationMessageImpl(new NotificationMessage(notificationMessageEntity.getMessageType().getCode(), notificationMessageEntity.getMessageDestination(), notificationMessageEntity.getMessageText(), messageHeaders));
// Delete this message from the queue.
notificationMessageDao.delete(notificationMessageEntity);
// Set the result flag to true.
result = true;
}
return result;
}
use of org.finra.herd.model.dto.MessageHeader in project herd by FINRAOS.
the class NotificationMessagePublishingServiceTest method testNotificationPublishingServiceMethodsNewTransactionPropagation.
@Test
public void testNotificationPublishingServiceMethodsNewTransactionPropagation() {
// Validate that notification message database queue is empty.
assertNull(notificationMessageDao.getOldestNotificationMessage());
// Add a notification message to the database queue.
notificationMessagePublishingServiceImpl.addNotificationMessageToDatabaseQueue(new NotificationMessage(MessageTypeEntity.MessageEventTypes.SQS.name(), MESSAGE_DESTINATION, MESSAGE_TEXT, Collections.singletonList(new MessageHeader(KEY, VALUE))));
// Validate that the database queue is not empty now.
assertNotNull(notificationMessageDao.getOldestNotificationMessage());
// Publish the notification message from the database queue.
assertTrue(notificationMessagePublishingServiceImpl.publishOldestNotificationMessageFromDatabaseQueue());
// Publish notification message directly - not from the database queue.
notificationMessagePublishingServiceImpl.publishNotificationMessage(new NotificationMessage(MessageTypeEntity.MessageEventTypes.SQS.name(), MESSAGE_DESTINATION, MESSAGE_TEXT, Collections.singletonList(new MessageHeader(KEY, VALUE))));
}
use of org.finra.herd.model.dto.MessageHeader in project herd by FINRAOS.
the class NotificationMessagePublishingServiceTest method testPublishNotificationMessageInvalidMessageType.
@Test
public void testPublishNotificationMessageInvalidMessageType() {
// Try to publish notification message with an invalid message type.
try {
notificationMessagePublishingService.publishNotificationMessage(new NotificationMessage(I_DO_NOT_EXIST, MESSAGE_DESTINATION, MESSAGE_TEXT, Collections.singletonList(new MessageHeader(KEY, VALUE))));
fail();
} catch (IllegalStateException e) {
assertEquals(String.format("Notification message type \"%s\" is not supported.", I_DO_NOT_EXIST), e.getMessage());
}
}
Aggregations