Search in sources :

Example 1 with GpsCoordinates

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

the class LightMeasurementDeviceSteps method aLightMeasurementDevice.

@Given("^a light measurement device$")
@Transactional("txMgrCore")
public LightMeasurementDevice aLightMeasurementDevice(final Map<String, String> settings) {
    final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION);
    final LightMeasurementDevice lmd = new LightMeasurementDevice(deviceIdentification);
    final List<DeviceModel> deviceModels = this.deviceModelRepository.findByModelCode(getString(settings, PlatformKeys.KEY_DEVICE_MODEL, PlatformDefaults.DEFAULT_DEVICE_MODEL_MODEL_CODE));
    final DeviceModel deviceModel = deviceModels.get(0);
    lmd.setDeviceModel(deviceModel);
    if (settings.containsKey(PlatformKeys.KEY_DEVICE_TYPE)) {
        InetAddress inetAddress;
        try {
            inetAddress = InetAddress.getByName(getString(settings, PlatformKeys.IP_ADDRESS, this.configuration.getDeviceNetworkAddress()));
        } catch (final UnknownHostException e) {
            inetAddress = InetAddress.getLoopbackAddress();
        }
        lmd.updateRegistrationData(inetAddress, getString(settings, PlatformKeys.KEY_DEVICE_TYPE));
    }
    lmd.updateMetaData(getString(settings, PlatformKeys.ALIAS, PlatformDefaults.DEFAULT_ALIAS), new Address(getString(settings, PlatformKeys.KEY_CITY, PlatformDefaults.DEFAULT_CONTAINER_CITY), getString(settings, PlatformKeys.KEY_POSTCODE, PlatformDefaults.DEFAULT_CONTAINER_POSTALCODE), getString(settings, PlatformKeys.KEY_STREET, PlatformDefaults.DEFAULT_CONTAINER_STREET), getInteger(settings, PlatformKeys.KEY_NUMBER, PlatformDefaults.DEFAULT_CONTAINER_NUMBER), getString(settings, PlatformKeys.KEY_NUMBER_ADDITION, PlatformDefaults.DEFAULT_CONTAINER_NUMBER_ADDITION), getString(settings, PlatformKeys.KEY_MUNICIPALITY, PlatformDefaults.DEFAULT_CONTAINER_MUNICIPALITY)), new GpsCoordinates(settings.containsKey(PlatformKeys.KEY_LATITUDE) && StringUtils.isNotBlank(settings.get(PlatformKeys.KEY_LATITUDE)) ? getFloat(settings, PlatformKeys.KEY_LATITUDE, PlatformDefaults.DEFAULT_LATITUDE) : null, settings.containsKey(PlatformKeys.KEY_LONGITUDE) && StringUtils.isNotBlank(settings.get(PlatformKeys.KEY_LONGITUDE)) ? getFloat(settings, PlatformKeys.KEY_LONGITUDE, PlatformDefaults.DEFAULT_LONGITUDE) : null));
    lmd.setActivated(getBoolean(settings, PlatformKeys.KEY_ACTIVATED, PlatformDefaults.DEFAULT_ACTIVATED));
    lmd.setDescription(getString(settings, PlatformKeys.KEY_LMD_DESCRIPTION, PlatformDefaults.DEFAULT_LMD_DESCRIPTION));
    lmd.setCode(getString(settings, PlatformKeys.KEY_LMD_CODE, PlatformDefaults.DEFAULT_LMD_CODE));
    lmd.setColor(getString(settings, PlatformKeys.KEY_LMD_COLOR, PlatformDefaults.DEFAULT_LMD_COLOR));
    lmd.setDigitalInput(getShort(settings, PlatformKeys.KEY_LMD_DIGITAL_INPUT, PlatformDefaults.DEFAULT_LMD_DIGITAL_INPUT));
    this.setDefaultDeviceAuthorizationForDevice(lmd);
    return this.lightMeasurementDeviceRepository.findByDeviceIdentification(deviceIdentification);
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) UnknownHostException(java.net.UnknownHostException) InetAddress(java.net.InetAddress) Address(org.opensmartgridplatform.domain.core.valueobjects.Address) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) InetAddress(java.net.InetAddress) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates) Given(io.cucumber.java.en.Given) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with GpsCoordinates

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

the class BaseDeviceSteps method updateDevice.

/**
 * Update an existing device with the given settings.
 *
 * @param device The Device to update
 * @param settings The settings to update the device with.
 * @return The Device
 */
public Device updateDevice(Device device, final Map<String, String> settings) {
    // Now set the optional stuff
    if (settings.containsKey(PlatformKeys.KEY_TECHNICAL_INSTALLATION_DATE) && StringUtils.isNotBlank(settings.get(PlatformKeys.KEY_TECHNICAL_INSTALLATION_DATE))) {
        device.setTechnicalInstallationDate(getDate(settings, PlatformKeys.KEY_TECHNICAL_INSTALLATION_DATE).toDate());
    }
    /*
     * Model code does not uniquely identify a device model, which is why
     * deviceModelRepository is changed to return a list of device models.
     * In the test data that is set up, there probably is only one device
     * model for the given model code, and just selecting the first device
     * model returned should work.
     *
     * A better solution might be to add the manufacturer in the scenario
     * data and do a lookup by manufacturer and model code, which should
     * uniquely define the device model.
     */
    final List<DeviceModel> deviceModels = this.deviceModelRepository.findByModelCode(getString(settings, PlatformKeys.KEY_DEVICE_MODEL, PlatformDefaults.DEFAULT_DEVICE_MODEL_MODEL_CODE));
    final DeviceModel deviceModel = deviceModels.get(0);
    device.setDeviceModel(deviceModel);
    device.updateProtocol(this.protocolInfoRepository.findByProtocolAndProtocolVersion(getString(settings, PlatformKeys.KEY_PROTOCOL, PlatformDefaults.DEFAULT_PROTOCOL), getString(settings, PlatformKeys.KEY_PROTOCOL_VERSION, PlatformDefaults.DEFAULT_PROTOCOL_VERSION)));
    InetAddress inetAddress;
    try {
        inetAddress = InetAddress.getByName(getString(settings, PlatformKeys.IP_ADDRESS, this.configuration.getDeviceNetworkAddress()));
    } catch (final UnknownHostException e) {
        inetAddress = InetAddress.getLoopbackAddress();
    }
    device.setBtsId(getInteger(settings, PlatformKeys.BTS_ID, null));
    device.setCellId(getInteger(settings, PlatformKeys.CELL_ID, null));
    device.updateRegistrationData(inetAddress, getString(settings, PlatformKeys.KEY_DEVICE_TYPE, PlatformDefaults.DEFAULT_DEVICE_TYPE));
    device.updateInMaintenance(getBoolean(settings, PlatformKeys.IN_MAINTENANCE, PlatformDefaults.IN_MAINTENANCE));
    device.setDeviceLifecycleStatus(getEnum(settings, PlatformKeys.KEY_DEVICE_LIFECYCLE_STATUS, DeviceLifecycleStatus.class, PlatformDefaults.DEFAULT_DEVICE_LIFECYCLE_STATUS));
    if (!Objects.equals(getString(settings, PlatformKeys.KEY_ORGANIZATION_IDENTIFICATION, PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION), "null")) {
        device.addOrganisation(getString(settings, PlatformKeys.KEY_ORGANIZATION_IDENTIFICATION, PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION));
    }
    device.updateMetaData(getString(settings, PlatformKeys.ALIAS, PlatformDefaults.DEFAULT_ALIAS), new Address(getString(settings, PlatformKeys.KEY_CITY, PlatformDefaults.DEFAULT_CONTAINER_CITY), getString(settings, PlatformKeys.KEY_POSTCODE, PlatformDefaults.DEFAULT_CONTAINER_POSTALCODE), getString(settings, PlatformKeys.KEY_STREET, PlatformDefaults.DEFAULT_CONTAINER_STREET), getInteger(settings, PlatformKeys.KEY_NUMBER, PlatformDefaults.DEFAULT_CONTAINER_NUMBER), getString(settings, PlatformKeys.KEY_NUMBER_ADDITION, PlatformDefaults.DEFAULT_CONTAINER_NUMBER_ADDITION), getString(settings, PlatformKeys.KEY_MUNICIPALITY, PlatformDefaults.DEFAULT_CONTAINER_MUNICIPALITY)), new GpsCoordinates(settings.containsKey(PlatformKeys.KEY_LATITUDE) && StringUtils.isNotBlank(settings.get(PlatformKeys.KEY_LATITUDE)) ? getFloat(settings, PlatformKeys.KEY_LATITUDE, PlatformDefaults.DEFAULT_LATITUDE) : null, settings.containsKey(PlatformKeys.KEY_LONGITUDE) && StringUtils.isNotBlank(settings.get(PlatformKeys.KEY_LONGITUDE)) ? getFloat(settings, PlatformKeys.KEY_LONGITUDE, PlatformDefaults.DEFAULT_LONGITUDE) : null));
    device.setActivated(getBoolean(settings, PlatformKeys.KEY_ACTIVATED, PlatformDefaults.DEFAULT_ACTIVATED));
    final String integrationType = getString(settings, PlatformKeys.KEY_INTEGRATION_TYPE, PlatformDefaults.DEFAULT_INTEGRATION_TYPE).toUpperCase();
    device.setIntegrationType(IntegrationType.valueOf(integrationType));
    device = this.deviceRepository.save(device);
    device = this.updateWithAuthorization(device, settings);
    this.addEanToDevice(device, settings);
    final String mastSegment = getString(settings, PlatformKeys.KEY_CDMA_MAST_SEGMENT, PlatformDefaults.DEFAULT_CDMA_MAST_SEGMENT);
    final Short batchNumber = getShort(settings, PlatformKeys.KEY_CDMA_BATCH_NUMBER, PlatformDefaults.DEFAULT_CDMA_BATCH_NUMBER);
    final CdmaSettings cdmaSettings = mastSegment == null && batchNumber == null ? null : new CdmaSettings(mastSegment, batchNumber);
    device.updateCdmaSettings(cdmaSettings);
    return device;
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) UnknownHostException(java.net.UnknownHostException) DeviceLifecycleStatus(org.opensmartgridplatform.domain.core.valueobjects.DeviceLifecycleStatus) InetAddress(java.net.InetAddress) Address(org.opensmartgridplatform.domain.core.valueobjects.Address) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) CdmaSettings(org.opensmartgridplatform.domain.core.valueobjects.CdmaSettings) InetAddress(java.net.InetAddress) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates) ReadSettingsHelper.getShort(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getShort)

Example 3 with GpsCoordinates

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

the class LmdConverter method convertTo.

@Override
public LightMeasurementDevice convertTo(final org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice source, final Type<LightMeasurementDevice> destinationType, final MappingContext mappingContext) {
    final LightMeasurementDevice lmd = new LightMeasurementDevice();
    final String deviceIdentification = source.getDeviceIdentification();
    lmd.setDeviceUid(Base64.encodeBase64String(deviceIdentification.getBytes(StandardCharsets.US_ASCII)));
    lmd.setDeviceIdentification(deviceIdentification);
    final Address containerAddress = source.getContainerAddress();
    if (containerAddress != null) {
        lmd.setContainerPostalCode(containerAddress.getPostalCode());
        lmd.setContainerCity(containerAddress.getCity());
        lmd.setContainerStreet(containerAddress.getStreet());
        if (containerAddress.getNumber() != null) {
            lmd.setContainerNumber(containerAddress.getNumber().toString());
        }
    }
    final GpsCoordinates gpsCoordinates = source.getGpsCoordinates();
    if (gpsCoordinates != null) {
        lmd.setGpsLatitude(gpsCoordinates.getLatitude());
        lmd.setGpsLongitude(gpsCoordinates.getLongitude());
    }
    lmd.setDeviceType(source.getDeviceType());
    lmd.setActivated(source.isActivated());
    lmd.setDescription(source.getDescription());
    lmd.setCode(source.getCode());
    lmd.setColor(source.getColor());
    lmd.setDigitalInput(source.getDigitalInput());
    return lmd;
}
Also used : Address(org.opensmartgridplatform.domain.core.valueobjects.Address) LightMeasurementDevice(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightMeasurementDevice) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates)

Example 4 with GpsCoordinates

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

the class DeviceInstallationMapperTest method createSsld.

private Ssld createSsld() {
    final Address containerAddress = this.createAddress();
    final GpsCoordinates gps = new GpsCoordinates(GPS_LATITUDE, GPS_LONGITUDE);
    final Ssld ssld = new Ssld(DEVICE_IDENTIFICATION, ALIAS, containerAddress, gps, null);
    ssld.setPublicKeyPresent(PUBLIC_KEY_PRESENT);
    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)

Example 5 with GpsCoordinates

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

the class GpsCoordinatesMapper method mapAtoB.

@Override
public void mapAtoB(final UpdatedDevice source, final Ssld destination, final MappingContext context) {
    if (StringUtils.isNotEmpty(source.getGpsLatitude()) && StringUtils.isNotEmpty(source.getGpsLongitude())) {
        final Float latitude = Float.valueOf(source.getGpsLatitude());
        final Float longitude = Float.valueOf(source.getGpsLongitude());
        destination.setGpsCoordinates(new GpsCoordinates(latitude, longitude));
    }
}
Also used : GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates)

Aggregations

GpsCoordinates (org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates)21 Address (org.opensmartgridplatform.domain.core.valueobjects.Address)20 InetAddress (java.net.InetAddress)5 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)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 Test (org.junit.jupiter.api.Test)3 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)3 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)3 Given (io.cucumber.java.en.Given)2 UnknownHostException (java.net.UnknownHostException)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 DeviceModel (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceModel)2 LightMeasurementDevice (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightMeasurementDevice)2 Ssld (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Ssld)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1