Search in sources :

Example 1 with CategoryEntity

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

the class CategoryDAO method getOrInsertCategory.

public CategoryEntity getOrInsertCategory(SweText sweText, Session session) {
    CategoryEntity category = getCategoryForIdentifier(sweText.getValue(), session);
    if (category == null) {
        category = new CategoryEntity();
        addIdentifier(category, sweText.getValue(), session);
        addName(category, sweText.getName(), session);
        addDescription(category, sweText.getDescription());
        session.save(category);
        session.flush();
        session.refresh(category);
    }
    return category;
}
Also used : CategoryEntity(org.n52.series.db.beans.CategoryEntity)

Example 2 with CategoryEntity

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

the class InsertResultHandler method insertObservationConstellationForProfiles.

private DatasetEntity insertObservationConstellationForProfiles(AbstractSeriesDAO obsConstDao, FormatDAO obsTypeDao, OmObservation o, Session session) throws OwsExceptionReport {
    ProcedureEntity procedure = getDaoFactory().getProcedureDAO().getProcedureForIdentifier(o.getObservationConstellation().getProcedureIdentifier(), session);
    PhenomenonEntity observableProperty = getDaoFactory().getObservablePropertyDAO().getOrInsertObservableProperty(o.getObservationConstellation().getObservableProperty(), session);
    OfferingEntity offering = getDaoFactory().getOfferingDAO().getOfferingForIdentifier(o.getObservationConstellation().getOfferings().iterator().next(), session);
    CategoryEntity category = getDaoFactory().getCategoryDAO().getOrInsertCategory(observableProperty, session);
    DatasetEntity oc = obsConstDao.checkOrInsertSeries(procedure, observableProperty, offering, category, false, session);
    if (o.getObservationConstellation().isSetObservationType()) {
        oc.setOmObservationType(obsTypeDao.getFormatEntityObject(o.getObservationConstellation().getObservationType(), session));
    }
    return oc;
}
Also used : ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) DatasetEntity(org.n52.series.db.beans.DatasetEntity) PhenomenonEntity(org.n52.series.db.beans.PhenomenonEntity) OfferingEntity(org.n52.series.db.beans.OfferingEntity) CategoryEntity(org.n52.series.db.beans.CategoryEntity)

Example 3 with CategoryEntity

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

the class HibernateObservationBuilder method getCategory.

protected CategoryEntity getCategory() {
    CategoryEntity category = (CategoryEntity) session.createCriteria(CategoryEntity.class).add(Restrictions.eq(CategoryEntity.IDENTIFIER, CATEGORY)).uniqueResult();
    if (category == null) {
        category = new CategoryEntity();
        category.setDescription(CATEGORY);
        category.setIdentifier(CATEGORY);
        session.save(category);
        session.flush();
    }
    return category;
}
Also used : CategoryEntity(org.n52.series.db.beans.CategoryEntity)

Example 4 with CategoryEntity

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

use of org.n52.series.db.beans.CategoryEntity in project sensorweb-server-sta by 52North.

the class ObservationService method createEntity.

@Override
public ObservationEntity<?> createEntity(ObservationEntity<?> entity) throws STACRUDException {
    synchronized (getLock(entity.getStaIdentifier())) {
        ObservationEntity observation = entity;
        if (!observation.isProcessed()) {
            observation.setProcessed(true);
            check(observation);
            DatastreamEntity datastream = getDatastreamService().createEntity(observation.getDatastream());
            observation.setDatastream(datastream);
            // Fetch with all needed associations
            datastream = datastreamRepository.findByStaIdentifier(datastream.getStaIdentifier(), EntityGraphRepository.FetchGraph.FETCHGRAPH_THINGLOCATION, EntityGraphRepository.FetchGraph.FETCHGRAPH_PROCEDURE, EntityGraphRepository.FetchGraph.FETCHGRAPH_UOM, EntityGraphRepository.FetchGraph.FETCHGRAPH_OBS_TYPE, EntityGraphRepository.FetchGraph.FETCHGRAPH_OBSERVABLE_PROP, EntityGraphRepository.FetchGraph.FETCHGRAPH_DATASETS).orElseThrow(() -> new STACRUDException("Unable to find Datastream!"));
            AbstractFeatureEntity<?> feature = checkFeature(observation, datastream);
            // category (obdProp)
            CategoryEntity category = checkCategory();
            // offering (sensor)
            OfferingEntity offering = checkOffering(datastream);
            // dataset
            DatasetEntity dataset = checkDataset(datastream, feature, category, offering);
            // observation
            ObservationEntity<?> data = checkData(observation, dataset);
            if (data != null) {
                updateDataset(dataset, data);
                updateDatastream(datastream, dataset, data);
            }
            return data;
        }
        return observation;
    }
}
Also used : DatasetEntity(org.n52.series.db.beans.DatasetEntity) DatastreamEntity(org.n52.series.db.beans.sta.DatastreamEntity) CategoryObservationEntity(org.n52.series.db.beans.sta.CategoryObservationEntity) QuantityObservationEntity(org.n52.series.db.beans.sta.QuantityObservationEntity) TextObservationEntity(org.n52.series.db.beans.sta.TextObservationEntity) BooleanObservationEntity(org.n52.series.db.beans.sta.BooleanObservationEntity) ObservationEntity(org.n52.series.db.beans.sta.ObservationEntity) CountObservationEntity(org.n52.series.db.beans.sta.CountObservationEntity) OfferingEntity(org.n52.series.db.beans.OfferingEntity) STACRUDException(org.n52.shetland.ogc.sta.exception.STACRUDException) CategoryEntity(org.n52.series.db.beans.CategoryEntity)

Aggregations

CategoryEntity (org.n52.series.db.beans.CategoryEntity)10 DatasetEntity (org.n52.series.db.beans.DatasetEntity)4 OfferingEntity (org.n52.series.db.beans.OfferingEntity)4 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)3 ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)3 Session (org.hibernate.Session)2 Transaction (org.hibernate.Transaction)2 FormatEntity (org.n52.series.db.beans.FormatEntity)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Criteria (org.hibernate.Criteria)1 HibernateException (org.hibernate.HibernateException)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1 BindingRepository (org.n52.iceland.binding.BindingRepository)1 CodespaceEntity (org.n52.series.db.beans.CodespaceEntity)1 DataEntity (org.n52.series.db.beans.DataEntity)1 FeatureEntity (org.n52.series.db.beans.FeatureEntity)1 PlatformEntity (org.n52.series.db.beans.PlatformEntity)1