Search in sources :

Example 26 with FormatEntity

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

the class UpdateSensorDescriptionHandler method updateSensorDescription.

@Override
public synchronized UpdateSensorResponse updateSensorDescription(UpdateSensorRequest request) throws OwsExceptionReport {
    Session session = null;
    Transaction transaction = null;
    try {
        session = sessionHolder.getSession();
        transaction = session.beginTransaction();
        UpdateSensorResponse response = new UpdateSensorResponse();
        response.setService(request.getService());
        response.setVersion(request.getVersion());
        for (SosProcedureDescription<?> procedureDescription : request.getProcedureDescriptions()) {
            DateTime currentTime = new DateTime(DateTimeZone.UTC);
            // TODO: check for all validTimes of descriptions for this
            // identifier
            // ITime validTime =
            // getValidTimeForProcedure(procedureDescription);
            ProcedureEntity procedure = daoFactory.getProcedureDAO().getProcedureForIdentifier(request.getProcedureIdentifier(), session);
            FormatEntity procedureDescriptionFormat = new DaoFactory().getProcedureDescriptionFormatDAO().getFormatEntityObject(request.getProcedureDescriptionFormat(), session);
            Set<ProcedureHistoryEntity> procedureHistories = procedure.getProcedureHistory();
            ProcedureHistoryDAO procedureHistroyDAO = daoFactory.getProcedureHistoryDAO();
            for (ProcedureHistoryEntity procedureHistroy : procedureHistories) {
                if (procedureHistroy.getFormat().getFormat().equals(procedureDescriptionFormat.getFormat()) && procedureHistroy.getEndTime() == null) {
                    procedureHistroy.setEndTime(currentTime.toDate());
                    procedureHistroyDAO.update(procedureHistroy, session);
                }
            }
            procedureHistroyDAO.insert(procedure, procedureDescriptionFormat, getSensorDescriptionFromProcedureDescription(procedureDescription), currentTime, session);
        }
        session.flush();
        transaction.commit();
        response.setUpdatedProcedure(request.getProcedureIdentifier());
        return response;
    } catch (HibernateException he) {
        if (transaction != null) {
            transaction.rollback();
        }
        throw new NoApplicableCodeException().causedBy(he).withMessage("Error while processing data for UpdateSensorDescription document!");
    } finally {
        sessionHolder.returnSession(session);
    }
}
Also used : ProcedureHistoryEntity(org.n52.series.db.beans.ProcedureHistoryEntity) HibernateException(org.hibernate.HibernateException) FormatEntity(org.n52.series.db.beans.FormatEntity) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) DateTime(org.joda.time.DateTime) DaoFactory(org.n52.sos.ds.hibernate.dao.DaoFactory) ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) Transaction(org.hibernate.Transaction) UpdateSensorResponse(org.n52.shetland.ogc.sos.response.UpdateSensorResponse) ProcedureHistoryDAO(org.n52.sos.ds.hibernate.dao.ProcedureHistoryDAO) Session(org.hibernate.Session)

Example 27 with FormatEntity

use of org.n52.series.db.beans.FormatEntity in project sensorweb-server-sta by 52North.

the class ObservationService method checkOffering.

private OfferingEntity checkOffering(DatastreamEntity datastream) throws STACRUDException {
    ProcedureEntity procedure = datastream.getProcedure();
    synchronized (getLock(procedure.getIdentifier())) {
        if (!offeringRepository.existsByIdentifier(procedure.getIdentifier())) {
            OfferingEntity offering = new OfferingEntity();
            offering.setIdentifier(procedure.getIdentifier());
            offering.setStaIdentifier(procedure.getStaIdentifier());
            offering.setName(procedure.getName());
            offering.setDescription(procedure.getDescription());
            if (datastream.hasSamplingTimeStart()) {
                offering.setSamplingTimeStart(datastream.getSamplingTimeStart());
            }
            if (datastream.hasSamplingTimeEnd()) {
                offering.setSamplingTimeEnd(datastream.getSamplingTimeEnd());
            }
            if (datastream.getResultTimeStart() != null) {
                offering.setResultTimeStart(datastream.getResultTimeStart());
            }
            if (datastream.getResultTimeEnd() != null) {
                offering.setResultTimeEnd(datastream.getResultTimeEnd());
            }
            if (datastream.isSetGeometry()) {
                offering.setGeometryEntity(datastream.getGeometryEntity());
            }
            HashSet<FormatEntity> set = new HashSet<>();
            set.add(datastream.getObservationType());
            offering.setObservationTypes(set);
            return offeringRepository.save(offering);
        } else {
            // TODO expand time and geometry if necessary
            return offeringRepository.findByIdentifier(procedure.getIdentifier()).get();
        }
    }
}
Also used : ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) FormatEntity(org.n52.series.db.beans.FormatEntity) OfferingEntity(org.n52.series.db.beans.OfferingEntity) HashSet(java.util.HashSet)

Aggregations

FormatEntity (org.n52.series.db.beans.FormatEntity)24 Session (org.hibernate.Session)7 OfferingEntity (org.n52.series.db.beans.OfferingEntity)7 ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)7 Transaction (org.hibernate.Transaction)6 Criteria (org.hibernate.Criteria)5 HibernateException (org.hibernate.HibernateException)5 UnitEntity (org.n52.series.db.beans.UnitEntity)5 DatasetEntity (org.n52.series.db.beans.DatasetEntity)4 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)4 DateTime (org.joda.time.DateTime)3 ParseException (org.locationtech.jts.io.ParseException)3 GeoJsonReader (org.locationtech.jts.io.geojson.GeoJsonReader)3 AbstractFeatureEntity (org.n52.series.db.beans.AbstractFeatureEntity)3 CategoryEntity (org.n52.series.db.beans.CategoryEntity)3 FeatureEntity (org.n52.series.db.beans.FeatureEntity)3 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)3 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)3 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)3 HashSet (java.util.HashSet)2