use of org.n52.sos.ds.hibernate.dao.ObservablePropertyDAO in project SOS by 52North.
the class ObservablePropertyDAOTest method save.
protected Map<String, PhenomenonEntity> save(List<AbstractPhenomenon> abstractPhenomenons, Session session) {
I18NDAORepository i18NDAORepository = new I18NDAORepository();
DaoFactory daoFactory = new DaoFactory();
daoFactory.setI18NDAORepository(i18NDAORepository);
ObservablePropertyDAO dao = daoFactory.getObservablePropertyDAO();
Collection<PhenomenonEntity> savedObservableProperties = dao.getOrInsertObservableProperty(abstractPhenomenons, session);
return asMap(savedObservableProperties);
}
use of org.n52.sos.ds.hibernate.dao.ObservablePropertyDAO in project SOS by 52North.
the class AbstractSeriesDAO method checkSeries.
/**
* Check and Update and/or get observation constellation objects
*
* @param sosOC
* SOS observation constellation
* @param offering
* Offering identifier
* @param session
* Hibernate session
* @param parameterName
* Parameter name for exception
* @return Observation constellation object
* @throws OwsExceptionReport
* If the requested observation type is invalid
*/
public DatasetEntity checkSeries(OmObservationConstellation sosOC, String offering, Session session, String parameterName) throws OwsExceptionReport {
// TODO: check for Unit if available!!!
AbstractPhenomenon observableProperty = sosOC.getObservableProperty();
String observablePropertyIdentifier = observableProperty.getIdentifier();
Criteria c = session.createCriteria(getSeriesClass()).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
c.createCriteria(DatasetEntity.PROPERTY_OFFERING).add(Restrictions.eq(OfferingEntity.IDENTIFIER, offering));
c.createCriteria(DatasetEntity.PROPERTY_PHENOMENON).add(Restrictions.eq(PhenomenonEntity.IDENTIFIER, observablePropertyIdentifier));
if (sosOC.isSetProcedure()) {
c.createCriteria(DatasetEntity.PROPERTY_PROCEDURE).add(Restrictions.eq(ProcedureEntity.IDENTIFIER, sosOC.getProcedureIdentifier()));
}
LOGGER.trace("QUERY checkObservationConstellation(sosObservationConstellation, offering): {}", HibernateHelper.getSqlString(c));
List<DatasetEntity> hocs = c.list();
if (hocs == null || hocs.isEmpty()) {
throw new InvalidParameterValueException().at(Sos2Constants.InsertObservationParams.observation).withMessage("The requested observation constellation (procedure=%s, " + "observedProperty=%s and offering=%s) is invalid!", sosOC.getProcedureIdentifier(), observablePropertyIdentifier, sosOC.getOfferings());
}
String observationType = sosOC.getObservationType();
DatasetEntity hObsConst = null;
for (DatasetEntity hoc : hocs) {
if (!checkObservationType(hoc, observationType, session)) {
throw new InvalidParameterValueException().at(parameterName).withMessage("The requested observationType (%s) is invalid for procedure = %s, " + "observedProperty = %s and offering = %s! The valid observationType is '%s'!", observationType, sosOC.getProcedureIdentifier(), observablePropertyIdentifier, sosOC.getOfferings(), hoc.getOmObservationType().getFormat());
}
if (hObsConst == null) {
if (sosOC.isSetProcedure()) {
if (hoc.getProcedure().getIdentifier().equals(sosOC.getProcedureIdentifier())) {
hObsConst = hoc;
}
} else {
hObsConst = hoc;
}
}
// add parent/childs
// if (observableProperty instanceof OmCompositePhenomenon) {
// OmCompositePhenomenon omCompositePhenomenon =
// (OmCompositePhenomenon) observableProperty;
// ObservablePropertyDAO dao = new
// ObservablePropertyDAO(getDaoFactory());
// Map<String, PhenomenonEntity> obsprop =
// dao.getOrInsertObservablePropertyAsMap(Arrays.asList(observableProperty),
// false, session);
// for (OmObservableProperty child : omCompositePhenomenon) {
// checkOrInsertSeries(hoc.getProcedure(),
// obsprop.get(child.getIdentifier()),
// hoc.getOffering(), true, session);
// }
// }
}
return hObsConst;
}
Aggregations