use of org.n52.series.db.beans.AbstractFeatureEntity in project SOS by 52North.
the class GetFeatureOfInterestHandler method createFeature.
private AbstractFeature createFeature(AbstractFeatureEntity feature) throws InvalidSridException, OwsExceptionReport {
final SamplingFeature sampFeat = new SamplingFeature(new CodeWithAuthority(feature.getIdentifier()));
if (feature.isSetName()) {
sampFeat.addName(feature.getName());
}
if (!Strings.isNullOrEmpty(feature.getDescription())) {
sampFeat.setDescription(feature.getDescription());
}
if (feature.isSetGeometry() && !feature.getGeometryEntity().isEmpty()) {
sampFeat.setGeometry(getGeometryHandler().switchCoordinateAxisFromToDatasourceIfNeeded(feature.getGeometryEntity().getGeometry()));
}
final Set<FeatureEntity> parentFeatures = feature.getParents();
if (parentFeatures != null && !parentFeatures.isEmpty()) {
final List<AbstractFeature> sampledFeatures = new ArrayList<>(parentFeatures.size());
for (final FeatureEntity parentFeature : parentFeatures) {
sampledFeatures.add(createFeature(parentFeature));
}
sampFeat.setSampledFeatures(sampledFeatures);
}
return sampFeat;
}
use of org.n52.series.db.beans.AbstractFeatureEntity in project SOS by 52North.
the class ResultTemplateDAO method checkOrInsertResultTemplate.
/**
* Check or insert result template
*
* @param request
* Insert result template request
* @param dataset
* Observation constellation object
* @param procedure
* the procedure
* @param featureOfInterest
* FeatureOfInterest object
* @param session
* Hibernate session
* @return created or exiting {@link ResultTemplateEntity}
* @throws OwsExceptionReport
* If the requested structure/encoding is invalid
*/
public ResultTemplateEntity checkOrInsertResultTemplate(InsertResultTemplateRequest request, DatasetEntity dataset, ProcedureEntity procedure, AbstractFeatureEntity featureOfInterest, Session session) throws OwsExceptionReport {
try {
String offering = dataset.getOffering().getIdentifier();
String observableProperty = dataset.getObservableProperty().getIdentifier();
List<ResultTemplateEntity> resultTemplates = getResultTemplateObject(offering, observableProperty, null, session);
if (CollectionHelper.isEmpty(resultTemplates)) {
return createAndSaveResultTemplate(request, dataset, procedure, featureOfInterest, session);
} else {
List<String> storedIdentifiers = new ArrayList<>(0);
for (ResultTemplateEntity storedResultTemplate : resultTemplates) {
storedIdentifiers.add(storedResultTemplate.getIdentifier());
SosResultStructure storedStructure = createSosResultStructure(storedResultTemplate.getStructure());
SosResultEncoding storedEncoding = createSosResultEncoding(storedResultTemplate.getEncoding());
SosResultStructure storedObservationStructure = createSosResultStructure(storedResultTemplate.getObservationStructure());
SosResultEncoding storedObservationEncoding = createSosResultEncoding(storedResultTemplate.getObservationEncoding());
if (request instanceof InternalInsertResultTemplateRequest) {
((InternalInsertResultTemplateRequest) request).getObservationStructure().clearXml();
((InternalInsertResultTemplateRequest) request).getObservationEncoding().clearXml();
if (storedObservationStructure != null && !storedObservationStructure.equals(((InternalInsertResultTemplateRequest) request).getObservationStructure())) {
throw new InvalidParameterValueException().at(Sos2Constants.InsertResultTemplateParams.proposedTemplate).withMessage(LOG_TEMPLATE, procedure.getIdentifier(), observableProperty, offering);
}
if (storedObservationEncoding != null && !storedObservationEncoding.equals(((InternalInsertResultTemplateRequest) request).getObservationEncoding())) {
throw new InvalidParameterValueException().at(Sos2Constants.InsertResultTemplateParams.proposedTemplate).withMessage(LOG_TEMPLATE, procedure.getIdentifier(), observableProperty, offering);
}
} else {
if (storedStructure != null && !storedStructure.equals(request.getResultStructure())) {
throw new InvalidParameterValueException().at(Sos2Constants.InsertResultTemplateParams.proposedTemplate).withMessage(LOG_TEMPLATE, procedure.getIdentifier(), observableProperty, offering);
}
if (storedEncoding != null && !storedEncoding.equals(request.getResultEncoding())) {
throw new InvalidParameterValueException().at(Sos2Constants.InsertResultTemplateParams.proposedTemplate).withMessage(LOG_TEMPLATE, procedure.getIdentifier(), observableProperty, offering);
}
}
}
if (request.getIdentifier() != null && request.getIdentifier().isSetValue()) {
if (!resultTemplates.isEmpty() && request instanceof InternalInsertResultTemplateRequest && request.getIdentifier().getValue().startsWith("OBS_")) {
updateTemplates(resultTemplates, (InternalInsertResultTemplateRequest) request, session);
return resultTemplates.iterator().next();
}
if (!storedIdentifiers.contains(request.getIdentifier().getValue())) {
/* save it only if the identifier is different */
return createAndSaveResultTemplate(request, dataset, procedure, featureOfInterest, session);
}
}
return resultTemplates.iterator().next();
}
} catch (EncodingException | DecodingException ex) {
throw new NoApplicableCodeException().causedBy(ex);
}
}
use of org.n52.series.db.beans.AbstractFeatureEntity in project sensorweb-server-sta by 52North.
the class ServiceUtils method createFeatureOfInterest.
static AbstractFeatureEntity<?> createFeatureOfInterest(LocationEntity location) {
FeatureEntity featureOfInterest = new FeatureEntity();
featureOfInterest.setIdentifier(location.getIdentifier());
featureOfInterest.setStaIdentifier(location.getStaIdentifier());
// Used to distinguish in FeatureOfInterestService
featureOfInterest.setXml("autogenerated");
featureOfInterest.setName(location.getName());
featureOfInterest.setDescription(location.getDescription());
featureOfInterest.setGeometryEntity(location.getGeometryEntity());
featureOfInterest.setFeatureType(createFeatureType(location.getGeometry()));
return featureOfInterest;
}
use of org.n52.series.db.beans.AbstractFeatureEntity 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;
}
}
use of org.n52.series.db.beans.AbstractFeatureEntity in project sensorweb-server-sta by 52North.
the class FeatureOfInterestService method updateFeatureOfInterestGeometry.
/**
* Extends the geometry of the FOI with given id by geom. Used for automatically expanding FOIs e.g. for
* Observations along a track.
* Used for non-standard feature 'updateFOI'.
*
* @param id id of the FOI
* @param geom geom to expand the existing Geometry
* @throws STACRUDException if an error occurred
*/
public void updateFeatureOfInterestGeometry(String id, Geometry geom) throws STACRUDException {
synchronized (getLock(id)) {
Optional<AbstractFeatureEntity<?>> existing = getRepository().findByStaIdentifier(id, EntityGraphRepository.FetchGraph.FETCHGRAPH_FEATURETYPE);
if (existing.isPresent()) {
AbstractFeatureEntity<?> featureOfInterest = existing.get();
if (featureOfInterest.isSetGeometry()) {
if (geom instanceof Point) {
List<Coordinate> coords = new ArrayList<>();
Geometry convert = featureOfInterest.getGeometry();
if (convert instanceof Point) {
coords.add(convert.getCoordinate());
} else if (convert instanceof LineString || convert instanceof GeometryCollection) {
coords.addAll(Arrays.asList(convert.getCoordinates()));
} else {
LOGGER.error("Could not update FOI geometry. Unknown GeometryType." + convert.getClass().getSimpleName());
throw new STACRUDException("Could not update FeatureOfInterest. Unknown GeometryType:" + convert.getClass().getSimpleName());
}
Geometry newGeometry;
if (!coords.isEmpty()) {
coords.add(geom.getCoordinate());
newGeometry = new GeometryFactory().createLineString(coords.toArray(new Coordinate[coords.size()]));
} else {
newGeometry = new GeometryFactory().createPoint(geom.getCoordinate());
}
newGeometry.setSRID(featureOfInterest.getGeometry().getSRID());
featureOfInterest.setGeometry(newGeometry);
}
} else {
featureOfInterest.setGeometry(geom);
}
getRepository().save(featureOfInterest);
} else {
throw new STACRUDException("Could not update FeatureOfInterest. No FeatureOfInterest with id \"" + id + "\" found!");
}
}
}
Aggregations