br.com.caelum.vraptor.Result Java Examples

The following examples show how to use br.com.caelum.vraptor.Result. 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: 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 #2
Source File: ChangeLocaleController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
public void redirectBack( Result result, HttpServletRequest request ){
    String urlToGoBack = request.getHeader("Referer"); //Get the url that originated the request
    if(urlToGoBack != null)
        result.redirectTo( urlToGoBack );
    else
        result.redirectTo( IndexController.class ).index();
}
 
Example #3
Source File: EquipmentController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Inject
public EquipmentController(Result result, EquipmentBean equipmentBean, EquipmentModelBean equipmentModelBean,
		ResourceBundle messagesBundle , @ValidationMessages ResourceBundle validationBundle) {
       this.result = result;
       this.equipmentBean = equipmentBean;
       this.equipmentModelBean = equipmentModelBean;
       this.validationBundle = validationBundle;
       this.messagesBundle = messagesBundle;
}
 
Example #4
Source File: OpenOccurrenceController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Inject
public OpenOccurrenceController(Result result, OccurrenceBean occurrenceBean,
		ProblemTypeBean problemTypeBean,
		SectorBean sectorBean,
		OccurrenceStateBean occurrenceStateBean,
		ResourceBundle messagesBundle,
		@ValidationMessages ResourceBundle validationBundle) {
	this.result = result;
	this.occurrenceBean = occurrenceBean;
	this.occurrenceStateBean = occurrenceStateBean;
	this.messageBundle = messagesBundle;
	this.validationBundle = validationBundle;
	this.problemTypeBean = problemTypeBean;
	this.sectorBean = sectorBean;
}
 
Example #5
Source File: UpdateOccurrenceController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Inject
public UpdateOccurrenceController(Result result, OccurrenceBean occurrenceBean,
		ProblemTypeBean problemTypeBean,
		SectorBean sectorBean,
		OccurrenceStateBean occurrenceStateBean,
		ResourceBundle messagesBundle,
		@ValidationMessages ResourceBundle validationBundle) {
	this.result = result;
	this.occurrenceBean = occurrenceBean;
	this.occurrenceStateBean = occurrenceStateBean;
	this.messageBundle = messagesBundle;
	this.validationBundle = validationBundle;
	this.problemTypeBean = problemTypeBean;
	this.sectorBean = sectorBean;
}
 
Example #6
Source File: CejugValidator.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Inject
public CejugValidator(Result result, ValidationViewsFactory factory, Outjector outjector, Proxifier proxifier,
		ResourceBundle bundle, Validator validator, MessageInterpolator interpolator, Locale locale) {
	super(result, factory, outjector, proxifier, bundle,  validator, interpolator, locale);
	this.result = result;
	this.viewsFactory = factory;
	this.outjector = outjector;
	this.proxifier = proxifier;
}
 
Example #7
Source File: VerifyUsersController.java    From mamute with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Post("/asjkdjnjsaknfknsdklglas")
public void verify(Result r){
	List<User> users = session.createCriteria(User.class).list();
	List<User> invalid = new ArrayList<>();
	for (User user : users) {
		if (!isValid(user)) {
			invalid.add(user);
		}
	}
	r.include("invalid", invalid);
}
 
Example #8
Source File: PimpMyControllerInterceptor.java    From mamute with Apache License 2.0 5 votes vote down vote up
@Override
public void intercept(InterceptorStack stack, ControllerMethod method,
		Object obj) throws InterceptionException {
	try {
		locals.reset().put(Result.class, result).put(MessageFactory.class, factory);
		stack.next(method, obj);
	} finally {
		locals.clear();
	}
}
 
Example #9
Source File: RegularUserNewsletterJob.java    From mamute with Apache License 2.0 5 votes vote down vote up
@Inject
public RegularUserNewsletterJob(Result result, UserDAO users,
		NewsletterMailer newsMailer, Environment env,
		NewsletterSentLogDAO newsletterSentLogs) {
	this.result = result;
	this.users = users;
	this.newsMailer = newsMailer;
	this.env = env;
	this.newsletterSentLogs = newsletterSentLogs;
}
 
Example #10
Source File: ChangeLocaleController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Path("/change-location/{lenguageName}/{country}")
public void changeLocale(String lenguageName , String country , Result result, HttpSession session , HttpServletRequest request ){
    Locale locale = new Locale( lenguageName , country );
    Config.set( session, Config.FMT_FALLBACK_LOCALE, locale);
    Config.set (session, Config.FMT_LOCALE, locale);
    redirectBack(result , request);
}
 
Example #11
Source File: ListOccurrenceController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Inject
public ListOccurrenceController(Result result, OccurrenceBean occurrenceBean , @ValidationMessages ResourceBundle validationBundle) {
	super();
	this.result = result;
	this.occurrenceBean = occurrenceBean;
	this.validationBundle = validationBundle;
}
 
Example #12
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 #13
Source File: AuthorizationInterceptor.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Inject
public AuthorizationInterceptor(UserInfo info, UserDao dao, 
		Result result, ResourceBundle bundle) {
	this.info = info;
	this.dao = dao;
	this.result = result;
	this.bundle = bundle;
}
 
Example #14
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 #15
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 #16
Source File: DefaultValidator.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Inject
public DefaultValidator(Result result, ValidationViewsFactory factory, Outjector outjector, Proxifier proxifier, 
		ResourceBundle bundle, javax.validation.Validator bvalidator, MessageInterpolator interpolator, Locale locale,
		Messages messages) {
	this.result = result;
	this.viewsFactory = factory;
	this.outjector = outjector;
	this.proxifier = proxifier;
	this.bundle = bundle;
	this.bvalidator = bvalidator;
	this.interpolator = interpolator;
	this.locale = locale;
	this.messages = messages;
}
 
Example #17
Source File: ExceptionHandlerInterceptor.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
protected boolean replay(Exception e) {
	ExceptionRecorder<Result> exresult = exceptions.findByException(e);

	if (exresult == null) {
		return false;
	}

	reportException(e);

	logger.debug("handling exception {}", e.getClass(), e);
	exresult.replay(result);

	return true;
}
 
Example #18
Source File: DefaultStatus.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Inject
public DefaultStatus(HttpServletResponse response, Result result, Configuration config,
		Proxifier proxifier, Router router) {
	this.response = response;
	this.result = result;
	this.config = config;
	this.proxifier = proxifier;
	this.router = router;
}
 
Example #19
Source File: DefaultRefererResult.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Inject
public DefaultRefererResult(Result result, MutableRequest request, Router router, ParametersProvider provider,
		ReflectionProvider reflectionProvider) {
	this.result = result;
	this.request = request;
	this.router = router;
	this.provider = provider;
	this.reflectionProvider = reflectionProvider;
}
 
Example #20
Source File: OutjectResult.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
public void outject(@Observes MethodExecuted event, Result result, MethodInfo methodInfo) {

		Type returnType = event.getMethodReturnType();

		if (!returnType.equals(Void.TYPE)) {
			String name = extractor.nameFor(returnType);
			Object value = methodInfo.getResult();
			logger.debug("outjecting {}={}", name, value);
			result.include(name, value);
		}
	}
 
Example #21
Source File: DefaultResult.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Override
public Result include(String key, Object value) {
	logger.debug("including attribute {}: {}", key, value);
	
	includedAttributes.put(key, value);
	request.setAttribute(key, value);
	return this;
}
 
Example #22
Source File: DefaultResult.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Override
public Result include(Object value) {
	if(value == null) {
		return this;
	}
	
	String key = extractor.nameFor(value.getClass());
	return include(key, value);
}
 
Example #23
Source File: DefaultExceptionMapper.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Override
public Result record(Class<? extends Exception> exception) {
	requireNonNull(exception, "Exception cannot be null.");

	ExceptionRecorder<Result> instance = new ExceptionRecorder<>(proxifier, reflectionProvider);
	exceptions.put(exception, instance);

	return proxifier.proxify(Result.class, instance);
}
 
Example #24
Source File: DefaultExceptionMapper.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Override
public ExceptionRecorder<Result> findByException(Exception e) {
	logger.debug("find for exception {}", e.getClass());

	for (Entry<Class<? extends Exception>, ExceptionRecorder<Result>> entry : exceptions.entrySet()) {
		if (entry.getKey().isInstance(e)) {
			logger.debug("found exception mapping: {} -> {}", entry.getKey(), entry.getValue());

			return entry.getValue();
		}
	}

	return hasExceptionCause(e) ? findByException((Exception) e.getCause()) : null;
}
 
Example #25
Source File: DefaultLogicResultTest.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
/**
 * @bug #337
 */
@Test
public void shouldForwardToTheRightDefaultValue() throws Exception {
	Result result = mock(Result.class);
	PageResult pageResult = new DefaultPageResult(request, response, methodInfo, resolver, proxifier);
	when(result.use(PageResult.class)).thenReturn(pageResult);
	when(container.instanceFor(TheComponent.class)).thenReturn(new TheComponent(result));
	when(resolver.pathFor(argThat(sameMethodAs(TheComponent.class.getDeclaredMethod("method"))))).thenReturn("controlled!");
	when(request.getRequestDispatcher(anyString())).thenThrow(new AssertionError("should have called with the right method!"));
	doReturn(dispatcher).when(request).getRequestDispatcher("controlled!");
	
	methodInfo.setControllerMethod(DefaultControllerMethod.instanceFor(MyComponent.class, MyComponent.class.getDeclaredMethod("base")));
	
	logicResult.forwardTo(TheComponent.class).method();
}
 
Example #26
Source File: DefaultValidationViewsFactoryTest.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	result = mock(Result.class);

	proxifier = new JavassistProxifier();
	factory = new DefaultValidationViewsFactory(result, proxifier, new DefaultReflectionProvider());
	errors = Collections.emptyList();

}
 
Example #27
Source File: IogiParametersProviderTest.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Test
public void returnsDependenciesIfContainerCanProvide() throws Exception {
	thereAreNoParameters();
	Result result = mock(Result.class);

	when(container.canProvide(Result.class)).thenReturn(true);
	when(container.instanceFor(Result.class)).thenReturn(result);

	Result returned = getFirstParameterFor(method("dependency", Result.class));
	assertThat(returned, is(result));
}
 
Example #28
Source File: IogiParametersProviderTest.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Test
public void returnsDependenciesIfRequestCanProvide() throws Exception {
	thereAreNoParameters();
	Result result = mock(Result.class);

	when(request.getAttribute("result")).thenReturn(result);

	Result returned = getFirstParameterFor(method("dependency", Result.class));
	assertThat(returned, is(result));
}
 
Example #29
Source File: IogiParametersProviderTest.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldInjectOnlyAttributesWithSameType() throws Exception {
	Result result = mock(Result.class);
	when(request.getAttribute("result")).thenReturn(result);
	when(request.getParameterMap()).thenReturn(singletonMap("result", new String[] { "buggy" }));

	ControllerMethod method = method(OtherResource.class, OtherResource.class, "logic", String.class);

	Object[] out = iogi.getParametersFor(method, errors);

	assertThat(out[0], is(not((Object) result)));
	assertThat(out[0], is((Object) "buggy"));
}
 
Example #30
Source File: ExceptionRecorderTest.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Test
public void whenNotFoundException() {
	mapper.record(IOException.class).forwardTo(DEFAULT_REDIRECT);
	ExceptionRecorder<Result> recorder = mapper.findByException(new RuntimeException(new IllegalStateException()));

	assertThat(recorder, Matchers.nullValue());
}