Skip to content
This repository was archived by the owner on Jan 22, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions watsonml-java-proxy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
*#
*.iml
*.ipr
*.iws
*.jar
*.sw?
*~
.#*
.*.md.html
.DS_Store
.classpath
.factorypath
.gradle
.idea
.metadata
.project
.recommenders
.settings
.springBeans
/build
/code
MANIFEST.MF
_site/
activemq-data
bin
build
build.log
dependency-reduced-pom.xml
dump.rdb
interpolated*.xml
lib/
manifest.yml
overridedb.*
settings.xml
target
transaction-logs
.flattened-pom.xml
secrets.yml
.gradletasknamecache
.sts4-cache
117 changes: 117 additions & 0 deletions watsonml-java-proxy/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.ibm</groupId>
<artifactId>watsonml</artifactId>
<version>1.0-SNAPSHOT</version>

<packaging>war</packaging>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- logging -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<!-- connection pooling -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>

<!-- swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
<scope>compile</scope>
</dependency>

<!-- test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-couchbase</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>

<!-- IBM Cloudant -->
<dependency>
<groupId>com.cloudant</groupId>
<artifactId>cloudant-client</artifactId>
<version>2.12.0</version>
</dependency>

<!-- IBM push notification -->
<dependency>
<groupId>com.ibm.mobilefirstplatform.serversdk.java</groupId>
<artifactId>push</artifactId>
<version>1.1.0</version>
</dependency>

</dependencies>

<properties>
<java.version>1.8</java.version>
</properties>


<build>

<finalName>watsonml</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.ibm.watsonml;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.AsyncRestTemplate;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
public class Application {


public static void main(String[] args) {
SpringApplication.run(Application.class,args);
}


/**
* Rest template configuration
* @param builder
* @return
*/
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
return builder.build();
}

@Bean
AsyncRestTemplate asyncRestTemplate() {
return new AsyncRestTemplate();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.ibm.watsonml.controller;


import com.ibm.watsonml.service.ScoreEntryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;

@RestController
@RequestMapping("/avatar")
public class AvatarController {


Logger log = LoggerFactory.getLogger(this.getClass().getName());


@Autowired
private ScoreEntryService scoreEntryService;


@GetMapping("/leaderboardAvatar/{id}")
public CompletableFuture<byte[]> getLeaderBoardAvatar(@PathVariable String id){

CompletableFuture<byte[]> media = new CompletableFuture<>();
try {
media = scoreEntryService.getLeaderBoardAvatar(id);
} catch (InterruptedException e) {
log.error("Not able to get image bytes");
media.completeExceptionally(e);
}

return media;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.ibm.watsonml.controller;


import com.ibm.watsonml.model.ScoreEntry;
import com.ibm.watsonml.model.UserCount;
import com.ibm.watsonml.service.ScoreEntryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.concurrent.CompletableFuture;

@RestController
@RequestMapping("/watsonml")
public class ScoreEntryController {

Logger log = LoggerFactory.getLogger(this.getClass().getName());


@Autowired
private ScoreEntryService scoreEntryService;


@PostMapping("/entries")
public CompletableFuture<ScoreEntry> saveUserData(HttpServletRequest request, @RequestBody ScoreEntry scoreEntry) {
log.debug("REST request to save user score");
CompletableFuture<ScoreEntry> entries = new CompletableFuture<>();
try {
entries.complete(scoreEntryService.saveUserScore(scoreEntry).get());
} catch (Exception e) {
log.error("Error while making external API call {}", e);
entries.completeExceptionally(e);
}
return entries;
}

@PutMapping("/entries/{identifier}")
public CompletableFuture<ScoreEntry> updateUserData(@RequestBody ScoreEntry scoreEntry,@PathVariable String identifier) {
log.debug("REST request to update user score");
CompletableFuture<ScoreEntry> entries = new CompletableFuture<>();
try {
entries.complete(scoreEntryService.updateUserScore(scoreEntry).get());
} catch (Exception e) {
log.error("Error while making external API call {}", e);
entries.completeExceptionally(e);
}
return entries;
}


@GetMapping("/leaderboard")
public CompletableFuture<List<ScoreEntry>> getLeaderBoard() {
log.debug("REST request to get leaderboard");
CompletableFuture<List<ScoreEntry>> entries = new CompletableFuture<>();
try {
entries.complete(scoreEntryService.getLeaderBoard().get());
} catch (Exception e) {
log.error("Error while making external API call {}", e);
entries.completeExceptionally(e);
}
return entries;
}

@GetMapping("/leaderboard/{id}")
public CompletableFuture<List<ScoreEntry>> getLeaderBoardForUser(@PathVariable String id) {
log.debug("REST request to get leaderboard");
CompletableFuture<List<ScoreEntry>> entries = new CompletableFuture<>();
try {
entries.complete(scoreEntryService.getLeaderBoard(id).get());
} catch (Exception e) {
log.error("Error while making external API call {}", e);
entries.completeExceptionally(e);
}
return entries;
}


@GetMapping("/user/counts")
public CompletableFuture<UserCount> getTotaUsersCount() {
log.debug("REST request to get leaderboard");
CompletableFuture<UserCount> entries = new CompletableFuture<>();
try {
entries.complete(scoreEntryService.getUserCount().get());
} catch (Exception e) {
log.error("Error while making external API call {}", e);
entries.completeExceptionally(e);
}
return entries;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.ibm.watsonml.model;

import java.io.Serializable;
import java.math.BigDecimal;

public class IdentifiedObjects implements Serializable{

private String name;
private BigDecimal timestamp;


public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public BigDecimal getTimestamp() {
return timestamp;
}

public void setTimestamp(BigDecimal timestamp) {
this.timestamp = timestamp;
}
}
Loading