|
31 | 31 | import java.util.stream.Stream; |
32 | 32 |
|
33 | 33 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 34 | +import io.swagger.v3.oas.annotations.Hidden; |
34 | 35 | import io.swagger.v3.oas.models.OpenAPI; |
35 | 36 | import org.apache.commons.lang3.reflect.MethodUtils; |
36 | 37 | import org.slf4j.Logger; |
|
44 | 45 |
|
45 | 46 | import org.springframework.context.ApplicationContext; |
46 | 47 | import org.springframework.core.annotation.AnnotatedElementUtils; |
| 48 | +import org.springframework.core.annotation.AnnotationUtils; |
47 | 49 | import org.springframework.data.mapping.PersistentEntity; |
48 | 50 | import org.springframework.data.mapping.PersistentProperty; |
49 | 51 | import org.springframework.data.mapping.SimpleAssociationHandler; |
@@ -219,57 +221,60 @@ public List<RouterOperation> getRouterOperations(OpenAPI openAPI, Locale locale) |
219 | 221 | dataRestRepository.setPersistentEntity(entity); |
220 | 222 | final JacksonMetadata jackson = new JacksonMetadata(mapper, domainType); |
221 | 223 |
|
222 | | - if (resourceMetadata.isExported()) { |
223 | | - for (HandlerMapping handlerMapping : handlerMappingList) { |
224 | | - if (handlerMapping instanceof RepositoryRestHandlerMapping) { |
225 | | - RepositoryRestHandlerMapping repositoryRestHandlerMapping = (RepositoryRestHandlerMapping) handlerMapping; |
226 | | - Map<RequestMappingInfo, HandlerMethod> handlerMethodMap = repositoryRestHandlerMapping.getHandlerMethods(); |
227 | | - // Entity controllers lookup first |
228 | | - Map<RequestMappingInfo, HandlerMethod> handlerMethodMapFiltered = handlerMethodMap.entrySet().stream() |
229 | | - .filter(requestMappingInfoHandlerMethodEntry -> REPOSITORY_ENTITY_CONTROLLER.equals(requestMappingInfoHandlerMethodEntry |
230 | | - .getValue().getBeanType().getName())) |
231 | | - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a1, a2) -> a1)); |
232 | | - dataRestRepository.setControllerType(ControllerType.ENTITY); |
233 | | - findControllers(routerOperationList, handlerMethodMapFiltered, resourceMetadata, dataRestRepository, openAPI); |
234 | | - |
235 | | - Map<RequestMappingInfo, HandlerMethod> handlerMethodMapFilteredMethodMap = handlerMethodMap.entrySet().stream() |
236 | | - .filter(requestMappingInfoHandlerMethodEntry -> REPOSITORY_PROPERTY_CONTROLLER.equals(requestMappingInfoHandlerMethodEntry |
237 | | - .getValue().getBeanType().getName())) |
238 | | - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a1, a2) -> a1)); |
239 | | - |
240 | | - entity.doWithAssociations((SimpleAssociationHandler) association -> { |
241 | | - PersistentProperty<?> property = association.getInverse(); |
242 | | - if (jackson.isExported(property) && associations.isLinkableAssociation(property)) { |
243 | | - dataRestRepository.setRelationName(resourceMetadata.getMappingFor(property).getRel().value()); |
244 | | - dataRestRepository.setControllerType(ControllerType.PROPERTY); |
245 | | - dataRestRepository.setCollectionLike(property.isCollectionLike()); |
246 | | - dataRestRepository.setMap(property.isMap()); |
247 | | - dataRestRepository.setPropertyType(property.getActualType()); |
248 | | - findControllers(routerOperationList, handlerMethodMapFilteredMethodMap, resourceMetadata, dataRestRepository, openAPI); |
249 | | - } |
250 | | - }); |
251 | | - } |
252 | | - else if (handlerMapping instanceof BasePathAwareHandlerMapping) { |
253 | | - BasePathAwareHandlerMapping beanBasePathAwareHandlerMapping = (BasePathAwareHandlerMapping) handlerMapping; |
254 | | - Map<RequestMappingInfo, HandlerMethod> handlerMethodMap = beanBasePathAwareHandlerMapping.getHandlerMethods(); |
255 | | - Map<RequestMappingInfo, HandlerMethod> handlerMethodMapFiltered = handlerMethodMap.entrySet().stream() |
256 | | - .filter(requestMappingInfoHandlerMethodEntry -> REPOSITORY_SCHEMA_CONTROLLER.equals(requestMappingInfoHandlerMethodEntry |
257 | | - .getValue().getBeanType().getName())) |
258 | | - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a1, a2) -> a1)); |
259 | | - dataRestRepository.setControllerType(ControllerType.SCHEMA); |
260 | | - findControllers(routerOperationList, handlerMethodMapFiltered, resourceMetadata, dataRestRepository, openAPI); |
261 | | - handlerMethodMapFiltered = handlerMethodMap.entrySet().stream() |
262 | | - .filter(requestMappingInfoHandlerMethodEntry -> ProfileController.class.equals(requestMappingInfoHandlerMethodEntry |
263 | | - .getValue().getBeanType()) || AlpsController.class.equals(requestMappingInfoHandlerMethodEntry |
264 | | - .getValue().getBeanType())) |
265 | | - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a1, a2) -> a1)); |
266 | | - dataRestRepository.setControllerType(ControllerType.GENERAL); |
267 | | - findControllers(routerOperationList, handlerMethodMapFiltered, resourceMetadata, dataRestRepository, openAPI); |
| 224 | + boolean hiddenRepository = (AnnotationUtils.findAnnotation(repository, Hidden.class) != null); |
| 225 | + if(!hiddenRepository) { |
| 226 | + if (resourceMetadata.isExported()) { |
| 227 | + for (HandlerMapping handlerMapping : handlerMappingList) { |
| 228 | + if (handlerMapping instanceof RepositoryRestHandlerMapping) { |
| 229 | + RepositoryRestHandlerMapping repositoryRestHandlerMapping = (RepositoryRestHandlerMapping) handlerMapping; |
| 230 | + Map<RequestMappingInfo, HandlerMethod> handlerMethodMap = repositoryRestHandlerMapping.getHandlerMethods(); |
| 231 | + // Entity controllers lookup first |
| 232 | + Map<RequestMappingInfo, HandlerMethod> handlerMethodMapFiltered = handlerMethodMap.entrySet().stream() |
| 233 | + .filter(requestMappingInfoHandlerMethodEntry -> REPOSITORY_ENTITY_CONTROLLER.equals(requestMappingInfoHandlerMethodEntry |
| 234 | + .getValue().getBeanType().getName())) |
| 235 | + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a1, a2) -> a1)); |
| 236 | + dataRestRepository.setControllerType(ControllerType.ENTITY); |
| 237 | + findControllers(routerOperationList, handlerMethodMapFiltered, resourceMetadata, dataRestRepository, openAPI); |
| 238 | + |
| 239 | + Map<RequestMappingInfo, HandlerMethod> handlerMethodMapFilteredMethodMap = handlerMethodMap.entrySet().stream() |
| 240 | + .filter(requestMappingInfoHandlerMethodEntry -> REPOSITORY_PROPERTY_CONTROLLER.equals(requestMappingInfoHandlerMethodEntry |
| 241 | + .getValue().getBeanType().getName())) |
| 242 | + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a1, a2) -> a1)); |
| 243 | + |
| 244 | + entity.doWithAssociations((SimpleAssociationHandler) association -> { |
| 245 | + PersistentProperty<?> property = association.getInverse(); |
| 246 | + if (jackson.isExported(property) && associations.isLinkableAssociation(property)) { |
| 247 | + dataRestRepository.setRelationName(resourceMetadata.getMappingFor(property).getRel().value()); |
| 248 | + dataRestRepository.setControllerType(ControllerType.PROPERTY); |
| 249 | + dataRestRepository.setCollectionLike(property.isCollectionLike()); |
| 250 | + dataRestRepository.setMap(property.isMap()); |
| 251 | + dataRestRepository.setPropertyType(property.getActualType()); |
| 252 | + findControllers(routerOperationList, handlerMethodMapFilteredMethodMap, resourceMetadata, dataRestRepository, openAPI); |
| 253 | + } |
| 254 | + }); |
| 255 | + } |
| 256 | + else if (handlerMapping instanceof BasePathAwareHandlerMapping) { |
| 257 | + BasePathAwareHandlerMapping beanBasePathAwareHandlerMapping = (BasePathAwareHandlerMapping) handlerMapping; |
| 258 | + Map<RequestMappingInfo, HandlerMethod> handlerMethodMap = beanBasePathAwareHandlerMapping.getHandlerMethods(); |
| 259 | + Map<RequestMappingInfo, HandlerMethod> handlerMethodMapFiltered = handlerMethodMap.entrySet().stream() |
| 260 | + .filter(requestMappingInfoHandlerMethodEntry -> REPOSITORY_SCHEMA_CONTROLLER.equals(requestMappingInfoHandlerMethodEntry |
| 261 | + .getValue().getBeanType().getName())) |
| 262 | + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a1, a2) -> a1)); |
| 263 | + dataRestRepository.setControllerType(ControllerType.SCHEMA); |
| 264 | + findControllers(routerOperationList, handlerMethodMapFiltered, resourceMetadata, dataRestRepository, openAPI); |
| 265 | + handlerMethodMapFiltered = handlerMethodMap.entrySet().stream() |
| 266 | + .filter(requestMappingInfoHandlerMethodEntry -> ProfileController.class.equals(requestMappingInfoHandlerMethodEntry |
| 267 | + .getValue().getBeanType()) || AlpsController.class.equals(requestMappingInfoHandlerMethodEntry |
| 268 | + .getValue().getBeanType())) |
| 269 | + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a1, a2) -> a1)); |
| 270 | + dataRestRepository.setControllerType(ControllerType.GENERAL); |
| 271 | + findControllers(routerOperationList, handlerMethodMapFiltered, resourceMetadata, dataRestRepository, openAPI); |
| 272 | + } |
268 | 273 | } |
269 | 274 | } |
| 275 | + // search |
| 276 | + findSearchResourceMappings(openAPI, routerOperationList, handlerMappingList, dataRestRepository, resourceMetadata); |
270 | 277 | } |
271 | | - // search |
272 | | - findSearchResourceMappings(openAPI, routerOperationList, handlerMappingList, dataRestRepository, resourceMetadata); |
273 | 278 | } |
274 | 279 | return routerOperationList; |
275 | 280 | } |
|
0 commit comments