Search in sources :

Example 16 with ProcedureEntity

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

the class InsertResultHandler method insertObservationConstellationForProfiles.

private DatasetEntity insertObservationConstellationForProfiles(AbstractSeriesDAO obsConstDao, FormatDAO obsTypeDao, OmObservation o, Session session) throws OwsExceptionReport {
    ProcedureEntity procedure = getDaoFactory().getProcedureDAO().getProcedureForIdentifier(o.getObservationConstellation().getProcedureIdentifier(), session);
    PhenomenonEntity observableProperty = getDaoFactory().getObservablePropertyDAO().getOrInsertObservableProperty(o.getObservationConstellation().getObservableProperty(), session);
    OfferingEntity offering = getDaoFactory().getOfferingDAO().getOfferingForIdentifier(o.getObservationConstellation().getOfferings().iterator().next(), session);
    CategoryEntity category = getDaoFactory().getCategoryDAO().getOrInsertCategory(observableProperty, session);
    DatasetEntity oc = obsConstDao.checkOrInsertSeries(procedure, observableProperty, offering, category, false, session);
    if (o.getObservationConstellation().isSetObservationType()) {
        oc.setOmObservationType(obsTypeDao.getFormatEntityObject(o.getObservationConstellation().getObservationType(), session));
    }
    return oc;
}
Also used : ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) DatasetEntity(org.n52.series.db.beans.DatasetEntity) PhenomenonEntity(org.n52.series.db.beans.PhenomenonEntity) OfferingEntity(org.n52.series.db.beans.OfferingEntity) CategoryEntity(org.n52.series.db.beans.CategoryEntity)

Example 17 with ProcedureEntity

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

the class DescribeSensorDaoImpl method getProcedureDescriptions.

/**
 * @param request
 *            DescribeSensorRequest request
 * @param session
 *            Hibernate session
 * @return Matching procedure descriptions
 * @throws OwsExceptionReport
 *             If an error occurs
 */
private List<SosProcedureDescription<?>> getProcedureDescriptions(DescribeSensorRequest request, Session session) throws OwsExceptionReport {
    Set<String> possibleProcedureDescriptionFormats = getPossibleProcedureDescriptionFormats(request.getProcedureDescriptionFormat());
    final ProcedureEntity procedure = new ProcedureDAO(daoFactory).getProcedureForIdentifier(request.getProcedure(), possibleProcedureDescriptionFormats, request.getValidTime(), session);
    List<SosProcedureDescription<?>> list = Lists.newLinkedList();
    if (procedure != null) {
        if (procedure.hasProcedureHistory()) {
            for (ProcedureHistoryEntity validProcedureTime : daoFactory.getProcedureHistoryDAO().get(procedure, possibleProcedureDescriptionFormats, request.getValidTime(), session)) {
                SosProcedureDescription<?> sosProcedureDescription = procedureConverter.createSosProcedureDescriptionFromValidProcedureTime(procedure, request.getProcedureDescriptionFormat(), validProcedureTime, request.getVersion(), getRequestedLocale(request), session);
                list.add(convertProcedureDescription(sosProcedureDescription, request));
            }
        }
    } else {
        SosProcedureDescription<?> procedureDescription = getProcedureDescription(request, session);
        if (procedureDescription != null) {
            list.add(procedureDescription);
        } else {
            if (!request.isSetValidTime()) {
                throw new NoApplicableCodeException().causedBy(new IllegalArgumentException(LOG_PARAMETER_PROCEDURE_NOT_NULL)).setStatus(HTTPStatus.INTERNAL_SERVER_ERROR);
            }
        }
    }
    return list;
}
Also used : ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) ProcedureHistoryEntity(org.n52.series.db.beans.ProcedureHistoryEntity) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) SosProcedureDescription(org.n52.shetland.ogc.sos.SosProcedureDescription)

Example 18 with ProcedureEntity

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

the class InsertResultHandler method createProcedure.

/**
 * Create internal ProcedureDescription from Procedure entity
 *
 * @param hProcedure
 *            Procedure entity
 * @return Internal ProcedureDescription
 */
private SosProcedureDescription<?> createProcedure(final ProcedureEntity hProcedure) {
    final SensorML procedure = new SensorML();
    procedure.setIdentifier(hProcedure.getIdentifier());
    return new SosProcedureDescription<AbstractFeature>(procedure);
}
Also used : SosProcedureDescription(org.n52.shetland.ogc.sos.SosProcedureDescription) SensorML(org.n52.shetland.ogc.sensorML.SensorML)

Example 19 with ProcedureEntity

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

the class InsertResultTemplateHandler method insertResultTemplate.

@Override
public synchronized InsertResultTemplateResponse insertResultTemplate(InsertResultTemplateRequest request) throws OwsExceptionReport {
    InsertResultTemplateResponse response = new InsertResultTemplateResponse();
    response.setService(request.getService());
    response.setVersion(request.getVersion());
    response.setAcceptedTemplate(request.getIdentifier().getValue());
    Session session = null;
    Transaction transaction = null;
    try {
        session = sessionHolder.getSession();
        transaction = session.beginTransaction();
        OmObservationConstellation sosObsConst = request.getObservationTemplate();
        DatasetEntity obsConst = null;
        for (String offeringID : sosObsConst.getOfferings()) {
            obsConst = getDaoFactory().getSeriesDAO().checkSeries(sosObsConst, offeringID, session, Sos2Constants.InsertResultTemplateParams.proposedTemplate.name());
            if (obsConst != null) {
                // check if result structure elements are supported
                checkResultStructure(request.getResultStructure(), obsConst.getObservableProperty().getIdentifier(), sosObsConst);
                ProcedureEntity procedure = null;
                AbstractFeatureEntity<?> feature = null;
                if (sosObsConst.isSetFeatureOfInterest()) {
                    FeatureOfInterestDAO featureOfInterestDAO = getDaoFactory().getFeatureOfInterestDAO();
                    feature = featureOfInterestDAO.checkOrInsert(sosObsConst.getFeatureOfInterest(), session);
                    featureOfInterestDAO.checkOrInsertRelatedFeatureRelation(feature, obsConst.getOffering(), session);
                }
                if (sosObsConst.isSetProcedure()) {
                    procedure = obsConst.getProcedure();
                }
                checkOrInsertResultTemplate(request, obsConst, procedure, feature, session);
            } else {
                // TODO make better exception.
                throw new InvalidObservationTypeException(request.getObservationTemplate().getObservationType());
            }
        }
        session.flush();
        transaction.commit();
    } catch (HibernateException he) {
        if (transaction != null) {
            transaction.rollback();
        }
        throw new NoApplicableCodeException().causedBy(he).withMessage("Insert result template into database failed!");
    } catch (OwsExceptionReport owse) {
        if (transaction != null) {
            transaction.rollback();
        }
        throw owse;
    } finally {
        sessionHolder.returnSession(session);
    }
    return response;
}
Also used : InsertResultTemplateResponse(org.n52.shetland.ogc.sos.response.InsertResultTemplateResponse) FeatureOfInterestDAO(org.n52.sos.ds.hibernate.dao.FeatureOfInterestDAO) HibernateException(org.hibernate.HibernateException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) DatasetEntity(org.n52.series.db.beans.DatasetEntity) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation) InvalidObservationTypeException(org.n52.sos.exception.ows.concrete.InvalidObservationTypeException) ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) Transaction(org.hibernate.Transaction) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) Session(org.hibernate.Session)

Example 20 with ProcedureEntity

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

the class HibernateObservationBuilder method getProcedure.

protected ProcedureEntity getProcedure() {
    ProcedureEntity procedure = (ProcedureEntity) session.createCriteria(ProcedureEntity.class).add(Restrictions.eq(ProcedureEntity.IDENTIFIER, PROCEDURE)).uniqueResult();
    if (procedure == null) {
        ProcedureEntity tProcedure = new ProcedureEntity();
        tProcedure.setDeleted(false);
        tProcedure.setIdentifier(PROCEDURE);
        tProcedure.setFormat(getProcedureDescriptionFormat());
        tProcedure.setChildren(null);
        tProcedure.setParents(null);
        session.save(tProcedure);
        session.flush();
        tProcedure.setProcedureHistory(Collections.singleton(getValidProcedureTime()));
        session.update(tProcedure);
        session.flush();
        return tProcedure;
    }
    return procedure;
}
Also used : ProcedureEntity(org.n52.series.db.beans.ProcedureEntity)

Aggregations

ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)32 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)14 HibernateException (org.hibernate.HibernateException)11 DatasetEntity (org.n52.series.db.beans.DatasetEntity)10 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)10 Criteria (org.hibernate.Criteria)9 Session (org.hibernate.Session)9 OfferingEntity (org.n52.series.db.beans.OfferingEntity)9 SosProcedureDescription (org.n52.shetland.ogc.sos.SosProcedureDescription)9 HashSet (java.util.HashSet)8 FormatEntity (org.n52.series.db.beans.FormatEntity)7 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)6 DateTime (org.joda.time.DateTime)6 ArrayList (java.util.ArrayList)5 Collection (java.util.Collection)5 HashMap (java.util.HashMap)5 Transaction (org.hibernate.Transaction)5 ProcedureHistoryEntity (org.n52.series.db.beans.ProcedureHistoryEntity)5 Set (java.util.Set)4 Collectors.toCollection (java.util.stream.Collectors.toCollection)4