use of eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceSetting in project UVMS-ExchangeModule-APP by UnionVMS.
the class ServiceRegistryModelBean method updatePluginSettings.
@Override
public ServiceResponseType updatePluginSettings(String serviceClassName, SettingListType settings, String username) throws ExchangeModelException {
LOG.info("Update plugin settings for " + serviceClassName);
Service service = dao.getServiceByServiceClassName(serviceClassName);
if (service != null) {
List<ServiceSetting> newSettings = ServiceMapper.mapSettingsList(service, settings, username);
service.getServiceSettingList().addAll(newSettings);
dao.updateService(service);
return ServiceMapper.toServiceModel(service);
}
throw new ExchangeDaoException("No plugin found when update plugin settings");
}
use of eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceSetting in project UVMS-ExchangeModule-APP by UnionVMS.
the class ServiceRegistryModelBean method registerService.
@Override
public ServiceResponseType registerService(ServiceType serviceType, CapabilityListType capabilityList, SettingListType settingList, String username) throws ExchangeModelException {
// Look for existing service
Service service = dao.getServiceByServiceClassName(serviceType.getServiceClassName());
if (service == null) {
// create
service = ServiceMapper.toServiceEntity(serviceType, capabilityList, settingList, username);
service.setActive(true);
service.setStatus(StatusType.STARTED.name());
dao.createEntity(service);
} else {
service.setActive(true);
service.setStatus(StatusType.STARTED.name());
List<ServiceSetting> newSettings = ServiceMapper.mapSettingsList(service, settingList, username);
List<ServiceCapability> serviceCapabilityList = ServiceMapper.upsetCapabilityList(service, capabilityList, username);
service.getServiceCapabilityList().clear();
service.getServiceCapabilityList().addAll(serviceCapabilityList);
service.getServiceSettingList().clear();
service.getServiceSettingList().addAll(newSettings);
service.setDescription(serviceType.getDescription());
service.setName(serviceType.getName());
service.setUpdated(new DateTime(DateTimeZone.UTC).toDate());
service.setUpdatedBy(username);
dao.updateService(service);
}
return ServiceMapper.toServiceModel(service);
}
use of eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceSetting in project UVMS-ExchangeModule-APP by UnionVMS.
the class MockData method getEntitySettings.
public static List<ServiceSetting> getEntitySettings(Service parent) {
List<ServiceSetting> list = new ArrayList<>();
ServiceSetting setting = new ServiceSetting();
setting.setService(parent);
setting.setSetting(SETTING_KEY);
setting.setValue("value");
list.add(setting);
return list;
}
use of eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceSetting 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);
}
use of eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceSetting in project UVMS-ExchangeModule-APP by UnionVMS.
the class ServiceMapper method mapSettingsList.
public static List<ServiceSetting> mapSettingsList(Service parent, SettingListType settingList, String username) {
List<ServiceSetting> newSettings = new ArrayList<>();
List<ServiceSetting> currentSettings = parent.getServiceSettingList();
Map<String, ServiceSetting> map = new HashMap<>();
if (currentSettings != null) {
for (ServiceSetting i : currentSettings) {
map.put(i.getSetting(), i);
}
}
for (SettingType setting : settingList.getSetting()) {
ServiceSetting currentSetting = map.get(setting.getKey());
if (currentSetting == null) {
ServiceSetting newSetting = toSettingEntity(parent, setting, username);
newSettings.add(newSetting);
} else {
if (!currentSetting.getValue().equalsIgnoreCase(setting.getValue())) {
currentSetting.setValue(setting.getValue());
currentSetting.setUpdatedTime(DateUtils.nowUTC().toDate());
currentSetting.setUser(username);
}
newSettings.add(currentSetting);
}
}
return newSettings;
}
Aggregations