Search in sources :

Example 1 with FeatureOfInterest

use of de.fraunhofer.iosb.ilt.sta.model.FeatureOfInterest in project FROST-Server by FraunhoferIOSB.

the class AdditionalTests method testRecreateAutomaticFoi.

@Test
public void testRecreateAutomaticFoi() throws ServiceFailureException {
    LOGGER.info("  testRecreateAutomaticFoi");
    EntityUtils.deleteAll(service);
    // Create two things
    Location location1 = new Location("LocationThing1", "Location of Thing 1", "application/geo+json", new Point(8, 50));
    service.create(location1);
    Thing thing1 = new Thing("Thing 1", "The first thing.");
    thing1.getLocations().add(location1.withOnlyId());
    service.create(thing1);
    Sensor sensor1 = new Sensor("Test Thermometre", "Test Sensor", "None", "-");
    service.create(sensor1);
    ObservedProperty obsProp1 = new ObservedProperty("Temperature", "http://example.org", "-");
    service.create(obsProp1);
    Datastream datastream1 = new Datastream("Ds 1, Thing 1", "The datastream of Thing 1", "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement", new UnitOfMeasurement("Degrees Celcius", "°C", "http://qudt.org/vocab/unit#DegreeCelsius"));
    datastream1.setThing(thing1);
    datastream1.setSensor(sensor1);
    datastream1.setObservedProperty(obsProp1);
    service.create(datastream1);
    Observation obs1 = new Observation(1.0, datastream1);
    service.create(obs1);
    FeatureOfInterest foiGenerated1 = service.observations().find(obs1.getId()).getFeatureOfInterest();
    Assert.assertNotNull(foiGenerated1);
    service.delete(foiGenerated1);
    Observation obs2 = new Observation(1.0, datastream1);
    service.create(obs2);
    FeatureOfInterest foiGenerated2 = service.observations().find(obs2.getId()).getFeatureOfInterest();
    Assert.assertNotNull(foiGenerated2);
    Assert.assertNotEquals(foiGenerated1, foiGenerated2);
}
Also used : Datastream(de.fraunhofer.iosb.ilt.sta.model.Datastream) UnitOfMeasurement(de.fraunhofer.iosb.ilt.sta.model.ext.UnitOfMeasurement) ObservedProperty(de.fraunhofer.iosb.ilt.sta.model.ObservedProperty) FeatureOfInterest(de.fraunhofer.iosb.ilt.sta.model.FeatureOfInterest) Observation(de.fraunhofer.iosb.ilt.sta.model.Observation) Point(org.geojson.Point) Thing(de.fraunhofer.iosb.ilt.sta.model.Thing) HistoricalLocation(de.fraunhofer.iosb.ilt.sta.model.HistoricalLocation) Location(de.fraunhofer.iosb.ilt.sta.model.Location) Sensor(de.fraunhofer.iosb.ilt.sta.model.Sensor) Test(org.junit.Test)

Example 2 with FeatureOfInterest

use of de.fraunhofer.iosb.ilt.sta.model.FeatureOfInterest in project FROST-Server by FraunhoferIOSB.

the class AdditionalTests method testMultipleLocations.

/**
 * Check the creation of a FoI on Observation creation, for Things that have
 * multiple Locations, only one of which is a geoJson location.
 *
 * @throws ServiceFailureException If the service doesn't respond.
 */
@Test
public void testMultipleLocations() throws ServiceFailureException {
    LOGGER.info("  testMultipleLocations");
    EntityUtils.deleteAll(service);
    Thing thing = new Thing("Thing 1", "The first thing.");
    Location location1 = new Location("Location 1.0, Address", "The address of Thing 1.", "text/plain", "");
    thing.getLocations().add(location1);
    Location location2 = new Location("Location 1.0", "Location of Thing 1.", "application/geo+json", new Point(8, 51));
    thing.getLocations().add(location2);
    Location location3 = new Location("Location 1.0, Directions", "How to find Thing 1 in human language.", "text/plain", "");
    thing.getLocations().add(location3);
    service.create(thing);
    THINGS.add(thing);
    Sensor sensor = new Sensor("Sensor 1", "The first sensor.", "text", "Some metadata.");
    ObservedProperty obsProp = new ObservedProperty("Temperature", "http://ucom.org/temperature", "The temperature of the thing.");
    Datastream datastream = new Datastream("Datastream 1", "The temperature of thing 1, sensor 1.", "someType", new UnitOfMeasurement("degree celcius", "°C", "ucum:T"));
    datastream.setSensor(sensor);
    datastream.setObservedProperty(obsProp);
    datastream.setThing(thing);
    service.create(datastream);
    DATASTREAMS.add(datastream);
    ObservationDao doa = service.observations();
    Observation observation = new Observation(1.0, DATASTREAMS.get(0));
    doa.create(observation);
    OBSERVATIONS.add(observation);
    Observation found;
    found = doa.find(observation.getId());
    FeatureOfInterest featureOfInterest = found.getFeatureOfInterest();
    Assert.assertNotNull("A FeatureOfInterest should have been generated, but got NULL.", featureOfInterest);
}
Also used : Datastream(de.fraunhofer.iosb.ilt.sta.model.Datastream) UnitOfMeasurement(de.fraunhofer.iosb.ilt.sta.model.ext.UnitOfMeasurement) ObservedProperty(de.fraunhofer.iosb.ilt.sta.model.ObservedProperty) FeatureOfInterest(de.fraunhofer.iosb.ilt.sta.model.FeatureOfInterest) ObservationDao(de.fraunhofer.iosb.ilt.sta.dao.ObservationDao) Observation(de.fraunhofer.iosb.ilt.sta.model.Observation) Point(org.geojson.Point) Thing(de.fraunhofer.iosb.ilt.sta.model.Thing) HistoricalLocation(de.fraunhofer.iosb.ilt.sta.model.HistoricalLocation) Location(de.fraunhofer.iosb.ilt.sta.model.Location) Sensor(de.fraunhofer.iosb.ilt.sta.model.Sensor) Test(org.junit.Test)

Example 3 with FeatureOfInterest

use of de.fraunhofer.iosb.ilt.sta.model.FeatureOfInterest in project FROST-Server by FraunhoferIOSB.

the class GeoTests method createLocation2.

private static void createLocation2() throws ServiceFailureException {
    // Locations 2
    Point gjo = new Point(8, 53);
    Location location = new Location("Location 2", "Location of Thing 2.", "application/vnd.geo+json", gjo);
    location.getThings().add(THINGS.get(1));
    service.create(location);
    LOCATIONS.add(location);
    FeatureOfInterest featureOfInterest = new FeatureOfInterest("FoI 2", "This should be FoI #2.", "application/geo+json", gjo);
    service.create(featureOfInterest);
    FEATURESOFINTEREST.add(featureOfInterest);
    Observation o = new Observation(3, DATASTREAMS.get(1));
    o.setFeatureOfInterest(featureOfInterest);
    o.setPhenomenonTimeFrom(ZonedDateTime.parse("2016-01-03T01:01:01.000Z"));
    o.setValidTime(Interval.of(Instant.parse("2016-01-03T01:01:01.000Z"), Instant.parse("2016-01-03T23:59:59.999Z")));
    service.create(o);
    OBSERVATIONS.add(o);
}
Also used : FeatureOfInterest(de.fraunhofer.iosb.ilt.sta.model.FeatureOfInterest) Observation(de.fraunhofer.iosb.ilt.sta.model.Observation) Point(org.geojson.Point) Location(de.fraunhofer.iosb.ilt.sta.model.Location)

Example 4 with FeatureOfInterest

use of de.fraunhofer.iosb.ilt.sta.model.FeatureOfInterest in project FROST-Server by FraunhoferIOSB.

the class GeoTests method createLocation3.

private static void createLocation3() throws ServiceFailureException {
    // Locations 3
    Point gjo = new Point(8, 54);
    Location location = new Location("Location 3", "Location of Thing 3.", "application/vnd.geo+json", gjo);
    location.getThings().add(THINGS.get(2));
    service.create(location);
    LOCATIONS.add(location);
    FeatureOfInterest featureOfInterest = new FeatureOfInterest("FoI 3", "This should be FoI #3.", "application/geo+json", gjo);
    service.create(featureOfInterest);
    FEATURESOFINTEREST.add(featureOfInterest);
    Observation o = new Observation(4, DATASTREAMS.get(2));
    o.setFeatureOfInterest(featureOfInterest);
    o.setPhenomenonTimeFrom(ZonedDateTime.parse("2016-01-04T01:01:01.000Z"));
    o.setValidTime(Interval.of(Instant.parse("2016-01-04T01:01:01.000Z"), Instant.parse("2016-01-04T23:59:59.999Z")));
    service.create(o);
    OBSERVATIONS.add(o);
}
Also used : FeatureOfInterest(de.fraunhofer.iosb.ilt.sta.model.FeatureOfInterest) Observation(de.fraunhofer.iosb.ilt.sta.model.Observation) Point(org.geojson.Point) Location(de.fraunhofer.iosb.ilt.sta.model.Location)

Example 5 with FeatureOfInterest

use of de.fraunhofer.iosb.ilt.sta.model.FeatureOfInterest in project FROST-Manager by FraunhoferIOSB.

the class ControllerCleaner method cleanFeatures.

private void cleanFeatures() throws ServiceFailureException {
    LOGGER.info("Cleaning Features");
    EntityList<FeatureOfInterest> list = service.featuresOfInterest().query().select("name", "id").expand("Observations($select=id;$top=1)").orderBy("id asc").list();
    long count = 0;
    long toDel = 0;
    List<FeatureOfInterest> toDelete = new ArrayList<>();
    Iterator<FeatureOfInterest> it;
    for (it = list.fullIterator(); it.hasNext(); ) {
        FeatureOfInterest next = it.next();
        count++;
        logStatusCleaner.setFeatures(count);
        if (next.getObservations().isEmpty()) {
            toDelete.add(next);
            logStatusCleaner.setToDelete(++toDel);
        }
    }
    LOGGER.info("Deleting {} FeaturesOfInterest", toDelete.size());
    for (FeatureOfInterest item : toDelete) {
        logStatusCleaner.setToDelete(--toDel);
        service.delete(item.withOnlyId());
    }
}
Also used : FeatureOfInterest(de.fraunhofer.iosb.ilt.sta.model.FeatureOfInterest) ArrayList(java.util.ArrayList)

Aggregations

FeatureOfInterest (de.fraunhofer.iosb.ilt.sta.model.FeatureOfInterest)18 Location (de.fraunhofer.iosb.ilt.sta.model.Location)13 Observation (de.fraunhofer.iosb.ilt.sta.model.Observation)12 Point (org.geojson.Point)11 Datastream (de.fraunhofer.iosb.ilt.sta.model.Datastream)7 ObservedProperty (de.fraunhofer.iosb.ilt.sta.model.ObservedProperty)5 Sensor (de.fraunhofer.iosb.ilt.sta.model.Sensor)5 Thing (de.fraunhofer.iosb.ilt.sta.model.Thing)5 IdString (de.fraunhofer.iosb.ilt.sta.model.IdString)4 MultiDatastream (de.fraunhofer.iosb.ilt.sta.model.MultiDatastream)4 UnitOfMeasurement (de.fraunhofer.iosb.ilt.sta.model.ext.UnitOfMeasurement)4 LngLatAlt (org.geojson.LngLatAlt)4 Test (org.junit.Test)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ServiceFailureException (de.fraunhofer.iosb.ilt.sta.ServiceFailureException)3 HistoricalLocation (de.fraunhofer.iosb.ilt.sta.model.HistoricalLocation)3 HttpResponse (de.fraunhofer.iosb.ilt.statests.util.HTTPMethods.HttpResponse)3 IOException (java.io.IOException)3 LineString (org.geojson.LineString)3