Search in sources :

Example 16 with InputValidationException

use of com.willshex.gson.web.service.server.InputValidationException in project blogwt by billy1380.

the class FollowUsersActionHandler 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(FollowUsersRequest input, FollowUsersResponse output) throws Exception {
    PropertyValidator.ensureTrue(PropertyHelper.ALLOW_USER_REGISTRATION, PropertyHelper.ENABLE_USER_RELATIONSHIPS);
    ApiValidator.request(input, FollowUsersRequest.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-follow
                RelationshipServiceProvider.provide().deleteUsersRelationship(user, other, RelationshipTypeType.RelationshipTypeTypeFollow);
            } else {
                // follow
                added.add(RelationshipServiceProvider.provide().addUsersRelationship(user, other, RelationshipTypeType.RelationshipTypeTypeFollow));
            }
        } 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)

Example 17 with InputValidationException

use of com.willshex.gson.web.service.server.InputValidationException in project blogwt by billy1380.

the class ResetPasswordActionHandler 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(ResetPasswordRequest input, ResetPasswordResponse output) throws Exception {
    ApiValidator.request(input, ResetPasswordRequest.class);
    ApiValidator.accessCode(input.accessCode, "input.accessCode");
    if (input.session != null) {
        try {
            output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
        } catch (InputValidationException ex) {
            output.session = input.session = null;
        }
    }
    ApiValidator.notNull(input.email, String.class, "input.email");
    User user = UserServiceProvider.provide().getEmailUser(input.email);
    if (user == null)
        ApiValidator.throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, "String: input.email");
    UserServiceProvider.provide().resetPassword(user);
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Example 18 with InputValidationException

use of com.willshex.gson.web.service.server.InputValidationException in project blogwt by billy1380.

the class GeneratedDownloadValidator method lookup.

public static GeneratedDownload lookup(GeneratedDownload generatedDownload, String name) throws InputValidationException {
    if (generatedDownload == null)
        throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
    notNull(generatedDownload.id, Long.class, name + ".id");
    GeneratedDownload lookupGeneratedDownload = GeneratedDownloadServiceProvider.provide().getGeneratedDownload(generatedDownload.id);
    if (lookupGeneratedDownload == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupGeneratedDownload;
}
Also used : GeneratedDownload(com.willshex.blogwt.shared.api.datatype.GeneratedDownload) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Example 19 with InputValidationException

use of com.willshex.gson.web.service.server.InputValidationException in project blogwt by billy1380.

the class PageValidator method validate.

public static Page validate(Page page, String name) throws InputValidationException {
    if (page == null)
        throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
    List<Post> posts = new ArrayList<Post>();
    for (Post post : page.posts) {
        posts.add(PostValidator.lookup(post, name + ".posts[n]"));
    }
    page.posts = posts;
    if (page.parent != null) {
        page.parent = lookup(page.parent, name + ".parent");
    }
    page.owner = UserValidator.lookup(page.owner, name + ".owner");
    return page;
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post) ArrayList(java.util.ArrayList) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Example 20 with InputValidationException

use of com.willshex.gson.web.service.server.InputValidationException in project blogwt by billy1380.

the class PermissionValidator method lookup.

public static Permission lookup(Permission permission, String name) throws InputValidationException {
    if (permission == null)
        ApiValidator.throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
    boolean isIdLookup = false, isCodeLookup = false, isNameLookup = false;
    if (permission.id != null) {
        isIdLookup = true;
    } else if (permission.code != null) {
        isCodeLookup = true;
    }
    if (!(isIdLookup || isNameLookup || isCodeLookup))
        ApiValidator.throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    Permission lookupPermission = null;
    if (isIdLookup) {
        lookupPermission = PermissionServiceProvider.provide().getPermission(permission.id);
    } else if (isCodeLookup) {
        lookupPermission = PermissionServiceProvider.provide().getCodePermission(permission.code);
    }
    if (lookupPermission == null)
        ApiValidator.throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupPermission;
}
Also used : Permission(com.willshex.blogwt.shared.api.datatype.Permission) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Aggregations

InputValidationException (com.willshex.gson.web.service.server.InputValidationException)25 User (com.willshex.blogwt.shared.api.datatype.User)9 Post (com.willshex.blogwt.shared.api.datatype.Post)5 Permission (com.willshex.blogwt.shared.api.datatype.Permission)3 Property (com.willshex.blogwt.shared.api.datatype.Property)3 Relationship (com.willshex.blogwt.shared.api.datatype.Relationship)3 Key (com.googlecode.objectify.Key)2 Page (com.willshex.blogwt.shared.api.datatype.Page)2 Role (com.willshex.blogwt.shared.api.datatype.Role)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AuthorisationException (com.willshex.blogwt.server.api.exception.AuthorisationException)1 ArchiveEntry (com.willshex.blogwt.shared.api.datatype.ArchiveEntry)1 GeneratedDownload (com.willshex.blogwt.shared.api.datatype.GeneratedDownload)1 MetaNotification (com.willshex.blogwt.shared.api.datatype.MetaNotification)1 NotificationSetting (com.willshex.blogwt.shared.api.datatype.NotificationSetting)1 Rating (com.willshex.blogwt.shared.api.datatype.Rating)1 Resource (com.willshex.blogwt.shared.api.datatype.Resource)1 Session (com.willshex.blogwt.shared.api.datatype.Session)1 Tag (com.willshex.blogwt.shared.api.datatype.Tag)1