Search in sources :

Example 6 with Post

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

the class PostController method createPost.

public void createPost(String title, Boolean listed, Boolean commentsEnabled, String summary, String content, Boolean publish, String tags) {
    BlogService blogService = ApiHelper.createBlogClient();
    final CreatePostRequest input = SessionController.get().setSession(ApiHelper.setAccessCode(new CreatePostRequest())).post(new Post().title(title).summary(summary).content(new PostContent().body(content)).tags(TagHelper.convertToTagList(tags)).listed(listed).commentsEnabled(commentsEnabled)).publish(publish);
    blogService.createPost(input, new AsyncCallback<CreatePostResponse>() {

        @Override
        public void onSuccess(CreatePostResponse output) {
            if (output.status == StatusType.StatusTypeSuccess) {
            }
            DefaultEventBus.get().fireEventFromSource(new CreatePostSuccess(input, output), PostController.this);
        }

        @Override
        public void onFailure(Throwable caught) {
            DefaultEventBus.get().fireEventFromSource(new CreatePostFailure(input, caught), PostController.this);
        }
    });
}
Also used : BlogService(com.willshex.blogwt.client.api.blog.BlogService) CreatePostRequest(com.willshex.blogwt.shared.api.blog.call.CreatePostRequest) Post(com.willshex.blogwt.shared.api.datatype.Post) CreatePostSuccess(com.willshex.blogwt.client.api.blog.event.CreatePostEventHandler.CreatePostSuccess) CreatePostFailure(com.willshex.blogwt.client.api.blog.event.CreatePostEventHandler.CreatePostFailure) PostContent(com.willshex.blogwt.shared.api.datatype.PostContent) CreatePostResponse(com.willshex.blogwt.shared.api.blog.call.CreatePostResponse)

Example 7 with Post

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

the class PostController method getPost.

public void getPost(Post post) {
    final GetPostRequest input = SessionController.get().setSession(ApiHelper.setAccessCode(new GetPostRequest())).post(post);
    if (getPostRequest != null) {
        getPostRequest.cancel();
    }
    getPostRequest = ApiHelper.createBlogClient().getPost(input, new AsyncCallback<GetPostResponse>() {

        @Override
        public void onSuccess(GetPostResponse output) {
            getPostRequest = null;
            boolean retryingGetWithSlug = false;
            if (output.status == StatusType.StatusTypeSuccess) {
                if (output.post != null) {
                }
            } else {
                if (input.post.id != null) {
                    getPost(new Post().slug(input.post.id.toString()));
                    retryingGetWithSlug = true;
                }
            }
            if (!retryingGetWithSlug) {
                DefaultEventBus.get().fireEventFromSource(new GetPostSuccess(input, output), PostController.this);
            }
        }

        @Override
        public void onFailure(Throwable caught) {
            getPostRequest = null;
            DefaultEventBus.get().fireEventFromSource(new GetPostFailure(input, caught), PostController.this);
        }
    });
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GetPostRequest(com.willshex.blogwt.shared.api.blog.call.GetPostRequest) GetPostSuccess(com.willshex.blogwt.client.api.blog.event.GetPostEventHandler.GetPostSuccess) GetPostFailure(com.willshex.blogwt.client.api.blog.event.GetPostEventHandler.GetPostFailure) GetPostResponse(com.willshex.blogwt.shared.api.blog.call.GetPostResponse)

Example 8 with Post

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

the class PostsPlugin method emit.

/* (non-Javadoc)
	 * 
	 * @see org.markdown4j.Plugin#emit(java.lang.StringBuilder, java.util.List,
	 * java.util.Map) */
@Override
public void emit(StringBuilder out, List<String> lines, Map<String, String> params) {
    String count = params.get("count");
    final String id = HTMLPanel.createUniqueId();
    out.append("<div id=\"");
    out.append(id);
    out.append("\">Loading...</div>");
    ApiHelper.createBlogClient().getPosts(SessionController.get().setSession(ApiHelper.setAccessCode(new GetPostsRequest())).pager(PagerHelper.createDefaultPager().count(Integer.valueOf(count)).sortBy(PostSortType.PostSortTypeCreated.toString())), (i, o) -> {
        if (manager != null) {
            String content = "";
            if (o.status == StatusType.StatusTypeSuccess && o.posts != null && !o.posts.isEmpty()) {
                SafeHtmlBuilder b = new SafeHtmlBuilder();
                for (Post object : o.posts) {
                    RENDERER.render(null, object, b);
                }
                content = b.toSafeHtml().asString();
            }
            manager.fireEvent(new PluginContentReadyEvent(this, lines, params, id, content));
        }
    }, (i, c) -> {
        if (manager != null) {
            String content = "";
            manager.fireEvent(new PluginContentReadyEvent(this, lines, params, id, content));
        }
    });
}
Also used : PluginContentReadyEvent(org.markdown4j.client.event.PluginContentReadyEventHandler.PluginContentReadyEvent) Post(com.willshex.blogwt.shared.api.datatype.Post) GetPostsRequest(com.willshex.blogwt.shared.api.blog.call.GetPostsRequest) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder)

Example 9 with Post

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

the class StaticPost method appendPage.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.page.StaticTemplate#appendPage(java.lang.
	 * StringBuffer) */
@Override
protected void appendPage(StringBuffer markup) {
    Post post = ensurePost();
    if (post != null) {
        markup.append(process("##" + post.title));
        markup.append("<div><span>");
        markup.append(DateTimeHelper.ago(post.published));
        markup.append("</span> by <img src=\"");
        markup.append(post.author.avatar);
        markup.append("?s=");
        markup.append(UserHelper.AVATAR_HEADER_SIZE);
        markup.append("&default=retro\" /> ");
        markup.append(UserHelper.handle(post.author));
        if (post.content != null) {
            markup.append(process(post.content.body));
        }
        if (post.tags != null) {
            markup.append("<ul>");
            for (String tag : post.tags) {
                markup.append("<li><a href=\"");
                markup.append("#" + PageType.TagPostsPageType.asTargetHistoryToken(tag));
                markup.append("\">");
                markup.append(tag);
                markup.append("</a></li>");
            }
            markup.append("</ul>");
        }
    } else {
        markup.append("Page not found.");
    }
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post)

Example 10 with Post

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

the class ArchiveEntryService method generateArchive.

@Override
public void generateArchive() {
    Map<String, ArchiveEntry> archiveEntryLookup = new HashMap<String, ArchiveEntry>();
    List<Post> posts;
    ArchiveEntry archiveEntry;
    Pager pager = PagerHelper.createDefaultPager();
    do {
        posts = PostServiceProvider.provide().getPosts(Boolean.FALSE, Boolean.FALSE, pager.start, pager.count, PostSortType.PostSortTypePublished, SortDirectionType.SortDirectionTypeDescending);
        if (posts != null) {
            PagerHelper.moveForward(pager);
            for (Post post : posts) {
                if (Boolean.TRUE.equals(post.listed) && post.published != null) {
                    Calendar c = ensureCalendar();
                    c.setTime(post.published);
                    Integer month = Integer.valueOf(c.get(java.util.Calendar.MONTH));
                    Integer year = Integer.valueOf(c.get(java.util.Calendar.YEAR));
                    String key = year + "/" + month;
                    if ((archiveEntry = archiveEntryLookup.get(key)) == null) {
                        archiveEntry = new ArchiveEntry().month(month).year(year).posts(new ArrayList<Post>());
                        archiveEntryLookup.put(key, archiveEntry);
                    }
                    archiveEntry.posts.add(post);
                }
            }
        }
    } while (posts != null && posts.size() >= pager.count.intValue());
    if (archiveEntryLookup.size() > 0) {
        addArchiveEntryBatch(archiveEntryLookup.values());
    }
}
Also used : HashMap(java.util.HashMap) Post(com.willshex.blogwt.shared.api.datatype.Post) Pager(com.willshex.blogwt.shared.api.Pager) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ArchiveEntry(com.willshex.blogwt.shared.api.datatype.ArchiveEntry)

Aggregations

Post (com.willshex.blogwt.shared.api.datatype.Post)52 JsonElement (com.google.gson.JsonElement)11 ArrayList (java.util.ArrayList)11 Pager (com.willshex.blogwt.shared.api.Pager)10 Key (com.googlecode.objectify.Key)8 Page (com.willshex.blogwt.shared.api.datatype.Page)7 Date (java.util.Date)6 InputValidationException (com.willshex.gson.web.service.server.InputValidationException)5 HashMap (java.util.HashMap)5 Tag (com.willshex.blogwt.shared.api.datatype.Tag)4 User (com.willshex.blogwt.shared.api.datatype.User)4 ArchiveEntry (com.willshex.blogwt.shared.api.datatype.ArchiveEntry)3 PostContent (com.willshex.blogwt.shared.api.datatype.PostContent)3 ScoredDocument (com.google.appengine.api.search.ScoredDocument)2 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)2 EditPageWizardPage (com.willshex.blogwt.client.wizard.page.EditPageWizardPage)2 SelectPostWizardPage (com.willshex.blogwt.client.wizard.page.SelectPostWizardPage)2 GetPostRequest (com.willshex.blogwt.shared.api.blog.call.GetPostRequest)2 MarkdownProcessor (org.markdown4j.server.MarkdownProcessor)2 Document (com.google.appengine.api.search.Document)1