Search in sources :

Example 6 with ServiceCapability

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

the class ServiceMapper method toCapabilityEntity.

private static ServiceCapability toCapabilityEntity(Service parent, CapabilityType capability, String username) {
    ServiceCapability entity = new ServiceCapability();
    entity.setService(parent);
    entity.setCapability(capability.getType());
    entity.setUpdatedBy(username);
    entity.setUpdatedTime(DateUtils.nowUTC().toDate());
    entity.setValue(capability.getValue());
    return entity;
}
Also used : ServiceCapability(eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceCapability)

Example 7 with ServiceCapability

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

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

the class ServiceMapper method upsetCapabilityList.

public static List<ServiceCapability> upsetCapabilityList(Service parent, CapabilityListType capabilityList, String username) {
    List<ServiceCapability> newCapabilityList = new ArrayList<>();
    for (CapabilityType capabilityType : capabilityList.getCapability()) {
        ServiceCapability newServiceCapability = toCapabilityEntity(parent, capabilityType, username);
        newCapabilityList.add(newServiceCapability);
    }
    return newCapabilityList;
}
Also used : CapabilityType(eu.europa.ec.fisheries.schema.exchange.service.v1.CapabilityType) ArrayList(java.util.ArrayList) ServiceCapability(eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceCapability)

Example 9 with ServiceCapability

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

the class ServiceRegistryDaoBean method getServiceCapabilities.

@Override
public List<ServiceCapability> getServiceCapabilities(String serviceClassName) throws ExchangeDaoException {
    try {
        TypedQuery<ServiceCapability> query = em.createNamedQuery(ExchangeConstants.CAPABILITY_FIND_BY_SERVICE, ServiceCapability.class);
        query.setParameter(SERVICE_CLASS_NAME_PARAMETER, serviceClassName);
        return query.getResultList();
    } catch (IllegalArgumentException e) {
        LOG.error("[ Error when getting capabilities ] {}", e.getMessage());
        throw new ExchangeDaoException("[ Error when getting capabilities ] ");
    } catch (Exception e) {
        LOG.error("[ Error when getting capabilities ] {}", e.getMessage());
        throw new ExchangeDaoException("[ Error when getting capabilities ] ");
    }
}
Also used : ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) ServiceCapability(eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceCapability) EntityExistsException(javax.persistence.EntityExistsException) NoResultException(javax.persistence.NoResultException) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) NoEntityFoundException(eu.europa.ec.fisheries.uvms.exchange.exception.NoEntityFoundException)

Aggregations

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