Search in sources :

Example 6 with FeatureEntity

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

the class HibernateFeatureQueryHandlerTest method create.

public FeatureEntity create(long id, String identifier, Geometry geom, String name, String url, FormatEntity type) throws CodedException {
    FeatureEntity featureOfInterest = new FeatureEntity();
    featureOfInterest.setIdentifier(identifier);
    featureOfInterest.setId(id);
    // featureOfInterest.setNames(name);
    featureOfInterest.setGeometry(geom);
    featureOfInterest.setUrl(url);
    featureOfInterest.setFeatureType(type);
    return featureOfInterest;
}
Also used : FeatureEntity(org.n52.series.db.beans.FeatureEntity)

Example 7 with FeatureEntity

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

the class HibernateFeatureQueryHandlerTest method shouldCreateValidModelDomainFeature.

@Test
public void shouldCreateValidModelDomainFeature() throws OwsExceptionReport {
    Session session = getSession();
    try {
        final String id = "id";
        final String type = SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_POINT;
        FeatureEntity feature = create(1, id, null, "name", "url", createFeatureOfInterestType(1L, type));
        String version = Sos2Constants.SERVICEVERSION;
        AbstractFeature result = featureQueryHandler.createSosAbstractFeature(feature, new FeatureQueryHandlerQueryObject(session).setVersion(version));
        final AbstractFeature expectedResult = SamplingFeatureBuilder.aSamplingFeature().setFeatureType(type).setIdentifier(id).build();
        assertThat(expectedResult, is(result));
    } catch (HibernateException he) {
        throw new NoApplicableCodeException().causedBy(he);
    } finally {
        returnSession(session);
    }
}
Also used : FeatureEntity(org.n52.series.db.beans.FeatureEntity) HibernateException(org.hibernate.HibernateException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) Session(org.hibernate.Session) FeatureQueryHandlerQueryObject(org.n52.sos.ds.FeatureQueryHandlerQueryObject) Test(org.junit.Test)

Example 8 with FeatureEntity

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

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

the class GetFeatureOfInterestHandler method createFeature.

private AbstractFeature createFeature(AbstractFeatureEntity feature) throws InvalidSridException, OwsExceptionReport {
    final SamplingFeature sampFeat = new SamplingFeature(new CodeWithAuthority(feature.getIdentifier()));
    if (feature.isSetName()) {
        sampFeat.addName(feature.getName());
    }
    if (!Strings.isNullOrEmpty(feature.getDescription())) {
        sampFeat.setDescription(feature.getDescription());
    }
    if (feature.isSetGeometry() && !feature.getGeometryEntity().isEmpty()) {
        sampFeat.setGeometry(getGeometryHandler().switchCoordinateAxisFromToDatasourceIfNeeded(feature.getGeometryEntity().getGeometry()));
    }
    final Set<FeatureEntity> parentFeatures = feature.getParents();
    if (parentFeatures != null && !parentFeatures.isEmpty()) {
        final List<AbstractFeature> sampledFeatures = new ArrayList<>(parentFeatures.size());
        for (final FeatureEntity parentFeature : parentFeatures) {
            sampledFeatures.add(createFeature(parentFeature));
        }
        sampFeat.setSampledFeatures(sampledFeatures);
    }
    return sampFeat;
}
Also used : AbstractFeatureEntity(org.n52.series.db.beans.AbstractFeatureEntity) FeatureEntity(org.n52.series.db.beans.FeatureEntity) ArrayList(java.util.ArrayList) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority)

Example 10 with FeatureEntity

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

the class ServiceUtils method createFeatureOfInterest.

static AbstractFeatureEntity<?> createFeatureOfInterest(LocationEntity location) {
    FeatureEntity featureOfInterest = new FeatureEntity();
    featureOfInterest.setIdentifier(location.getIdentifier());
    featureOfInterest.setStaIdentifier(location.getStaIdentifier());
    // Used to distinguish in FeatureOfInterestService
    featureOfInterest.setXml("autogenerated");
    featureOfInterest.setName(location.getName());
    featureOfInterest.setDescription(location.getDescription());
    featureOfInterest.setGeometryEntity(location.getGeometryEntity());
    featureOfInterest.setFeatureType(createFeatureType(location.getGeometry()));
    return featureOfInterest;
}
Also used : AbstractFeatureEntity(org.n52.series.db.beans.AbstractFeatureEntity) FeatureEntity(org.n52.series.db.beans.FeatureEntity)

Aggregations

FeatureEntity (org.n52.series.db.beans.FeatureEntity)19 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)8 AbstractFeatureEntity (org.n52.series.db.beans.AbstractFeatureEntity)7 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)7 HibernateException (org.hibernate.HibernateException)6 Session (org.hibernate.Session)6 ArrayList (java.util.ArrayList)5 SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)5 Test (org.junit.Test)4 Geometry (org.locationtech.jts.geom.Geometry)4 FeatureDao (org.n52.series.db.dao.FeatureDao)4 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)4 DatasetEntity (org.n52.series.db.beans.DatasetEntity)3 FeatureQueryHandlerQueryObject (org.n52.sos.ds.FeatureQueryHandlerQueryObject)3 HashMap (java.util.HashMap)2 Set (java.util.Set)2 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)2 DataAccessException (org.n52.series.db.DataAccessException)2 FormatEntity (org.n52.series.db.beans.FormatEntity)2 DbQuery (org.n52.series.db.dao.DbQuery)2