Search in sources :

Example 11 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 theDeviceSendsAConfirmRegisterDeviceRequestToThePlatform.

@Given("^the device sends a confirm register device request to the platform over \"([^\"]*)\"$")
public void theDeviceSendsAConfirmRegisterDeviceRequestToThePlatform(final String protocol, final Map<String, String> settings) throws DeviceSimulatorException {
    try {
        final String deviceIdentification = getString(settings, PlatformPubliclightingKeys.KEY_DEVICE_IDENTIFICATION, PlatformPubliclightingDefaults.DEFAULT_DEVICE_IDENTIFICATION);
        final String deviceUid = getString(settings, PlatformPubliclightingKeys.KEY_DEVICE_UID, PlatformPubliclightingDefaults.DEVICE_UID);
        final OslpDevice oslpDevice = this.oslpDeviceRepository.findByDeviceIdentification(deviceIdentification);
        final int randomDevice = oslpDevice.getRandomDevice();
        final int randomPlatform = oslpDevice.getRandomPlatform();
        final Oslp.ConfirmRegisterDeviceRequest confirmRegisterDeviceRequest = Oslp.ConfirmRegisterDeviceRequest.newBuilder().setRandomDevice(randomDevice).setRandomPlatform(randomPlatform).build();
        final Message message = Message.newBuilder().setConfirmRegisterDeviceRequest(confirmRegisterDeviceRequest).build();
        this.oslpMockServer.incrementSequenceNumber(this.getDeviceUid(settings));
        final OslpEnvelope request = this.createEnvelopeBuilder(deviceUid, this.oslpMockServer.getSequenceNumber(this.getDeviceUid(settings))).withPayloadMessage(message).build();
        this.send(request, settings);
    } catch (final IOException | IllegalArgumentException e) {
        ScenarioContext.current().put("Error", e);
    }
}
Also used : Message(org.opensmartgridplatform.oslp.Oslp.Message) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) Oslp(org.opensmartgridplatform.oslp.Oslp) OslpDevice(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice) OslpEnvelope(org.opensmartgridplatform.oslp.OslpEnvelope) Given(io.cucumber.java.en.Given)

Example 12 with OslpDevice

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

the class DeviceManagementService method revokeKey.

// === REVOKE KEY ===
public void revokeKey(final MessageMetadata messageMetadata, final DeviceResponseMessageSender responseMessageSender) {
    final String deviceIdentification = messageMetadata.getDeviceIdentification();
    final String organisationIdentification = messageMetadata.getOrganisationIdentification();
    LOGGER.info("revokeKey called for device: {} for organisation: {}", deviceIdentification, organisationIdentification);
    try {
        final OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByDeviceIdentification(deviceIdentification);
        if (oslpDevice == null) {
            throw new ProtocolAdapterException(String.format("Device not found: %s", deviceIdentification));
        }
        oslpDevice.revokePublicKey();
        this.oslpDeviceSettingsService.updateDevice(oslpDevice);
        this.sendResponseMessage(messageMetadata, ResponseMessageResultType.OK, null, responseMessageSender);
    } catch (final Exception e) {
        LOGGER.error("Unexpected exception during revokeKey", e);
        final TechnicalException ex = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while revoking key", e);
        this.sendResponseMessage(messageMetadata, ResponseMessageResultType.NOT_OK, ex, responseMessageSender);
    }
}
Also used : TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException) OslpDevice(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)

Example 13 with OslpDevice

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

the class LoggingService method getDeviceIdentification.

private String getDeviceIdentification(final String deviceUid) {
    String deviceIdentification = EMPTY;
    final OslpDevice oslpDevice = this.oslpDeviceRepository.findByDeviceUid(deviceUid);
    if (oslpDevice != null) {
        deviceIdentification = oslpDevice.getDeviceIdentification();
    }
    return deviceIdentification;
}
Also used : OslpDevice(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice)

Example 14 with OslpDevice

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

the class PublicLightingSetScheduleRequestMessageProcessor method handleSetScheduleSetRebootResponse.

private void handleSetScheduleSetRebootResponse(final SetScheduleDeviceRequest deviceRequest) {
    // The device will reboot now.
    // At this point we will need to save the current state to the
    // pending_set_schedule_request table
    LOGGER.info(LOG_MESSAGE_CALL_DEVICE_SERVICE, deviceRequest.getMessageType(), ScheduleMessageTypeDto.SET_SCHEDULE, deviceRequest.getDomain(), deviceRequest.getDomainVersion());
    final ScheduleMessageDataContainerDto dataContainer = new ScheduleMessageDataContainerDto.Builder(deviceRequest.getScheduleMessageDataContainer().getSchedule()).withScheduleMessageType(ScheduleMessageTypeDto.SET_SCHEDULE).build();
    final String deviceIdentification = deviceRequest.getDeviceIdentification();
    final OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByDeviceIdentification(deviceIdentification);
    final String deviceUid = oslpDevice.getDeviceUid();
    final Date expireDateTime = Date.from(ZonedDateTime.now().plusMinutes(this.pendingSetScheduleRequestExpiresInMinutes).toInstant());
    final PendingSetScheduleRequest pendingSetScheduleRequest = PendingSetScheduleRequest.builder().deviceIdentification(deviceIdentification).deviceUid(deviceUid).scheduleMessageDataContainerDto(dataContainer).deviceRequest(deviceRequest).expiredAt(expireDateTime).build();
    this.pendingSetScheduleRequestService.add(pendingSetScheduleRequest);
}
Also used : PendingSetScheduleRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.PendingSetScheduleRequest) ScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto) OslpDevice(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice) Date(java.util.Date)

Example 15 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 saveOslpResponseLogEntry.

private void saveOslpResponseLogEntry(final DeviceRequest deviceRequest, final OslpEnvelope oslpResponse) {
    final OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByDeviceIdentification(deviceRequest.getDeviceIdentification());
    final OslpLogItemRequestMessage oslpLogItemRequestMessage = new OslpLogItemRequestMessage(deviceRequest.getOrganisationIdentification(), oslpDevice.getDeviceUid(), deviceRequest.getDeviceIdentification(), true, oslpResponse.isValid(), oslpResponse.getPayloadMessage(), oslpResponse.getSize());
    this.oslpLogItemRequestMessageSender.send(oslpLogItemRequestMessage);
}
Also used : OslpLogItemRequestMessage(org.opensmartgridplatform.adapter.protocol.oslp.elster.infra.messaging.OslpLogItemRequestMessage) 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