use of org.opensmartgridplatform.dto.valueobjects.EventNotificationDto in project open-smart-grid-platform by OSGP.
the class EventNotificationMessageService method handleEvents.
public void handleEvents(final String deviceIdentification, final List<EventNotificationDto> eventNotifications) throws UnknownEntityException {
LOGGER.info("handleEvents() called for device: {} with eventNotifications.size(): {}", deviceIdentification, eventNotifications.size());
for (final EventNotificationDto event : eventNotifications) {
LOGGER.info(" event: {}", event);
}
final Device device = this.eventNotificationHelperService.findDevice(deviceIdentification);
/*
* A list of bundled events may contain events that occurred over a
* period of time (and as such may contain multiple switching events per
* relay). Handling light switching events, only update the relay status
* once for the last switching in the list.
*/
final List<Event> switchDeviceEvents = new ArrayList<>();
for (final EventNotificationDto eventNotification : eventNotifications) {
final DateTime eventTime = eventNotification.getDateTime();
final EventType eventType = EventType.valueOf(eventNotification.getEventType().name());
final Event event = new Event(deviceIdentification, eventTime != null ? eventTime.toDate() : DateTime.now().toDate(), eventType, eventNotification.getDescription(), eventNotification.getIndex());
LOGGER.info("Saving event for device: {} with eventType: {} eventTime: {} description: {} index: {}", deviceIdentification, eventType.name(), eventTime, eventNotification.getDescription(), eventNotification.getIndex());
this.eventNotificationHelperService.saveEvent(event);
if (this.isSwitchingEvent(eventType)) {
switchDeviceEvents.add(event);
} else if (this.isLightMeasurementEvent(eventType)) {
this.handleLightMeasurementDeviceEvents(deviceIdentification, eventNotifications);
}
}
this.handleSwitchDeviceEvents(device, switchDeviceEvents);
}
use of org.opensmartgridplatform.dto.valueobjects.EventNotificationDto in project open-smart-grid-platform by OSGP.
the class EventNotificationMessageService method handleLightMeasurementDeviceEvents.
private void handleLightMeasurementDeviceEvents(final String deviceIdentification, final List<EventNotificationDto> eventNotifications) {
if (eventNotifications.size() != 1) {
throw new NotImplementedException("Only lists containing exactly one light event are supported as bundled events.");
}
final EventNotificationDto event = eventNotifications.get(0);
final EventType eventType = EventType.valueOf(event.getEventType().toString());
this.handleLightMeasurementDeviceEvent(deviceIdentification, event.getDateTime().toDate(), eventType, event.getDescription(), event.getIndex());
}
use of org.opensmartgridplatform.dto.valueobjects.EventNotificationDto in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method createEventNotificationDto.
// === ADD EVENT NOTIFICATION ===
/**
* Create a new event notification DTO with the given arguments.
*
* @param deviceIdentification 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, "event type must not be null");
Assert.notNull(description, "description must not be null");
Assert.notNull(index, "index must not be null");
LOGGER.info("addEventNotification called for device: {} with eventType: {}, description: {} and timestamp: {}", deviceIdentification, eventType, description, timestamp);
// Convert timestamp to DateTime.
final 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);
}
use of org.opensmartgridplatform.dto.valueobjects.EventNotificationDto 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.dto.valueobjects.EventNotificationDto in project open-smart-grid-platform by OSGP.
the class Iec61850ClientLMDEventListener method newReport.
@Override
public void newReport(final Report report) {
final DateTime timeOfEntry = this.getTimeOfEntry(report);
final String reportDescription = this.getReportDescription(report, timeOfEntry);
this.logger.info("newReport for {}", reportDescription);
if (Boolean.TRUE.equals(report.getBufOvfl())) {
this.logger.warn("Buffer Overflow reported for {} - entries within the buffer may have been lost.", reportDescription);
}
if (this.firstNewSqNum != null && report.getSqNum() != null && report.getSqNum() < this.firstNewSqNum) {
this.logger.warn("report.getSqNum() < this.firstNewSqNum, report.getSqNum() = {}, this.firstNewSqNum = {}", report.getSqNum(), this.firstNewSqNum);
}
this.logReportDetails(report);
if (CollectionUtils.isEmpty(report.getValues())) {
this.logger.warn("No dataSet members available for {}", reportDescription);
return;
}
final Map<LightMeasurementDevice, FcModelNode> reportMemberPerDevice = this.processReportedDataForLightMeasurementDevices(report.getValues());
for (final LightMeasurementDevice lmd : reportMemberPerDevice.keySet()) {
final String deviceIdentification = lmd.getDeviceIdentification();
final Short index = lmd.getDigitalInput();
final FcModelNode member = reportMemberPerDevice.get(lmd);
final EventNotificationDto eventNotification = this.getEventNotificationForReportedData(member, timeOfEntry, reportDescription, deviceIdentification, index.intValue());
try {
this.deviceManagementService.addEventNotifications(deviceIdentification, Arrays.asList(eventNotification));
} catch (final ProtocolAdapterException pae) {
this.logger.error("Error adding device notifications for device: " + deviceIdentification, pae);
}
}
}
Aggregations