List of usage examples for org.springframework.data.rest.core.mapping ResourceMetadata getRel
LinkRelation getRel();
From source file:org.moserp.common.structure.factories.AssociationPropertyFactory.java
private String calculateUri(PropertyFactoryContext context) { ResourceMetadata mapping = mappings.getMetadataFor(context.getPersistentProperty().getType()); final BaseUri baseUri = new BaseUri("http://" + moduleRegistry.getModuleForResource(mapping.getRel())); UriComponentsBuilder builder = baseUri.getUriComponentsBuilder(); return builder.path(mapping.getPath().toString()).build().toUriString(); }
From source file:org.moserp.common.structure.ApplicationStructureController.java
@RequestMapping(value = BASE_PATH, method = RequestMethod.GET) public HttpEntity<Map<String, ResourceSupport>> listRepositories() { Map<String, ResourceSupport> groups = new HashMap<>(); for (Class<?> domainType : repositories) { ResourceMetadata metadata = mappings.getMetadataFor(domainType); if (!metadata.isExported()) { continue; }//from w w w .j a v a 2s. co m String group = groupResolver.resolveGroup(domainType); ResourceSupport resource = groups.get(group); if (resource == null) { resource = new ResourceSupport(); groups.put(group, resource); } resource.add(new Link(getPath(metadata), metadata.getRel())); } return new ResponseEntity<>(groups, HttpStatus.OK); }
From source file:org.springframework.data.rest.webmvc.alps.RootResourceInformationToAlpsDescriptorConverter.java
private Descriptor buildCollectionResourceDescriptor(Class<?> type, RootResourceInformation resourceInformation, Descriptor representationDescriptor, HttpMethod method) { ResourceMetadata metadata = associations.getMetadataFor(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(); }
From source file:org.springframework.data.rest.webmvc.alps.RootResourceInformationToAlpsDescriptorConverter.java
/** * Builds a descriptor for the projection parameter of the given resource. * // www . j a va 2s.c om * @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(); }