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