Skip to content

Commit ef0df86

Browse files
committed
Samples added
1 parent dc61486 commit ef0df86

File tree

7 files changed

+241
-0
lines changed

7 files changed

+241
-0
lines changed

sample/.gitignore

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

sample/pom.xml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.databox</groupId>
6+
<artifactId>java-push-sdk-sample</artifactId>
7+
<version>1.0.0-SNAPSHOT</version>
8+
<name>java-push-sdk-sample</name>
9+
<packaging>jar</packaging>
10+
11+
<properties>
12+
<java.source.version>1.6</java.source.version>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
<junit.version>4.10</junit.version>
15+
<databox-sdk.version>2.0.0-SNAPSHOT</databox-sdk.version>
16+
</properties>
17+
18+
<repositories>
19+
<repository>
20+
<id>java.net</id>
21+
<url>https://maven.java.net/content/repositories/public/</url>
22+
</repository>
23+
<repository>
24+
<id>mave-repo-1</id>
25+
<url>http://repo.maven.apache.org/maven2/</url>
26+
</repository>
27+
<repository>
28+
<id>umajeric-public-repo</id>
29+
<name>UMajeric Releases</name>
30+
<releases>
31+
<enabled>true</enabled>
32+
</releases>
33+
<snapshots>
34+
<enabled>false</enabled>
35+
</snapshots>
36+
<url>https://raw.github.com/umajeric/maven-public-repo/releases</url>
37+
</repository>
38+
</repositories>
39+
40+
<dependencies>
41+
<dependency>
42+
<groupId>com.databox</groupId>
43+
<artifactId>java-push-sdk</artifactId>
44+
<version>${databox-sdk.version}</version>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>ch.qos.logback</groupId>
49+
<artifactId>logback-classic</artifactId>
50+
<version>1.0.13</version>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>si.majeric</groupId>
55+
<artifactId>intercom-api-services</artifactId>
56+
<version>1.0.0</version>
57+
</dependency>
58+
59+
<dependency>
60+
<groupId>org.apache.poi</groupId>
61+
<artifactId>poi-ooxml</artifactId>
62+
<version>3.9</version>
63+
</dependency>
64+
65+
<!-- TEST scope dependencies -->
66+
<dependency>
67+
<groupId>junit</groupId>
68+
<artifactId>junit</artifactId>
69+
<version>${junit.version}</version>
70+
<scope>test</scope>
71+
</dependency>
72+
73+
</dependencies>
74+
75+
<build>
76+
<plugins>
77+
<plugin>
78+
<groupId>org.apache.maven.plugins</groupId>
79+
<artifactId>maven-compiler-plugin</artifactId>
80+
<version>2.0.2</version>
81+
<configuration>
82+
<source>${java.source.version}</source>
83+
<target>${java.source.version}</target>
84+
<encoding>${project.build.sourceEncoding}</encoding>
85+
</configuration>
86+
</plugin>
87+
<plugin>
88+
<groupId>org.apache.maven.plugins</groupId>
89+
<artifactId>maven-jar-plugin</artifactId>
90+
<version>2.1</version>
91+
<configuration>
92+
<archive>
93+
<manifest>
94+
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
95+
</manifest>
96+
</archive>
97+
</configuration>
98+
</plugin>
99+
</plugins>
100+
</build>
101+
</project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.databox.sdk.sample;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
import com.databox.sdk.DataSink;
7+
import com.databox.sdk.ResponseWrapper;
8+
import com.databox.sdk.impl.DataboxDataSource;
9+
import com.databox.sdk.impl.DataboxSink;
10+
11+
/**
12+
*
13+
* @author Uros Majeric
14+
*
15+
*/
16+
public class DataboxSample {
17+
private static final Logger logger = LoggerFactory.getLogger(DataboxSample.class);
18+
19+
public static void main(String[] args) throws Exception {
20+
String spaceAccessToken = "hd32o1ga8sf7sad0fu9sdufs8440442kj2";
21+
22+
DataSink<DataboxDataSource> sink = new DataboxSink();
23+
24+
DataboxDataSource connection = new DataboxDataSource(spaceAccessToken);
25+
XSLDailyDataProvider xlsxDataProvider = new XSLDailyDataProvider("cycling.xlsx");
26+
connection.addDataProvider(xlsxDataProvider);
27+
28+
// DefaultDataProvider dataProvider = new DefaultDataProvider();
29+
// Calendar c = new GregorianCalendar();
30+
// dataProvider.addKPI(new KPI.Builder().setKey("visits_this_month").setValue(234D).setDate(c.getTime()).build());
31+
// c.add(Calendar.DAY_OF_MONTH, -1);
32+
// dataProvider.addKPI(new KPI.Builder().setKey("visits_this_month").setValue(431D).build());
33+
// connection.addDataProvider(dataProvider);
34+
35+
ResponseWrapper response = sink.push(connection);
36+
if (!response.isSucceeded()) {
37+
logger.error(sink.getLogs(connection));
38+
} else {
39+
logger.info(response.getMessage());
40+
}
41+
}
42+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.databox.sdk.sample;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.util.Collection;
6+
import java.util.Date;
7+
import java.util.Iterator;
8+
9+
import org.apache.poi.ss.usermodel.Row;
10+
import org.apache.poi.xssf.usermodel.XSSFSheet;
11+
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
14+
15+
import com.databox.sdk.daily.impl.DailyDataProvider;
16+
import com.databox.sdk.kpi.KPI;
17+
18+
/**
19+
*
20+
* @author Uros Majeric
21+
*
22+
*/
23+
public class XSLDailyDataProvider extends DailyDataProvider {
24+
static final Logger logger = LoggerFactory.getLogger(XSLDailyDataProvider.class);
25+
26+
private final String _fileName;
27+
28+
public XSLDailyDataProvider(String fileName) {
29+
_fileName = fileName;
30+
}
31+
32+
@Override
33+
public Collection<KPI> getKPIs() {
34+
/* Lazy load data */
35+
if (this.data == null || this.data.isEmpty()) {
36+
try {
37+
read();
38+
} catch (IOException e) {
39+
logger.error(e.getLocalizedMessage(), e);
40+
}
41+
}
42+
return this.data;
43+
}
44+
45+
public void read() throws IOException {
46+
InputStream res = XSLDailyDataProvider.class.getClassLoader().getResourceAsStream(_fileName);
47+
48+
/* Get the workbook instance for XLS file */
49+
XSSFWorkbook workbook = new XSSFWorkbook(res);
50+
51+
/* Get first sheet from the workbook */
52+
XSSFSheet sheet = workbook.getSheetAt(0);
53+
54+
Iterator<Row> rowIterator = sheet.iterator();
55+
/* skip first row (titles) */
56+
rowIterator.next();
57+
58+
/* Iterate through each rows from first sheet */
59+
while (rowIterator.hasNext()) {
60+
Row row = rowIterator.next();
61+
Date date = row.getCell(0).getDateCellValue();
62+
63+
/* Get the value from the cell and add a KPI for it for matching date */
64+
double movingTime = row.getCell(2).getNumericCellValue();
65+
addKPI("moving_time", date, movingTime);
66+
67+
double distance = row.getCell(3).getNumericCellValue();
68+
addKPI("distance", date, distance);
69+
70+
double avgSpeed = row.getCell(5).getNumericCellValue();
71+
addKPI("average_speed", date, avgSpeed);
72+
73+
double maxSpeed = row.getCell(6).getNumericCellValue();
74+
addKPI("max_speed", date, maxSpeed);
75+
}
76+
}
77+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#config.properties in your application overrides the default values
2+
# databox-base-url=http://zep.com:8080
3+
databox-base-url=https://api.databox.com
4+
user-agent=My-Custom-Data-Connection/1.1
5.36 KB
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
4+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
5+
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
6+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
7+
</encoder>
8+
</appender>
9+
10+
<root level="info">
11+
<appender-ref ref="STDOUT" />
12+
</root>
13+
</configuration>

0 commit comments

Comments
 (0)