Search in sources :

Example 1 with SubQueryIdentifier

use of org.n52.sos.ds.hibernate.util.ResultFilterRestrictions.SubQueryIdentifier in project SOS by 52North.

the class AbstractSeriesDAO method getSeriesCriteria.

@SuppressWarnings("unchecked")
protected Set<DatasetEntity> getSeriesCriteria(GetDataAvailabilityRequest request, Session session) throws OwsExceptionReport {
    Set<DatasetEntity> set = new LinkedHashSet<>();
    if (request.hasResultFilter()) {
        for (SubQueryIdentifier identifier : ResultFilterRestrictions.getSubQueryIdentifier(getResultFilterClasses())) {
            Criteria c = getSeriesCriteria(request.getProcedures(), request.getObservedProperties(), request.getFeaturesOfInterest(), request.getOfferings(), session);
            checkAndAddResultFilterCriterion(c, request, identifier, session);
            checkAndAddSpatialFilterCriterion(c, request, session);
            LOGGER.trace("QUERY getSeriesCriteria(request) and result filter sub query '{}': {}", identifier.name(), HibernateHelper.getSqlString(c));
            set.addAll(c.list());
        }
    } else {
        Criteria c = getSeriesCriteria(request.getProcedures(), request.getObservedProperties(), request.getFeaturesOfInterest(), request.getOfferings(), session);
        checkAndAddSpatialFilterCriterion(c, request, session);
        LOGGER.trace(QUERY_SERIES_CRITERIA, HibernateHelper.getSqlString(c));
        set.addAll(c.list());
    }
    return set;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DatasetEntity(org.n52.series.db.beans.DatasetEntity) Criteria(org.hibernate.Criteria) DetachedCriteria(org.hibernate.criterion.DetachedCriteria) SubQueryIdentifier(org.n52.sos.ds.hibernate.util.ResultFilterRestrictions.SubQueryIdentifier)

Example 2 with SubQueryIdentifier

use of org.n52.sos.ds.hibernate.util.ResultFilterRestrictions.SubQueryIdentifier in project SOS by 52North.

the class AbstractSeriesValueDAO method getStreamingSeriesValuesFor.

/**
 * Query streaming value for parameter as chunk {@link List}
 *
 * @param request
 *            {@link AbstractObservationRequest}
 * @param series
 *            Datasource series id
 * @param chunkSize
 *            Chunk size
 * @param currentRow
 *            Start row
 * @param session
 *            Hibernate Session
 * @return Resulting chunk {@link List}
 * @throws OwsExceptionReport
 *             If an error occurs when querying
 */
@SuppressWarnings("unchecked")
public List<DataEntity<?>> getStreamingSeriesValuesFor(AbstractObservationRequest request, long series, int chunkSize, int currentRow, Session session) throws OwsExceptionReport {
    if (request instanceof GetObservationRequest && ((GetObservationRequest) request).hasResultFilter()) {
        StringBuilder logArgs = new StringBuilder();
        List<DataEntity<?>> list = new LinkedList<>();
        for (SubQueryIdentifier identifier : ResultFilterRestrictions.getSubQueryIdentifier(getResultFilterClasses())) {
            Criteria c = getSeriesValueCriteriaFor(request, series, null, session, logArgs);
            addChunkValuesToCriteria(c, chunkSize, currentRow, request, logArgs);
            checkAndAddResultFilterCriterion(c, (GetObservationRequest) request, identifier, session, logArgs);
            LOGGER.trace(QUERY_STREAMING_SERIES_VALUE, logArgs.toString(), HibernateHelper.getSqlString(c));
            list.addAll(c.list());
        }
        return list;
    } else {
        StringBuilder logArgs = new StringBuilder();
        Criteria c = getSeriesValueCriteriaFor(request, series, null, session, logArgs);
        addChunkValuesToCriteria(c, chunkSize, currentRow, request, logArgs);
        LOGGER.trace(QUERY_STREAMING_SERIES_VALUE, logArgs.toString(), HibernateHelper.getSqlString(c));
        return (List<DataEntity<?>>) c.list();
    }
}
Also used : GetObservationRequest(org.n52.shetland.ogc.sos.request.GetObservationRequest) DataEntity(org.n52.series.db.beans.DataEntity) List(java.util.List) LinkedList(java.util.LinkedList) Criteria(org.hibernate.Criteria) LinkedList(java.util.LinkedList) SubQueryIdentifier(org.n52.sos.ds.hibernate.util.ResultFilterRestrictions.SubQueryIdentifier)

Example 3 with SubQueryIdentifier

use of org.n52.sos.ds.hibernate.util.ResultFilterRestrictions.SubQueryIdentifier in project SOS by 52North.

the class AbstractSeriesValueDAO method getStreamingSeriesValuesFor.

/**
 * Query streaming value for parameter as chunk {@link List}
 *
 * @param request
 *            {@link AbstractObservationRequest}
 * @param series
 *            Datasource series ids
 * @param chunkSize
 *            Chunk size
 * @param currentRow
 *            Start row
 * @param session
 *            Hibernate Session
 * @return Resulting chunk {@link List}
 * @throws OwsExceptionReport
 *             If an error occurs when querying
 */
@SuppressWarnings("unchecked")
public List<DataEntity<?>> getStreamingSeriesValuesFor(AbstractObservationRequest request, Set<Long> series, int chunkSize, int currentRow, Session session) throws OwsExceptionReport {
    if (request instanceof GetObservationRequest && ((GetObservationRequest) request).hasResultFilter()) {
        List<DataEntity<?>> list = new LinkedList<>();
        for (SubQueryIdentifier identifier : ResultFilterRestrictions.getSubQueryIdentifier(getResultFilterClasses())) {
            StringBuilder logArgs = new StringBuilder();
            Criteria c = getSeriesValueCriteriaFor(request, series, null, session, logArgs);
            addChunkValuesToCriteria(c, chunkSize, currentRow, request, logArgs);
            checkAndAddResultFilterCriterion(c, (GetObservationRequest) request, identifier, session, logArgs);
            LOGGER.trace(QUERY_STREAMING_SERIES_VALUE, logArgs.toString(), HibernateHelper.getSqlString(c));
            list.addAll(c.list());
        }
        return list;
    } else {
        StringBuilder logArgs = new StringBuilder();
        Criteria c = getSeriesValueCriteriaFor(request, series, null, session, logArgs);
        addChunkValuesToCriteria(c, chunkSize, currentRow, request, logArgs);
        LOGGER.trace(QUERY_STREAMING_SERIES_VALUE, logArgs.toString(), HibernateHelper.getSqlString(c));
        return (List<DataEntity<?>>) c.list();
    }
}
Also used : GetObservationRequest(org.n52.shetland.ogc.sos.request.GetObservationRequest) DataEntity(org.n52.series.db.beans.DataEntity) List(java.util.List) LinkedList(java.util.LinkedList) Criteria(org.hibernate.Criteria) LinkedList(java.util.LinkedList) SubQueryIdentifier(org.n52.sos.ds.hibernate.util.ResultFilterRestrictions.SubQueryIdentifier)

Example 4 with SubQueryIdentifier

use of org.n52.sos.ds.hibernate.util.ResultFilterRestrictions.SubQueryIdentifier in project SOS by 52North.

the class ResultFilterRestrictions method getResultFilterExpression.

public static Criterion getResultFilterExpression(ComparisonFilter resultFilter, ResultFilterClasses resultFilterClasses, String subqueryColumn, String column, SubQueryIdentifier identifier) throws NoApplicableCodeException, InvalidParameterValueException {
    List<DetachedCriteria> list = new LinkedList<>();
    List<DetachedCriteria> complexList = new LinkedList<>();
    switch(resultFilter.getOperator()) {
        case PropertyIsEqualTo:
            if (isNumeric(resultFilter.getValue())) {
                list.add(createEqDC(createDC(resultFilterClasses.getNumeric()), getBigDecimal(resultFilter.getValue()), column));
                complexList.add(createEqDC(createDC(resultFilterClasses.getNumeric()), getBigDecimal(resultFilter.getValue()), DataEntity.PROPERTY_ID));
            }
            if (isCount(resultFilter.getValue())) {
                list.add(createEqDC(createDC(resultFilterClasses.getCount()), Integer.parseInt(resultFilter.getValue()), column));
                complexList.add(createEqDC(createDC(resultFilterClasses.getCount()), Integer.parseInt(resultFilter.getValue()), DataEntity.PROPERTY_ID));
            }
            if (!isNumeric(resultFilter.getValue()) && !isCount(resultFilter.getValue())) {
                list.add(createEqDC(createDC(resultFilterClasses.getCategory()), resultFilter.getValue(), column));
                list.add(createEqDC(createDC(resultFilterClasses.getText()), resultFilter.getValue(), column));
                complexList.add(createEqDC(createDC(resultFilterClasses.getCategory()), resultFilter.getValue(), DataEntity.PROPERTY_ID));
                complexList.add(createEqDC(createDC(resultFilterClasses.getText()), resultFilter.getValue(), DataEntity.PROPERTY_ID));
            }
            break;
        case PropertyIsBetween:
            if (isCount(resultFilter.getValue()) && isCount(resultFilter.getValueUpper())) {
                list.add(createBetweenDC(createDC(resultFilterClasses.getCount()), Integer.parseInt(resultFilter.getValue()), Integer.parseInt(resultFilter.getValueUpper()), column));
                complexList.add(createBetweenDC(createDC(resultFilterClasses.getCount()), Integer.parseInt(resultFilter.getValue()), Integer.parseInt(resultFilter.getValueUpper()), DataEntity.PROPERTY_ID));
            }
            if (isNumeric(resultFilter.getValue()) && isNumeric(resultFilter.getValueUpper())) {
                list.add(createBetweenDC(createDC(resultFilterClasses.getNumeric()), getBigDecimal(resultFilter.getValue()), getBigDecimal(resultFilter.getValueUpper()), column));
                complexList.add(createBetweenDC(createDC(resultFilterClasses.getNumeric()), getBigDecimal(resultFilter.getValue()), getBigDecimal(resultFilter.getValueUpper()), DataEntity.PROPERTY_ID));
            }
            if (!isNumeric(resultFilter.getValue()) && !isCount(resultFilter.getValue())) {
                throw new NoApplicableCodeException();
            }
            break;
        case PropertyIsGreaterThan:
            if (isCount(resultFilter.getValue())) {
                list.add(createGtDC(createDC(resultFilterClasses.getCount()), Integer.parseInt(resultFilter.getValue()), column));
                complexList.add(createGtDC(createDC(resultFilterClasses.getCount()), Integer.parseInt(resultFilter.getValue()), DataEntity.PROPERTY_ID));
            }
            if (isNumeric(resultFilter.getValue())) {
                list.add(createGtDC(createDC(resultFilterClasses.getNumeric()), getBigDecimal(resultFilter.getValue()), column));
                complexList.add(createGtDC(createDC(resultFilterClasses.getNumeric()), getBigDecimal(resultFilter.getValue()), DataEntity.PROPERTY_ID));
            }
            if (!isNumeric(resultFilter.getValue()) && !isCount(resultFilter.getValue())) {
                throw new NoApplicableCodeException();
            }
            break;
        case PropertyIsGreaterThanOrEqualTo:
            if (isCount(resultFilter.getValue())) {
                list.add(createGeDC(createDC(resultFilterClasses.getCount()), Integer.parseInt(resultFilter.getValue()), column));
                complexList.add(createGeDC(createDC(resultFilterClasses.getCount()), Integer.parseInt(resultFilter.getValue()), DataEntity.PROPERTY_ID));
            }
            if (isNumeric(resultFilter.getValue())) {
                list.add(createGeDC(createDC(resultFilterClasses.getNumeric()), getBigDecimal(resultFilter.getValue()), column));
                complexList.add(createGeDC(createDC(resultFilterClasses.getNumeric()), getBigDecimal(resultFilter.getValue()), DataEntity.PROPERTY_ID));
            }
            if (!isNumeric(resultFilter.getValue()) && !isCount(resultFilter.getValue())) {
                throw new NoApplicableCodeException();
            }
            break;
        case PropertyIsLessThan:
            if (isCount(resultFilter.getValue())) {
                list.add(createLtDC(createDC(resultFilterClasses.getCount()), Integer.parseInt(resultFilter.getValue()), column));
                complexList.add(createLtDC(createDC(resultFilterClasses.getCount()), Integer.parseInt(resultFilter.getValue()), DataEntity.PROPERTY_ID));
            }
            if (isNumeric(resultFilter.getValue())) {
                list.add(createLtDC(createDC(resultFilterClasses.getNumeric()), getBigDecimal(resultFilter.getValue()), column));
                complexList.add(createLtDC(createDC(resultFilterClasses.getNumeric()), getBigDecimal(resultFilter.getValue()), DataEntity.PROPERTY_ID));
            }
            if (!isNumeric(resultFilter.getValue()) && !isCount(resultFilter.getValue())) {
                throw new NoApplicableCodeException();
            }
            break;
        case PropertyIsLessThanOrEqualTo:
            if (isCount(resultFilter.getValue())) {
                list.add(createLeDC(createDC(resultFilterClasses.getCount()), Integer.parseInt(resultFilter.getValue()), column));
                complexList.add(createLeDC(createDC(resultFilterClasses.getCount()), Integer.parseInt(resultFilter.getValue()), DataEntity.PROPERTY_ID));
            }
            if (isNumeric(resultFilter.getValue())) {
                list.add(createLeDC(createDC(resultFilterClasses.getNumeric()), getBigDecimal(resultFilter.getValue()), column));
                complexList.add(createLeDC(createDC(resultFilterClasses.getNumeric()), getBigDecimal(resultFilter.getValue()), DataEntity.PROPERTY_ID));
            }
            if (!isNumeric(resultFilter.getValue()) && !isCount(resultFilter.getValue())) {
                throw new NoApplicableCodeException();
            }
            break;
        case PropertyIsLike:
            list.add(createLikeDC(createDC(resultFilterClasses.getCategory()), resultFilter, column));
            list.add(createLikeDC(createDC(resultFilterClasses.getText()), resultFilter, column));
            complexList.add(createLikeDC(createDC(resultFilterClasses.getCategory()), resultFilter, DataEntity.PROPERTY_ID));
            complexList.add(createLikeDC(createDC(resultFilterClasses.getText()), resultFilter, DataEntity.PROPERTY_ID));
            break;
        default:
            throw new InvalidParameterValueException(ResultFilterConstants.RESULT_FILTER + ".operator", resultFilter.getOperator().toString());
    }
    if (!complexList.isEmpty()) {
        if (identifier == null) {
            if (HibernateHelper.isEntitySupported(resultFilterClasses.getProfile())) {
                list.add(createProfileDC(createDC(resultFilterClasses.getProfile(), PO_PREFIX), complexList, column));
            }
            if (HibernateHelper.isEntitySupported(resultFilterClasses.getComplex())) {
                list.add(createComplexDC(createDC(resultFilterClasses.getComplex(), CO_PREFIX), complexList, column));
            }
        } else if (identifier.equals(SubQueryIdentifier.Profile) && HibernateHelper.isEntitySupported(resultFilterClasses.getProfile())) {
            list.clear();
            list.add(createProfileDC(createDC(resultFilterClasses.getProfile(), PO_PREFIX), complexList, column));
        } else if (identifier.equals(SubQueryIdentifier.Complex) && HibernateHelper.isEntitySupported(resultFilterClasses.getComplex())) {
            list.clear();
            list.add(createComplexDC(createDC(resultFilterClasses.getComplex(), CO_PREFIX), complexList, column));
        }
    }
    if (!list.isEmpty()) {
        if (list.size() > 1) {
            Disjunction d = Restrictions.disjunction();
            for (DetachedCriteria dc : list) {
                d.add(getSubquery(dc, subqueryColumn));
            }
            return d;
        } else {
            return getSubquery(list.iterator().next(), subqueryColumn);
        }
    }
    return null;
}
Also used : Disjunction(org.hibernate.criterion.Disjunction) InvalidParameterValueException(org.n52.shetland.ogc.ows.exception.InvalidParameterValueException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) DetachedCriteria(org.hibernate.criterion.DetachedCriteria) LinkedList(java.util.LinkedList)

Example 5 with SubQueryIdentifier

use of org.n52.sos.ds.hibernate.util.ResultFilterRestrictions.SubQueryIdentifier in project SOS by 52North.

the class AbstractSeriesValueTimeDAO method getTimeExtremaForSeries.

/**
 * Get {@link ObservationTimeExtrema} for a dataset id with temporal
 * filter.
 *
 * @param request
 *            {@link AbstractObservationRequest} request
 * @param series
 *            {@link Set} of dataset ids to get time extrema for
 * @param temporalFilterCriterion
 *            Temporal filter
 * @param session
 *            Hibernate session
 * @return Time extrema for dataset ids
 * @throws OwsExceptionReport
 *             If an error occurs
 */
public ObservationTimeExtrema getTimeExtremaForSeries(AbstractObservationRequest request, Set<Long> series, Criterion temporalFilterCriterion, Session session) throws OwsExceptionReport {
    if (request instanceof GetObservationRequest && ((GetObservationRequest) request).hasResultFilter()) {
        ObservationTimeExtrema ote = new ObservationTimeExtrema();
        for (SubQueryIdentifier identifier : ResultFilterRestrictions.getSubQueryIdentifier(getResultFilterClasses())) {
            Criteria c = getSeriesValueCriteriaFor(request, series, temporalFilterCriterion, null, session);
            checkAndAddResultFilterCriterion(c, (GetObservationRequest) request, identifier, session, new StringBuilder());
            addMinMaxTimeProjection(c);
            ote.expand(parseMinMaxTime((Object[]) c.uniqueResult()));
        }
        return ote;
    } else {
        Criteria c = getSeriesValueCriteriaFor(request, series, temporalFilterCriterion, null, session);
        addMinMaxTimeProjection(c);
        LOGGER.trace(LOG_QUERY_TIME_EXTREMA, HibernateHelper.getSqlString(c));
        return parseMinMaxTime((Object[]) c.uniqueResult());
    }
}
Also used : ObservationTimeExtrema(org.n52.sos.ds.hibernate.util.ObservationTimeExtrema) GetObservationRequest(org.n52.shetland.ogc.sos.request.GetObservationRequest) Criteria(org.hibernate.Criteria) SubQueryIdentifier(org.n52.sos.ds.hibernate.util.ResultFilterRestrictions.SubQueryIdentifier)

Aggregations

Criteria (org.hibernate.Criteria)9 SubQueryIdentifier (org.n52.sos.ds.hibernate.util.ResultFilterRestrictions.SubQueryIdentifier)9 LinkedList (java.util.LinkedList)6 DataEntity (org.n52.series.db.beans.DataEntity)5 GetObservationRequest (org.n52.shetland.ogc.sos.request.GetObservationRequest)5 List (java.util.List)3 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)3 LinkedHashSet (java.util.LinkedHashSet)2 DatasetEntity (org.n52.series.db.beans.DatasetEntity)2 ObservationTimeExtrema (org.n52.sos.ds.hibernate.util.ObservationTimeExtrema)2 Disjunction (org.hibernate.criterion.Disjunction)1 InvalidParameterValueException (org.n52.shetland.ogc.ows.exception.InvalidParameterValueException)1 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)1