use of org.n52.sos.ds.hibernate.util.observation.ObservationValueCreator in project SOS by 52North.
the class ResultHandlingHelper method createObservedPropertyField.
private List<SweField> createObservedPropertyField(DataEntity<?> observation) throws OwsExceptionReport {
List<SweField> fields = new LinkedList<>();
PhenomenonEntity phenomenon = observation.getDataset().getPhenomenon();
if (observation.getDataset().getDatasetType().equals(DatasetType.profile) || observation.getDataset().getObservationType().equals(ObservationType.profile)) {
ProfileValue profile = (ProfileValue) new ObservationValueCreator(decoderRepository).visit(observation);
ProfileLevel level = profile.getValue().get(0);
fields.add(createVerticalParameter(level));
if (level.getValue().get(0) instanceof SweAbstractDataComponent) {
if (level.getValue().size() > 1) {
SweDataRecord record = new SweDataRecord();
for (Value<?> v : level.getValue()) {
SweAbstractDataComponent dc = (SweAbstractDataComponent) v;
record.addField(new SweField(NcName.makeValid(dc.getDefinition()), dc));
}
fields.add(new SweField(getNcNameName(phenomenon), record));
return fields;
} else {
SweAbstractDataComponent swe = (SweAbstractDataComponent) level.getValue().get(0).setValue(null);
swe.setDefinition(phenomenon.getIdentifier());
fields.add(new SweField(getNcNameName(phenomenon), swe));
return fields;
}
}
} else {
SweAbstractDataComponent value = new SweAbstractDataComponentCreator(decoderRepository, true).visit(observation);
fields.add(new SweField(getNcNameName(phenomenon), (SweAbstractDataComponent) value));
return fields;
}
throw new NoApplicableCodeException();
}
use of org.n52.sos.ds.hibernate.util.observation.ObservationValueCreator in project SOS by 52North.
the class ObservationOmObservationCreator method createObservation.
protected OmObservation createObservation(DataEntity<?> hObservation) throws OwsExceptionReport, ConverterException {
long start = System.currentTimeMillis();
LOGGER.trace("Creating Observation...");
SosHelper.checkFreeMemory();
String procedureId = createProcedure(hObservation);
String featureId = createFeatureOfInterest(hObservation);
String phenomenonId = createPhenomenon(hObservation);
Set<String> offerings = createOfferingSet(hObservation, procedureId, phenomenonId);
final Value<?> value = new ObservationValueCreator(getCreatorContext().getDecoderRepository()).visit(unproxy(hObservation, getSession()));
OmObservation sosObservation = null;
if (value != null) {
value.setUnit(queryUnit(hObservation.getDataset()));
checkOrSetObservablePropertyUnit(getObservedProperty(phenomenonId), value.getUnit());
OmObservationConstellation obsConst = createObservationConstellation(hObservation, procedureId, phenomenonId, featureId, offerings);
sosObservation = createNewObservation(obsConst, hObservation, value);
// add SpatialFilteringProfile
if (hObservation.isSetGeometryEntity()) {
sosObservation.addSpatialFilteringProfileParameter(getGeometryHandler().switchCoordinateAxisFromToDatasourceIfNeeded(hObservation.getGeometryEntity().getGeometry()));
}
addRelatedObservations(sosObservation, hObservation);
addParameter(sosObservation, hObservation);
checkForAdditionalObservationCreator(hObservation, sosObservation);
// + setFirstResult
if (!value.isSetValue() && hObservation.hasDetectionLimit()) {
sosObservation.addParameter(createDetectionLimit(hObservation.getDetectionLimit(), value.getUnitObject()));
}
}
getSession().evict(hObservation);
LOGGER.trace("Creating Observation done in {} ms.", System.currentTimeMillis() - start);
return sosObservation;
}
use of org.n52.sos.ds.hibernate.util.observation.ObservationValueCreator in project SOS by 52North.
the class AbstractHibernateStreamingValue method addValuesToObservation.
/**
* Add {@code DataEntity} data to {@code OmObservation}
*
* @param observation
* {@link OmObservation} to add data
* @param responseFormat
*
* @throws OwsExceptionReport
* If an error occurs when getting the value
*/
public OmObservation addValuesToObservation(DataEntity<?> o, OmObservation observation, String responseFormat) throws OwsExceptionReport {
observation.setObservationID(Long.toString(o.getId()));
if (!observation.isSetIdentifier() && o.isSetIdentifier()) {
CodeWithAuthority identifier = new CodeWithAuthority(o.getIdentifier());
if (o.isSetIdentifierCodespace()) {
identifier.setCodeSpace(o.getIdentifierCodespace().getName());
}
observation.setIdentifier(identifier);
}
if (!observation.isSetName() && o.isSetName()) {
CodeType name = new CodeType(o.getName());
if (o.isSetNameCodespace()) {
try {
name.setCodeSpace(new URI(o.getNameCodespace().getName()));
} catch (URISyntaxException e) {
throw new NoApplicableCodeException().causedBy(e).withMessage("Invalid codespace value: {}", o.getNameCodespace().getName());
}
}
observation.setName(name);
}
if (!observation.isSetDescription() && o.isSetDescription()) {
observation.setDescription(o.getDescription());
}
Value<?> value = new ObservationValueCreator(daoFactory.getDecoderRepository()).visit(o);
if (!value.isSetUnit() && observation.getObservationConstellation().getObservableProperty() instanceof OmObservableProperty && ((OmObservableProperty) observation.getObservationConstellation().getObservableProperty()).isSetUnit()) {
value.setUnit(((OmObservableProperty) observation.getObservationConstellation().getObservableProperty()).getUnit());
}
if (!value.isSetValue() && o.hasDetectionLimit()) {
observation.addParameter(createDetectionLimit(o.getDetectionLimit(), value.getUnitObject()));
}
if (!observation.getObservationConstellation().isSetObservationType()) {
observation.getObservationConstellation().setObservationType(OMHelper.getObservationTypeFor(value));
}
observation.setResultTime(createResutlTime(o.getResultTime()));
observation.setValidTime(createValidTime(o.getValidTimeStart(), o.getValidTimeEnd()));
if (o.isSetGeometryEntity()) {
observation.addParameter(spatialFilteringProfileCreator.create(o.getGeometryEntity().getGeometry()));
}
if (o.getDataset().hasVerticalMetadata()) {
VerticalMetadataEntity verticalMetadata = o.getDataset().getVerticalMetadata();
if (o.hasVerticalInterval()) {
observation.addParameter(createParameter(getVerticalFromName(verticalMetadata), o.getVerticalFrom(), verticalMetadata.getVerticalUnit()));
observation.addParameter(createParameter(getVerticalToName(verticalMetadata), o.getVerticalTo(), verticalMetadata.getVerticalUnit()));
} else {
observation.addParameter(createParameter(getVerticalFromName(verticalMetadata), o.getVerticalFrom(), verticalMetadata.getVerticalUnit()));
}
}
addRelatedObservation(o, observation);
addParameter(o, observation);
addValueSpecificDataToObservation(o, observation, responseFormat);
addObservationValueToObservation(o, observation, value, responseFormat);
return observation;
}
use of org.n52.sos.ds.hibernate.util.observation.ObservationValueCreator in project SOS by 52North.
the class AbstractHibernateStreamingValue method mergeValueToObservation.
public OmObservation mergeValueToObservation(DataEntity<?> o, OmObservation observation, String responseFormat) throws OwsExceptionReport {
if (checkResponseFormat(responseFormat) && o.hasEreportingProfile()) {
if (!observation.isSetValue()) {
addValuesToObservation(o, observation, responseFormat);
} else {
checkTime(o, observation);
helper.mergeValues((SweDataArray) observation.getValue().getValue().getValue(), helper.createSweDataArray(observation, o));
}
if (!OmConstants.OBS_TYPE_SWE_ARRAY_OBSERVATION.equals(observation.getObservationConstellation().getObservationType())) {
observation.getObservationConstellation().setObservationType(OmConstants.OBS_TYPE_SWE_ARRAY_OBSERVATION);
}
} else {
if (!observation.isSetValue()) {
addValuesToObservation(o, observation, responseFormat);
} else {
// TODO
if (!OmConstants.OBS_TYPE_SWE_ARRAY_OBSERVATION.equals(observation.getObservationConstellation().getObservationType())) {
observation.getObservationConstellation().setObservationType(OmConstants.OBS_TYPE_SWE_ARRAY_OBSERVATION);
}
observation.mergeWithObservation(getSingleObservationValue(o, new ObservationValueCreator(daoFactory.getDecoderRepository()).visit(o)));
}
}
return observation;
}
Aggregations