Skip to content

Commit 031c8a6

Browse files
committed
GH-2383 - Clean up projection property filter support.
Closes #2383
1 parent 33d1a20 commit 031c8a6

File tree

1 file changed

+5
-43
lines changed

1 file changed

+5
-43
lines changed

src/main/java/org/springframework/data/neo4j/core/PropertyFilterSupport.java

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,14 @@
1818
import org.apiguardian.api.API;
1919
import org.springframework.data.mapping.PropertyPath;
2020
import org.springframework.data.neo4j.core.mapping.Neo4jMappingContext;
21-
import org.springframework.data.neo4j.core.mapping.Neo4jPersistentEntity;
22-
import org.springframework.data.neo4j.core.mapping.Neo4jPersistentProperty;
2321
import org.springframework.data.projection.ProjectionFactory;
2422
import org.springframework.data.projection.ProjectionInformation;
2523
import org.springframework.data.repository.query.ResultProcessor;
2624
import org.springframework.data.repository.query.ReturnedType;
2725

2826
import java.beans.PropertyDescriptor;
29-
import java.util.Collection;
3027
import java.util.Collections;
3128
import java.util.HashMap;
32-
import java.util.HashSet;
3329
import java.util.Map;
3430

3531
/**
@@ -95,7 +91,7 @@ private static void addPropertiesFrom(Class<?> domainType, Class<?> returnedType
9591
if (mappingContext.getConversionService().isSimpleType(propertyType)) {
9692
filteredProperties.put(propertyPath, false);
9793
} else if (mappingContext.hasPersistentEntityFor(propertyType)) {
98-
addPropertiesFromEntity(filteredProperties, propertyPath, propertyType, mappingContext, new HashSet<>());
94+
filteredProperties.put(propertyPath, true);
9995
} else {
10096
ProjectionInformation nestedProjectionInformation = factory.getProjectionInformation(propertyType);
10197
// Closed projection should get handled as above (recursion)
@@ -112,46 +108,12 @@ private static void addPropertiesFrom(Class<?> domainType, Class<?> returnedType
112108
nestedPropertyPath.toDotPath(), mappingContext);
113109
}
114110
} else {
115-
// an open projection at this place needs to get replaced with the matching (real) entity
116-
filteredProperties.put(propertyPath, true);
117-
processEntity(domainType, filteredProperties, inputProperty, mappingContext);
111+
// An open projection at this place needs to get replaced with the matching (real) entity
112+
// Use domain type as root type for the property path
113+
PropertyPath domainBasedPropertyPath = PropertyPath.from(inputProperty, domainType);
114+
filteredProperties.put(domainBasedPropertyPath, true);
118115
}
119116
}
120117
}
121118

122-
private static void processEntity(Class<?> domainType, Map<PropertyPath, Boolean> filteredProperties,
123-
String inputProperty, Neo4jMappingContext mappingContext) {
124-
125-
Neo4jPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(domainType);
126-
Neo4jPersistentProperty persistentProperty = persistentEntity.getPersistentProperty(inputProperty);
127-
Class<?> propertyEntityType = persistentProperty.getActualType();
128-
129-
// Use domain type as root type for the property path
130-
PropertyPath propertyPath = PropertyPath.from(inputProperty, domainType);
131-
addPropertiesFromEntity(filteredProperties, propertyPath, propertyEntityType, mappingContext, new HashSet<>());
132-
}
133-
134-
private static void addPropertiesFromEntity(Map<PropertyPath, Boolean> filteredProperties, PropertyPath propertyPath,
135-
Class<?> propertyType, Neo4jMappingContext mappingContext,
136-
Collection<Neo4jPersistentEntity<?>> processedEntities) {
137-
138-
if (!mappingContext.hasPersistentEntityFor(propertyType)) {
139-
throw new RuntimeException("hmmmm");
140-
}
141-
142-
Neo4jPersistentEntity<?> persistentEntityFromProperty = mappingContext.getPersistentEntity(propertyType);
143-
// break the recursion / cycles
144-
if (hasProcessedEntity(persistentEntityFromProperty, processedEntities)) {
145-
return;
146-
}
147-
148-
filteredProperties.put(propertyPath, true);
149-
150-
}
151-
152-
private static boolean hasProcessedEntity(Neo4jPersistentEntity<?> persistentEntityFromProperty,
153-
Collection<Neo4jPersistentEntity<?>> processedEntities) {
154-
155-
return processedEntities.contains(persistentEntityFromProperty);
156-
}
157119
}

0 commit comments

Comments
 (0)