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);
}
}
Aggregations