Search in sources :

Example 1 with MultiDatastream

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

the class DateTimeTests method createEntities.

private static void createEntities() throws ServiceFailureException, URISyntaxException {
    Thing thing = new Thing("Thing 1", "The first thing.");
    THINGS.add(thing);
    Location location = new Location("Location 1.0", "Location of Thing 1.", "application/vnd.geo+json", new Point(8, 51));
    thing.getLocations().add(location);
    service.create(thing);
    Sensor sensor = new Sensor("Sensor 1", "The first sensor.", "text", "Some metadata.");
    ObservedProperty obsProp = new ObservedProperty("Temperature", new URI("http://ucom.org/temperature"), "The temperature of the thing.");
    MultiDatastream datastream = new MultiDatastream("Datastream 1", "The temperature of thing 1, sensor 1.", Arrays.asList("someType"), Arrays.asList(new UnitOfMeasurement("degree celcius", "°C", "ucum:T")));
    datastream.setThing(thing);
    datastream.setSensor(sensor);
    datastream.getObservedProperties().add(obsProp);
    service.create(datastream);
    MULTI_DATASTREAMS.add(datastream);
    // 0
    createObservation(0, datastream, T600, T600, null);
    // 1
    createObservation(1, datastream, T659, T659, null);
    // 2
    createObservation(2, datastream, T700, T700, null);
    // 3
    createObservation(3, datastream, T701, T701, null);
    // 4
    createObservation(4, datastream, T759, T759, null);
    // 5
    createObservation(5, datastream, T800, T800, null);
    // 6
    createObservation(6, datastream, T801, T801, null);
    // 7
    createObservation(7, datastream, T900, T900, null);
    // 8
    createObservation(8, datastream, I600_659, null, I600_659);
    // 9
    createObservation(9, datastream, I600_700, null, I600_700);
    // 10
    createObservation(10, datastream, I600_701, null, I600_701);
    // 11
    createObservation(11, datastream, I700_800, null, I700_800);
    // 12
    createObservation(12, datastream, I701_759, null, I701_759);
    // 13
    createObservation(13, datastream, I759_900, null, I759_900);
    // 14
    createObservation(14, datastream, I800_900, null, I800_900);
    // 15
    createObservation(15, datastream, I801_900, null, I801_900);
    // 16
    createObservation(16, datastream, I659_801, null, I659_801);
    // 17
    createObservation(17, datastream, I700_759, null, I700_759);
    // 18
    createObservation(18, datastream, I700_801, null, I700_801);
    // 19
    createObservation(19, datastream, I659_800, null, I659_800);
    // 20
    createObservation(20, datastream, I701_800, null, I701_800);
    // 21
    createObservation(21, datastream, T2015, T2015, null);
    // 22
    createObservation(22, datastream, T2017, T2017, null);
    // 23
    createObservation(23, datastream, I2015, T2015, I2015);
    // 24
    createObservation(24, datastream, I2017, T2017.plus(1, ChronoUnit.HOURS), I2017);
    // A second Datastream, with no observations.
    MultiDatastream datastream2 = new MultiDatastream("Datastream 2", "The second temperature of thing 1, sensor 1.", Arrays.asList("someType"), Arrays.asList(new UnitOfMeasurement("degree celcius", "°C", "ucum:T")));
    datastream2.setThing(thing);
    datastream2.setSensor(sensor);
    datastream2.getObservedProperties().add(obsProp);
    service.create(datastream2);
    MULTI_DATASTREAMS.add(datastream2);
}
Also used : UnitOfMeasurement(de.fraunhofer.iosb.ilt.sta.model.ext.UnitOfMeasurement) ObservedProperty(de.fraunhofer.iosb.ilt.sta.model.ObservedProperty) MultiDatastream(de.fraunhofer.iosb.ilt.sta.model.MultiDatastream) Point(org.geojson.Point) URI(java.net.URI) Thing(de.fraunhofer.iosb.ilt.sta.model.Thing) Location(de.fraunhofer.iosb.ilt.sta.model.Location) Sensor(de.fraunhofer.iosb.ilt.sta.model.Sensor)

Example 2 with MultiDatastream

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

the class MultiDatastreamTests method test09ObservationLinks1.

@Test
public void test09ObservationLinks1() throws ServiceFailureException {
    LOGGER.info("  test09ObservationLinks1");
    // First Observation should have a Datastream but not a MultiDatasteam.
    Observation fetchedObservation = service.observations().find(OBSERVATIONS.get(0).getId());
    Datastream fetchedDatastream = fetchedObservation.getDatastream();
    String message = "Observation has wrong or no Datastream";
    Assert.assertEquals(message, DATASTREAMS.get(0), fetchedDatastream);
    MultiDatastream fetchedMultiDatastream = fetchedObservation.getMultiDatastream();
    message = "Observation should not have a MultiDatastream";
    Assert.assertEquals(message, null, fetchedMultiDatastream);
}
Also used : MultiDatastream(de.fraunhofer.iosb.ilt.sta.model.MultiDatastream) Datastream(de.fraunhofer.iosb.ilt.sta.model.Datastream) Observation(de.fraunhofer.iosb.ilt.sta.model.Observation) MultiDatastream(de.fraunhofer.iosb.ilt.sta.model.MultiDatastream) Test(org.junit.Test)

Example 3 with MultiDatastream

use of de.fraunhofer.iosb.ilt.sta.model.MultiDatastream in project SensorThingsProcessor by FraunhoferIOSB.

the class Service method findDataArrayValue.

private void findDataArrayValue(Entity ds, Observation o) {
    DataArrayValue dav = davMap.get(ds);
    if (dav == null) {
        if (ds instanceof Datastream) {
            dav = new DataArrayValue((Datastream) ds, getDefinedProperties(o));
        } else {
            dav = new DataArrayValue((MultiDatastream) ds, getDefinedProperties(o));
        }
        davMap.put(ds, dav);
    }
    lastDav = dav;
    lastDatastream = ds;
}
Also used : MultiDatastream(de.fraunhofer.iosb.ilt.sta.model.MultiDatastream) Datastream(de.fraunhofer.iosb.ilt.sta.model.Datastream) DataArrayValue(de.fraunhofer.iosb.ilt.sta.model.ext.DataArrayValue) MultiDatastream(de.fraunhofer.iosb.ilt.sta.model.MultiDatastream)

Example 4 with MultiDatastream

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

the class ControllerCleaner method cleanMultiDatastreams.

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

Example 5 with MultiDatastream

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

the class AggregationData method checkReference.

private void checkReference(MultiDatastream aggregate, String expectedAggFor, AggregationLevel level, String aggSourceKey, Object aggSourceId) {
    Map<String, Object> properties = aggregate.getProperties();
    if (properties == null) {
        properties = new HashMap<>();
        aggregate.setProperties(properties);
    }
    boolean changed = false;
    changed = changed | checkProperty(properties, Utils.KEY_AGGREGATE_AMOUNT, level.amount);
    changed = changed | checkProperty(properties, Utils.KEY_AGGREGATE_UNIT, level.unit.toString());
    if (aggSourceKey != null) {
        changed = changed | checkProperty(properties, aggSourceKey, aggSourceId);
    }
    String aggFor = Objects.toString(properties.get(Utils.KEY_AGGREGATE_FOR));
    if (!expectedAggFor.equals(aggFor)) {
        if (fixReferences) {
            LOGGER.info("Setting source reference for {} to {}.", aggregate.getName(), expectedAggFor);
            properties.put(Utils.KEY_AGGREGATE_FOR, expectedAggFor);
            changed = true;
        } else {
            LOGGER.info("Source reference for {} not correct. Should be {}.", aggregate.getName(), expectedAggFor);
        }
    }
    if (changed && fixReferences) {
        try {
            MultiDatastream copy = aggregate.withOnlyId();
            copy.setProperties(aggregate.getProperties());
            copy.setMultiObservationDataTypes(null);
            copy.setUnitOfMeasurements(null);
            service.update(copy);
        } catch (ServiceFailureException ex) {
            LOGGER.error("Failed to update reference.", ex);
        }
    }
}
Also used : MultiDatastream(de.fraunhofer.iosb.ilt.sta.model.MultiDatastream) ServiceFailureException(de.fraunhofer.iosb.ilt.sta.ServiceFailureException)

Aggregations

MultiDatastream (de.fraunhofer.iosb.ilt.sta.model.MultiDatastream)23 Datastream (de.fraunhofer.iosb.ilt.sta.model.Datastream)12 Test (org.junit.Test)9 ObservedProperty (de.fraunhofer.iosb.ilt.sta.model.ObservedProperty)8 ServiceFailureException (de.fraunhofer.iosb.ilt.sta.ServiceFailureException)7 Thing (de.fraunhofer.iosb.ilt.sta.model.Thing)7 Observation (de.fraunhofer.iosb.ilt.sta.model.Observation)6 ArrayList (java.util.ArrayList)6 Sensor (de.fraunhofer.iosb.ilt.sta.model.Sensor)5 Location (de.fraunhofer.iosb.ilt.sta.model.Location)4 UnitOfMeasurement (de.fraunhofer.iosb.ilt.sta.model.ext.UnitOfMeasurement)4 Point (org.geojson.Point)4 FeatureOfInterest (de.fraunhofer.iosb.ilt.sta.model.FeatureOfInterest)3 URI (java.net.URI)3 StatusCodeException (de.fraunhofer.iosb.ilt.sta.StatusCodeException)2 ProcessException (de.fraunhofer.iosb.ilt.stp.ProcessException)2 Matcher (java.util.regex.Matcher)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ControllerEntity (de.fraunhofer.iosb.ilt.sensorthingsmanager.controller.ControllerEntity)1