All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.stratio.cassandra.lucene.search.condition.builder.GeoShapeConditionBuilder Maven / Gradle / Ivy

There is a newer version: 3.9.1
Show newest version
/**
 * Copyright (C) 2014 Stratio (http://stratio.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.stratio.cassandra.lucene.search.condition.builder;

import com.stratio.cassandra.lucene.common.GeoOperation;
import com.stratio.cassandra.lucene.common.GeoTransformation;
import com.stratio.cassandra.lucene.common.JTSNotFoundException;
import com.stratio.cassandra.lucene.search.condition.GeoBBoxCondition;
import com.stratio.cassandra.lucene.search.condition.GeoShapeCondition;
import org.apache.commons.lang3.StringUtils;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonProperty;

import java.util.ArrayList;
import java.util.List;

/**
 * {@link ConditionBuilder} for building a new {@link GeoShapeCondition}.
 *
 * @author Andres de la Pena {@literal }
 */
public class GeoShapeConditionBuilder extends ConditionBuilder {

    /** The name of the field to be matched. */
    @JsonProperty("field")
    private final String field;

    /** The shape in  WKT format. */
    @JsonProperty("shape")
    private final String shape;

    /** The spatial operation to be applied. */
    @JsonProperty("operation")
    private String operation;

    /** The sequence of transformations to be applied to the shape before searching. */
    @JsonProperty("transformations")
    private List transformations = new ArrayList<>();

    /**
     * Constructor receiving the name of the field and the shape.
     *
     * @param field the name of the field
     * @param shape the shape in  WKT format
     */
    @JsonCreator
    public GeoShapeConditionBuilder(@JsonProperty("field") String field, @JsonProperty("shape") String shape) {
        this.field = field;
        this.shape = shape;
    }

    /**
     * Sets the name of the spatial operation to be performed.
     *
     * @param operation the name of the spatial operation
     * @return this with the operation set
     */
    public GeoShapeConditionBuilder operation(String operation) {
        this.operation = operation;
        return this;
    }

    /**
     * Sets the transformations to be applied to the shape before using it for searching.
     *
     * @param transformations the sequence of transformations
     * @return this with the transformations set
     */
    public GeoShapeConditionBuilder transformations(List transformations) {
        this.transformations = transformations;
        return this;
    }

    /**
     * Returns the {@link GeoBBoxCondition} represented by this builder.
     *
     * @return a new geo shape condition
     */
    @Override
    public GeoShapeCondition build() {
        GeoOperation geoOperation = StringUtils.isBlank(operation) ? null : GeoOperation.parse(operation);
        if (transformations == null) {
            transformations = new ArrayList<>();
        }
        try {
            return new GeoShapeCondition(boost, field, shape, geoOperation, transformations);
        } catch (NoClassDefFoundError e) {
            throw new JTSNotFoundException();

        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy