/** * internal factory method for fields where the filter and the sortOptions field expression is the same. * * @throws IllegalArgumentException if the property can not be mapped. Because of this, call this method last in the * workflow. */ private FieldExpression common(final String propertyName) throws IllegalArgumentException { if (FieldExpressionUtil.isAttributeFieldName(propertyName)) { return new AttributeExpressionImpl(FieldExpressionUtil.stripAttributesPrefix(propertyName)); } final String fieldName = simpleFieldMappings.get(propertyName); if (fieldName != null) { return new SimpleFieldExpressionImpl(fieldName); } throw new IllegalArgumentException("Unknown property name: " + propertyName); }
@Override public SortFieldExpression sortBy(final String propertyName) throws IllegalArgumentException { return FieldExpressionUtil.parseFeatureField(requireNonNull(propertyName)) .flatMap(f -> f.getFeatureId() .flatMap(id -> f.getProperty() .flatMap(property -> Optional .of((SortFieldExpression) new FeatureIdPropertyExpressionImpl(id, property)) ) ) ) .orElseGet(() -> (SortFieldExpression) common(propertyName)); }
@Override public Bson visitAttribute(final String key) { return Filters.regex(PersistenceConstants.FIELD_GRANTS_RESOURCE, FieldExpressionUtil.wrapExistsRegex( PersistenceConstants.FIELD_ATTRIBUTE_PREFIX_WITH_ENDING_SLASH + key)); }
@Override public Bson visitFeatureProperty(final String property) { return Filters.regex(PersistenceConstants.FIELD_GRANTS_RESOURCE, FieldExpressionUtil.wrapExistsRegex( PersistenceConstants.FIELD_FEATURE_PROPERTIES_PREFIX_WITH_ENDING_SLASH + property)); } }
@Override public FilterFieldExpression filterBy(final String propertyName) throws IllegalArgumentException { final Supplier<FilterFieldExpression> defaultSupplier = () -> (FilterFieldExpression) common(propertyName); return FieldExpressionUtil.parseFeatureField(requireNonNull(propertyName)) .map(f -> f.getProperty() .map(property -> f.getFeatureId() // we have a feature id and a property path .map(id -> (FilterFieldExpression) new FeatureIdPropertyExpressionImpl(id, property)) // we have a property path .orElseGet(() -> new FeaturePropertyExpressionImpl(property)) ) // we have a feature field but no property path, this is invalid for filter operations .orElseGet(defaultSupplier) ) // we have no feature at all, continue with the other possibilities .orElseGet(defaultSupplier); }
@Override public Bson visitFeatureProperty(final String property) { return Filters.regex(PersistenceConstants.FIELD_PATH_KEY, FieldExpressionUtil.wrapExistsRegex( PersistenceConstants.FIELD_FEATURE_PROPERTIES_PREFIX_WITH_ENDING_SLASH + property)); }
@Override public ExistsFieldExpression existsBy(final String propertyName) throws IllegalArgumentException { return FieldExpressionUtil.parseFeatureField(requireNonNull(propertyName)) .map(f -> f.getFeatureId() .map(id -> f.getProperty() // we have a feature id and a property path .map(property -> (ExistsFieldExpression) new FeatureIdPropertyExpressionImpl(id, property)) // we have a feature id but no property path .orElseGet(() -> new FeatureExpressionImpl(id)) ) // we have a feature field but no feature id, means it must be a property path .orElseGet(() -> (ExistsFieldExpression) f.getProperty() .map((String property) -> (ExistsFieldExpression) new FeaturePropertyExpressionImpl( property)) // at this point, we know that there must be a property, so the following throw should // never happen and is only there to make the compiler happy: .orElseThrow(() -> new IllegalStateException("Illegal state while parsing feature property path.")) ) ) // we have no feature at all, continue with the other possibilities .orElseGet(() -> (ExistsFieldExpression) common(propertyName)); }
@Override public Bson visitFeatureIdProperty(final String featureId, final String property) { return Filters.regex(PersistenceConstants.FIELD_GRANTS_RESOURCE, FieldExpressionUtil.wrapExistsRegex( PersistenceConstants.FIELD_FEATURE_PROPERTIES_PREFIX_WITH_ENDING_SLASH + property)); }
@Override public Bson visitAttribute(final String key) { return Filters.regex(PersistenceConstants.FIELD_PATH_KEY, FieldExpressionUtil.wrapExistsRegex( PersistenceConstants.FIELD_ATTRIBUTE_PREFIX_WITH_ENDING_SLASH + key)); }
@Override public Bson visitAttribute(final String key) { return Filters.regex(PersistenceConstants.FIELD_PATH_KEY, FieldExpressionUtil.wrapExistsRegex( PersistenceConstants.FIELD_ATTRIBUTE_PREFIX_WITH_ENDING_SLASH + key)); }
@Override public Bson visitFeatureProperty(final String property) { return Filters.regex(PersistenceConstants.FIELD_PATH_KEY, FieldExpressionUtil.wrapExistsRegex( PersistenceConstants.FIELD_FEATURE_PROPERTIES_PREFIX_WITH_ENDING_SLASH + property)); }
@Override public Bson visitAttribute(final String key) { return Filters.regex(PersistenceConstants.FIELD_GRANTS_RESOURCE, FieldExpressionUtil.wrapExistsRegex( PersistenceConstants.FIELD_ATTRIBUTE_PREFIX_WITH_ENDING_SLASH + key)); }
@Override public Bson visitFeatureProperty(final String property) { return Filters.regex(PersistenceConstants.FIELD_GRANTS_RESOURCE, FieldExpressionUtil.wrapExistsRegex( PersistenceConstants.FIELD_FEATURE_PROPERTIES_PREFIX_WITH_ENDING_SLASH + property)); } }
@Override public Bson visitFeatureIdProperty(final String featureId, final String property) { return Filters.regex(PersistenceConstants.FIELD_GRANTS_RESOURCE, FieldExpressionUtil.wrapExistsRegex( PersistenceConstants.FIELD_FEATURE_PROPERTIES_PREFIX_WITH_ENDING_SLASH + property)); }
@Override public Bson visitFeatureIdProperty(final String featureId, final String property) { return Filters.and(Filters.regex(PersistenceConstants.FIELD_PATH_KEY, FieldExpressionUtil.wrapExistsRegex( PersistenceConstants.FIELD_FEATURE_PROPERTIES_PREFIX_WITH_ENDING_SLASH + property)), Filters.eq(PersistenceConstants.FIELD_FEATURE_PATH_KEY, featureId)); }
@Override public Bson visitFeatureIdProperty(final String featureId, final String property) { return Filters.and(Filters.regex(PersistenceConstants.FIELD_PATH_KEY, FieldExpressionUtil.wrapExistsRegex( PersistenceConstants.FIELD_FEATURE_PROPERTIES_PREFIX_WITH_ENDING_SLASH + property)), Filters.eq(PersistenceConstants.FIELD_FEATURE_PATH_KEY, featureId)); }
@Override public Optional<Bson> visitFeatureProperty(final String property) { return Optional.of(withOrWithoutPredicate( predicate -> Filters.and( Filters.eq(FIELD_PATH_KEY, FIELD_FEATURE_PROPERTIES_PREFIX_WITH_ENDING_SLASH + property), CreateBsonPredicateVisitor.apply(predicate, FIELD_PATH_VALUE)), () -> Filters.regex(FIELD_PATH_KEY, FieldExpressionUtil.wrapExistsRegex( FIELD_FEATURE_PROPERTIES_PREFIX_WITH_ENDING_SLASH + property)) )); }
@Override public Optional<Bson> visitFeatureProperty(final String property) { return Optional.of(withOrWithoutPredicate( predicate -> Filters.and( Filters.eq(FIELD_PATH_KEY, FIELD_FEATURE_PROPERTIES_PREFIX_WITH_ENDING_SLASH + property), CreateBsonPredicateVisitor.apply(predicate, FIELD_PATH_VALUE)), () -> Filters.regex(FIELD_PATH_KEY, FieldExpressionUtil.wrapExistsRegex( FIELD_FEATURE_PROPERTIES_PREFIX_WITH_ENDING_SLASH + property)) )); }
@Override public Optional<Bson> visitAttribute(final String key) { return Optional.of(withOrWithoutPredicate( predicate -> { final String attributeKeyWithPrefix = FIELD_ATTRIBUTE_PREFIX_WITH_ENDING_SLASH + key; final Bson keyRestrictionBson = Filters.eq(FIELD_PATH_KEY, attributeKeyWithPrefix); return Filters.and(keyRestrictionBson, CreateBsonPredicateVisitor.apply(predicate, FIELD_PATH_VALUE)); }, () -> Filters.regex(FIELD_PATH_KEY, FieldExpressionUtil.wrapExistsRegex(FIELD_ATTRIBUTE_PREFIX_WITH_ENDING_SLASH + key)) )); }
@Override public Optional<Bson> visitAttribute(final String key) { return Optional.of(withOrWithoutPredicate( predicate -> { final String attributeKeyWithPrefix = FIELD_ATTRIBUTE_PREFIX_WITH_ENDING_SLASH + key; final Bson keyRestrictionBson = Filters.eq(FIELD_PATH_KEY, attributeKeyWithPrefix); return Filters.and(keyRestrictionBson, CreateBsonPredicateVisitor.apply(predicate, FIELD_PATH_VALUE)); }, () -> Filters.regex(FIELD_PATH_KEY, FieldExpressionUtil.wrapExistsRegex(FIELD_ATTRIBUTE_PREFIX_WITH_ENDING_SLASH + key)) )); }