Skip to content

Commit bfb35f7

Browse files
committed
Initial java SDK commit
1 parent 10cdc34 commit bfb35f7

23 files changed

+1368
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/target
2+
/.settings
3+
/.classpath
4+
/.project
5+
16
*.class
27

38
# Mobile Tools for Java (J2ME)

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
language: java
2+

README.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Databox Java SDK
2+
3+
[![Build Status](https://travis-ci.org/databox/databox-java.png?branch=master)](https://travis-ci.org/databox/databox-java)
4+
5+
The Java SDK for interacting with the Databox Push API.
6+
7+
## Features
8+
9+
* Built on top of a solid and extensively tested framework [Apache HttpComponents](http://hc.apache.org/)
10+
* Uses Java library to convert JSON to Java objects and vice-versa [google-gson](https://code.google.com/p/google-gson)
11+
* Tested and well-documented
12+
13+
## Requirements
14+
15+
* Java >= 1.5 or later,
16+
* Maven >= 3.0.3 (optional but highly recomended)
17+
18+
## Maven supported
19+
20+
Add a maven repository to your pom file:
21+
```xml
22+
<repository>
23+
<id>umajeric-public-repo</id>
24+
<name>Umajeric Releases</name>
25+
<releases>
26+
<enabled>true</enabled>
27+
</releases>
28+
<snapshots>
29+
<enabled>false</enabled>
30+
</snapshots>
31+
<url>https://raw.github.com/umajeric/maven-public-repo/releases</url>
32+
</repository>
33+
```
34+
35+
Then add a dependency for Databox Custom DataSource artefact (see [here](https://github.com/umajeric/maven-public-repo/tree/releases/com/databox/custom-datasource-sdk) to find the latest version):
36+
```xml
37+
<dependency>
38+
<groupId>com.databox</groupId>
39+
<artifactId>custom-datasource-sdk</artifactId>
40+
<version>LATEST</version>
41+
</dependency>
42+
```
43+
44+
## Basic usage of the Databox's `custom-datasource-sdk` client
45+
46+
Most basic sample:
47+
48+
```java
49+
DataSink<DataboxDataSource> sink = new DataboxSink();
50+
51+
String accessToken = "hd32o1ga8sf7sad0fu9sdufs8440442kj2";
52+
DataboxDataSource dataSource = new DataboxDataSource(accessToken);
53+
54+
DefaultDataProvider dataProvider = new DefaultDataProvider();
55+
dataProvider.addKPI(new KPI.Builder().setKey("new_signups").setValue(234D).withAttribute("no_of_items", 12).build());
56+
dataProvider.addKPI(new KPI.Builder().setKey("new_signups").setValue(234D).build());
57+
dataSource.addDataProvider(dataProvider);
58+
59+
sink.push(dataSource);
60+
```
61+
62+
One more advanced example (XSLDailyDataProvider implements DataProvider interface) that reads data from [Excel file](https://github.com/umajeric/databox-java-sdk/blob/master/sample/src/main/resources/cycling.xlsx):
63+
64+
```java
65+
DataboxSink sink = new DataboxSink();
66+
List<DataboxDataSource> dataSources = new ArrayList<DataboxDataSource>();
67+
68+
String accessToken = "hd32o1ga8sf7sad0fu9sdufs8440442kj2";
69+
DataboxDataSource dataSource = new DataboxDataSource(accessToken);
70+
71+
XSLDailyDataProvider xlsxDataProvider = new XSLDailyDataProvider("cycling.xlsx");
72+
dataSource.addDataProvider(xlsxDataProvider);
73+
/* You can implement your own data provider that implements DataProvider interface */
74+
// dataSource.addDataProvider(new MyCustomDataProviderImpl());
75+
dataSources.add(dataSource);
76+
77+
/* For each data source we add a separate connection to the sink (each uses a different API Key and URL postfix) */
78+
// dataSource2 = new DataboxDataSource("5r4w91ga8sf7sad0fu9sdufs844044");
79+
/* We can use the same data provider for different connections */
80+
// dataSource2.addDataProvider(xlsxDataProvider);
81+
// dataSources.add(dataSource2);
82+
83+
for (DataSource ds : dataSources) {
84+
sink.push(ds);
85+
}
86+
87+
```
88+
89+
Snippet from excel file:
90+
91+
|Date |Total Time |Moving Time |Distance |Distance Unit |Average Speed |Max Speed |Speed Unit|
92+
| -------:| ------:| ------:| ------:|:------ | ------:| ------:|:------|
93+
|7/6/13 | 56 | 56 | 27.00 | km | 28.93 | 34.00 | km/h |
94+
|7/7/13 | 34 | 34 | 13 | km | 22.94 | 30 | km/h |
95+
|7/8/13 | 56 | 56 | 23 | km | 24.54 | 38 | km/h |
96+
|7/9/13 | 63 | 63 | 28 | km | 26.67 | 35 | km/h |
97+
|7/10/13 | 22 | 22 | 9 | km | 24.55 | 35 | km/h |
98+
99+
100+
101+
More examples can be found here [Example project](https://github.com/umajeric/databox-java-sdk/tree/master/sample)
102+
103+
## Documentation
104+
105+
See [wiki page](https://github.com/umajeric/databox-java-sdk/wiki) for additional documentation.
106+
107+
## License
108+
109+
Databox `databox-java` is licensed under the Apache License, Version 2.0 - see the [LICENSE](http://www.apache.org/licenses/LICENSE-2.0) file for details
110+
111+
### Contributors & Credits
112+
113+
- [Uros Majeric](http://github.com/umajeric)
114+

pom.xml

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.databox</groupId>
5+
<artifactId>custom-datasource-sdk</artifactId>
6+
<version>1.1.1-SNAPSHOT</version>
7+
<name>custom-datasource-sdk</name>
8+
<description>The Java SDK for interacting with the Databox Push API.</description>
9+
<packaging>jar</packaging>
10+
11+
<licenses>
12+
<license>
13+
<name>The Apache Software License, Version 2.0</name>
14+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
15+
<distribution>repo</distribution>
16+
</license>
17+
</licenses>
18+
19+
<properties>
20+
<java.source.version>1.6</java.source.version>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<junit.version>4.10</junit.version>
23+
</properties>
24+
25+
<scm>
26+
<connection>scm:git:ssh://[email protected]/umajeric/databox-java-sdk.git</connection>
27+
<developerConnection>scm:git:ssh://[email protected]/umajeric/databox-java-sdk.git</developerConnection>
28+
<url>https://github.com/umajeric/databox-java-sdk.git</url>
29+
<tag>HEAD</tag>
30+
</scm>
31+
32+
<distributionManagement>
33+
<repository>
34+
<id>umajeric-git-maven-public-releases</id>
35+
<name>UMajeric Releases</name>
36+
<url>git:releases://[email protected]:umajeric/maven-public-repo.git</url>
37+
</repository>
38+
<snapshotRepository>
39+
<id>umajeric-git-maven-public-snapshots</id>
40+
<name>UMajeric Snapshots</name>
41+
<url>git:snapshots://[email protected]:umajeric/maven-public-repo.git</url>
42+
</snapshotRepository>
43+
</distributionManagement>
44+
45+
<repositories>
46+
<repository>
47+
<id>java.net</id>
48+
<url>https://maven.java.net/content/repositories/public/</url>
49+
</repository>
50+
<repository>
51+
<id>mave-repo-1</id>
52+
<url>http://repo.maven.apache.org/maven2/</url>
53+
</repository>
54+
<repository>
55+
<id>umajeric-public-repo</id>
56+
<name>UMajeric Releases</name>
57+
<releases>
58+
<enabled>true</enabled>
59+
</releases>
60+
<snapshots>
61+
<enabled>false</enabled>
62+
</snapshots>
63+
<url>https://raw.github.com/umajeric/maven-public-repo/releases</url>
64+
</repository>
65+
</repositories>
66+
67+
<pluginRepositories>
68+
<pluginRepository>
69+
<id>synergian-repo</id>
70+
<url>https://raw.github.com/synergian/wagon-git/releases</url>
71+
</pluginRepository>
72+
</pluginRepositories>
73+
74+
<dependencies>
75+
<dependency>
76+
<groupId>com.google.code.gson</groupId>
77+
<artifactId>gson</artifactId>
78+
<version>2.2.4</version>
79+
</dependency>
80+
81+
<dependency>
82+
<groupId>org.apache.httpcomponents</groupId>
83+
<artifactId>httpclient</artifactId>
84+
<version>4.3.1</version>
85+
</dependency>
86+
87+
<dependency>
88+
<groupId>org.slf4j</groupId>
89+
<artifactId>slf4j-api</artifactId>
90+
<version>1.7.5</version>
91+
</dependency>
92+
93+
<!-- TEST scope dependencies -->
94+
<dependency>
95+
<groupId>junit</groupId>
96+
<artifactId>junit</artifactId>
97+
<version>${junit.version}</version>
98+
<scope>test</scope>
99+
</dependency>
100+
101+
<dependency>
102+
<groupId>ch.qos.logback</groupId>
103+
<artifactId>logback-classic</artifactId>
104+
<version>1.0.13</version>
105+
<scope>test</scope>
106+
</dependency>
107+
</dependencies>
108+
109+
<build>
110+
<plugins>
111+
<plugin>
112+
<groupId>org.apache.maven.plugins</groupId>
113+
<artifactId>maven-compiler-plugin</artifactId>
114+
<version>2.0.2</version>
115+
<configuration>
116+
<source>${java.source.version}</source>
117+
<target>${java.source.version}</target>
118+
<encoding>${project.build.sourceEncoding}</encoding>
119+
</configuration>
120+
</plugin>
121+
<plugin>
122+
<groupId>org.apache.maven.plugins</groupId>
123+
<artifactId>maven-jar-plugin</artifactId>
124+
<version>2.1</version>
125+
<configuration>
126+
<archive>
127+
<manifest>
128+
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
129+
</manifest>
130+
</archive>
131+
</configuration>
132+
</plugin>
133+
<plugin>
134+
<groupId>org.apache.maven.plugins</groupId>
135+
<artifactId>maven-release-plugin</artifactId>
136+
<version>2.4.2</version>
137+
<configuration>
138+
<goals>deploy</goals>
139+
<autoVersionSubmodules>true</autoVersionSubmodules>
140+
<releaseProfiles>release</releaseProfiles>
141+
</configuration>
142+
<dependencies>
143+
<dependency>
144+
<groupId>org.apache.maven.scm</groupId>
145+
<artifactId>maven-scm-api</artifactId>
146+
<version>1.8.1</version>
147+
</dependency>
148+
<dependency>
149+
<groupId>org.apache.maven.scm</groupId>
150+
<artifactId>maven-scm-provider-gitexe</artifactId>
151+
<version>1.8.1</version>
152+
</dependency>
153+
</dependencies>
154+
</plugin>
155+
</plugins>
156+
157+
<extensions>
158+
<extension>
159+
<groupId>ar.com.synergian</groupId>
160+
<artifactId>wagon-git</artifactId>
161+
<version>0.2.1</version>
162+
</extension>
163+
</extensions>
164+
</build>
165+
</project>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.databox;
2+
3+
import java.io.FileInputStream;
4+
import java.io.IOException;
5+
import java.util.Properties;
6+
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
10+
/**
11+
*
12+
* @author Uros Majeric
13+
*
14+
*/
15+
public class Environment {
16+
private static final Logger logger = LoggerFactory.getLogger(Environment.class);
17+
18+
public static Properties prop = new Properties();
19+
20+
static {
21+
try {
22+
prop.load(Environment.class.getClassLoader().getResourceAsStream("config.properties"));
23+
try {
24+
String configFile = System.getProperty("configFile");
25+
if (configFile != null && !configFile.isEmpty()) {
26+
prop.load(new FileInputStream(configFile));
27+
}
28+
} catch (IOException ex) {
29+
/* ignore if there is no override conf file - use defualts */
30+
logger.error("Configuration error: {}", ex.getLocalizedMessage());
31+
}
32+
} catch (IOException ex) {
33+
logger.error(ex.getLocalizedMessage(), ex);
34+
}
35+
}
36+
37+
public static String getDataboxBaseURL() {
38+
return prop.getProperty("databox-base-url");
39+
}
40+
41+
public static String getUserAgent() {
42+
return prop.getProperty("user-agent");
43+
}
44+
45+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.databox.sdk;
2+
3+
import java.util.Collection;
4+
5+
import com.databox.sdk.kpi.KPI;
6+
7+
/**
8+
*
9+
* This class serves as a KPI provider.
10+
*
11+
* @author Uros Majeric
12+
*
13+
*/
14+
public interface DataProvider {
15+
/**
16+
*
17+
* @return List of KPI's for data provider.
18+
*/
19+
public Collection<KPI> getKPIs();
20+
}

0 commit comments

Comments
 (0)