Search in sources :

Example 1 with AcknowledgeType

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

the class ExchangeEventOutgoingServiceBean method validate.

private boolean validate(ServiceResponseType service, SendMovementToPluginType sendReport, TextMessage origin, String username) {
    // Use first and only
    String serviceName = service.getServiceClassName();
    if (serviceName == null || serviceName.isEmpty()) {
        String faultMessage = "First plugin of type " + sendReport.getPluginType() + " is invalid. Missing serviceClassName";
        exchangeErrorEvent.fire(new ExchangeMessageEvent(origin, ExchangeModuleResponseMapper.createFaultMessage(FaultCode.EXCHANGE_PLUGIN_INVALID, faultMessage)));
        try {
            List<UnsentMessageTypeProperty> unsentMessageProperties = ExchangeLogMapper.getUnsentMessageProperties(sendReport);
            exchangeLog.createUnsentMessage(sendReport.getRecipient(), sendReport.getTimestamp(), ExchangeLogMapper.getSendMovementSenderReceiver(sendReport), origin.getText(), unsentMessageProperties, username);
        } catch (ExchangeLogException | JMSException e) {
            LOG.error("Couldn't create unsent message " + e.getMessage());
        }
        return false;
    } else if (!sendReport.getPluginType().equals(service.getPluginType())) {
        String faultMessage = "First plugin of type " + sendReport.getPluginType() + " does not match plugin type of " + serviceName + ". Current type is " + service.getPluginType();
        exchangeErrorEvent.fire(new ExchangeMessageEvent(origin, ExchangeModuleResponseMapper.createFaultMessage(FaultCode.EXCHANGE_PLUGIN_INVALID, faultMessage)));
        return false;
    } else if (sendReport.getPluginName() != null && !serviceName.equalsIgnoreCase(sendReport.getPluginName())) {
        String faultMessage = "First plugin of type " + sendReport.getPluginType() + " does not matching input of " + sendReport.getPluginName();
        exchangeErrorEvent.fire(new ExchangeMessageEvent(origin, ExchangeModuleResponseMapper.createFaultMessage(FaultCode.EXCHANGE_PLUGIN_INVALID, faultMessage)));
        return false;
    } else if (!StatusType.STARTED.equals(service.getStatus())) {
        try {
            List<UnsentMessageTypeProperty> unsentMessageProperties = ExchangeLogMapper.getUnsentMessageProperties(sendReport);
            exchangeLog.createUnsentMessage(sendReport.getRecipient(), sendReport.getTimestamp(), ExchangeLogMapper.getSendMovementSenderReceiver(sendReport), origin.getText(), unsentMessageProperties, username);
        } catch (ExchangeLogException | JMSException e) {
            LOG.error("Couldn't create unsent message " + e.getMessage());
        }
        try {
            AcknowledgeType ackType = ExchangeModuleResponseMapper.mapAcknowledgeTypeNOK(origin.getJMSMessageID(), "Plugin to send movement is not started");
            String moduleResponse = ExchangeModuleResponseMapper.mapSendMovementToPluginResponse(ackType);
            producer.sendModuleResponseMessage(origin, moduleResponse);
        } catch (JMSException | ExchangeModelMarshallException e) {
            LOG.error("Plugin not started, couldn't send module response: " + e.getMessage());
        }
        return false;
    }
    return true;
}
Also used : ExchangeLogException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException) AcknowledgeType(eu.europa.ec.fisheries.schema.exchange.common.v1.AcknowledgeType) JMSException(javax.jms.JMSException) List(java.util.List) ArrayList(java.util.ArrayList) UnsentMessageTypeProperty(eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty) ExchangeMessageEvent(eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.ExchangeMessageEvent)

Example 2 with AcknowledgeType

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

the class ExchangeEventIncomingServiceBean method processAcknowledge.

@Override
public void processAcknowledge(@Observes @ExchangeLogEvent ExchangeMessageEvent message) {
    log.info("Process acknowledge:{}", message);
    try {
        AcknowledgeResponse response = JAXBMarshaller.unmarshallTextMessage(message.getJmsMessage(), AcknowledgeResponse.class);
        AcknowledgeType acknowledge = response.getResponse();
        String serviceClassName = response.getServiceClassName();
        ExchangePluginMethod method = response.getMethod();
        switch(method) {
            case SET_COMMAND:
                // Only Acknowledge for poll should have a poll status set
                if (acknowledge.getPollStatus() != null && acknowledge.getPollStatus().getPollId() != null) {
                    handleSetPollStatusAcknowledge(method, serviceClassName, acknowledge);
                } else {
                    handleUpdateExchangeLogAcknowledge(method, serviceClassName, acknowledge);
                }
                break;
            case SET_REPORT:
                handleUpdateExchangeLogAcknowledge(method, serviceClassName, acknowledge);
                break;
            case START:
                handleUpdateServiceAcknowledge(serviceClassName, acknowledge, StatusType.STARTED);
                pluginStatusEvent.fire(createNotificationMessage(serviceClassName, true));
                break;
            case STOP:
                handleUpdateServiceAcknowledge(serviceClassName, acknowledge, StatusType.STOPPED);
                pluginStatusEvent.fire(createNotificationMessage(serviceClassName, false));
                break;
            case SET_CONFIG:
            default:
                handleAcknowledge(method, serviceClassName, acknowledge);
                break;
        }
    } catch (ExchangeModelMarshallException e) {
        log.error("Process acknowledge couldn't be marshalled {} {}", message, e);
    } catch (ExchangeServiceException e) {
        // TODO Audit.log() couldn't process acknowledge in exchange service
        log.error("Couldn't process acknowledge in exchange service:{} {} ", message, e.getMessage());
    }
}
Also used : ExchangeModelMarshallException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException) ExchangePluginMethod(eu.europa.ec.fisheries.schema.exchange.plugin.v1.ExchangePluginMethod) AcknowledgeType(eu.europa.ec.fisheries.schema.exchange.common.v1.AcknowledgeType) AcknowledgeResponse(eu.europa.ec.fisheries.schema.exchange.plugin.v1.AcknowledgeResponse) ExchangeServiceException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)

Example 3 with AcknowledgeType

use of eu.europa.ec.fisheries.schema.exchange.common.v1.AcknowledgeType 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)

Example 4 with AcknowledgeType

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

the class ExchangeEventOutgoingServiceBean method validate.

private boolean validate(CommandType command, TextMessage origin, ServiceResponseType service, CommandType commandType, String username) {
    if (command == null) {
        String faultMessage = "No command";
        exchangeErrorEvent.fire(new ExchangeMessageEvent(origin, ExchangeModuleResponseMapper.createFaultMessage(FaultCode.EXCHANGE_COMMAND_INVALID, faultMessage)));
        return false;
    } else if (command.getCommand() == null) {
        String faultMessage = "No command type";
        exchangeErrorEvent.fire(new ExchangeMessageEvent(origin, ExchangeModuleResponseMapper.createFaultMessage(FaultCode.EXCHANGE_COMMAND_INVALID, faultMessage)));
        return false;
    } else if (command.getPluginName() == null) {
        String faultMessage = "No plugin to send to";
        exchangeErrorEvent.fire(new ExchangeMessageEvent(origin, ExchangeModuleResponseMapper.createFaultMessage(FaultCode.EXCHANGE_COMMAND_INVALID, faultMessage)));
        return false;
    } else if (service == null || service.getServiceClassName() == null || !service.getServiceClassName().equalsIgnoreCase(command.getPluginName())) {
        String faultMessage = "No plugin receiver available";
        exchangeErrorEvent.fire(new ExchangeMessageEvent(origin, ExchangeModuleResponseMapper.createFaultMessage(FaultCode.EXCHANGE_COMMAND_INVALID, faultMessage)));
        try {
            List<UnsentMessageTypeProperty> setUnsentMessageTypePropertiesForPoll = getSetUnsentMessageTypePropertiesForPoll(commandType);
            exchangeLog.createUnsentMessage(service.getName(), command.getTimestamp(), command.getCommand().name(), origin.getText(), setUnsentMessageTypePropertiesForPoll, username);
        } catch (ExchangeLogException | JMSException e) {
            LOG.error("Couldn't create unsentMessage " + e.getMessage());
        }
        return false;
    } else if (command.getTimestamp() == null) {
        String faultMessage = "No timestamp";
        exchangeErrorEvent.fire(new ExchangeMessageEvent(origin, ExchangeModuleResponseMapper.createFaultMessage(FaultCode.EXCHANGE_COMMAND_INVALID, faultMessage)));
        return false;
    } else if (!StatusType.STARTED.equals(service.getStatus())) {
        LOG.info("Plugin to send report to is not started:{}", service);
        try {
            List<UnsentMessageTypeProperty> setUnsentMessageTypePropertiesForPoll = getSetUnsentMessageTypePropertiesForPoll(commandType);
            exchangeLog.createUnsentMessage(service.getName(), command.getTimestamp(), command.getCommand().name(), origin.getText(), setUnsentMessageTypePropertiesForPoll, username);
        } catch (ExchangeLogException | JMSException e) {
            LOG.error("Couldn't create unsentMessage " + e.getMessage());
        }
        try {
            AcknowledgeType ackType = ExchangeModuleResponseMapper.mapAcknowledgeTypeNOK(origin.getJMSMessageID(), "Plugin to send command to is not started");
            String moduleResponse = ExchangeModuleResponseMapper.mapSetCommandResponse(ackType);
            producer.sendModuleResponseMessage(origin, moduleResponse);
        } catch (JMSException | ExchangeModelMarshallException e) {
            LOG.error("Plugin not started, couldn't send module response: " + e.getMessage());
        }
        return false;
    }
    return true;
}
Also used : AcknowledgeType(eu.europa.ec.fisheries.schema.exchange.common.v1.AcknowledgeType) List(java.util.List) ArrayList(java.util.ArrayList) ExchangeMessageEvent(eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.ExchangeMessageEvent)

Aggregations

AcknowledgeType (eu.europa.ec.fisheries.schema.exchange.common.v1.AcknowledgeType)4 ExchangeMessageEvent (eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.ExchangeMessageEvent)3 UnsentMessageTypeProperty (eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty)2 ExchangeLogException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 JMSException (javax.jms.JMSException)2 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 AcknowledgeResponse (eu.europa.ec.fisheries.schema.exchange.plugin.v1.AcknowledgeResponse)1 ExchangePluginMethod (eu.europa.ec.fisheries.schema.exchange.plugin.v1.ExchangePluginMethod)1 ServiceResponseType (eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType)1 ExchangeLogType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType)1 ExchangeException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeException)1 ExchangeModelMarshallException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException)1 ExchangeServiceException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)1