use of eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessage in project UVMS-ExchangeModule-APP by UnionVMS.
the class UnsentModelBean method resend.
@Override
public List<UnsentMessageType> resend(List<String> unsentMessageId) throws ExchangeModelException {
if (unsentMessageId == null) {
throw new InputArgumentException("No messageList to resend");
}
try {
List<UnsentMessageType> unsentMessageList = new ArrayList<>();
for (String messageId : unsentMessageId) {
try {
UnsentMessage message = dao.getByGuid(messageId);
UnsentMessage removedMessage = dao.remove(message);
unsentMessageList.add(UnsentMessageMapper.toModel(removedMessage));
} catch (NoEntityFoundException e) {
LOG.error("Couldn't find message to resend with guid: " + messageId);
}
}
return unsentMessageList;
} catch (ExchangeDaoException ex) {
LOG.error("[ Error when resending message message list ] {}", ex.getMessage());
throw new ExchangeModelException("Error when resending unsent message list");
}
}
use of eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessage in project UVMS-ExchangeModule-APP by UnionVMS.
the class UnsentModelBean method createMessage.
@Override
public String createMessage(UnsentMessageType message, String username) throws ExchangeModelException {
if (message == null) {
throw new InputArgumentException("No message to create");
}
try {
UnsentMessage entity = UnsentMessageMapper.toEntity(message, username);
UnsentMessage persistedEntity = dao.create(entity);
UnsentMessageType model = UnsentMessageMapper.toModel(persistedEntity);
return model.getMessageId();
} catch (ExchangeDaoException ex) {
LOG.error("[ Error when creating unsent message ] {}", ex.getMessage());
throw new ExchangeModelException("Error when creating unsent message ");
}
}
use of eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessage in project UVMS-ExchangeModule-APP by UnionVMS.
the class UnsentModelBean method removeMessage.
@Override
public String removeMessage(String unsentMessageId) throws ExchangeModelException {
if (unsentMessageId == null) {
throw new InputArgumentException("No message to remove");
}
try {
UnsentMessage entity = dao.getByGuid(unsentMessageId);
if (entity != null) {
String guid = entity.getGuid();
dao.remove(entity);
return guid;
} else {
LOG.error("[ Error when removing unsent message ]");
throw new ExchangeModelException("Error when removing unsent message ");
}
} catch (ExchangeDaoException ex) {
LOG.error("[ Error when creating unsent message ] {}", ex.getMessage());
throw new ExchangeModelException("Error when creating unsent message ");
}
}
use of eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessage in project UVMS-ExchangeModule-APP by UnionVMS.
the class UnsentMessageMapper method toEntity.
public static UnsentMessage toEntity(UnsentMessageType message, String username) {
UnsentMessage entity = new UnsentMessage();
entity.setDateReceived(message.getDateReceived());
entity.setRecipient(message.getRecipient());
entity.setSenderReceiver(message.getSenderReceiver());
entity.setMessage(message.getMessage());
entity.setUpdatedBy(username);
entity.setUpdateTime(DateUtils.nowUTC().toDate());
List<UnsentMessageProperty> unsentMessageProperties = mapToUnsentMessagePropertyEntities(message, entity);
entity.setProperties(unsentMessageProperties);
return entity;
}
use of eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessage in project UVMS-ExchangeModule-APP by UnionVMS.
the class UnsentMessageDaoBean method getByGuid.
@Override
public UnsentMessage getByGuid(String guid) throws NoEntityFoundException {
try {
TypedQuery<UnsentMessage> query = em.createNamedQuery(ExchangeConstants.UNSENT_BY_GUID, UnsentMessage.class);
query.setParameter("guid", guid);
return query.getSingleResult();
} catch (NoResultException e) {
LOG.error("[ Error when getting entity by ID. ] {}", e.getMessage());
throw new NoEntityFoundException("[ Error when getting entity by ID. ]");
}
}
Aggregations