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);
}
}
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);
}
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());
}
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);
}
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;
}
Aggregations