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