Search in sources :

Example 46 with Ssld

use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.

the class DeviceManagementMapper method configure.

@Override
public void configure(final MapperFactory mapperFactory) {
    mapperFactory.registerClassMap(mapperFactory.classMap(org.opensmartgridplatform.domain.core.entities.Device.class, org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device.class).field("ipAddress", "networkAddress").byDefault().toClassMap());
    mapperFactory.registerClassMap(mapperFactory.classMap(org.opensmartgridplatform.domain.core.entities.Event.class, org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Event.class).field("dateTime", "timestamp").byDefault().toClassMap());
    mapperFactory.registerClassMap(mapperFactory.classMap(org.opensmartgridplatform.domain.core.entities.ScheduledTaskWithoutData.class, org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.ScheduledTask.class).byDefault().toClassMap());
    mapperFactory.registerClassMap(mapperFactory.classMap(org.opensmartgridplatform.domain.core.entities.ScheduledTaskWithoutData.class, org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.ScheduledTask.class).byDefault().toClassMap());
    final Mapper<org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.UpdatedDevice, Ssld> updatedDeviceToSsldMapper = new UpdatedDeviceToSsldMapper();
    mapperFactory.classMap(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.UpdatedDevice.class, Ssld.class).exclude("outputSettings").exclude("gpsLatitude").exclude("gpsLongitude").byDefault().customize(updatedDeviceToSsldMapper).register();
    mapperFactory.getConverterFactory().registerConverter(new XMLGregorianCalendarToDateTimeConverter());
    mapperFactory.getConverterFactory().registerConverter(new XMLGregorianCalendarToInstantConverter());
    mapperFactory.getConverterFactory().registerConverter(new EventTypeConverter());
    mapperFactory.getConverterFactory().registerConverter(new SmartMeterConverter());
    mapperFactory.getConverterFactory().registerConverter(new DeviceConverter());
    mapperFactory.getConverterFactory().registerConverter(new RtuDeviceConverter());
    mapperFactory.getConverterFactory().registerConverter(new LightMeasurementDeviceConverter());
    mapperFactory.getConverterFactory().registerConverter(new SsldConverter(this.ssldRepository));
}
Also used : EventTypeConverter(org.opensmartgridplatform.adapter.ws.core.application.mapping.ws.EventTypeConverter) XMLGregorianCalendarToDateTimeConverter(org.opensmartgridplatform.shared.mappers.XMLGregorianCalendarToDateTimeConverter) XMLGregorianCalendarToInstantConverter(org.opensmartgridplatform.shared.mappers.XMLGregorianCalendarToInstantConverter) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 47 with Ssld

use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.

the class SsldConverter method convertTo.

@Override
public org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device convertTo(final Ssld source, final Type<org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device> destinationType, final MappingContext context) {
    if (source == null) {
        return null;
    }
    final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device destination = this.helper.initJaxb(source);
    final Ssld ssld = this.ssldRepository.findByDeviceIdentification(source.getDeviceIdentification());
    if (ssld != null) {
        final List<org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceOutputSetting> deviceOutputSettings = new ArrayList<>();
        for (final DeviceOutputSetting deviceOutputSetting : ssld.getOutputSettings()) {
            final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceOutputSetting newDeviceOutputSetting = new org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceOutputSetting();
            newDeviceOutputSetting.setExternalId(deviceOutputSetting.getExternalId());
            newDeviceOutputSetting.setInternalId(deviceOutputSetting.getInternalId());
            newDeviceOutputSetting.setRelayType(deviceOutputSetting.getOutputType() == null ? null : RelayType.valueOf(deviceOutputSetting.getOutputType().name()));
            newDeviceOutputSetting.setAlias(deviceOutputSetting.getAlias());
            deviceOutputSettings.add(newDeviceOutputSetting);
        }
        destination.getOutputSettings().addAll(deviceOutputSettings);
        destination.setPublicKeyPresent(ssld.isPublicKeyPresent());
        destination.setHasSchedule(ssld.getHasSchedule());
        final List<org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Ean> eans = new ArrayList<>();
        for (final org.opensmartgridplatform.domain.core.entities.Ean ean : ssld.getEans()) {
            final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Ean newEan = new org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Ean();
            newEan.setCode(ean.getCode());
            newEan.setDescription(ean.getDescription());
            eans.add(newEan);
        }
        destination.getEans().addAll(eans);
        this.addRelayStatuses(destination, ssld);
    }
    return destination;
}
Also used : ArrayList(java.util.ArrayList) Device(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) Ean(org.opensmartgridplatform.domain.core.entities.Ean) Ean(org.opensmartgridplatform.domain.core.entities.Ean) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 48 with Ssld

use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.

the class WsInstallationDeviceToDeviceConverter method convertFrom.

@Override
public Device convertFrom(final org.opensmartgridplatform.domain.core.entities.Device source, final Type<Device> destinationType, final MappingContext context) {
    Device destination = null;
    if (source != null) {
        destination = new Device();
        destination.setDeviceIdentification(source.getDeviceIdentification());
        destination.setAlias(source.getAlias());
        destination.setContainerAddress(this.mapperFacade.map(source.getContainerAddress(), org.opensmartgridplatform.adapter.ws.schema.core.common.Address.class));
        if (!Objects.isNull(source.getGpsCoordinates())) {
            final GpsCoordinates gpsCoordinates = source.getGpsCoordinates();
            destination.setGpsLatitude(gpsCoordinates.getLatitude());
            destination.setGpsLongitude(gpsCoordinates.getLongitude());
        }
        destination.setActivated(source.isActivated());
        final Optional<Ssld> ssld = this.ssldRepository.findById(source.getId());
        if (ssld.isPresent()) {
            destination.setHasSchedule(ssld.get().getHasSchedule());
        }
        return destination;
    }
    return null;
}
Also used : Address(org.opensmartgridplatform.domain.core.valueobjects.Address) Device(org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.Device) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 49 with Ssld

use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.

the class DeviceConverterHelper method initEntity.

@SuppressWarnings("unchecked")
T initEntity(final Device source) {
    T destination;
    final Address containerAddress = this.mapper.map(source.getContainerAddress(), Address.class);
    GpsCoordinates gpsCoordinates = null;
    if (source.getGpsLatitude() != null && source.getGpsLongitude() != null) {
        gpsCoordinates = new GpsCoordinates(Float.valueOf(source.getGpsLatitude()), Float.valueOf(source.getGpsLongitude()));
    }
    if (this.clazz.isAssignableFrom(SmartMeter.class)) {
        destination = (T) new SmartMeter(source.getDeviceIdentification(), source.getAlias(), containerAddress, gpsCoordinates);
    } else {
        destination = (T) new Ssld(source.getDeviceIdentification(), source.getAlias(), containerAddress, gpsCoordinates, null);
    }
    if (source.isActivated() != null) {
        destination.setActivated(source.isActivated());
    }
    if (source.getDeviceLifecycleStatus() != null) {
        destination.setDeviceLifecycleStatus(DeviceLifecycleStatus.valueOf(source.getDeviceLifecycleStatus().name()));
    }
    destination.updateRegistrationData(destination.getNetworkAddress(), source.getDeviceType());
    if (source.getTechnicalInstallationDate() != null) {
        destination.setTechnicalInstallationDate(source.getTechnicalInstallationDate().toGregorianCalendar().getTime());
    }
    destination.setDeviceModel(this.mapper.map(source.getDeviceModel(), org.opensmartgridplatform.domain.core.entities.DeviceModel.class));
    return destination;
}
Also used : DeviceModel(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceModel) Address(org.opensmartgridplatform.domain.core.valueobjects.Address) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 50 with Ssld

use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.

the class WsInstallationDeviceToSsldConverter method convert.

@Override
public Ssld convert(final Device source, final Type<? extends Ssld> destinationType, final MappingContext mappingContext) {
    LOGGER.debug("Converting WS Installation Device into SSLD [{}]", source.getDeviceIdentification());
    final String deviceIdentification = source.getDeviceIdentification();
    final String alias = source.getAlias();
    final Address containerAddress = this.mapperFacade.map(source.getContainerAddress(), Address.class);
    final GpsCoordinates gpsCoordinates = new GpsCoordinates(source.getGpsLatitude(), source.getGpsLongitude());
    final Ssld ssld = new Ssld(deviceIdentification, alias, containerAddress, gpsCoordinates, null);
    ssld.setPublicKeyPresent(source.isPublicKeyPresent());
    return ssld;
}
Also used : Address(org.opensmartgridplatform.domain.core.valueobjects.Address) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Aggregations

Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)50 DeviceOutputSetting (org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting)16 Device (org.opensmartgridplatform.domain.core.entities.Device)13 ArrayList (java.util.ArrayList)12 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)11 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)10 Test (org.junit.jupiter.api.Test)9 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)9 Given (io.cucumber.java.en.Given)8 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)8 RelayType (org.opensmartgridplatform.domain.core.valueobjects.RelayType)6 Transactional (org.springframework.transaction.annotation.Transactional)6 Date (java.util.Date)5 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)5 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)5 RelayStatus (org.opensmartgridplatform.domain.core.entities.RelayStatus)4 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)4 Address (org.opensmartgridplatform.domain.core.valueobjects.Address)4 GpsCoordinates (org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates)4 NoDeviceResponseException (org.opensmartgridplatform.shared.exceptionhandling.NoDeviceResponseException)4