Search in sources :

Example 11 with ExchangeServiceException

use of eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException 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)

Example 12 with ExchangeServiceException

use of eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException in project UVMS-ExchangeModule-APP by UnionVMS.

the class PluginServiceBean method unregisterService.

@Override
public void unregisterService(@Observes @UnRegisterServiceEvent PluginMessageEvent event) {
    LOG.info("unregister service:{}", event);
    TextMessage textMessage = event.getJmsMessage();
    ServiceResponseType service = null;
    try {
        UnregisterServiceRequest unregister = JAXBMarshaller.unmarshallTextMessage(textMessage, UnregisterServiceRequest.class);
        service = exchangeService.unregisterService(unregister.getService(), unregister.getService().getName());
        String serviceClassName = service.getServiceClassName();
    // NO ack back to plugin
    // TODO log to exchange log
    } catch (ExchangeModelMarshallException | ExchangeServiceException e) {
        LOG.error("Unregister service exception " + e.getMessage());
        errorEvent.fire(new PluginMessageEvent(textMessage, service, ExchangePluginResponseMapper.mapToPluginFaultResponse(FaultCode.EXCHANGE_PLUGIN_EVENT.getCode(), "Exception when unregister service")));
    }
}
Also used : ExchangeModelMarshallException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException) ServiceResponseType(eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType) UnregisterServiceRequest(eu.europa.ec.fisheries.schema.exchange.registry.v1.UnregisterServiceRequest) PluginMessageEvent(eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.PluginMessageEvent) TextMessage(javax.jms.TextMessage) ExchangeServiceException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)

Example 13 with ExchangeServiceException

use of eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException in project UVMS-ExchangeModule-APP by UnionVMS.

the class PluginServiceBean method ping.

@Override
public boolean ping(String serviceClassName) throws ExchangeServiceException {
    if (serviceClassName == null) {
        throw new InputArgumentException("No service to ping");
    }
    try {
        String text = ExchangePluginRequestMapper.createPingRequest();
        producer.sendEventBusMessage(text, serviceClassName);
        return true;
    } catch (ExchangeModelMarshallException e) {
        throw new ExchangeServiceException("[ Couldn't map ping request for " + serviceClassName + " ]");
    } catch (ExchangeMessageException e) {
        throw new ExchangeServiceException("[ Couldn't send ping request for " + serviceClassName + " ]");
    }
}
Also used : ExchangeModelMarshallException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException) InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.service.exception.InputArgumentException) ExchangeMessageException(eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException) ExchangeServiceException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)

Example 14 with ExchangeServiceException

use of eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException in project UVMS-ExchangeModule-APP by UnionVMS.

the class PluginServiceBean method registerService.

private void registerService(RegisterServiceRequest register, String messageId) throws ExchangeModelMarshallException, ExchangeMessageException {
    try {
        overrideSettingsFromConfig(register);
        ServiceResponseType service = exchangeService.registerService(register.getService(), register.getCapabilityList(), register.getSettingList(), register.getService().getName());
        // push to config module
        try {
            String serviceClassName = register.getService().getServiceClassName();
            SettingListType settings = register.getSettingList();
            for (SettingType setting : settings.getSetting()) {
                String description = "Plugin " + serviceClassName + " " + setting.getKey() + " setting";
                configService.pushSettingToConfig(SettingTypeMapper.map(setting.getKey(), setting.getValue(), description), false);
            }
        } catch (ConfigServiceException e) {
            LOG.error("Couldn't register plugin settings in config parameter table");
        }
        // TODO log to exchange log
        String response = ExchangePluginResponseMapper.mapToRegisterServiceResponseOK(messageId, service);
        producer.sendEventBusMessage(response, register.getService().getServiceResponseMessageName());
        setServiceStatusOnRegister(register.getService().getServiceClassName());
    } catch (ExchangeServiceException | ExchangeModelMapperException e) {
        String response = ExchangePluginResponseMapper.mapToRegisterServiceResponseNOK(messageId, "Exchange service exception when registering plugin [ " + e.getMessage() + " ]");
        producer.sendEventBusMessage(response, register.getService().getServiceResponseMessageName());
    }
}
Also used : ExchangeModelMapperException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMapperException) ServiceResponseType(eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType) ConfigServiceException(eu.europa.ec.fisheries.uvms.config.exception.ConfigServiceException) SettingType(eu.europa.ec.fisheries.schema.exchange.service.v1.SettingType) SettingListType(eu.europa.ec.fisheries.schema.exchange.service.v1.SettingListType) ExchangeServiceException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)

Example 15 with ExchangeServiceException

use of eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException in project UVMS-ExchangeModule-APP by UnionVMS.

the class PluginServiceBean method setConfig.

@Override
public void setConfig(@Observes @ConfigSettingUpdatedEvent ConfigSettingEvent settingEvent) {
    switch(settingEvent.getType()) {
        case STORE:
            // ConfigModule and/or Exchange module deployed
            break;
        case UPDATE:
            LOG.info("ConfigModule updated parameter table with settings of plugins");
            try {
                String key = settingEvent.getKey();
                String value = parameterService.getStringValue(key);
                String settingKey;
                String[] splittedKey = key.split(PARAMETER_DELIMETER);
                if (splittedKey.length > 2) {
                    settingKey = key;
                    String serviceClassName = "";
                    for (int i = 0; i < splittedKey.length - 2; i++) {
                        serviceClassName += splittedKey[i] + ".";
                    }
                    serviceClassName += splittedKey[splittedKey.length - 2];
                    SettingType settingType = new SettingType();
                    settingType.setKey(key);
                    settingType.setValue(value);
                    updatePluginSetting(serviceClassName, settingType, "UVMS");
                } else {
                    LOG.error("No key or malformed key sent in settingEvent: key: {}, value: {}", key, value);
                }
            } catch (ConfigServiceException e) {
                LOG.error("Couldn't get updated parameter table value");
            } catch (ExchangeServiceException e) {
                LOG.error("Couldn't upsert settings in exchange");
            } catch (ExchangeModelMarshallException e) {
                LOG.error("Couldn't create plugin set config request");
            } catch (ExchangeMessageException e) {
                LOG.error("Couldn't send message to plugin");
            }
            break;
        case DELETE:
            LOG.info("ConfigModule removed parameter setting");
            break;
    }
}
Also used : ExchangeModelMarshallException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException) ConfigServiceException(eu.europa.ec.fisheries.uvms.config.exception.ConfigServiceException) ExchangeMessageException(eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException) SettingType(eu.europa.ec.fisheries.schema.exchange.service.v1.SettingType) ExchangeServiceException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)

Aggregations

ExchangeServiceException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)15 ServiceResponseType (eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType)8 ExchangeModelMarshallException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException)8 ExchangeMessageException (eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException)6 ExchangeModelException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)4 InputArgumentException (eu.europa.ec.fisheries.uvms.exchange.service.exception.InputArgumentException)3 TextMessage (javax.jms.TextMessage)3 PluginType (eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginType)2 SettingType (eu.europa.ec.fisheries.schema.exchange.service.v1.SettingType)2 ConfigServiceException (eu.europa.ec.fisheries.uvms.config.exception.ConfigServiceException)2 ExchangeModelMapperException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMapperException)2 AcknowledgeType (eu.europa.ec.fisheries.schema.exchange.common.v1.AcknowledgeType)1 SetMovementReportRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.SetMovementReportRequest)1 UpdatePluginSettingRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.UpdatePluginSettingRequest)1 MovementBaseType (eu.europa.ec.fisheries.schema.exchange.movement.v1.MovementBaseType)1 AcknowledgeResponse (eu.europa.ec.fisheries.schema.exchange.plugin.v1.AcknowledgeResponse)1 ExchangePluginMethod (eu.europa.ec.fisheries.schema.exchange.plugin.v1.ExchangePluginMethod)1 UnregisterServiceRequest (eu.europa.ec.fisheries.schema.exchange.registry.v1.UnregisterServiceRequest)1 SettingListType (eu.europa.ec.fisheries.schema.exchange.service.v1.SettingListType)1 ProcessedMovementAck (eu.europa.ec.fisheries.schema.movement.module.v1.ProcessedMovementAck)1