Search in sources :

Example 1 with OGCExceptionMessage

use of io.arlas.server.ogc.common.exceptions.OGC.OGCExceptionMessage in project ARLAS-server by gisaia.

the class FilterToElastic method writeLiteral.

/**
 * Writes out a non null, non geometry literal. The base class properly handles
 * null, numeric and booleans (true|false), and turns everything else into a string.
 * Subclasses are expected to override this shall they need a different treatment
 * (e.g. for dates)
 *
 * @param literal
 */
protected void writeLiteral(Object literal) {
    boolean isDate = false;
    if (((String) field).split(":").length > 1) {
        String[] pathElements = ((String) field).split(":")[1].split(ArlasServerConfiguration.FLATTEN_CHAR);
        isDate = isPathDate(pathElements, collectionReference.properties);
    } else if (((String) field).split(":").length == 1) {
        String[] pathElements = ((String) field).split(ArlasServerConfiguration.FLATTEN_CHAR);
        isDate = isPathDate(pathElements, collectionReference.properties);
    }
    field = literal;
    if (isDate && !Date.class.isAssignableFrom(literal.getClass())) {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX");
        f.setTimeZone(TimeZone.getTimeZone("UTC"));
        try {
            // hack for the ets test suite wich test with bad date
            // bad 1970-01-01T00:13:33.4Z
            // bad 1970-01-01T00:13:33.43Z
            // good 1970-01-01T00:13:33.430Z
            String lastElement = ((String) literal).split("\\.")[1];
            String firstElement = ((String) literal).split("\\.")[0];
            String millisPart = lastElement.trim();
            if (millisPart.length() == 1) {
                literal = firstElement.concat(".").concat(millisPart).concat("00").concat("Z");
            } else if (lastElement.trim().length() == 2) {
                literal = firstElement.concat(".").concat(millisPart).concat("0").concat("Z");
            }
            // TODO change the test
            field = dateFormatter.print((f.parse((String) literal)).getTime());
        } catch (ParseException e) {
            List<OGCExceptionMessage> wfsExceptionMessages = new ArrayList<>();
            wfsExceptionMessages.add(new OGCExceptionMessage(OGCExceptionCode.OPERATION_PROCESSING_FAILED, "Invalid Filter", "filter"));
            wfsExceptionMessages.add(new OGCExceptionMessage(OGCExceptionCode.INVALID_PARAMETER_VALUE, "Unable to format " + field + "  in " + collectionReference.collectionName + ".", "filter"));
            ogcException = new OGCException(wfsExceptionMessages, Service.WFS);
            throw new RuntimeException();
        }
    }
    if (Date.class.isAssignableFrom(literal.getClass())) {
        field = dateFormatter.print(((Date) literal).getTime());
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) OGCExceptionMessage(io.arlas.server.ogc.common.exceptions.OGC.OGCExceptionMessage) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) OGCException(io.arlas.server.ogc.common.exceptions.OGC.OGCException)

Example 2 with OGCExceptionMessage

use of io.arlas.server.ogc.common.exceptions.OGC.OGCExceptionMessage in project ARLAS-server by gisaia.

the class FilterToElastic method throwInvalidFesFilterException.

private void throwInvalidFesFilterException(String message) {
    List<OGCExceptionMessage> ogcExceptionMessages = new ArrayList<>();
    ogcExceptionMessages.add(new OGCExceptionMessage(OGCExceptionCode.MISSING_ATTRIBUTE_FOR_OPERATOR, message, "filter"));
    ogcException = new OGCException(ogcExceptionMessages, service);
    throw new RuntimeException();
}
Also used : OGCExceptionMessage(io.arlas.server.ogc.common.exceptions.OGC.OGCExceptionMessage) OGCException(io.arlas.server.ogc.common.exceptions.OGC.OGCException)

Example 3 with OGCExceptionMessage

use of io.arlas.server.ogc.common.exceptions.OGC.OGCExceptionMessage in project ARLAS-server by gisaia.

the class FilterToElastic method throwDateException.

private void throwDateException() {
    List<OGCExceptionMessage> ogcExceptionMessages = new ArrayList<>();
    ogcExceptionMessages.add(new OGCExceptionMessage(INSPIREExceptionCode.INVALID_PARAMETER_VALUE, "Invalid date format. It should be YYYY-MM-DD", "filter"));
    ogcException = new OGCException(ogcExceptionMessages, service);
    throw new RuntimeException();
}
Also used : OGCExceptionMessage(io.arlas.server.ogc.common.exceptions.OGC.OGCExceptionMessage) OGCException(io.arlas.server.ogc.common.exceptions.OGC.OGCException)

Example 4 with OGCExceptionMessage

use of io.arlas.server.ogc.common.exceptions.OGC.OGCExceptionMessage in project ARLAS-server by gisaia.

the class FilterToElastic method throwInvalidFieldException.

private void throwInvalidFieldException() {
    List<OGCExceptionMessage> ogcExceptionMessages = new ArrayList<>();
    ogcExceptionMessages.add(new OGCExceptionMessage(OGCExceptionCode.OPERATION_PROCESSING_FAILED, "Invalid Filter", "filter"));
    String exceptionText;
    if (service == Service.WFS) {
        exceptionText = "Unable to find " + field + "  in " + collectionReference.collectionName + ".";
    } else {
        exceptionText = "Unable to find the queried metadata : '" + key + "'";
    }
    ogcExceptionMessages.add(new OGCExceptionMessage(OGCExceptionCode.INVALID_PARAMETER_VALUE, exceptionText, "filter"));
    ogcException = new OGCException(ogcExceptionMessages, service);
    throw new RuntimeException();
}
Also used : OGCExceptionMessage(io.arlas.server.ogc.common.exceptions.OGC.OGCExceptionMessage) OGCException(io.arlas.server.ogc.common.exceptions.OGC.OGCException)

Example 5 with OGCExceptionMessage

use of io.arlas.server.ogc.common.exceptions.OGC.OGCExceptionMessage in project ARLAS-server by gisaia.

the class FilterToElastic method visit.

/**
 * Writes the FilterBuilder for the Like Filter.
 *
 * @param filter the filter to be visited
 */
public Object visit(PropertyIsLike filter, Object extraData) {
    if (filter.getEscape() == null) {
        throwInvalidFesFilterException("Missing escape attribute in 'PropertyIsLike' filter");
    }
    if (filter.getWildCard() == null) {
        throwInvalidFesFilterException("Missing wildCard attribute in 'PropertyIsLike' filter");
    }
    if (filter.getSingleChar() == null) {
        throwInvalidFesFilterException("Missing singleChar attribute in 'PropertyIsLike' filter");
    }
    char esc = filter.getEscape().charAt(0);
    char multi = filter.getWildCard().charAt(0);
    char single = filter.getSingleChar().charAt(0);
    boolean matchCase = false;
    if (filter.isMatchingCase()) {
        LOGGER.debug("Case sensitive search not supported");
    }
    String literal = filter.getLiteral();
    Expression att = filter.getExpression();
    AttributeDescriptor attType = (AttributeDescriptor) att.evaluate(featureType);
    analyzed = false;
    nested = false;
    if (attType != null) {
        if (attType.getUserData().containsKey(ANALYZED)) {
            analyzed = (Boolean) attType.getUserData().get(ANALYZED);
        }
        if (attType.getUserData().containsKey(NESTED)) {
            nested = (Boolean) attType.getUserData().get(NESTED);
        }
        if (Date.class.isAssignableFrom(attType.getType().getBinding())) {
            updateDateFormatter(attType);
        }
    }
    att.accept(this, extraData);
    key = (String) XmlUtils.retrievePointPath((String) field);
    String[] pathElements = getPathElements(key);
    if (isPathDate(pathElements, collectionReference.properties)) {
        updateDateFormatter(key);
    }
    if (isFilterQueryableADate(literal)) {
        List<OGCExceptionMessage> ogcExceptionMessages = new ArrayList<>();
        ogcExceptionMessages.add(new OGCExceptionMessage(OGCExceptionCode.OPERATION_PROCESSING_FAILED, "Invalid Filter", "filter"));
        ogcExceptionMessages.add(new OGCExceptionMessage(OGCExceptionCode.INVALID_PARAMETER_VALUE, "Date fields are not allowed in PropertyIsLike filter", "filter"));
        ogcException = new OGCException(ogcExceptionMessages, Service.CSW);
        throw new RuntimeException();
    }
    if (service == Service.CSW) {
        if (isFilterQueryableADate(literal)) {
            List<OGCExceptionMessage> ogcExceptionMessages = new ArrayList<>();
            ogcExceptionMessages.add(new OGCExceptionMessage(OGCExceptionCode.OPERATION_PROCESSING_FAILED, "Invalid Filter", "filter"));
            ogcExceptionMessages.add(new OGCExceptionMessage(OGCExceptionCode.INVALID_PARAMETER_VALUE, "Date fields are not allowed in PropertyIsLike filter", "filter"));
            ogcException = new OGCException(ogcExceptionMessages, service);
            throw new RuntimeException();
        }
        setNestedKeys(key);
        key = mapFieldNameToInspireRequirements(key);
    }
    if (!OGCCheckParam.isFieldInMapping(collectionReference, key)) {
        throwInvalidFieldException();
    }
    if (analyzed) {
        // use query string query post filter for analyzed fields
        pattern = convertToQueryString(esc, multi, single, matchCase, literal);
    } else {
        // default to regexp filter
        pattern = convertToRegex(esc, multi, single, matchCase, literal);
    }
    if (nested) {
        path = extractNestedPath(key);
    }
    if (analyzed) {
        // use query string query for analyzed fields
        queryBuilder = ImmutableMap.of("query_string", ImmutableMap.of("query", pattern, "default_field", key));
    } else {
        // default to regexp query
        queryBuilder = ImmutableMap.of("regexp", ImmutableMap.of(key, pattern));
    }
    if (nested) {
        queryBuilder = ImmutableMap.of("nested", ImmutableMap.of("path", path, "query", queryBuilder));
    }
    return extraData;
}
Also used : AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) OGCExceptionMessage(io.arlas.server.ogc.common.exceptions.OGC.OGCExceptionMessage) OGCException(io.arlas.server.ogc.common.exceptions.OGC.OGCException)

Aggregations

OGCException (io.arlas.server.ogc.common.exceptions.OGC.OGCException)6 OGCExceptionMessage (io.arlas.server.ogc.common.exceptions.OGC.OGCExceptionMessage)6 ImmutableList (com.google.common.collect.ImmutableList)1 ArlasException (io.arlas.server.core.exceptions.ArlasException)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 GeoJsonObject (org.geojson.GeoJsonObject)1 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)1