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