Search in sources :

Example 1 with SendMovementToPluginRequest

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

the class ExchangeEventOutgoingServiceBean method sendReportToPlugin.

@Override
public void sendReportToPlugin(@Observes @SendReportToPluginEvent ExchangeMessageEvent message) {
    try {
        SendMovementToPluginRequest request = JAXBMarshaller.unmarshallTextMessage(message.getJmsMessage(), SendMovementToPluginRequest.class);
        LOG.info("Send report to plugin: {}", request);
        SendMovementToPluginType sendReport = request.getReport();
        List<PluginType> type = new ArrayList<>();
        type.add(sendReport.getPluginType());
        List<ServiceResponseType> services = exchangeService.getServiceList(type);
        if (services == null || services.isEmpty()) {
            String faultMessage = "No plugins of type " + sendReport.getPluginType() + " found";
            LOG.debug(faultMessage);
        } else {
            ServiceResponseType service = services.get(0);
            String serviceName = service.getServiceClassName();
            if (validate(service, sendReport, message.getJmsMessage(), request.getUsername())) {
                List<UnsentMessageTypeProperty> unsentMessageProperties = ExchangeLogMapper.getUnsentMessageProperties(sendReport);
                String unsentMessageGuid = exchangeLog.createUnsentMessage(sendReport.getRecipient(), sendReport.getTimestamp(), ExchangeLogMapper.getSendMovementSenderReceiver(sendReport), message.getJmsMessage().getText(), unsentMessageProperties, request.getUsername());
                String text = ExchangePluginRequestMapper.createSetReportRequest(sendReport.getTimestamp(), sendReport, unsentMessageGuid);
                String pluginMessageId = producer.sendEventBusMessage(text, serviceName);
                // System.out.println("SendReport: PluginMessageId: " + pluginMessageId);
                try {
                    ExchangeLogType log = ExchangeLogMapper.getSendMovementExchangeLog(sendReport);
                    exchangeLog.logAndCache(log, pluginMessageId, request.getUsername());
                } catch (ExchangeLogException e) {
                    LOG.error(e.getMessage());
                }
            } else {
                LOG.debug("Cannot send to plugin. Response sent to caller:{}", message);
            }
        }
    } catch (ExchangeException e) {
        LOG.error("[ Error when sending report to plugin {} ] {}", message, e);
    } catch (JMSException ex) {
        LOG.error("[ Error when creating unsent movement {}] {}", message, ex);
    }
}
Also used : SendMovementToPluginRequest(eu.europa.ec.fisheries.schema.exchange.module.v1.SendMovementToPluginRequest) ServiceResponseType(eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType) ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) ArrayList(java.util.ArrayList) JMSException(javax.jms.JMSException) UnsentMessageTypeProperty(eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty) PluginType(eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginType) SendMovementToPluginType(eu.europa.ec.fisheries.schema.exchange.movement.v1.SendMovementToPluginType) ExchangeLogException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException) SendMovementToPluginType(eu.europa.ec.fisheries.schema.exchange.movement.v1.SendMovementToPluginType) ExchangeException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeException)

Aggregations

SendMovementToPluginRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.SendMovementToPluginRequest)1 SendMovementToPluginType (eu.europa.ec.fisheries.schema.exchange.movement.v1.SendMovementToPluginType)1 PluginType (eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginType)1 ServiceResponseType (eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType)1 ExchangeLogType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType)1 UnsentMessageTypeProperty (eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty)1 ExchangeException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeException)1 ExchangeLogException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException)1 ArrayList (java.util.ArrayList)1 JMSException (javax.jms.JMSException)1