br.com.caelum.vraptor.Path Java Examples

The following examples show how to use br.com.caelum.vraptor.Path. 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 6 votes vote down vote up
/**
    * Accepts HTTP PUT requests. <br>
    * 
    * <strong>URL:</strong> /users/login/musics/id (for example, 
    * /users/john/musics/3 adds the music with id 3 to the john's 
    * collection)<br>
    * 
    * <strong>View:</strong> redirects to user's home <br>
    *
    * You can use more than one variable on URI. Since the browsers 
    * don't support PUT method you have to pass an additional parameter: 
    * <strong>_method=PUT</strong> for calling this method.<br>
    *
    * This method adds a music to a user's collection.
    */
   @Path("/users/{user.login}/musics/{music.id}")
   @Put
public void addToMyList(User user, Music music) {
   	User currentUser = userInfo.getUser();
    userDao.refresh(currentUser);
    
    validator.check(user.getLogin().equals(currentUser.getLogin()), 
            new SimpleMessage("user", "you_cant_add_to_others_list"));

    validator.check(!currentUser.getMusics().contains(music), 
            new SimpleMessage("music", "you_already_have_this_music"));

	validator.onErrorUsePageOf(UsersController.class).home();

	music = musicDao.load(music);
	currentUser.add(music);
	
	result.redirectTo(UsersController.class).home();
}
 
Example #2
Source File: DefaultRouterTest.java    From vraptor4 with Apache License 2.0 6 votes vote down vote up
@Test
public void usesTheFirstRegisteredRuleMatchingThePattern() throws SecurityException, NoSuchMethodException {
	Route route = mock(Route.class);
	Route second = mock(Route.class, "second");
	when(route.getControllerMethod()).thenReturn(anyControllerMethod());
	when(second.getControllerMethod()).thenReturn(anyControllerMethod());

	when(route.canHandle("/clients/add")).thenReturn(true);
	when(second.canHandle("/clients/add")).thenReturn(true);

	EnumSet<HttpMethod> all = EnumSet.allOf(HttpMethod.class);

	when(route.allowedMethods()).thenReturn(all);
	when(second.allowedMethods()).thenReturn(all);

	when(route.controllerMethod(request, "/clients/add")).thenReturn(method);
	when(route.getPriority()).thenReturn(Path.HIGHEST);
	when(second.getPriority()).thenReturn(Path.LOWEST);

	router.add(route);
	router.add(second);

	ControllerMethod found = router.parse("/clients/add", HttpMethod.POST, request);
	assertThat(found, is(equalTo(method)));
}
 
Example #3
Source File: ContatoController.java    From aprendendo-vraptor with Apache License 2.0 5 votes vote down vote up
@Post
@Path(value = {"/", ""})
@Consumes(value = "application/json", options = WithoutRoot.class)
public void novo( Contato contato ) {
	setPhone(contato);
	contatos.novo(contato);
	result.use(status()).created();
}
 
Example #4
Source File: ManufacturerController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Post
@Path("insert")
public void insert(@Valid Manufacturer manufacturer, Validator validator) {
    validator.onErrorRedirectTo(ManufacturerController.class).form();

    manufacturerBean.insert(manufacturer);
    result.include("message", messagesBundle.getString("insert.success"));
    result.redirectTo("/manufacturer/list");
}
 
Example #5
Source File: ContatoController.java    From aprendendo-vraptor with Apache License 2.0 5 votes vote down vote up
@Get
@Path(value = {"/", ""})
public void todos() {
	result.use(json())
		  .withoutRoot()
		  .from(contatos.todosAtivos())
		  .include("telefones")
		  .serialize();
}
 
Example #6
Source File: ContatoController.java    From aprendendo-vraptor with Apache License 2.0 5 votes vote down vote up
@Get
@Path(value = "/tipo")
public void tipos() {
	result.use(json())
		  .withoutRoot()
		  .from(TipoContato.values())
		  .serialize();
}
 
Example #7
Source File: MusicController.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Path("/musics/download/{m.id}")
@Get
public Download download(Music m) throws FileNotFoundException {
	Music music = musicDao.load(m);
	File file = musics.getFile(music);
	String contentType = "audio/mpeg";
	String filename = music.getTitle() + ".mp3";

	return new FileDownload(file, contentType, filename);
}
 
Example #8
Source File: ContatoController.java    From aprendendo-vraptor with Apache License 2.0 5 votes vote down vote up
@Put
@Path(value = "/{id}")
@Consumes(value = "application/json", options = WithoutRoot.class)
public void editar(Contato contato, Long id) {
	contato.setId(id);
	setPhone(contato);
	contatos.atualizar(contato);
	result.use(status()).ok();
}
 
Example #9
Source File: RegularUserNewsletterJob.java    From mamute with Apache License 2.0 5 votes vote down vote up
@Override
@Path("/wjh1jkh34jk12hkjehd13kj4h1kjh41jkhwe12341")
public void execute() {
	LOG.info("executing " + getClass().getSimpleName());
	if (shouldSendNewsletter()) {
		LOG.info("sending newsletter emails");
		ScrollableResults results = users.newsletterConfirmed();
		newsMailer.sendTo(results, false);
		newsletterSentLogs.saveLog();
		result.notFound();
	}
}
 
Example #10
Source File: InfoQRSSJob.java    From mamute with Apache License 2.0 5 votes vote down vote up
@Override
@Path("/jdnakfh3nfis39103f1")
public void execute() {
	LOG.debug("executing " + getClass().getSimpleName());
	feedsMap.putOrUpdate(INFOQ_BASE_KEY, RSSType.INFO_Q);
	LOG.debug(feedsMap.get(INFOQ_BASE_KEY));
	result.nothing();
}
 
Example #11
Source File: TelefoneController.java    From aprendendo-vraptor with Apache License 2.0 5 votes vote down vote up
@Get
@Path(value = { "/tipo", "/tipo/" })
public void tipos() {
	result.use(json())
		  .withoutRoot()
		  .from(TipoTelefone.values())
		  .serialize();
}
 
Example #12
Source File: ContatoController.java    From aprendendo-vraptor with Apache License 2.0 5 votes vote down vote up
@Get
@Path(value = {"/", ""})
public void todos() {
	result.use(json())
		  .withoutRoot()
		  .from(contatos.todosAtivos())
		  .include("telefones")
		  .serialize();
}
 
Example #13
Source File: ContatoController.java    From aprendendo-vraptor with Apache License 2.0 5 votes vote down vote up
@Post
@Path(value = {"/", ""})
@Consumes(value = "application/json", options = WithoutRoot.class)
public void novo( Contato contato ) {
	setPhone(contato);
	contatos.novo(contato);
	result.use(status()).created();
}
 
Example #14
Source File: ContatoController.java    From aprendendo-vraptor with Apache License 2.0 5 votes vote down vote up
@Get
@Path(value = "/tipo")
public void tipos() {
	result.use(json())
		  .withoutRoot()
		  .from(TipoContato.values())
		  .serialize();
}
 
Example #15
Source File: DefaultRouterTest.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Test
public void throwsExceptionIfMoreThanOneUriMatchesWithSamePriority() throws NoSuchMethodException {
	Route route = mock(Route.class);
	Route second = mock(Route.class, "second");
	when(route.getControllerMethod()).thenReturn(anyControllerMethod());
	when(second.getControllerMethod()).thenReturn(anyControllerMethod());

	when(route.canHandle("/clients/add")).thenReturn(true);
	when(second.canHandle("/clients/add")).thenReturn(true);

	EnumSet<HttpMethod> all = EnumSet.allOf(HttpMethod.class);

	when(route.allowedMethods()).thenReturn(all);
	when(second.allowedMethods()).thenReturn(all);

	when(route.getPriority()).thenReturn(Path.DEFAULT);
	when(second.getPriority()).thenReturn(Path.DEFAULT);

	router.add(route);
	router.add(second);

	try {
		router.parse("/clients/add", HttpMethod.POST, request);
		fail("IllegalStateException expected");
	} catch (IllegalStateException e) {
	}
}
 
Example #16
Source File: TelefoneController.java    From aprendendo-vraptor with Apache License 2.0 5 votes vote down vote up
@Get
@Path(value = { "/tipo", "/tipo/" })
public void tipos() {
	result.use(json())
		  .withoutRoot()
		  .from(TipoTelefone.values())
		  .serialize();
}
 
Example #17
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 #18
Source File: ManufacturerController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Post
@Path("update")
public void update(@Valid Manufacturer manufacturer, Validator validator) {
    validator.onErrorRedirectTo(ManufacturerController.class).form();

    manufacturerBean.update(manufacturer);
    result.include("message", messagesBundle.getString("update.success"));
    result.redirectTo(ManufacturerController.class).list();
}
 
Example #19
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 #20
Source File: UserController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Post
@Path("insert")
public void insert(@Valid User user, String passwordConfirmation, Validator validator) {
    verifyPasswordConfirmation(user, passwordConfirmation, validator);
    validator.onErrorForwardTo(UserController.class).form();

    userBean.insert(user);
    result.include("message", messagesBundle.getString("insert.success"));
    result.redirectTo("/user/list");
}
 
Example #21
Source File: EquipmentController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Path("form/{id}")
public void form(Long id) {
    Equipment equipment = equipmentBean.findById(id);
    result.include( equipment );
    result.include("models" , equipmentModelBean.findAll() );
    
}
 
Example #22
Source File: UserController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Post
@Path("update")
public void update(@Valid User user, String passwordConfirmation, Validator validator) {
    verifyPasswordConfirmation(user, passwordConfirmation, validator);
    validator.onErrorForwardTo(UserController.class).form();

    userBean.update(user);
    result.include("message", messagesBundle.getString("update.success"));
    result.redirectTo(UserController.class).list();
}
 
Example #23
Source File: PathAnnotationRoutesParser.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
protected List<Route> registerRulesFor(Class<?> baseType) {
	EnumSet<HttpMethod> typeMethods = getHttpMethods(baseType);

	List<Route> routes = new ArrayList<>();
	for (Method javaMethod : baseType.getMethods()) {
		if (isEligible(javaMethod)) {
			String[] uris = getURIsFor(javaMethod, baseType);

			for (String uri : uris) {
				RouteBuilder rule = router.builderFor(uri);

				EnumSet<HttpMethod> methods = getHttpMethods(javaMethod);

				rule.with(methods.isEmpty() ? typeMethods : methods);

				if(javaMethod.isAnnotationPresent(Path.class)){
					rule.withPriority(javaMethod.getAnnotation(Path.class).priority());
				}

				if (getUris(javaMethod).length > 0) {
					rule.withPriority(Path.DEFAULT);
				}

				rule.is(baseType, javaMethod);
				routes.add(rule.build());
			}
		}
	}

	return routes;
}
 
Example #24
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 #25
Source File: ProblemTypeController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Post
@Path("update")
public void update(
        @Valid
        @Unique(identityPropertyName = "id", propertyName = "name", entityClass = ProblemType.class)
        ProblemType problemType, Validator validator) {
    validator.onErrorForwardTo(this).form();

    problemTypeBean.update(problemType);

    result.include("message", messagesBundle.getString("update.success"));
    result.redirectTo(this).list();
}
 
Example #26
Source File: ProblemTypeController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Path("delete/{problemType.id}")
public void delete(ProblemType problemType) {
    problemTypeBean.delete(problemType);

    result.include("message", messagesBundle.getString("delete.success"));
    result.redirectTo(this).list();
}
 
Example #27
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 #28
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 #29
Source File: UpdateOccurrenceController.java    From hurraa with GNU General Public License v2.0 5 votes vote down vote up
@Get
@Path("/{occurrenceId}")
public void form(Long occurrenceId){
	Occurrence occurrence = occurrenceBean.findById(occurrenceId);
	if(occurrence != null){
	    result.include("problemTypes", problemTypeBean.findAll());
		result.include("sectors", sectorBean.findAll());
		result.include("occurrenceStates" , occurrenceStateBean.findAll() );
		result.include("occurrence", occurrence);
	}
}
 
Example #30
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();
}