Search in sources :

Example 1 with NotAllowedException

use of io.arlas.server.core.exceptions.NotAllowedException in project ARLAS-server by gisaia.

the class JdbiFluidSearch method setOrder.

private void setOrder(Aggregation aggregationModel, MetricSelectClause metricAggregation, SelectClause sp) throws ArlasException {
    Order order = aggregationModel.order;
    OrderOn on = aggregationModel.on;
    boolean isGeo = GEO_AGGREGATION_TYPE_ENUMS.contains(aggregationModel.type);
    if (order == null && on == null && !isGeo) {
        if (aggregationModel.type == AggregationTypeEnum.term) {
            order = Order.desc;
            on = OrderOn.count;
        } else {
            order = Order.asc;
            on = OrderOn.field;
        }
    }
    boolean orderAsc = order == Order.asc;
    if (order != null && on != null) {
        if (!isGeo) {
            switch(on) {
                case field:
                    req.addOrderClause(sp.asName, orderAsc);
                    break;
                case count:
                    req.addOrderClause(((AggregationSelectClause) sp).asNameCount, orderAsc);
                    break;
                case result:
                    if (metricAggregation != null) {
                        // ORDER ON RESULT IS NOT ALLOWED ON COORDINATES (CENTROID) OR BOUNDING BOX
                        if (!metricAggregation.isGeo()) {
                            req.addOrderClause(metricAggregation.asName, orderAsc);
                        } else {
                            throw new BadRequestException(ORDER_ON_GEO_RESULT_NOT_ALLOWED);
                        }
                    } else {
                        throw new BadRequestException(ORDER_ON_RESULT_NOT_ALLOWED);
                    }
                    break;
            }
        } else {
            throw new NotAllowedException(ORDER_PARAM_NOT_ALLOWED);
        }
    } else if (order != null) {
        if (isGeo)
            throw new NotAllowedException(ORDER_PARAM_NOT_ALLOWED);
        else
            throw new BadRequestException(ON_NOT_SPECIFIED);
    } else if (on != null) {
        if (isGeo)
            throw new NotAllowedException(ORDER_PARAM_NOT_ALLOWED);
        else
            throw new BadRequestException(ORDER_NOT_SPECIFIED);
    }
}
Also used : NotAllowedException(io.arlas.server.core.exceptions.NotAllowedException) BadRequestException(io.arlas.server.core.exceptions.BadRequestException)

Example 2 with NotAllowedException

use of io.arlas.server.core.exceptions.NotAllowedException in project ARLAS-server by gisaia.

the class CheckParams method checkExcludeField.

public static void checkExcludeField(List<String> excludeFields, List<String> fields) throws NotAllowedException {
    ArrayList<Pattern> excludeFieldsPattern = new ArrayList<>();
    excludeFields.forEach(field -> excludeFieldsPattern.add(Pattern.compile("^" + field.replace(".", "\\.").replace("*", ".*") + ".*$")));
    boolean excludePath;
    for (String field : fields) {
        excludePath = excludeFieldsPattern.stream().anyMatch(pattern -> pattern.matcher(field).matches());
        if (excludePath)
            throw new NotAllowedException("Unable to exclude field " + field + " used for id, geometry, centroid or timestamp.");
    }
}
Also used : Arrays(java.util.Arrays) SimpleDateFormat(java.text.SimpleDateFormat) LanguageAlpha3Code(com.neovisionaries.i18n.LanguageAlpha3Code) Keyword(io.arlas.server.core.model.Keyword) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) ArlasException(io.arlas.server.core.exceptions.ArlasException) InvalidParameterException(io.arlas.server.core.exceptions.InvalidParameterException) CollectionReferenceManager(io.arlas.server.core.managers.CollectionReferenceManager) Inspire(io.arlas.server.core.model.Inspire) ParseException(java.text.ParseException) DateFormat(java.text.DateFormat) BadRequestException(io.arlas.server.core.exceptions.BadRequestException) DateTimeFormat(org.joda.time.format.DateTimeFormat) CollectionReference(io.arlas.server.core.model.CollectionReference) io.arlas.server.core.model.request(io.arlas.server.core.model.request) FieldType(io.arlas.server.core.model.response.FieldType) NotAllowedException(io.arlas.server.core.exceptions.NotAllowedException) List(java.util.List) Polygon(org.locationtech.jts.geom.Polygon) Geometry(org.locationtech.jts.geom.Geometry) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) FluidSearchService(io.arlas.server.core.services.FluidSearchService) io.arlas.server.core.model.enumerations(io.arlas.server.core.model.enumerations) Pattern(java.util.regex.Pattern) NotAllowedException(io.arlas.server.core.exceptions.NotAllowedException) ArrayList(java.util.ArrayList)

Aggregations

BadRequestException (io.arlas.server.core.exceptions.BadRequestException)2 NotAllowedException (io.arlas.server.core.exceptions.NotAllowedException)2 LanguageAlpha3Code (com.neovisionaries.i18n.LanguageAlpha3Code)1 ArlasException (io.arlas.server.core.exceptions.ArlasException)1 InvalidParameterException (io.arlas.server.core.exceptions.InvalidParameterException)1 CollectionReferenceManager (io.arlas.server.core.managers.CollectionReferenceManager)1 CollectionReference (io.arlas.server.core.model.CollectionReference)1 Inspire (io.arlas.server.core.model.Inspire)1 Keyword (io.arlas.server.core.model.Keyword)1 io.arlas.server.core.model.enumerations (io.arlas.server.core.model.enumerations)1 io.arlas.server.core.model.request (io.arlas.server.core.model.request)1 FieldType (io.arlas.server.core.model.response.FieldType)1 FluidSearchService (io.arlas.server.core.services.FluidSearchService)1 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1