use of org.summerb.validation.ValidationContext in project summerb by skarpushin.
the class UserServiceImpl method validateEmail.
private void validateEmail(String email) throws FieldValidationException {
ValidationContext ctx = new ValidationContext();
validateEmail(email, ctx);
ctx.throwIfHasErrors();
}
use of org.summerb.validation.ValidationContext in project summerb by skarpushin.
the class StringTemplateValidationUtilsTest method testValidateStringTemplate_blackbox_expectOkForConstant.
@Test
public void testValidateStringTemplate_blackbox_expectOkForConstant() throws Exception {
StringTemplateCompiler stringTemplateCompiler = new StringTemplateCompilerlImpl();
String stringTemplate = "Constant text";
ValidationContext ctx = new ValidationContext();
String fieldToken = "fieldToken";
StringTemplateValidationUtils.validateStringTemplate(stringTemplateCompiler, stringTemplate, ctx, fieldToken);
assertEquals(false, ctx.getHasErrors());
}
use of org.summerb.validation.ValidationContext in project summerb by skarpushin.
the class UsersServiceFacadeImpl method getUserStatusByEmail.
@Override
public UserStatus getUserStatusByEmail(String email) throws FieldValidationException {
ValidationContext ctx = new ValidationContext();
ctx.validateNotEmpty(email, LoginParams.FN_EMAIL);
ctx.throwIfHasErrors();
// Check if user have record
User user = null;
try {
user = userService.getUserByEmail(email);
} catch (UserNotFoundException nfe) {
return UserStatus.NotExists;
}
// Check if user has ROLE_USER
List<String> permissions = permissionService.findUserPermissionsForSubject(SecurityConstants.DOMAIN, user.getUuid(), null);
if (permissions.contains(SecurityConstants.ROLE_USER)) {
return UserStatus.NormalUser;
}
if (permissions.contains(SecurityConstants.MARKER_AWAITING_ACTIVATION)) {
return UserStatus.AwaitingActivation;
}
return UserStatus.Provisioned;
}
use of org.summerb.validation.ValidationContext in project summerb by skarpushin.
the class DaoExceptionToFveTranslatorPostgresImpl method throwIfDuplicate.
private void throwIfDuplicate(Throwable t) throws FieldValidationException {
DuplicateKeyException dke = ExceptionUtils.findExceptionOfType(t, DuplicateKeyException.class);
if (dke == null) {
return;
}
PSQLException dkep = ExceptionUtils.findExceptionOfType(t, PSQLException.class);
if (dkep == null) {
return;
}
String detail = dkep.getServerErrorMessage().getDetail();
if (!StringUtils.hasText(detail)) {
return;
}
if (!detail.startsWith("Key (")) {
return;
}
String fieldsStr = detail.substring(5, detail.indexOf(")"));
String[] fields = fieldsStr.split(",");
ValidationContext ctx = new ValidationContext();
for (String field : fields) {
ctx.add(new DuplicateRecordValidationError(JdbcUtils.convertUnderscoreNameToPropertyName(field.trim())));
}
ctx.throwIfHasErrors();
}
Aggregations