Search in sources :

Example 1 with GetPostsActionHandler

use of com.willshex.blogwt.server.api.blog.action.GetPostsActionHandler in project blogwt by billy1380.

the class BlogJsonServlet method processAction.

@Override
protected String processAction(String action, JsonObject request) {
    String output = "null";
    if ("GetProperties".equals(action)) {
        GetPropertiesRequest input = new GetPropertiesRequest();
        input.fromJson(request);
        output = new GetPropertiesActionHandler().handle(input).toString();
    } else if ("GetRatings".equals(action)) {
        GetRatingsRequest input = new GetRatingsRequest();
        input.fromJson(request);
        output = new GetRatingsActionHandler().handle(input).toString();
    } else if ("SubmitRating".equals(action)) {
        SubmitRatingRequest input = new SubmitRatingRequest();
        input.fromJson(request);
        output = new SubmitRatingActionHandler().handle(input).toString();
    } else if ("UpdateResource".equals(action)) {
        UpdateResourceRequest input = new UpdateResourceRequest();
        input.fromJson(request);
        output = new UpdateResourceActionHandler().handle(input).toString();
    } else if ("GetResource".equals(action)) {
        GetResourceRequest input = new GetResourceRequest();
        input.fromJson(request);
        output = new GetResourceActionHandler().handle(input).toString();
    } else if ("GetPosts".equals(action)) {
        GetPostsRequest input = new GetPostsRequest();
        input.fromJson(request);
        output = new GetPostsActionHandler().handle(input).toString();
    } else if ("GetArchiveEntries".equals(action)) {
        GetArchiveEntriesRequest input = new GetArchiveEntriesRequest();
        input.fromJson(request);
        output = new GetArchiveEntriesActionHandler().handle(input).toString();
    } else if ("DeleteResource".equals(action)) {
        DeleteResourceRequest input = new DeleteResourceRequest();
        input.fromJson(request);
        output = new DeleteResourceActionHandler().handle(input).toString();
    } else if ("GetResources".equals(action)) {
        GetResourcesRequest input = new GetResourcesRequest();
        input.fromJson(request);
        output = new GetResourcesActionHandler().handle(input).toString();
    } else if ("GetRelatedPosts".equals(action)) {
        GetRelatedPostsRequest input = new GetRelatedPostsRequest();
        input.fromJson(request);
        output = new GetRelatedPostsActionHandler().handle(input).toString();
    } else if ("UpdateProperties".equals(action)) {
        UpdatePropertiesRequest input = new UpdatePropertiesRequest();
        input.fromJson(request);
        output = new UpdatePropertiesActionHandler().handle(input).toString();
    } else if ("GetTags".equals(action)) {
        GetTagsRequest input = new GetTagsRequest();
        input.fromJson(request);
        output = new GetTagsActionHandler().handle(input).toString();
    } else if ("GetPost".equals(action)) {
        GetPostRequest input = new GetPostRequest();
        input.fromJson(request);
        output = new GetPostActionHandler().handle(input).toString();
    } else if ("DeletePost".equals(action)) {
        DeletePostRequest input = new DeletePostRequest();
        input.fromJson(request);
        output = new DeletePostActionHandler().handle(input).toString();
    } else if ("SetupBlog".equals(action)) {
        SetupBlogRequest input = new SetupBlogRequest();
        input.fromJson(request);
        output = new SetupBlogActionHandler().handle(input).toString();
    } else if ("CreatePost".equals(action)) {
        CreatePostRequest input = new CreatePostRequest();
        input.fromJson(request);
        output = new CreatePostActionHandler().handle(input).toString();
    } else if ("UpdatePost".equals(action)) {
        UpdatePostRequest input = new UpdatePostRequest();
        input.fromJson(request);
        output = new UpdatePostActionHandler().handle(input).toString();
    }
    return output;
}
Also used : SubmitRatingRequest(com.willshex.blogwt.shared.api.blog.call.SubmitRatingRequest) GetPostsActionHandler(com.willshex.blogwt.server.api.blog.action.GetPostsActionHandler) SetupBlogRequest(com.willshex.blogwt.shared.api.blog.call.SetupBlogRequest) CreatePostRequest(com.willshex.blogwt.shared.api.blog.call.CreatePostRequest) DeleteResourceActionHandler(com.willshex.blogwt.server.api.blog.action.DeleteResourceActionHandler) GetResourceRequest(com.willshex.blogwt.shared.api.blog.call.GetResourceRequest) GetPostsRequest(com.willshex.blogwt.shared.api.blog.call.GetPostsRequest) DeletePostActionHandler(com.willshex.blogwt.server.api.blog.action.DeletePostActionHandler) GetRatingsActionHandler(com.willshex.blogwt.server.api.blog.action.GetRatingsActionHandler) DeletePostRequest(com.willshex.blogwt.shared.api.blog.call.DeletePostRequest) UpdatePropertiesRequest(com.willshex.blogwt.shared.api.blog.call.UpdatePropertiesRequest) SetupBlogActionHandler(com.willshex.blogwt.server.api.blog.action.SetupBlogActionHandler) SubmitRatingActionHandler(com.willshex.blogwt.server.api.blog.action.SubmitRatingActionHandler) GetTagsActionHandler(com.willshex.blogwt.server.api.blog.action.GetTagsActionHandler) UpdateResourceRequest(com.willshex.blogwt.shared.api.blog.call.UpdateResourceRequest) UpdatePostActionHandler(com.willshex.blogwt.server.api.blog.action.UpdatePostActionHandler) GetRatingsRequest(com.willshex.blogwt.shared.api.blog.call.GetRatingsRequest) GetRelatedPostsActionHandler(com.willshex.blogwt.server.api.blog.action.GetRelatedPostsActionHandler) UpdatePropertiesActionHandler(com.willshex.blogwt.server.api.blog.action.UpdatePropertiesActionHandler) GetPostActionHandler(com.willshex.blogwt.server.api.blog.action.GetPostActionHandler) GetResourcesRequest(com.willshex.blogwt.shared.api.blog.call.GetResourcesRequest) GetPropertiesRequest(com.willshex.blogwt.shared.api.blog.call.GetPropertiesRequest) GetPropertiesActionHandler(com.willshex.blogwt.server.api.blog.action.GetPropertiesActionHandler) GetResourceActionHandler(com.willshex.blogwt.server.api.blog.action.GetResourceActionHandler) GetPostRequest(com.willshex.blogwt.shared.api.blog.call.GetPostRequest) GetTagsRequest(com.willshex.blogwt.shared.api.blog.call.GetTagsRequest) UpdatePostRequest(com.willshex.blogwt.shared.api.blog.call.UpdatePostRequest) GetResourcesActionHandler(com.willshex.blogwt.server.api.blog.action.GetResourcesActionHandler) GetArchiveEntriesRequest(com.willshex.blogwt.shared.api.blog.call.GetArchiveEntriesRequest) UpdateResourceActionHandler(com.willshex.blogwt.server.api.blog.action.UpdateResourceActionHandler) GetArchiveEntriesActionHandler(com.willshex.blogwt.server.api.blog.action.GetArchiveEntriesActionHandler) CreatePostActionHandler(com.willshex.blogwt.server.api.blog.action.CreatePostActionHandler) GetRelatedPostsRequest(com.willshex.blogwt.shared.api.blog.call.GetRelatedPostsRequest) DeleteResourceRequest(com.willshex.blogwt.shared.api.blog.call.DeleteResourceRequest)

Example 2 with GetPostsActionHandler

use of com.willshex.blogwt.server.api.blog.action.GetPostsActionHandler in project blogwt by billy1380.

the class StaticPosts method appendPage.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.page.StaticTemplate#appendPage(java.lang.
	 * StringBuffer) */
@Override
protected void appendPage(StringBuffer markup) {
    markup.append("<h2>Blog</h2>");
    GetPostsRequest input = input(GetPostsRequest.class).pager(PagerHelper.createDefaultPager().sortBy(PostSortType.PostSortTypePublished.toString()));
    GetPostsResponse output = new GetPostsActionHandler().handle(input);
    if (output.status == StatusType.StatusTypeSuccess && output.posts != null) {
        showPosts(output.posts, markup);
    } else {
        markup.append(output.error.toString());
    }
}
Also used : GetPostsActionHandler(com.willshex.blogwt.server.api.blog.action.GetPostsActionHandler) GetPostsRequest(com.willshex.blogwt.shared.api.blog.call.GetPostsRequest) GetPostsResponse(com.willshex.blogwt.shared.api.blog.call.GetPostsResponse)

Example 3 with GetPostsActionHandler

use of com.willshex.blogwt.server.api.blog.action.GetPostsActionHandler in project blogwt by billy1380.

the class StaticTag method appendPage.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.page.StaticTemplate#appendPage(java.lang.
	 * StringBuffer) */
@Override
protected void appendPage(StringBuffer markup) {
    String tag;
    if ((tag = stack.getAction()) != null) {
        markup.append("<h2>Posts tagged with <strong>&apos;" + tag + "&apos;</strong></h2>");
        GetPostsRequest input = input(GetPostsRequest.class).pager(PagerHelper.createDefaultPager()).tag(tag);
        GetPostsResponse output = (new GetPostsActionHandler()).handle(input);
        if (output.status == StatusType.StatusTypeSuccess && output.posts != null) {
            showPosts(output.posts, markup);
        } else {
            markup.append(output.error.toString());
        }
    }
}
Also used : GetPostsActionHandler(com.willshex.blogwt.server.api.blog.action.GetPostsActionHandler) GetPostsRequest(com.willshex.blogwt.shared.api.blog.call.GetPostsRequest) GetPostsResponse(com.willshex.blogwt.shared.api.blog.call.GetPostsResponse)

Example 4 with GetPostsActionHandler

use of com.willshex.blogwt.server.api.blog.action.GetPostsActionHandler 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")) {
        String group = REQUEST.get().getParameter("group");
        if (group == null || group.trim().isEmpty()) {
            group = "blogwt";
        }
        PageServiceProvider.provide();
        PostServiceProvider.provide();
        UserServiceProvider.provide();
        SearchHelper.indexAll((ISearch<?>) ServiceDiscovery.getService(group + "." + action.replace("index", "")));
    } else if ("clearsearch".equals(action)) {
        PersistenceServiceProvider.provide();
        String name = REQUEST.get().getParameter("index");
        String ids = REQUEST.get().getParameter("ids");
        String namespace = REQUEST.get().getParameter("ns");
        String[] split = ids.split(",");
        for (String id : split) {
            SearchHelper.deleteSearch(() -> namespace == null ? false : Boolean.valueOf(namespace).booleanValue(), 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;
        }
    } else if (action != null && action.startsWith("resave")) {
        String typeName = REQUEST.get().getParameter("type");
        ResaveServlet.queueForResaving(typeName);
    } else if (action != null && action.startsWith("deleteposts")) {
        processPaged((Integer s, Integer c, PostSortType o, SortDirectionType d) -> PostServiceProvider.provide().getPosts(Boolean.TRUE, Boolean.FALSE, s, c, o, d), PostServiceProvider.provide()::deletePost);
    }
}
Also used : GetPostsActionHandler(com.willshex.blogwt.server.api.blog.action.GetPostsActionHandler) User(com.willshex.blogwt.shared.api.datatype.User) GetPostsRequest(com.willshex.blogwt.shared.api.blog.call.GetPostsRequest) JsonObject(com.google.gson.JsonObject) PostSortType(com.willshex.blogwt.shared.api.datatype.PostSortType) BlobKey(com.google.appengine.api.blobstore.BlobKey) ISearch(com.willshex.blogwt.server.service.search.ISearch) Permission(com.willshex.blogwt.shared.api.datatype.Permission) List(java.util.List) ArrayList(java.util.ArrayList) JsonParser(com.google.gson.JsonParser) Resource(com.willshex.blogwt.shared.api.datatype.Resource) MetaNotification(com.willshex.blogwt.shared.api.datatype.MetaNotification) SortDirectionType(com.willshex.blogwt.shared.api.SortDirectionType) Stack(com.willshex.blogwt.shared.page.Stack) Role(com.willshex.blogwt.shared.api.datatype.Role) GeneratedDownload(com.willshex.blogwt.shared.api.datatype.GeneratedDownload) Filter(com.willshex.blogwt.shared.page.search.Filter) Collection(java.util.Collection)

Aggregations

GetPostsActionHandler (com.willshex.blogwt.server.api.blog.action.GetPostsActionHandler)4 GetPostsRequest (com.willshex.blogwt.shared.api.blog.call.GetPostsRequest)4 GetPostsResponse (com.willshex.blogwt.shared.api.blog.call.GetPostsResponse)2 BlobKey (com.google.appengine.api.blobstore.BlobKey)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 CreatePostActionHandler (com.willshex.blogwt.server.api.blog.action.CreatePostActionHandler)1 DeletePostActionHandler (com.willshex.blogwt.server.api.blog.action.DeletePostActionHandler)1 DeleteResourceActionHandler (com.willshex.blogwt.server.api.blog.action.DeleteResourceActionHandler)1 GetArchiveEntriesActionHandler (com.willshex.blogwt.server.api.blog.action.GetArchiveEntriesActionHandler)1 GetPostActionHandler (com.willshex.blogwt.server.api.blog.action.GetPostActionHandler)1 GetPropertiesActionHandler (com.willshex.blogwt.server.api.blog.action.GetPropertiesActionHandler)1 GetRatingsActionHandler (com.willshex.blogwt.server.api.blog.action.GetRatingsActionHandler)1 GetRelatedPostsActionHandler (com.willshex.blogwt.server.api.blog.action.GetRelatedPostsActionHandler)1 GetResourceActionHandler (com.willshex.blogwt.server.api.blog.action.GetResourceActionHandler)1 GetResourcesActionHandler (com.willshex.blogwt.server.api.blog.action.GetResourcesActionHandler)1 GetTagsActionHandler (com.willshex.blogwt.server.api.blog.action.GetTagsActionHandler)1 SetupBlogActionHandler (com.willshex.blogwt.server.api.blog.action.SetupBlogActionHandler)1 SubmitRatingActionHandler (com.willshex.blogwt.server.api.blog.action.SubmitRatingActionHandler)1 UpdatePostActionHandler (com.willshex.blogwt.server.api.blog.action.UpdatePostActionHandler)1