use of org.n52.series.db.beans.DatasetEntity 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.DatasetEntity in project SOS by 52North.
the class AbstractSeriesDAO method getSeriesCriteria.
@SuppressWarnings("unchecked")
protected Set<DatasetEntity> getSeriesCriteria(GetDataAvailabilityRequest request, Session session) throws OwsExceptionReport {
Set<DatasetEntity> set = new LinkedHashSet<>();
if (request.hasResultFilter()) {
for (SubQueryIdentifier identifier : ResultFilterRestrictions.getSubQueryIdentifier(getResultFilterClasses())) {
Criteria c = getSeriesCriteria(request.getProcedures(), request.getObservedProperties(), request.getFeaturesOfInterest(), request.getOfferings(), session);
checkAndAddResultFilterCriterion(c, request, identifier, session);
checkAndAddSpatialFilterCriterion(c, request, session);
LOGGER.trace("QUERY getSeriesCriteria(request) and result filter sub query '{}': {}", identifier.name(), HibernateHelper.getSqlString(c));
set.addAll(c.list());
}
} else {
Criteria c = getSeriesCriteria(request.getProcedures(), request.getObservedProperties(), request.getFeaturesOfInterest(), request.getOfferings(), session);
checkAndAddSpatialFilterCriterion(c, request, session);
LOGGER.trace(QUERY_SERIES_CRITERIA, HibernateHelper.getSqlString(c));
set.addAll(c.list());
}
return set;
}
use of org.n52.series.db.beans.DatasetEntity in project SOS by 52North.
the class AbstractSeriesDAO method delete.
public List<DatasetEntity> delete(ProcedureEntity procedure, Session session) {
Criteria c = getDefaultAllSeriesCriteria(session);
addProcedureToCriteria(c, procedure);
List<DatasetEntity> series = c.list();
if (series != null && !series.isEmpty()) {
StringBuilder builder = new StringBuilder();
builder.append("delete ");
builder.append(DatasetEntity.class.getSimpleName());
builder.append(" where ").append(DatasetEntity.PROPERTY_PROCEDURE).append(" = :").append(DatasetEntity.PROPERTY_PROCEDURE);
Query<?> q = session.createQuery(builder.toString());
q.setParameter(DatasetEntity.PROPERTY_PROCEDURE, procedure);
int executeUpdate = q.executeUpdate();
LOGGER.debug("{} datasets were physically deleted!", executeUpdate);
session.flush();
}
return series;
}
use of org.n52.series.db.beans.DatasetEntity in project SOS by 52North.
the class AbstractSeriesObservationDAO method updateObservationSetAsDeletedForSeries.
/**
* Update series observation by setting deleted flag
*
* @param series
* Series for which the observations should be updated
* @param deleteFlag
* New deleted flag value
* @param session
* Hibernate Session
*/
public void updateObservationSetAsDeletedForSeries(List<DatasetEntity> series, boolean deleteFlag, Session session) {
if (CollectionHelper.isNotEmpty(series)) {
Criteria criteria = getDefaultObservationCriteria(session);
criteria.add(Restrictions.in(DataEntity.PROPERTY_DATASET_ID, series.stream().map(DatasetEntity::getId).collect(Collectors.toSet())));
ScrollableIterable<DataEntity<?>> scroll = ScrollableIterable.fromCriteria(criteria);
updateObservation(scroll, deleteFlag, session);
}
}
use of org.n52.series.db.beans.DatasetEntity in project SOS by 52North.
the class AbstractSeriesObservationDAO method getFirstObservationFor.
/**
* Get the first not deleted observation for the {@link DatasetEntity}
*
* @param series
* Series to get observation for
* @param session
* Hibernate session
* @return First not deleted observation
*/
public DataEntity<?> getFirstObservationFor(DatasetEntity series, Session session) {
Criteria c = getDefaultObservationCriteria(session);
c.add(Restrictions.eq(DataEntity.PROPERTY_DATASET_ID, series.getId()));
c.addOrder(Order.asc(DataEntity.PROPERTY_SAMPLING_TIME_START));
c.setMaxResults(1);
LOGGER.trace("QUERY getFirstObservationFor(series): {}", HibernateHelper.getSqlString(c));
return (DataEntity) c.uniqueResult();
}
Aggregations