Search in sources :

Example 6 with OslpDevice

use of com.alliander.osgp.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project Protocol-Adapter-OSLP by OSGP.

the class DeviceManagementService method updateKey.

// === UPDATE KEY ===
public void updateKey(final String organisationIdentification, final String deviceIdentification, final String correlationUid, final DeviceResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final String publicKey) {
    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(domain, domainVersion, messageType, correlationUid, organisationIdentification, deviceIdentification, 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(domain, domainVersion, messageType, correlationUid, organisationIdentification, deviceIdentification, ResponseMessageResultType.NOT_OK, ex, responseMessageSender);
    }
}
Also used : TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException) OslpDevice(com.alliander.osgp.adapter.protocol.oslp.elster.domain.entities.OslpDevice) OsgpException(com.alliander.osgp.shared.exceptionhandling.OsgpException) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException) TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException)

Example 7 with OslpDevice

use of com.alliander.osgp.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project Protocol-Adapter-OSLP 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(com.alliander.osgp.adapter.protocol.oslp.elster.domain.entities.OslpDevice)

Example 8 with OslpDevice

use of com.alliander.osgp.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project Protocol-Adapter-OSLP by OSGP.

the class DeviceManagementService method addEventNotifications.

/**
 * Send a list of event notifications to OSGP Core.
 *
 * @param deviceIdentification
 *            The identification of the device.
 * @param eventNotifications
 *            The event notifications.
 *
 * @throws ProtocolAdapterException
 *             In case the device can not be found in the database.
 */
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, DeviceFunctionDto.ADD_EVENT_NOTIFICATION.name());
}
Also used : RequestMessage(com.alliander.osgp.shared.infra.jms.RequestMessage) ArrayList(java.util.ArrayList) EventNotificationDto(com.alliander.osgp.dto.valueobjects.EventNotificationDto) Oslp(com.alliander.osgp.oslp.Oslp) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) OslpDevice(com.alliander.osgp.adapter.protocol.oslp.elster.domain.entities.OslpDevice)

Example 9 with OslpDevice

use of com.alliander.osgp.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project Protocol-Adapter-OSLP by OSGP.

the class DeviceRegistrationService method checkSequenceNumber.

public void checkSequenceNumber(final byte[] deviceId, final Integer newSequenceNumber) throws ProtocolAdapterException {
    // Lookup device.
    final OslpDevice oslpDevice = this.findDevice(deviceId);
    this.checkSequenceNumber(oslpDevice.getSequenceNumber(), newSequenceNumber);
}
Also used : OslpDevice(com.alliander.osgp.adapter.protocol.oslp.elster.domain.entities.OslpDevice)

Example 10 with OslpDevice

use of com.alliander.osgp.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project Protocol-Adapter-OSLP 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(com.alliander.osgp.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException) OslpDevice(com.alliander.osgp.adapter.protocol.oslp.elster.domain.entities.OslpDevice)

Aggregations

OslpDevice (com.alliander.osgp.adapter.protocol.oslp.elster.domain.entities.OslpDevice)13 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException)3 OslpLogItemRequestMessage (com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.OslpLogItemRequestMessage)3 OsgpException (com.alliander.osgp.shared.exceptionhandling.OsgpException)2 TechnicalException (com.alliander.osgp.shared.exceptionhandling.TechnicalException)2 EventNotificationDto (com.alliander.osgp.dto.valueobjects.EventNotificationDto)1 GpsCoordinatesDto (com.alliander.osgp.dto.valueobjects.GpsCoordinatesDto)1 Oslp (com.alliander.osgp.oslp.Oslp)1 LocationInfo (com.alliander.osgp.oslp.Oslp.LocationInfo)1 OslpEnvelope (com.alliander.osgp.oslp.OslpEnvelope)1 RequestMessage (com.alliander.osgp.shared.infra.jms.RequestMessage)1 ByteString (com.google.protobuf.ByteString)1 InetAddress (java.net.InetAddress)1 PublicKey (java.security.PublicKey)1 ArrayList (java.util.ArrayList)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1