Search in sources :

Example 1 with Page

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

the class EditPagePage method onAttach.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.client.page.Page#onAttach() */
@Override
protected void onAttach() {
    register(DefaultEventBus.get().addHandlerToSource(NavigationChangedEventHandler.TYPE, NavigationController.get(), (p, c) -> {
        String action = c.getAction();
        if (action != null && "new".equalsIgnoreCase(action)) {
            setPlan((new PagePlanBuilder()).addPage(new EditPageWizardPage()).addPage(new SelectPostWizardPage()).setName("New Page").addFinishedHandler(this).build());
        } else {
            Page page = null;
            if (c.getParameterCount() >= 1) {
                switch(c.getAction()) {
                    case "id":
                        (page = new Page()).id(Long.valueOf(c.getParameter(0)));
                        break;
                    case "slug":
                        page = new Page().slug(c.getParameter(0));
                        break;
                }
            } else {
                page = new Page().slug(c.getAction());
            }
            if (page != null) {
                PageController.get().getPage(page, true);
            }
        }
    }));
    register(DefaultEventBus.get().addHandlerToSource(CreatePageEventHandler.TYPE, PageController.get(), this));
    register(DefaultEventBus.get().addHandlerToSource(GetPageEventHandler.TYPE, PageController.get(), this));
    register(DefaultEventBus.get().addHandlerToSource(UpdatePageEventHandler.TYPE, PageController.get(), this));
    super.onAttach();
}
Also used : UpdatePageResponse(com.willshex.blogwt.shared.api.page.call.UpdatePageResponse) Page(com.willshex.blogwt.shared.api.datatype.Page) PagePlanBuilder(com.willshex.blogwt.client.wizard.PagePlan.PagePlanBuilder) NavigationChangedEventHandler(com.willshex.blogwt.client.event.NavigationChangedEventHandler) CreatePageEventHandler(com.willshex.blogwt.client.api.page.event.CreatePageEventHandler) UpdatePageEventHandler(com.willshex.blogwt.client.api.page.event.UpdatePageEventHandler) GWT(com.google.gwt.core.client.GWT) ArrayList(java.util.ArrayList) PageType(com.willshex.blogwt.shared.page.PageType) CreatePageResponse(com.willshex.blogwt.shared.api.page.call.CreatePageResponse) GetPageResponse(com.willshex.blogwt.shared.api.page.call.GetPageResponse) Post(com.willshex.blogwt.shared.api.datatype.Post) StatusType(com.willshex.gson.web.service.shared.StatusType) EditPageWizardPage(com.willshex.blogwt.client.wizard.page.EditPageWizardPage) WizardPage(com.willshex.blogwt.client.wizard.WizardPage) UpdatePageRequest(com.willshex.blogwt.shared.api.page.call.UpdatePageRequest) GetPageRequest(com.willshex.blogwt.shared.api.page.call.GetPageRequest) CreatePageRequest(com.willshex.blogwt.shared.api.page.call.CreatePageRequest) PageController(com.willshex.blogwt.client.controller.PageController) GetPageEventHandler(com.willshex.blogwt.client.api.page.event.GetPageEventHandler) List(java.util.List) PagePlanFinishedHandler(com.willshex.blogwt.client.wizard.PagePlanFinishedHandler) WizardDialogPage(com.willshex.blogwt.client.page.wizard.WizardDialogPage) NavigationController(com.willshex.blogwt.client.controller.NavigationController) DefaultEventBus(com.willshex.blogwt.client.DefaultEventBus) SelectPostWizardPage(com.willshex.blogwt.client.wizard.page.SelectPostWizardPage) PageTypeHelper(com.willshex.blogwt.client.helper.PageTypeHelper) SelectPostWizardPage(com.willshex.blogwt.client.wizard.page.SelectPostWizardPage) PagePlanBuilder(com.willshex.blogwt.client.wizard.PagePlan.PagePlanBuilder) EditPageWizardPage(com.willshex.blogwt.client.wizard.page.EditPageWizardPage) Page(com.willshex.blogwt.shared.api.datatype.Page) EditPageWizardPage(com.willshex.blogwt.client.wizard.page.EditPageWizardPage) WizardPage(com.willshex.blogwt.client.wizard.WizardPage) WizardDialogPage(com.willshex.blogwt.client.page.wizard.WizardDialogPage) SelectPostWizardPage(com.willshex.blogwt.client.wizard.page.SelectPostWizardPage)

Example 2 with Page

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

the class EditPageWizardPage method getData.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.client.wizard.WizardPage#getData() */
@Override
public Page getData() {
    if (page == null) {
        page = new Page();
    }
    if (page.owner == null) {
        page.owner = SessionController.get().user();
    }
    if (cbxHasParent.getValue().booleanValue()) {
        (page.parent = new Page()).slug(txtParentPage.getValue());
    } else {
        page.parent = null;
    }
    if (cbxHasPriority.getValue().booleanValue()) {
        page.priority = Float.valueOf(txtPriority.getValue());
    } else {
        page.priority = null;
    }
    page.title = txtTitle.getValue();
    page.slug = PostHelper.slugify(page.title);
    return page;
}
Also used : Page(com.willshex.blogwt.shared.api.datatype.Page) WizardPage(com.willshex.blogwt.client.wizard.WizardPage)

Example 3 with Page

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

the class UpdatePageActionHandler method handle.

/* (non-Javadoc)
	 * 
	 * @see
	 * com.willshex.gson.web.service.server.ActionHandler#handle(com.willshex.
	 * gson.web.service.shared.Request,
	 * com.willshex.gson.web.service.shared.Response) */
@Override
protected void handle(UpdatePageRequest input, UpdatePageResponse output) throws Exception {
    ApiValidator.request(input, UpdatePageRequest.class);
    ApiValidator.accessCode(input.accessCode, "input.accessCode");
    output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
    List<Permission> permissions = new ArrayList<Permission>();
    Permission postPermission = PermissionServiceProvider.provide().getCodePermission(PermissionHelper.MANAGE_PAGES);
    permissions.add(postPermission);
    UserValidator.authorisation(input.session.user, permissions, "input.session.user");
    Page updatedPage = input.page;
    input.page = PageValidator.lookup(input.page, "input.page");
    updatedPage = PageValidator.validate(updatedPage, "input.page");
    input.page.hasChildren = updatedPage.hasChildren;
    input.page.parent = updatedPage.parent;
    input.page.posts = updatedPage.posts;
    input.page.priority = updatedPage.priority;
    input.page.title = updatedPage.title;
    input.page.slug = PostHelper.slugify(input.page.title);
    output.page = PageServiceProvider.provide().updatePage(input.page);
}
Also used : Permission(com.willshex.blogwt.shared.api.datatype.Permission) ArrayList(java.util.ArrayList) Page(com.willshex.blogwt.shared.api.datatype.Page)

Example 4 with Page

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

the class SearchAllActionHandler method handle.

/* (non-Javadoc)
	 * 
	 * @see
	 * com.willshex.gson.web.service.server.ActionHandler#handle(com.willshex.
	 * gson.web.service.shared.Request,
	 * com.willshex.gson.web.service.shared.Response) */
@SuppressWarnings("unchecked")
@Override
protected void handle(SearchAllRequest input, SearchAllResponse output) throws Exception {
    ApiValidator.request(input, SearchAllRequest.class);
    ApiValidator.accessCode(input.accessCode, "input.accessCode");
    try {
        output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
    } catch (InputValidationException ex) {
        output.session = input.session = null;
    }
    if (input.query == null)
        ApiValidator.throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, "String: input.query");
    output.posts = ((ISearch<Post>) PostServiceProvider.provide()).search(input.query, Integer.valueOf(0), SearchHelper.SHORT_SEARCH_LIMIT, null, null);
    Map<Key<User>, User> users = new HashMap<Key<User>, User>();
    if (output.posts != null) {
        for (Post post : output.posts) {
            if (users.get(post.authorKey) == null) {
                users.put(post.authorKey, UserServiceProvider.provide().getUser(keyToId(post.authorKey)));
            }
            post.author = users.get(post.authorKey);
        }
    }
    output.pages = ((ISearch<Page>) PageServiceProvider.provide()).search(input.query, Integer.valueOf(0), SearchHelper.SHORT_SEARCH_LIMIT, null, null);
    if (output.pages != null) {
        for (Page page : output.pages) {
            if (users.get(page.ownerKey) == null) {
                users.put(page.ownerKey, UserServiceProvider.provide().getUser(keyToId(page.ownerKey)));
            }
            page.owner = users.get(page.ownerKey);
        }
    }
    output.users = ((ISearch<User>) UserServiceProvider.provide()).search(input.query, Integer.valueOf(0), SearchHelper.SHORT_SEARCH_LIMIT, null, null);
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User) HashMap(java.util.HashMap) Post(com.willshex.blogwt.shared.api.datatype.Post) InputValidationException(com.willshex.gson.web.service.server.InputValidationException) Page(com.willshex.blogwt.shared.api.datatype.Page) Key(com.googlecode.objectify.Key)

Example 5 with Page

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

the class PageValidator method lookup.

public static Page lookup(Page page, String name) throws InputValidationException {
    if (page == null)
        throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
    boolean isIdLookup = false, isSlugLookup = false;
    if (page.id != null) {
        isIdLookup = true;
    } else if (page.slug != null) {
        isSlugLookup = true;
    }
    if (!(isIdLookup || isSlugLookup))
        throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    Page lookupPage;
    if (isIdLookup) {
        lookupPage = PageServiceProvider.provide().getPage(page.id);
    } else {
        lookupPage = PageServiceProvider.provide().getSlugPage(page.slug, Boolean.FALSE);
    }
    if (lookupPage == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupPage;
}
Also used : InputValidationException(com.willshex.gson.web.service.server.InputValidationException) Page(com.willshex.blogwt.shared.api.datatype.Page)

Aggregations

Page (com.willshex.blogwt.shared.api.datatype.Page)28 JsonElement (com.google.gson.JsonElement)10 Post (com.willshex.blogwt.shared.api.datatype.Post)9 ArrayList (java.util.ArrayList)6 User (com.willshex.blogwt.shared.api.datatype.User)4 HashMap (java.util.HashMap)4 Pager (com.willshex.blogwt.shared.api.Pager)3 GetPageRequest (com.willshex.blogwt.shared.api.page.call.GetPageRequest)3 GWT (com.google.gwt.core.client.GWT)2 Element (com.google.gwt.dom.client.Element)2 Key (com.googlecode.objectify.Key)2 DefaultEventBus (com.willshex.blogwt.client.DefaultEventBus)2 GetPageEventHandler (com.willshex.blogwt.client.api.page.event.GetPageEventHandler)2 NavigationController (com.willshex.blogwt.client.controller.NavigationController)2 PageController (com.willshex.blogwt.client.controller.PageController)2 NavigationChangedEventHandler (com.willshex.blogwt.client.event.NavigationChangedEventHandler)2 PageTypeHelper (com.willshex.blogwt.client.helper.PageTypeHelper)2 WizardDialogPage (com.willshex.blogwt.client.page.wizard.WizardDialogPage)2 WizardPage (com.willshex.blogwt.client.wizard.WizardPage)2 InputValidationException (com.willshex.gson.web.service.server.InputValidationException)2