Search in sources :

Example 1 with MetaNotification

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

the class UpdateMetaNotificationActionHandler method handle.

@Override
public void handle(UpdateMetaNotificationRequest input, UpdateMetaNotificationResponse output) throws Exception {
    ApiValidator.request(input, UpdateMetaNotificationRequest.class);
    ApiValidator.accessCode(input.accessCode, "input.accessCode");
    output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
    UserValidator.authorisation(input.session.user, Arrays.asList(PermissionServiceProvider.provide().getCodePermission(PermissionHelper.MANAGE_NOTIFICATIONS)), "input.session.user");
    MetaNotification updatedMetaNotification = input.meta;
    input.meta = MetaNotificationValidator.lookup(input.meta, "input.meta");
    updatedMetaNotification = MetaNotificationValidator.validate(updatedMetaNotification, "input.meta");
    input.meta.code = updatedMetaNotification.code;
    input.meta.name = updatedMetaNotification.name;
    input.meta.group = updatedMetaNotification.group;
    input.meta.content = updatedMetaNotification.content;
    input.meta.modes = updatedMetaNotification.modes;
    input.meta.defaults = updatedMetaNotification.defaults;
    output.meta = MetaNotificationServiceProvider.provide().updateMetaNotification(input.meta);
}
Also used : MetaNotification(com.willshex.blogwt.shared.api.datatype.MetaNotification)

Example 2 with MetaNotification

use of com.willshex.blogwt.shared.api.datatype.MetaNotification 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 3 with MetaNotification

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

the class MetaNotificationValidator method lookup.

public static MetaNotification lookup(MetaNotification metaNotification, String name) throws InputValidationException {
    notNull(metaNotification, CLASS, name);
    boolean isIdLookup = false, isCodeLookup = false;
    if (metaNotification.id != null) {
        isIdLookup = true;
    } else if (metaNotification.code != null) {
        isCodeLookup = true;
    }
    if (!(isIdLookup || isCodeLookup))
        throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    MetaNotification lookupMetaNotification = null;
    if (isIdLookup) {
        lookupMetaNotification = MetaNotificationServiceProvider.provide().getMetaNotification(metaNotification.id);
    } else if (isCodeLookup) {
        lookupMetaNotification = MetaNotificationServiceProvider.provide().getCodeMetaNotification(metaNotification.code);
    }
    if (lookupMetaNotification == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupMetaNotification;
}
Also used : InputValidationException(com.willshex.gson.web.service.server.InputValidationException) MetaNotification(com.willshex.blogwt.shared.api.datatype.MetaNotification)

Example 4 with MetaNotification

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

the class AddMetaNotificationResponse method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("meta")) {
        JsonElement jsonMeta = jsonObject.get("meta");
        if (jsonMeta != null) {
            meta = new MetaNotification();
            meta.fromJson(jsonMeta.getAsJsonObject());
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) MetaNotification(com.willshex.blogwt.shared.api.datatype.MetaNotification)

Example 5 with MetaNotification

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

the class GetMetaNotificationResponse method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("meta")) {
        JsonElement jsonMeta = jsonObject.get("meta");
        if (jsonMeta != null) {
            meta = new MetaNotification();
            meta.fromJson(jsonMeta.getAsJsonObject());
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) MetaNotification(com.willshex.blogwt.shared.api.datatype.MetaNotification)

Aggregations

MetaNotification (com.willshex.blogwt.shared.api.datatype.MetaNotification)15 JsonElement (com.google.gson.JsonElement)7 NotificationSetting (com.willshex.blogwt.shared.api.datatype.NotificationSetting)3 User (com.willshex.blogwt.shared.api.datatype.User)3 JsonObject (com.google.gson.JsonObject)2 ArrayList (java.util.ArrayList)2 BlobKey (com.google.appengine.api.blobstore.BlobKey)1 JsonParser (com.google.gson.JsonParser)1 UiHandler (com.google.gwt.uibinder.client.UiHandler)1 GetPostsActionHandler (com.willshex.blogwt.server.api.blog.action.GetPostsActionHandler)1 AndroidMessage (com.willshex.blogwt.server.helper.push.AndroidMessage)1 Pager (com.willshex.blogwt.shared.api.Pager)1 GetPostsRequest (com.willshex.blogwt.shared.api.blog.call.GetPostsRequest)1 DataType (com.willshex.blogwt.shared.api.datatype.DataType)1 GeneratedDownload (com.willshex.blogwt.shared.api.datatype.GeneratedDownload)1 Notification (com.willshex.blogwt.shared.api.datatype.Notification)1 NotificationModeType (com.willshex.blogwt.shared.api.datatype.NotificationModeType)1 Permission (com.willshex.blogwt.shared.api.datatype.Permission)1 PushToken (com.willshex.blogwt.shared.api.datatype.PushToken)1 Resource (com.willshex.blogwt.shared.api.datatype.Resource)1