use of org.n52.series.db.DataAccessException in project SOS by 52North.
the class AbstractProcedureDescriptionGeneratorSml method createOutputs.
/**
* Create SensorML output list from observableProperties
*
* @param procedure
* Hibernate procedure entity
* @param observableProperties
* Properties observed by the procedure
*
* @return Output list
*
* @throws OwsExceptionReport
* If an error occurs
*/
private List<SmlIo> createOutputs(ProcedureEntity procedure, List<PhenomenonEntity> observableProperties, Session session) throws OwsExceptionReport {
try {
final List<SmlIo> outputs = Lists.newArrayListWithExpectedSize(observableProperties.size());
int i = 1;
for (PhenomenonEntity observableProperty : observableProperties) {
final SmlIo output = createOutputFromDatasets(procedure, observableProperty, session);
if (output != null) {
output.setIoName("output#" + i++);
outputs.add(output);
}
}
return outputs;
} catch (final HibernateException | DataAccessException he) {
throw new NoApplicableCodeException().causedBy(he).withMessage("Error while querying observation data!").setStatus(HTTPStatus.INTERNAL_SERVER_ERROR);
}
}
use of org.n52.series.db.DataAccessException in project SOS by 52North.
the class GetCapabilitiesHandler method getContentsForSosV1.
/**
* Get the contents for SOS 1.0.0 capabilities
*
* @return sectionSpecificContentObject metadata holder to get contents
*
* @throws OwsExceptionReport
* If an error occurs
*/
@Override
protected List<SosObservationOffering> getContentsForSosV1(SectionSpecificContentObject sectionSpecificContentObject) throws OwsExceptionReport {
Session session = null;
try {
session = sessionStore.getSession();
Collection<OfferingEntity> offerings = getOfferings(session);
List<SosObservationOffering> sosOfferings = new ArrayList<>(offerings.size());
for (OfferingEntity offering : offerings) {
Collection<ProcedureEntity> procedures = GetCapabilitiesHandler.this.getProceduresForOfferingEntity(offering, session);
ReferencedEnvelope envelopeForOffering = getCache().getEnvelopeForOffering(offering.getIdentifier());
Set<String> featuresForoffering = getFOI4offering(offering.getIdentifier());
Collection<String> responseFormats = getResponseFormatRepository().getSupportedResponseFormats(SosConstants.SOS, Sos1Constants.SERVICEVERSION);
if (checkOfferingValues(envelopeForOffering, featuresForoffering, responseFormats)) {
SosObservationOffering sosObservationOffering = new SosObservationOffering();
// insert observationTypes
sosObservationOffering.setObservationTypes(getObservationTypes(offering.getIdentifier()));
// the envelope
if (offering.isSetGeometry()) {
sosObservationOffering.setObservedArea(processObservedArea(offering.getGeometry()));
} else if (getCache().hasEnvelopeForOffering(offering.getIdentifier())) {
sosObservationOffering.setObservedArea(getCache().getEnvelopeForOffering(offering.getIdentifier()));
}
// TODO: add intended application
// xb_oo.addIntendedApplication("");
// add offering name
addSosOfferingToObservationOffering(offering, sosObservationOffering, sectionSpecificContentObject.getGetCapabilitiesRequest());
// set up phenomena
sosObservationOffering.setObservableProperties(getCache().getObservablePropertiesForOffering(offering.getIdentifier()));
Set<String> compositePhenomenonsForOffering = getCache().getCompositePhenomenonsForOffering(offering.getIdentifier());
sosObservationOffering.setCompositePhenomena(compositePhenomenonsForOffering);
Map<String, Collection<String>> phens4CompPhens = Optional.ofNullable(compositePhenomenonsForOffering).map(Set::stream).orElseGet(Stream::empty).collect(toMap(Function.identity(), getCache()::getObservablePropertiesForCompositePhenomenon));
sosObservationOffering.setPhens4CompPhens(phens4CompPhens);
// set up time
setUpTimeForOffering(offering, sosObservationOffering);
// add feature of interests
if (getProfileHandler().getActiveProfile().isListFeatureOfInterestsInOfferings()) {
sosObservationOffering.setFeatureOfInterest(getFOI4offering(offering.getIdentifier()));
}
// set procedures
sosObservationOffering.setProcedures(procedures.stream().map(p -> p.getIdentifier()).collect(Collectors.toSet()));
// insert result models
Collection<QName> resultModels = OMHelper.getQNamesForResultModel(getCache().getObservationTypesForOffering(offering.getIdentifier()));
sosObservationOffering.setResultModels(resultModels);
// set response format
sosObservationOffering.setResponseFormats(responseFormats);
// set response Mode
sosObservationOffering.setResponseModes(SosConstants.RESPONSE_MODES);
sosOfferings.add(sosObservationOffering);
}
}
return sosOfferings;
} catch (HibernateException | DataAccessException e) {
throw new NoApplicableCodeException().causedBy(e).withMessage(ERROR_QUERYING_CAPABILITIES);
} finally {
sessionStore.returnSession(session);
}
}
use of org.n52.series.db.DataAccessException in project SOS by 52North.
the class GetCapabilitiesHandler method setUpPhenomenaForOffering.
protected void setUpPhenomenaForOffering(OfferingEntity offering, ProcedureEntity procedure, SosObservationOffering sosOffering, Session session) throws DataAccessException {
Map<String, String> map = new HashMap<>();
map.put(IoParameters.OFFERINGS, Long.toString(offering.getId()));
map.put(IoParameters.PROCEDURES, Long.toString(procedure.getId()));
Collection<PhenomenonEntity> observableProperties = new PhenomenonDao(session).get(new DbQuery(IoParameters.createFromSingleValueMap(map)));
Set<String> validObsProps = getCache().getObservablePropertiesForOffering(offering.getIdentifier());
Collection<String> phenomenons = new LinkedList<>();
Map<String, Collection<String>> phens4CompPhens = new HashMap<>(observableProperties.size());
observableProperties.forEach(observableProperty -> {
if (validObsProps.contains(observableProperty.getIdentifier())) {
if (!observableProperty.hasChildren() && !observableProperty.hasParents()) {
phenomenons.add(observableProperty.getIdentifier());
} else if (observableProperty.hasChildren() && !observableProperty.hasParents()) {
phens4CompPhens.put(observableProperty.getIdentifier(), observableProperty.getChildren().stream().map(PhenomenonEntity::getIdentifier).collect(toCollection(TreeSet::new)));
}
}
});
sosOffering.addObservatbleProperties(phenomenons);
sosOffering.setPhens4CompPhens(phens4CompPhens);
}
use of org.n52.series.db.DataAccessException 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.series.db.DataAccessException in project SOS by 52North.
the class ObservationTimeCacheUpdate method execute.
@Override
public void execute() {
LOGGER.debug("Executing ObservationTimeCacheUpdate");
startStopwatch();
try {
// TODD Use TimerPeriod.expand from OfferingTimes
List<OfferingEntity> offerings = new OfferingDao(getSession()).getAllInstances(new DbQuery(IoParameters.createDefaults()));
TimePeriod phenomenonTime = new TimePeriod();
TimePeriod resultTime = new TimePeriod();
for (OfferingEntity offering : offerings) {
phenomenonTime.extendToContain(new TimePeriod(offering.getSamplingTimeStart(), offering.getSamplingTimeEnd()));
resultTime.extendToContain(new TimePeriod(offering.getResultTimeStart(), offering.getResultTimeEnd()));
}
getCache().setMinPhenomenonTime(phenomenonTime.getStart());
getCache().setMaxPhenomenonTime(phenomenonTime.getEnd());
getCache().setMinResultTime(resultTime.getStart());
getCache().setMaxResultTime(resultTime.getEnd());
} catch (HibernateException | DataAccessException dae) {
getErrors().add(new NoApplicableCodeException().causedBy(dae).withMessage("Error while updating observation time cache!"));
}
LOGGER.debug("Finished executing ObservationTimeCacheUpdate ({})", getStopwatchResult());
}
Aggregations