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