use of org.n52.series.db.beans.ProcedureEntity in project SOS by 52North.
the class ProcedureDAO method getProcedureForIdentifier.
//
// private ProcedureEntity
// getProcedureWithLatestValidProcedureDescription(String
// identifier, Session session) {
// Criteria criteria = getDefaultCriteria(session);
// criteria.add(Restrictions.eq(ProcedureEntity.IDENTIFIER, identifier));
// criteria.createCriteria(TProcedureEntity.VALID_PROCEDURE_TIME).add(
// Restrictions.isNull(ValidProcedureTime.END_TIME));
// LOGGER.trace(QUERY_IDENTIFIER_LOG_TEMPLATE,
// HibernateHelper.getSqlString(criteria));
// return (ProcedureEntity) criteria.uniqueResult();
// }
/**
* Get ProcedureEntity object for procedure identifier
*
* @param identifier
* ProcedureEntity identifier
* @param session
* Hibernate session
* @return ProcedureEntity object
*/
public ProcedureEntity getProcedureForIdentifier(final String identifier, Time time, final Session session) {
Criteria criteria = getDefaultCriteria(session).add(Restrictions.eq(ProcedureEntity.IDENTIFIER, identifier));
LOGGER.trace(QUERY_IDENTIFIER_LOG_TEMPLATE, HibernateHelper.getSqlString(criteria));
return (ProcedureEntity) criteria.uniqueResult();
}
use of org.n52.series.db.beans.ProcedureEntity in project SOS by 52North.
the class ProcedureDAO method getProcedureForIdentifier.
/**
* Get procedure for identifier, possible procedureDescriptionFormats and
* valid time
*
* @param identifier
* Identifier of the procedure
* @param possibleProcedureDescriptionFormats
* Possible procedureDescriptionFormats
* @param validTime
* Valid time of the procedure
* @param session
* Hibernate Session
* @return ProcedureEntity entity that match the parameters
* @throws UnsupportedTimeException
* If the time is not supported
* @throws UnsupportedValueReferenceException
* If the valueReference is not supported
* @throws UnsupportedOperatorException
* If the temporal operator is not supported
*/
public ProcedureEntity getProcedureForIdentifier(String identifier, Set<String> possibleProcedureDescriptionFormats, Time validTime, Session session) throws UnsupportedTimeException, UnsupportedValueReferenceException, UnsupportedOperatorException {
Criteria criteria = getDefaultCriteria(session).add(Restrictions.eq(ProcedureEntity.IDENTIFIER, identifier));
Criteria createValidProcedureTime = criteria.createCriteria(ProcedureEntity.PROPERTY_VALID_PROCEDURE_TIME);
Criterion validTimeCriterion = QueryHelper.getValidTimeCriterion(validTime);
if (validTime == null || validTimeCriterion == null) {
createValidProcedureTime.add(Restrictions.isNull(ProcedureHistoryEntity.END_TIME));
} else {
createValidProcedureTime.add(validTimeCriterion);
}
createValidProcedureTime.createCriteria(ProcedureHistoryEntity.PROCEDURE_DESCRIPTION_FORMAT).add(Restrictions.in(FormatEntity.FORMAT, possibleProcedureDescriptionFormats));
LOGGER.trace("QUERY getProcedureForIdentifier(identifier, possibleProcedureDescriptionFormats, validTime): {}", HibernateHelper.getSqlString(criteria));
return (ProcedureEntity) criteria.uniqueResult();
}
use of org.n52.series.db.beans.ProcedureEntity in project SOS by 52North.
the class ProcedureDAO method updateProcedure.
public ProcedureEntity updateProcedure(ProcedureEntity procedure, SosProcedureDescription procedureDescription, Session session) {
AbstractFeature af = procedureDescription.getProcedureDescription();
if (af.isSetName()) {
if (!procedure.isSetName() || procedure.isSetName() && !checkForName(af.getName(), procedure.getName())) {
procedure.setName(af.getFirstName().getValue());
}
if (af.isSetDescription() && !af.getDescription().equals(procedure.getDescription())) {
procedure.setDescription(af.getDescription());
}
}
session.saveOrUpdate(procedure);
session.flush();
session.refresh(procedure);
return procedure;
}
use of org.n52.series.db.beans.ProcedureEntity in project SOS by 52North.
the class ProcedureDAO method getMaxDate4Procedure.
/**
* Get max time from observations for procedure
*
* @param procedure
* ProcedureEntity identifier
* @param session
* Hibernate session
* @return max time for procedure
* @throws CodedException
* If an error occurs
*/
public DateTime getMaxDate4Procedure(final String procedure, final Session session) throws OwsExceptionReport {
Object maxStart = null;
Object maxEnd = null;
if (HibernateHelper.isNamedQuerySupported(SQL_QUERY_GET_MAX_DATE_FOR_PROCEDURE, session)) {
Query namedQuery = session.getNamedQuery(SQL_QUERY_GET_MAX_DATE_FOR_PROCEDURE);
namedQuery.setParameter(PROCEDURE, procedure);
LOGGER.trace("QUERY getMaxDate4Procedure(procedure) with NamedQuery: {}", SQL_QUERY_GET_MAX_DATE_FOR_PROCEDURE);
maxStart = namedQuery.uniqueResult();
maxEnd = maxStart;
} else {
AbstractObservationDAO observationDAO = getDaoFactory().getObservationDAO();
Criteria cstart = observationDAO.getDefaultObservationInfoCriteria(session);
Criteria cend = observationDAO.getDefaultObservationInfoCriteria(session);
if (observationDAO instanceof SeriesObservationDAO) {
addProcedureRestrictionForSeries(cstart, procedure);
addProcedureRestrictionForSeries(cend, procedure);
} else {
addProcedureRestrictionForObservation(cstart, procedure);
addProcedureRestrictionForObservation(cend, procedure);
}
addMinMaxProjection(cstart, MinMax.MAX, DataEntity.PROPERTY_SAMPLING_TIME_START);
addMinMaxProjection(cend, MinMax.MAX, DataEntity.PROPERTY_SAMPLING_TIME_END);
LOGGER.trace("QUERY getMaxDate4Procedure(procedure) start: {}", HibernateHelper.getSqlString(cstart));
LOGGER.trace("QUERY getMaxDate4Procedure(procedure) end: {}", HibernateHelper.getSqlString(cend));
if (HibernateHelper.getSqlString(cstart).endsWith(HibernateHelper.getSqlString(cend))) {
maxStart = cstart.uniqueResult();
maxEnd = maxStart;
LOGGER.trace("Max time start and end query are identically, only one query is executed!");
} else {
maxStart = cstart.uniqueResult();
maxEnd = cend.uniqueResult();
}
}
if (maxStart == null && maxEnd == null) {
return null;
} else {
final DateTime start = new DateTime(maxStart, DateTimeZone.UTC);
if (maxEnd != null) {
final DateTime end = new DateTime(maxEnd, DateTimeZone.UTC);
if (end.isAfter(start)) {
return end;
}
}
return start;
}
}
use of org.n52.series.db.beans.ProcedureEntity in project SOS by 52North.
the class ProcedureDAO method getProcedureForIdentifierIncludeDeleted.
/**
* Get ProcedureEntity object for procedure identifier inclusive deleted
* procedure
*
* @param identifier
* ProcedureEntity identifier
* @param session
* Hibernate session
* @return ProcedureEntity object
*/
public ProcedureEntity getProcedureForIdentifierIncludeDeleted(final String identifier, final Session session) {
Criteria criteria = session.createCriteria(ProcedureEntity.class).add(Restrictions.eq(ProcedureEntity.IDENTIFIER, identifier));
LOGGER.trace("QUERY getProcedureForIdentifierIncludeDeleted(identifier): {}", HibernateHelper.getSqlString(criteria));
return (ProcedureEntity) criteria.uniqueResult();
}
Aggregations