Search in sources :

Example 1 with EventNotificationDto

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);
}
Also used : EventType(org.opensmartgridplatform.domain.core.valueobjects.EventType) Device(org.opensmartgridplatform.domain.core.entities.Device) ArrayList(java.util.ArrayList) EventNotificationDto(org.opensmartgridplatform.dto.valueobjects.EventNotificationDto) Event(org.opensmartgridplatform.domain.core.entities.Event) DateTime(org.joda.time.DateTime)

Example 2 with EventNotificationDto

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());
}
Also used : EventType(org.opensmartgridplatform.domain.core.valueobjects.EventType) NotImplementedException(org.apache.commons.lang3.NotImplementedException) EventNotificationDto(org.opensmartgridplatform.dto.valueobjects.EventNotificationDto)

Example 3 with EventNotificationDto

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);
}
Also used : EventNotificationDto(org.opensmartgridplatform.dto.valueobjects.EventNotificationDto) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime)

Example 4 with EventNotificationDto

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());
}
Also used : RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) ArrayList(java.util.ArrayList) EventNotificationDto(org.opensmartgridplatform.dto.valueobjects.EventNotificationDto) Oslp(org.opensmartgridplatform.oslp.Oslp) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) OslpDevice(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice)

Example 5 with EventNotificationDto

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);
        }
    }
}
Also used : LightMeasurementDevice(org.opensmartgridplatform.core.db.api.iec61850.entities.LightMeasurementDevice) FcModelNode(com.beanit.openiec61850.FcModelNode) EventNotificationDto(org.opensmartgridplatform.dto.valueobjects.EventNotificationDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) DateTime(org.joda.time.DateTime)

Aggregations

EventNotificationDto (org.opensmartgridplatform.dto.valueobjects.EventNotificationDto)11 DateTime (org.joda.time.DateTime)6 EventTypeDto (org.opensmartgridplatform.dto.valueobjects.EventTypeDto)4 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)4 ArrayList (java.util.ArrayList)2 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)2 EventType (org.opensmartgridplatform.domain.core.valueobjects.EventType)2 BdaVisibleString (com.beanit.openiec61850.BdaVisibleString)1 FcModelNode (com.beanit.openiec61850.FcModelNode)1 Then (io.cucumber.java.en.Then)1 Serializable (java.io.Serializable)1 List (java.util.List)1 JMSException (javax.jms.JMSException)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1 Test (org.junit.jupiter.api.Test)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1 OslpDevice (org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice)1 LightMeasurementDevice (org.opensmartgridplatform.core.db.api.iec61850.entities.LightMeasurementDevice)1 Device (org.opensmartgridplatform.domain.core.entities.Device)1 Event (org.opensmartgridplatform.domain.core.entities.Event)1