org.springframework.hateoas.mvc.ControllerLinkBuilder Java Examples
The following examples show how to use
org.springframework.hateoas.mvc.ControllerLinkBuilder.
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: SecurityController.java From spring-cloud-dashboard with Apache License 2.0 | 6 votes |
/** * Return security information. E.g. is security enabled? Which user do you represent? */ @ResponseBody @RequestMapping(method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) public SecurityInfoResource getSecurityInfo() { final boolean authenticationEnabled = securityProperties.getBasic().isEnabled(); final SecurityInfoResource securityInfo = new SecurityInfoResource(); securityInfo.setAuthenticationEnabled(authenticationEnabled); securityInfo.add(ControllerLinkBuilder.linkTo(SecurityController.class).withSelfRel()); if (authenticationEnabled && SecurityContextHolder.getContext() != null) { final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (!(authentication instanceof AnonymousAuthenticationToken)) { securityInfo.setAuthenticated(authentication.isAuthenticated()); securityInfo.setUsername(authentication.getName()); } } return securityInfo; }
Example #2
Source File: TodoController.java From Mastering-Spring-5.1 with MIT License | 5 votes |
@GetMapping(path = "/users/{name}/todos/{id}") public Resource<Todo> retrieveTodo(@PathVariable String name, @PathVariable int id) { Todo todo = todoService.retrieveTodo(id); if (todo == null) { throw new TodoNotFoundException("Todo Not Found"); } Resource<Todo> todoResource = new Resource<com.mastering.spring.springboot.bean.Todo>(todo); ControllerLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveTodos(name)); todoResource.add(linkTo.withRel("parent")); return todoResource; }
Example #3
Source File: TodoController.java From Mastering-Spring-5.1 with MIT License | 5 votes |
@GetMapping(path = "/users/{name}/todos/{id}") public Resource<Todo> retrieveTodo(@PathVariable String name, @PathVariable int id) { Todo todo = todoService.retrieveTodo(id); if (todo == null) { throw new TodoNotFoundException("Todo Not Found"); } Resource<Todo> todoResource = new Resource<com.mastering.spring.springboot.bean.Todo>(todo); ControllerLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveTodos(name)); todoResource.add(linkTo.withRel("parent")); return todoResource; }
Example #4
Source File: TodoController.java From Mastering-Spring-5.1 with MIT License | 5 votes |
@GetMapping(path = "/users/{name}/todos/{id}") public Resource<Todo> retrieveTodo(@PathVariable String name, @PathVariable int id) { Todo todo = todoService.retrieveTodo(id); if (todo == null) { throw new TodoNotFoundException("Todo Not Found"); } Resource<Todo> todoResource = new Resource<com.mastering.spring.springboot.bean.Todo>(todo); ControllerLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveTodos(name)); todoResource.add(linkTo.withRel("parent")); return todoResource; }
Example #5
Source File: TodoController.java From Mastering-Spring-5.1 with MIT License | 5 votes |
@GetMapping(path = "/users/{name}/todos/{id}") public Resource<Todo> retrieveTodo(@PathVariable String name, @PathVariable int id) { Todo todo = todoService.retrieveTodo(id); if (todo == null) { throw new TodoNotFoundException("Todo Not Found"); } Resource<Todo> todoResource = new Resource<com.mastering.spring.springboot.bean.Todo>(todo); ControllerLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveTodos(name)); todoResource.add(linkTo.withRel("parent")); return todoResource; }
Example #6
Source File: UserJPAController.java From Spring with Apache License 2.0 | 5 votes |
@GetMapping(path = "/jpa/users/{id}") public Resource<User> retrieveUser(@PathVariable int id) { final User user = userJPAService.findOne(id); if (Objects.isNull(user)) { throw new UserNotFoundException("There is no user with id: " + id); } final Resource<User> resource = new Resource<>(user); final ControllerLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveAllUsers()); resource.add(linkTo.withRel("all-users")); return resource; }
Example #7
Source File: TodoController.java From Mastering-Spring-5.0 with MIT License | 5 votes |
@GetMapping(path = "/users/{name}/todos/{id}") public Resource<Todo> retrieveTodo(@PathVariable String name, @PathVariable int id) { Todo todo = todoService.retrieveTodo(id); if (todo == null) { throw new TodoNotFoundException("Todo Not Found"); } Resource<com.mastering.spring.springboot.bean.Todo> todoResource = new Resource<com.mastering.spring.springboot.bean.Todo>(todo); ControllerLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveTodos(name)); todoResource.add(linkTo.withRel("parent")); return todoResource; }
Example #8
Source File: TodoController.java From Mastering-Spring-5.0 with MIT License | 5 votes |
@GetMapping(path = "/users/{name}/todos/{id}") public Resource<Todo> retrieveTodo(@PathVariable String name, @PathVariable int id) { Todo todo = todoService.retrieveTodo(id); if (todo == null) { throw new TodoNotFoundException("Todo Not Found"); } Resource<com.mastering.spring.springboot.bean.Todo> todoResource = new Resource<com.mastering.spring.springboot.bean.Todo>(todo); ControllerLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveTodos(name)); todoResource.add(linkTo.withRel("parent")); return todoResource; }
Example #9
Source File: TodoController.java From Mastering-Spring-5.0 with MIT License | 5 votes |
@GetMapping(path = "/users/{name}/todos/{id}") public Resource<Todo> retrieveTodo(@PathVariable String name, @PathVariable int id) { Todo todo = todoService.retrieveTodo(id); if (todo == null) { throw new TodoNotFoundException("Todo Not Found"); } Resource<com.mastering.spring.springboot.bean.Todo> todoResource = new Resource<com.mastering.spring.springboot.bean.Todo>(todo); ControllerLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveTodos(name)); todoResource.add(linkTo.withRel("parent")); return todoResource; }
Example #10
Source File: PageLinksAspect.java From Showcase with Apache License 2.0 | 5 votes |
private UriComponentsBuilder originalUri(Class<?> controller, HttpServletRequest request) { UriComponentsBuilder baseUri = ControllerLinkBuilder.linkTo(controller).toUriComponentsBuilder(); for (Map.Entry<String, String[]> entry : request.getParameterMap().entrySet()) { for (String value : entry.getValue()) { baseUri.queryParam(entry.getKey(), value); } } return baseUri; }
Example #11
Source File: DataConversionHelper.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
static DdiControllerBase fromTarget(final Target target, final Action action, final String defaultControllerPollTime, final TenantAware tenantAware) { final DdiControllerBase result = new DdiControllerBase( new DdiConfig(new DdiPolling(defaultControllerPollTime))); if (action != null) { if (action.isCancelingOrCanceled()) { result.add(ControllerLinkBuilder .linkTo(ControllerLinkBuilder.methodOn(DdiRootController.class, tenantAware.getCurrentTenant()) .getControllerCancelAction(tenantAware.getCurrentTenant(), target.getControllerId(), action.getId())) .withRel(DdiRestConstants.CANCEL_ACTION)); } else { // we need to add the hashcode here of the actionWithStatus // because the action might // have changed from 'soft' to 'forced' type and we need to // change the payload of the // response because of eTags. result.add(ControllerLinkBuilder .linkTo(ControllerLinkBuilder.methodOn(DdiRootController.class, tenantAware.getCurrentTenant()) .getControllerBasedeploymentAction(tenantAware.getCurrentTenant(), target.getControllerId(), action.getId(), calculateEtag(action), null)) .withRel(DdiRestConstants.DEPLOYMENT_BASE_ACTION)); } } if (target.isRequestControllerAttributes()) { result.add(ControllerLinkBuilder .linkTo(ControllerLinkBuilder.methodOn(DdiRootController.class, tenantAware.getCurrentTenant()) .putConfigData(null, tenantAware.getCurrentTenant(), target.getControllerId())) .withRel(DdiRestConstants.CONFIG_DATA_ACTION)); } return result; }
Example #12
Source File: UserResource.java From in28minutes-spring-microservices with MIT License | 4 votes |
@GetMapping("/users/{id}") public Resource<User> retrieveUser(@PathVariable int id) { User user = service.findOne(id); if(user==null) throw new UserNotFoundException("id-"+ id); //"all-users", SERVER_PATH + "/users" //retrieveAllUsers Resource<User> resource = new Resource<User>(user); ControllerLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveAllUsers()); resource.add(linkTo.withRel("all-users")); //HATEOAS return resource; }
Example #13
Source File: UserJPAResource.java From in28minutes-spring-microservices with MIT License | 4 votes |
@GetMapping("/jpa/users/{id}") public Resource<User> retrieveUser(@PathVariable int id) { Optional<User> user = userRepository.findById(id); if (!user.isPresent()) throw new UserNotFoundException("id-" + id); // "all-users", SERVER_PATH + "/users" // retrieveAllUsers Resource<User> resource = new Resource<User>(user.get()); ControllerLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveAllUsers()); resource.add(linkTo.withRel("all-users")); // HATEOAS return resource; }
Example #14
Source File: NotesController.java From restdocs-raml with MIT License | 4 votes |
@RequestMapping(method = RequestMethod.GET) PagedResources<NoteResource> all(Pageable pageable) { return pagedResourcesAssembler.toResource(noteRepository.findAll(pageable), noteResourceAssembler, ControllerLinkBuilder.linkTo(methodOn(this.getClass()).all(null)).withSelfRel()); }
Example #15
Source File: TaskResourceAssembler.java From chaos-lemur with Apache License 2.0 | 4 votes |
private ControllerLinkBuilder getTaskLinkBuilder(Task task) { return linkTo(TaskManager.class).slash(task.getId()); }