Search in sources :

Example 1 with SetCommandRequest

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

the class ExchangeEventOutgoingServiceBean method sendCommandToPlugin.

@Override
public void sendCommandToPlugin(@Observes @SendCommandToPluginEvent ExchangeMessageEvent message) {
    SetCommandRequest request = new SetCommandRequest();
    try {
        request = JAXBMarshaller.unmarshallTextMessage(message.getJmsMessage(), SetCommandRequest.class);
        LOG.info("Send command to plugin:{}", request);
        String pluginName = request.getCommand().getPluginName();
        CommandType commandType = request.getCommand();
        ServiceResponseType service = exchangeService.getService(pluginName);
        if (validate(request.getCommand(), message.getJmsMessage(), service, commandType, request.getUsername())) {
            List<UnsentMessageTypeProperty> setUnsentMessageTypePropertiesForPoll = getSetUnsentMessageTypePropertiesForPoll(commandType);
            String unsentMessageGuid = exchangeLog.createUnsentMessage(service.getName(), request.getCommand().getTimestamp(), request.getCommand().getCommand().name(), message.getJmsMessage().getText(), setUnsentMessageTypePropertiesForPoll, request.getUsername());
            request.getCommand().setUnsentMessageGuid(unsentMessageGuid);
            String text = ExchangePluginRequestMapper.createSetCommandRequest(request.getCommand());
            String pluginMessageId = producer.sendEventBusMessage(text, pluginName);
            try {
                ExchangeLogType log = ExchangeLogMapper.getSendCommandExchangeLog(request.getCommand());
                exchangeLog.logAndCache(log, pluginMessageId, request.getUsername());
            } catch (ExchangeLogException e) {
                LOG.error(e.getMessage());
            }
            CommandTypeType x = request.getCommand().getCommand();
            // response back to MobileTerminal (not to rules when email)
            if (request.getCommand().getCommand() != CommandTypeType.EMAIL) {
                AcknowledgeType ackType = ExchangeModuleResponseMapper.mapAcknowledgeTypeOK();
                String moduleResponse = ExchangeModuleResponseMapper.mapSetCommandResponse(ackType);
                producer.sendModuleResponseMessage(message.getJmsMessage(), moduleResponse);
            }
        } else {
            LOG.debug("Can not send to plugin. Response sent to caller.");
        }
    } catch (NullPointerException | ExchangeException e) {
        if (request.getCommand().getCommand() != CommandTypeType.EMAIL) {
            LOG.error("[ Error when sending command to plugin {} ]", e.getMessage());
            exchangeErrorEvent.fire(new ExchangeMessageEvent(message.getJmsMessage(), ExchangeModuleResponseMapper.createFaultMessage(FaultCode.EXCHANGE_EVENT_SERVICE, "Exception when sending command to plugin")));
        }
    } catch (JMSException ex) {
        LOG.error("[ Error when creating unsent message {} ]", ex.getMessage());
    }
}
Also used : SetCommandRequest(eu.europa.ec.fisheries.schema.exchange.module.v1.SetCommandRequest) ServiceResponseType(eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType) ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) AcknowledgeType(eu.europa.ec.fisheries.schema.exchange.common.v1.AcknowledgeType) JMSException(javax.jms.JMSException) UnsentMessageTypeProperty(eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty) ExchangeMessageEvent(eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.ExchangeMessageEvent) CommandType(eu.europa.ec.fisheries.schema.exchange.common.v1.CommandType) ExchangeLogException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException) ExchangeException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeException) CommandTypeType(eu.europa.ec.fisheries.schema.exchange.common.v1.CommandTypeType)

Aggregations

AcknowledgeType (eu.europa.ec.fisheries.schema.exchange.common.v1.AcknowledgeType)1 CommandType (eu.europa.ec.fisheries.schema.exchange.common.v1.CommandType)1 CommandTypeType (eu.europa.ec.fisheries.schema.exchange.common.v1.CommandTypeType)1 SetCommandRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.SetCommandRequest)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 ExchangeMessageEvent (eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.ExchangeMessageEvent)1 ExchangeException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeException)1 ExchangeLogException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException)1 JMSException (javax.jms.JMSException)1