Search in sources :

Example 21 with InputValidationException

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

the class PostValidator method lookup.

public static Post lookup(Post post, String name) throws InputValidationException {
    if (post == null)
        throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
    boolean isIdLookup = false, isSlugLookup = false;
    if (post.id != null) {
        isIdLookup = true;
    } else if (post.slug != null) {
        isSlugLookup = true;
    }
    if (!(isIdLookup || isSlugLookup))
        throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    Post lookupPost;
    if (isIdLookup) {
        lookupPost = PostServiceProvider.provide().getPost(post.id);
    } else {
        lookupPost = PostServiceProvider.provide().getSlugPost(post.slug);
    }
    if (lookupPost == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupPost;
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Example 22 with InputValidationException

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

the class PropertyValidator method lookup.

public static Property lookup(Property property, String name) throws InputValidationException {
    if (property == null)
        ApiValidator.throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
    boolean isIdLookup = false, isNameLookup = false;
    if (property.id != null) {
        isIdLookup = true;
    } else if (property.name != null) {
        isNameLookup = true;
    }
    if (!(isIdLookup || isNameLookup))
        ApiValidator.throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    Property lookupProperty;
    if (isIdLookup) {
        lookupProperty = PropertyServiceProvider.provide().getProperty(property.id);
    } else {
        lookupProperty = PropertyServiceProvider.provide().getNamedProperty(property.name);
    }
    if (lookupProperty == null)
        ApiValidator.throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupProperty;
}
Also used : InputValidationException(com.willshex.gson.web.service.server.InputValidationException) Property(com.willshex.blogwt.shared.api.datatype.Property)

Example 23 with InputValidationException

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

the class RatingValidator method lookup.

public static Rating lookup(Rating rating, String name) throws InputValidationException {
    if (rating == null)
        throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
    boolean isIdLookup = false;
    if (rating.id != null) {
        isIdLookup = true;
    }
    if (!isIdLookup)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    Rating lookupRating = null;
    if (isIdLookup) {
        lookupRating = RatingServiceProvider.provide().getRating(rating.id);
    }
    if (lookupRating == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupRating;
}
Also used : Rating(com.willshex.blogwt.shared.api.datatype.Rating) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Example 24 with InputValidationException

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

the class RoleValidator method lookup.

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

Example 25 with InputValidationException

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

the class UserValidator method validate.

public static User validate(User user, String name) throws InputValidationException {
    boolean foundUsername = false, foundEmail = false;
    if (user.username != null) {
        validateLength(user.username, 1, 512, TYPE + ": " + name + "[" + user.username + "].username");
        foundUsername = true;
    }
    if (user.email != null) {
        validateLength(user.email, 1, 512, TYPE + ": " + name + "[" + user.email + "].email");
        foundEmail = true;
    }
    if (foundUsername) {
        User existingUsernameUser = UserServiceProvider.provide().getUsernameUser(user.username);
        if (existingUsernameUser != null && !DataTypeHelper.<User>same(user, existingUsernameUser))
            throwServiceError(InputValidationException.class, ApiError.UsernameInUse, "String: " + name + ".username");
    }
    if (foundEmail) {
        User existingEmailUser = UserServiceProvider.provide().getEmailUser(user.email);
        if (existingEmailUser != null && !DataTypeHelper.<User>same(user, existingEmailUser))
            throwServiceError(InputValidationException.class, ApiError.EmailInUse, "String: " + name + ".email");
    }
    if (!(foundUsername || foundEmail))
        throwServiceError(InputValidationException.class, ApiError.NotEnoughData, TYPE + ": no username or email in " + name);
    return user;
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User) 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