Example usage for org.springframework.data.rest.core.config ProjectionDefinitionConfiguration getProjectionsFor

List of usage examples for org.springframework.data.rest.core.config ProjectionDefinitionConfiguration getProjectionsFor

Introduction

In this page you can find the example usage for org.springframework.data.rest.core.config ProjectionDefinitionConfiguration getProjectionsFor.

Prototype

public Map<String, Class<?>> getProjectionsFor(Class<?> sourceType) 

Source Link

Document

Returns all projections registered for the given source type.

Usage

From source file:org.springframework.data.rest.webmvc.alps.RootResourceInformationToAlpsDescriptorConverter.java

/**
 * Builds a descriptor for the projection parameter of the given resource.
 * //from w  w  w.j av  a  2s  .  c  o  m
 * @param metadata
 * @return
 */
private Descriptor buildProjectionDescriptor(ResourceMetadata metadata) {

    ProjectionDefinitionConfiguration projectionConfiguration = configuration.getProjectionConfiguration();
    String projectionParameterName = projectionConfiguration.getParameterName();

    Map<String, Class<?>> projections = projectionConfiguration.getProjectionsFor(metadata.getDomainType());
    List<Descriptor> projectionDescriptors = new ArrayList<Descriptor>(projections.size());

    for (Entry<String, Class<?>> projection : projections.entrySet()) {

        Class<?> type = projection.getValue();
        String key = String.format("%s.%s.%s", metadata.getRel(), projectionParameterName, projection.getKey());
        ResourceDescription fallback = SimpleResourceDescription.defaultFor(key);
        AnnotationBasedResourceDescription projectionDescription = new AnnotationBasedResourceDescription(type,
                fallback);

        projectionDescriptors.add(//
                descriptor().//
                        type(Type.SEMANTIC).//
                        name(projection.getKey()).//
                        doc(getDocFor(projectionDescription)).//
                        descriptors(createJacksonDescriptor(projection.getKey(), type)).//
                        build());
    }

    return descriptor().//
            type(Type.SEMANTIC).//
            name(projectionParameterName).//
            doc(getDocFor(SimpleResourceDescription.defaultFor(projectionParameterName))).//
            descriptors(projectionDescriptors).build();
}