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