Search in sources :

Example 6 with ServiceSetting

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");
}
Also used : ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) Service(eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.Service) ServiceSetting(eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceSetting)

Example 7 with ServiceSetting

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);
}
Also used : Service(eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.Service) ServiceCapability(eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceCapability) DateTime(org.joda.time.DateTime) ServiceSetting(eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceSetting)

Example 8 with ServiceSetting

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;
}
Also used : ArrayList(java.util.ArrayList) ServiceSetting(eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceSetting)

Example 9 with ServiceSetting

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);
}
Also used : Service(eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.Service) SettingType(eu.europa.ec.fisheries.schema.exchange.service.v1.SettingType) SettingListType(eu.europa.ec.fisheries.schema.exchange.service.v1.SettingListType) ServiceSetting(eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceSetting) Test(org.junit.Test)

Example 10 with ServiceSetting

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SettingType(eu.europa.ec.fisheries.schema.exchange.service.v1.SettingType) ServiceSetting(eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceSetting)

Aggregations

ServiceSetting (eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceSetting)11 Service (eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.Service)6 ArrayList (java.util.ArrayList)6 ServiceCapability (eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceCapability)4 Test (org.junit.Test)4 ServiceType (eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceType)3 ExchangeDaoException (eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException)3 SettingListType (eu.europa.ec.fisheries.schema.exchange.service.v1.SettingListType)2 SettingType (eu.europa.ec.fisheries.schema.exchange.service.v1.SettingType)2 CapabilityListType (eu.europa.ec.fisheries.schema.exchange.service.v1.CapabilityListType)1 ServiceResponseType (eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType)1 NoEntityFoundException (eu.europa.ec.fisheries.uvms.exchange.exception.NoEntityFoundException)1 ExchangeModelException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)1 HashMap (java.util.HashMap)1 EntityExistsException (javax.persistence.EntityExistsException)1 NoResultException (javax.persistence.NoResultException)1 DateTime (org.joda.time.DateTime)1 Ignore (org.junit.Ignore)1