use of com.willshex.blogwt.shared.api.datatype.MetaNotification in project blogwt by billy1380.
the class GetMetaNotificationsResponse method fromJson.
@Override
public void fromJson(JsonObject jsonObject) {
super.fromJson(jsonObject);
if (jsonObject.has("metas")) {
JsonElement jsonMetas = jsonObject.get("metas");
if (jsonMetas != null) {
metas = new ArrayList<MetaNotification>();
MetaNotification item = null;
for (int i = 0; i < jsonMetas.getAsJsonArray().size(); i++) {
if (jsonMetas.getAsJsonArray().get(i) != null) {
(item = new MetaNotification()).fromJson(jsonMetas.getAsJsonArray().get(i).getAsJsonObject());
metas.add(item);
}
}
}
}
if (jsonObject.has("pager")) {
JsonElement jsonPager = jsonObject.get("pager");
if (jsonPager != null) {
pager = new Pager();
pager.fromJson(jsonPager.getAsJsonObject());
}
}
}
use of com.willshex.blogwt.shared.api.datatype.MetaNotification in project blogwt by billy1380.
the class UpdateMetaNotificationResponse 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 UpdateMetaNotificationRequest 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 DevServlet method doGet.
/* (non-Javadoc)
*
* @see com.willshex.service.ContextAwareServlet#doGet() */
@Override
protected void doGet() throws ServletException, IOException {
super.doGet();
String action = REQUEST.get().getParameter("action");
if (action != null) {
action = action.toLowerCase();
}
if ("gentags".equals(action)) {
TagServiceProvider.provide().generateTags();
} else if (action != null && action.startsWith("index")) {
PageServiceProvider.provide();
PostServiceProvider.provide();
UserServiceProvider.provide();
((ISearch<?>) ServiceDiscovery.getService("blogwt." + action.replace("index", ""))).indexAll();
} else if ("clearsearch".equals(action)) {
PersistenceServiceProvider.provide();
String name = REQUEST.get().getParameter("index");
String ids = REQUEST.get().getParameter("ids");
String[] split = ids.split(",");
for (String id : split) {
SearchHelper.deleteSearch(name, id);
}
} else if ("linkall".equals(action)) {
PostServiceProvider.provide().linkAll();
} else if ("clearlinks".equals(action)) {
PostServiceProvider.provide().clearLinks();
} else if ("archiveall".equals(action)) {
ArchiveEntryServiceProvider.provide().generateArchive();
} else if ("fixroles".equals(action)) {
Collection<Role> all = RoleHelper.createAll();
all.stream().forEach(role -> {
Role loaded = RoleServiceProvider.provide().getCodeRole(role.code);
if (loaded == null || loaded.id == null) {
RoleServiceProvider.provide().addRole(role);
}
if (role.permissions != null) {
role.permissions.stream().forEach(i -> {
Permission lp = PermissionServiceProvider.provide().getCodePermission(i.code);
if (lp == null) {
if (LOG.isLoggable(Level.WARNING)) {
LOG.warning("Could not find permission with code [" + i.code + "], might want to run [fixpermissions] action");
}
} else {
if (loaded.permissions == null) {
loaded.permissions = new ArrayList<>();
}
loaded.permissions.add(lp);
}
});
RoleServiceProvider.provide().updateRole(loaded);
}
});
} else if ("fixpermissions".equals(action)) {
Collection<Permission> all = PermissionHelper.createAll();
Permission loaded;
for (Permission permission : all) {
loaded = PermissionServiceProvider.provide().getCodePermission(permission.code);
if (loaded == null || loaded.id == null) {
PermissionServiceProvider.provide().addPermission(permission);
}
}
} else if ("getposts".equals(action)) {
RESPONSE.get().getOutputStream().print(JsonUtils.beautifyJson((new GetPostsActionHandler()).handle((GetPostsRequest) new GetPostsRequest().showAll(Boolean.TRUE).pager(PagerHelper.createDefaultPager()).accessCode(ApiValidator.DEV_ACCESS_CODE)).toString()));
} else if ("staticurl".equals(action)) {
List<Resource> resources = ResourceServiceProvider.provide().getResources(Integer.valueOf(0), Integer.valueOf(Integer.MAX_VALUE), null, null);
JsonObject object;
for (Resource resource : resources) {
if (resource.properties != null) {
if (resource.properties.contains(":image")) {
resource.properties = resource.properties.replace(":image", ":\"image").replace("}", "\"}");
}
object = new JsonParser().parse(resource.properties).getAsJsonObject();
} else {
object = new JsonObject();
}
if (!object.has("staticUrl") || object.get("staticUrl").getAsString().startsWith("http")) {
try {
object.addProperty("staticUrl", ImagesServiceFactory.getImagesService().getServingUrl(ServingUrlOptions.Builder.withBlobKey(new BlobKey(resource.data.replace("gs://", "")))).replaceFirst("https:\\/\\/", "//").replaceFirst("http:\\/\\/", "//"));
} catch (Throwable e) {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Could not update resource");
}
}
resource.properties = object.toString();
ResourceServiceProvider.provide().updateResource(resource);
}
}
} else if ("fixmetanotifications".equals(action)) {
List<MetaNotification> metas = MetaNotificationHelper.createAll();
for (MetaNotification meta : metas) {
if (MetaNotificationServiceProvider.provide().getCodeMetaNotification(meta.code) == null) {
meta = MetaNotificationServiceProvider.provide().addMetaNotification(meta);
LOG.info("added meta notification [" + meta.code + "] with id [" + meta.id + "]");
} else {
LOG.info("Meta notification [" + meta.code + "] already exists");
}
}
} else if ("admin".equals(action)) {
User user = UserServiceProvider.provide().getUsernameUser(REQUEST.get().getParameter("user"));
UserServiceProvider.provide().addUserRolesAndPermissions(user, Arrays.asList(RoleServiceProvider.provide().getCodeRole(RoleHelper.ADMIN)), null);
} else if ("genandshowdownload".equals(action)) {
String idParam = REQUEST.get().getParameter("id");
Long id = Long.valueOf(idParam);
GeneratedDownload d = GeneratedDownloadServiceProvider.provide().getGeneratedDownload(id);
Stack stack = Stack.parse(d.parameters);
Filter filter = Filter.fromStack(stack);
switch(filter.type) {
default:
break;
}
}
}
use of com.willshex.blogwt.shared.api.datatype.MetaNotification in project blogwt by billy1380.
the class GetNotificationSettingsActionHandler method handle.
@Override
public void handle(GetNotificationSettingsRequest input, GetNotificationSettingsResponse output) throws Exception {
ApiValidator.request(input, GetNotificationSettingsRequest.class);
ApiValidator.accessCode(input.accessCode, "input.accessCode");
output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
if (input.user == null) {
input.user = input.session.user;
} else {
UserValidator.authorisation(input.session.user, Arrays.asList(PermissionServiceProvider.provide().getCodePermission(PermissionHelper.MANAGE_NOTIFICATIONS)), "input.session.user");
input.user = UserValidator.lookup(input.user, "input.user");
}
if (input.pager == null) {
input.pager = PagerHelper.createDefaultPager();
}
List<MetaNotification> metas = MetaNotificationServiceProvider.provide().getMetaNotifications(input.pager.start, input.pager.count, MetaNotificationSortType.fromString(input.pager.sortBy), input.pager.sortDirection);
if (metas != null && metas.size() > 0) {
output.settings = new ArrayList<>();
NotificationSetting setting;
User slimUser = (User) new User().id(input.user.id);
for (MetaNotification meta : metas) {
setting = NotificationSettingServiceProvider.provide().getMetaUserNotificationSetting(meta, input.user);
if (setting == null) {
setting = new NotificationSetting().meta(meta).user(input.user).selected(meta.defaults);
setting = NotificationSettingServiceProvider.provide().addNotificationSetting(setting);
}
setting.user = slimUser;
setting.meta = meta;
}
}
output.pager = PagerHelper.moveForward(input.pager);
}
Aggregations