Skip to content

Commit

Permalink
Work in progress: now went to cloud foundry and cloudant.
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtdb committed Feb 11, 2016
1 parent d14e0bd commit 704d380
Show file tree
Hide file tree
Showing 19 changed files with 446 additions and 55 deletions.
8 changes: 8 additions & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
applications:
- name: boks-run
memory: 320MB
instances: 1
path: target/run-0.0.1-SNAPSHOT.jar
services:
- boks-run-cloudant
26 changes: 9 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<ektorp.version>1.4.2</ektorp.version>
<commons.lang3.version>3.4</commons.lang3.version>
</properties>

<dependencies>
Expand All @@ -41,8 +43,14 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
<version>${commons.lang3.version}</version>
</dependency>
<dependency>
<groupId>org.ektorp</groupId>
<artifactId>org.ektorp.spring</artifactId>
<version>${ektorp.version}</version>
</dependency>

</dependencies>

<build>
Expand All @@ -51,22 +59,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.3.8</version>
<configuration>
<imageName>boksrun/${project.artifactId}</imageName>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.war</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>

</build>
Expand Down
19 changes: 0 additions & 19 deletions src/main/docker/dockerfile

This file was deleted.

31 changes: 31 additions & 0 deletions src/main/java/be/boks/RunApplication.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@
package be.boks;

import java.io.IOException;

import org.ektorp.CouchDbConnector;
import org.ektorp.CouchDbInstance;
import org.ektorp.http.HttpClient;
import org.ektorp.http.StdHttpClient;
import org.ektorp.impl.StdCouchDbConnector;
import org.ektorp.impl.StdCouchDbInstance;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class RunApplication {

private static final String DATABASE_NAME = "boks-run";
@Value("${vcap.services.boks-run-cloudant.credentials.host:}")
private String host;
@Value("${vcap.services.boks-run-cloudant.credentials.username:}")
private String username;
@Value("${vcap.services.boks-run-cloudant.credentials.password:}")
private String password;

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

@Bean
public CouchDbConnector couchDb() throws IOException {
HttpClient httpClient = new StdHttpClient.Builder()
.url("https://" + host).port(443).username(username)
.password(password).build();

CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);

CouchDbConnector db = new StdCouchDbConnector(DATABASE_NAME, dbInstance);
db.createDatabaseIfNotExists();

return db;
}
}

42 changes: 42 additions & 0 deletions src/main/java/be/boks/domain/Club.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package be.boks.domain;

import java.io.Serializable;

import org.springframework.data.annotation.Id;

public class Club implements Serializable {

private static final long serialVersionUID = -1535672487981334177L;

@Id
private Long id;

private String name;

private String type = "club";

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

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

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

}
22 changes: 18 additions & 4 deletions src/main/java/be/boks/domain/Runner.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package be.boks.domain;

import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;

Expand All @@ -8,7 +9,10 @@
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.springframework.data.annotation.Id;

public class Runner {
public class Runner implements Serializable {

private static final long serialVersionUID = 2530453437671327658L;

@Id
private Long id;

Expand All @@ -26,7 +30,7 @@ public class Runner {

private String city;

private String runningClub;
private Club runningClub;

private List<Category> categories;

Expand All @@ -36,6 +40,8 @@ public class Runner {

private List<Time> times;

private String type = "runner";

public Long getId() {
return id;
}
Expand Down Expand Up @@ -96,11 +102,11 @@ public void setCity(String city) {
this.city = city;
}

public String getRunningClub() {
public Club getRunningClub() {
return runningClub;
}

public void setRunningClub(String runningClub) {
public void setRunningClub(Club runningClub) {
this.runningClub = runningClub;
}

Expand Down Expand Up @@ -136,6 +142,14 @@ public void setTimes(List<Time> times) {
this.times = times;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

@Override
public int hashCode() {
HashCodeBuilder builder = new HashCodeBuilder();
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/be/boks/domain/Time.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class Time {

private Category category;

private String type = "time";

public Long getId() {
return id;
}
Expand Down Expand Up @@ -41,6 +43,13 @@ public Category getCategory() {
public void setCategory(Category category) {
this.category = category;
}


public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

}
12 changes: 12 additions & 0 deletions src/main/java/be/boks/repository/ClubRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package be.boks.repository;

import java.util.List;

import org.ektorp.support.GenericRepository;

import be.boks.domain.Club;

public interface ClubRepository extends GenericRepository<Club> {

List<Club> getClubs();
}
32 changes: 32 additions & 0 deletions src/main/java/be/boks/repository/ClubRepositoryImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package be.boks.repository;

import java.util.List;

import org.ektorp.CouchDbConnector;
import org.ektorp.support.CouchDbRepositorySupport;
import org.ektorp.support.View;
import org.ektorp.support.Views;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import be.boks.domain.Club;

@Repository
@Views({
@View(name = "all", map = "function(doc) { if (doc.type == 'club' ) emit( null, doc )}")
})
public class ClubRepositoryImpl extends CouchDbRepositorySupport<Club> implements ClubRepository {

@Autowired
public ClubRepositoryImpl(CouchDbConnector db) {
super(Club.class, db);
initStandardDesignDocument();
}

@Override
public List<Club> getClubs() {
return queryView("all");
}


}
12 changes: 4 additions & 8 deletions src/main/java/be/boks/repository/RunnerRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

import java.util.List;

import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import org.ektorp.support.GenericRepository;

import be.boks.domain.Runner;

@Repository
public interface RunnerRepository extends MongoRepository<Runner, Long> {

public List<Runner> findByFirstNameAndLastName(String firstName, String lastName);

public List<Runner> findByLastName(String lastName);
public interface RunnerRepository extends GenericRepository<Runner> {

List<Runner> getAll();
}
31 changes: 31 additions & 0 deletions src/main/java/be/boks/repository/RunnerRepositoryImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package be.boks.repository;

import java.util.List;

import org.ektorp.CouchDbConnector;
import org.ektorp.support.CouchDbRepositorySupport;
import org.ektorp.support.View;
import org.ektorp.support.Views;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import be.boks.domain.Runner;

@Repository
@Views({
@View(name = "all", map = "function(doc) { if (doc.type == 'runner' ) emit( null, doc )}")
})
public class RunnerRepositoryImpl extends CouchDbRepositorySupport<Runner> implements RunnerRepository {


@Autowired
public RunnerRepositoryImpl(CouchDbConnector db) {
super(Runner.class, db);
initStandardDesignDocument();
}

@Override
public List<Runner> getAll() {
return queryView("all");
}
}
14 changes: 14 additions & 0 deletions src/main/java/be/boks/rest/ClubController.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
package be.boks.rest;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import be.boks.domain.Club;
import be.boks.service.ClubService;

@RestController
@RequestMapping("/club")
public class ClubController {

private static final Logger LOGGER = LoggerFactory.getLogger(ClubController.class);

@Autowired
private ClubService clubService;

@RequestMapping(method=RequestMethod.GET)
public List<Club> getClubs() {
LOGGER.info("Getting the clubs information.");
return clubService.getAll();
}
}
Loading

0 comments on commit 704d380

Please sign in to comment.