Package org.springframework.data.rest.core.mapping

Examples of org.springframework.data.rest.core.mapping.ResourceMetadata


    ResourceTester tester = ResourceTester.of(response.getBody());
    PagedResources<Object> pagedResources = tester.assertIsPage();
    assertThat(pagedResources.getContent().size(), is(1));

    ResourceMetadata metadata = getMetadata(Person.class);
    tester.withContentResource(new HasSelfLink(BASE.slash(metadata.getPath()).slash("{id}")));
  }
View Full Code Here


    if (response.getStatusCode() != HttpStatus.OK) {
      return response;
    }

    ResourceMetadata repoMapping = repoRequest.getResourceMetadata();
    PersistentProperty<?> persistentProp = repoRequest.getPersistentEntity().getPersistentProperty(property);
    ResourceMapping propertyMapping = repoMapping.getMappingFor(persistentProp);

    ResourceSupport resource = response.getBody();

    List<Link> links = new ArrayList<Link>();
View Full Code Here

   */
  @Override
  public RootResourceInformation resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
      NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

    ResourceMetadata resourceMetadata = resourceMetadataResolver.resolveArgument(parameter, mavContainer, webRequest,
        binderFactory);

    Class<?> domainType = resourceMetadata.getDomainType();
    RepositoryInvoker repositoryInvoker = invokerFactory.getInvokerFor(domainType);
    PersistentEntity<?, ?> persistentEntity = repositories.getPersistentEntity(domainType);

    // TODO reject if ResourceMetadata cannot be resolved
    return new RootResourceInformation(resourceMetadata, persistentEntity, repositoryInvoker);
View Full Code Here

    if (!hasText(repositoryKey)) {
      return null;
    }

    for (Class<?> domainType : repositories) {
      ResourceMetadata mapping = mappings.getMappingFor(domainType);
      if (mapping.getPath().matches(repositoryKey) && mapping.isExported()) {
        return mapping;
      }
    }

    throw new IllegalArgumentException(String.format("Could not resolve repository metadata for %s.", repositoryKey));
View Full Code Here

    return Alps.alps().descriptors(descriptors).build();
  }

  private Descriptor buildRepresentationDescriptor(Class<?> type) {

    ResourceMetadata metadata = mappings.getMappingFor(type);

    return descriptor().//
        id(metadata.getItemResourceRel().concat("-representation")).//
        doc(getDocFor(metadata.getItemResourceDescription())).//
        descriptors(buildPropertyDescriptors(type, metadata.getItemResourceRel())).//
        build();
  }
View Full Code Here

   * @see org.springframework.hateoas.EntityLinks#linkFor(java.lang.Class)
   */
  @Override
  public LinkBuilder linkFor(Class<?> type) {

    ResourceMetadata metadata = mappings.getMappingFor(type);
    return new RepositoryLinkBuilder(metadata, new BaseUri(config.getBaseUri()));
  }
View Full Code Here

    return linkFor(type);
  }

  public Link linkToPagedResource(Class<?> type, Pageable pageable) {

    ResourceMetadata metadata = mappings.getMappingFor(type);
    TemplateVariables variables = new TemplateVariables();
    String href = linkFor(type).withSelfRel().getHref();

    if (metadata.isPagingResource()) {

      UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(href);

      if (pageable != null) {
        resolver.enhance(builder, null, pageable);
      }

      href = builder.build().toString();

      variables = variables.concat(resolver.getPaginationTemplateVariables(null, builder.build()));
    }

    ProjectionDefinitionConfiguration projectionConfiguration = config.projectionConfiguration();

    if (projectionConfiguration.hasProjectionFor(type)) {
      variables = variables.concat(new TemplateVariable(projectionConfiguration.getParameterName(), REQUEST_PARAM));
    }

    return variables.asList().isEmpty() ? linkFor(type).withRel(metadata.getRel()) : new Link(new UriTemplate(href,
        variables), metadata.getRel());
  }
View Full Code Here

  }

  private Descriptor buildCollectionResourceDescriptor(Class<?> type, RootResourceInformation resourceInformation,
      Descriptor representationDescriptor, HttpMethod method) {

    ResourceMetadata metadata = mappings.getMappingFor(type);

    List<Descriptor> nestedDescriptors = new ArrayList<Descriptor>();
    nestedDescriptors.addAll(getPaginationDescriptors(type, method));
    nestedDescriptors.addAll(getProjectionDescriptor(type, method));

    Type descriptorType = getType(method);
    return descriptor().//
        id(prefix(method).concat(metadata.getRel())).//
        name(metadata.getRel()).//
        type(descriptorType).//
        doc(getDocFor(metadata.getDescription())).//
        rt("#" + representationDescriptor.getId()).//
        descriptors(nestedDescriptors).build();
  }
View Full Code Here

  private Descriptor buildItemResourceDescriptor(RootResourceInformation resourceInformation,
      Descriptor representationDescriptor, HttpMethod method) {

    PersistentEntity<?, ?> entity = resourceInformation.getPersistentEntity();
    ResourceMetadata metadata = mappings.getMappingFor(entity.getType());

    return descriptor().//
        id(prefix(method).concat(metadata.getItemResourceRel())).//
        name(metadata.getItemResourceRel()).//
        type(getType(method)).//
        doc(getDocFor(metadata.getItemResourceDescription())).//
        rt("#".concat(representationDescriptor.getId())). //
        descriptors(getProjectionDescriptor(entity.getType(), method)).//
        build();
  }
View Full Code Here

  @Override
  public Link linkToSingleResource(Class<?> type, Object id) {

    Assert.isInstanceOf(Serializable.class, id, "Id must be assignable to Serializable!");

    ResourceMetadata metadata = mappings.getMappingFor(type);
    String mappedId = idConverters.getPluginFor(type, DefaultIdConverter.INSTANCE).toRequestId((Serializable) id, type);

    Link link = linkFor(type).slash(mappedId).withRel(metadata.getItemResourceRel());
    ProjectionDefinitionConfiguration projectionConfiguration = config.projectionConfiguration();

    if (!projectionConfiguration.hasProjectionFor(type)) {
      return link;
    }

    String parameterName = projectionConfiguration.getParameterName();
    TemplateVariables templateVariables = new TemplateVariables(new TemplateVariable(parameterName, REQUEST_PARAM));
    UriTemplate template = new UriTemplate(link.getHref(), templateVariables);

    return new Link(template.toString(), metadata.getItemResourceRel());
  }
View Full Code Here

TOP

Related Classes of org.springframework.data.rest.core.mapping.ResourceMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.