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