/** * Converts all given entities into resources and wraps the result in a {@link Resources} instance. * * @see #toListOfResources() and {@link ResourceAssembler#toResource(Object)} * @return */ public Resources<D> toResources() { return new Resources<>(toListOfResources()); } }
/** * Creates a new {@link Resources} instance by wrapping the given domain class instances into a {@link Resource}. * * @param content must not be {@literal null}. * @return */ @SuppressWarnings("unchecked") public static <T extends Resource<S>, S> Resources<T> wrap(Iterable<S> content) { Assert.notNull(content, "Content must not be null!"); ArrayList<T> resources = new ArrayList<>(); for (S element : content) { resources.add((T) new Resource<>(element)); } return new Resources<>(resources); }
/** * 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); } }
protected Resources<?> entitiesToResources(Iterable<Object> entities, PersistentEntityResourceAssembler assembler, Class<?> domainType) { if (!entities.iterator().hasNext()) { List<Object> content = Arrays.<Object> asList(WRAPPERS.emptyCollectionOf(domainType)); return new Resources<Object>(content, getDefaultSelfLink()); } List<Resource<Object>> resources = new ArrayList<Resource<Object>>(); for (Object obj : entities) { resources.add(obj == null ? null : assembler.toResource(obj)); } return new Resources<Resource<Object>>(resources, getDefaultSelfLink()); }
@Override public ResourceSupport read(Class<? extends ResourceSupport> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { List<Link> links = new ArrayList<Link>(); Scanner scanner = new Scanner(inputMessage.getBody()); try { while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (StringUtils.hasText(line)) { links.add(new Link(line)); } } } finally { scanner.close(); } return new Resources<Object>(Collections.emptyList(), links); }
/** * Converts all given entities into resources and wraps the collection as a resource as well. * * @see #toResource(Object) * @param entities must not be {@literal null}. * @return {@link Resources} containing {@link Resource} of {@code T}. */ @Override default Resources<Resource<T>> toResources(Iterable<? extends T> entities) { Assert.notNull(entities, "entities must not be null!"); List<Resource<T>> resourceList = new ArrayList<>(); for (T entity : entities) { resourceList.add(toResource(entity)); } Resources<Resource<T>> resources = new Resources<>(resourceList); addLinks(resources); return resources; }
@SuppressWarnings({ "unchecked" }) protected Resources<?> toResources(Iterable<?> source, PersistentEntityResourceAssembler assembler, Class<?> domainType, Optional<Link> baseLink) { if (source instanceof Page) { Page<Object> page = (Page<Object>) source; return entitiesToResources(page, assembler, domainType, baseLink); } else if (source instanceof Iterable) { return entitiesToResources((Iterable<Object>) source, assembler, domainType); } else { return new Resources(EMPTY_RESOURCE_LIST); } }
@ResponseBody @SuppressWarnings({ "unchecked" }) @RequestMapping(value = BASE_MAPPING, method = RequestMethod.GET, produces = { "application/x-spring-data-compact+json", "text/uri-list" }) public Resources<?> getCollectionResourceCompact(@QuerydslPredicate RootResourceInformation resourceinformation, DefaultedPageable pageable, Sort sort, PersistentEntityResourceAssembler assembler) throws ResourceNotFoundException, HttpRequestMethodNotSupportedException { Resources<?> resources = getCollectionResource(resourceinformation, pageable, sort, assembler); List<Link> links = new ArrayList<Link>(resources.getLinks()); for (Resource<?> resource : ((Resources<Resource<?>>) resources).getContent()) { PersistentEntityResource persistentEntityResource = (PersistentEntityResource) resource; links.add(resourceLink(resourceinformation, persistentEntityResource)); } if (resources instanceof PagedResources) { return new PagedResources<Object>(Collections.emptyList(), ((PagedResources<?>) resources).getMetadata(), links); } else { return new Resources<Object>(Collections.emptyList(), links); } }
return new Resources<Resource<?>>(EMPTY_RESOURCE_LIST, links);
@Override public Resources deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JavaType rootType = JacksonHelper.findRootType(this.contentType); JavaType wrappedType = ctxt.getTypeFactory().constructParametricType(CollectionJsonDocument.class, rootType); CollectionJsonDocument<?> document = jp.getCodec().readValue(jp, wrappedType); List<Object> contentList = new ArrayList<>(); if (document.getCollection().getItems() != null) { for (CollectionJsonItem<?> item : document.getCollection().getItems()) { Object data = item.toRawData(rootType); if (this.contentType.hasGenericTypes()) { if (isResource(this.contentType)) { contentList.add(new Resource<>(data, potentiallyAddSelfLink(item.getLinks(), item.getHref()))); } else { contentList.add(data); } } } } return new Resources(contentList, potentiallyAddSelfLink(document.getCollection().getLinks(), document.getCollection().getHref())); }
@PathVariable String property) throws Exception { Resources<Object> source = incoming == null ? new Resources<Object>(Collections.emptyList()) : incoming; RepositoryInvoker invoker = resourceInformation.getInvoker();
public HttpEntity<Resources<Offer>> getOffers() { Resources<Offer> offers = new Resources<Offer>( mockOffers()); return new HttpEntity<Resources<Offer>>(offers); }
public HttpEntity<Resources<Offer>> getOffers() { Resources<Offer> offers = new Resources<Offer>( mockOffers()); return new HttpEntity<Resources<Offer>>(offers); }
@RequestMapping public @ResponseBody Resources<Product> getProducts() { List<Product> resources = new ArrayList<Product>(); for (ProductModel productModel : productModels) { Product product = assembler.toResource(productModel); resources.add(product); } return new Resources<Product>(resources); }
@RequestMapping(value = "/{id}/sections", method = RequestMethod.GET) public ResponseEntity<Resources<SectionResource>> sections(@PathVariable String id) throws DocumentNotFoundException, TemplateNotFoundException, NotAuthenticatedException { List<SectionContent> sectionContents = documentQueryService.findSectionContents(new DocumentId(id)); return new ResponseEntity<>(new Resources<>(sectionResourceAssembler.toResources(sectionContents)), HttpStatus.OK); }
@ApiOperation( value = "Find categorization rule", authorizations = { @Authorization(value = "multibanking_auth", scopes = { @AuthorizationScope(scope = "openid", description = "") })}) @GetMapping(value = "/search") public Resources<RuleEntity> searchRules(@RequestParam String query) { return new Resources<>(rulesService.search(query)); }
@RequestMapping(method = GET, value = "/{user}/customers") Resources<Resource<Customer>> loadUserCustomers(@PathVariable Long user) { List<Resource<Customer>> customers = this.crmService.loadCustomerAccounts(user).parallelStream() .map(customerResourceAssembler::toResource) .collect(Collectors.toList()); Resources<Resource<Customer>> customerResources = new Resources<Resource<Customer>>(customers); customerResources.add(linkTo(methodOn(UserController.class).loadUserCustomers(user)).withSelfRel()); return customerResources; }
@RequestMapping(value = "/{id}/versions", method = RequestMethod.GET) public ResponseEntity<Resources<ProjectVersionResource>> getVersions(@PathVariable String id) throws ProjectNotFoundException { try { List<ProjectVersion> projectVersions = projectQueryService.findAllVersionsBy(new ProjectId(id)); List<Link> links = new ArrayList<>(); links.add(linkWithMethodPost(linkTo(methodOn(ProjectController.class).createVersion(id, null, null)).withRel(RestMethods.CREATE.getName()))); return new ResponseEntity<>(new Resources<>(projectVersionResourceAssembler.toResources(projectVersions), links), HttpStatus.OK); } catch (BindException | IncorrectProjectVersionException | NotAuthenticatedException e) { throw new RuntimeException(e); } }
public void mockSkipperAboutInfo() { AboutResource about = new AboutResource(); about.setVersionInfo(new VersionInfo()); about.getVersionInfo().setServer(new Dependency()); about.getVersionInfo().getServer().setName("Test Server"); about.getVersionInfo().getServer().setVersion("Test Version"); when(this.skipperClient.info()).thenReturn(about); when(this.skipperClient.listDeployers()).thenReturn(new Resources<>(new ArrayList<>(), new ArrayList<>())); }