Search in sources :

Example 1 with NotificationSetting

use of com.willshex.blogwt.shared.api.datatype.NotificationSetting in project blogwt by billy1380.

the class UpdateNotificationSettingsActionHandler method handle.

@Override
public void handle(UpdateNotificationSettingsRequest input, UpdateNotificationSettingsResponse output) throws Exception {
    ApiValidator.request(input, UpdateNotificationSettingsRequest.class);
    ApiValidator.accessCode(input.accessCode, "input.accessCode");
    output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
    List<NotificationSetting> settings = NotificationSettingValidator.lookupAll(input.settings, "input.settings");
    input.settings = NotificationSettingValidator.validateAll(input.settings, "input.settings");
    Map<Long, NotificationSetting> inputMap = PersistenceHelper.typeMap(input.settings);
    for (NotificationSetting setting : settings) {
        setting.selected = inputMap.get(setting.id).selected;
    }
    output.settings = NotificationServiceProvider.provide().updateNotificationSettings(settings);
    if (output.settings != null) {
        Map<Long, NotificationSetting> notificationSettingLookup = new HashMap<>();
        for (NotificationSetting setting : output.settings) {
            notificationSettingLookup.put(PersistenceHelper.keyToId(setting.metaKey), setting);
            setting.user = PersistenceHelper.type(User.class, setting.userKey);
        }
        List<MetaNotification> metas = PersistenceHelper.batchLookup(MetaNotificationServiceProvider.provide(), PersistenceHelper.idsToKeys(MetaNotification.class, notificationSettingLookup.keySet()));
        for (MetaNotification meta : metas) {
            notificationSettingLookup.get(meta.id).meta = meta;
        }
    }
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User) HashMap(java.util.HashMap) NotificationSetting(com.willshex.blogwt.shared.api.datatype.NotificationSetting) MetaNotification(com.willshex.blogwt.shared.api.datatype.MetaNotification)

Example 2 with NotificationSetting

use of com.willshex.blogwt.shared.api.datatype.NotificationSetting in project blogwt by billy1380.

the class NotificationSettingValidator method lookup.

public static NotificationSetting lookup(NotificationSetting notificationSetting, String name) throws InputValidationException {
    notNull(notificationSetting, CLASS, name);
    boolean isIdLookup = false, isUserMetaNotificationLookup = false;
    if (notificationSetting.id != null) {
        isIdLookup = true;
    } else if (notificationSetting.user != null && notificationSetting.meta != null) {
        isUserMetaNotificationLookup = true;
    }
    if (!(isIdLookup || isUserMetaNotificationLookup))
        throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    NotificationSetting lookupNotificationSetting = null;
    if (isIdLookup) {
        notificationSetting = NotificationSettingServiceProvider.provide().getNotificationSetting(notificationSetting.id);
    } else if (isUserMetaNotificationLookup) {
        notificationSetting.user = UserValidator.lookup(notificationSetting.user, name + ".user");
        notificationSetting.meta = MetaNotificationValidator.lookup(notificationSetting.meta, name + ".meta");
        notificationSetting = NotificationSettingServiceProvider.provide().getMetaUserNotificationSetting(notificationSetting.meta, notificationSetting.user);
    }
    if (lookupNotificationSetting == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return notificationSetting;
}
Also used : NotificationSetting(com.willshex.blogwt.shared.api.datatype.NotificationSetting) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Example 3 with NotificationSetting

use of com.willshex.blogwt.shared.api.datatype.NotificationSetting in project blogwt by billy1380.

the class UpdateNotificationSettingsResponse method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("settings")) {
        JsonElement jsonSettings = jsonObject.get("settings");
        if (jsonSettings != null) {
            settings = new ArrayList<NotificationSetting>();
            NotificationSetting item = null;
            for (int i = 0; i < jsonSettings.getAsJsonArray().size(); i++) {
                if (jsonSettings.getAsJsonArray().get(i) != null) {
                    (item = new NotificationSetting()).fromJson(jsonSettings.getAsJsonArray().get(i).getAsJsonObject());
                    settings.add(item);
                }
            }
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) NotificationSetting(com.willshex.blogwt.shared.api.datatype.NotificationSetting)

Example 4 with NotificationSetting

use of com.willshex.blogwt.shared.api.datatype.NotificationSetting in project blogwt by billy1380.

the class GetNotificationSettingsResponse method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("pager")) {
        JsonElement jsonPager = jsonObject.get("pager");
        if (jsonPager != null) {
            pager = new Pager();
            pager.fromJson(jsonPager.getAsJsonObject());
        }
    }
    if (jsonObject.has("settings")) {
        JsonElement jsonSettings = jsonObject.get("settings");
        if (jsonSettings != null) {
            settings = new ArrayList<NotificationSetting>();
            NotificationSetting item = null;
            for (int i = 0; i < jsonSettings.getAsJsonArray().size(); i++) {
                if (jsonSettings.getAsJsonArray().get(i) != null) {
                    (item = new NotificationSetting()).fromJson(jsonSettings.getAsJsonArray().get(i).getAsJsonObject());
                    settings.add(item);
                }
            }
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) Pager(com.willshex.blogwt.shared.api.Pager) NotificationSetting(com.willshex.blogwt.shared.api.datatype.NotificationSetting)

Example 5 with NotificationSetting

use of com.willshex.blogwt.shared.api.datatype.NotificationSetting in project blogwt by billy1380.

the class UpdateNotificationSettingsRequest method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("settings")) {
        JsonElement jsonSettings = jsonObject.get("settings");
        if (jsonSettings != null) {
            settings = new ArrayList<NotificationSetting>();
            NotificationSetting item = null;
            for (int i = 0; i < jsonSettings.getAsJsonArray().size(); i++) {
                if (jsonSettings.getAsJsonArray().get(i) != null) {
                    (item = new NotificationSetting()).fromJson(jsonSettings.getAsJsonArray().get(i).getAsJsonObject());
                    settings.add(item);
                }
            }
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) NotificationSetting(com.willshex.blogwt.shared.api.datatype.NotificationSetting)

Aggregations

NotificationSetting (com.willshex.blogwt.shared.api.datatype.NotificationSetting)8 JsonElement (com.google.gson.JsonElement)3 MetaNotification (com.willshex.blogwt.shared.api.datatype.MetaNotification)3 User (com.willshex.blogwt.shared.api.datatype.User)2 JsonObject (com.google.gson.JsonObject)1 AndroidMessage (com.willshex.blogwt.server.helper.push.AndroidMessage)1 Pager (com.willshex.blogwt.shared.api.Pager)1 DataType (com.willshex.blogwt.shared.api.datatype.DataType)1 Notification (com.willshex.blogwt.shared.api.datatype.Notification)1 NotificationModeType (com.willshex.blogwt.shared.api.datatype.NotificationModeType)1 PushToken (com.willshex.blogwt.shared.api.datatype.PushToken)1 Jsonable (com.willshex.gson.shared.Jsonable)1 InputValidationException (com.willshex.gson.web.service.server.InputValidationException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1