Code Monkey home page Code Monkey logo

frost-client-dynamic's Introduction

Frost-Client Build Status codecov Codacy Badge

FROST-Client Logo

The FRaunhofer Opensource SensorThings-Client-Dynamic is a Java-based client library for the SensorThingsAPI and other data models. It aims to simplify development of SensorThings enabled client applications.

Features

  • CRUD operations
  • Queries on entity sets
  • Loading of referenced entities
  • MultiDatastreams
  • Tasking
  • STA plus

Unsupported

  • Batch requests
  • dataArray (for requesting observations)
  • MQTT

Using with maven

Add the dependency:

<dependency>
    <groupId>de.fraunhofer.iosb.ilt</groupId>
    <artifactId>FROST-Client-Dynamic</artifactId>
    <version>2.12</version>
</dependency>

Using with gradle

Add the dependency:

compile 'de.fraunhofer.iosb.ilt:FROST-Client-Dynamic:2.12'

API

The SensorThingsService class is central to the library. An instance of it represents a SensorThings service and is identified by an URI. This class needs to be initialised with a data model, but if initialised without a model it will try to figure out the model automatically. Data models for the SensorThings API exist, but you can also create your own data models.

CRUD operations

The source code below demonstrates the CRUD operations for Thing objects. Operations for other entities work similarly.

SensorThingsSensingV11 modelSensing = new SensorThingsSensingV11();
SensorThingsTaskingV11 modelTasking = new SensorThingsTaskingV11();
URL serviceEndpoint = new URL("http://example.org/v1.0/");
SensorThingsService service = new SensorThingsService(serviceEndpoint, modelSensing, modelTasking);
Entity thing = new Entity(modelSensing.etThing)
    .setProperty(SensorThingsSensingV11.EP_NAME, "Thingything")
    .setProperty(SensorThingsSensingV11.EP_DESCRIPTION, "I'm a thing!")
service.create(thing);

// get Thing with numeric id 1234
thing = service.dao(modelSensing.etThing).find(1234l);
// get Thing with String id ab12cd
thing = service.dao(modelSensing.etThing).find("ab12cd");

thing.setDescription("Things change...");
service.update(thing);

service.delete(thing);

Entity Sets

Entity Sets are represented by instances of EntityList<>. The query parameters specified by the SensorThingsAPI standard can be applied to queries.

EntitySet things = service.query(modelSensing.etThing)
                            .count()
                            .orderBy("description")
                            .select("name","id","description")
                            .filter("")
                            .expand()
                            .skip(5)
                            .top(10)
                            .list();

for (Entity thing : things) {
    System.out.println("So many things!");
}

Entity sets only load so many entities at a time, but the iterator will automatically load more entities when more entities exist on the server. To get only the currently loaded entities, use the toList() method to get the List of currently loaded entites.

List<Entity> observations = service.query(modelSensing.etObservation)
                            .count()
                            .top(1000)
                            .list()
                            .toList();

for (Entity obs : observations) {
    // Only the loaded Observations...
    System.out.println("Observation " + obs.getId() + " has result " + obs.getResult());
}

Related entity sets can also be queried.

// Get the thing with ID 1
Entity thing = service.dao(modelSensing.etThing).find(1l);

// Get the Datastreams of this Thing
EntitySet dataStreams = thing.query(modelSensing.npThingDatastreams).list();
for (Entity dataStream : dataStreams) {
    Entity sensor = dataStream.getProperty(modelSensing.npDatastreamSensor);
    System.out.println("dataStream " + dataStream.getId() + " has Sensor " + sensor.getId());
}

Loading referenced objects

Loading referenced objects in one operation (and therefore in one request) is supported. The $expand option of the SensorThingsAPI standard is used internally.

EntitySet things = service.query(modelSensing.etThing)
        .expand("Locations($select=name,encodingType,location)")
        .list();
for (entity Thing : things) {
    EntitySet locations = thing.getProperty(modelSensing.npThingLocations);
}

Contributing

Contributions are welcome!

  1. Fork this repository
  2. Commit your changes
  3. Create a pull request

License

The code and the documentation of this work is available under the MIT license.

frost-client-dynamic's People

Contributors

hylkevds avatar dependabot[bot] avatar

Watchers

James Cloos avatar  avatar ๐Ÿ‘จโ€๐Ÿ’ป avatar  avatar

frost-client-dynamic's Issues

How to use?

I am not too familiar with usage of java applications.
Also I do not find in the project a file, which would look like main executable file of Client-Dynamic.
Should I "compile" it myself?
Are there Instructions somewhere, how to make it running on Windows?
Is the client already working?

Thanks,
Kind regards,
Pavel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.