Search in sources :

Example 26 with DatasetEntity

use of org.n52.series.db.beans.DatasetEntity in project sensorweb-server-sta by 52North.

the class ObservationService method createEntity.

@Override
public ObservationEntity<?> createEntity(ObservationEntity<?> entity) throws STACRUDException {
    synchronized (getLock(entity.getStaIdentifier())) {
        ObservationEntity observation = entity;
        if (!observation.isProcessed()) {
            observation.setProcessed(true);
            check(observation);
            DatastreamEntity datastream = getDatastreamService().createEntity(observation.getDatastream());
            observation.setDatastream(datastream);
            // Fetch with all needed associations
            datastream = datastreamRepository.findByStaIdentifier(datastream.getStaIdentifier(), EntityGraphRepository.FetchGraph.FETCHGRAPH_THINGLOCATION, EntityGraphRepository.FetchGraph.FETCHGRAPH_PROCEDURE, EntityGraphRepository.FetchGraph.FETCHGRAPH_UOM, EntityGraphRepository.FetchGraph.FETCHGRAPH_OBS_TYPE, EntityGraphRepository.FetchGraph.FETCHGRAPH_OBSERVABLE_PROP, EntityGraphRepository.FetchGraph.FETCHGRAPH_DATASETS).orElseThrow(() -> new STACRUDException("Unable to find Datastream!"));
            AbstractFeatureEntity<?> feature = checkFeature(observation, datastream);
            // category (obdProp)
            CategoryEntity category = checkCategory();
            // offering (sensor)
            OfferingEntity offering = checkOffering(datastream);
            // dataset
            DatasetEntity dataset = checkDataset(datastream, feature, category, offering);
            // observation
            ObservationEntity<?> data = checkData(observation, dataset);
            if (data != null) {
                updateDataset(dataset, data);
                updateDatastream(datastream, dataset, data);
            }
            return data;
        }
        return observation;
    }
}
Also used : DatasetEntity(org.n52.series.db.beans.DatasetEntity) DatastreamEntity(org.n52.series.db.beans.sta.DatastreamEntity) CategoryObservationEntity(org.n52.series.db.beans.sta.CategoryObservationEntity) QuantityObservationEntity(org.n52.series.db.beans.sta.QuantityObservationEntity) TextObservationEntity(org.n52.series.db.beans.sta.TextObservationEntity) BooleanObservationEntity(org.n52.series.db.beans.sta.BooleanObservationEntity) ObservationEntity(org.n52.series.db.beans.sta.ObservationEntity) CountObservationEntity(org.n52.series.db.beans.sta.CountObservationEntity) OfferingEntity(org.n52.series.db.beans.OfferingEntity) STACRUDException(org.n52.shetland.ogc.sta.exception.STACRUDException) CategoryEntity(org.n52.series.db.beans.CategoryEntity)

Example 27 with DatasetEntity

use of org.n52.series.db.beans.DatasetEntity in project sensorweb-server-sta by 52North.

the class DatastreamService method processObservation.

private DatastreamEntity processObservation(DatastreamEntity datastream, Set<AbstractObservationEntity> observations) throws STACRUDException {
    if (observations != null && !observations.isEmpty()) {
        Set<DatasetEntity> datasets = new LinkedHashSet<>();
        if (datastream.getDatasets() != null) {
            datasets.addAll(datastream.getDatasets());
        }
        for (AbstractObservationEntity observation : observations) {
            AbstractObservationEntity<?> data = getObservationService().createEntity(observation);
            if (data != null) {
                datasets.add(data.getDataset());
            }
        }
        datastream.setDatasets(datasets);
    }
    return datastream;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AbstractObservationEntity(org.n52.series.db.beans.sta.AbstractObservationEntity) DatasetEntity(org.n52.series.db.beans.DatasetEntity)

Example 28 with DatasetEntity

use of org.n52.series.db.beans.DatasetEntity in project sensorweb-server-sta by 52North.

the class DatastreamQuerySpecifications method handleRelatedPropertyFilter.

/**
 * Handles filtering of properties in related Entities.
 *
 * @param propertyName  Name of property
 * @param propertyValue Supposed value of Property
 * @return BooleanExpression evaluating to true if Entity is not filtered out
 */
@Override
protected Specification<DatastreamEntity> handleRelatedPropertyFilter(String propertyName, Specification<?> propertyValue) {
    return (root, query, builder) -> {
        try {
            switch(propertyName) {
                case SENSOR:
                    {
                        Subquery<DatastreamEntity> sq = query.subquery(DatastreamEntity.class);
                        Root<ProcedureEntity> sensor = sq.from(ProcedureEntity.class);
                        sq.select(sensor.get(DescribableEntity.PROPERTY_ID)).where(((Specification<ProcedureEntity>) propertyValue).toPredicate(sensor, query, builder));
                        return builder.in(root.get(DatastreamEntity.PROPERTY_SENSOR)).value(sq);
                    }
                case OBSERVED_PROPERTY:
                    {
                        Subquery<DatastreamEntity> sq = query.subquery(DatastreamEntity.class);
                        Root<PhenomenonEntity> observedProperty = sq.from(PhenomenonEntity.class);
                        sq.select(observedProperty.get(DescribableEntity.PROPERTY_ID)).where(((Specification<PhenomenonEntity>) propertyValue).toPredicate(observedProperty, query, builder));
                        return builder.in(root.get(DatastreamEntity.PROPERTY_OBSERVABLE_PROPERTY)).value(sq);
                    }
                case THING:
                    {
                        Subquery<DatastreamEntity> sq = query.subquery(DatastreamEntity.class);
                        Root<PlatformEntity> thing = sq.from(PlatformEntity.class);
                        sq.select(thing.get(DescribableEntity.PROPERTY_ID)).where(((Specification<PlatformEntity>) propertyValue).toPredicate(thing, query, builder));
                        return builder.in(root.get(DatastreamEntity.PROPERTY_THING)).value(sq);
                    }
                case OBSERVATIONS:
                    {
                        Subquery<DatasetEntity> sq = query.subquery(DatasetEntity.class);
                        Join<DatastreamEntity, DatasetEntity> join = root.join(DatastreamEntity.PROPERTY_DATASETS);
                        Root<ObservationEntity> data = sq.from(ObservationEntity.class);
                        sq.select(data.get(ObservationEntity.PROPERTY_DATASET)).where(((Specification<ObservationEntity>) propertyValue).toPredicate(data, query, builder));
                        return builder.in(join.get(DatasetEntity.PROPERTY_ID)).value(sq);
                    }
                default:
                    throw new STAInvalidFilterExpressionException("Could not find related property: " + propertyName);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    };
}
Also used : Join(javax.persistence.criteria.Join) DatastreamEntity(org.n52.series.db.beans.sta.DatastreamEntity) STAInvalidFilterExpressionException(org.n52.shetland.ogc.sta.exception.STAInvalidFilterExpressionException) Collection(java.util.Collection) DatasetEntity(org.n52.series.db.beans.DatasetEntity) FormatEntity(org.n52.series.db.beans.FormatEntity) DescribableEntity(org.n52.series.db.beans.DescribableEntity) Specification(org.springframework.data.jpa.domain.Specification) PhenomenonEntity(org.n52.series.db.beans.PhenomenonEntity) ObservationEntity(org.n52.series.db.beans.sta.ObservationEntity) FilterConstants(org.n52.shetland.ogc.filter.FilterConstants) JoinType(javax.persistence.criteria.JoinType) Subquery(javax.persistence.criteria.Subquery) PlatformEntity(org.n52.series.db.beans.PlatformEntity) Expression(javax.persistence.criteria.Expression) ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) Root(javax.persistence.criteria.Root) DatasetEntity(org.n52.series.db.beans.DatasetEntity) DatastreamEntity(org.n52.series.db.beans.sta.DatastreamEntity) PhenomenonEntity(org.n52.series.db.beans.PhenomenonEntity) ObservationEntity(org.n52.series.db.beans.sta.ObservationEntity) STAInvalidFilterExpressionException(org.n52.shetland.ogc.sta.exception.STAInvalidFilterExpressionException) ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) PlatformEntity(org.n52.series.db.beans.PlatformEntity) STAInvalidFilterExpressionException(org.n52.shetland.ogc.sta.exception.STAInvalidFilterExpressionException)

Example 29 with DatasetEntity

use of org.n52.series.db.beans.DatasetEntity in project SOS by 52North.

the class ObservationOmObservationCreator method createObservationConstellation.

private OmObservationConstellation createObservationConstellation(DataEntity<?> hObservation, String procedureId, String phenomenonId, String featureId, Set<String> offerings) throws OwsExceptionReport {
    long start = System.currentTimeMillis();
    LOGGER.trace("Creating ObservationConstellation...");
    OmObservationConstellation obsConst = new OmObservationConstellation(getProcedure(procedureId), getObservedProperty(phenomenonId), getFeature(featureId), offerings);
    if (observationConstellations.containsKey(obsConst.hashCode())) {
        obsConst = observationConstellations.get(obsConst.hashCode());
    }
    int hashCode = obsConst.hashCode();
    if (!Strings.isNullOrEmpty(getResultModel())) {
        obsConst.setObservationType(getResultModel());
    }
    if (hObservation.getDataset().isSetOmObservationType()) {
        obsConst.setObservationType(hObservation.getDataset().getOmObservationType().getFormat());
    }
    observationConstellations.put(hashCode, obsConst);
    DatasetEntity series = hObservation.getDataset();
    if (series.isSetIdentifier()) {
        addIdentifier(obsConst, series);
    }
    obsConst.setObservationType(getResultModel());
    if (request.isSetRequestedLanguage()) {
        addNameAndDescription(series, obsConst, getRequestedLanguage(), getI18N(), false);
        if (obsConst.isSetName()) {
            obsConst.setHumanReadableIdentifier(obsConst.getFirstName().getValue());
        }
    } else {
        if (series.isSetName()) {
            addName(obsConst, series);
        }
        if (series.isSetDescription()) {
            obsConst.setDescription(series.getDescription());
        }
    }
    LOGGER.trace("Creating ObservationConstellation done in {} ms.", System.currentTimeMillis() - start);
    return obsConst;
}
Also used : DatasetEntity(org.n52.series.db.beans.DatasetEntity) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation)

Example 30 with DatasetEntity

use of org.n52.series.db.beans.DatasetEntity in project SOS by 52North.

the class ObservationOmObservationCreator method addParameter.

private void addParameter(OmObservation observation, DataEntity<?> hObservation) throws OwsExceptionReport {
    long start = System.currentTimeMillis();
    LOGGER.trace("Creating Parameter...");
    DatasetEntity series = ((DataEntity<?>) hObservation).getDataset();
    if (!seriesParameter.containsKey(series.getId()) && series.hasParameters()) {
        seriesParameter.put(series.getId(), series.getParameters());
    }
    if (seriesParameter.get(series.getId()) != null && !seriesParameter.get(series.getId()).isEmpty()) {
        new DatasetParameterAdder(observation, seriesParameter.get(series.getId())).add();
    }
    new ParameterAdder(observation, hObservation).add();
    LOGGER.trace("Creating Parameter done in {} ms.", System.currentTimeMillis() - start);
}
Also used : DatasetEntity(org.n52.series.db.beans.DatasetEntity) DataEntity(org.n52.series.db.beans.DataEntity)

Aggregations

DatasetEntity (org.n52.series.db.beans.DatasetEntity)49 Criteria (org.hibernate.Criteria)21 DataEntity (org.n52.series.db.beans.DataEntity)13 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)13 ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)11 Session (org.hibernate.Session)10 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)10 OfferingEntity (org.n52.series.db.beans.OfferingEntity)9 HashSet (java.util.HashSet)8 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)8 LinkedHashSet (java.util.LinkedHashSet)7 Set (java.util.Set)7 HibernateException (org.hibernate.HibernateException)7 FormatEntity (org.n52.series.db.beans.FormatEntity)7 DatastreamEntity (org.n52.series.db.beans.sta.DatastreamEntity)7 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)7 Collection (java.util.Collection)6 LinkedList (java.util.LinkedList)6 AbstractFeatureEntity (org.n52.series.db.beans.AbstractFeatureEntity)6 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)6