Search in sources :

Example 1 with UnsentMessage

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");
    }
}
Also used : UnsentMessageType(eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageType) InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) NoEntityFoundException(eu.europa.ec.fisheries.uvms.exchange.exception.NoEntityFoundException) ArrayList(java.util.ArrayList) UnsentMessage(eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessage) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)

Example 2 with UnsentMessage

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 ");
    }
}
Also used : UnsentMessageType(eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageType) InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) UnsentMessage(eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessage) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)

Example 3 with UnsentMessage

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 ");
    }
}
Also used : InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) UnsentMessage(eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessage) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)

Example 4 with UnsentMessage

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;
}
Also used : UnsentMessage(eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessage) UnsentMessageProperty(eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessageProperty)

Example 5 with UnsentMessage

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. ]");
    }
}
Also used : NoEntityFoundException(eu.europa.ec.fisheries.uvms.exchange.exception.NoEntityFoundException) UnsentMessage(eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessage) NoResultException(javax.persistence.NoResultException)

Aggregations

UnsentMessage (eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessage)5 ExchangeDaoException (eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException)3 ExchangeModelException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)3 InputArgumentException (eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException)3 UnsentMessageType (eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageType)2 NoEntityFoundException (eu.europa.ec.fisheries.uvms.exchange.exception.NoEntityFoundException)2 UnsentMessageProperty (eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessageProperty)1 ArrayList (java.util.ArrayList)1 NoResultException (javax.persistence.NoResultException)1