@ SuppressWarnings ( "unchecked" ) private Set < Resource > lookupRelationshipField ( Collection < Resource > sourceResources , ResourceField relationshipField , QueryAdapter queryAdapter , RepositoryMethodParameterProvider parameterProvider , Map < ResourceIdentifier , Resource > resourceMap , Map < ResourceIdentifier , Object > entityMap ) { if ( sourceResources . isEmpty ( ) ) { return Collections . emptySet ( ) ; } ResourceInformation resourceInformation = relationshipField . getParentResourceInformation ( ) ; RegistryEntry registyEntry = resourceRegistry . getEntry ( resourceInformation . getResourceType ( ) ) ; List < Serializable > resourceIds = getIds ( sourceResources , resourceInformation ) ; boolean isMany = Iterable . class . isAssignableFrom ( relationshipField . getType ( ) ) ; Class < ? > relationshipFieldClass = relationshipField . getElementType ( ) ; Set < Resource > loadedTargets = new HashSet <> ( ) ; @ SuppressWarnings ( "rawtypes" ) RelationshipRepositoryAdapter relationshipRepository = registyEntry . getRelationshipRepositoryForClass ( relationshipFieldClass , parameterProvider ) ; if ( relationshipRepository != null ) { Map < Object , JsonApiResponse > responseMap ; if ( isMany ) { responseMap = relationshipRepository . findBulkManyTargets ( resourceIds , relationshipField , queryAdapter ) ; } else { responseMap = relationshipRepository . findBulkOneTargets ( resourceIds , relationshipField , queryAdapter ) ; } for ( Resource sourceResource : sourceResources ) { Serializable sourceId = resourceInformation . parseIdString ( sourceResource . getId ( ) ) ; JsonApiResponse targetResponse = responseMap . get ( sourceId ) ; if ( targetResponse != null && targetResponse . getEntity ( ) != null ) { Object targetEntity = targetResponse . getEntity ( ) ; List < Resource > targets = setupRelation ( sourceResource , relationshipField , targetEntity , queryAdapter , resourceMap , entityMap ) ; loadedTargets . addAll ( targets ) ; } else { Nullable < Object > emptyData = Nullable . of ( Iterable . class . isAssignableFrom ( relationshipField . getType ( ) ) ? ( Object ) Collections . emptyList ( ) : null ) ; Relationship relationship = sourceResource . getRelationships ( ) . get ( relationshipField . getJsonName ( ) ) ; relationship . setData ( emptyData ) ; } } } return loadedTargets ; }
Loads all related resources for the given resources and relationship field . It updates the relationship data of the source resources accordingly and returns the loaded resources for potential inclusion in the result document .