Search in sources :

Example 6 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 addEventNotifications.

/**
 * Send a list of event notifications to OSGP Core.
 *
 * @param deviceUid The identification of the device.
 * @param eventNotifications The event notifications.
 */
public void addEventNotifications(final String deviceUid, final List<Oslp.EventNotification> eventNotifications) {
    LOGGER.info("addEventNotifications called for device {}", deviceUid);
    final OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByUid(deviceUid);
    final String deviceIdentification = oslpDevice.getDeviceIdentification();
    final List<EventNotificationDto> eventNotificationDtos = new ArrayList<>();
    for (final Oslp.EventNotification eventNotification : eventNotifications) {
        final String eventType = eventNotification.getEvent().name();
        final String description = eventNotification.getDescription();
        final int index = eventNotification.getIndex().isEmpty() ? 0 : (int) eventNotification.getIndex().byteAt(0);
        String timestamp = eventNotification.getTimestamp();
        LOGGER.debug("-->> timestamp: {}", timestamp);
        // illegal timestamp value of 20000000xxxxxx.
        if (!StringUtils.isEmpty(timestamp) && timestamp.startsWith("20000000")) {
            final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyyMMddHHmmss");
            timestamp = DateTime.now().withZone(DateTimeZone.UTC).toString(dateTimeFormatter);
            LOGGER.info("Using DateTime.now() instead of '20000000xxxxxx', value is: {}", timestamp);
        }
        final EventNotificationDto dto = this.createEventNotificationDto(deviceIdentification, deviceUid, eventType, description, index, timestamp);
        eventNotificationDtos.add(dto);
    }
    final RequestMessage requestMessage = new RequestMessage("no-correlationUid", "no-organisation", deviceIdentification, new ArrayList<>(eventNotificationDtos));
    this.osgpRequestMessageSender.send(requestMessage, MessageType.EVENT_NOTIFICATION.name());
}
Also used : RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) ArrayList(java.util.ArrayList) EventNotificationDto(org.opensmartgridplatform.dto.valueobjects.EventNotificationDto) Oslp(org.opensmartgridplatform.oslp.Oslp) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) OslpDevice(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice)

Example 7 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 updateKey.

// === UPDATE KEY ===
public void updateKey(final MessageMetadata messageMetadata, final DeviceResponseMessageSender responseMessageSender, final String publicKey) {
    final String deviceIdentification = messageMetadata.getDeviceIdentification();
    final String organisationIdentification = messageMetadata.getOrganisationIdentification();
    LOGGER.info("updateKey called for device: {} for organisation: {} with new publicKey: {}", deviceIdentification, organisationIdentification, publicKey);
    try {
        OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByDeviceIdentification(deviceIdentification);
        if (oslpDevice == null) {
            // Device not found, create new device
            LOGGER.debug("Device [{}] does not exist, creating new device", deviceIdentification);
            oslpDevice = new OslpDevice(deviceIdentification);
            oslpDevice = this.oslpDeviceSettingsService.addDevice(oslpDevice);
        }
        oslpDevice.updatePublicKey(publicKey);
        this.oslpDeviceSettingsService.updateDevice(oslpDevice);
        this.sendResponseMessage(messageMetadata, ResponseMessageResultType.OK, null, responseMessageSender);
    } catch (final Exception e) {
        LOGGER.error("Unexpected exception during updateKey", e);
        final TechnicalException ex = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while updating key", e);
        this.sendResponseMessage(messageMetadata, ResponseMessageResultType.NOT_OK, ex, responseMessageSender);
    }
}
Also used : TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) 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 8 with OslpDevice

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

the class DeviceRegistrationService method updateDeviceSequenceNumber.

public void updateDeviceSequenceNumber(final byte[] deviceId, final int newSequenceNumber) throws ProtocolAdapterException {
    // Lookup device.
    final OslpDevice oslpDevice = this.findDevice(deviceId);
    this.checkSequenceNumber(oslpDevice.getSequenceNumber(), newSequenceNumber);
    // Persist the new sequence number.
    oslpDevice.setSequenceNumber(newSequenceNumber);
    this.oslpDeviceSettingsService.updateDevice(oslpDevice);
}
Also used : OslpDevice(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice)

Example 9 with OslpDevice

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

the class DeviceRegistrationService method findDevice.

public OslpDevice findDevice(final byte[] deviceId) throws ProtocolAdapterException {
    // Convert byte array to String.
    final String deviceUid = Base64.encodeBase64String(deviceId);
    final OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByUid(deviceUid);
    if (oslpDevice == null) {
        throw new ProtocolAdapterException("Unable to find device using deviceUid: " + deviceUid);
    }
    return oslpDevice;
}
Also used : ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException) OslpDevice(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice)

Example 10 with OslpDevice

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

the class DeviceRegistrationService method confirmRegisterDevice.

public void confirmRegisterDevice(final byte[] deviceId, final Integer newSequenceNumber, final Integer randomDevice, final Integer randomPlatform) throws ProtocolAdapterException {
    this.checkDeviceRandomAndPlatformRandom(deviceId, randomDevice, randomPlatform);
    this.updateDeviceSequenceNumber(deviceId, newSequenceNumber);
    final OslpDevice oslpDevice = this.findDevice(deviceId);
    final RequestMessage requestMessage = new RequestMessage(NO_CORRELATION_UID, NO_ORGANISATION, oslpDevice.getDeviceIdentification());
    this.osgpRequestMessageSender.send(requestMessage, MessageType.DEVICE_REGISTRATION_COMPLETED.name());
    LOGGER.debug("confirmRegisterDevice successful for device with UID: {}.", deviceId);
}
Also used : RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) 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