Search in sources :

Example 11 with Service

use of eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.Service in project UVMS-ExchangeModule-APP by UnionVMS.

the class ServiceRegistryModelBean method unregisterService.

@Override
public ServiceResponseType unregisterService(ServiceType serviceType, String username) throws ExchangeModelException {
    // Look for existing service
    Service service = dao.getServiceByServiceClassName(serviceType.getServiceClassName());
    ServiceResponseType response = null;
    if (service != null) {
        service.setActive(false);
        service.setStatus(StatusType.STOPPED.name());
        service.getServiceCapabilityList().clear();
        service.getServiceSettingList().clear();
        service.setUpdatedBy(username);
        Service updateService = dao.updateService(service);
        response = ServiceMapper.toServiceModel(updateService);
    }
    if (response != null) {
        return response;
    }
    // TODO handle unable to unregister
    throw new ExchangeDaoException("[ No service to unregister ]");
}
Also used : ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) Service(eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.Service)

Example 12 with Service

use of eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.Service 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 13 with Service

use of eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.Service in project UVMS-ExchangeModule-APP by UnionVMS.

the class DaoBeanTest method testCreateService.

@Test
public void testCreateService() throws ExchangeDaoException {
    Service carrier = new Service();
    dao.createEntity(carrier);
    verify(em).persist(carrier);
}
Also used : Service(eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.Service) Test(org.junit.Test)

Example 14 with Service

use of eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.Service in project UVMS-ExchangeModule-APP by UnionVMS.

the class MockData method getEntity.

public static Service getEntity(long id) {
    Service entity = new Service();
    entity.setId(id);
    entity.setName("Plugin name");
    entity.setDescription("Some description");
    entity.setServiceClassName("the.qualified.id.of.plugin" + id);
    return entity;
}
Also used : Service(eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.Service)

Example 15 with Service

use of eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.Service in project UVMS-ExchangeModule-APP by UnionVMS.

the class MapperTest method testEntityAndModelToEntity.

@Test
public void testEntityAndModelToEntity() throws ExchangeDaoException, ExchangeDaoMappingException {
    Integer id = 1;
    Service entity = MockData.getEntity(id);
    ServiceType service = MockData.getModel(1);
    CapabilityListType capabilityListType = MockData.getCapabilityList();
    SettingListType settingListType = MockData.getSettingList();
    // mockDaoToEntity();
    Service result = mapper.toServiceEntity(entity, service, capabilityListType, settingListType, "TEST");
    assertSame(entity.getName(), result.getName());
    assertSame(entity.getServiceClassName(), result.getServiceClassName());
}
Also used : CapabilityListType(eu.europa.ec.fisheries.schema.exchange.service.v1.CapabilityListType) ServiceType(eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceType) Service(eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.Service) SettingListType(eu.europa.ec.fisheries.schema.exchange.service.v1.SettingListType) Test(org.junit.Test)

Aggregations

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