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

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


        DescriptorBuilder builder = descriptor().//
            name(mapping.getRel()).doc(getDocFor(mapping.getDescription()));

        if (associationLinks.isLinkableAssociation(property)) {

          ResourceMetadata targetTypeMapping = mappings.getMappingFor(property.getActualType());
          String localPath = targetTypeMapping.getRel().concat("#").concat(targetTypeMapping.getItemResourceRel());
          Link link = ControllerLinkBuilder.linkTo(AlpsController.class).slash(localPath).withSelfRel();

          builder.//
              type(Type.SAFE).//
              rt(link.getHref());
View Full Code Here


    return propertyDescriptors;
  }

  private Collection<Descriptor> buildSearchResourceDescriptors(PersistentEntity<?, ?> entity) {

    ResourceMetadata metadata = mappings.getMappingFor(entity.getType());
    List<Descriptor> descriptors = new ArrayList<Descriptor>();

    for (MethodResourceMapping methodMapping : metadata.getSearchResourceMappings()) {

      List<Descriptor> parameterDescriptors = new ArrayList<Descriptor>();

      for (ParameterMetadata parameterMetadata : methodMapping.getParametersMetadata()) {
View Full Code Here

    PersistentEntity<?, ?> entity = repositories.getPersistentEntity(instance.getClass());

    final List<EmbeddedWrapper> associationProjections = new ArrayList<EmbeddedWrapper>();
    final BeanWrapper<Object> wrapper = BeanWrapper.create(instance, null);
    final AssociationLinks associationLinks = new AssociationLinks(mappings);
    final ResourceMetadata metadata = mappings.getMappingFor(instance.getClass());

    entity.doWithAssociations(new SimpleAssociationHandler() {

      /*
       * (non-Javadoc)
       * @see org.springframework.data.mapping.SimpleAssociationHandler#doWithAssociation(org.springframework.data.mapping.Association)
       */
      @Override
      public void doWithAssociation(Association<? extends PersistentProperty<?>> association) {

        PersistentProperty<?> property = association.getInverse();

        if (!associationLinks.isLinkableAssociation(property)) {
          return;
        }

        if (!projector.hasExcerptProjection(property.getActualType())) {
          return;
        }

        Object value = wrapper.getProperty(association.getInverse());

        if (value == null) {
          return;
        }

        String rel = metadata.getMappingFor(property).getRel();

        if (value instanceof Collection) {

          Collection<?> collection = (Collection<?>) value;

View Full Code Here

    List<Descriptor> descriptors = new ArrayList<Descriptor>();

    for (Class<?> domainType : repositories) {

      ResourceMetadata mapping = mappings.getMappingFor(domainType);

      if (mapping.isExported()) {

        BaseUri baseUri = new BaseUri(configuration.getBaseUri());
        UriComponentsBuilder builder = baseUri.getUriComponentsBuilder().path(ALPS_ROOT_MAPPING);
        String href = builder.path(mapping.getPath().toString()).build().toUriString();
        descriptors.add(Alps.descriptor().name(mapping.getRel()).href(href).build());
      }
    }

    Alps alps = Alps.alps().//
        descriptors(descriptors).//
View Full Code Here

   */
  public ResourceMapping getMappingFor(PersistentProperty<?> property) {

    Assert.notNull(property, "PersistentProperty must not be null!");

    ResourceMetadata metadata = resourceMetadata.get(property);

    if (metadata != null) {
      return metadata.getMappingFor(property);
    }

    metadata = resourceMappings.getMappingFor(property.getOwner().getType());

    if (metadata != null) {
View Full Code Here

    return new ResponseEntity<T>(body, hdrs, status);
  }

  protected Link resourceLink(RootResourceInformation resourceLink, Resource resource) {

    ResourceMetadata repoMapping = resourceLink.getResourceMetadata();

    Link selfLink = resource.getLink("self");
    String rel = repoMapping.getItemResourceRel();

    return new Link(selfLink.getHref(), rel);
  }
View Full Code Here

   */
  @Override
  public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {

    final PersistentEntity<?, ?> persistentEntity = repositories.getPersistentEntity((Class<?>) source);
    final ResourceMetadata metadata = mappings.getMappingFor(persistentEntity.getType());
    final JsonSchema jsonSchema = new JsonSchema(persistentEntity.getName(),
        resolveMessage(metadata.getItemResourceDescription()));

    persistentEntity.doWithProperties(new SimplePropertyHandler() {

      /*
       * (non-Javadoc)
       * @see org.springframework.data.mapping.PropertyHandler#doWithPersistentProperty(org.springframework.data.mapping.PersistentProperty)
       */
      @Override
      public void doWithPersistentProperty(PersistentProperty<?> persistentProperty) {

        Class<?> propertyType = persistentProperty.getType();
        String type = uncapitalize(propertyType.getSimpleName());

        ResourceMapping propertyMapping = metadata.getMappingFor(persistentProperty);
        ResourceDescription description = propertyMapping.getDescription();
        String message = resolveMessage(description);

        Property property = persistentProperty.isCollectionLike() ? //
        new ArrayProperty("array", message, false)
View Full Code Here

    if (property == null || !property.isAssociation()) {
      return false;
    }

    ResourceMetadata metadata = mappings.getMappingFor(property.getOwner().getType());

    if (metadata != null && !metadata.isExported(property)) {
      return false;
    }

    metadata = mappings.getMappingFor(property.getActualType());
    return metadata == null ? false : metadata.isExported();
  }
View Full Code Here

  }

  private void assertRootUriFor(String baseUri, String expectedUri) {

    MongoPersistentEntity<?> entity = context.getPersistentEntity(Profile.class);
    ResourceMetadata metadata = new MappingResourceMetadata(entity);

    RepositoryLinkBuilder builder = new RepositoryLinkBuilder(metadata, new BaseUri(baseUri));
    Link link = builder.withSelfRel();

    assertThat(link.getHref(), is(expectedUri));
View Full Code Here

      throw new IllegalArgumentException(String.format(
          "Method parameter for @%s must be of type %s! Got %s for method %s.", BackendId.class.getSimpleName(),
          Serializable.class.getSimpleName(), parameterType.getSimpleName(), parameter.getMethod()));
    }

    ResourceMetadata metadata = resourceMetadataResolver.resolveArgument(parameter, mavContainer, request,
        binderFactory);

    if (metadata == null) {
      throw new IllegalArgumentException("Could not obtain ResourceMetadata for request " + request);
    }

    BackendIdConverter pluginFor = idConverters.getPluginFor(metadata.getDomainType(), DefaultIdConverter.INSTANCE);
    String lookupPath = baseUri.getRepositoryLookupPath(request);
    return pluginFor.fromRequestId(UriUtils.findMappingVariable("id", parameter.getMethod(), lookupPath),
        metadata.getDomainType());
  }
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.