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);
}
}
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);
}
}
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);
}
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);
}
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());
}
Aggregations