Search in sources :

Example 1 with Notification

use of org.opensmartgridplatform.adapter.ws.schema.core.notification.Notification in project open-smart-grid-platform by OSGP.

the class NotificationSteps method waitForNotification.

protected Notification waitForNotification(final NotificationType notificationType) {
    final int nextWait = this.getNextWait();
    final Notification notification = this.coreNotificationService.getNotification(notificationType, nextWait, TimeUnit.MILLISECONDS);
    if (notification == null) {
        throw new AssertionError("Did not receive a notification for notification type: " + notificationType + " within " + nextWait + " milliseconds");
    }
    return notification;
}
Also used : Notification(org.opensmartgridplatform.adapter.ws.schema.core.notification.Notification)

Example 2 with Notification

use of org.opensmartgridplatform.adapter.ws.schema.core.notification.Notification in project open-smart-grid-platform by OSGP.

the class NotificationSteps method waitForNotification.

protected void waitForNotification(final String correlationUid) {
    final int nextWait = this.getNextWait();
    LOGGER.info("Waiting for a notification for correlation UID {} for at most {} milliseconds.", correlationUid, nextWait);
    final Notification notification = this.coreNotificationService.getNotification(correlationUid, nextWait, TimeUnit.MILLISECONDS);
    if (notification == null) {
        throw new AssertionError("Did not receive a notification for correlation UID: " + correlationUid + " within " + nextWait + " milliseconds");
    }
}
Also used : Notification(org.opensmartgridplatform.adapter.ws.schema.core.notification.Notification)

Example 3 with Notification

use of org.opensmartgridplatform.adapter.ws.schema.core.notification.Notification in project open-smart-grid-platform by OSGP.

the class CoreNotificationSteps method waitForNotification.

private void waitForNotification(final int maxTimeOut, final boolean expectNotification) {
    final String correlationUid = (String) ScenarioContext.current().get(PlatformKeys.KEY_CORRELATION_UID);
    if (correlationUid == null) {
        Assertions.fail("No " + PlatformKeys.KEY_CORRELATION_UID + " stored in the scenario context. Unable to make assumptions as to whether a notification has been sent in ws-core.");
    }
    LOGGER.info("Waiting to make sure {} notification is received for correlation UID {} for at most {} milliseconds.", expectNotification ? "a" : "no", correlationUid, maxTimeOut);
    final Notification notification = this.coreNotificationService.getNotification(correlationUid, maxTimeOut, TimeUnit.MILLISECONDS);
    if (expectNotification && notification == null) {
        Assertions.fail("Did not receive a notification for correlation UID: " + correlationUid + " within " + maxTimeOut + " milliseconds");
    }
    if (!expectNotification && notification != null) {
        Assertions.fail("Received notification for correlation UID: " + correlationUid);
    }
}
Also used : Notification(org.opensmartgridplatform.adapter.ws.schema.core.notification.Notification)

Example 4 with Notification

use of org.opensmartgridplatform.adapter.ws.schema.core.notification.Notification in project open-smart-grid-platform by OSGP.

the class AdminNotificationService method doSendNotification.

private void doSendNotification(final NotificationType notificationType, final String organisationIdentification, final String deviceIdentification, final String correlationUid, final String result, final String message) {
    final Notification notification = new Notification();
    // Required fields.
    notification.setNotificationType(notificationType);
    notification.setDeviceIdentification(deviceIdentification);
    // Optional fields.
    if (StringUtils.hasText(correlationUid)) {
        notification.setCorrelationUid(correlationUid);
    }
    if (StringUtils.hasText(result)) {
        notification.setResult(OsgpResultType.valueOf(result));
    }
    if (StringUtils.hasText(message)) {
        notification.setMessage(message);
    }
    // Try to send notification and catch security exceptions.
    try {
        this.sendNotificationServiceClient.sendNotification(organisationIdentification, notification);
    } catch (final WebServiceSecurityException e) {
        LOGGER.error("Unable to send notification", e);
    }
}
Also used : Notification(org.opensmartgridplatform.adapter.ws.schema.core.notification.Notification) WebServiceSecurityException(org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException)

Example 5 with Notification

use of org.opensmartgridplatform.adapter.ws.schema.core.notification.Notification in project open-smart-grid-platform by OSGP.

the class CoreNotificationService method getNotification.

private Notification getNotification(final Predicate<Notification> predicate, final long maxTimeout) {
    final long startTime = System.currentTimeMillis();
    long remaining = maxTimeout;
    while (remaining > 0) {
        try {
            final Notification notification = this.queue.poll(remaining, TimeUnit.MILLISECONDS);
            if (notification != null) {
                if (predicate.test(notification)) {
                    return notification;
                } else {
                    this.putBackOnQueue(notification);
                }
            }
            final long elapsed = System.currentTimeMillis() - startTime;
            remaining = maxTimeout - elapsed;
        } catch (final InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new CompletionException(e);
        }
    }
    return null;
}
Also used : CompletionException(java.util.concurrent.CompletionException) Notification(org.opensmartgridplatform.adapter.ws.schema.core.notification.Notification)

Aggregations

Notification (org.opensmartgridplatform.adapter.ws.schema.core.notification.Notification)6 WebServiceSecurityException (org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException)2 CompletionException (java.util.concurrent.CompletionException)1