Search in sources :

Example 1 with CodespaceEntity

use of org.n52.series.db.beans.CodespaceEntity in project SOS by 52North.

the class HibernateObservationBuilder method getCodespace.

protected CodespaceEntity getCodespace() {
    CodespaceEntity codespace = (CodespaceEntity) session.createCriteria(CodespaceEntity.class).add(Restrictions.eq(CodespaceEntity.PROPERTY_NAME, CODESPACE)).uniqueResult();
    if (codespace == null) {
        codespace = new CodespaceEntity();
        codespace.setName(CODESPACE);
        session.save(codespace);
        session.flush();
    }
    return codespace;
}
Also used : CodespaceEntity(org.n52.series.db.beans.CodespaceEntity)

Example 2 with CodespaceEntity

use of org.n52.series.db.beans.CodespaceEntity 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 3 with CodespaceEntity

use of org.n52.series.db.beans.CodespaceEntity in project SOS by 52North.

the class CodespaceDAO method getCodespace.

/**
 * Get codespace object for identifier
 *
 * @param codespace
 *            identifier
 * @param session
 *            Hibernate session
 * @return Codespace object
 */
public CodespaceEntity getCodespace(final String codespace, final Session session) {
    Criteria criteria = session.createCriteria(CodespaceEntity.class).add(Restrictions.eq(CodespaceEntity.PROPERTY_NAME, codespace));
    LOGGER.trace("QUERY getCodespace(codespace): {}", HibernateHelper.getSqlString(criteria));
    return (CodespaceEntity) criteria.uniqueResult();
}
Also used : CodespaceEntity(org.n52.series.db.beans.CodespaceEntity) Criteria(org.hibernate.Criteria)

Example 4 with CodespaceEntity

use of org.n52.series.db.beans.CodespaceEntity in project SOS by 52North.

the class CodespaceDAO method getOrInsertCodespace.

/**
 * Insert and/or get codespace object
 *
 * @param codespace
 *            Codespace identifier
 * @param session
 *            Hibernate session
 * @return Codespace object
 */
public CodespaceEntity getOrInsertCodespace(final String codespace, final Session session) {
    CodespaceEntity result = getCodespace(codespace, session);
    if (result == null) {
        result = new CodespaceEntity();
        result.setName(codespace);
        session.save(result);
        session.flush();
        session.refresh(result);
    }
    return result;
}
Also used : CodespaceEntity(org.n52.series.db.beans.CodespaceEntity)

Example 5 with CodespaceEntity

use of org.n52.series.db.beans.CodespaceEntity in project SOS by 52North.

the class InsertSensorHandler method addStaticReferenceValues.

private void addStaticReferenceValues(InsertSensorRequest request, Session session, FormatEntity procedureDescriptionFormat, ProcedureEntity hProcedure, List<FormatEntity> observationTypes, List<FormatEntity> featureOfInterestTypes, List<RelatedFeatureEntity> hRelatedFeatures, OfferingEntity hOffering, PhenomenonEntity hObservableProperty, AbstractSeriesDAO seriesDAO) throws OwsExceptionReport {
    AbstractFeature sosFeatureOfInterest = request.getProcedureDescription().getFeaturesOfInterestMap().entrySet().iterator().next().getValue();
    AbstractFeatureEntity<?> hFeature = getDaoFactory().getFeatureDAO().insertFeature(sosFeatureOfInterest, session);
    for (SmlCapability referenceValue : ((AbstractSensorML) request.getProcedureDescription().getProcedureDescription()).findCapabilities(REFERENCE_VALUES_PREDICATE).get().getCapabilities()) {
        if (!(referenceValue.getAbstractDataComponent() instanceof SweQuantity)) {
            throw new NoApplicableCodeException().withMessage("ReferenceValue of Type '%s' is not supported -> Aborting InsertSensor Operation!", referenceValue.getAbstractDataComponent().getDataComponentType());
        }
        SweQuantity referenceValueValue = (SweQuantity) referenceValue.getAbstractDataComponent();
        String identifier = hProcedure.getIdentifier() + REFERENCE_VALUE;
        SosProcedureDescription<?> procedureReferenceSeries = new SosProcedureDescriptionUnknownType(identifier, procedureDescriptionFormat.getFormat(), "");
        procedureReferenceSeries.setReference(true);
        procedureReferenceSeries.setName(new CodeType(referenceValue.getName()));
        ProcedureEntity hProcedureReferenceSeries = getDaoFactory().getProcedureDAO().getOrInsertProcedure(identifier, procedureDescriptionFormat, procedureReferenceSeries, false, session);
        OfferingEntity hOfferingReferenceSeries = getDaoFactory().getOfferingDAO().getAndUpdateOrInsert(new SosOffering(hOffering.getIdentifier() + REFERENCE_VALUE, hOffering.getName() + REFERENCE_VALUE), hRelatedFeatures, observationTypes, featureOfInterestTypes, session);
        TimeInstant time = new TimeInstant(new DateTime(0));
        SingleObservationValue<BigDecimal> sosValue = new SingleObservationValue<>(new QuantityValue(referenceValueValue.getValue(), referenceValueValue.getUom()));
        OmObservation sosObservation = new OmObservation();
        sosValue.setPhenomenonTime(time);
        sosObservation.setResultTime(time);
        sosObservation.setValue(sosValue);
        sosObservation.setObservationConstellation(new OmObservationConstellation(procedureReferenceSeries, new OmObservableProperty(hObservableProperty.getIdentifier()), sosFeatureOfInterest));
        DatasetEntity hObservationConstellationReferenceSeries = new DatasetEntity();
        hObservationConstellationReferenceSeries.setObservableProperty(hObservableProperty);
        hObservationConstellationReferenceSeries.setOffering(hOfferingReferenceSeries);
        hObservationConstellationReferenceSeries.setProcedure(hProcedureReferenceSeries);
        Map<String, CodespaceEntity> codespaceCache = CollectionHelper.synchronizedMap();
        Map<UoM, UnitEntity> unitCache = CollectionHelper.synchronizedMap();
        Map<String, FormatEntity> formatCache = CollectionHelper.synchronizedMap();
        ObservationPersister persister = new ObservationPersister(getDaoFactory(), getDaoFactory().getObservationDAO(), sosObservation, hObservationConstellationReferenceSeries, hFeature, codespaceCache, unitCache, formatCache, Collections.singleton(hOfferingReferenceSeries), session);
        DataEntity<?> observation = sosValue.getValue().accept(persister);
        DatasetEntity hReferenceSeries = seriesDAO.getSeries(hProcedureReferenceSeries.getIdentifier(), hObservableProperty.getIdentifier(), hOfferingReferenceSeries.getIdentifier(), Collections.singleton(hFeature.getIdentifier()), session).get(0);
        hReferenceSeries.setPublished(false);
        session.update(hReferenceSeries);
        ObservationContext ctxReferenced = new ObservationContext();
        ctxReferenced.setPhenomenon(hObservableProperty);
        ctxReferenced.setFeatureOfInterest(hFeature);
        ctxReferenced.setProcedure(hProcedure);
        ctxReferenced.setOffering(hOffering);
        ctxReferenced.setPublish(false);
        DatasetEntity hSeries = seriesDAO.getOrInsertSeries(ctxReferenced, observation, session);
        if (hSeries.getValueType().equals(ValueType.quantity)) {
            hSeries.setReferenceValues(Lists.newArrayList(hReferenceSeries));
        }
        session.update(hSeries);
    }
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) OmObservation(org.n52.shetland.ogc.om.OmObservation) CodespaceEntity(org.n52.series.db.beans.CodespaceEntity) DateTime(org.joda.time.DateTime) ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) UoM(org.n52.shetland.ogc.UoM) ObservationPersister(org.n52.sos.ds.hibernate.dao.observation.ObservationPersister) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) SosOffering(org.n52.shetland.ogc.sos.SosOffering) UnitEntity(org.n52.series.db.beans.UnitEntity) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty) SmlCapability(org.n52.shetland.ogc.sensorML.elements.SmlCapability) FormatEntity(org.n52.series.db.beans.FormatEntity) DatasetEntity(org.n52.series.db.beans.DatasetEntity) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation) BigDecimal(java.math.BigDecimal) AbstractSensorML(org.n52.shetland.ogc.sensorML.AbstractSensorML) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) SosProcedureDescriptionUnknownType(org.n52.shetland.ogc.sos.SosProcedureDescriptionUnknownType) CodeType(org.n52.shetland.ogc.gml.CodeType) ObservationContext(org.n52.sos.ds.hibernate.dao.observation.ObservationContext) OfferingEntity(org.n52.series.db.beans.OfferingEntity) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Aggregations

CodespaceEntity (org.n52.series.db.beans.CodespaceEntity)6 DatasetEntity (org.n52.series.db.beans.DatasetEntity)3 FormatEntity (org.n52.series.db.beans.FormatEntity)3 Session (org.hibernate.Session)2 Transaction (org.hibernate.Transaction)2 OfferingEntity (org.n52.series.db.beans.OfferingEntity)2 ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)2 ResultTemplateEntity (org.n52.series.db.beans.ResultTemplateEntity)2 UnitEntity (org.n52.series.db.beans.UnitEntity)2 UoM (org.n52.shetland.ogc.UoM)2 OmObservation (org.n52.shetland.ogc.om.OmObservation)2 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)2 SingleObservationValue (org.n52.shetland.ogc.om.SingleObservationValue)2 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 PersistenceException (javax.persistence.PersistenceException)1 Criteria (org.hibernate.Criteria)1 HibernateException (org.hibernate.HibernateException)1