Search in sources :

Example 1 with AcknowledgeResponse

use of eu.europa.ec.fisheries.schema.exchange.plugin.v1.AcknowledgeResponse 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 2 with AcknowledgeResponse

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

the class ExchangeMessageConsumerBean method onMessage.

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void onMessage(Message message) {
    TextMessage textMessage = (TextMessage) message;
    ExchangeBaseRequest request = tryConsumeExchangeBaseRequest(textMessage);
    LOG.info("Message received in Exchange Message MDB");
    LOG.debug("Request body : ", request);
    final ExchangeMessageEvent messageEventWrapper = new ExchangeMessageEvent(textMessage);
    if (request == null) {
        LOG.warn("[ERROR] ExchangeBaseRequest is null!! Check the message sent...");
        try {
            // Handle PingResponse from plugin
            JAXBMarshaller.unmarshallTextMessage(textMessage, PingResponse.class);
            updatePingStateEvent.fire(messageEventWrapper);
        } catch (ExchangeModelMarshallException e) {
            AcknowledgeResponse type = tryConsumeAcknowledgeResponse(textMessage);
            if (type == null) {
                LOG.error("[ Error when receiving message in exchange: {}]", message);
                errorEvent.fire(new ExchangeMessageEvent(textMessage, ExchangeModuleResponseMapper.createFaultMessage(FaultCode.EXCHANGE_MESSAGE, "Error when receiving message in exchange")));
            } else {
                updateStateEvent.fire(messageEventWrapper);
            }
        }
    } else if (!checkUsernameShouldBeProvided(request)) {
        LOG.error("[ Error when receiving message in exchange, username must be set in the request: ]");
        errorEvent.fire(new ExchangeMessageEvent(textMessage, ExchangeModuleResponseMapper.createFaultMessage(FaultCode.EXCHANGE_MESSAGE, "Username in the request must be set")));
    } else {
        LOG.info("[INFO] Going to process following message type (aka Exchange Method) : " + request.getMethod());
        switch(request.getMethod()) {
            case LIST_SERVICES:
                pluginConfigEvent.fire(messageEventWrapper);
                break;
            case SET_COMMAND:
                sendCommandToPluginEvent.fire(messageEventWrapper);
                break;
            case SEND_REPORT_TO_PLUGIN:
                sendMessageToPluginEvent.fire(messageEventWrapper);
                break;
            case SET_MOVEMENT_REPORT:
                processMovementEvent.fire(messageEventWrapper);
                break;
            case RECEIVE_SALES_REPORT:
                receiveSalesReportEvent.fire(messageEventWrapper);
                break;
            case RECEIVE_SALES_QUERY:
                receiveSalesQueryEvent.fire(messageEventWrapper);
                break;
            case RECEIVE_SALES_RESPONSE:
                receiveSalesResponseEvent.fire(messageEventWrapper);
                break;
            case RECEIVE_INVALID_SALES_MESSAGE:
                receiveInvalidSalesMessageEvent.fire(messageEventWrapper);
                break;
            case SEND_SALES_RESPONSE:
                sendSalesResponseEvent.fire(messageEventWrapper);
                break;
            case SEND_SALES_REPORT:
                sendSalesReportEvent.fire(messageEventWrapper);
                break;
            case UPDATE_PLUGIN_SETTING:
                updatePluginSettingEvent.fire(messageEventWrapper);
                break;
            case PING:
                pingEvent.fire(messageEventWrapper);
                break;
            case PROCESSED_MOVEMENT:
                processedMovementEvent.fire(messageEventWrapper);
                break;
            case SET_MDR_SYNC_MESSAGE_REQUEST:
                mdrSyncRequestMessageEvent.fire(messageEventWrapper);
                break;
            case SET_MDR_SYNC_MESSAGE_RESPONSE:
                mdrSyncResponseMessageEvent.fire(messageEventWrapper);
                break;
            case SET_FLUX_FA_REPORT_MESSAGE:
                processFLUXFAReportMessageEvent.fire(messageEventWrapper);
                break;
            case SEND_FLUX_FA_REPORT_MESSAGE:
                sendFaReportToPluginMessageEvent.fire(messageEventWrapper);
                break;
            case SET_FA_QUERY_MESSAGE:
                receivedFaQueryFromFlux.fire(messageEventWrapper);
                break;
            case SEND_FA_QUERY_MESSAGE:
                sendFaQueryToPluginEvent.fire(messageEventWrapper);
                break;
            case SET_FLUX_FA_RESPONSE_MESSAGE:
                processFLUXFAResponseMessageEvent.fire(messageEventWrapper);
                break;
            case RCV_FLUX_FA_RESPONSE_MESSAGE:
                receivedFLUXFAResponseMessageEvent.fire(messageEventWrapper);
                break;
            case UPDATE_LOG_STATUS:
                updateLogStatusEvent.fire(messageEventWrapper);
                break;
            case LOG_REF_ID_BY_TYPE_EXISTS:
                logRefIdByTyeExists.fire(messageEventWrapper);
                break;
            case LOG_ID_BY_TYPE_EXISTS:
                logIdByTyeExists.fire(messageEventWrapper);
                break;
            default:
                LOG.error("[ Not implemented method consumed: {} ] ", request.getMethod());
                errorEvent.fire(new ExchangeMessageEvent(textMessage, ExchangeModuleResponseMapper.createFaultMessage(FaultCode.EXCHANGE_MESSAGE, "Method not implemented")));
        }
    }
}
Also used : ExchangeModelMarshallException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException) AcknowledgeResponse(eu.europa.ec.fisheries.schema.exchange.plugin.v1.AcknowledgeResponse) TextMessage(javax.jms.TextMessage) ExchangeBaseRequest(eu.europa.ec.fisheries.schema.exchange.module.v1.ExchangeBaseRequest) ExchangeMessageEvent(eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.ExchangeMessageEvent) TransactionAttribute(javax.ejb.TransactionAttribute)

Aggregations

AcknowledgeResponse (eu.europa.ec.fisheries.schema.exchange.plugin.v1.AcknowledgeResponse)2 ExchangeModelMarshallException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException)2 AcknowledgeType (eu.europa.ec.fisheries.schema.exchange.common.v1.AcknowledgeType)1 ExchangeBaseRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.ExchangeBaseRequest)1 ExchangePluginMethod (eu.europa.ec.fisheries.schema.exchange.plugin.v1.ExchangePluginMethod)1 ExchangeMessageEvent (eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.ExchangeMessageEvent)1 ExchangeServiceException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)1 TransactionAttribute (javax.ejb.TransactionAttribute)1 TextMessage (javax.jms.TextMessage)1