use of com.alliander.osgp.dto.valueobjects.EventNotificationDto in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850ClientSSLDEventListener method addEventNotificationForReportedData.
private void addEventNotificationForReportedData(final FcModelNode evnRpn, final DateTime timeOfEntry, final String reportDescription) throws ProtocolAdapterException {
final EventTypeDto eventType = this.determineEventType(evnRpn, reportDescription);
final Integer index = this.determineRelayIndex(evnRpn, reportDescription);
final String description = this.determineDescription(evnRpn);
final DateTime dateTime = this.determineDateTime(evnRpn, timeOfEntry);
final EventNotificationDto eventNotification = new EventNotificationDto(this.deviceIdentification, dateTime, eventType, description, index);
synchronized (this.eventNotifications) {
this.eventNotifications.add(eventNotification);
}
}
use of com.alliander.osgp.dto.valueobjects.EventNotificationDto 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.dto.valueobjects.EventNotificationDto in project Protocol-Adapter-OSLP by OSGP.
the class DeviceManagementService method createEventNotificationDto.
// === ADD EVENT NOTIFICATION ===
/**
* Create a new event notification DTO with the given arguments.
*
* @param deviceIdentitication
* The identification of the device.
* @param deviceUid
* The UID of the device.
* @param eventType
* The event type. May not be empty or null.
* @param description
* The description which came along with the event from the
* device. May be an empty string, but not null.
* @param index
* The index of the relay. May not be null.
* @param timestamp
* The date and time of the event. May be an empty string or
* null.
*/
private EventNotificationDto createEventNotificationDto(final String deviceIdentification, final String deviceUid, final String eventType, final String description, final Integer index, final String timestamp) {
Assert.notNull(eventType);
Assert.notNull(description);
Assert.notNull(index);
LOGGER.info("addEventNotification called for device: {} with eventType: {}, description: {} and timestamp: {}", deviceIdentification, eventType, description, timestamp);
// Convert timestamp to DateTime.
DateTime dateTime;
if (StringUtils.isEmpty(timestamp)) {
dateTime = DateTime.now();
LOGGER.info("timestamp is empty, using DateTime.now(): {}", dateTime);
} else {
final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyyMMddHHmmss Z");
dateTime = dateTimeFormatter.withOffsetParsed().parseDateTime(timestamp.concat(" +0000"));
LOGGER.info("parsed timestamp from string: {} to DateTime: {}", timestamp, dateTime);
}
return new EventNotificationDto(deviceUid, dateTime, EventTypeDto.valueOf(eventType), description, index);
}
Aggregations