Giter Club home page Giter Club logo

open-data-service-v1's Introduction

New version (v2) available here: https://www.github.com/jvalue/open-data-service

Open Data Service

The Open Data Service (ODS) is Java server application which can collect data from multiple sources simulataneously, process that data and then offer an improved (or "cleaned") version to its clients.

It is currently actively being used for gathering water level information about rivers and Germany and by the Android application Pegel Alarm (available also on GitHub).

Modules

The ODS is divided into a number of gradle modules:

  • server: the main server application, built using Dropwizard
  • models: domain models
  • client-retrofit: a Java client implementation for the REST API of the ODS

Setup

The ODS uses Apache CouchDb as its underlying data storage. In oder to run the ODS you will need to have CouchDb setup.

To configure the ODS copy server/ods-configuration.yml.template to server/ods-configuration.yml and supply the missing values:

  • gcmApiKey: the ODS allows clients to receive updates about new data via Google Cloud Messaging (GCM). To enable this feature you will need to enter your GCM Api key here
  • couchdb username and couchdb password: admin credentials for CouchDb
  • auth: the ODS supports two types of authentication mechanisms: basic (username + password) and via Google's OAuth
    • basic: to add users which use basic auth simply add the corresponding details to the users section under auth
    • OAuth: to setup OAuth you will need to create a new project in the Google Developer Console and one client id for a web application (that is the ODS) and additional client ids for each client that should communicate with the ODS. Then copy the created client ids to googleOAuthWebClientId and googleOAuthClientIds respectively.

Once done you should be able to run

./gradlew run (Windows users use the .bat version)

which first downloads all required dependencies and then starts the ODS. The server should be be running at http://localhost:8080/ods/api/v1 and http://localhost:8080/ods/api/v2.

Docker

An easy way to use the ODS is via a pre build Docker image. Therefore use docker-compose to start the ODS Docker container and its dependent services.

docker-compose -f docker/docker-compose.yml up

You can find prebuild Docker images in the following container registry: GitLab Container Registry

Building a Docker Image

You can build a local Docker image from source files using the Gradle task ./gradlew dockerBuild. To run the local image with docker-compose call:

docker-compose -f docker/docker-compose.yml -f docker/docker-compose.local.yml up

Usage of API v1

The ODS uses a REST API for communicating with clients of all kinds, be it end users or admins. The basic usage of the api follows the template /someObjects/{objectId}/someProperty and is always relative to the base url you have defined in the ods-configuration.yml file.

The two 'concepts' that are most important in the context of the ODS are sources and filter chains.

Sources are available at /datasources and represent a collection of data, meta data, filter chains and update listeners.

Filter chains are located 'below' sources at /datasources/{sourceId}/filterChains and represent processing chains which fetch, manipulate and finally store data on the ODS.

To get a feeling for how this API works and which parameters are supported, you can

  • take a look at the implementation of the REST api
  • have a look at this Postman collection
  • or start working with the Java client implementation (see below)

In order for the Postman collection to work, Postman needs to know a couple of things (e.g. passwords, urls, etc.), which can be set by importing a so called environment file that looks like this:

{
	"id": "b9d8ff70-9540-e7c6-e423-d8cd74d9c6e3",
	"name": "localhost",
	"values": [
		{
			"key": "ods_base_url",
			"value": "http://localhost:8080/ods/api/v1",
			"type": "text",
			"name": "ods_base_url",
			"enabled": true
		},
		{
			"key": "ods_admin_username",
			"value": "[email protected]",
			"type": "text",
			"name": "ods_admin_username",
			"enabled": true
		},
		{
			"key": "ods_admin_password",
			"value": "admin123",
			"type": "text",
			"name": "ods_admin_password",
			"enabled": true
		}
	],
	"timestamp": 1429550360212,
	"synced": false,
	"syncedFilename": ""
}

To import those variables, save the above JSON in a file and click the environment button at the top of Postman.

Usage of API v2

The current API of the ODS (v2) implements the JSON API specification to ensure a standardized data exchange format. Therefore, all HTTP requests containing a message body must contain the content-type header field with value "application/vnd.api+json".
Most of the v1 endpoints still remain but, since they are mutually linked, you can explore the API by simply clicking through it. On the base path of API v2 you will find an entry point from which each endpoint is reachable.

Getting Started

Please see PegelOnline-Example.md for an introduction on how to use ODS.

Swagger

Another way of exploring the API is via Swagger. By executing the above mentioned docker-compose command (docker-compose -f docker/docker-compose.yml -f docker/docker-compose.local.yml up) Swagger-UI will be started and can be reached via localhost:8082.

Postman

If you prefer using postman to get to know the API, there is also a Postman Collection and a Environment File adapted to API v2. Remember to declare the content-type as "application/vnd.api+json".

Client implementation (for API v1)

If you want to start working the ODS and don't mind Java, you can use the client lib that comes with the ODS. The library was created using JaxRs2Retrofit and is available on bintray. For gradle builds:

repositories {
  jcenter()
}

dependencies {
  compile 'org.jvalue.ods:client-retrofit:0.1.3'
}

For an example usage please refer to the test cases or take a look at Pegel Alarm.

Test cases

The are two types of tests in this repo: unit tests and integration tests. The unit tests are available under {module}/src/test and can be run via ./gradlew test and the integration tests can be found at {module}/src/integrationtest and can be run via ./gradlew integrationTest. Please note that the integration tests assume that CouchDB and the ODS are running locally with default settings.

Health checks

The ODS has a number of health checks which ensure that a running instance of the ODS conforms to the requirements of the Pegel Alarm application. To see the output of those health checks simply go to /{adminContextPath}/healthcheck. The default config for localhost is http://localhost:8081/healthcheck.

Additional information about filter and adapter

License

Copyright 2014-2019 Friedrich-Alexander Universität Erlangen-Nürnberg

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.gnu.org/licenses/.

SPDX-License-Identifier: AGPL-3.0-only

open-data-service-v1's People

Contributors

andreas-bauer avatar cythey avatar dannglk avatar dknogl avatar dvahle avatar faupat avatar georg-schwarz avatar jlink avatar maddoc42 avatar mathiaszinnen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

open-data-service-v1's Issues

QA filters break on internal error in pegelonline

QA filter throws exception (1) when pegelonline source is experiencing an internal error (2)

(1)

java.lang.NullPointerException at org.jvalue.ods.qa.improvement.CombineSourceFilter.filter(CombineSourceFilter.java:74)
at org.jvalue.ods.qa.improvement.CombineSourceFilter.filter(CombineSourceFilter.java:48)
at org.jvalue.ods.filter.FilterChain.filter(FilterChain.java:49)
at org.jvalue.ods.filter.FilterChain.filter(FilterChain.java:50)
at org.jvalue.ods.filter.FilterChainManager.startFilterChains(FilterChainManager.java:63)
at org.jvalue.ods.grabber.DataGrabberMain.updateData(DataGrabberMain.java:64)
at org.jvalue.ods.server.ContainerRestletApp.run(ContainerRestletApp.java:118)
at java.lang.Thread.run(Thread.java:744)

(2)
http://pegelonline.wsv.de/webservices/rest-api/v2/stations.json

currently (18.07.14 12:52) returns

{
   status: 500,
   message: "Internal server error. Please retry."
}

Offer ODS version via REST Api

Api could / should offer two version counts

  • current build (automatically increased?)
  • release version (incremented manually on each larger release)

Filter should not modify original data

No filter should be able to modify the callers data.

For example if there are two filters A --> B, then A should create a copy of the data before forwarding it to B.

Offer pagination for admin log

The content of

/admin/logs

keeps growing and is not limited by any size restrictions.

Instead of one log with all entries offer some pagination mechanism for fetching only the most recent entries.

Builder for defining source schema definitions

Source schema definitions (how data is available in the original source and how it will be stored in the DB) are currently created by manually by constructing large nested map and list objects.

When wanting to create these schemata dynamically at runtime, having a builder object that takes care on the internal referencing makes constructing this definition at lot easier.

--> Create a builder class for constructing schema, eliminating the need for manual linking

Queries in REST-API

Allow simple key-value-queries

f.e.: ods/stations?timeseries.measurement.level=10

Extract parts of documents

Clients should again be able to extract parts of all kinds of documents.

with $1234 being the ID of the document, water/coordinate two of its fields:
GET /ods/$1234/water
GET /ods/$1234/water/longname
GET /ods/$1234/coordinate
GET /ods/$1234/coordinate/longitude
... as deep as they want (except lists)

The ugly, former previously used code can be found here:
https://github.com/jvalue/open-data-service/blob/76299da9d021fe1775118c008343ec66da9fb1be/src/main/java/org/jvalue/ods/server/restlet/DefaultRestlet.java

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.