br.com.caelum.vraptor.validator.Validator Java Examples

The following examples show how to use br.com.caelum.vraptor.validator.Validator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MethodValidator.java    From vraptor4 with Apache License 2.0 6 votes vote down vote up
public void validate(@Observes MethodReady event, ControllerInstance controllerInstance, MethodInfo methodInfo, 
		Validator validator) {
	ControllerMethod method = event.getControllerMethod();

	if (hasConstraints(method)) {
		Set<ConstraintViolation<Object>> violations = bvalidator.forExecutables().validateParameters(
				controllerInstance.getController(), method.getMethod(), methodInfo.getParametersValues());

		logger.debug("there are {} constraint violations at method {}.", violations.size(), method);

		for (ConstraintViolation<Object> v : violations) {
			String category = extractCategory(methodInfo.getValuedParameters(), v);
			String msg = extractInternacionalizedMessage(v);
			validator.add(new SimpleMessage(category, msg));
			logger.debug("added message {}={} for contraint violation", category, msg);
		}
	}
}
 
Example #2
Source File: OpenOccurrenceController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
protected void verifyIfSelectedProblemType(Occurrence occurrence,
		Validator validator) {
	if (occurrence.getProblemType() == null
			|| occurrence.getProblemType().getId() == null) {
		validator
				.add(new SimpleMessage("occurrence.problemType", validationBundle
						.getString("occurrence.problemType.required")));
	}
}
 
Example #3
Source File: SectorController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Post("/insert")
public void insert(@Valid Sector sector, Validator validator) {
    validator.onErrorForwardTo(SectorController.class).form();

    sectorBean.insert(sector);
    result.include("message", messagesBundle.getString("insert.success"));
    result.redirectTo(SectorController.class).list();
}
 
Example #4
Source File: BrutalDateTimeConverter.java    From mamute with Apache License 2.0 5 votes vote down vote up
@Inject
public BrutalDateTimeConverter(Locale locale, Validator validator, MessageFactory messageFactory, BundleFormatter bundle)
{
	super(locale);
	this.validator = validator;
	this.messageFactory = messageFactory;
	this.bundle = bundle;
}
 
Example #5
Source File: BrutalValidator.java    From mamute with Apache License 2.0 5 votes vote down vote up
@Inject
public BrutalValidator(javax.validation.Validator javaxValidator,
		Validator validator, MessageFactory factory) {
	this.javaxValidator = javaxValidator;
	this.validator = validator;
	this.factory = factory;
}
 
Example #6
Source File: SignupValidatorTest.java    From mamute with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    validator = new MockValidator();
    messageFactory = new MessageFactory(bundle);
    emailValidator = new EmailValidator(validator, users, messageFactory);
    javax.validation.Validator javaxValidator = Validation.buildDefaultValidatorFactory().getValidator();
    BrutalValidator brutalValidator = new BrutalValidator(javaxValidator, validator, messageFactory);
    userValidator = new UserValidator(validator, emailValidator, messageFactory, brutalValidator);
    signupValidator = new SignupValidator(validator, userValidator, messageFactory, users);
    when(users.existsWithEmail(VALID_EMAIL)).thenReturn(false);
    when(users.existsWithName(VALID_USER_NAME)).thenReturn(false);
}
 
Example #7
Source File: SectorController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Post
@Path("update")
public void update(@Valid Sector sector, Validator validator) {
    validator.onErrorForwardTo(SectorController.class).form();

    sectorBean.update(sector);
    result.include("message", messagesBundle.getString("update.success"));
    result.redirectTo(SectorController.class).list();
}
 
Example #8
Source File: UpdateOccurrenceController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Post
@Path("/{occurrenceId}")
public void processForm(Long occurrenceId, String updateNote, @Valid Occurrence occurrence, Validator validator) {
	validator.onErrorForwardTo(OpenOccurrenceController.class).form();
	
	//TODO Add user from the session
	User user = userBean.findAll().get(0);
	try {
		occurrenceBean.updateOccurrence( occurrence  , updateNote , user);
		result.include("message" , messageBundle.getString("updateOccurrence.messageSuccess") );
	} catch (NoChangeInOccurrenceException e) {
		result.include("errorMessage" , messageBundle.getString("updateOccurrence.messageError") );
	}
	result.forwardTo(this.getClass()).form( occurrenceId );
}
 
Example #9
Source File: EquipmentTypeController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Post("insert")
public void insert(@Valid EquipmentType equipmentType, Validator validator) {
    validator.onErrorForwardTo(EquipmentTypeController.class).form();

    equipmentTypeBean.insert(equipmentType);
    result.include("message", messagesBundle.getString("insert.success"));
    result.redirectTo(EquipmentTypeController.class).list();
}
 
Example #10
Source File: EquipmentTypeController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Post("update")
public void update(@Valid EquipmentType equipmentType, Validator validator) {
    validator.onErrorForwardTo(EquipmentTypeController.class).form();

    equipmentTypeBean.update(equipmentType);
    result.include("message", messagesBundle.getString("update.success"));
    result.redirectTo(EquipmentTypeController.class).list();
}
 
Example #11
Source File: EquipmentTypeController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Path("delete/{equipmentType.id}")
public void delete(@EquipmentTypeInUse EquipmentType equipmentType, Validator validator) {
    validator.onErrorForwardTo(EquipmentTypeController.class).list();
    equipmentTypeBean.delete(equipmentType);
    result.include("message", messagesBundle.getString("delete.success"));
    result.redirectTo(EquipmentTypeController.class).list();
}
 
Example #12
Source File: EquipmentController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Post("insert")
public void insert(@Valid  
		@Unique(propertyName = "serialId" , identityPropertyName="id" , entityClass =Equipment.class )
		Equipment equipment, Validator validator ) {
	
	verifyIfSelectedEquipmentModel(equipment, validator);
	validator.onErrorForwardTo( EquipmentController.class ).form();
	equipmentBean.insert(equipment);
	
    result.include("message", messagesBundle.getString("insert.success") );
    result.redirectTo(EquipmentController.class).list();
}
 
Example #13
Source File: EquipmentController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Post
@Path("update")
public void update(@Valid 
		@Unique(propertyName = "serialId" , identityPropertyName="id" , entityClass =Equipment.class )
		Equipment equipment, Validator validator) {
	
	verifyIfSelectedEquipmentModel(equipment, validator);
	validator.onErrorForwardTo( EquipmentController.class ).form();       
    
	equipmentBean.update(equipment);
	result.redirectTo(EquipmentController.class).list();
}
 
Example #14
Source File: OpenOccurrenceController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Post
@Path("/")
public void processForm(@Valid Occurrence occurrence, Validator validator) {
	verifyIfSelectedSector(occurrence, validator);
	verifyIfSelectedProblemType(occurrence, validator);
	verifyIfSelectedOccurrenceState(occurrence, validator);
	validator.onErrorForwardTo(OpenOccurrenceController.class).form();
	
	//TODO Add user from the session
	occurrence.setUser( userBean.findAll().get(0) );
	
	occurrenceBean.insert(occurrence);
	result.include("message" , messageBundle.getString("openOccurrence.messageSuccess") );
	result.forwardTo(OpenOccurrenceController.class).form();
}
 
Example #15
Source File: OpenOccurrenceController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
private void verifyIfSelectedOccurrenceState(Occurrence occurrence,
		Validator validator) {
	if (occurrence.getOccurrenceState() == null
			|| occurrence.getOccurrenceState().getId() == null) {
		validator
				.add(new SimpleMessage("occurrence.occurrenceState", validationBundle
						.getString("occurrence.occurrenceState.required")));
	}
}
 
Example #16
Source File: OpenOccurrenceController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
protected void verifyIfSelectedSector(Occurrence occurrence,
		Validator validator) {
	if (occurrence.getSector() == null
			|| occurrence.getSector().getId() == null) {
		validator
				.add(new SimpleMessage("occurrence.sector", validationBundle
						.getString("occurrence.sector.required")));
	}
}
 
Example #17
Source File: UserPersonalInfoValidator.java    From mamute with Apache License 2.0 5 votes vote down vote up
@Inject
public UserPersonalInfoValidator(Validator validator, EmailValidator emailValidator, 
		MessageFactory messageFactory, BundleFormatter bundle, BrutalValidator brutalValidator){
	this.validator = validator;
	this.emailValidator = emailValidator;
	this.messageFactory = messageFactory;
	this.bundle = bundle;
	this.brutalValidator = brutalValidator;
}
 
Example #18
Source File: OccurrenceStateController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Post("insert")
public void insert(
	@Valid 
	@Unique(identityPropertyName="id" , propertyName="name" , entityClass=OccurrenceState.class)
	OccurrenceState occurrenceState, Validator validator) {
	validator.onErrorForwardTo( this.getClass() ).form();

	occurrenceStateBean.insert(occurrenceState);
	result.include("message", messagesBundle.getString("insert.success"));
	result.redirectTo( this.getClass() ).list();
}
 
Example #19
Source File: OccurrenceStateController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Post("update")
public void update(
	@Valid
	@Unique(identityPropertyName="id" , propertyName="name" , entityClass=OccurrenceState.class)
	OccurrenceState occurrenceState, Validator validator) {
	validator.onErrorForwardTo(this.getClass()).form();

	occurrenceStateBean.update(occurrenceState);
	result.include("message", messagesBundle.getString("update.success"));
	result.redirectTo(this.getClass()).list();
}
 
Example #20
Source File: OccurrenceStateController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Path("delete/{occurrenceState.id}")
public void delete(OccurrenceState occurrenceState,
		Validator validator) {
	validator.onErrorForwardTo(this.getClass()).list();
	occurrenceStateBean.delete(occurrenceState);
	result.include("message", messagesBundle.getString("delete.success"));
	result.redirectTo(this.getClass()).list();
}
 
Example #21
Source File: ListOccurrenceController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Path("find")
public void find( Long filter , Validator validator ){
	if( validator.hasErrors() ){
		validator.add( new SimpleMessage( "occurrences", validationBundle.getString("occurrence.wrongFilter") ) );
	}
	validator.onErrorUsePageOf( ListOccurrenceController.class ).list();
	
	result.forwardTo( ListOccurrenceController.class ).detail( filter  );
}
 
Example #22
Source File: AuthController.java    From tutorials with MIT License 5 votes vote down vote up
@Inject
public AuthController(Validator validator, UserDao userDao, Result result, UserInfo userInfo) {
    this.validator = validator;
    this.userDao = userDao;
    this.result = result;
    this.userInfo = userInfo;
}
 
Example #23
Source File: PostController.java    From tutorials with MIT License 5 votes vote down vote up
@Inject
public PostController(Result result, PostDao postDao, UserInfo userInfo, Validator validator) {
    this.result = result;
    this.postDao = postDao;
    this.userInfo = userInfo;
    this.validator = validator;
}
 
Example #24
Source File: HomeController.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
/**
 * You can receive any dependency on constructor. If VRaptor knows all dependencies, this
 * class will be created with no problem. You can use as dependencies:
 * - all VRaptor components, e.g {@link Result} and {@link Validator}
 * - all of your CDI classes, e.g {@link DefaultUserDao}
 */
@Inject
public HomeController(UserDao dao, UserInfo userInfo, Result result, Validator validator) {
    this.dao = dao;
	this.result = result;
    this.validator = validator;
       this.userInfo = userInfo;
}
 
Example #25
Source File: MusicController.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
/**
 * Receives dependencies through the constructor.
 * 
 * @param userInfo info on the logged user.
 * @param result VRaptor result handler.
 * @param validator VRaptor validator.
 * @param factory dao factory.
 * @param userDao
 */
@Inject
public MusicController(MusicDao musicDao, UserInfo userInfo, 
			Result result, Validator validator, Musics musics, UserDao userDao) {
	this.musicDao = musicDao;
	this.result = result;
       this.validator = validator;
       this.userInfo = userInfo;
	this.musics = musics;
	this.userDao = userDao;
}
 
Example #26
Source File: UsersController.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
/**
 * Receives dependencies through the constructor.
 * 
 * @param factory dao factory.
 * @param userInfo info on the logged user.
 * @param result VRaptor result handler.
 * @param validator VRaptor validator.
 * @param userInfo 
 */
@Inject
public UsersController(UserDao dao, Result result, Validator validator, 
		UserInfo userInfo, MusicDao musicDao) {
	
	this.userDao = dao;
	this.result = result;
	this.validator = validator;
	this.userInfo = userInfo;
	this.musicDao = musicDao;
}
 
Example #27
Source File: ParametersInstantiator.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Inject
public ParametersInstantiator(ParametersProvider provider, MethodInfo methodInfo, Validator validator, 
		MutableRequest request, FlashScope flash) {
	this.provider = provider;
	this.methodInfo = methodInfo;
	this.validator = validator;
	this.request = request;
	this.flash = flash;
}
 
Example #28
Source File: MockValidator.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Override
public Validator addIf(boolean expression, Message message) {
	if (expression) {
		add(message);
	}
	return this;
}
 
Example #29
Source File: MockValidator.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Override
public <T> Validator addAll(String alias, Set<ConstraintViolation<T>> errors) {
	for (ConstraintViolation<T> v : errors) {
		String category = v.getPropertyPath().toString();
		if (isNullOrEmpty(alias)) {
			category = alias + "." + category;
		}

		add(new SimpleMessage(category, v.getMessage()));
	}
	return this;
}
 
Example #30
Source File: MockValidator.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Override
public Validator addAll(Collection<? extends Message> messages) {
	for(Message message: messages) {
		add(message);
	}
	return this;
}