Search in sources :

Example 1 with OslpDevice

use of org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project open-smart-grid-platform by OSGP.

the class OslpDeviceSteps method anSsldOslpDevice.

@Given("^an ssld oslp device$")
public void anSsldOslpDevice(final Map<String, String> settings) {
    // First create the device itself in the OSGP core database
    this.ssldDeviceSteps.anSsldDevice(settings);
    // Now create the OSLP device in the OSLP database
    final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION);
    final OslpDevice device = new OslpDevice(getString(settings, PlatformKeys.KEY_DEVICE_UID, DEFAULT_DEVICE_UID), deviceIdentification, getString(settings, PlatformKeys.KEY_DEVICE_TYPE, PlatformDefaults.DEFAULT_DEVICE_TYPE));
    device.setSequenceNumber(0);
    device.setRandomDevice(0);
    device.setRandomPlatform(0);
    device.updatePublicKey(DEVICE_PUBLIC_KEY);
    this.oslpDeviceRepository.save(device);
}
Also used : ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) OslpDevice(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice) Given(io.cucumber.java.en.Given)

Example 2 with OslpDevice

use of org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project open-smart-grid-platform by OSGP.

the class OslpDeviceSteps method theSsldOslpDeviceContains.

@Then("^the ssld oslp device contains$")
public void theSsldOslpDeviceContains(final Map<String, String> expectedEntity) {
    Wait.until(() -> {
        final OslpDevice entity = this.oslpDeviceRepository.findByDeviceIdentification(getString(expectedEntity, PlatformKeys.KEY_DEVICE_IDENTIFICATION));
        assertThat(entity.getDeviceType()).isEqualTo(getString(expectedEntity, PlatformKeys.KEY_DEVICE_TYPE));
        assertThat(entity.getDeviceUid()).isEqualTo(getString(expectedEntity, PlatformKeys.KEY_DEVICE_UID));
    });
    this.ssldDeviceSteps.theSsldDeviceContains(expectedEntity);
}
Also used : OslpDevice(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice) Then(io.cucumber.java.en.Then)

Example 3 with OslpDevice

use of org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project open-smart-grid-platform by OSGP.

the class OslpChannelHandlerServer method handleRegisterDeviceRequest.

private Oslp.Message handleRegisterDeviceRequest(final byte[] deviceUid, final byte[] sequenceNumber, final Oslp.RegisterDeviceRequest registerRequest) throws UnknownHostException {
    final String deviceIdentification = registerRequest.getDeviceIdentification();
    final String deviceType = registerRequest.getDeviceType().toString();
    final boolean hasSchedule = registerRequest.getHasSchedule();
    final InetAddress inetAddress = this.getInetAddress(registerRequest, deviceIdentification);
    // Send message to OSGP-CORE to save IP Address, device type and has
    // schedule values in OSGP-CORE database.
    this.deviceRegistrationService.sendDeviceRegisterRequest(inetAddress, deviceType, hasSchedule, deviceIdentification);
    OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByDeviceIdentification(registerRequest.getDeviceIdentification());
    // Save the security related values in the OSLP database.
    oslpDevice.updateRegistrationData(deviceUid, registerRequest.getDeviceType().toString(), registerRequest.getRandomDevice());
    oslpDevice.setSequenceNumber(SequenceNumberUtils.convertByteArrayToInteger(sequenceNumber));
    oslpDevice = this.oslpDeviceSettingsService.updateDevice(oslpDevice);
    // Return current date and time in UTC so the device can sync the clock.
    final Oslp.RegisterDeviceResponse.Builder responseBuilder = Oslp.RegisterDeviceResponse.newBuilder().setStatus(Oslp.Status.OK).setCurrentTime(Instant.now().toString(format)).setRandomDevice(registerRequest.getRandomDevice()).setRandomPlatform(oslpDevice.getRandomPlatform());
    // Return local time zone information of the platform. Devices can use
    // this to convert UTC times to local times.
    final LocationInfo.Builder locationInfo = LocationInfo.newBuilder();
    locationInfo.setTimeOffset(this.timeZoneOffsetMinutes);
    // Get the GPS values from OSGP-CORE database.
    final GpsCoordinatesDto gpsCoordinates = this.deviceDataService.getGpsCoordinatesForDevice(deviceIdentification);
    if (gpsCoordinates != null && gpsCoordinates.getLatitude() != null && gpsCoordinates.getLongitude() != null) {
        // Add GPS information when available in meta data.
        locationInfo.setLatitude(this.convertGpsCoordinateFromFloatToInt(gpsCoordinates.getLatitude())).setLongitude(this.convertGpsCoordinateFromFloatToInt(gpsCoordinates.getLongitude()));
    } else {
        // Otherwise use default GPS information.
        locationInfo.setLatitude(this.convertGpsCoordinateFromFloatToInt(this.defaultLatitude)).setLongitude(this.convertGpsCoordinateFromFloatToInt(this.defaultLongitude));
    }
    responseBuilder.setLocationInfo(locationInfo);
    return Oslp.Message.newBuilder().setRegisterDeviceResponse(responseBuilder.build()).build();
}
Also used : GpsCoordinatesDto(org.opensmartgridplatform.dto.valueobjects.GpsCoordinatesDto) InetAddress(java.net.InetAddress) OslpDevice(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice) LocationInfo(org.opensmartgridplatform.oslp.Oslp.LocationInfo)

Example 4 with OslpDevice

use of org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project open-smart-grid-platform by OSGP.

the class OslpDeviceService method buildAndSignEnvelope.

private void buildAndSignEnvelope(final DeviceRequest deviceRequest, final Oslp.Message payloadMessage, final Serializable extraData) {
    final String deviceIdentification = deviceRequest.getDeviceIdentification();
    final String organisationIdentification = deviceRequest.getOrganisationIdentification();
    final String correlationUid = deviceRequest.getCorrelationUid();
    final String ipAddress = deviceRequest.getIpAddress();
    final String domain = deviceRequest.getDomain();
    final String domainVersion = deviceRequest.getDomainVersion();
    final String messageType = deviceRequest.getMessageType();
    final int messagePriority = deviceRequest.getMessagePriority();
    final int retryCount = deviceRequest.getRetryCount();
    final boolean isScheduled = deviceRequest.isScheduled();
    // Get some values from the database.
    final OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByDeviceIdentification(deviceIdentification);
    if (oslpDevice == null) {
        LOGGER.error("Unable to find OSLP device: {}", deviceIdentification);
        return;
    }
    final byte[] deviceId = Base64.decodeBase64(oslpDevice.getDeviceUid());
    final byte[] sequenceNumber = SequenceNumberUtils.convertIntegerToByteArray(oslpDevice.getSequenceNumber());
    this.oslpSigningService.buildAndSignEnvelope(organisationIdentification, deviceIdentification, correlationUid, deviceId, sequenceNumber, ipAddress, domain, domainVersion, messageType, messagePriority, retryCount, isScheduled, payloadMessage, extraData);
}
Also used : ByteString(com.google.protobuf.ByteString) OslpDevice(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice)

Example 5 with OslpDevice

use of org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project open-smart-grid-platform by OSGP.

the class OslpDeviceService method updateSequenceNumber.

private void updateSequenceNumber(final String deviceIdentification, final OslpEnvelope oslpResponse) {
    final Integer sequenceNumber = SequenceNumberUtils.convertByteArrayToInteger(oslpResponse.getSequenceNumber());
    final OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByDeviceIdentification(deviceIdentification);
    oslpDevice.setSequenceNumber(sequenceNumber);
    this.oslpDeviceSettingsService.updateDeviceAndForceSave(oslpDevice);
}
Also used : OslpDevice(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice)

Aggregations

OslpDevice (org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice)18 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException)3 ByteString (com.google.protobuf.ByteString)2 Given (io.cucumber.java.en.Given)2 OslpLogItemRequestMessage (org.opensmartgridplatform.adapter.protocol.oslp.elster.infra.messaging.OslpLogItemRequestMessage)2 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)2 Oslp (org.opensmartgridplatform.oslp.Oslp)2 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)2 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)2 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)2 Then (io.cucumber.java.en.Then)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 PublicKey (java.security.PublicKey)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1 PendingSetScheduleRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.PendingSetScheduleRequest)1 EventNotificationDto (org.opensmartgridplatform.dto.valueobjects.EventNotificationDto)1 GpsCoordinatesDto (org.opensmartgridplatform.dto.valueobjects.GpsCoordinatesDto)1