Search in sources :

Example 1 with DataAccessException

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);
    }
}
Also used : HibernateException(org.hibernate.HibernateException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) PhenomenonEntity(org.n52.series.db.beans.PhenomenonEntity) SmlIo(org.n52.shetland.ogc.sensorML.elements.SmlIo) DataAccessException(org.n52.series.db.DataAccessException)

Example 2 with DataAccessException

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);
    }
}
Also used : Collectors.toSet(java.util.stream.Collectors.toSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) HibernateException(org.hibernate.HibernateException) QName(javax.xml.namespace.QName) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) ArrayList(java.util.ArrayList) SosObservationOffering(org.n52.shetland.ogc.sos.SosObservationOffering) ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) Collection(java.util.Collection) Collectors.toCollection(java.util.stream.Collectors.toCollection) OfferingEntity(org.n52.series.db.beans.OfferingEntity) DataAccessException(org.n52.series.db.DataAccessException) Session(org.hibernate.Session)

Example 3 with DataAccessException

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);
}
Also used : DbQuery(org.n52.series.db.dao.DbQuery) HashMap(java.util.HashMap) PhenomenonDao(org.n52.series.db.dao.PhenomenonDao) Collection(java.util.Collection) Collectors.toCollection(java.util.stream.Collectors.toCollection) PhenomenonEntity(org.n52.series.db.beans.PhenomenonEntity) LinkedList(java.util.LinkedList)

Example 4 with DataAccessException

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)));
}
Also used : ProcedureDao(org.n52.series.db.dao.ProcedureDao) DbQuery(org.n52.series.db.dao.DbQuery) HashMap(java.util.HashMap)

Example 5 with DataAccessException

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());
}
Also used : DbQuery(org.n52.series.db.dao.DbQuery) HibernateException(org.hibernate.HibernateException) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) OfferingEntity(org.n52.series.db.beans.OfferingEntity) OfferingDao(org.n52.series.db.dao.OfferingDao) DataAccessException(org.n52.series.db.DataAccessException)

Aggregations

NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)9 DataAccessException (org.n52.series.db.DataAccessException)8 HibernateException (org.hibernate.HibernateException)7 DbQuery (org.n52.series.db.dao.DbQuery)7 Session (org.hibernate.Session)6 OfferingEntity (org.n52.series.db.beans.OfferingEntity)6 Collection (java.util.Collection)5 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 DatasetEntity (org.n52.series.db.beans.DatasetEntity)5 ArrayList (java.util.ArrayList)4 Set (java.util.Set)4 Collectors.toCollection (java.util.stream.Collectors.toCollection)4 ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)4 DatasetDao (org.n52.series.db.dao.DatasetDao)4 Collections (java.util.Collections)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3