|
19 | 19 | import java.util.Map.Entry;
|
20 | 20 | import java.util.regex.Matcher;
|
21 | 21 | import java.util.regex.Pattern;
|
| 22 | +import java.util.stream.Collectors; |
22 | 23 |
|
23 | 24 | import org.bson.BsonValue;
|
24 | 25 | import org.bson.Document;
|
25 | 26 | import org.bson.conversions.Bson;
|
26 | 27 | import org.bson.types.ObjectId;
|
| 28 | +import org.slf4j.Logger; |
| 29 | +import org.slf4j.LoggerFactory; |
27 | 30 | import org.springframework.core.convert.ConversionService;
|
28 | 31 | import org.springframework.core.convert.converter.Converter;
|
29 | 32 | import org.springframework.data.domain.Example;
|
|
66 | 69 | */
|
67 | 70 | public class QueryMapper {
|
68 | 71 |
|
| 72 | + protected static final Logger LOGGER = LoggerFactory.getLogger(QueryMapper.class); |
| 73 | + |
69 | 74 | private static final List<String> DEFAULT_ID_NAMES = Arrays.asList("id", "_id");
|
70 | 75 | private static final Document META_TEXT_SCORE = new Document("$meta", "textScore");
|
71 | 76 | static final ClassTypeInformation<?> NESTED_DOCUMENT = ClassTypeInformation.from(NestedDocument.class);
|
@@ -1099,29 +1104,46 @@ private PersistentPropertyPath<MongoPersistentProperty> getPath(String pathExpre
|
1099 | 1104 | return null;
|
1100 | 1105 | }
|
1101 | 1106 |
|
1102 |
| - try { |
| 1107 | + PersistentPropertyPath<MongoPersistentProperty> propertyPath = tryToResolvePersistentPropertyPath(path); |
1103 | 1108 |
|
1104 |
| - PersistentPropertyPath<MongoPersistentProperty> propertyPath = mappingContext.getPersistentPropertyPath(path); |
| 1109 | + if (propertyPath == null) { |
1105 | 1110 |
|
1106 |
| - Iterator<MongoPersistentProperty> iterator = propertyPath.iterator(); |
1107 |
| - boolean associationDetected = false; |
| 1111 | + if (QueryMapper.LOGGER.isInfoEnabled()) { |
| 1112 | + |
| 1113 | + String types = StringUtils.collectionToDelimitedString( |
| 1114 | + path.stream().map(it -> it.getType().getSimpleName()).collect(Collectors.toList()), " -> "); |
| 1115 | + QueryMapper.LOGGER.info( |
| 1116 | + "Could not map '{}'. Maybe a fragment in '{}' is considered a simple type. Mapper continues with {}.", |
| 1117 | + path, types, pathExpression); |
| 1118 | + } |
| 1119 | + return null; |
| 1120 | + } |
1108 | 1121 |
|
1109 |
| - while (iterator.hasNext()) { |
| 1122 | + Iterator<MongoPersistentProperty> iterator = propertyPath.iterator(); |
| 1123 | + boolean associationDetected = false; |
1110 | 1124 |
|
1111 |
| - MongoPersistentProperty property = iterator.next(); |
| 1125 | + while (iterator.hasNext()) { |
1112 | 1126 |
|
1113 |
| - if (property.isAssociation()) { |
1114 |
| - associationDetected = true; |
1115 |
| - continue; |
1116 |
| - } |
| 1127 | + MongoPersistentProperty property = iterator.next(); |
1117 | 1128 |
|
1118 |
| - if (associationDetected && !property.isIdProperty()) { |
1119 |
| - throw new MappingException(String.format(INVALID_ASSOCIATION_REFERENCE, pathExpression)); |
1120 |
| - } |
| 1129 | + if (property.isAssociation()) { |
| 1130 | + associationDetected = true; |
| 1131 | + continue; |
1121 | 1132 | }
|
1122 | 1133 |
|
1123 |
| - return propertyPath; |
1124 |
| - } catch (InvalidPersistentPropertyPath e) { |
| 1134 | + if (associationDetected && !property.isIdProperty()) { |
| 1135 | + throw new MappingException(String.format(INVALID_ASSOCIATION_REFERENCE, pathExpression)); |
| 1136 | + } |
| 1137 | + } |
| 1138 | + |
| 1139 | + return propertyPath; |
| 1140 | + } |
| 1141 | + |
| 1142 | + private PersistentPropertyPath<MongoPersistentProperty> tryToResolvePersistentPropertyPath(PropertyPath path) { |
| 1143 | + |
| 1144 | + try { |
| 1145 | + return mappingContext.getPersistentPropertyPath(path); |
| 1146 | + } catch (MappingException e) { |
1125 | 1147 | return null;
|
1126 | 1148 | }
|
1127 | 1149 | }
|
|
0 commit comments