Search in sources :

Example 1 with EventType

use of org.opensmartgridplatform.domain.core.valueobjects.EventType in project open-smart-grid-platform by OSGP.

the class RetrieveReceivedEventNotifications method allEvents.

/**
 * There are 47 events enumerated by {@link
 * org.opensmartgridplatform.domain.core.valueobjects.EventType}. This step will create an event
 * record for every event type.
 */
@Given("^all events are present for device$")
public void allEvents(final Map<String, String> data) {
    final String deviceIdentification = getString(data, PlatformKeys.KEY_DEVICE_IDENTIFICATION);
    for (final EventType eventType : EventType.values()) {
        final Event event = new Event(deviceIdentification, getDateTime(PlatformDefaults.TIMESTAMP).toDate(), eventType, PlatformDefaults.DEFAULT_EVENT_DESCRIPTION, PlatformDefaults.DEFAULT_INDEX);
        this.eventRepository.save(event);
    }
}
Also used : EventType(org.opensmartgridplatform.domain.core.valueobjects.EventType) Event(org.opensmartgridplatform.domain.core.entities.Event) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) Given(io.cucumber.java.en.Given)

Example 2 with EventType

use of org.opensmartgridplatform.domain.core.valueobjects.EventType in project open-smart-grid-platform by OSGP.

the class EventNotificationMessageService method createRelayStatus.

private void createRelayStatus(final Device device, final Event switchingEvent, final Integer relayIndex, final Map<Integer, RelayStatus> lastRelayStatusPerIndex) {
    final EventType eventType = switchingEvent.getEventType();
    final boolean isRelayOn = EventType.LIGHT_EVENTS_LIGHT_ON.equals(eventType) || EventType.TARIFF_EVENTS_TARIFF_ON.equals(eventType);
    if (lastRelayStatusPerIndex.get(relayIndex) == null || switchingEvent.getDateTime().after(lastRelayStatusPerIndex.get(relayIndex).getLastSwitchingEventTime())) {
        final RelayStatus relayStatus = new RelayStatus.Builder(device, relayIndex).withLastSwitchingEventState(isRelayOn, switchingEvent.getDateTime()).build();
        lastRelayStatusPerIndex.put(relayIndex, relayStatus);
    }
}
Also used : RelayStatus(org.opensmartgridplatform.domain.core.entities.RelayStatus) EventType(org.opensmartgridplatform.domain.core.valueobjects.EventType)

Example 3 with EventType

use of org.opensmartgridplatform.domain.core.valueobjects.EventType 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 4 with EventType

use of org.opensmartgridplatform.domain.core.valueobjects.EventType in project open-smart-grid-platform by OSGP.

the class EventNotificationMessageService method handleEvent.

public void handleEvent(final String deviceIdentification, final EventNotificationDto event) throws UnknownEntityException {
    LOGGER.info("handleEvent() called for device: {} with event: {}", deviceIdentification, event);
    final Date dateTime = event.getDateTime() != null ? event.getDateTime().toDate() : DateTime.now().toDate();
    final EventType eventType = EventType.valueOf(event.getEventType().name());
    final String description = event.getDescription();
    final Integer index = event.getIndex();
    this.handleEvent(deviceIdentification, dateTime, eventType, description, index);
}
Also used : EventType(org.opensmartgridplatform.domain.core.valueobjects.EventType) Date(java.util.Date)

Example 5 with EventType

use of org.opensmartgridplatform.domain.core.valueobjects.EventType 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)

Aggregations

EventType (org.opensmartgridplatform.domain.core.valueobjects.EventType)7 Event (org.opensmartgridplatform.domain.core.entities.Event)4 Given (io.cucumber.java.en.Given)2 Date (java.util.Date)2 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)2 EventNotificationDto (org.opensmartgridplatform.dto.valueobjects.EventNotificationDto)2 Then (io.cucumber.java.en.Then)1 ArrayList (java.util.ArrayList)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1 DateTime (org.joda.time.DateTime)1 ReadSettingsHelper.getInteger (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getInteger)1 Device (org.opensmartgridplatform.domain.core.entities.Device)1 RelayStatus (org.opensmartgridplatform.domain.core.entities.RelayStatus)1