use of org.n52.sos.ds.hibernate.dao.ProcedureDAO in project SOS by 52North.
the class DescribeSensorDaoImpl method getProcedureDescriptions.
/**
* @param request
* DescribeSensorRequest request
* @param session
* Hibernate session
* @return Matching procedure descriptions
* @throws OwsExceptionReport
* If an error occurs
*/
private List<SosProcedureDescription<?>> getProcedureDescriptions(DescribeSensorRequest request, Session session) throws OwsExceptionReport {
Set<String> possibleProcedureDescriptionFormats = getPossibleProcedureDescriptionFormats(request.getProcedureDescriptionFormat());
final ProcedureEntity procedure = new ProcedureDAO(daoFactory).getProcedureForIdentifier(request.getProcedure(), possibleProcedureDescriptionFormats, request.getValidTime(), session);
List<SosProcedureDescription<?>> list = Lists.newLinkedList();
if (procedure != null) {
if (procedure.hasProcedureHistory()) {
for (ProcedureHistoryEntity validProcedureTime : daoFactory.getProcedureHistoryDAO().get(procedure, possibleProcedureDescriptionFormats, request.getValidTime(), session)) {
SosProcedureDescription<?> sosProcedureDescription = procedureConverter.createSosProcedureDescriptionFromValidProcedureTime(procedure, request.getProcedureDescriptionFormat(), validProcedureTime, request.getVersion(), getRequestedLocale(request), session);
list.add(convertProcedureDescription(sosProcedureDescription, request));
}
}
} else {
SosProcedureDescription<?> procedureDescription = getProcedureDescription(request, session);
if (procedureDescription != null) {
list.add(procedureDescription);
} else {
if (!request.isSetValidTime()) {
throw new NoApplicableCodeException().causedBy(new IllegalArgumentException(LOG_PARAMETER_PROCEDURE_NOT_NULL)).setStatus(HTTPStatus.INTERNAL_SERVER_ERROR);
}
}
}
return list;
}
use of org.n52.sos.ds.hibernate.dao.ProcedureDAO in project SOS by 52North.
the class GetCapabilitiesHandler method getProceduresForOfferingEntity.
private Collection<ProcedureEntity> getProceduresForOfferingEntity(OfferingEntity offering, Session session) throws OwsExceptionReport, DataAccessException {
Map<String, String> map = new HashMap<>(1);
map.put(IoParameters.OFFERINGS, Long.toString(offering.getId()));
return new ProcedureDao(session).get(new DbQuery(IoParameters.createFromSingleValueMap(map)));
}
use of org.n52.sos.ds.hibernate.dao.ProcedureDAO in project SOS by 52North.
the class ProcedureHistoryDAO method setEndTime.
/**
* Set valid end time to valid procedure time object for procedure
* identifier
*
* @param procedureIdentifier
* Procedure identifier
* @param session
* Hibernate session
* @throws UnsupportedOperatorException If an error occurs
* @throws UnsupportedValueReferenceException If an error occurs
* @throws UnsupportedTimeException If an error occurs
*/
public void setEndTime(String procedureIdentifier, String procedureDescriptionFormat, Session session) throws UnsupportedTimeException, UnsupportedValueReferenceException, UnsupportedOperatorException {
ProcedureEntity procedure = new ProcedureDAO(daoFactory).getProcedureForIdentifier(procedureIdentifier, procedureDescriptionFormat, null, session);
Set<ProcedureHistoryEntity> validProcedureTimes = procedure.getProcedureHistory();
for (ProcedureHistoryEntity validProcedureTime : validProcedureTimes) {
if (validProcedureTime.getEndTime() == null) {
validProcedureTime.setEndTime(new DateTime(DateTimeZone.UTC).toDate());
}
}
}
use of org.n52.sos.ds.hibernate.dao.ProcedureDAO in project SOS by 52North.
the class AbstractHibernateProcedureDescriptionGenerator method addNameAndDescription.
protected void addNameAndDescription(ProcedureEntity procedure, AbstractFeature feature, Session session) throws OwsExceptionReport {
HibernateI18NDAO<I18NProcedureMetadata> i18nDAO = (HibernateI18NDAO<I18NProcedureMetadata>) i18NDAORepository.getDAO(I18NProcedureMetadata.class);
Locale requestedLocale = getLocale();
if (i18nDAO == null) {
// no locale support
ProcedureDAO dao = daoFactory.getProcedureDAO();
feature.addName(dao.getName(procedure));
feature.setDescription(dao.getDescription(procedure));
} else {
if (requestedLocale != null) {
// specific locale was requested
I18NProcedureMetadata i18n = i18nDAO.getMetadata(procedure.getIdentifier(), requestedLocale, session);
Optional<LocalizedString> name = i18n.getName().getLocalization(requestedLocale);
if (name.isPresent()) {
feature.addName(new CodeType(name.get()));
}
Optional<LocalizedString> description = i18n.getDescription().getLocalization(requestedLocale);
if (description.isPresent()) {
feature.setDescription(description.get().getText());
}
} else {
final I18NProcedureMetadata i18n;
if (this.showAllLanguages) {
// load all names
i18n = i18nDAO.getMetadata(procedure.getIdentifier(), session);
} else {
// load only name in default locale
i18n = i18nDAO.getMetadata(procedure.getIdentifier(), defaultLanguage, session);
}
for (LocalizedString name : i18n.getName()) {
// either all or default only
feature.addName(new CodeType(name));
}
// choose always the description in the default locale
Optional<LocalizedString> description = i18n.getDescription().getLocalization(defaultLanguage);
if (description.isPresent()) {
feature.setDescription(description.get().getText());
}
}
}
}
use of org.n52.sos.ds.hibernate.dao.ProcedureDAO in project SOS by 52North.
the class DescribeSensorHandler method getSensorDescription.
@Override
public DescribeSensorResponse getSensorDescription(final DescribeSensorRequest request) throws OwsExceptionReport {
Session session = null;
try {
session = sessionStore.getSession();
final DescribeSensorResponse response = new DescribeSensorResponse();
response.setService(request.getService());
response.setVersion(request.getVersion());
response.setOutputFormat(request.getProcedureDescriptionFormat());
Collection<ProcedureEntity> entities = new ProcedureDao(session).get(createDbQuery(request));
if (entities == null || entities.isEmpty()) {
throw new NoApplicableCodeException().causedBy(new IllegalArgumentException("Parameter 'procedure' should not be null!")).setStatus(HTTPStatus.INTERNAL_SERVER_ERROR);
}
if (dao != null) {
response.setSensorDescriptions(dao.querySensorDescriptions(request, session));
} else {
response.addSensorDescription(createSensorDescription(entities.iterator().next(), request, session));
}
return response;
} catch (final HibernateException e) {
throw new NoApplicableCodeException().causedBy(e).withMessage("Error while querying data for DescribeSensor document!");
} finally {
sessionStore.returnSession(session);
}
}
Aggregations