org.springframework.data.rest.core.mapping.ResourceMetadata Java Examples
The following examples show how to use
org.springframework.data.rest.core.mapping.ResourceMetadata.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpringRepositoryRestResourceProvider.java From springdoc-openapi with Apache License 2.0 | 6 votes |
/** * Find search resource mappings. * * @param openAPI the open api * @param routerOperationList the router operation list * @param handlerMappingList the handler mapping list * @param domainType the domain type * @param resourceMetadata the resource metadata */ private void findSearchResourceMappings(OpenAPI openAPI, List<RouterOperation> routerOperationList, List<HandlerMapping> handlerMappingList, Class<?> domainType, ResourceMetadata resourceMetadata) { for (HandlerMapping handlerMapping : handlerMappingList) { if (handlerMapping instanceof RepositoryRestHandlerMapping) { RepositoryRestHandlerMapping repositoryRestHandlerMapping = (RepositoryRestHandlerMapping) handlerMapping; Map<RequestMappingInfo, HandlerMethod> handlerMethodMap = repositoryRestHandlerMapping.getHandlerMethods(); Map<RequestMappingInfo, HandlerMethod> handlerMethodMapFiltered = handlerMethodMap.entrySet().stream() .filter(requestMappingInfoHandlerMethodEntry -> REPOSITORY_SERACH_CONTROLLER.equals(requestMappingInfoHandlerMethodEntry .getValue().getBeanType().getName())) .filter(controller -> !AbstractOpenApiResource.isHiddenRestControllers(controller.getValue().getBeanType())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a1, a2) -> a1)); ResourceMetadata metadata = associations.getMetadataFor(domainType); SearchResourceMappings searchResourceMappings = metadata.getSearchResourceMappings(); if (searchResourceMappings.isExported()) { findSearchControllers(routerOperationList, handlerMethodMapFiltered, resourceMetadata, domainType, openAPI, searchResourceMappings); } } } }
Example #2
Source File: AssociationPropertyFactoryTest.java From moserp with Apache License 2.0 | 6 votes |
@Before public void setup() { when(persistentProperty.isAssociation()).thenReturn(true); when(persistentProperty.getActualType()).thenReturn((Class) OtherRepositoryClass.class); when(persistentProperty.getType()).thenReturn((Class) OtherRepositoryClass.class); ResourceMappings mappings = mock(ResourceMappings.class); ResourceMetadata metaData = mock(ResourceMetadata.class); when(metaData.getPath()).thenReturn(new Path("otherRepositoryClasses")); when(metaData.isExported()).thenReturn(true); when(mappings.getMetadataFor(eq(OtherRepositoryClass.class))).thenReturn(metaData); ModuleRegistry moduleRegistry = mock(ModuleRegistry.class); when(moduleRegistry.getModuleForResource(anyString())).thenReturn("environment-module"); propertyFactory = new AssociationPropertyFactory(createConfiguration(), mappings, moduleRegistry); }
Example #3
Source File: DataRestRequestBuilder.java From springdoc-openapi with Apache License 2.0 | 5 votes |
/** * Build parameters. * * @param domainType the domain type * @param openAPI the open api * @param handlerMethod the handler method * @param requestMethod the request method * @param methodAttributes the method attributes * @param operation the operation * @param resourceMetadata the resource metadata */ public void buildParameters(Class<?> domainType, OpenAPI openAPI, HandlerMethod handlerMethod, RequestMethod requestMethod, MethodAttributes methodAttributes, Operation operation, ResourceMetadata resourceMetadata) { String[] pNames = this.localSpringDocParameterNameDiscoverer.getParameterNames(handlerMethod.getMethod()); MethodParameter[] parameters = handlerMethod.getMethodParameters(); if (!resourceMetadata.isPagingResource()) { Optional<MethodParameter> methodParameterPage = Arrays.stream(parameters).filter(methodParameter -> DefaultedPageable.class.equals(methodParameter.getParameterType())).findFirst(); if (methodParameterPage.isPresent()) parameters = ArrayUtils.removeElement(parameters, methodParameterPage.get()); } String[] reflectionParametersNames = Arrays.stream(handlerMethod.getMethod().getParameters()).map(java.lang.reflect.Parameter::getName).toArray(String[]::new); if (pNames == null || Arrays.stream(pNames).anyMatch(Objects::isNull)) pNames = reflectionParametersNames; buildCommonParameters(domainType, openAPI, requestMethod, methodAttributes, operation, pNames, parameters); }
Example #4
Source File: DataRestRouterOperationBuilder.java From springdoc-openapi with Apache License 2.0 | 5 votes |
/** * Build search router operation list. * * @param routerOperationList the router operation list * @param handlerMethodMap the handler method map * @param resourceMetadata the resource metadata * @param domainType the domain type * @param openAPI the open api * @param methodResourceMapping the method resource mapping */ public void buildSearchRouterOperationList(List<RouterOperation> routerOperationList, Map<RequestMappingInfo, HandlerMethod> handlerMethodMap, ResourceMetadata resourceMetadata, Class<?> domainType, OpenAPI openAPI, MethodResourceMapping methodResourceMapping) { String path = resourceMetadata.getPath().toString(); Path subPath = methodResourceMapping.getPath(); Optional<Entry<RequestMappingInfo, HandlerMethod>> entryOptional = getSearchEntry(handlerMethodMap); if (entryOptional.isPresent()) { Entry<RequestMappingInfo, HandlerMethod> entry = entryOptional.get(); buildRouterOperationList(routerOperationList, null, domainType, openAPI, path, entry, subPath.toString(), ControllerType.SEARCH, methodResourceMapping); } }
Example #5
Source File: DataRestRouterOperationBuilder.java From springdoc-openapi with Apache License 2.0 | 5 votes |
/** * Build router operation. * * @param routerOperationList the router operation list * @param domainType the domain type * @param openAPI the open api * @param methodResourceMapping the method resource mapping * @param handlerMethod the handler method * @param requestMethod the request method * @param resourceMetadata the resource metadata * @param operationPath the operation path * @param controllerType the controller type */ private void buildRouterOperation(List<RouterOperation> routerOperationList, Class<?> domainType, OpenAPI openAPI, MethodResourceMapping methodResourceMapping, HandlerMethod handlerMethod, RequestMethod requestMethod, ResourceMetadata resourceMetadata, String operationPath, ControllerType controllerType) { RouterOperation routerOperation = new RouterOperation(operationPath, new RequestMethod[] { requestMethod }); MethodAttributes methodAttributes = new MethodAttributes(springDocConfigProperties.getDefaultConsumesMediaType(), springDocConfigProperties.getDefaultProducesMediaType()); methodAttributes.calculateConsumesProduces(handlerMethod.getMethod()); routerOperation.setConsumes(methodAttributes.getMethodConsumes()); routerOperation.setProduces(methodAttributes.getMethodProduces()); Operation operation = dataRestOperationBuilder.buildOperation(handlerMethod, domainType, openAPI, requestMethod, operationPath, methodAttributes, resourceMetadata, methodResourceMapping, controllerType); routerOperation.setOperationModel(operation); routerOperationList.add(routerOperation); }
Example #6
Source File: DataRestOperationBuilder.java From springdoc-openapi with Apache License 2.0 | 5 votes |
/** * Build operation operation. * * @param handlerMethod the handler method * @param domainType the domain type * @param openAPI the open api * @param requestMethod the request method * @param operationPath the operation path * @param methodAttributes the method attributes * @param resourceMetadata the resource metadata * @param methodResourceMapping the method resource mapping * @param controllerType the controller type * @return the operation */ public Operation buildOperation(HandlerMethod handlerMethod, Class<?> domainType, OpenAPI openAPI, RequestMethod requestMethod, String operationPath, MethodAttributes methodAttributes, ResourceMetadata resourceMetadata, MethodResourceMapping methodResourceMapping, ControllerType controllerType) { Operation operation = null; if (ControllerType.ENTITY.equals(controllerType)) { operation = buildEntityOperation(handlerMethod, domainType, openAPI, requestMethod, operationPath, methodAttributes, resourceMetadata); } else if (ControllerType.SEARCH.equals(controllerType)) { operation = buildSearchOperation(handlerMethod, domainType, openAPI, requestMethod, methodAttributes, methodResourceMapping); } return operation; }
Example #7
Source File: ContentLinksResourceProcessor.java From spring-content with Apache License 2.0 | 5 votes |
private Link propertyLink(ResourceMetadata md, URI baseUri, Object id, String property, String contentId) { LinkBuilder builder = new RepositoryLinkBuilder(md, new BaseUri(baseUri)); builder = builder.slash(id).slash(property); if (contentId != null) { builder = builder.slash(contentId); } return builder.withRel(property); }
Example #8
Source File: ApplicationStructureBuilderTest.java From moserp with Apache License 2.0 | 5 votes |
public void setupMocks() throws URISyntaxException { configuration = mock(RepositoryRestConfiguration.class); when(configuration.getBaseUri()).thenReturn(new URI("http://localhost:8080/")); mappings = mock(ResourceMappings.class); metaData = mock(ResourceMetadata.class); when(metaData.getPath()).thenReturn(new Path("valueLists")); PersistentEntity persistentEntity = mock(PersistentEntity.class); when(persistentEntities.getPersistentEntity(any())).thenReturn(persistentEntity); PersistentProperty persistentProperty = mock(PersistentProperty.class); when(persistentEntity.getPersistentProperty(any(String.class))).thenReturn(persistentProperty); when(entityLinks.linkFor(any())).thenReturn(BaseUriLinkBuilder.create(new URI("http://localhost:8080/"))); moduleRegistry = mock(ModuleRegistry.class); when(moduleRegistry.getBaseUriForResource(anyString())).thenReturn(new RestUri("http://localhost:8080/valueLists")); }
Example #9
Source File: JsonSchemaBuilderTest.java From moserp with Apache License 2.0 | 5 votes |
public void setupMocks() throws URISyntaxException { configuration = mock(RepositoryRestConfiguration.class); when(configuration.getBaseUri()).thenReturn(new URI("http://localhost:8080/")); mappings = mock(ResourceMappings.class); metaData = mock(ResourceMetadata.class); when(metaData.getPath()).thenReturn(new Path("valueLists")); PersistentEntity persistentEntity = mock(PersistentEntity.class); when(persistentEntities.getPersistentEntity(any())).thenReturn(persistentEntity); PersistentProperty persistentProperty = mock(PersistentProperty.class); when(persistentEntity.getPersistentProperty(any(String.class))).thenReturn(persistentProperty); when(entityLinks.linkFor(any())).thenReturn(BaseUriLinkBuilder.create(new URI("http://localhost:8080/"))); moduleRegistry = mock(ModuleRegistry.class); when(moduleRegistry.getBaseUriForResource(anyString())).thenReturn(new RestUri("http://localhost:8080/valueLists")); }
Example #10
Source File: AssociationPropertyFactory.java From moserp with Apache License 2.0 | 4 votes |
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(); }
Example #11
Source File: DemoRepositoryEntityLinks.java From spring-data-dynamodb-demo with Apache License 2.0 | 4 votes |
@Override public LinkBuilder linkFor(Class<?> type) { ResourceMetadata metadata = resourceMappings.getMappingFor(type); return new DemoRepositoryLinkBuilder(metadata, config.getBaseUri()); }
Example #12
Source File: DemoRepositoryLinkBuilder.java From spring-data-dynamodb-demo with Apache License 2.0 | 4 votes |
public DemoRepositoryLinkBuilder(ResourceMetadata metadata, URI baseUri) { super(metadata, baseUri); }
Example #13
Source File: SpringRepositoryRestResourceProvider.java From springdoc-openapi with Apache License 2.0 | 3 votes |
/** * Find search controllers list. * * @param routerOperationList the router operation list * @param handlerMethodMap the handler method map * @param resourceMetadata the resource metadata * @param domainType the domain type * @param openAPI the open api * @param searchResourceMappings the search resource mappings * @return the list */ private List<RouterOperation> findSearchControllers(List<RouterOperation> routerOperationList, Map<RequestMappingInfo, HandlerMethod> handlerMethodMap, ResourceMetadata resourceMetadata, Class<?> domainType, OpenAPI openAPI, SearchResourceMappings searchResourceMappings) { Stream<MethodResourceMapping> methodResourceMappingStream = searchResourceMappings.getExportedMappings(); methodResourceMappingStream.forEach(methodResourceMapping -> dataRestRouterOperationBuilder.buildSearchRouterOperationList( routerOperationList, handlerMethodMap, resourceMetadata, domainType, openAPI, methodResourceMapping)); return routerOperationList; }
Example #14
Source File: SpringRepositoryRestResourceProvider.java From springdoc-openapi with Apache License 2.0 | 3 votes |
/** * Find controllers list. * * @param routerOperationList the router operation list * @param handlerMethodMap the handler method map * @param resourceMetadata the resource metadata * @param domainType the domain type * @param openAPI the open api * @return the list */ private List<RouterOperation> findControllers (List<RouterOperation> routerOperationList, Map<RequestMappingInfo, HandlerMethod> handlerMethodMap, ResourceMetadata resourceMetadata, Class<?> domainType, OpenAPI openAPI) { dataRestRouterOperationBuilder.buildEntityRouterOperationList(routerOperationList, handlerMethodMap, resourceMetadata, domainType, openAPI); return routerOperationList; }
Example #15
Source File: DataRestRouterOperationBuilder.java From springdoc-openapi with Apache License 2.0 | 3 votes |
/** * Build entity router operation list. * * @param routerOperationList the router operation list * @param handlerMethodMap the handler method map * @param resourceMetadata the resource metadata * @param domainType the domain type * @param openAPI the open api */ public void buildEntityRouterOperationList(List<RouterOperation> routerOperationList, Map<RequestMappingInfo, HandlerMethod> handlerMethodMap, ResourceMetadata resourceMetadata, Class<?> domainType, OpenAPI openAPI) { String path = resourceMetadata.getPath().toString(); for (Entry<RequestMappingInfo, HandlerMethod> entry : handlerMethodMap.entrySet()) { buildRouterOperationList(routerOperationList, resourceMetadata, domainType, openAPI, path, entry, null, ControllerType.ENTITY, null); } }
Example #16
Source File: DataRestOperationBuilder.java From springdoc-openapi with Apache License 2.0 | 3 votes |
/** * Build entity operation operation. * * @param handlerMethod the handler method * @param domainType the domain type * @param openAPI the open api * @param requestMethod the request method * @param operationPath the operation path * @param methodAttributes the method attributes * @param resourceMetadata the resource metadata * @return the operation */ private Operation buildEntityOperation(HandlerMethod handlerMethod, Class<?> domainType, OpenAPI openAPI, RequestMethod requestMethod, String operationPath, MethodAttributes methodAttributes, ResourceMetadata resourceMetadata) { Operation operation = initOperation(handlerMethod, domainType, requestMethod); dataRestRequestBuilder.buildParameters(domainType, openAPI, handlerMethod, requestMethod, methodAttributes, operation, resourceMetadata); dataRestResponseBuilder.buildEntityResponse(operation, handlerMethod, openAPI, requestMethod, operationPath, domainType, methodAttributes); tagsBuilder.buildEntityTags(operation, openAPI, handlerMethod, domainType); if (domainType != null) addOperationDescription(operation, requestMethod, domainType.getSimpleName().toLowerCase()); return operation; }