Search in sources :

Example 1 with EventNotificationDto

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);
    }
}
Also used : EventNotificationDto(com.alliander.osgp.dto.valueobjects.EventNotificationDto) BdaVisibleString(org.openmuc.openiec61850.BdaVisibleString) DateTime(org.joda.time.DateTime) EventTypeDto(com.alliander.osgp.dto.valueobjects.EventTypeDto)

Example 2 with EventNotificationDto

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

Example 3 with EventNotificationDto

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

Aggregations

EventNotificationDto (com.alliander.osgp.dto.valueobjects.EventNotificationDto)3 DateTime (org.joda.time.DateTime)2 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)2 OslpDevice (com.alliander.osgp.adapter.protocol.oslp.elster.domain.entities.OslpDevice)1 EventTypeDto (com.alliander.osgp.dto.valueobjects.EventTypeDto)1 Oslp (com.alliander.osgp.oslp.Oslp)1 RequestMessage (com.alliander.osgp.shared.infra.jms.RequestMessage)1 ArrayList (java.util.ArrayList)1 BdaVisibleString (org.openmuc.openiec61850.BdaVisibleString)1