/** * Converts an {@link Iterable} or {@code T}s into an {@link Iterable} of {@link ResourceSupport} and wraps * them in a {@link Resources} instance. * * @param entities must not be {@literal null}. * @return {@link Resources} containing {@code D}. */ default Resources<D> toResources(Iterable<? extends T> entities) { List<D> resources = new ArrayList<>(); for (T entity : entities) { resources.add(toResource(entity)); } return new Resources<>(resources); } }
/** * Retrieve information about a specific counter. */ @RequestMapping(value = "/{name}", method = RequestMethod.GET) public CounterResource display(@PathVariable("name") String name) { Metric<Double> c = findCounter(name); return counterResourceAssembler.toResource(c); }
@RequestMapping(method = GET, value = "/{user}/customers/{customer}") ResponseEntity<Resource<Customer>> loadSingleUserCustomer(@PathVariable Long user, @PathVariable Long customer) { return Optional.of(this.crmService.findCustomerById(customer)) .map(u -> new ResponseEntity<>(customerResourceAssembler.toResource(u), HttpStatus.OK)) .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND)); }
/** * Retrieve information about a specific counter. * * @param name name * @return counter information */ @RequestMapping(value = "/{name}", method = RequestMethod.GET) public CounterResource display(@PathVariable("name") String name) { Metric<Double> c = findCounter(name); return counterResourceAssembler.toResource(c); }
@RequestMapping(method = GET, value = "/{user}/customers/{customer}") ResponseEntity<Resource<Customer>> loadSingleUserCustomer(@PathVariable Long user, @PathVariable Long customer) { return Optional.of(this.crmService.findCustomerById(customer)) .map(u -> new ResponseEntity<>(customerResourceAssembler.toResource(u), HttpStatus.OK)) .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND)); }
@RequestMapping(method = GET, value = "/{user}") ResponseEntity<Resource<User>> loadUser(@PathVariable Long user) { return Optional.of(this.crmService.findById(user)) .map(u -> new ResponseEntity<>(userResourceAssembler.toResource(u), HttpStatus.OK)) .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND)); }
@RequestMapping(method = GET, value = "/{user}") ResponseEntity<Resource<User>> loadUser(@PathVariable Long user) { return Optional.of(this.crmService.findById(user)) .map(u -> new ResponseEntity<>(userResourceAssembler.toResource(u), HttpStatus.OK)) .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND)); }
@RequestMapping(method = DELETE, value = "/{user}") ResponseEntity<Resource<User>> deleteUser(@PathVariable Long user) { return new ResponseEntity<>(userResourceAssembler.toResource(crmService.removeUser(user)), HttpStatus.NOT_FOUND); }
@RequestMapping(method = DELETE, value = "/{user}") ResponseEntity<Resource<User>> deleteUser(@PathVariable Long user) { return new ResponseEntity<>(userResourceAssembler.toResource(crmService.removeUser(user)), HttpStatus.NOT_FOUND); }
@RequestMapping("/{id}") public ModuleStatusResource display(@PathVariable String id) { ModuleDeploymentId moduleDeploymentId = ModuleDeploymentId.parse(id); for (ModuleDeployer moduleDeployer : moduleDeployers) { ModuleStatus status = moduleDeployer.status(moduleDeploymentId); if (status != null) { return statusAssembler.toResource(status); } } throw new ResourceNotFoundException(); }
private <S, R extends ResourceSupport> PagedResources<R> createResource(Page<S> page, ResourceAssembler<S, R> assembler, Optional<Link> link) { Assert.notNull(page, "Page must not be null!"); Assert.notNull(assembler, "ResourceAssembler must not be null!"); List<R> resources = new ArrayList<>(page.getNumberOfElements()); for (S element : page) { resources.add(assembler.toResource(element)); } PagedResources<R> resource = createPagedResource(resources, asPageMetadata(page), page); return addPaginationLinks(resource, page, link); }
@RequestMapping("/{appId}") public AppStatusResource display(@PathVariable String appId) { AppStatus status = streamDeployer.getAppStatus(appId); if (status.getState().equals(DeploymentState.unknown)) { throw new NoSuchAppException(appId); } return statusAssembler.toResource(status); }
@RequestMapping("/{id}") public AppStatusResource display(@PathVariable String id) { AppStatus status = streamDeployer.getAppStatus(id); if (status.getState().equals(DeploymentState.unknown)) { throw new NoSuchAppException(id); } return statusAssembler.toResource(status); }
@RequestMapping(method = POST) HttpEntity<Void> writeUserProfilePhoto(@PathVariable Long user, @RequestParam MultipartFile file) throws Throwable { byte bytesForProfilePhoto[] = FileCopyUtils.copyToByteArray(file.getInputStream()); this.crmService.writeUserProfilePhoto(user, MediaType.parseMediaType(file.getContentType()), bytesForProfilePhoto); Resource<User> userResource = this.userResourceAssembler.toResource(crmService.findById(user)); List<Link> linkCollection = userResource.getLinks(); Links wrapperOfLinks = new Links(linkCollection); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.add("Link", wrapperOfLinks.toString()); // we can't encode the links in the body of the response, so we put them in the "Links:" header. httpHeaders.setLocation(URI.create(userResource.getLink("photo").getHref())); // "Location: /users/{userId}/photo" return new ResponseEntity<>(httpHeaders, HttpStatus.ACCEPTED); }
@RequestMapping(method = POST) HttpEntity<Void> writeUserProfilePhoto(@PathVariable Long user, @RequestParam MultipartFile file) throws Throwable { byte bytesForProfilePhoto[] = FileCopyUtils.copyToByteArray(file.getInputStream()); this.crmService.writeUserProfilePhoto(user, MediaType.parseMediaType(file.getContentType()), bytesForProfilePhoto); Resource<User> userResource = this.userResourceAssembler.toResource(crmService.findById(user)); List<Link> linkCollection = userResource.getLinks(); Links wrapperOfLinks = new Links(linkCollection); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.add("Link", wrapperOfLinks.toString()); // we can't encode the links in the body of the response, so we put them in the "Links:" header. httpHeaders.setLocation(URI.create(userResource.getLink("photo").getHref())); // "Location: /users/{userId}/photo" return new ResponseEntity<>(httpHeaders, HttpStatus.ACCEPTED); }