use of org.n52.series.db.beans.AbstractFeatureEntity in project SOS by 52North.
the class FeatureOfInterestDAO method checkOrInsert.
/**
* Insert featureOfInterest if it is supported
*
* @param featureOfInterest
* SOS featureOfInterest to insert
* @param session
* Hibernate session
* @return FeatureOfInterest object
* @throws NoApplicableCodeException
* If SOS feature type is not supported (with status
* {@link HTTPStatus}.BAD_REQUEST
*/
public AbstractFeatureEntity checkOrInsert(AbstractFeature featureOfInterest, Session session) throws OwsExceptionReport {
if (featureOfInterest == null) {
throw new NoApplicableCodeException().withMessage("The feature to check or insert is null.");
}
AbstractFeatureEntity<?> feature = getFeature(featureOfInterest.getIdentifier(), session);
if (feature != null) {
return feature;
}
if (featureOfInterest instanceof AbstractSamplingFeature) {
AbstractSamplingFeature sf = (AbstractSamplingFeature) featureOfInterest;
String featureIdentifier = getFeatureQueryHandler().insertFeature(sf, session);
return getFeature(featureIdentifier, session);
} else {
throw new NoApplicableCodeException().withMessage("The used feature type '%s' is not supported.", featureOfInterest.getClass().getName()).setStatus(HTTPStatus.BAD_REQUEST);
}
}
use of org.n52.series.db.beans.AbstractFeatureEntity in project SOS by 52North.
the class FeatureOfInterestDAO method getOrInsert.
/**
* Insert and/or get featureOfInterest object for identifier
*
* @param identifier
* FeatureOfInterest identifier
* @param url
* FeatureOfInterest URL, if defined as link
* @param session
* Hibernate session
* @return FeatureOfInterest object
*/
public AbstractFeatureEntity getOrInsert(String identifier, String url, Session session) {
AbstractFeatureEntity feature = get(identifier, session);
if (feature == null) {
feature = new FeatureEntity();
feature.setIdentifier(identifier, getDaoFactory().isStaSupportsUrls());
if (url != null && !url.isEmpty()) {
feature.setUrl(url);
}
FormatEntity type = new FormatDAO().getOrInsertFormatEntity(OGCConstants.UNKNOWN, session);
feature.setFeatureType(type);
session.save(feature);
} else if (feature.getUrl() != null && !feature.getUrl().isEmpty() && url != null && !url.isEmpty()) {
feature.setUrl(url);
session.saveOrUpdate(feature);
}
// don't flush here because we may be batching
return feature;
}
use of org.n52.series.db.beans.AbstractFeatureEntity in project SOS by 52North.
the class FeatureOfInterestDAO method updateFeatureOfInterestGeometry.
public void updateFeatureOfInterestGeometry(AbstractFeatureEntity featureOfInterest, Geometry geom, Session session) {
if (featureOfInterest != null) {
if (featureOfInterest.isSetGeometry()) {
if (geom instanceof Point) {
List<Coordinate> coords = Lists.newArrayList();
Geometry convert = featureOfInterest.getGeometry();
if (convert instanceof Point) {
coords.add(convert.getCoordinate());
} else if (convert instanceof LineString) {
coords.addAll(Lists.newArrayList(convert.getCoordinates()));
}
if (!coords.isEmpty()) {
coords.add(geom.getCoordinate());
Geometry newGeometry = new GeometryFactory().createLineString(coords.toArray(new Coordinate[coords.size()]));
newGeometry.setSRID(featureOfInterest.getGeometry().getSRID());
featureOfInterest.setGeometry(newGeometry);
}
}
} else {
featureOfInterest.setGeometry(geom);
}
session.merge(featureOfInterest);
}
}
use of org.n52.series.db.beans.AbstractFeatureEntity in project SOS by 52North.
the class InsertObservationHandler method insertObservation.
private void insertObservation(OmObservation sosObservation, InsertObservationCache cache, CompositeOwsException exceptions, Session session) throws OwsExceptionReport, CodedException {
checkSpatialFilteringProfile(sosObservation);
OmObservationConstellation sosObsConst = sosObservation.getObservationConstellation();
cache.addOfferings(sosObsConst.getOfferings());
AbstractFeatureEntity hFeature = null;
// if (sosObsConst.getOfferings().size() > 1) {
//
// }
String offeringID = sosObsConst.getOfferings().iterator().next();
DatasetEntity hDataset = cache.get(sosObsConst, offeringID);
if (hDataset == null) {
if (!cache.isChecked(sosObsConst, offeringID)) {
try {
hDataset = getDaoFactory().getSeriesDAO().checkSeries(sosObsConst, offeringID, session, Sos2Constants.InsertObservationParams.observationType.name());
// add to cache table
cache.putConstellation(sosObsConst, offeringID, hDataset);
} catch (OwsExceptionReport owse) {
exceptions.add(owse);
}
// mark as checked
cache.checkConstellation(sosObsConst, offeringID);
}
}
if (hDataset != null) {
// getFeature feature from local cache or create if necessary
hFeature = getFeature(sosObsConst.getFeatureOfInterest(), cache, session);
// AbstractFeature/offering combo
if (!cache.isChecked(sosObsConst.getFeatureOfInterest(), offeringID)) {
getDaoFactory().getFeatureOfInterestDAO().checkOrInsertRelatedFeatureRelation(hFeature, hDataset.getOffering(), session);
cache.checkFeature(sosObsConst.getFeatureOfInterest(), offeringID);
}
AbstractObservationDAO observationDAO = getDaoFactory().getObservationDAO();
DatasetEntity dataset = null;
if (sosObservation.getValue() instanceof SingleObservationValue) {
dataset = observationDAO.insertObservationSingleValue(hDataset, hFeature, sosObservation, cache.getCodespaceCache(), cache.getUnitCache(), cache.getFormatCache(), session);
} else if (sosObservation.getValue() instanceof MultiObservationValues) {
dataset = observationDAO.insertObservationMultiValue(hDataset, hFeature, sosObservation, cache.getCodespaceCache(), cache.getUnitCache(), cache.getFormatCache(), session);
}
if (dataset != null && !cache.get(sosObsConst, offeringID).equals(dataset)) {
cache.putConstellation(sosObsConst, offeringID, dataset);
}
}
}
use of org.n52.series.db.beans.AbstractFeatureEntity in project SOS by 52North.
the class AbstractFeatureOfInerestCreator method createFeature.
public AbstractFeature createFeature(FeatureEntity f) throws OwsExceptionReport {
final CodeWithAuthority identifier = getIdentifier(f);
if (!SosHelper.checkFeatureOfInterestIdentifierForSosV2(f.getIdentifier(), getContext().getVersion())) {
identifier.setValue(null);
}
final AbstractFeature absFeat = createFeature(identifier);
addNameAndDescription(f, absFeat, getContext().getRequestedLanguage(), getContext().getDefaultLanguage(), getContext().isShowAllLanguages());
if (absFeat instanceof AbstractSamplingFeature) {
AbstractSamplingFeature absSampFeat = (AbstractSamplingFeature) absFeat;
absSampFeat.setGeometry(createGeometryFrom(f));
absSampFeat.setFeatureType(getFeatureTypes(f));
absSampFeat.setUrl(f.getUrl());
if (f.isSetXml()) {
absSampFeat.setXml(f.getXml());
}
addParameter(absSampFeat, f);
final Set<FeatureEntity> parentFeatures = f.getParents();
if (parentFeatures != null && !parentFeatures.isEmpty()) {
final List<AbstractFeature> sampledFeatures = new ArrayList<AbstractFeature>(parentFeatures.size());
for (final AbstractFeatureEntity parentFeature : parentFeatures) {
sampledFeatures.add(new HibernateFeatureVisitor(getContext()).visit(parentFeature));
}
absSampFeat.setSampledFeatures(sampledFeatures);
}
}
return absFeat;
}
Aggregations