Search in sources :

Example 11 with FormatEntity

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

the class DatastreamService method checkObservationType.

private void checkObservationType(DatastreamEntity datastream) throws STACRUDException {
    FormatEntity format;
    synchronized (getLock(datastream.getObservationType().getFormat() + "format")) {
        if (!formatRepository.existsByFormat(datastream.getObservationType().getFormat())) {
            format = formatRepository.save(datastream.getObservationType());
        } else {
            format = formatRepository.findByFormat(datastream.getObservationType().getFormat());
        }
    }
    datastream.setObservationType(format);
}
Also used : FormatEntity(org.n52.series.db.beans.FormatEntity)

Example 12 with FormatEntity

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

the class JSONLocation method toEntity.

@Override
public LocationEntity toEntity(JSONBase.EntityType type) {
    GeoJsonReader reader;
    switch(type) {
        case FULL:
            parseReferencedFrom();
            Assert.notNull(name, INVALID_INLINE_ENTITY_MISSING + "name");
            Assert.notNull(description, INVALID_INLINE_ENTITY_MISSING + "description");
            Assert.notNull(encodingType, INVALID_INLINE_ENTITY_MISSING + "encodingType");
            Assert.notNull(encodingType, INVALID_ENCODINGTYPE);
            Assert.isTrue(Objects.equals(encodingType, ENCODINGTYPE_GEOJSON), INVALID_ENCODINGTYPE);
            Assert.notNull(location, INVALID_INLINE_ENTITY_MISSING + "location");
            // TODO: check what is actually allowed here.
            if (location.has(GEOMETRY)) {
                Assert.isTrue("Feature".equals(location.get(TYPE).asText()), INVALID_INLINE_ENTITY_MISSING + LOCATION_TYPE);
                Assert.notNull(location.get(GEOMETRY), INVALID_INLINE_ENTITY_MISSING + LOCATION_GEOM);
            } else {
                Assert.isTrue("Point".equals(location.get(TYPE).asText()), INVALID_INLINE_ENTITY_MISSING + LOCATION_TYPE);
                Assert.notNull(location.get(COORDINATES), INVALID_INLINE_ENTITY_MISSING + LOCATION_GEOM);
            }
            self.setIdentifier(identifier);
            self.setStaIdentifier(identifier);
            self.setName(name);
            self.setDescription(description);
            self.setLocationEncoding(new FormatEntity().setFormat(encodingType));
            reader = new GeoJsonReader(factory);
            try {
                if (location.has(GEOMETRY)) {
                    self.setGeometry(reader.read(location.get(GEOMETRY).toString()));
                } else {
                    self.setGeometry(reader.read(location.toString()));
                }
            } catch (ParseException e) {
                Assert.notNull(null, COULD_NOT_PARSE + e.getMessage());
            }
            if (Things != null) {
                self.setThings(Arrays.stream(Things).map(thing -> thing.toEntity(JSONBase.EntityType.FULL, JSONBase.EntityType.REFERENCE)).collect(Collectors.toSet()));
            }
            if (HistoricalLocations != null) {
                self.setHistoricalLocations(Arrays.stream(HistoricalLocations).map(loc -> loc.toEntity(JSONBase.EntityType.FULL, JSONBase.EntityType.REFERENCE)).collect(Collectors.toSet()));
            }
            if (backReference != null) {
                if (backReference instanceof JSONThing) {
                    if (self.getThings() != null) {
                        self.getThings().add(((JSONThing) backReference).getEntity());
                    } else {
                        self.setThings(Collections.singleton(((JSONThing) backReference).getEntity()));
                    }
                } else {
                    JSONHistoricalLocation backRef = (JSONHistoricalLocation) backReference;
                    self.addHistoricalLocation(backRef.getEntity());
                }
            }
            return self;
        case PATCH:
            parseReferencedFrom();
            self.setIdentifier(identifier);
            self.setStaIdentifier(identifier);
            self.setName(name);
            self.setDescription(description);
            self.setLocationEncoding(new FormatEntity().setFormat(encodingType));
            if (encodingType != null) {
                Assert.state(encodingType.equals(ENCODINGTYPE_GEOJSON), INVALID_ENCODINGTYPE);
            }
            if (location != null) {
                reader = new GeoJsonReader(factory);
                try {
                    if (location.has(GEOMETRY)) {
                        self.setGeometry(reader.read(location.get(GEOMETRY).toString()));
                    } else {
                        self.setGeometry(reader.read(location.toString()));
                    }
                } catch (ParseException e) {
                    Assert.notNull(null, COULD_NOT_PARSE + e.getMessage());
                }
            }
            if (Things != null) {
                self.setThings(Arrays.stream(Things).map(thing -> thing.toEntity(JSONBase.EntityType.REFERENCE)).collect(Collectors.toSet()));
            }
            if (HistoricalLocations != null) {
                self.setHistoricalLocations(Arrays.stream(HistoricalLocations).map(loc -> loc.toEntity(JSONBase.EntityType.REFERENCE)).collect(Collectors.toSet()));
            }
            return self;
        case REFERENCE:
            Assert.isNull(name, INVALID_REFERENCED_ENTITY);
            Assert.isNull(description, INVALID_REFERENCED_ENTITY);
            Assert.isNull(encodingType, INVALID_REFERENCED_ENTITY);
            Assert.isNull(location, INVALID_REFERENCED_ENTITY);
            Assert.isNull(Things, INVALID_REFERENCED_ENTITY);
            self.setIdentifier(identifier);
            self.setStaIdentifier(identifier);
            return self;
        default:
            return null;
    }
}
Also used : GeoJsonReader(org.locationtech.jts.io.geojson.GeoJsonReader) FormatEntity(org.n52.series.db.beans.FormatEntity) ParseException(org.locationtech.jts.io.ParseException)

Example 13 with FormatEntity

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

the class JSONSensor method handleEncodingType.

protected void handleEncodingType() {
    if (encodingType.equalsIgnoreCase(STA_SENSORML_2)) {
        self.setFormat(new FormatEntity().setFormat(SENSORML_2));
        ProcedureHistoryEntity procedureHistoryEntity = new ProcedureHistoryEntity();
        procedureHistoryEntity.setProcedure(self);
        procedureHistoryEntity.setFormat(self.getFormat());
        procedureHistoryEntity.setStartTime(DateTime.now().toDate());
        procedureHistoryEntity.setXml(metadata);
        Set<ProcedureHistoryEntity> set = new LinkedHashSet<>();
        set.add(procedureHistoryEntity);
        self.setProcedureHistory(set);
    } else if (encodingType.equalsIgnoreCase(PDF)) {
        self.setFormat(new FormatEntity().setFormat(PDF));
        self.setDescriptionFile(metadata);
    } else {
        Assert.notNull(null, INALID_ENCODING_TYPE);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ProcedureHistoryEntity(org.n52.series.db.beans.ProcedureHistoryEntity) FormatEntity(org.n52.series.db.beans.FormatEntity)

Example 14 with FormatEntity

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

the class JSONDatastream method createPostEntity.

private DatastreamEntity createPostEntity() {
    self.setIdentifier(identifier);
    self.setStaIdentifier(identifier);
    self.setName(name);
    self.setDescription(description);
    self.setObservationType(new FormatEntity().setFormat(observationType));
    if (observedArea != null) {
        GeoJsonReader reader = new GeoJsonReader(factory);
        try {
            self.setGeometry(reader.read(observedArea.toString()));
        } catch (ParseException e) {
            Assert.notNull(null, COULD_NOT_PARSE_OBS_AREA + e.getMessage());
        }
    }
    if (unitOfMeasurement.name != null) {
        UnitEntity unit = new UnitEntity();
        unit.setLink(unitOfMeasurement.definition);
        unit.setName(unitOfMeasurement.name);
        unit.setSymbol(unitOfMeasurement.symbol);
        self.setUnit(unit);
    }
    if (resultTime != null) {
        Time time = parseTime(resultTime);
        if (time instanceof TimeInstant) {
            self.setResultTimeStart(((TimeInstant) time).getValue().toDate());
            self.setResultTimeEnd(((TimeInstant) time).getValue().toDate());
        } else if (time instanceof TimePeriod) {
            self.setResultTimeStart(((TimePeriod) time).getStart().toDate());
            self.setResultTimeEnd(((TimePeriod) time).getEnd().toDate());
        }
    }
    if (Thing != null) {
        self.setThing(Thing.toEntity(JSONBase.EntityType.FULL, JSONBase.EntityType.REFERENCE));
    } else if (backReference instanceof JSONThing) {
        self.setThing(((JSONThing) backReference).getEntity());
    } else {
        Assert.notNull(null, INVALID_INLINE_ENTITY_MISSING + "Thing");
    }
    if (Sensor != null) {
        self.setProcedure(Sensor.toEntity(JSONBase.EntityType.FULL, JSONBase.EntityType.REFERENCE));
    } else if (backReference instanceof JSONSensor) {
        self.setProcedure(((JSONSensor) backReference).getEntity());
    } else {
        Assert.notNull(null, INVALID_INLINE_ENTITY_MISSING + "Sensor");
    }
    if (ObservedProperty != null) {
        self.setObservableProperty(ObservedProperty.toEntity(JSONBase.EntityType.FULL, JSONBase.EntityType.REFERENCE));
    } else if (backReference instanceof JSONObservedProperty) {
        self.setObservableProperty(((JSONObservedProperty) backReference).getEntity());
    } else {
        Assert.notNull(null, INVALID_INLINE_ENTITY_MISSING + "ObservedProperty");
    }
    if (Observations != null) {
        self.setObservations(Arrays.stream(Observations).map(entity -> entity.toEntity(JSONBase.EntityType.FULL, JSONBase.EntityType.REFERENCE)).collect(Collectors.toSet()));
    } else if (backReference instanceof JSONObservation) {
        self.setObservations(Collections.singleton(((JSONObservation) backReference).self));
    }
    return self;
}
Also used : GeoJsonReader(org.locationtech.jts.io.geojson.GeoJsonReader) FormatEntity(org.n52.series.db.beans.FormatEntity) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) Time(org.n52.shetland.ogc.gml.time.Time) ParseException(org.locationtech.jts.io.ParseException) UnitEntity(org.n52.series.db.beans.UnitEntity) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 15 with FormatEntity

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

the class JSONDatastream method createPatchEntity.

private DatastreamEntity createPatchEntity() {
    self.setIdentifier(identifier);
    self.setStaIdentifier(identifier);
    self.setName(name);
    self.setDescription(description);
    if (observationType != null) {
        self.setObservationType(new FormatEntity().setFormat(observationType));
    }
    if (observedArea != null) {
        GeoJsonReader reader = new GeoJsonReader(factory);
        try {
            self.setGeometry(reader.read(observedArea.toString()));
        } catch (ParseException e) {
            Assert.notNull(null, COULD_NOT_PARSE_OBS_AREA + e.getMessage());
        }
    }
    if (unitOfMeasurement != null) {
        if (unitOfMeasurement.name == null) {
            self.setUnit(null);
        } else {
            UnitEntity unit = new UnitEntity();
            unit.setLink(unitOfMeasurement.definition);
            unit.setName(unitOfMeasurement.name);
            unit.setSymbol(unitOfMeasurement.symbol);
            self.setUnit(unit);
        }
    }
    if (resultTime != null) {
        Time time = parseTime(resultTime);
        if (time instanceof TimeInstant) {
            self.setResultTimeStart(((TimeInstant) time).getValue().toDate());
            self.setResultTimeEnd(((TimeInstant) time).getValue().toDate());
        } else if (time instanceof TimePeriod) {
            self.setResultTimeStart(((TimePeriod) time).getStart().toDate());
            self.setResultTimeEnd(((TimePeriod) time).getEnd().toDate());
        }
    }
    // }
    if (Thing != null) {
        self.setThing(Thing.toEntity(JSONBase.EntityType.REFERENCE));
    }
    if (Sensor != null) {
        self.setProcedure(Sensor.toEntity(JSONBase.EntityType.REFERENCE));
    }
    if (ObservedProperty != null) {
        self.setObservableProperty(ObservedProperty.toEntity(JSONBase.EntityType.REFERENCE));
    }
    if (Observations != null) {
        self.setObservations(Arrays.stream(Observations).map(obs -> obs.toEntity(JSONBase.EntityType.REFERENCE)).collect(Collectors.toSet()));
    }
    return self;
}
Also used : GeoJsonReader(org.locationtech.jts.io.geojson.GeoJsonReader) FormatEntity(org.n52.series.db.beans.FormatEntity) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) Time(org.n52.shetland.ogc.gml.time.Time) ParseException(org.locationtech.jts.io.ParseException) UnitEntity(org.n52.series.db.beans.UnitEntity) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Aggregations

FormatEntity (org.n52.series.db.beans.FormatEntity)24 Session (org.hibernate.Session)7 OfferingEntity (org.n52.series.db.beans.OfferingEntity)7 ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)7 Transaction (org.hibernate.Transaction)6 Criteria (org.hibernate.Criteria)5 HibernateException (org.hibernate.HibernateException)5 UnitEntity (org.n52.series.db.beans.UnitEntity)5 DatasetEntity (org.n52.series.db.beans.DatasetEntity)4 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)4 DateTime (org.joda.time.DateTime)3 ParseException (org.locationtech.jts.io.ParseException)3 GeoJsonReader (org.locationtech.jts.io.geojson.GeoJsonReader)3 AbstractFeatureEntity (org.n52.series.db.beans.AbstractFeatureEntity)3 CategoryEntity (org.n52.series.db.beans.CategoryEntity)3 FeatureEntity (org.n52.series.db.beans.FeatureEntity)3 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)3 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)3 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)3 HashSet (java.util.HashSet)2