@Override public boolean match(Path<?> path, Path<?> otherPath) { if (path != null && otherPath != null) { return path.relativeName().equals(otherPath.relativeName()); } return false; }
@Override public boolean match(Path<?> path, Path<?> otherPath) { if (path != null && otherPath != null) { return path.relativeName().equals(otherPath.relativeName()); } return false; }
@Override public boolean match(Path<?> path, Path<?> otherPath) { if (path != null && otherPath != null) { return path.relativeName().equalsIgnoreCase(otherPath.relativeName()); } return false; }
@Override protected Optional<String> getSortPropertyName(Property<?> property) { if (property != null && Path.class.isAssignableFrom(property.getClass())) { return Optional.ofNullable(((Path<?>) property).relativeName()); } return Optional.empty(); }
/** * Get the path names hierarchy from given path, ujsing any parent path and splitting the path name if a dot * notation is detected. * @param path Path * @return the path names hierarchy */ private static List<String> getPathNameHierarchy(Path<?> path) { final String pathName = path.relativeName(); if (pathName == null) { return Collections.emptyList(); } if (pathName.indexOf('.') < 1) { return Collections.singletonList(pathName); } return Arrays.asList(pathName.split("\\.")); }
/** * Get the path data model name, using {@link DataMappable#getDataPath()} if available or returning the path name if * not. * @param path The path for which to obtain the data path name * @return The data path name */ private static String getPathName(Path<?> path) { return path.getDataPath().orElse(path.relativeName()); }
/** * Gets the <em>relative</em> path name, separated by a dot <code>.</code> character, i.e. exclude any * {@link FinalPath} path instance from path name composition. * @return Path relative name, en empty String if this Path is a {@link FinalPath} itself. */ default String relativeName() { return relativeName(p -> p.getName()); }
/** * Get the path names hierarchy from given path, ujsing any parent path and splitting the path name if a dot * notation is detected. * @param path Path * @return the path names hierarchy */ private static List<String> getPathNameHierarchy(Path<?> path) { final String pathName = path.relativeName(); if (pathName == null) { return Collections.emptyList(); } if (pathName.indexOf('.') < 1) { return Collections.singletonList(pathName); } return Arrays.asList(pathName.split("\\.")); }
@SuppressWarnings("unchecked") @Override public <T> Optional<T> getInsertedKey(Path<T> path) { ObjectUtils.argumentNotNull(path, "Path must be not null"); final String pathName = path.relativeName(); if (pathName != null) { for (Entry<Path<?>, Object> entry : getInsertedKeys().entrySet()) { if (pathName.equalsIgnoreCase(entry.getKey().relativeName())) { return Optional.ofNullable((T) entry.getValue()); } } } return Optional.empty(); }
/** * Check if given expression represents the default document id attribute. * @param expression The expression to check * @return Whether the given expression represents the default document id attribute */ public static boolean isDocumentIdPropertyPath(TypedExpression<?> expression) { if (Path.class.isAssignableFrom(expression.getClass())) { return MongoDocumentContext.ID_FIELD_NAME.equals(((Path<?>) expression).relativeName()); } if (Property.class.isAssignableFrom(expression.getClass())) { return MongoDocumentContext.ID_FIELD_NAME.equals(((Property<?>) expression).getName()); } return false; }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Sort on path ["); sb.append(getPath() != null ? getPath().relativeName() : "<NULL>"); sb.append("] with direction ["); if (getDirection() == null) { sb.append(SortDirection.ASCENDING.name()); } else { sb.append(getDirection().name()); } sb.append("]"); return sb.toString(); }
/** * Get the property with given <code>propertyPath</code> from bean property set using the properties full name as * matching rule. * @param propertyPath Property path * @param ignoreMissing <code>true</code> to ignore mismatches * @return Optional matching bean property * @throws PropertyNotFoundException If ignoreMissing is false and a matching bean property was not found */ private Optional<BeanProperty<?>> getProperty(Path<?> propertyPath, boolean ignoreMissing) throws PropertyNotFoundException { ObjectUtils.argumentNotNull(propertyPath, "Property path must be not null"); Optional<PathProperty<?>> beanProperty = stream() .filter(p -> propertyPath.relativeName().equals(p.relativeName())).findFirst(); if (!ignoreMissing && !beanProperty.isPresent()) { throw new PropertyNotFoundException((propertyPath instanceof Property) ? (Property<?>) propertyPath : null, "Property with name [" + propertyPath.relativeName() + "] was not found in bean [" + getBeanClass() + "] property set"); } return beanProperty.map(p -> (BeanProperty<?>) p); }
PropertySet<S> propertySet, Stream<S> properties) throws InvalidDocumentIdentifierException { List<P> documentIdProperties = properties.filter(p -> Path.class.isAssignableFrom(p.getClass())).map(p -> (P) p) .filter(p -> DOCUMENT_ID_PATH_NAME.equals(p.relativeName())).collect(Collectors.toList()); if (!documentIdProperties.isEmpty()) { if (documentIdProperties.size() > 1) {
private static Optional<Path> getPathUsingDocumentContext(MongoResolutionContext context, String fieldName) { PathPropertySetAdapter adapter = MongoDocumentContext.isDocumentContext(context) .map(dc -> PathPropertySetAdapter.create(dc.getPropertySet())).orElse(null); if (adapter != null) { Optional<Path> path = adapter.getProperty(fieldName).flatMap(p -> adapter.getPath(p)).map(p -> (Path) p); if (path.isPresent()) { return path; } // check data path return adapter.propertyPaths() .filter(pp -> fieldName.equals(pp.getPath().relativeName(p -> p.getDataPath().orElse(p.getName())))) .map(pp -> (Path) pp.getPath()).findFirst(); } return Optional.empty(); }
@Override public <V> V read(Path<V> path, T instance) { ObjectUtils.argumentNotNull(path, "Path must be not null"); ObjectUtils.argumentNotNull(instance, "Bean instance must be not null"); final BeanProperty<?> property = (BeanProperty<?>) property(path.relativeName()); return read(property, instance, path.getType()); }
@Override public <P> void write(Path<P> path, P value, T instance) { ObjectUtils.argumentNotNull(path, "Path must be not null"); ObjectUtils.argumentNotNull(instance, "Bean instance must be not null"); final BeanProperty<?> property = (BeanProperty<?>) property(path.relativeName()); write(property, path.getType(), value, instance); }
beanPropertySet.getProperty(path.relativeName()).ifPresent(p -> { Object resolvedValue = context.resolveOrFail(FieldValue.create(value, p), Value.class).getValue(); beanPropertySet.write(path, resolvedValue, instance);
&& !MongoDocumentContext.ID_FIELD_NAME.equals(property.relativeName())) {