/** * Gets the path full name, including any parent path, separated by a dot <code>.</code> character. * @return Path full name */ default String fullName() { return fullName(p -> p.getName()); }
/** * 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()); }
@SuppressWarnings({ "unchecked", "rawtypes" }) private static Optional<Path<?>> getPathByName(PropertySet set, String propertyName) { if (set != null && propertyName != null) { return set.stream().filter(p -> Path.class.isAssignableFrom(p.getClass())) .filter(p -> propertyName.equals(((Path) p).getName())).findFirst(); } return Optional.empty(); }
private static Path<?> getPathByName(String propertyName, Iterable<?> properties) { if (propertyName != null && properties != null) { for (Object property : properties) { if (String.class.isAssignableFrom(property.getClass()) && propertyName.equals(property)) { return Path.of(propertyName, Object.class); } if (property instanceof Path && propertyName.equals(((Path<?>) property).getName())) { return (Path<?>) property; } } } return null; }
/** * Get the {@link Property} in given <code>propertySet</code> which corresponds to given <code>name</code>. * @param propertySet Property set * @param name Property name * @return The {@link Property} in given <code>propertySet</code> which corresponds to given <code>name</code>, if * available */ @SuppressWarnings({ "unchecked", "rawtypes" }) private static Optional<Property<?>> getPropertyByName(PropertySet propertySet, String name) { if (propertySet != null && name != null) { return propertySet.stream().filter(p -> p instanceof Path).filter(p -> name.equals(((Path<?>) p).getName())) .findFirst(); } return Optional.empty(); }
/** * Try to obtain a {@link Path} which corresponds to given <code>propertyName</code>, using the provided property * set. * @param propertySet The property set to use * @param propertyName The property name to look for * @return Optional {@link Path} which corresponds to given <code>propertyName</code> */ @SuppressWarnings({ "unchecked", "rawtypes" }) private static Optional<Path<?>> getPathByName(PropertySet propertySet, String propertyName) { if (propertySet != null && propertyName != null) { return propertySet.stream().filter(p -> Path.class.isAssignableFrom(p.getClass())) .filter(p -> propertyName.equals(((Path) p).getName())).findFirst(); } return Optional.empty(); }
/** * Gets the path full name, including any parent path, separated by a dot <code>.</code> character. * @param nameMapper The function to use to obtain the path name (not null) * @return Path full name */ default String fullName(Function<Path<?>, String> nameMapper) { ObjectUtils.argumentNotNull(nameMapper, "Path name mapper function must be not null"); return getParent().map(pr -> stream().map(p -> nameMapper.apply(p)) .collect(LinkedList<String>::new, LinkedList::addFirst, (a, b) -> a.addAll(0, b)).stream() .collect(Collectors.joining("."))).orElse(getName()); }
/** * 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. * @param nameMapper The function to use to obtain the path name (not null) * @return Path relative name, en empty String if this Path is a {@link FinalPath} itself. */ default String relativeName(Function<Path<?>, String> nameMapper) { ObjectUtils.argumentNotNull(nameMapper, "Path name mapper function must be not null"); return getParent() .map(pr -> stream().filter(p -> !FinalPath.class.isAssignableFrom(p.getClass())) .map(p -> nameMapper.apply(p)) .collect(LinkedList<String>::new, LinkedList::addFirst, (a, b) -> a.addAll(0, b)).stream() .collect(Collectors.joining("."))) .orElse(FinalPath.class.isAssignableFrom(this.getClass()) ? "" : getName()); }
public DefaultPropertyColumn(P property) { super(); if (property != null) { if (Localizable.class.isAssignableFrom(property.getClass())) { this.caption = (Localizable) property; } if ((this.caption == null || this.caption.getMessage() == null) && Path.class.isAssignableFrom(property.getClass())) { this.caption = Localizable.builder().message(((Path<?>) property).getName()).build(); } } }
/** * Constructor. * @param property Property * @param virtual Whether the property is virtual */ public DefaultPropertyColumn(P property, boolean virtual) { super(); this.virtual = virtual; if (property != null) { if (Localizable.class.isAssignableFrom(property.getClass())) { this.caption = (Localizable) property; } if ((this.caption == null || this.caption.getMessage() == null) && Path.class.isAssignableFrom(property.getClass())) { this.caption = Localizable.builder().message(((Path<?>) property).getName()).build(); } } }
/** * Create a new {@link BooleanProperty} from given <code>path</code>, using given {@link Path} <code>name</code>. * @param path Path from which to obtain the property path name (not null) * @return {@link BooleanProperty} builder */ static BooleanPropertyBuilder create(Path<Boolean> path) { ObjectUtils.argumentNotNull(path, "Path must be not null"); BooleanPropertyBuilder builder = create(path.getName()); path.getParent().ifPresent(p -> builder.parent(p)); return builder; }
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(); }
/** * Create a new {@link StringProperty} from given <code>path</code>, using given {@link Path} <code>name</code>. * @param path Path from which to obtain the property path name (not null) * @return {@link StringProperty} builder */ static StringPropertyBuilder create(Path<String> path) { ObjectUtils.argumentNotNull(path, "Path must be not null"); StringPropertyBuilder builder = create(path.getName()); path.getParent().ifPresent(p -> builder.parent(p)); return builder; }
/** * Configure given component using given property. * @param property Property to which the component refers * @param component Component to configure */ protected void configureComponent(Property<?> property, Component component) { if (hiddenPropertyCaptions.contains(property)) { component.setCaption(null); } else { if (propertyCaptions.containsKey(property)) { component.setCaption(LocalizationContext.translate(propertyCaptions.get(property), true)); } else { if (component.getCaption() == null) { if (Path.class.isAssignableFrom(property.getClass())) { component.setCaption(((Path<?>) property).getName()); } else { component.setCaption(property.toString()); } } } } }
/** * Create a {@link PathExpression} from given {@link Path}. * @param <T> Path type * @param path Suorce path * @return A new {@link PathExpression} with the same name, type and parent of the given path */ static <T> PathExpression<T> from(Path<T> path) { ObjectUtils.argumentNotNull(path, "Path must be not null"); DefaultPathExpression<T> expression = new DefaultPathExpression<>(path.getName(), path.getType()); path.getParent().ifPresent(p -> expression.parent(p)); return expression; }
/** * Create a new {@link NumericProperty} from given <code>path</code>, using given {@link Path} <code>name</code>and * <code>type</code>. * @param <T> Path type * @param path Path from which to obtain the property path name and type (not null) * @return {@link NumericProperty} builder */ static <T extends Number> NumericPropertyBuilder<T> create(Path<T> path) { ObjectUtils.argumentNotNull(path, "Path must be not null"); NumericPropertyBuilder<T> builder = create(path.getName(), path.getType()); path.getParent().ifPresent(p -> builder.parent(p)); return builder; }
/** * Create a new {@link PathProperty} from given <code>path</code>, using given {@link Path} <code>name</code> and * <code>type</code>. * @param <T> Property (path) type * @param path Path from which to obtain the property path name and type (not null) * @return {@link PathProperty} builder */ static <T> PathPropertyBuilder<T> create(Path<T> path) { ObjectUtils.argumentNotNull(path, "Path must be not null"); PathPropertyBuilder<T> builder = create(path.getName(), path.getType()); path.getParent().ifPresent(p -> builder.parent(p)); return builder; }
/** * Create a new {@link TemporalProperty} from given <code>path</code>, using given {@link Path} <code>name</code>and * <code>type</code>. * @param <T> Path type * @param path Path from which to obtain the property path name and type (not null) * @return {@link TemporalProperty} builder */ static <T> TemporalPropertyBuilder<T> create(Path<T> path) { ObjectUtils.argumentNotNull(path, "Path must be not null"); TemporalPropertyBuilder<T> builder = create(path.getName(), path.getType()); path.getParent().ifPresent(p -> builder.parent(p)); return builder; }
public void path() { // tag::path[] Path<String> stringPath = Path.of("pathName", String.class); // <1> String name = stringPath.getName(); // <2> boolean root = stringPath.isRootPath(); // <3> Path<String> hierarchicalPath = Path.of("subName", String.class).parent(stringPath); // <4> String fullName = hierarchicalPath.fullName(); // <5> // end::path[] }
@Override public Optional<QueryDslExpression> resolve(Path expression, QueryDslResolutionContext context) throws InvalidExpressionException { // validate expression.validate(); // intermediate resolution and validation Path path = context.resolve(expression, Path.class).orElse(expression); path.validate(); // get root com.querydsl.core.types.Path<?> root = getParentRootPath(path, context).orElse(getQueryRootPath(path, context)); // get query path from property final String queryPath = path.getName(); PathBuilder<?> rootPathBuilder = new PathBuilder<>(root.getType(), root.getMetadata()); @SuppressWarnings("unchecked") PathBuilder<?> pb = rootPathBuilder.get(queryPath, path.getType()); if (pb == null) { throw new InvalidExpressionException("Cannot get a valid PathBuilder for path expression [" + path + "]"); } return Optional.of(QueryDslExpression.create(pb)); }