public ModelBasedThingsFieldExpressionFactory() { this.delegate = new ThingsFieldExpressionFactoryImpl(filteringSimpleFieldMappings); }
@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 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); }
private ActorRef initializeSearchActor(final ServiceConfigReader configReader, final MongoClientWrapper mongoClientWrapper) { final Config rawConfig = configReader.getRawConfig(); final ThingsSearchPersistence thingsSearchPersistence = new MongoThingsSearchPersistence(mongoClientWrapper, getContext().system()); final boolean indexInitializationEnabled = rawConfig.getBoolean(ConfigKeys.INDEX_INITIALIZATION_ENABLED); if (indexInitializationEnabled) { thingsSearchPersistence.initializeIndices(); } else { log.info("Skipping IndexInitializer because it is disabled."); } final CriteriaFactory criteriaFactory = new CriteriaFactoryImpl(); final ThingsFieldExpressionFactory fieldExpressionFactory = new ThingsFieldExpressionFactoryImpl(); final AggregationBuilderFactory aggregationBuilderFactory = new MongoAggregationBuilderFactory(configReader.limits()); final QueryBuilderFactory queryBuilderFactory = new MongoQueryBuilderFactory(configReader.limits()); final ActorRef aggregationQueryActor = startChildActor(AggregationQueryActor.ACTOR_NAME, AggregationQueryActor.props(criteriaFactory, fieldExpressionFactory, aggregationBuilderFactory)); final ActorRef apiV1QueryActor = startChildActor(QueryActor.ACTOR_NAME, QueryActor.props(criteriaFactory, fieldExpressionFactory, queryBuilderFactory)); return startChildActor(SearchActor.ACTOR_NAME, SearchActor.props(aggregationQueryActor, apiV1QueryActor, thingsSearchPersistence)); }
@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)); }