Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mark Needham
committed
Sep 9, 2014
1 parent
7fc999b
commit 790a9f4
Showing
27 changed files
with
11,500 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?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>neo4j-wcapp</groupId> | ||
<artifactId>neo4j-wcapp</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<properties> | ||
<dropwizard.version>0.7.0</dropwizard.version> | ||
<maven.compiler.source>1.7</maven.compiler.source> | ||
<maven.compiler.target>1.7</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.sun.jersey</groupId> | ||
<artifactId>jersey-client</artifactId> | ||
<version>1.18.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.googlecode.jcsv</groupId> | ||
<artifactId>jcsv</artifactId> | ||
<version>1.4.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.neo4j</groupId> | ||
<artifactId>neo4j</artifactId> | ||
<version>2.1.0-M01</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.googlecode.totallylazy</groupId> | ||
<artifactId>totallylazy</artifactId> | ||
<version>1049</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.dropwizard</groupId> | ||
<artifactId>dropwizard-core</artifactId> | ||
<version>${dropwizard.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.dropwizard</groupId> | ||
<artifactId>dropwizard-views</artifactId> | ||
<version>${dropwizard.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.dropwizard</groupId> | ||
<artifactId>dropwizard-views-freemarker</artifactId> | ||
<version>${dropwizard.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.dropwizard</groupId> | ||
<artifactId>dropwizard-assets</artifactId> | ||
<version>${dropwizard.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<repositories> | ||
<repository> | ||
<id>repo.bodar.com</id> | ||
<url>http://repo.bodar.com</url> | ||
</repository> | ||
|
||
<repository> | ||
<id>neo4j-maven</id> | ||
<name>neo4j maven</name> | ||
<url>http://m2.neo4j.org</url> | ||
</repository> | ||
</repositories> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>1.6</version> | ||
<configuration> | ||
<createDependencyReducedPom>true</createDependencyReducedPom> | ||
<filters> | ||
<filter> | ||
<artifact>*:*</artifact> | ||
<excludes> | ||
<exclude>META-INF/*.SF</exclude> | ||
<exclude>META-INF/*.DSA</exclude> | ||
<exclude>META-INF/*.RSA</exclude> | ||
</excludes> | ||
</filter> | ||
</filters> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>org.neo4j.wcapp.web.WorldCupApplication</mainClass> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>2.4</version> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.neo4j.wcapp.web; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.dropwizard.views.View; | ||
|
||
public class EventView extends View | ||
{ | ||
|
||
private JsonNode result; | ||
|
||
public EventView( JsonNode result ) | ||
{ | ||
super("event.ftl"); | ||
this.result = result; | ||
} | ||
|
||
public WorldCup getWorldCup() { | ||
String host = result.get( "data" ).get( 0 ).get( "row" ).get( 1 ).get( "name" ).asText(); | ||
int year = result.get( "data" ).get( 0 ).get( "row" ).get( 2 ).get( "year" ).asInt(); | ||
|
||
return new WorldCup( year, host ); | ||
} | ||
|
||
public List<Match> getMatches() { | ||
List<Match> matches = new ArrayList<>( ); | ||
|
||
JsonNode rows = result.get( "data" ); | ||
for ( JsonNode row : rows ) | ||
{ | ||
|
||
matches.add( new Match( row.get( "row" ).get( 0 ).get( "description" ).asText() ) ); | ||
} | ||
return matches; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.neo4j.wcapp.web; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ArrayNode; | ||
import io.dropwizard.views.View; | ||
|
||
public class HomeView extends View | ||
{ | ||
private JsonNode result; | ||
|
||
public HomeView( JsonNode result ) { | ||
super("home.ftl"); | ||
this.result = result; | ||
} | ||
|
||
public List<WorldCup> getWorldCups() { | ||
ArrayNode rows = (ArrayNode) result.get( "data" ); | ||
|
||
List<WorldCup> worldCups = new ArrayList<>( ); | ||
for ( JsonNode row : rows ) | ||
{ | ||
JsonNode wc = row.get( "row" ).get( 0 ); | ||
JsonNode host = row.get( "row" ).get( 1 ); | ||
worldCups.add( new WorldCup( wc.get( "year" ).asInt() , host.get( "name" ).asText() )); | ||
} | ||
|
||
return worldCups; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.neo4j.wcapp.web; | ||
|
||
public class Match | ||
{ | ||
|
||
private String description; | ||
|
||
public Match( String description ) | ||
{ | ||
|
||
this.description = description; | ||
} | ||
|
||
public String getDescription() | ||
{ | ||
return description; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.neo4j.wcapp.web; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
import javax.ws.rs.core.MediaType; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ArrayNode; | ||
import com.fasterxml.jackson.databind.node.JsonNodeFactory; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; | ||
import com.sun.jersey.api.client.Client; | ||
import com.sun.jersey.api.client.ClientResponse; | ||
import com.sun.jersey.api.client.config.DefaultClientConfig; | ||
|
||
public class Neo4jDatabase | ||
{ | ||
private final URI neo4jURI; | ||
private final Client client; | ||
|
||
public Neo4jDatabase( URI neo4jURI ) | ||
{ | ||
this.neo4jURI = neo4jURI; | ||
|
||
client = Client.create( config() ); | ||
} | ||
|
||
private DefaultClientConfig config() | ||
{ | ||
DefaultClientConfig defaultClientConfig = new DefaultClientConfig(); | ||
defaultClientConfig.getClasses().add( JacksonJsonProvider.class ); | ||
return defaultClientConfig; | ||
} | ||
|
||
public JsonNode query( String query, Map<String, Object> properties ) | ||
{ | ||
ObjectNode data = JsonNodeFactory.instance.objectNode(); | ||
|
||
ArrayNode statements = JsonNodeFactory.instance.arrayNode(); | ||
data.put("statements", statements); | ||
|
||
ObjectNode aQuery = JsonNodeFactory.instance.objectNode(); | ||
aQuery.put( "statement", query ); | ||
|
||
aQuery.put( "parameters", new ObjectMapper().valueToTree( properties ) ); | ||
|
||
statements.add( aQuery ); | ||
|
||
ClientResponse clientResponse = client. | ||
resource( neo4jURI + "/db/data/transaction/commit" ). | ||
accept( MediaType.APPLICATION_JSON_TYPE ). | ||
entity( data, MediaType.APPLICATION_JSON_TYPE ). | ||
post( ClientResponse.class ); | ||
|
||
return clientResponse.getEntity( JsonNode.class ).get("results").get(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.neo4j.wcapp.web; | ||
|
||
public class WorldCup | ||
{ | ||
|
||
private int year; | ||
private String host; | ||
|
||
public WorldCup( int year, String host ) | ||
{ | ||
|
||
this.year = year; | ||
this.host = host; | ||
} | ||
|
||
public int getYear() | ||
{ | ||
return year; | ||
} | ||
|
||
|
||
public String getHost() | ||
{ | ||
return host; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/org/neo4j/wcapp/web/WorldCupApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.neo4j.wcapp.web; | ||
|
||
import java.net.URI; | ||
|
||
import io.dropwizard.Application; | ||
import io.dropwizard.assets.AssetsBundle; | ||
import io.dropwizard.setup.Bootstrap; | ||
import io.dropwizard.setup.Environment; | ||
import io.dropwizard.views.ViewBundle; | ||
|
||
public class WorldCupApplication extends Application<WorldCupConfiguration> | ||
{ | ||
public static void main( String[] args ) throws Exception | ||
{ | ||
new WorldCupApplication().run( args ); | ||
} | ||
|
||
@Override | ||
public String getName() | ||
{ | ||
return "World Cup Graph"; | ||
} | ||
|
||
@Override | ||
public void initialize( Bootstrap<WorldCupConfiguration> bootstrap ) | ||
{ | ||
bootstrap.addBundle( new ViewBundle() ); | ||
bootstrap.addBundle( new AssetsBundle( "/assets/" ) ); | ||
} | ||
|
||
@Override | ||
public void run( WorldCupConfiguration configuration, Environment environment ) | ||
{ | ||
Neo4jDatabase neo4jDatabase = new Neo4jDatabase( URI.create( "http://localhost:7474" ) ); | ||
|
||
final WorldCupResource resource = new WorldCupResource( neo4jDatabase ); | ||
environment.jersey().register( resource ); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/org/neo4j/wcapp/web/WorldCupConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.neo4j.wcapp.web; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import io.dropwizard.Configuration; | ||
import org.hibernate.validator.constraints.NotEmpty; | ||
|
||
public class WorldCupConfiguration extends Configuration | ||
{ | ||
@NotEmpty | ||
private String defaultName = "World Cup Application"; | ||
|
||
|
||
@JsonProperty | ||
public String getDefaultName() { | ||
return defaultName; | ||
} | ||
|
||
@JsonProperty | ||
public void setDefaultName(String name) { | ||
this.defaultName = name; | ||
} | ||
} |
Oops, something went wrong.