use of eu.europa.ec.fisheries.schema.config.types.v1.SettingType 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());
}
}
use of eu.europa.ec.fisheries.schema.config.types.v1.SettingType 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;
}
}
use of eu.europa.ec.fisheries.schema.config.types.v1.SettingType in project UVMS-ExchangeModule-APP by UnionVMS.
the class PluginServiceBean method overrideSettingsFromConfig.
private void overrideSettingsFromConfig(RegisterServiceRequest registerServiceRequest) {
List<SettingType> currentRequestSettings = registerServiceRequest.getSettingList().getSetting();
try {
List<eu.europa.ec.fisheries.schema.config.types.v1.SettingType> configServiceSettings = configService.getSettings(registerServiceRequest.getService().getServiceClassName());
Map<String, SettingType> configServiceSettingsMap = putConfigSettingsInAMap(configServiceSettings);
if (!configServiceSettingsMap.isEmpty()) {
for (SettingType type : currentRequestSettings) {
SettingType configSettingType = configServiceSettingsMap.get(type.getKey());
if (configSettingType != null && !configSettingType.getValue().equalsIgnoreCase(type.getValue())) {
type.setValue(configSettingType.getValue());
}
}
}
} catch (ConfigServiceException e) {
LOG.error("Register service exception, cannot read Exchange settings from Config {} {}", registerServiceRequest, e.getMessage());
// Ignore when we can't get the settings from Config. It is possible there is no Config module setup.
}
}
use of eu.europa.ec.fisheries.schema.config.types.v1.SettingType in project UVMS-ExchangeModule-APP by UnionVMS.
the class MockData method getSettingList.
public static SettingListType getSettingList() {
SettingListType dto = new SettingListType();
SettingType setting = new SettingType();
setting.setKey(SETTING_KEY);
setting.setValue("setting.value");
dto.getSetting().add(setting);
return dto;
}
use of eu.europa.ec.fisheries.schema.config.types.v1.SettingType in project UVMS-ExchangeModule-APP by UnionVMS.
the class MapperTest method testUpsert.
@Test
public void testUpsert() {
String newValue = "NEW_VALUE";
Service entity = MockData.getEntity(1);
entity.setServiceCapabilityList(MockData.getEntityCapabilities(entity));
entity.setServiceSettingList(MockData.getEntitySettings(entity));
SettingListType updateSettings = new SettingListType();
SettingType updateSetting = new SettingType();
updateSetting.setKey(MockData.SETTING_KEY);
updateSetting.setValue(newValue);
updateSettings.getSetting().add(updateSetting);
List<ServiceSetting> list = mapper.mapSettingsList(entity, updateSettings, "TEST");
assertFalse(list.isEmpty());
for (ServiceSetting setting : list) {
assertSame(setting.getValue(), newValue);
}
SettingListType newSettings = new SettingListType();
SettingType newSetting = new SettingType();
newSetting.setKey("NEW.KEY");
newSetting.setValue("NEW.VALUE");
newSettings.getSetting().add(newSetting);
list = mapper.mapSettingsList(entity, newSettings, "TEST");
assertTrue(list.size() == 1);
}
Aggregations