Search in sources :

Example 1 with InputValidationException

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

the class UpdatePropertiesActionHandler 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(UpdatePropertiesRequest input, UpdatePropertiesResponse output) throws Exception {
    ApiValidator.request(input, UpdatePropertiesRequest.class);
    ApiValidator.accessCode(input.accessCode, "input.accessCode");
    output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
    UserValidator.authorisation(input.session.user, null, "input.session.user");
    List<Property> updatedProperties = PropertyValidator.validateAll(input.properties, "input.properties");
    Property existingProperty = null;
    boolean found;
    for (Property property : updatedProperties) {
        found = false;
        try {
            existingProperty = PropertyValidator.lookup(property, "input.properties[n]");
            found = true;
        } catch (InputValidationException ex) {
            if (LOG.isLoggable(Level.INFO)) {
                LOG.info("Property [" + property.name + "] does not exist. Will add with value [" + property.value + "].");
            }
        }
        if (found) {
            existingProperty.value = property.value;
            PropertyServiceProvider.provide().updateProperty(existingProperty);
        } else {
            PropertyServiceProvider.provide().addProperty(property);
        }
    }
}
Also used : InputValidationException(com.willshex.gson.web.service.server.InputValidationException) Property(com.willshex.blogwt.shared.api.datatype.Property)

Example 2 with InputValidationException

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

the class SessionValidator method lookup.

/**
 * @param session
 * @param name
 * @return
 * @throws InputValidationException
 */
public static Session lookup(Session session, String name) throws InputValidationException {
    if (session == null)
        throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
    boolean isIdLookup = false;
    if (session.id != null) {
        isIdLookup = true;
    }
    if (!isIdLookup)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    Session lookupSession = null;
    if (isIdLookup) {
        lookupSession = SessionServiceProvider.provide().getSession(session.id);
    }
    if (lookupSession == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupSession;
}
Also used : InputValidationException(com.willshex.gson.web.service.server.InputValidationException) Session(com.willshex.blogwt.shared.api.datatype.Session)

Example 3 with InputValidationException

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

the class RegisterUserActionHandler 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(RegisterUserRequest input, RegisterUserResponse output) throws Exception {
    ApiValidator.request(input, RegisterUserRequest.class);
    ApiValidator.accessCode(input.accessCode, "input.accessCode");
    if (input.session != null) {
        try {
            output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
            UserValidator.authorisation(input.session.user, Arrays.asList(PermissionServiceProvider.provide().getCodePermission(PermissionHelper.MANAGE_USERS)), "input.session.user");
        } catch (InputValidationException ex) {
            output.session = input.session = null;
        }
    } else {
        PropertyValidator.ensureTrue(PropertyHelper.ALLOW_USER_REGISTRATION);
    }
    input.user = UserValidator.validate(input.user, "input.user");
    List<String> codes;
    List<Permission> permissions = null;
    Property property = PropertyServiceProvider.provide().getNamedProperty(PropertyHelper.NEW_USER_PERMISSIONS);
    if (!PropertyHelper.isEmpty(property) && !PropertyHelper.NONE_VALUE.equals(property.value)) {
        codes = TagHelper.convertToTagList(property.value, true);
        for (String code : codes) {
            if (permissions == null) {
                permissions = new ArrayList<Permission>();
            }
            permissions.add(new Permission().code(code.toUpperCase()));
        }
        permissions = PermissionValidator.lookupAll(permissions, PropertyHelper.NEW_USER_PERMISSIONS);
    }
    List<Role> roles = null;
    property = PropertyServiceProvider.provide().getNamedProperty(PropertyHelper.NEW_USER_ROLES);
    if (!PropertyHelper.isEmpty(property) && !PropertyHelper.NONE_VALUE.equals(property.value)) {
        codes = TagHelper.convertToTagList(property.value, true);
        for (String code : codes) {
            if (roles == null) {
                roles = new ArrayList<Role>();
            }
            roles.add(new Role().code(code.toUpperCase()));
        }
        roles = RoleValidator.lookupAll(roles, PropertyHelper.NEW_USER_ROLES);
    }
    input.user.permissions = permissions;
    input.user.roles = roles;
    output.user = UserServiceProvider.provide().addUser(input.user);
    UserServiceProvider.provide().verifyAccount(output.user);
}
Also used : Role(com.willshex.blogwt.shared.api.datatype.Role) Permission(com.willshex.blogwt.shared.api.datatype.Permission) InputValidationException(com.willshex.gson.web.service.server.InputValidationException) Property(com.willshex.blogwt.shared.api.datatype.Property)

Example 4 with InputValidationException

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

the class ArchiveEntryValidator method lookup.

public static ArchiveEntry lookup(ArchiveEntry archiveEntry, String name) throws InputValidationException {
    if (archiveEntry == null)
        throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
    boolean isIdLookup = false, isYearMonthLookup = false;
    if (archiveEntry.id != null) {
        isIdLookup = true;
    } else if (archiveEntry.year != null && archiveEntry.month != null) {
        isYearMonthLookup = true;
    }
    if (!(isIdLookup || isYearMonthLookup))
        throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    ArchiveEntry lookupArchiveEntry = null;
    if (isIdLookup) {
        lookupArchiveEntry = ArchiveEntryServiceProvider.provide().getArchiveEntry(archiveEntry.id);
    } else if (isYearMonthLookup) {
        lookupArchiveEntry = ArchiveEntryServiceProvider.provide().getMonthArchiveEntry(archiveEntry.month, archiveEntry.year);
    }
    if (lookupArchiveEntry == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupArchiveEntry;
}
Also used : InputValidationException(com.willshex.gson.web.service.server.InputValidationException) ArchiveEntry(com.willshex.blogwt.shared.api.datatype.ArchiveEntry)

Example 5 with InputValidationException

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

the class MetaNotificationValidator method lookup.

public static MetaNotification lookup(MetaNotification metaNotification, String name) throws InputValidationException {
    notNull(metaNotification, CLASS, name);
    boolean isIdLookup = false, isCodeLookup = false;
    if (metaNotification.id != null) {
        isIdLookup = true;
    } else if (metaNotification.code != null) {
        isCodeLookup = true;
    }
    if (!(isIdLookup || isCodeLookup))
        throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    MetaNotification lookupMetaNotification = null;
    if (isIdLookup) {
        lookupMetaNotification = MetaNotificationServiceProvider.provide().getMetaNotification(metaNotification.id);
    } else if (isCodeLookup) {
        lookupMetaNotification = MetaNotificationServiceProvider.provide().getCodeMetaNotification(metaNotification.code);
    }
    if (lookupMetaNotification == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupMetaNotification;
}
Also used : InputValidationException(com.willshex.gson.web.service.server.InputValidationException) MetaNotification(com.willshex.blogwt.shared.api.datatype.MetaNotification)

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 ISearch (com.willshex.blogwt.server.service.search.ISearch)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