use of eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginType in project UVMS-ExchangeModule-APP by UnionVMS.
the class ExchangeEventIncomingServiceBean method processMovement.
@Override
public void processMovement(@Observes @SetMovementEvent ExchangeMessageEvent message) {
try {
final TextMessage jmsMessage = message.getJmsMessage();
final String jmsMessageID = jmsMessage.getJMSMessageID();
SetMovementReportRequest request = JAXBMarshaller.unmarshallTextMessage(jmsMessage, SetMovementReportRequest.class);
log.info("[INFO] Processing Movement : {}", request);
String username;
SetReportMovementType setRepMovType = request.getRequest();
if (MovementSourceType.MANUAL.equals(setRepMovType.getMovement().getSource())) {
// A person has created a position
username = request.getUsername();
// Send some response to Movement, if it originated from there (manual movement)
ProcessedMovementAck response = MovementModuleResponseMapper.mapProcessedMovementAck(eu.europa.ec.fisheries.schema.movement.common.v1.AcknowledgeTypeType.OK, jmsMessageID, "Movement successfully processed");
producer.sendModuleAckMessage(jmsMessageID, MessageQueue.MOVEMENT_RESPONSE, JAXBMarshaller.marshallJaxBObjectToString(response));
} else {
// A plugin has reported a position
username = setRepMovType.getPluginType().name();
}
String pluginName = setRepMovType.getPluginName();
ServiceResponseType service = exchangeService.getService(pluginName);
PluginType pluginType = setRepMovType.getPluginType();
if (validate(setRepMovType, service, jmsMessage)) {
MovementBaseType baseMovement = setRepMovType.getMovement();
RawMovementType rawMovement = MovementMapper.getInstance().getMapper().map(baseMovement, RawMovementType.class);
final AssetId assetId = rawMovement.getAssetId();
if (assetId != null && assetId.getAssetIdList() != null) {
assetId.getAssetIdList().addAll(MovementMapper.mapAssetIdList(baseMovement.getAssetId().getAssetIdList()));
}
if (baseMovement.getMobileTerminalId() != null && baseMovement.getMobileTerminalId().getMobileTerminalIdList() != null) {
rawMovement.getMobileTerminal().getMobileTerminalIdList().addAll(MovementMapper.mapMobileTerminalIdList(baseMovement.getMobileTerminalId().getMobileTerminalIdList()));
}
rawMovement.setPluginType(pluginType.value());
rawMovement.setPluginName(pluginName);
rawMovement.setDateRecieved(setRepMovType.getTimestamp());
// TODO : Temporary - probably better to change corr id to have the same though the entire flow;
// TODO : then we can use this to send response to original caller from anywhere needed
rawMovement.setAckResponseMessageID(jmsMessageID);
log.info("[INFO] Logging received movement.");
exchangeLog.log(request, LogType.RECEIVE_MOVEMENT, ExchangeLogStatusTypeType.ISSUED, TypeRefType.MOVEMENT, JAXBMarshaller.marshallJaxBObjectToString(request), true);
forwardToRules(RulesModuleRequestMapper.createSetMovementReportRequest(PluginTypeMapper.map(pluginType), rawMovement, username), message, service);
log.info("[INFO] Finished forwarding received movement to rules module.");
} else {
log.debug("[ERROR] Validation error. Event sent to plugin {}", message);
}
} catch (ExchangeServiceException e) {
log.error("[ERROR] Couldn't get the Service type for the received message : {} {}", message, e);
} catch (ExchangeModelMarshallException e) {
log.error("[ERROR] Couldn't map to SetMovementReportRequest when processing movement from plugin:{} {}", message, e);
} catch (JMSException e) {
log.error("[ERROR] Failed to get response queue:{} {}", message, e);
} catch (RulesModelMapperException e) {
log.error("[ERROR] Failed to build Rules momvent request:{} {}", message, e);
} catch (ExchangeLogException e) {
log.error("[ERROR] Failed to log momvent request : {} {}", message, e);
}
}
use of eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginType in project UVMS-ExchangeModule-APP by UnionVMS.
the class ExchangeEventIncomingServiceBean method receiveSalesReport.
@Override
public void receiveSalesReport(@Observes @ReceiveSalesReportEvent ExchangeMessageEvent event) {
try {
ReceiveSalesReportRequest request = JAXBMarshaller.unmarshallTextMessage(event.getJmsMessage(), ReceiveSalesReportRequest.class);
log.info("Receive sales report in Exchange module:{}", request);
String report = request.getReport();
PluginType plugin = request.getPluginType();
String sender = request.getSenderOrReceiver();
String messageGuid = request.getMessageGuid();
ExchangeLogType log = exchangeLog.log(request, LogType.RECEIVE_SALES_REPORT, ExchangeLogStatusTypeType.ISSUED, TypeRefType.SALES_REPORT, report, true);
forwardToRules(RulesModuleRequestMapper.createReceiveSalesReportRequest(report, messageGuid, plugin.name(), log.getGuid(), sender, request.getOnValue()));
} catch (ExchangeModelMarshallException e) {
try {
String errorMessage = "Couldn't map to SetSalesReportRequest when processing sales report from plugin. The event was " + event.getJmsMessage().getText();
firePluginFault(event, errorMessage, e);
} catch (JMSException e1) {
firePluginFault(event, "Couldn't map to SetSalesReportRequest when processing sales report from plugin.", e);
}
} catch (ExchangeLogException e) {
firePluginFault(event, "Could not log the incoming sales report.", e);
} catch (RulesModelMarshallException e) {
firePluginFault(event, "Could not create a request for the Rules module for an incoming sales report.", e);
}
}
use of eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginType in project UVMS-ExchangeModule-APP by UnionVMS.
the class ExchangeEventIncomingServiceBean method receiveSalesQuery.
@Override
public void receiveSalesQuery(@Observes @ReceiveSalesQueryEvent ExchangeMessageEvent event) {
try {
ReceiveSalesQueryRequest request = JAXBMarshaller.unmarshallTextMessage(event.getJmsMessage(), ReceiveSalesQueryRequest.class);
log.info("Process sales query in Exchange module:{}", request);
String query = request.getQuery();
PluginType plugin = request.getPluginType();
String sender = request.getSenderOrReceiver();
String messageGuid = request.getMessageGuid();
ExchangeLogType log = exchangeLog.log(request, LogType.RECEIVE_SALES_QUERY, ExchangeLogStatusTypeType.ISSUED, TypeRefType.SALES_QUERY, query, true);
forwardToRules(RulesModuleRequestMapper.createReceiveSalesQueryRequest(query, messageGuid, plugin.name(), log.getGuid(), sender, request.getOnValue()));
} catch (ExchangeModelMarshallException e) {
try {
firePluginFault(event, "Couldn't map to SalesQueryRequest when processing sales query from plugin. The message was " + event.getJmsMessage().getText(), e);
} catch (JMSException e1) {
firePluginFault(event, "Couldn't map to SalesQueryRequest when processing sales query from plugin.", e);
}
} catch (ExchangeLogException e) {
firePluginFault(event, "Could not log the incoming sales query.", e);
} catch (RulesModelMarshallException e) {
firePluginFault(event, "Could not create a request for the Rules module for an incoming sales query.", e);
}
}
use of eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginType 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);
}
}
use of eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginType in project UVMS-ExchangeModule-APP by UnionVMS.
the class PluginServiceBean method checkPluginType.
private boolean checkPluginType(PluginType pluginType, String responseTopicMessageSelector, String messageId) throws ExchangeModelMarshallException, ExchangeMessageException {
LOG.debug("checkPluginType " + pluginType.name());
if (PluginType.EMAIL == pluginType || PluginType.NAF == pluginType) {
// Check if type already exists
List<PluginType> type = new ArrayList<>();
type.add(pluginType);
try {
List<ServiceResponseType> services = exchangeService.getServiceList(type);
if (!services.isEmpty()) {
for (ServiceResponseType service : services) {
if (service.isActive()) {
// TODO log to audit log
String response = ExchangePluginResponseMapper.mapToRegisterServiceResponseNOK(messageId, "Plugin of " + pluginType + " already registered. Only one is allowed.");
producer.sendEventBusMessage(response, responseTopicMessageSelector);
return false;
}
}
}
} catch (ExchangeServiceException e) {
String response = ExchangePluginResponseMapper.mapToRegisterServiceResponseNOK(messageId, "Exchange service exception when registering plugin [ " + e.getMessage() + " ]");
producer.sendEventBusMessage(response, responseTopicMessageSelector);
return false;
}
}
return true;
}
Aggregations