Search in sources :

Example 1 with Event

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));
    }
}
Also used : EventType(org.opensmartgridplatform.domain.core.valueobjects.EventType) Event(org.opensmartgridplatform.domain.core.entities.Event) Then(io.cucumber.java.en.Then)

Example 2 with Event

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);
    }
}
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 3 with 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);
}
Also used : ArrayList(java.util.ArrayList) Event(org.opensmartgridplatform.domain.core.entities.Event) SliceImpl(org.springframework.data.domain.SliceImpl) Date(java.util.Date)

Example 4 with Event

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);
}
Also used : Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) Event(org.opensmartgridplatform.domain.core.entities.Event)

Example 5 with Event

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

Aggregations

Event (org.opensmartgridplatform.domain.core.entities.Event)21 EventType (org.opensmartgridplatform.domain.core.valueobjects.EventType)6 Then (io.cucumber.java.en.Then)5 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 DateTime (org.joda.time.DateTime)4 Device (org.opensmartgridplatform.domain.core.entities.Device)4 PageRequest (org.springframework.data.domain.PageRequest)4 Given (io.cucumber.java.en.Given)3 Test (org.junit.jupiter.api.Test)3 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)3 ReadSettingsHelper.getInteger (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getInteger)2 RelayStatus (org.opensmartgridplatform.domain.core.entities.RelayStatus)2 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)2 File (java.io.File)1 IOException (java.io.IOException)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1