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