Search in sources :

Example 1 with BasicNotification

use of org.apache.rya.periodic.notification.notification.BasicNotification in project incubator-rya by apache.

the class CommandNotificationTypeAdapter method serialize.

@Override
public JsonElement serialize(CommandNotification arg0, Type arg1, JsonSerializationContext arg2) {
    JsonObject result = new JsonObject();
    result.add("command", new JsonPrimitive(arg0.getCommand().name()));
    Notification notification = arg0.getNotification();
    if (notification instanceof PeriodicNotification) {
        result.add("type", new JsonPrimitive(PeriodicNotification.class.getSimpleName()));
        PeriodicNotificationTypeAdapter adapter = new PeriodicNotificationTypeAdapter();
        result.add("notification", adapter.serialize((PeriodicNotification) notification, PeriodicNotification.class, arg2));
    } else if (notification instanceof BasicNotification) {
        result.add("type", new JsonPrimitive(BasicNotification.class.getSimpleName()));
        BasicNotificationTypeAdapter adapter = new BasicNotificationTypeAdapter();
        result.add("notification", adapter.serialize((BasicNotification) notification, BasicNotification.class, arg2));
    } else {
        throw new IllegalArgumentException("Invalid notification type.");
    }
    return result;
}
Also used : BasicNotification(org.apache.rya.periodic.notification.notification.BasicNotification) JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject) PeriodicNotification(org.apache.rya.periodic.notification.notification.PeriodicNotification) Notification(org.apache.rya.periodic.notification.api.Notification) PeriodicNotification(org.apache.rya.periodic.notification.notification.PeriodicNotification) CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) BasicNotification(org.apache.rya.periodic.notification.notification.BasicNotification)

Example 2 with BasicNotification

use of org.apache.rya.periodic.notification.notification.BasicNotification in project incubator-rya by apache.

the class BasicNotificationTypeAdapter method deserialize.

@Override
public BasicNotification deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException {
    JsonObject json = arg0.getAsJsonObject();
    String id = json.get("id").getAsString();
    return new BasicNotification(id);
}
Also used : BasicNotification(org.apache.rya.periodic.notification.notification.BasicNotification) JsonObject(com.google.gson.JsonObject)

Example 3 with BasicNotification

use of org.apache.rya.periodic.notification.notification.BasicNotification in project incubator-rya by apache.

the class CommandNotificationSerializerTest method basicSerializationTest.

@Test
public void basicSerializationTest() {
    PeriodicNotification notification = PeriodicNotification.builder().id(UUID.randomUUID().toString()).period(24).timeUnit(TimeUnit.DAYS).initialDelay(1).build();
    CommandNotification command = new CommandNotification(Command.ADD, notification);
    Assert.assertEquals(command, serializer.deserialize(topic, serializer.serialize(topic, command)));
    PeriodicNotification notification1 = PeriodicNotification.builder().id(UUID.randomUUID().toString()).period(32).timeUnit(TimeUnit.SECONDS).initialDelay(15).build();
    CommandNotification command1 = new CommandNotification(Command.ADD, notification1);
    Assert.assertEquals(command1, serializer.deserialize(topic, serializer.serialize(topic, command1)));
    PeriodicNotification notification2 = PeriodicNotification.builder().id(UUID.randomUUID().toString()).period(32).timeUnit(TimeUnit.SECONDS).initialDelay(15).build();
    CommandNotification command2 = new CommandNotification(Command.ADD, notification2);
    Assert.assertEquals(command2, serializer.deserialize(topic, serializer.serialize(topic, command2)));
    BasicNotification notification3 = new BasicNotification(UUID.randomUUID().toString());
    CommandNotification command3 = new CommandNotification(Command.ADD, notification3);
    Assert.assertEquals(command3, serializer.deserialize(topic, serializer.serialize(topic, command3)));
}
Also used : BasicNotification(org.apache.rya.periodic.notification.notification.BasicNotification) PeriodicNotification(org.apache.rya.periodic.notification.notification.PeriodicNotification) CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) Test(org.junit.Test)

Example 4 with BasicNotification

use of org.apache.rya.periodic.notification.notification.BasicNotification in project incubator-rya by apache.

the class DeletePeriodicQuery method deletePeriodicQuery.

/**
 * Deletes the Periodic Query with the indicated pcjId from Fluo and {@link PeriodicQueryResultStorage}. In
 * addition, this method also informs the Periodic Notification Service to stop generating PeriodicNotifications
 * associated with the Periodic Query.
 *
 * @param queryId - Id of the Periodic Query to be deleted
 * @param periodicClient - Client used to inform the Periodic Notification Service to stop generating notifications
 * @throws QueryDeletionException
 */
public void deletePeriodicQuery(String pcjId, PeriodicNotificationClient periodicClient) throws QueryDeletionException {
    Preconditions.checkNotNull(periodicClient);
    deletePeriodicQuery(pcjId);
    periodicClient.deleteNotification(new BasicNotification(pcjId));
}
Also used : BasicNotification(org.apache.rya.periodic.notification.notification.BasicNotification)

Aggregations

BasicNotification (org.apache.rya.periodic.notification.notification.BasicNotification)4 JsonObject (com.google.gson.JsonObject)2 CommandNotification (org.apache.rya.periodic.notification.notification.CommandNotification)2 PeriodicNotification (org.apache.rya.periodic.notification.notification.PeriodicNotification)2 JsonPrimitive (com.google.gson.JsonPrimitive)1 Notification (org.apache.rya.periodic.notification.api.Notification)1 Test (org.junit.Test)1