Search in sources :

Example 21 with DataEntity

use of org.n52.series.db.beans.DataEntity in project SOS by 52North.

the class AbstractSeriesObservationDAO method getFirstObservationFor.

/**
 * Get the first not deleted observation for the {@link DatasetEntity}
 *
 * @param series
 *            Series to get observation for
 * @param session
 *            Hibernate session
 * @return First not deleted observation
 */
public DataEntity<?> getFirstObservationFor(DatasetEntity series, Session session) {
    Criteria c = getDefaultObservationCriteria(session);
    c.add(Restrictions.eq(DataEntity.PROPERTY_DATASET_ID, series.getId()));
    c.addOrder(Order.asc(DataEntity.PROPERTY_SAMPLING_TIME_START));
    c.setMaxResults(1);
    LOGGER.trace("QUERY getFirstObservationFor(series): {}", HibernateHelper.getSqlString(c));
    return (DataEntity) c.uniqueResult();
}
Also used : DataEntity(org.n52.series.db.beans.DataEntity) Criteria(org.hibernate.Criteria)

Example 22 with DataEntity

use of org.n52.series.db.beans.DataEntity 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 23 with DataEntity

use of org.n52.series.db.beans.DataEntity 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 24 with DataEntity

use of org.n52.series.db.beans.DataEntity in project SOS by 52North.

the class EReportingHelper method createSweDataArrayValue.

/**
 * Creates an {@link ObservationValue} from the {@link DataEntity}
 *
 * @param omObservation
 *            Corresponding {@link OmObservation}
 * @param observation
 *            {@link DataEntity} to create {@link ObservationValue} from
 * @return Created {@link ObservationValue}.
 * @throws CodedException
 *             If an error occurs
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public SingleObservationValue<?> createSweDataArrayValue(OmObservation omObservation, DataEntity observation) throws CodedException {
    SweDataArrayValue sweDataArrayValue = new SweDataArrayValue();
    sweDataArrayValue.setValue(createSweDataArray(omObservation, observation));
    SingleObservationValue observationValue = new SingleObservationValue(sweDataArrayValue);
    observationValue.setPhenomenonTime(getPhenomenonTime(omObservation, DataTimeCreator.createPhenomenonTime(observation)));
    addQuality(observation.getEreportingProfile(), observationValue);
    return observationValue;
}
Also used : SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) SweDataArrayValue(org.n52.shetland.ogc.om.values.SweDataArrayValue)

Example 25 with DataEntity

use of org.n52.series.db.beans.DataEntity in project SOS by 52North.

the class ObservationOmObservationCreator method createObservationConstellation.

private OmObservationConstellation createObservationConstellation(DataEntity<?> hObservation, String procedureId, String phenomenonId, String featureId, Set<String> offerings) throws OwsExceptionReport {
    long start = System.currentTimeMillis();
    LOGGER.trace("Creating ObservationConstellation...");
    OmObservationConstellation obsConst = new OmObservationConstellation(getProcedure(procedureId), getObservedProperty(phenomenonId), getFeature(featureId), offerings);
    if (observationConstellations.containsKey(obsConst.hashCode())) {
        obsConst = observationConstellations.get(obsConst.hashCode());
    }
    int hashCode = obsConst.hashCode();
    if (!Strings.isNullOrEmpty(getResultModel())) {
        obsConst.setObservationType(getResultModel());
    }
    if (hObservation.getDataset().isSetOmObservationType()) {
        obsConst.setObservationType(hObservation.getDataset().getOmObservationType().getFormat());
    }
    observationConstellations.put(hashCode, obsConst);
    DatasetEntity series = hObservation.getDataset();
    if (series.isSetIdentifier()) {
        addIdentifier(obsConst, series);
    }
    obsConst.setObservationType(getResultModel());
    if (request.isSetRequestedLanguage()) {
        addNameAndDescription(series, obsConst, getRequestedLanguage(), getI18N(), false);
        if (obsConst.isSetName()) {
            obsConst.setHumanReadableIdentifier(obsConst.getFirstName().getValue());
        }
    } else {
        if (series.isSetName()) {
            addName(obsConst, series);
        }
        if (series.isSetDescription()) {
            obsConst.setDescription(series.getDescription());
        }
    }
    LOGGER.trace("Creating ObservationConstellation done in {} ms.", System.currentTimeMillis() - start);
    return obsConst;
}
Also used : DatasetEntity(org.n52.series.db.beans.DatasetEntity) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation)

Aggregations

DataEntity (org.n52.series.db.beans.DataEntity)31 Criteria (org.hibernate.Criteria)20 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)18 DatasetEntity (org.n52.series.db.beans.DatasetEntity)14 QuantityDataEntity (org.n52.series.db.beans.QuantityDataEntity)14 Test (org.junit.Test)13 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)11 LinkedList (java.util.LinkedList)10 HibernateException (org.hibernate.HibernateException)9 Session (org.hibernate.Session)9 List (java.util.List)8 SubQueryIdentifier (org.n52.sos.ds.hibernate.util.ResultFilterRestrictions.SubQueryIdentifier)8 DateTime (org.joda.time.DateTime)7 OmObservation (org.n52.shetland.ogc.om.OmObservation)7 DataArrayDataEntity (org.n52.series.db.beans.DataArrayDataEntity)6 ReferencedDataEntity (org.n52.series.db.beans.ReferencedDataEntity)6 GetObservationRequest (org.n52.shetland.ogc.sos.request.GetObservationRequest)6 ComplexDataEntity (org.n52.series.db.beans.ComplexDataEntity)5 GeometryDataEntity (org.n52.series.db.beans.GeometryDataEntity)5 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)5