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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations