Search in sources :

Example 1 with DaoFactory

use of org.n52.sos.ds.hibernate.dao.DaoFactory 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;
}
Also used : ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) ProcedureHistoryEntity(org.n52.series.db.beans.ProcedureHistoryEntity) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) SosProcedureDescription(org.n52.shetland.ogc.sos.SosProcedureDescription)

Example 2 with DaoFactory

use of org.n52.sos.ds.hibernate.dao.DaoFactory in project SOS by 52North.

the class GetObservationByIdDaoImpl method querySeriesObservation.

/**
 * Query the series observations for streaming datasource
 *
 * @param request
 *            The GetObservation request
 * @param session
 *            Hibernate Session
 * @return List of internal observations
 * @throws OwsExceptionReport
 *             If an error occurs.
 * @throws ConverterException
 *             If an error occurs during sensor description creation.
 */
private List<OmObservation> querySeriesObservation(GetObservationByIdRequest request, final Session session) throws OwsExceptionReport, ConverterException {
    final long start = System.currentTimeMillis();
    final List<OmObservation> result = new LinkedList<OmObservation>();
    // get valid featureOfInterest identifier
    List<DatasetEntity> serieses = daoFactory.getSeriesDAO().getSeries(request, session);
    checkMaxNumberOfReturnedSeriesSize(serieses.size());
    for (DatasetEntity series : serieses) {
        ObservationStream createSosObservationFromSeries = HibernateObservationUtilities.createSosObservationFromSeries(series, request, getProcedureDescriptionFormat(request.getResponseFormat()), observationCreatorContext, session);
        OmObservation observationTemplate = createSosObservationFromSeries.next();
        HibernateSeriesStreamingValue streamingValue = new HibernateChunkSeriesStreamingValue(sessionHolder.getConnectionProvider(), daoFactory, request, series.getId(), observationCreatorContext.getBindingRepository(), getChunkSize());
        streamingValue.setResponseFormat(request.getResponseFormat());
        streamingValue.setObservationTemplate(observationTemplate);
        observationTemplate.setValue(streamingValue);
        result.add(observationTemplate);
    }
    LOGGER.debug("Time to query observations needs {} ms!", System.currentTimeMillis() - start);
    return result;
}
Also used : HibernateChunkSeriesStreamingValue(org.n52.sos.ds.hibernate.values.series.HibernateChunkSeriesStreamingValue) ObservationStream(org.n52.shetland.ogc.om.ObservationStream) DatasetEntity(org.n52.series.db.beans.DatasetEntity) OmObservation(org.n52.shetland.ogc.om.OmObservation) HibernateSeriesStreamingValue(org.n52.sos.ds.hibernate.values.series.HibernateSeriesStreamingValue) LinkedList(java.util.LinkedList)

Example 3 with DaoFactory

use of org.n52.sos.ds.hibernate.dao.DaoFactory in project SOS by 52North.

the class CacheQueryTest method fillObservations.

@BeforeClass
public static void fillObservations() throws OwsExceptionReport {
    Session session = getSession();
    Transaction transaction = null;
    try {
        transaction = session.beginTransaction();
        I18NDAORepository i18NDAORepository = new I18NDAORepository();
        DaoFactory daoFactory = new DaoFactory();
        daoFactory.setI18NDAORepository(i18NDAORepository);
        HibernateObservationBuilder b = new HibernateObservationBuilder(session, daoFactory);
        DateTime begin = new DateTime();
        int numObs = 10000;
        for (int i = 0; i < numObs; ++i) {
            if (i % 50 == 0) {
                LOGGER.debug(LOG_TEMPLATE, i, numObs);
                session.flush();
                session.clear();
            }
            b.createObservation(String.valueOf(i), begin.plusHours(i));
        }
        LOGGER.debug(LOG_TEMPLATE, numObs, numObs);
        session.flush();
        transaction.commit();
    } catch (HibernateException | CodedException he) {
        if (transaction != null) {
            transaction.rollback();
        }
        throw he;
    } finally {
        returnSession(session);
    }
}
Also used : Transaction(org.hibernate.Transaction) CodedException(org.n52.shetland.ogc.ows.exception.CodedException) HibernateException(org.hibernate.HibernateException) I18NDAORepository(org.n52.iceland.i18n.I18NDAORepository) HibernateObservationBuilder(org.n52.sos.ds.hibernate.util.HibernateObservationBuilder) DateTime(org.joda.time.DateTime) Session(org.hibernate.Session) BeforeClass(org.junit.BeforeClass)

Example 4 with DaoFactory

use of org.n52.sos.ds.hibernate.dao.DaoFactory in project SOS by 52North.

the class HibernateObservationUtilitiesTest method createSubObservationOfSweArrayObservationViaGetObservationById.

@Test
public // present
void createSubObservationOfSweArrayObservationViaGetObservationById() throws OwsExceptionReport, ConnectionProviderException, ConverterException {
    // PREPARE
    Session session = getSession();
    try {
        Transaction transaction = session.beginTransaction();
        GetObservationByIdRequest request = new GetObservationByIdRequest();
        request.setVersion(Sos2Constants.SERVICEVERSION);
        FormatEntity hProcedureDescriptionFormat = new FormatEntity();
        FormatEntity hFeatureOfInterestType = new FormatEntity();
        FeatureEntity hFeatureOfInterest = new FeatureEntity();
        PhenomenonEntity hObservableProperty = new PhenomenonEntity();
        CategoryEntity hCategory = new CategoryEntity();
        PlatformEntity hPlatform = new PlatformEntity();
        FormatEntity hObservationType = new FormatEntity();
        OfferingEntity hOffering = new OfferingEntity();
        DatasetEntity hObservationConstellation = new DatasetEntity();
        CodespaceEntity hCodespace = new CodespaceEntity();
        ProcedureEntity hProcedure = new ProcedureEntity();
        QuantityDataEntity hObservation = new QuantityDataEntity();
        ResultTemplateEntity hResultTemplateEntity = new ResultTemplateEntity();
        hProcedureDescriptionFormat.setFormat(PROCEDURE_DESCRIPTION_FORMAT);
        hCodespace.setName(CODESPACE);
        hProcedure.setIdentifier(PROCEDURE);
        hProcedure.setFormat(hProcedureDescriptionFormat);
        hFeatureOfInterestType.setFormat(FEATURE_OF_INTEREST_TYPE);
        hFeatureOfInterest.setIdentifier(FEATURE);
        hFeatureOfInterest.setFeatureType(hFeatureOfInterestType);
        hFeatureOfInterest.setIdentifierCodespace(hCodespace);
        hPlatform.setIdentifier(FEATURE);
        hObservableProperty.setIdentifier(OBSERVABLE_PROPERTY);
        hCategory.setIdentifier(OBSERVABLE_PROPERTY);
        hObservationType.setFormat(OmConstants.OBS_TYPE_SWE_ARRAY_OBSERVATION);
        hOffering.setIdentifier(OFFERING);
        hObservationConstellation.setProcedure(hProcedure);
        hObservationConstellation.setOffering(hOffering);
        hObservationConstellation.setObservableProperty(hObservableProperty);
        hObservationConstellation.setOmObservationType(hObservationType);
        hObservationConstellation.setFeature(hFeatureOfInterest);
        hObservationConstellation.setDeleted(false);
        hObservationConstellation.setHidden(false);
        hObservationConstellation.setCategory(hCategory);
        hObservationConstellation.setPlatform(hPlatform);
        hResultTemplateEntity.setFeature(hFeatureOfInterest);
        hResultTemplateEntity.setOffering(hOffering);
        hResultTemplateEntity.setPhenomenon(hObservableProperty);
        hResultTemplateEntity.setProcedure(hProcedure);
        hResultTemplateEntity.setIdentifier("test-rt-1");
        hResultTemplateEntity.setEncoding("<swe:TextEncoding xmlns:swe=\"http://www.opengis.net/swe/2.0\" " + "xmlns:sams=\"http://www.opengis.net/samplingSpatial/2.0\" " + "xmlns:sml=\"http://www.opengis.net/sensorML/1.0.1\" " + "xmlns:sf=\"http://www.opengis.net/sampling/2.0\" " + "xmlns:swes=\"http://www.opengis.net/swes/2.0\" " + "xmlns:sos=\"http://www.opengis.net/sos/2.0\" " + "xmlns:gml=\"http://www.opengis.net/gml/3.2\" " + "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" " + "xmlns:om=\"http://www.opengis.net/om/2.0\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + "xmlns:xlink=\"http://www.w3.org/1999/xlink\" " + "tokenSeparator=\"#\" blockSeparator=\"@\"/>");
        hResultTemplateEntity.setStructure("\"<swe:DataRecord xmlns:swe=\"http://www.opengis.net/swe/2.0\" " + "xmlns:sams=\"http://www.opengis.net/samplingSpatial/2.0\" " + "xmlns:sml=\"http://www.opengis.net/sensorML/1.0.1\" " + "xmlns:sf=\"http://www.opengis.net/sampling/2.0\" " + "xmlns:swes=\"http://www.opengis.net/swes/2.0\" " + "xmlns:sos=\"http://www.opengis.net/sos/2.0\" " + "xmlns:gml=\"http://www.opengis.net/gml/3.2\" " + "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" " + "xmlns:om=\"http://www.opengis.net/om/2.0\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + "xmlns:xlink=\"http://www.w3.org/1999/xlink\">\r\n" + "  <swe:field name=\"phenomenonTime\">\r\n" + "    <swe:Time definition=\"http://www.opengis.net/def/property/OGC/0/PhenomenonTime\">\r\n" + "      <swe:uom xlink:href=\"http://www.opengis.net/def/uom/ISO-8601/0/Gregorian\"/>\r\n" + "    </swe:Time>\r\n" + "  </swe:field>\r\n" + "  <swe:field name=\"Discharge\">\r\n" + "    <swe:Quantity definition=\"http://sweet.jpl.nasa.gov/2.0/hydroSurface.owl#Discharge\">\r\n" + "      <swe:uom code=\"m3\"/>\r\n" + "    </swe:Quantity>\r\n" + "  </swe:field>\r\n" + "</swe:DataRecord>\"");
        session.save(hProcedureDescriptionFormat);
        session.save(hProcedure);
        session.save(hCodespace);
        session.save(hOffering);
        session.save(hFeatureOfInterestType);
        session.save(hFeatureOfInterest);
        session.save(hPlatform);
        session.save(hObservableProperty);
        session.save(hCategory);
        session.save(hObservationType);
        session.save(hObservationConstellation);
        session.save(hResultTemplateEntity);
        session.flush();
        hObservation.setValue(BigDecimal.valueOf(1.0));
        hObservation.setSamplingTimeStart(DateTime.now().toDate());
        hObservation.setSamplingTimeEnd(hObservation.getSamplingTimeStart());
        hObservation.setResultTime(hObservation.getSamplingTimeStart());
        hObservation.setDataset(hObservationConstellation);
        hObservation.setStaIdentifier("123");
        hObservation.setDeleted(false);
        session.save(hObservation);
        transaction.commit();
        ArrayList<DataEntity<?>> observationsFromDataBase = new ArrayList<>();
        observationsFromDataBase.add(hObservation);
        SosHelper sosHelper = new SosHelper();
        sosHelper.setServiceURL(URI.create("http://test.org/"));
        DaoFactory daoFactory = new DaoFactory();
        daoFactory.setSosHelper(sosHelper);
        // CALL
        OmObservationCreatorContext ctx = new OmObservationCreatorContext(null, null, daoFactory, new ProfileHanlderMock(), Mockito.mock(AdditionalObservationCreatorRepository.class), null, new FeatureQueryHandlerMock(), null, null, null, null, null, Mockito.mock(BindingRepository.class));
        ObservationStream resultList = HibernateObservationUtilities.createSosObservationsFromObservations(observationsFromDataBase, request, Locale.ENGLISH, null, ctx, session);
        // TEST RESULTS
        assertThat(resultList, is(notNullValue()));
        assertThat(resultList.hasNext(), is(true));
        Object value = resultList.next().getValue().getValue();
        assertThat(resultList.hasNext(), is(false));
        assertThat(value, is(instanceOf(QuantityValue.class)));
        Double val = ((QuantityValue) value).getValue().doubleValue();
        // assertThat(value, is(instanceOf(SweDataArray.class)));
        // Double val = Double.parseDouble(((SweDataArray) value).getValues().get(0).get(1));
        assertThat(val, is(closeTo(1.0, 0.00001)));
    } finally {
        returnSession(session);
    }
}
Also used : CodespaceEntity(org.n52.series.db.beans.CodespaceEntity) ArrayList(java.util.ArrayList) PhenomenonEntity(org.n52.series.db.beans.PhenomenonEntity) DaoFactory(org.n52.sos.ds.hibernate.dao.DaoFactory) AdditionalObservationCreatorRepository(org.n52.sos.ds.hibernate.util.observation.AdditionalObservationCreatorRepository) ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) PlatformEntity(org.n52.series.db.beans.PlatformEntity) QuantityDataEntity(org.n52.series.db.beans.QuantityDataEntity) SosHelper(org.n52.sos.util.SosHelper) GetObservationByIdRequest(org.n52.shetland.ogc.sos.request.GetObservationByIdRequest) CategoryEntity(org.n52.series.db.beans.CategoryEntity) FeatureEntity(org.n52.series.db.beans.FeatureEntity) OmObservationCreatorContext(org.n52.sos.ds.hibernate.util.observation.OmObservationCreatorContext) FormatEntity(org.n52.series.db.beans.FormatEntity) DatasetEntity(org.n52.series.db.beans.DatasetEntity) Transaction(org.hibernate.Transaction) ObservationStream(org.n52.shetland.ogc.om.ObservationStream) BindingRepository(org.n52.iceland.binding.BindingRepository) ResultTemplateEntity(org.n52.series.db.beans.ResultTemplateEntity) DataEntity(org.n52.series.db.beans.DataEntity) QuantityDataEntity(org.n52.series.db.beans.QuantityDataEntity) OfferingEntity(org.n52.series.db.beans.OfferingEntity) Session(org.hibernate.Session) Test(org.junit.Test)

Example 5 with DaoFactory

use of org.n52.sos.ds.hibernate.dao.DaoFactory in project SOS by 52North.

the class TemporalRestrictionTest method getBuilder.

protected HibernateObservationBuilder getBuilder(Session session) throws OwsExceptionReport {
    I18NDAORepository i18NDAORepository = new I18NDAORepository();
    DaoFactory daoFactory = new DaoFactory();
    daoFactory.setI18NDAORepository(i18NDAORepository);
    return new HibernateObservationBuilder(session, daoFactory);
}
Also used : I18NDAORepository(org.n52.iceland.i18n.I18NDAORepository) DaoFactory(org.n52.sos.ds.hibernate.dao.DaoFactory)

Aggregations

DaoFactory (org.n52.sos.ds.hibernate.dao.DaoFactory)6 Session (org.hibernate.Session)5 I18NDAORepository (org.n52.iceland.i18n.I18NDAORepository)5 Transaction (org.hibernate.Transaction)4 DateTime (org.joda.time.DateTime)4 ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)4 HibernateException (org.hibernate.HibernateException)3 DatasetEntity (org.n52.series.db.beans.DatasetEntity)3 ProcedureHistoryEntity (org.n52.series.db.beans.ProcedureHistoryEntity)3 ObservationStream (org.n52.shetland.ogc.om.ObservationStream)3 LinkedList (java.util.LinkedList)2 FormatEntity (org.n52.series.db.beans.FormatEntity)2 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)2 OmObservation (org.n52.shetland.ogc.om.OmObservation)2 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)2 OmObservationCreatorContext (org.n52.sos.ds.hibernate.util.observation.OmObservationCreatorContext)2 SosHelper (org.n52.sos.util.SosHelper)2 ArrayList (java.util.ArrayList)1 Criterion (org.hibernate.criterion.Criterion)1 Before (org.junit.Before)1