Search in sources :

Example 1 with Command

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

the class CommandNotificationTypeAdapter method deserialize.

@Override
public CommandNotification deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException {
    JsonObject json = arg0.getAsJsonObject();
    Command command = Command.valueOf(json.get("command").getAsString());
    String type = json.get("type").getAsString();
    Notification notification = null;
    if (type.equals(PeriodicNotification.class.getSimpleName())) {
        notification = (new PeriodicNotificationTypeAdapter()).deserialize(json.get("notification"), PeriodicNotification.class, arg2);
    } else if (type.equals(BasicNotification.class.getSimpleName())) {
        notification = (new BasicNotificationTypeAdapter()).deserialize(json.get("notification"), BasicNotification.class, arg2);
    } else {
        throw new JsonParseException("Cannot deserialize Json");
    }
    return new CommandNotification(command, notification);
}
Also used : Command(org.apache.rya.periodic.notification.notification.CommandNotification.Command) JsonObject(com.google.gson.JsonObject) PeriodicNotification(org.apache.rya.periodic.notification.notification.PeriodicNotification) JsonParseException(com.google.gson.JsonParseException) CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) 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 Command

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

the class PeriodicNotificationCoordinatorExecutor method processNotification.

private void processNotification(CommandNotification notification) {
    Command command = notification.getCommand();
    Notification periodic = notification.getNotification();
    switch(command) {
        case ADD:
            addNotification(periodic);
            break;
        case DELETE:
            deleteNotification(periodic);
            break;
    }
}
Also used : Command(org.apache.rya.periodic.notification.notification.CommandNotification.Command) Notification(org.apache.rya.periodic.notification.api.Notification) PeriodicNotification(org.apache.rya.periodic.notification.notification.PeriodicNotification) CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) TimestampedNotification(org.apache.rya.periodic.notification.notification.TimestampedNotification)

Aggregations

Notification (org.apache.rya.periodic.notification.api.Notification)2 CommandNotification (org.apache.rya.periodic.notification.notification.CommandNotification)2 Command (org.apache.rya.periodic.notification.notification.CommandNotification.Command)2 PeriodicNotification (org.apache.rya.periodic.notification.notification.PeriodicNotification)2 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 BasicNotification (org.apache.rya.periodic.notification.notification.BasicNotification)1 TimestampedNotification (org.apache.rya.periodic.notification.notification.TimestampedNotification)1