Search in sources :

Example 1 with DataEntity

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

the class DeleteObservationHelper method checkForFirstLastReference.

default void checkForFirstLastReference(DataEntity<?> observation, Session session) {
    DatasetEntity dataset = observation.getDataset();
    if (dataset.getFirstObservation() != null && dataset.getFirstObservation().getId() != null && observation.getId() != null && dataset.getFirstObservation().getId().equals(observation.getId())) {
        dataset.setFirstObservation(null);
    }
    if (dataset.getLastObservation() != null && dataset.getLastObservation().getId() != null && observation.getId() != null && dataset.getLastObservation().getId().equals(observation.getId())) {
        dataset.setLastObservation(null);
    }
    session.update(dataset);
    session.flush();
}
Also used : DatasetEntity(org.n52.series.db.beans.DatasetEntity)

Example 2 with DataEntity

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

the class DeleteObservationHelper method checkSeriesForFirstLatest.

/**
 * Check if {@link Dataset} should be updated
 *
 * @param serieses
 *            Deleted observation
 * @param session
 *            Hibernate session
 * @throws OwsExceptionReport
 *             If an error occurs
 */
default void checkSeriesForFirstLatest(Collection<Long> serieses, Session session) throws OwsExceptionReport {
    if (!serieses.isEmpty()) {
        AbstractSeriesObservationDAO observationDAO = getDaoFactory().getObservationDAO();
        Map<Long, SeriesTimeExtrema> minMaxTimes = observationDAO.getMinMaxSeriesTimesById(serieses instanceof Set ? (Set<Long>) serieses : new LinkedHashSet<>(serieses), session);
        for (Long id : serieses) {
            DatasetEntity series = session.get(DatasetEntity.class, id);
            boolean update = false;
            if (minMaxTimes.containsKey(series.getId())) {
                SeriesTimeExtrema extrema = minMaxTimes.get(series.getId());
                if (!series.isSetFirstValueAt() || series.isSetFirstValueAt() && !DateTimeHelper.makeDateTime(series.getFirstValueAt()).equals(extrema.getMinPhenomenonTime())) {
                    series.setFirstValueAt(extrema.getMinPhenomenonTime().toDate());
                    DataEntity<?> o = unproxy(observationDAO.getMinObservation(series, extrema.getMinPhenomenonTime(), session), session);
                    series.setFirstObservation(o);
                    if (series.getValueType().equals(ValueType.quantity)) {
                        series.setFirstQuantityValue(((QuantityDataEntity) o).getValue());
                    }
                    update = true;
                }
                if (!series.isSetLastValueAt() || series.isSetLastValueAt() && !DateTimeHelper.makeDateTime(series.getLastValueAt()).equals(extrema.getMaxPhenomenonTime())) {
                    series.setLastValueAt(extrema.getMaxPhenomenonTime().toDate());
                    DataEntity<?> o = unproxy(observationDAO.getMaxObservation(series, extrema.getMaxPhenomenonTime(), session), session);
                    series.setLastObservation(o);
                    if (series.getValueType().equals(ValueType.quantity)) {
                        series.setLastQuantityValue(((QuantityDataEntity) o).getValue());
                    }
                    update = true;
                }
            } else {
                series.setFirstValueAt(null);
                series.setFirstQuantityValue(null);
                series.setFirstObservation(null);
                series.setLastValueAt(null);
                series.setLastQuantityValue(null);
                series.setLastObservation(null);
                update = true;
            }
            if (update) {
                session.saveOrUpdate(series);
                session.flush();
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) DatasetEntity(org.n52.series.db.beans.DatasetEntity) AbstractSeriesObservationDAO(org.n52.sos.ds.hibernate.dao.observation.series.AbstractSeriesObservationDAO) SeriesTimeExtrema(org.n52.sos.ds.hibernate.dao.observation.series.SeriesTimeExtrema)

Example 3 with DataEntity

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

the class GetResultHandler method getResult.

@Override
public GetResultResponse getResult(final GetResultRequest request) throws OwsExceptionReport {
    Session session = null;
    try {
        session = sessionHolder.getSession();
        final GetResultResponse response = new GetResultResponse();
        response.setService(request.getService());
        response.setVersion(request.getVersion());
        final Set<String> featureIdentifier = QueryHelper.getFeatures(getDaoFactory().getFeatureQueryHandler(), request, session);
        final ResultTemplateEntity resultTemplate = queryResultTemplate(request, featureIdentifier, session);
        SosResultEncoding sosResultEncoding = null;
        SosResultStructure sosResultStructure = null;
        if (resultTemplate != null) {
            sosResultEncoding = createSosResultEncoding(resultTemplate.getEncoding());
            sosResultStructure = createSosResultStructure(resultTemplate.getStructure());
        } else {
            sosResultEncoding = createSosResultEncoding();
            sosResultStructure = generateSosResultStructure(request.getObservedProperty(), request.getOffering(), featureIdentifier, session);
        }
        final List<DataEntity<?>> observations;
        observations = querySeriesObservation(request, featureIdentifier, session);
        response.setResultValues(getResultHandlingHelper().createResultValuesFromObservations(observations, sosResultEncoding, sosResultStructure, getProfileHandler().getActiveProfile().getResponseNoDataPlaceholder(), session));
        return response;
    } catch (final HibernateException he) {
        throw new NoApplicableCodeException().causedBy(he).withMessage("Error while querying result data!").setStatus(HTTPStatus.INTERNAL_SERVER_ERROR);
    } finally {
        sessionHolder.returnSession(session);
    }
}
Also used : HibernateException(org.hibernate.HibernateException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) GetResultResponse(org.n52.shetland.ogc.sos.response.GetResultResponse) ResultTemplateEntity(org.n52.series.db.beans.ResultTemplateEntity) DataEntity(org.n52.series.db.beans.DataEntity) SosResultEncoding(org.n52.shetland.ogc.sos.SosResultEncoding) SosResultStructure(org.n52.shetland.ogc.sos.SosResultStructure) Session(org.hibernate.Session)

Example 4 with DataEntity

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

the class ResultHandlingHelper method getSamplingGeometry.

private String getSamplingGeometry(DataEntity<?> observation, String tokenSeparator, SweAbstractDataComponent sweAbstractDataComponent, String noDataPlaceholder) throws OwsExceptionReport {
    SweVector vector = getVector(sweAbstractDataComponent);
    if (vector != null && vector.isSetCoordinates()) {
        final Map<Integer, String> valueOrder = new HashMap<>(0);
        addOrderAndVectorDefinitionToMap(vector.getCoordinates(), valueOrder, new IncDecInteger());
        final StringBuilder builder = new StringBuilder();
        Geometry samplingGeometry = null;
        if (observation.isSetGeometryEntity()) {
            samplingGeometry = getGeomtryHandler().switchCoordinateAxisFromToDatasourceIfNeeded(observation.getGeometryEntity().getGeometry());
        }
        for (final Entry<Integer, String> entry : valueOrder.entrySet()) {
            final String definition = entry.getValue();
            if (samplingGeometry != null && samplingGeometry instanceof Point) {
                Coordinate coordinate = samplingGeometry.getCoordinate();
                if (helper.hasAltitudeName(definition) && checkCoordinate(coordinate.getZ())) {
                    builder.append(coordinate.getZ());
                } else if (helper.hasNorthingName(definition)) {
                    if (getGeomtryHandler().isNorthingFirstEpsgCode(samplingGeometry.getSRID())) {
                        builder.append(coordinate.x);
                    } else {
                        builder.append(coordinate.y);
                    }
                } else if (helper.hasEastingName(definition)) {
                    if (getGeomtryHandler().isNorthingFirstEpsgCode(samplingGeometry.getSRID())) {
                        builder.append(coordinate.y);
                    } else {
                        builder.append(coordinate.x);
                    }
                } else {
                    builder.append(noDataPlaceholder);
                }
            } else {
                builder.append(noDataPlaceholder);
            }
            builder.append(tokenSeparator);
        }
        return builder.delete(builder.lastIndexOf(tokenSeparator), builder.length()).toString();
    }
    return noDataPlaceholder;
}
Also used : IncDecInteger(org.n52.sos.util.IncDecInteger) Geometry(org.locationtech.jts.geom.Geometry) SweVector(org.n52.shetland.ogc.swe.SweVector) HashMap(java.util.HashMap) Coordinate(org.locationtech.jts.geom.Coordinate) SweCoordinate(org.n52.shetland.ogc.swe.SweCoordinate) Point(org.locationtech.jts.geom.Point) IncDecInteger(org.n52.sos.util.IncDecInteger)

Example 5 with DataEntity

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

the class ResultHandlingHelper method createObservedPropertyField.

private List<SweField> createObservedPropertyField(DataEntity<?> observation) throws OwsExceptionReport {
    List<SweField> fields = new LinkedList<>();
    PhenomenonEntity phenomenon = observation.getDataset().getPhenomenon();
    if (observation.getDataset().getDatasetType().equals(DatasetType.profile) || observation.getDataset().getObservationType().equals(ObservationType.profile)) {
        ProfileValue profile = (ProfileValue) new ObservationValueCreator(decoderRepository).visit(observation);
        ProfileLevel level = profile.getValue().get(0);
        fields.add(createVerticalParameter(level));
        if (level.getValue().get(0) instanceof SweAbstractDataComponent) {
            if (level.getValue().size() > 1) {
                SweDataRecord record = new SweDataRecord();
                for (Value<?> v : level.getValue()) {
                    SweAbstractDataComponent dc = (SweAbstractDataComponent) v;
                    record.addField(new SweField(NcName.makeValid(dc.getDefinition()), dc));
                }
                fields.add(new SweField(getNcNameName(phenomenon), record));
                return fields;
            } else {
                SweAbstractDataComponent swe = (SweAbstractDataComponent) level.getValue().get(0).setValue(null);
                swe.setDefinition(phenomenon.getIdentifier());
                fields.add(new SweField(getNcNameName(phenomenon), swe));
                return fields;
            }
        }
    } else {
        SweAbstractDataComponent value = new SweAbstractDataComponentCreator(decoderRepository, true).visit(observation);
        fields.add(new SweField(getNcNameName(phenomenon), (SweAbstractDataComponent) value));
        return fields;
    }
    throw new NoApplicableCodeException();
}
Also used : SweField(org.n52.shetland.ogc.swe.SweField) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) ProfileLevel(org.n52.shetland.ogc.om.values.ProfileLevel) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) ObservationValueCreator(org.n52.sos.ds.hibernate.util.observation.ObservationValueCreator) SweAbstractDataComponentCreator(org.n52.sos.ds.hibernate.util.observation.SweAbstractDataComponentCreator) PhenomenonEntity(org.n52.series.db.beans.PhenomenonEntity) LinkedList(java.util.LinkedList) ProfileValue(org.n52.shetland.ogc.om.values.ProfileValue)

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