Search in sources :

Example 1 with UnsentMessageType

use of eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageType in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeLogServiceBean method resend.

@Override
public void resend(List<String> messageIdList, String username) throws ExchangeLogException {
    log.debug("resend in service layer:{} {}", messageIdList, username);
    List<UnsentMessageType> unsentMessageList;
    try {
        unsentMessageList = unsentModel.resend(messageIdList);
        sendAuditLogMessageForResendUnsentMessage(messageIdList.toString(), username);
    } catch (ExchangeModelException e) {
        log.error("Couldn't read unsent messages", e);
        throw new ExchangeLogException("Couldn't read unsent messages");
    }
    if (unsentMessageList != null && !unsentMessageList.isEmpty()) {
        sendingQueueEvent.fire(new NotificationMessage("messageIds", messageIdList));
        for (UnsentMessageType unsentMessage : unsentMessageList) {
            try {
                String unsentMessageId = producer.sendMessageOnQueue(unsentMessage.getMessage(), MessageQueue.EVENT);
                // TextMessage unsentResponse = consumer.getMessage(unsentMessageId, TextMessage.class);
                sendAuditLogMessageForCreateUnsentMessage(unsentMessageId, username);
            // ExchangeModuleResponseMapper.validateResponse(unsentResponse, unsentMessageId);
            } catch (ExchangeMessageException e) {
                log.error("Error when sending/receiving message {} {}", messageIdList, e);
            }
        }
    }
}
Also used : UnsentMessageType(eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageType) NotificationMessage(eu.europa.ec.fisheries.uvms.longpolling.notifications.NotificationMessage) ExchangeLogException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException) ExchangeMessageException(eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)

Example 2 with UnsentMessageType

use of eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageType 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 3 with UnsentMessageType

use of eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageType in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeLogServiceBean method createUnsentMessage.

@Override
public String createUnsentMessage(String senderReceiver, Date timestamp, String recipient, String message, List<UnsentMessageTypeProperty> properties, String username) throws ExchangeLogException {
    log.debug("createUnsentMessage in service layer:{}", message);
    try {
        UnsentMessageType unsentMessage = new UnsentMessageType();
        unsentMessage.setDateReceived(timestamp);
        unsentMessage.setSenderReceiver(senderReceiver);
        unsentMessage.setRecipient(recipient);
        unsentMessage.setMessage(message);
        unsentMessage.getProperties().addAll(properties);
        String createdUnsentMessageId = unsentModel.createMessage(unsentMessage, username);
        List<String> unsentMessageIds = Arrays.asList(createdUnsentMessageId);
        sendAuditLogMessageForCreateUnsentMessage(createdUnsentMessageId, username);
        sendingQueueEvent.fire(new NotificationMessage("messageIds", unsentMessageIds));
        return createdUnsentMessageId;
    } catch (ExchangeModelException e) {
        log.error("Couldn't add message to unsent list: {} {}", message, e);
        throw new ExchangeLogException("Couldn't add message to unsent list");
    }
}
Also used : UnsentMessageType(eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageType) NotificationMessage(eu.europa.ec.fisheries.uvms.longpolling.notifications.NotificationMessage) ExchangeLogException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)

Example 4 with UnsentMessageType

use of eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageType 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 5 with UnsentMessageType

use of eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageType in project UVMS-ExchangeModule-APP by UnionVMS.

the class UnsentMessageMapper method toModel.

public static UnsentMessageType toModel(UnsentMessage entity) {
    UnsentMessageType model = new UnsentMessageType();
    model.setDateReceived(entity.getDateReceived());
    model.setSenderReceiver(entity.getSenderReceiver());
    model.setMessageId(entity.getGuid());
    model.setRecipient(entity.getRecipient());
    model.setMessage(entity.getMessage());
    model.getProperties().addAll(mapToUnsentMessagePropertyModel(entity));
    return model;
}
Also used : UnsentMessageType(eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageType)

Aggregations

UnsentMessageType (eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageType)5 ExchangeModelException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)4 UnsentMessage (eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessage)2 ExchangeDaoException (eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException)2 InputArgumentException (eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException)2 ExchangeLogException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException)2 NotificationMessage (eu.europa.ec.fisheries.uvms.longpolling.notifications.NotificationMessage)2 ArrayList (java.util.ArrayList)2 UnsentMessageTypeProperty (eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty)1 UnsentMessageProperty (eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessageProperty)1 NoEntityFoundException (eu.europa.ec.fisheries.uvms.exchange.exception.NoEntityFoundException)1 ExchangeMessageException (eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException)1