Search in sources :

Example 1 with PluginType

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);
    }
}
Also used : ServiceResponseType(eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType) MovementBaseType(eu.europa.ec.fisheries.schema.exchange.movement.v1.MovementBaseType) JMSException(javax.jms.JMSException) ProcessedMovementAck(eu.europa.ec.fisheries.schema.movement.module.v1.ProcessedMovementAck) PluginType(eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginType) RulesModelMapperException(eu.europa.ec.fisheries.uvms.rules.model.exception.RulesModelMapperException) ExchangeServiceException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException) ExchangeModelMarshallException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException) RawMovementType(eu.europa.ec.fisheries.schema.rules.movement.v1.RawMovementType) ExchangeLogException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException) SetReportMovementType(eu.europa.ec.fisheries.schema.exchange.movement.v1.SetReportMovementType) AssetId(eu.europa.ec.fisheries.schema.rules.asset.v1.AssetId) TextMessage(javax.jms.TextMessage) SetMovementReportRequest(eu.europa.ec.fisheries.schema.exchange.module.v1.SetMovementReportRequest)

Example 2 with PluginType

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);
    }
}
Also used : ExchangeModelMarshallException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException) RulesModelMarshallException(eu.europa.ec.fisheries.uvms.rules.model.exception.RulesModelMarshallException) ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) ExchangeLogException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException) ReceiveSalesReportRequest(eu.europa.ec.fisheries.schema.exchange.module.v1.ReceiveSalesReportRequest) JMSException(javax.jms.JMSException) PluginType(eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginType)

Example 3 with PluginType

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);
    }
}
Also used : ExchangeModelMarshallException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException) RulesModelMarshallException(eu.europa.ec.fisheries.uvms.rules.model.exception.RulesModelMarshallException) ReceiveSalesQueryRequest(eu.europa.ec.fisheries.schema.exchange.module.v1.ReceiveSalesQueryRequest) ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) ExchangeLogException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException) JMSException(javax.jms.JMSException) PluginType(eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginType)

Example 4 with PluginType

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

Example 5 with PluginType

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;
}
Also used : ServiceResponseType(eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType) ArrayList(java.util.ArrayList) PluginType(eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginType) ExchangeServiceException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)

Aggregations

PluginType (eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginType)5 ExchangeLogException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException)4 JMSException (javax.jms.JMSException)4 ServiceResponseType (eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType)3 ExchangeLogType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType)3 ExchangeModelMarshallException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException)3 ExchangeServiceException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)2 RulesModelMarshallException (eu.europa.ec.fisheries.uvms.rules.model.exception.RulesModelMarshallException)2 ArrayList (java.util.ArrayList)2 ReceiveSalesQueryRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.ReceiveSalesQueryRequest)1 ReceiveSalesReportRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.ReceiveSalesReportRequest)1 SendMovementToPluginRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.SendMovementToPluginRequest)1 SetMovementReportRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.SetMovementReportRequest)1 MovementBaseType (eu.europa.ec.fisheries.schema.exchange.movement.v1.MovementBaseType)1 SendMovementToPluginType (eu.europa.ec.fisheries.schema.exchange.movement.v1.SendMovementToPluginType)1 SetReportMovementType (eu.europa.ec.fisheries.schema.exchange.movement.v1.SetReportMovementType)1 UnsentMessageTypeProperty (eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty)1 ProcessedMovementAck (eu.europa.ec.fisheries.schema.movement.module.v1.ProcessedMovementAck)1 AssetId (eu.europa.ec.fisheries.schema.rules.asset.v1.AssetId)1 RawMovementType (eu.europa.ec.fisheries.schema.rules.movement.v1.RawMovementType)1