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