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