use of org.finra.herd.model.jpa.MessageTypeEntity in project herd by FINRAOS.
the class MessageTypeDaoTestHelper method createMessageTypeEntity.
/**
* Creates and persists a new message type entity.
*
* @param code the code of the message type
*
* @return the newly created message type entity
*/
public MessageTypeEntity createMessageTypeEntity(String code) {
MessageTypeEntity messageTypeEntity = new MessageTypeEntity();
messageTypeEntity.setCode(code);
return messageTypeDao.saveAndRefresh(messageTypeEntity);
}
use of org.finra.herd.model.jpa.MessageTypeEntity in project herd by FINRAOS.
the class MessageTypeDaoHelperTest method testGetMessageTypeEntity.
@Test
public void testGetMessageTypeEntity() {
// Create and persist a message type entity.
MessageTypeEntity messageTypeEntity = messageTypeDaoTestHelper.createMessageTypeEntity(MESSAGE_TYPE);
// Retrieve the message type entity and validate the result.
assertEquals(messageTypeEntity, messageTypeDaoHelper.getMessageTypeEntity(MESSAGE_TYPE));
// Test case insensitivity of the message type code.
assertEquals(messageTypeEntity, messageTypeDaoHelper.getMessageTypeEntity(MESSAGE_TYPE.toUpperCase()));
assertEquals(messageTypeEntity, messageTypeDaoHelper.getMessageTypeEntity(MESSAGE_TYPE.toLowerCase()));
// Try to retrieve a non existing message type.
try {
messageTypeDaoHelper.getMessageTypeEntity(I_DO_NOT_EXIST);
fail();
} catch (ObjectNotFoundException e) {
assertEquals(String.format("Message type with code \"%s\" doesn't exist.", I_DO_NOT_EXIST), e.getMessage());
}
}
use of org.finra.herd.model.jpa.MessageTypeEntity in project herd by FINRAOS.
the class NotificationMessageDaoTestHelper method createNotificationMessageEntity.
/**
* Creates and persists a new notification message entity.
*
* @param messageDestination the destination of the message
* @param messageText the text of the message
*
* @return the newly created notification message entity
*/
public NotificationMessageEntity createNotificationMessageEntity(String messageType, String messageDestination, String messageText) {
// Create a message type entity if needed.
MessageTypeEntity messageTypeEntity = messageTypeDao.getMessageTypeByCode(messageType);
if (messageTypeEntity == null) {
messageTypeEntity = messageTypeDaoTestHelper.createMessageTypeEntity(messageType);
}
// Create a notification message entity.
NotificationMessageEntity notificationMessageEntity = new NotificationMessageEntity();
notificationMessageEntity.setMessageType(messageTypeEntity);
notificationMessageEntity.setMessageDestination(messageDestination);
notificationMessageEntity.setMessageText(messageText);
// Persist and return the newly created entity.
return notificationMessageDao.saveAndRefresh(notificationMessageEntity);
}
use of org.finra.herd.model.jpa.MessageTypeEntity in project herd by FINRAOS.
the class MessageTypeDaoImpl method getMessageTypeByCode.
@Override
public MessageTypeEntity getMessageTypeByCode(String code) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<MessageTypeEntity> criteria = builder.createQuery(MessageTypeEntity.class);
// The criteria root is the message type.
Root<MessageTypeEntity> messageTypeEntityRoot = criteria.from(MessageTypeEntity.class);
// Create the standard restrictions (i.e. the standard where clauses).
Predicate predicate = builder.equal(builder.upper(messageTypeEntityRoot.get(MessageTypeEntity_.code)), code.toUpperCase());
// Add all clauses to the query.
criteria.select(messageTypeEntityRoot).where(predicate);
// Execute the query and return the result.
return executeSingleResultQuery(criteria, String.format("Found more than one message type with code \"%s\".", code));
}
use of org.finra.herd.model.jpa.MessageTypeEntity in project herd by FINRAOS.
the class NotificationMessagePublishingServiceImpl method addNotificationMessageToDatabaseQueueImpl.
/**
* Adds a notification message to the database queue.
*
* @param notificationMessage the notification message
*/
protected void addNotificationMessageToDatabaseQueueImpl(NotificationMessage notificationMessage) {
// Get a message type entity and ensure it exists.
MessageTypeEntity messageTypeEntity = messageTypeDaoHelper.getMessageTypeEntity(notificationMessage.getMessageType());
// Create and persist a notification message entity.
NotificationMessageEntity notificationMessageEntity = new NotificationMessageEntity();
notificationMessageEntity.setMessageType(messageTypeEntity);
notificationMessageEntity.setMessageDestination(notificationMessage.getMessageDestination());
notificationMessageEntity.setMessageText(notificationMessage.getMessageText());
if (CollectionUtils.isNotEmpty(notificationMessage.getMessageHeaders())) {
notificationMessageEntity.setMessageHeaders(jsonHelper.objectToJson(notificationMessage.getMessageHeaders()));
}
notificationMessageDao.saveAndRefresh(notificationMessageEntity);
}
Aggregations