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);
}
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;
}
}
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);
}
}
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;
}
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;
}
Aggregations