use of io.arlas.server.core.exceptions.BadRequestException 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);
}
}
use of io.arlas.server.core.exceptions.BadRequestException in project ARLAS-server by gisaia.
the class ParamsParser method getHitsFetcher.
private static HitsFetcher getHitsFetcher(String fetchHitsString) throws ArlasException {
HitsFetcher hitsFetcher = new HitsFetcher();
if (StringUtil.isNullOrEmpty(fetchHitsString)) {
throw new BadRequestException("fetch_hits should not be null nor empty");
}
Matcher matcher = HITS_FETCHER_PATTERN.matcher(fetchHitsString);
if (!matcher.matches()) {
throw new InvalidParameterException("Invalid fetch_hits syntax. It should respect the following pattern : {size*}(+{field1}, -{field2}, {field3}, ...)");
}
hitsFetcher.size = Optional.ofNullable(ParamsParser.tryParseInteger(matcher.group(1))).orElse(1);
hitsFetcher.include = Arrays.asList(matcher.group(3).split(","));
return hitsFetcher;
}
use of io.arlas.server.core.exceptions.BadRequestException in project ARLAS-server by gisaia.
the class JdbiFluidSearch method setAggregationParameters.
private void setAggregationParameters(String aggName, Aggregation aggregationModel, SelectClause sp) throws ArlasException {
// firstMetricAggregationBuilder is the aggregation builder on which the order aggregation will be applied
MetricSelectClause firstMetric = null;
if (aggregationModel.metrics != null) {
for (Metric m : aggregationModel.metrics) {
if (m.collectFct == null) {
throw new BadRequestException(COLLECT_FCT_NOT_SPECIFIED);
} else if (m.collectField == null) {
throw new BadRequestException(COLLECT_FIELD_NOT_SPECIFIED);
}
MetricSelectClause metricPredicate = null;
switch(m.collectFct) {
case AVG:
metricPredicate = new MetricSelectClause(m.collectField, concat(aggName, US, ColumnQualifier.getQualifier(CollectionFunction.AVG, m.collectField)), AVG);
break;
case CARDINALITY:
metricPredicate = new MetricSelectClause(m.collectField, concat(aggName, US, ColumnQualifier.getQualifier(CollectionFunction.CARDINALITY, m.collectField)), COUNT);
break;
case MAX:
metricPredicate = new MetricSelectClause(m.collectField, concat(aggName, US, ColumnQualifier.getQualifier(CollectionFunction.MAX, m.collectField)), MAX);
break;
case MIN:
metricPredicate = new MetricSelectClause(m.collectField, concat(aggName, US, ColumnQualifier.getQualifier(CollectionFunction.MIN, m.collectField)), MIN);
break;
case SUM:
metricPredicate = new MetricSelectClause(m.collectField, concat(aggName, US, ColumnQualifier.getQualifier(CollectionFunction.SUM, m.collectField)), SUM);
break;
case GEOCENTROID:
setGeoMetricAggregationCollectField(m);
// We calculate this metric only if it wasn't requested as a geometry to return in `aggregatedGeometries` parameter
if (!(aggregationModel.aggregatedGeometries != null && aggregationModel.aggregatedGeometries.contains(AggregatedGeometryEnum.CENTROID) && aggregationModel.field.equals(m.collectField))) {
metricPredicate = new AggregatedGeoSelectClause(m.collectField, concat(aggName, US, ColumnQualifier.getQualifier(CollectionFunction.GEOCENTROID, m.collectField)), AggregatedGeometryEnum.CENTROID.value());
}
break;
case GEOBBOX:
setGeoMetricAggregationCollectField(m);
// We calculate this metric only if it wasn't requested as a geometry to return in `aggregatedGeometries` parameter
if (!(aggregationModel.aggregatedGeometries != null && aggregationModel.aggregatedGeometries.contains(AggregatedGeometryEnum.BBOX) && aggregationModel.field.equals(m.collectField))) {
metricPredicate = new AggregatedGeoSelectClause(m.collectField, concat(aggName, US, ColumnQualifier.getQualifier(CollectionFunction.GEOBBOX, m.collectField)), AggregatedGeometryEnum.BBOX.value());
}
break;
}
if (metricPredicate != null) {
req.addSelectClause(metricPredicate);
// Getting the first metric aggregation builder that is different from GEOBBOX and GEOCENTROID, on which the order will be applied
if (firstMetric == null && m.collectFct != CollectionFunction.GEOBBOX && m.collectFct != CollectionFunction.GEOCENTROID) {
firstMetric = metricPredicate;
}
}
}
}
if (aggregationModel.size != null) {
this.req.limit = ParamsParser.getValidAggregationSize(aggregationModel.size);
}
setOrder(aggregationModel, firstMetric, sp);
}
Aggregations