Search in sources :

Example 16 with Address

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

the class SmartMeterSteps method aSmartMeter.

/**
 * Given a smart meter exists.
 */
@Given("^a smart meter$")
@Transactional("txMgrCore")
public Device aSmartMeter(final Map<String, String> settings) {
    final String deviceIdentification = getString(settings, KEY_DEVICE_IDENTIFICATION, DEFAULT_DEVICE_IDENTIFICATION);
    final SmartMeter smartMeter = new SmartMeter(deviceIdentification, getString(settings, KEY_ALIAS, DEFAULT_ALIAS), new Address(getString(settings, KEY_CONTAINER_CITY, DEFAULT_CONTAINER_CITY), getString(settings, KEY_CONTAINER_POSTALCODE, DEFAULT_CONTAINER_POSTALCODE), getString(settings, KEY_CONTAINER_STREET, DEFAULT_CONTAINER_STREET), getInteger(settings, KEY_CONTAINER_NUMBER, DEFAULT_CONTAINER_NUMBER), getString(settings, KEY_CONTAINER_NUMBER_ADDITION, DEFAULT_CONTAINER_NUMBER_ADDITION), getString(settings, KEY_CONTAINER_MUNICIPALITY, DEFAULT_CONTAINER_MUNICIPALITY)), new GpsCoordinates(getFloat(settings, KEY_GPS_LATITUDE, DEFAULT_LATITUDE), getFloat(settings, KEY_GPS_LONGITUDE, DEFAULT_LONGITUDE)));
    smartMeter.setSupplier(getString(settings, KEY_SUPPLIER, DEFAULT_SUPPLIER));
    if (settings.containsKey(KEY_GATEWAY_DEVICE_ID)) {
        smartMeter.setChannel(getShort(settings, KEY_CHANNEL, DEFAULT_CHANNEL));
        final Device smartEMeter = this.deviceRepository.findByDeviceIdentification(settings.get(KEY_GATEWAY_DEVICE_ID));
        smartMeter.updateGatewayDevice(smartEMeter);
    }
    this.smartMeterRepository.save(smartMeter);
    return this.updateDevice(deviceIdentification, settings);
}
Also used : Address(org.opensmartgridplatform.domain.core.valueobjects.Address) Device(org.opensmartgridplatform.domain.core.entities.Device) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates) Given(io.cucumber.java.en.Given) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with Address

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

the class DeviceBuilder method build.

@Override
public Device build() {
    final Device device = new Device(this.deviceIdentification, this.alias, new Address(this.containerCity, this.containerPostalCode, this.containerStreet, this.containerNumber, this.containerNumberAddition, this.containerMunicipality), new GpsCoordinates(this.gpsLatitude, this.gpsLongitude), null);
    device.updateProtocol(this.protocolInfo);
    device.updateInMaintenance(this.inMaintenance);
    if (this.gatewayDeviceIdentification != null) {
        device.updateGatewayDevice(this.deviceRepository.findByDeviceIdentification(this.gatewayDeviceIdentification));
    }
    device.setVersion(this.version);
    device.setDeviceModel(this.deviceModel);
    device.setTechnicalInstallationDate(this.technicalInstallationDate);
    // updateRegistrationData sets the status to IN_USE, so setting of any
    // other status has to be done after that.
    device.updateRegistrationData(this.networkAddress, this.deviceType);
    device.setDeviceLifecycleStatus(this.deviceLifeCycleStatus);
    return device;
}
Also used : Address(org.opensmartgridplatform.domain.core.valueobjects.Address) Device(org.opensmartgridplatform.domain.core.entities.Device) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates)

Example 18 with Address

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

the class SmartMeterBuilder method build.

@Override
public SmartMeter build() {
    final SmartMeter device = new SmartMeter(this.deviceIdentification, this.alias, new Address(this.containerCity, this.containerPostalCode, this.containerStreet, this.containerNumber, this.containerNumberAddition, this.containerMunicipality), new GpsCoordinates(this.gpsLatitude, this.gpsLongitude));
    device.setActivated(this.isActivated);
    device.updateRegistrationData(this.networkAddress, this.deviceType);
    device.setBtsId(this.baseTransceiverStationId);
    device.setCellId(this.cellId);
    // After updateRegistrationData because that sets deviceLifecyleStatus
    // to IN_USE again.
    device.setDeviceLifecycleStatus(this.deviceLifeCycleStatus);
    device.updateProtocol(this.protocolInfo);
    device.updateInMaintenance(this.inMaintenance);
    device.setVersion(this.version);
    device.setDeviceModel(this.deviceModel);
    device.setTechnicalInstallationDate(this.technicalInstallationDate);
    device.setSupplier(this.supplier);
    device.setChannel(this.channel);
    device.setMbusIdentificationNumber(this.mbusIdentificationNumber);
    device.setMbusManufacturerIdentification(this.mbusManufacturerIdentification);
    device.setMbusVersion(this.mbusVersion);
    device.setMbusDeviceTypeIdentification(this.mbusDeviceTypeIdentification);
    device.setMbusPrimaryAddress(this.mbusPrimaryAddress);
    return device;
}
Also used : Address(org.opensmartgridplatform.domain.core.valueobjects.Address) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates)

Example 19 with Address

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

the class WsInstallationDeviceToDeviceConverter method convertTo.

@Override
public org.opensmartgridplatform.domain.core.entities.Device convertTo(final Device source, final Type<org.opensmartgridplatform.domain.core.entities.Device> destinationType, final MappingContext context) {
    org.opensmartgridplatform.domain.core.entities.Device destination = null;
    if (source != null) {
        final Address address = this.mapperFacade.map(source.getContainerAddress(), Address.class);
        destination = new org.opensmartgridplatform.domain.core.entities.Device(source.getDeviceIdentification(), source.getAlias(), address, new GpsCoordinates(source.getGpsLatitude(), source.getGpsLongitude()), null);
        final DeviceModel deviceModel = this.writableDeviceModelRepository.findByManufacturerCodeAndModelCode(source.getDeviceModel().getManufacturer(), source.getDeviceModel().getModelCode());
        if (deviceModel == null) {
            throw new AssertionError("Model code \"" + source.getDeviceModel().getModelCode() + "\" and Manufacturer \"" + source.getDeviceModel().getManufacturer() + "\" do not identify an existing device model.");
        } else {
            destination.setDeviceModel(deviceModel);
        }
        return destination;
    }
    return null;
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) Address(org.opensmartgridplatform.domain.core.valueobjects.Address) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates)

Example 20 with Address

use of org.opensmartgridplatform.domain.core.valueobjects.Address 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)

Aggregations

Address (org.opensmartgridplatform.domain.core.valueobjects.Address)21 GpsCoordinates (org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates)18 Test (org.junit.jupiter.api.Test)6 InetAddress (java.net.InetAddress)5 Device (org.opensmartgridplatform.domain.core.entities.Device)4 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)4 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)4 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)4 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)3 Given (io.cucumber.java.en.Given)2 UnknownHostException (java.net.UnknownHostException)2 LightMeasurementDevice (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightMeasurementDevice)2 Ssld (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Ssld)2 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Instant (java.time.Instant)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 LightMeasurementDevice (org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.LightMeasurementDevice)1