Search in sources :

Example 1 with ObservationValueCreator

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();
}
Also used : SweField(org.n52.shetland.ogc.swe.SweField) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) ProfileLevel(org.n52.shetland.ogc.om.values.ProfileLevel) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) ObservationValueCreator(org.n52.sos.ds.hibernate.util.observation.ObservationValueCreator) SweAbstractDataComponentCreator(org.n52.sos.ds.hibernate.util.observation.SweAbstractDataComponentCreator) PhenomenonEntity(org.n52.series.db.beans.PhenomenonEntity) LinkedList(java.util.LinkedList) ProfileValue(org.n52.shetland.ogc.om.values.ProfileValue)

Example 2 with ObservationValueCreator

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;
}
Also used : OmObservation(org.n52.shetland.ogc.om.OmObservation) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation)

Example 3 with ObservationValueCreator

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;
}
Also used : VerticalMetadataEntity(org.n52.series.db.beans.VerticalMetadataEntity) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) CodeType(org.n52.shetland.ogc.gml.CodeType) ObservationValueCreator(org.n52.sos.ds.hibernate.util.observation.ObservationValueCreator) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty)

Example 4 with ObservationValueCreator

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;
}
Also used : ObservationValueCreator(org.n52.sos.ds.hibernate.util.observation.ObservationValueCreator)

Aggregations

ObservationValueCreator (org.n52.sos.ds.hibernate.util.observation.ObservationValueCreator)3 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 LinkedList (java.util.LinkedList)1 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)1 VerticalMetadataEntity (org.n52.series.db.beans.VerticalMetadataEntity)1 CodeType (org.n52.shetland.ogc.gml.CodeType)1 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)1 OmObservableProperty (org.n52.shetland.ogc.om.OmObservableProperty)1 OmObservation (org.n52.shetland.ogc.om.OmObservation)1 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)1 ProfileLevel (org.n52.shetland.ogc.om.values.ProfileLevel)1 ProfileValue (org.n52.shetland.ogc.om.values.ProfileValue)1 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)1 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)1 SweField (org.n52.shetland.ogc.swe.SweField)1 SweAbstractDataComponentCreator (org.n52.sos.ds.hibernate.util.observation.SweAbstractDataComponentCreator)1