use of org.opensmartgridplatform.domain.core.entities.Event in project open-smart-grid-platform by OSGP.
the class RetrieveReceivedEventNotifications method theStoredEventsAreRetrieved.
@Then("^the stored events from \"([^\"]*)\" are retrieved and contain$")
public void theStoredEventsAreRetrieved(final String deviceIdentification, final Map<String, String> expectedResponse) throws Throwable {
final List<Event> events = Wait.untilAndReturn(() -> {
final List<Event> retval = this.retrieveStoredEvents(deviceIdentification);
assertThat(retval).isNotNull();
assertThat(retval.size() > 0).isTrue();
return retval;
});
for (final Event e : events) {
assertThat(e.getEventType()).isEqualTo(getEnum(expectedResponse, PlatformKeys.EVENT_TYPE, EventType.class));
assertThat(e.getDescription()).isEqualTo(getString(expectedResponse, PlatformKeys.KEY_DESCRIPTION));
assertThat((int) e.getIndex()).isEqualTo((int) getInteger(expectedResponse, PlatformKeys.KEY_INDEX, PlatformDefaults.DEFAULT_INDEX));
}
}
use of org.opensmartgridplatform.domain.core.entities.Event 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.entities.Event in project open-smart-grid-platform by OSGP.
the class TransactionalEventServiceTest method mockSliceOfEvents.
private Slice<Event> mockSliceOfEvents(final int numberOfEvents) {
final Date oneMonthAgo = DateTime.now().minusMonths(1).toDate();
final List<Event> events = new ArrayList<>();
for (int i = 0; i < numberOfEvents; i++) {
final Event event = new Event("test", oneMonthAgo, EventType.DIAG_EVENTS_GENERAL, "description", 1);
events.add(event);
}
return new SliceImpl<>(events);
}
use of org.opensmartgridplatform.domain.core.entities.Event in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method removeDevice.
// === REMOVE DEVICE ===
/**
* Removes a device.
*
* @param organisationIdentification The organisation identification who performs the action
* @param deviceIdentification The device identification of the device
* @throws FunctionalException In case the device or organisation can not be found or the
* organisation is not allowed to perform this action.
*/
public void removeDevice(@Identification final String organisationIdentification, @Identification final String deviceIdentification) throws FunctionalException {
final Organisation organisation = this.findOrganisation(organisationIdentification);
final Device device = this.findDevice(deviceIdentification);
this.isAllowed(organisation, device, DeviceFunction.REMOVE_DEVICE);
// First remove all authorizations
final List<DeviceAuthorization> authorisations = this.authorizationRepository.findByDevice(device);
for (final DeviceAuthorization authorisation : authorisations) {
this.authorizationRepository.delete(authorisation);
}
// Remove all events
final List<Event> events = this.eventRepository.findByDeviceIdentification(deviceIdentification);
for (final Event event : events) {
this.eventRepository.delete(event);
}
// Then remove the device.
this.deviceRepository.delete(device);
}
use of org.opensmartgridplatform.domain.core.entities.Event 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);
}
Aggregations