use of org.n52.sos.ds.hibernate.dao.observation.ObservationContext in project SOS by 52North.
the class EReportingObservationDAO method fillObservationContext.
@Override
protected ObservationContext fillObservationContext(ObservationContext ctx, OmObservation omObservation, Session session) {
if (ctx instanceof EReportingObservationContext) {
EReportingObservationContext ectx = (EReportingObservationContext) ctx;
AqdSamplingPoint samplingPoint = null;
if (omObservation.isSetParameter()) {
samplingPoint = new AqdSamplingPoint();
List<NamedValue<?>> remove = Lists.newArrayList();
for (NamedValue<?> namedValue : omObservation.getParameter()) {
if (checkForSamplingPoint(namedValue.getName())) {
addSamplingPointParameterValuesToAqdSamplingPoint(samplingPoint, namedValue.getValue());
remove.add(namedValue);
} else if (checkForAssessmentType(namedValue.getName())) {
addAssessmentTypeParameterValuesToAqdSamplingPoint(samplingPoint, namedValue.getValue());
remove.add(namedValue);
}
}
omObservation.getParameter().removeAll(remove);
EReportingSamplingPointDAO dao = new EReportingSamplingPointDAO(getDaoFactory());
ectx.setSamplingPoint(dao.getOrInsert(samplingPoint, session));
}
if (samplingPoint == null && omObservation.getObservationConstellation().isSetFeatureOfInterest()) {
samplingPoint = new AqdSamplingPoint();
AbstractFeature featureOfInterest = omObservation.getObservationConstellation().getFeatureOfInterest();
addSamplingPointParameterValuesToAqdSamplingPoint(samplingPoint, new ReferenceValue(new ReferenceType(featureOfInterest.getIdentifier(), featureOfInterest.isSetName() ? featureOfInterest.getFirstName().getValue() : "")));
EReportingSamplingPointDAO dao = new EReportingSamplingPointDAO(getDaoFactory());
ectx.setSamplingPoint(dao.getOrInsert(samplingPoint, session));
}
if (samplingPoint != null && samplingPoint.getAssessmentType() == null) {
addAssessmentTypeParameterValuesToAqdSamplingPoint(samplingPoint, new TextValue(AssessmentType.Fixed.name()));
}
}
return ctx;
}
use of org.n52.sos.ds.hibernate.dao.observation.ObservationContext in project SOS by 52North.
the class ObservationPersister method checkForParameter.
private <T extends DataEntity<?>> T checkForParameter(T observation, ParameterHolder parameterHolder, ObservationContext ctx, Session session) throws OwsExceptionReport {
if (parameterHolder.isSetParameter()) {
if (parameterHolder.isSetFromToParameter()) {
NamedValue<BigDecimal> fromParameter = parameterHolder.getFromParameter();
NamedValue<BigDecimal> toParameter = parameterHolder.getToParameter();
if (!(observation instanceof ProfileDataEntity)) {
observation.setVerticalFrom(fromParameter.getValue().getValue());
observation.setVerticalTo(toParameter.getValue().getValue());
}
// set vertical metadata
VerticalMetadataEntity verticalMetadata = new VerticalMetadataEntity();
verticalMetadata.setVerticalFromName(fromParameter.getName().getHref());
verticalMetadata.setVerticalToName(toParameter.getName().getHref());
if (fromParameter.getValue().isSetUnit()) {
verticalMetadata.setVerticalUnit(getUnit(fromParameter.getValue().getUnitObject(), caches.units, session));
}
if (parameterHolder.isSetHeightDepthParameter()) {
if (parameterHolder.isSetDepthParameter() && parameterHolder.isSetHeightParameter()) {
verticalMetadata.setOrientation(Integer.valueOf(0).shortValue());
} else if (parameterHolder.isSetDepthParameter()) {
verticalMetadata.setOrientation(Integer.valueOf(-1).shortValue());
} else {
verticalMetadata.setOrientation(Integer.valueOf(1).shortValue());
}
}
ctx.setVertical(verticalMetadata);
parameterHolder.removeParameter(fromParameter);
parameterHolder.removeParameter(toParameter);
} else if (parameterHolder.isSetHeightDepthParameter()) {
NamedValue<BigDecimal> parameter = parameterHolder.getHeightDepthParameter();
VerticalMetadataEntity verticalMetadata = new VerticalMetadataEntity();
if (parameterHolder.isSetDepthParameter()) {
if (!(observation instanceof ProfileDataEntity)) {
observation.setVerticalFrom(parameter.getValue().getValue());
observation.setVerticalTo(parameter.getValue().getValue());
}
verticalMetadata.setOrientation(Integer.valueOf(-1).shortValue());
} else {
if (!(observation instanceof ProfileDataEntity)) {
observation.setVerticalFrom(parameter.getValue().getValue());
observation.setVerticalTo(parameter.getValue().getValue());
}
verticalMetadata.setOrientation(Integer.valueOf(1).shortValue());
}
// set vertical metadata
verticalMetadata.setVerticalFromName(parameter.getName().getHref());
verticalMetadata.setVerticalToName(parameter.getName().getHref());
if (parameter.getValue().isSetUnit()) {
verticalMetadata.setVerticalUnit(getUnit(parameter.getValue().getUnitObject(), caches.units, session));
}
ctx.setVertical(verticalMetadata);
parameterHolder.removeParameter(parameter);
}
if (parameterHolder.isSetParameter()) {
Set<ParameterEntity<?>> insertParameter = daos.parameter().insertParameter(parameterHolder.getParameter(), caches.units, session);
observation.setParameters(insertParameter);
}
}
return observation;
}
use of org.n52.sos.ds.hibernate.dao.observation.ObservationContext in project SOS by 52North.
the class ObservationPersister method persist.
private <V, T extends DataEntity<V>> T persist(T observation, V value) throws OwsExceptionReport {
observation.setDeleted(false);
if (parent == null) {
daos.observation().addIdentifier(omObservation, observation, session, caches.codespaces);
} else {
observation.setParent(parent);
observation.setStaIdentifier(observation.generateUUID());
}
daos.observation().addName(omObservation, observation, session, caches.codespaces);
daos.observation().addDescription(omObservation, observation);
daos.observation().addTime(omObservation, observation);
observation.setValue(value);
if (samplingGeometry != null) {
GeometryEntity geometryEntity = new GeometryEntity();
geometryEntity.setGeometry(samplingGeometry);
observation.setGeometryEntity(geometryEntity);
checkUpdateFeatureOfInterestGeometry();
omObservation.removeSpatialFilteringProfileParameter();
}
ObservationContext observationContext = daos.observation().createObservationContext();
String observationType = ObservationTypeObservationVisitor.getInstance().visit((DataEntity<?>) observation);
observationContext.setObservationType(getObservationType(observationType, session));
if (dataset != null) {
if (!isProfileObservation(dataset) && !isDataArrayObservation(dataset) || isProfileObservation(dataset) && parent == null || isDataArrayObservation(dataset) && parent == null) {
offerings.add(dataset.getOffering());
if (!daos.dataset().checkObservationType(dataset, observationType, session)) {
throw new InvalidParameterValueException().withMessage("The requested observationType (%s) is invalid for procedure = " + "%s, observedProperty = %s and offering = %s! The valid observationType is '%s'!", observationType, observation.getDataset().getProcedure().getIdentifier(), dataset.getObservableProperty().getIdentifier(), dataset.getOffering().getIdentifier(), dataset.getOmObservationType().getFormat());
}
}
observationContext.setPhenomenon(dataset.getObservableProperty());
observationContext.setProcedure(dataset.getProcedure());
observationContext.setOffering(dataset.getOffering());
observationContext.setCategory(dataset.getCategory());
observationContext.setPlatform(dataset.getPlatform());
observationContext.setUnit(dataset.getUnit());
if (!ValueType.not_initialized.equals(dataset.getValueType()) && !observationContext.isSetValueType()) {
observationContext.setValueType(dataset.getValueType());
}
}
// currently only profiles with one observedProperty are supported
if (parent != null && !isProfileObservation(dataset)) {
observationContext.setHiddenChild(true);
}
observationContext.setFeatureOfInterest(featureOfInterest);
if (!observationContext.isSetPlatform()) {
observationContext.setPlatform(daos.platform().getOrInsertPlatform(featureOfInterest, session));
}
daos.observation().fillObservationContext(observationContext, omObservation, session);
checkForParameter(observation, omObservation.getParameterHolder(), observationContext, session);
if (observationContext.isSetVertical()) {
observationContext.setVertical(daos.verticalMetadata().getOrInsertVerticalMetadata(observationContext.getVertical(), session));
}
if (dataset != null && dataset.hasVerticalMetadata()) {
observationContext.setVertical(dataset.getVerticalMetadata());
}
DatasetEntity persitedDataset = daos.observation().addObservationContextToObservation(observationContext, observation, session);
session.save(observation);
session.flush();
session.refresh(observation);
daos.dataset.updateSeriesWithFirstLatestValues(persitedDataset, observation, session);
return observation;
}
use of org.n52.sos.ds.hibernate.dao.observation.ObservationContext in project SOS by 52North.
the class AbstractSeriesObservationDAO method addObservationContextToObservation.
@Override
protected DatasetEntity addObservationContextToObservation(ObservationContext ctx, DataEntity<?> observation, Session session) throws OwsExceptionReport {
AbstractSeriesDAO seriesDAO = getDaoFactory().getSeriesDAO();
DatasetEntity series = seriesDAO.getOrInsertSeries(ctx, observation, session);
((DataEntity) observation).setDataset(series);
OfferingDAO offeringDAO = getDaoFactory().getOfferingDAO();
offeringDAO.updateOfferingMetadata(series.getOffering(), observation, session);
return series;
}
use of org.n52.sos.ds.hibernate.dao.observation.ObservationContext in project SOS by 52North.
the class AbstractSeriesDAO method getOrInsert.
protected DatasetEntity getOrInsert(ObservationContext ctx, DataEntity<?> observation, Session session) throws OwsExceptionReport {
Criteria criteria = getDefaultAllSeriesCriteria(session);
ctx.addIdentifierRestrictionsToCritera(criteria, true, false);
// criteria.setMaxResults(1);
// TODO: check for Unit if available!!!
LOGGER.trace("QUERY getOrInsertSeries(feature, observableProperty, procedure, offering, platform, category): {}", HibernateHelper.getSqlString(criteria));
List<DatasetEntity> datasets = (List<DatasetEntity>) criteria.list();
DatasetEntity series = datasets.isEmpty() ? null : datasets.stream().filter(d -> d.getCategory().equals(ctx.getCategory())).findFirst().orElse(datasets.iterator().next());
if (series == null || series.getDatasetType().equals(DatasetType.not_initialized)) {
series = preCheckDataset(ctx, observation, series, session);
if (series != null && series.isMobile()) {
series.setDatasetType(DatasetType.trajectory);
}
}
if (series == null || series.isSetFeature() && ctx.isSetFeatureOfInterest() && !series.getFeature().getIdentifier().equals(ctx.getFeatureOfInterest().getIdentifier())) {
series = (DatasetEntity) getDatasetFactory().visit(observation);
ctx.addValuesToSeries(series);
series.setDeleted(false);
series.setPublished(ctx.isPublish());
} else if (!series.isSetFeature()) {
ctx.addValuesToSeries(series);
series.setDeleted(false);
series.setPublished(ctx.isPublish());
} else if (!series.hasUnit() && ctx.isSetUnit()) {
series.setUnit(ctx.getUnit());
series.setDeleted(false);
series.setPublished(ctx.isPublish());
} else if (ctx.isPublish() && !series.isPublished()) {
series.setPublished(ctx.isPublish());
} else if (series.isDeleted()) {
series.setDeleted(false);
} else {
return series;
}
session.saveOrUpdate(series);
session.flush();
session.refresh(series);
processSta(series, session);
return series;
}
Aggregations