Search in sources :

Example 11 with ServiceResponseType

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

the class ExchangeServiceBean method registerService.

/**
 * {@inheritDoc}
 *
 * @param data
 * @throws ExchangeServiceException
 */
@Override
public ServiceResponseType registerService(ServiceType data, CapabilityListType capabilityList, SettingListType settingList, String username) throws ExchangeServiceException {
    LOG.info("Register service invoked in service layer: {} {}", data, username);
    try {
        ServiceResponseType serviceResponseType = serviceRegistryModel.registerService(data, capabilityList, settingList, username);
        sendAuditLogMessageForRegisterService(compressServiceClassName(serviceResponseType.getServiceClassName()), username);
        return serviceResponseType;
    } catch (ExchangeModelMapperException ex) {
        throw new ExchangeServiceException(ex.getMessage());
    } catch (ExchangeModelException e) {
        throw new ExchangeServiceException(e.getMessage());
    }
}
Also used : ExchangeModelMapperException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMapperException) ServiceResponseType(eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException) ExchangeServiceException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)

Example 12 with ServiceResponseType

use of eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType 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 13 with ServiceResponseType

use of eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType 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 14 with ServiceResponseType

use of eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType 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 ServiceResponseType

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

the class PluginServiceBean method updatePluginSetting.

private void updatePluginSetting(String serviceClassName, SettingType updatedSetting, String username) throws ExchangeServiceException, ExchangeModelMarshallException, ExchangeMessageException {
    SettingListType settingListType = new SettingListType();
    settingListType.getSetting().add(updatedSetting);
    ServiceResponseType service = exchangeService.upsertSettings(serviceClassName, settingListType, username);
    // Send the plugin settings to the topic where all plugins should listen to
    String text = ExchangePluginRequestMapper.createSetConfigRequest(service.getSettingList());
    producer.sendEventBusMessage(text, serviceClassName);
}
Also used : ServiceResponseType(eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType) SettingListType(eu.europa.ec.fisheries.schema.exchange.service.v1.SettingListType)

Aggregations

ServiceResponseType (eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType)16 ExchangeServiceException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)8 SettingListType (eu.europa.ec.fisheries.schema.exchange.service.v1.SettingListType)4 ExchangeModelException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)4 ArrayList (java.util.ArrayList)4 PluginType (eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginType)3 ExchangeException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeException)3 JMSException (javax.jms.JMSException)3 CapabilityListType (eu.europa.ec.fisheries.schema.exchange.service.v1.CapabilityListType)2 ExchangeLogType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType)2 UnsentMessageTypeProperty (eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty)2 ExchangeMessageEvent (eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.ExchangeMessageEvent)2 ExchangeModelMapperException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMapperException)2 ExchangeModelMarshallException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException)2 ExchangeLogException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException)2 TextMessage (javax.jms.TextMessage)2 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 GetServiceListRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.GetServiceListRequest)1