@CacheEvict(value = {"books", "apibook", "apibooks"}, allEntries = true) @RequestMapping(value = "/save", method = RequestMethod.POST, name = "saveBook") public String save(@Valid BookDTO bookDTO, BindingResult result, RedirectAttributes redirectAttributes) { if (result.hasErrors()) { return "register"; } else { try { Book book = bookFactory.createBook(bookDTO); bookRepositoryService.saveEntity(book); System.out.println("BookDao: Livro salvo com Sucesso! - " + book); redirectAttributes.addFlashAttribute("mensagem", "Livro cadastrado com sucesso"); redirectAttributes.addFlashAttribute("cssStyle", "alert alert-success"); } catch (UnexpectedTypeException ute) { System.err.println(ute.getMessage()); } catch (Exception e) { System.out.println(e.getMessage()); } return "redirect:books"; } }
@CacheEvict(value = {"books", "apibook", "apibooks"}, allEntries = true) @RequestMapping(value = "/update", method = RequestMethod.POST, name = "updateBook") public String update(@Valid BookDTO bookDTO, BindingResult result, RedirectAttributes redirectAttributes) { if (result.hasErrors()) { return "edit"; }else{ try { Book book = bookFactory.createBook(bookDTO); bookRepositoryService.updateEntity(book); System.out.println("BookDao: Livro atualizado com Sucesso! - " + book); redirectAttributes.addFlashAttribute("mensagem", "Livro atualizado com sucesso"); redirectAttributes.addFlashAttribute("cssStyle", "alert alert-success"); } catch (UnexpectedTypeException ute) { System.err.println(ute.getMessage()); } catch (Exception e) { System.out.println(e.getMessage()); } return "redirect:books"; } }
/** * Gets the best {@link ConstraintValidator}. * * <p> * The ConstraintValidator chosen to validate a declared type {@code targetType} is the one where * the type supported by the ConstraintValidator is a supertype of {@code targetType} and where * there is no other ConstraintValidator whose supported type is a supertype of {@code type} and * not a supertype of the chosen ConstraintValidator supported type. * </p> * * @param constraint the constraint to find ConstraintValidators for. * @param targetType The type to find a ConstraintValidator for. * @return ConstraintValidator * * @throws UnexpectedTypeException if there is not exactly one maximally specific constraint * validator for targetType. */ private static <A extends Annotation> Class<? extends ConstraintValidator<A, ?>> // getValidatorForType(final ConstraintDescriptor<A> constraint, final Class<?> targetType) throws UnexpectedTypeException { final List<Class<? extends ConstraintValidator<A, ?>>> constraintValidatorClasses = constraint.getConstraintValidatorClasses(); if (constraintValidatorClasses.isEmpty()) { throw new UnexpectedTypeException( "No ConstraintValidator found for " + constraint.getAnnotation()); } final ImmutableSet<Class<? extends ConstraintValidator<A, ?>>> best = getValidatorForType(targetType, constraintValidatorClasses); if (best.isEmpty()) { throw new UnexpectedTypeException( "No " + constraint.getAnnotation() + " ConstraintValidator for type " + targetType); } if (best.size() > 1) { throw new UnexpectedTypeException("More than one maximally specific " + constraint.getAnnotation() + " ConstraintValidator for type " + targetType + ", found " + Ordering.usingToString().sortedCopy(best)); } return Iterables.get(best, 0); }
private void addCDMProperty(CDMProperty property) { if (property instanceof CDMPrimitiveProperty) { addPrimitiveProperty((CDMPrimitiveProperty) property); } else if (property instanceof CDMReferenceProperty) { CDMReferenceProperty refProp = (CDMReferenceProperty) property; CanonicalDataType targetType = refProp.getTargetDataType(); ObjectResourceDefinition targetResourceDef = ObjectResourceDefinitionRegistry.INSTANCE .getResourceDefinition(targetType); if (targetResourceDef == null) { // there's no resource definition for this data type. Default to // embedded representation. addReferenceEmbed(refProp); } else { // if we have a resource definition, default to a reference // link. addReferenceLink(refProp); } } else { throw new UnexpectedTypeException("Unknown CDMProperty subtype."); } }
public void testConstraintValidatorResolutionAlgorithm() { MaxTestEntity entity = new MaxTestEntity(); entity.setText("101"); entity.setProperty("201"); entity.setLongValue(301); entity.setDecimalValue(new BigDecimal(401)); Set<ConstraintViolation<MaxTestEntity>> violations = validator.validate(entity); assertEquals(4, violations.size()); NoValidatorTestEntity entity2 = new NoValidatorTestEntity(); try { validator.validate(entity2); fail("UnexpectedTypeException expected but not thrown"); } catch (UnexpectedTypeException ex) { // we expected this assertEquals("No validator could be found for type java.lang.Object. " + "See: @Max at private java.lang.Object " + "org.apache.bval.jsr303.example." + "NoValidatorTestEntity.anything", ex.getMessage()); } }
public String getLinkHint() { if (isExternalLink()) { try { return new URL(link).getHost(); } catch (MalformedURLException e) { //this should never happened because constructor protected with design contract. throw new UnexpectedTypeException("malformed url"); } } else { return "/z/" + zone; } }
@Test public void shouldThrowUnexpectedTypeException() throws NoSuchMethodException, SecurityException { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); Constructor<AnnotationTargetTypeBean> constructor = AnnotationTargetTypeBean.class.getConstructor(); EXECUTABLE_VALIDATOR.validateConstructorReturnValue(constructor, new AnnotationTargetTypeBean()); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class FixedGreaterThanEqualsToTargetBean { @FixedGreaterThanEqualsTo("0.5") public Object value; } FixedGreaterThanEqualsToTargetBean target = new FixedGreaterThanEqualsToTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class RegexTargetBean { @Regex("(ok|OK)") public Object value; } RegexTargetBean target = new RegexTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class MinByteLengthTargetBean { @MinByteLength(100) public Object value; } MinByteLengthTargetBean target = new MinByteLengthTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class FixedBeforeTargetBean { @FixedBefore("2013/07/05") public Object value; } FixedBeforeTargetBean target = new FixedBeforeTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class DateFormatTargetBean { @DateFormat public Object value; } DateFormatTargetBean target = new DateFormatTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class ASCIITargetBean { @ASCII public Object value; } ASCIITargetBean target = new ASCIITargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class AlphamericTargetBean { @Alphameric public Object value; } AlphamericTargetBean target = new AlphamericTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class MaxLengthTargetBean { @MaxLength(5) public Object value; } MaxLengthTargetBean target = new MaxLengthTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class FixedAfterTargetBean { @FixedAfter("2013/07/04") public Object value; } FixedAfterTargetBean target = new FixedAfterTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class FixedLessThanTargetBean { @FixedLessThan("0.5") public Object value; } FixedLessThanTargetBean target = new FixedLessThanTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class EmailTargetBean { @Email public Object value; } EmailTargetBean target = new EmailTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class CreditCardTargetBean { @CreditCard(value = Type.VISA) public Object value; } CreditCardTargetBean target = new CreditCardTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class NumberTargetBean { @Number(precision = 2) public Object value; } NumberTargetBean target = new NumberTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class MaxSizeTargetBean { @MaxSize(5) public Object value; } MaxSizeTargetBean target = new MaxSizeTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class AlphabetTargetBean { @Alphabet public Object value; } AlphabetTargetBean target = new AlphabetTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class FixedAfterEqualsToTargetBean { @FixedAfterEqualsTo("2013/07/04") public Object value; } FixedAfterEqualsToTargetBean target = new FixedAfterEqualsToTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class FixedGreaterThanTargetBean { @FixedGreaterThan("0.5") public Object value; } FixedGreaterThanTargetBean target = new FixedGreaterThanTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class ZenkakuTargetBean { @Zenkaku public Object value; } ZenkakuTargetBean target = new ZenkakuTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class FixedBeforeEqualsToTargetBean { @FixedBeforeEqualsTo("2013/07/05") public Object value; } FixedBeforeEqualsToTargetBean target = new FixedBeforeEqualsToTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class MaxByteLengthTargetBean { @MaxByteLength(100) public Object value; } MaxByteLengthTargetBean target = new MaxByteLengthTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class NumericFormatTargetBean { @NumericFormat public Object value; } NumericFormatTargetBean target = new NumericFormatTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class HiraganaTargetBean { @Hiragana public Object value; } HiraganaTargetBean target = new HiraganaTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class DecimalTargetBean { @Decimal(precision = 2, scale = 0) public Object value; } DecimalTargetBean target = new DecimalTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class MinLengthTargetBean { @MinLength(5) public Object value; } MinLengthTargetBean target = new MinLengthTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class KatakanaTargetBean { @Katakana public Object value; } KatakanaTargetBean target = new KatakanaTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class ZipCodeTargetBean { @ZipCode public Object value; } ZipCodeTargetBean target = new ZipCodeTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class EqualsLengthTargetBean { @EqualsLength(100) public Object value; } EqualsLengthTargetBean target = new EqualsLengthTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class EqualsByteLengthTargetBean { @EqualsByteLength(value = 100) public Object value; } EqualsByteLengthTargetBean target = new EqualsByteLengthTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class FixedLessThanEqualsToTargetBean { @FixedLessThanEqualsTo("0.5") public Object value; } FixedLessThanEqualsToTargetBean target = new FixedLessThanEqualsToTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class MinSizeTargetBean { @MinSize(5) public Object value; } MinSizeTargetBean target = new MinSizeTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class IPv4TargetBean { @IPv4 public Object value; } IPv4TargetBean target = new IPv4TargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class HalfwidthKatakanaTargetBean { @HalfwidthKatakana public Object value; } HalfwidthKatakanaTargetBean target = new HalfwidthKatakanaTargetBean(); VALIDATOR.validate(target); }
@Test public void shouldThrowUnexpectedTypeException() { thrown.expect(UnexpectedTypeException.class); thrown.expectMessage(containsString("HV000030")); class EqualsSizeTargetBean { @EqualsSize(5) public Object value; } EqualsSizeTargetBean target = new EqualsSizeTargetBean(); VALIDATOR.validate(target); }