Search in sources :

Example 1 with User

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

the class EditPostPage method updatePreview.

private void updatePreview() {
    pnlPreview.getElement().removeAllChildren();
    Document d = Document.get();
    HeadingElement title = d.createHElement(1);
    title.setInnerHTML(PostHelper.makeHeading(txtTitle.getValue()));
    pnlPreview.getElement().appendChild(title);
    User user = SessionController.get().user();
    DivElement elDate = d.createDivElement();
    if (post != null) {
        if (post.published == null) {
            elDate.setInnerSafeHtml(PostSummaryCell.Templates.INSTANCE.notPublished(DateTimeHelper.ago(post.created)));
        } else {
            elDate.setInnerSafeHtml(PostSummaryCell.Templates.INSTANCE.publishedDate(DateTimeHelper.ago(post.published)));
        }
    } else {
        elDate.setInnerSafeHtml(PostSummaryCell.Templates.INSTANCE.notPublished(DateTimeHelper.ago(new Date())));
    }
    pnlPreview.getElement().appendChild(elDate);
    DivElement elAuthor = d.createDivElement();
    if (PropertyController.get().booleanProperty(PropertyHelper.POST_SHOW_AUTHOR, false)) {
        elAuthor.setInnerSafeHtml(PostSummaryCell.Templates.INSTANCE.author(UriUtils.fromString((post != null ? post.author.avatar : user.avatar) + "?s=" + UserHelper.AVATAR_HEADER_SIZE + "&default=retro"), UserHelper.handle((post != null ? post.author : user))));
    }
    pnlPreview.getElement().appendChild(elAuthor);
    tagList.getList().clear();
    List<String> tags = TagHelper.convertToTagList(txtTags.getValue());
    if (tags != null) {
        for (String tag : tags) {
            tagList.getList().add(new Tag().name(tag));
        }
    }
    DivElement summary = d.createDivElement();
    summary.setInnerHTML(markup(txtSummary));
    pnlPreview.getElement().appendChild(summary);
    DivElement content = d.createDivElement();
    content.setInnerHTML(markup(txtContent));
    pnlPreview.getElement().appendChild(content);
}
Also used : DivElement(com.google.gwt.dom.client.DivElement) User(com.willshex.blogwt.shared.api.datatype.User) HeadingElement(com.google.gwt.dom.client.HeadingElement) Tag(com.willshex.blogwt.shared.api.datatype.Tag) Document(com.google.gwt.dom.client.Document) Date(java.util.Date)

Example 2 with User

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

the class ChangeDetailsPage method onUpdateClicked.

@UiHandler("btnUpdate")
void onUpdateClicked(ClickEvent ce) {
    if (isValid()) {
        loading();
        User user = new User().username(txtUsername.getText()).forename(txtForename.getText()).surname(txtSurname.getText()).email(txtEmail.getText()).summary(txtSummary.getValue());
        if (this.user == null) {
            user.password(txtPassword.getText());
            UserController.get().registerUser(user);
        } else {
            user.id(this.user.id);
            UserController.get().changeUserDetails(user);
        }
    } else {
        showErrors();
    }
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User) UiHandler(com.google.gwt.uibinder.client.UiHandler)

Example 3 with User

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

the class DeleteGeneratedDownloadsActionHandler method handle.

@Override
public void handle(DeleteGeneratedDownloadsRequest input, DeleteGeneratedDownloadsResponse output) throws Exception {
    ApiValidator.notNull(input, DeleteGeneratedDownloadsRequest.class, "input");
    ApiValidator.accessCode(input.accessCode, "input.accessCode");
    output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
    PropertyValidator.ensureTrue(PropertyHelper.DOWNLOAD_ENABLED);
    input.downloads = GeneratedDownloadValidator.lookupAll(input.downloads, "input.downloads");
    for (GeneratedDownload download : input.downloads) {
        if (download.status == GeneratedDownloadStatusType.GeneratedDownloadStatusTypeGenerating) {
            if (LOG.isLoggable(Level.WARNING)) {
                LOG.log(Level.WARNING, "Attempting to delete generated download [" + download.id + "] while it is generating. Skipping deletion.");
            }
        } else {
            if (DataTypeHelper.<User>same(download.userKey, input.session.user)) {
                GeneratedDownloadServiceProvider.provide().deleteGeneratedDownload(download);
            } else {
                if (LOG.isLoggable(Level.INFO)) {
                    LOG.log(Level.INFO, "Attempting to delete generated download [" + download.id + "] for user with id [" + download.userKey.getId() + "] out of session, current session belongs to user with id [" + input.session.user.id + "]");
                }
            }
        }
    }
}
Also used : GeneratedDownload(com.willshex.blogwt.shared.api.datatype.GeneratedDownload) User(com.willshex.blogwt.shared.api.datatype.User)

Example 4 with User

use of com.willshex.blogwt.shared.api.datatype.User 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 User

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

the class BlockUsersActionHandler 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(BlockUsersRequest input, BlockUsersResponse output) throws Exception {
    PropertyValidator.ensureTrue(PropertyHelper.ALLOW_USER_REGISTRATION, PropertyHelper.ENABLE_USER_RELATIONSHIPS);
    ApiValidator.request(input, BlockUsersRequest.class);
    ApiValidator.accessCode(input.accessCode, "input.accessCode");
    output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
    User user = null;
    if (input.user == null) {
        user = input.session.user;
    } else {
        user = input.user;
        UserValidator.validate(user, "input.user");
        if (!DataTypeHelper.<User>same(user, input.session.user)) {
            UserValidator.authorisation(input.session.user, Arrays.asList(PermissionServiceProvider.provide().getCodePermission(PermissionHelper.MANAGE_USERS)), "input.session.user");
        }
    }
    ApiValidator.notNull(input.others, User.class, "input.others");
    List<Relationship> added = null;
    if (!Boolean.TRUE.equals(input.un)) {
        added = new ArrayList<Relationship>();
    }
    for (User other : input.others) {
        try {
            // validate each user
            other = UserValidator.validate(other, "input.other[n]");
            // add a relationship for the validated users (skip failures)
            if (Boolean.TRUE.equals(input.un)) {
                // un-block
                RelationshipServiceProvider.provide().deleteUsersRelationship(user, other, RelationshipTypeType.RelationshipTypeTypeBlock);
            } else {
                // block
                added.add(RelationshipServiceProvider.provide().addUsersRelationship(user, other, RelationshipTypeType.RelationshipTypeTypeBlock));
            }
        } catch (InputValidationException inEx) {
        // just skip that user if the user is not valid
        }
    }
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User) Relationship(com.willshex.blogwt.shared.api.datatype.Relationship) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Aggregations

User (com.willshex.blogwt.shared.api.datatype.User)46 JsonElement (com.google.gson.JsonElement)19 InputValidationException (com.willshex.gson.web.service.server.InputValidationException)10 Pager (com.willshex.blogwt.shared.api.Pager)6 Permission (com.willshex.blogwt.shared.api.datatype.Permission)5 Page (com.willshex.blogwt.shared.api.datatype.Page)4 Post (com.willshex.blogwt.shared.api.datatype.Post)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Key (com.googlecode.objectify.Key)3 Role (com.willshex.blogwt.shared.api.datatype.Role)3 Date (java.util.Date)3 HeadingElement (com.google.gwt.dom.client.HeadingElement)2 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)2 UiHandler (com.google.gwt.uibinder.client.UiHandler)2 MetaNotification (com.willshex.blogwt.shared.api.datatype.MetaNotification)2 Relationship (com.willshex.blogwt.shared.api.datatype.Relationship)2 BlobKey (com.google.appengine.api.blobstore.BlobKey)1 ScoredDocument (com.google.appengine.api.search.ScoredDocument)1 JsonObject (com.google.gson.JsonObject)1