Search in sources :

Example 1 with FieldType

use of io.arlas.server.core.model.response.FieldType in project ARLAS-server by gisaia.

the class HazelcastCacheManager method getFieldType.

@Override
public FieldType getFieldType(String ref, String name) {
    FieldType t;
    try {
        t = (FieldType) this.instance.getReplicatedMap(ref).get(name);
    } catch (HazelcastInstanceNotActiveException e) {
        // recover from unexpected shutdown
        init();
        t = (FieldType) this.instance.getReplicatedMap(ref).get(name);
    }
    LOGGER.debug("Returning field type '" + name + "' for collection '" + ref + "' from cache with value " + (t == null ? "null" : t.fieldType));
    return t;
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) FieldType(io.arlas.server.core.model.response.FieldType)

Example 2 with FieldType

use of io.arlas.server.core.model.response.FieldType in project ARLAS-server by gisaia.

the class CollectionReferenceManager method getType.

public FieldType getType(CollectionReference collectionReference, String field, boolean throwException) throws ArlasException {
    FieldType fieldType = cacheManager.getFieldType(collectionReference.collectionName, field);
    if (fieldType == null) {
        String[] props = field.split("\\.");
        CollectionReferenceDescriptionProperty esField = collectionReferenceService.describeCollection(collectionReference).properties.get(props[0]);
        if (esField == null) {
            return getUnknownType(field, collectionReference.collectionName, throwException);
        }
        for (int i = 1; i < props.length; i++) {
            esField = esField.properties.get(props[i]);
            if (esField == null) {
                return getUnknownType(field, collectionReference.collectionName, throwException);
            }
        }
        if (esField != null) {
            fieldType = esField.type;
            cacheManager.putFieldType(collectionReference.collectionName, field, fieldType);
        } else {
            return getUnknownType(field, collectionReference.collectionName, throwException);
        }
    }
    return fieldType;
}
Also used : FieldType(io.arlas.server.core.model.response.FieldType) CollectionReferenceDescriptionProperty(io.arlas.server.core.model.response.CollectionReferenceDescriptionProperty)

Example 3 with FieldType

use of io.arlas.server.core.model.response.FieldType in project ARLAS-server by gisaia.

the class ElasticFluidSearch method filter.

private BoolQueryBuilder filter(Expression expression, String dateFormat) throws ArlasException {
    BoolQueryBuilder ret = QueryBuilders.boolQuery();
    if (Strings.isNullOrEmpty(expression.field) || expression.op == null || Strings.isNullOrEmpty(expression.value)) {
        throw new InvalidParameterException(INVALID_PARAMETER_F);
    }
    String field = expression.field;
    OperatorEnum op = expression.op;
    String value = expression.value;
    String[] fieldValues = value.split(",");
    switch(op) {
        case eq:
            if (fieldValues.length > 1) {
                BoolQueryBuilder orBoolQueryBuilder = QueryBuilders.boolQuery();
                for (String valueInValues : fieldValues) {
                    orBoolQueryBuilder = orBoolQueryBuilder.should(QueryBuilders.matchQuery(field, valueInValues));
                }
                ret = ret.filter(orBoolQueryBuilder);
            } else {
                ret = ret.filter(QueryBuilders.matchQuery(field, value));
            }
            break;
        case gte:
            if (isDateField(field) && !StringUtil.isNullOrEmpty(dateFormat)) {
                value = ParamsParser.parseDate(value, dateFormat);
            }
            RangeQueryBuilder gteRangeQuery = QueryBuilders.rangeQuery(field).gte(value);
            applyFormatOnRangeQuery(field, value, gteRangeQuery);
            ret = ret.filter(gteRangeQuery);
            break;
        case gt:
            if (isDateField(field) && !StringUtil.isNullOrEmpty(dateFormat)) {
                value = ParamsParser.parseDate(value, dateFormat);
            }
            RangeQueryBuilder gtRangeQuery = QueryBuilders.rangeQuery(field).gt(value);
            applyFormatOnRangeQuery(field, value, gtRangeQuery);
            ret = ret.filter(gtRangeQuery);
            break;
        case lte:
            if (isDateField(field) && !StringUtil.isNullOrEmpty(dateFormat)) {
                value = ParamsParser.parseDate(value, dateFormat);
            }
            RangeQueryBuilder lteRangeQuery = QueryBuilders.rangeQuery(field).lte(value);
            applyFormatOnRangeQuery(field, value, lteRangeQuery);
            ret = ret.filter(lteRangeQuery);
            break;
        case lt:
            if (isDateField(field) && !StringUtil.isNullOrEmpty(dateFormat)) {
                value = ParamsParser.parseDate(value, dateFormat);
            }
            RangeQueryBuilder ltRangeQuery = QueryBuilders.rangeQuery(field).lt(value);
            applyFormatOnRangeQuery(field, value, ltRangeQuery);
            ret = ret.filter(ltRangeQuery);
            break;
        case like:
            // TODO: if field type is fullText, use matchPhraseQuery instead of regexQuery
            ret = ret.filter(QueryBuilders.regexpQuery(field, ".*" + value + ".*"));
            break;
        case ne:
            for (String valueInValues : fieldValues) {
                ret = ret.mustNot(QueryBuilders.matchQuery(field, valueInValues));
            }
            break;
        case range:
            field = ParamsParser.getFieldFromFieldAliases(field, collectionReference);
            if (fieldValues.length > 1) {
                BoolQueryBuilder orBoolQueryBuilder = QueryBuilders.boolQuery();
                for (String valueInValues : fieldValues) {
                    CheckParams.checkRangeValidity(valueInValues);
                    orBoolQueryBuilder = orBoolQueryBuilder.should(getRangeQueryBuilder(field, valueInValues, dateFormat));
                }
                ret = ret.filter(orBoolQueryBuilder);
            } else {
                CheckParams.checkRangeValidity(value);
                ret = ret.filter(getRangeQueryBuilder(field, value, dateFormat));
            }
            break;
        case within:
            FieldType wType = collectionReferenceManager.getType(collectionReference, field, true);
            BoolQueryBuilder orBoolQueryBuilder = QueryBuilders.boolQuery();
            switch(wType) {
                case GEO_POINT:
                    for (AbstractQueryBuilder q : filterPWithin(field, value)) {
                        orBoolQueryBuilder = orBoolQueryBuilder.should(q);
                    }
                    break;
                case GEO_SHAPE:
                    orBoolQueryBuilder = orBoolQueryBuilder.should(filterGWithin(field, value));
                    break;
                default:
                    throw new ArlasException("'within' op on field '" + field + "' of type '" + wType + "' is not supported");
            }
            orBoolQueryBuilder.minimumShouldMatch(1);
            ret = ret.filter(orBoolQueryBuilder);
            break;
        case notwithin:
            FieldType type = collectionReferenceManager.getType(collectionReference, field, true);
            BoolQueryBuilder orBoolQueryBuilder2 = QueryBuilders.boolQuery();
            switch(type) {
                case GEO_POINT:
                    for (AbstractQueryBuilder q : filterNotPWithin(field, value)) {
                        orBoolQueryBuilder2 = orBoolQueryBuilder2.should(q);
                    }
                    break;
                case GEO_SHAPE:
                    orBoolQueryBuilder2 = orBoolQueryBuilder2.should(filterGWithin(field, value));
                    break;
                default:
                    throw new ArlasException("'notwithin' op on field '" + field + "' of type '" + type + "' is not supported");
            }
            ret = ret.mustNot(orBoolQueryBuilder2);
            break;
        case intersects:
            ret = ret.filter(filterGIntersect(field, value));
            break;
        case notintersects:
            ret = ret.mustNot(filterGIntersect(field, value));
            break;
        default:
            throw new InvalidParameterException(INVALID_OPERATOR);
    }
    return ret;
}
Also used : FieldType(io.arlas.server.core.model.response.FieldType)

Example 4 with FieldType

use of io.arlas.server.core.model.response.FieldType in project ARLAS-server by gisaia.

the class JdbiFluidSearch method filter.

private String filter(Expression e, String dateFormat) throws ArlasException {
    if (isNullOrEmpty(e.field) || e.op == null || isNullOrEmpty(e.value)) {
        throw new InvalidParameterException(INVALID_PARAMETER_F);
    }
    String field = e.field;
    String value = e.value;
    String[] fieldValues = value.split(COMMA);
    switch(e.op) {
        case eq:
            return req.formatInCondition(e.field, fieldValues);
        case gte:
            if (isDateField(field) && !isNullOrEmpty(dateFormat)) {
                value = ParamsParser.parseDate(e.value, dateFormat, false);
            }
            return req.formatGTECondition(e.field, value);
        case gt:
            if (isDateField(field) && !isNullOrEmpty(dateFormat)) {
                value = ParamsParser.parseDate(e.value, dateFormat, false);
            }
            return req.formatGTCondition(e.field, value);
        case lte:
            if (isDateField(field) && !isNullOrEmpty(dateFormat)) {
                value = ParamsParser.parseDate(e.value, dateFormat, false);
            }
            return req.formatLTECondition(e.field, value);
        case lt:
            if (isDateField(field) && !isNullOrEmpty(dateFormat)) {
                value = ParamsParser.parseDate(e.value, dateFormat, false);
            }
            return req.formatLTCondition(e.field, value);
        case like:
            return req.formatLikeCondition(e.field, value);
        case ne:
            return req.formatNotInCondition(e.field, fieldValues);
        case range:
            field = ParamsParser.getFieldFromFieldAliases(field, collectionReference);
            if (fieldValues.length > 1) {
                List<String> orCond = new ArrayList<>();
                for (String valueInValues : fieldValues) {
                    CheckParams.checkRangeValidity(valueInValues);
                    orCond.add(getRangeCondition(field, valueInValues, dateFormat));
                }
                return req.formatOrClauses(orCond);
            } else {
                CheckParams.checkRangeValidity(value);
                return getRangeCondition(field, value, dateFormat);
            }
        case notintersects:
        case notwithin:
        case intersects:
        case within:
            FieldType wType = collectionReferenceManager.getType(collectionReference, field, true);
            switch(wType) {
                case POINT:
                case LINESTRING:
                case POLYGON:
                case MULTIPOINT:
                case MULTILINESTRING:
                case MULTIPOLYGON:
                case GEOMETRYCOLLECTION:
                case GEO_SHAPE:
                case GEO_POINT:
                    Geometry geo;
                    if (CheckParams.isBboxMatch(value)) {
                        double[] tlbr = CheckParams.toDoubles(value);
                        geo = GeoTileUtil.toPolygon(new BoundingBox(tlbr[3], tlbr[1], tlbr[0], tlbr[2]));
                    } else {
                        geo = GeoUtil.readWKT(value);
                    }
                    return req.formatGeoCondition(e.field, e.op, geo);
                default:
                    throw new ArlasException(e.op + " op on field '" + field + "' of type '" + wType + "' is not supported");
            }
        default:
            throw new InvalidParameterException(INVALID_OPERATOR);
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) ArlasException(io.arlas.server.core.exceptions.ArlasException) InvalidParameterException(io.arlas.server.core.exceptions.InvalidParameterException) ArrayList(java.util.ArrayList) FieldType(io.arlas.server.core.model.response.FieldType)

Example 5 with FieldType

use of io.arlas.server.core.model.response.FieldType in project ARLAS-server by gisaia.

the class CollectionReferenceService method getType.

public FieldType getType(CollectionReference collectionReference, String field, boolean throwException) throws ArlasException {
    FieldType fieldType = cacheManager.getFieldType(collectionReference.collectionName, field);
    if (fieldType == null) {
        String[] props = field.split("\\.");
        CollectionReferenceDescriptionProperty esField = describeCollection(collectionReference).properties.get(props[0]);
        if (esField == null) {
            return getUnknownType(field, collectionReference.collectionName, throwException);
        }
        for (int i = 1; i < props.length; i++) {
            esField = esField.properties.get(props[i]);
            if (esField == null) {
                return getUnknownType(field, collectionReference.collectionName, throwException);
            }
        }
        if (esField != null) {
            fieldType = esField.type;
            cacheManager.putFieldType(collectionReference.collectionName, field, fieldType);
        } else {
            return getUnknownType(field, collectionReference.collectionName, throwException);
        }
    }
    return fieldType;
}
Also used : FieldType(io.arlas.server.core.model.response.FieldType) CollectionReferenceDescriptionProperty(io.arlas.server.core.model.response.CollectionReferenceDescriptionProperty)

Aggregations

FieldType (io.arlas.server.core.model.response.FieldType)5 CollectionReferenceDescriptionProperty (io.arlas.server.core.model.response.CollectionReferenceDescriptionProperty)2 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 ArlasException (io.arlas.server.core.exceptions.ArlasException)1 InvalidParameterException (io.arlas.server.core.exceptions.InvalidParameterException)1 ArrayList (java.util.ArrayList)1 Geometry (org.locationtech.jts.geom.Geometry)1