-
Notifications
You must be signed in to change notification settings - Fork 0
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
smelzi
committed
Nov 4, 2013
1 parent
b6ac620
commit 1664eed
Showing
23 changed files
with
7,693 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,15 @@ | ||
logs | ||
project/project | ||
project/target | ||
target | ||
tmp | ||
.history | ||
dist | ||
/.idea | ||
/*.iml | ||
/out | ||
/.idea_modules | ||
/.classpath | ||
/.project | ||
/RUNNING_PID | ||
/.settings |
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,17 @@ | ||
This is your new Play application | ||
===================================== | ||
|
||
This file will be packaged with your application, when using `play dist`. | ||
|
||
How to launch H2 and see it in browser ? | ||
Dans une console, play | ||
h2-browser -> ouvre un navigateur à l'url http://127.0.1.1:8082/ | ||
dans la console run | ||
dans le navigateur localhost:9000 | ||
apply this script | ||
Et maintenant dans la fenêtre http://127.0.1.1:8082/ plus qu'à cliquer sur connect | ||
|
||
How to make true persistency with H2 ? | ||
Changer l'url dans le fichier application.conf -> db.default.url="jdbc:h2:db/database" | ||
Les données vont être dans le dossier db fichier database.h2.db | ||
Du coup pour accéder à la base dans le navigateur, il faut maintenant taper jdbc:h2:db/database dans le champ URL JDBC |
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,102 @@ | ||
package controllers; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.OutputStream; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.hp.hpl.jena.rdf.model.Model; | ||
import com.hp.hpl.jena.rdf.model.ModelFactory; | ||
import com.hp.hpl.jena.rdf.model.Property; | ||
import com.hp.hpl.jena.rdf.model.Resource; | ||
|
||
import models.Tweet; | ||
import play.data.Form; | ||
import play.libs.Json; | ||
import play.mvc.*; | ||
import views.html.*; | ||
|
||
public class Application extends Controller { | ||
|
||
static Form<Tweet> tweetForm = Form.form(Tweet.class); | ||
|
||
public static final String NS_FOAF = "http://xmlns.com/foaf/0.1/"; | ||
|
||
public static Result index() | ||
{ | ||
return ok(index.render()); | ||
} | ||
|
||
public static Result listTweets(String username) | ||
{ | ||
List<Tweet> tweets ; | ||
if(username.equals("visiteur")) | ||
tweets = Tweet.all(); | ||
else | ||
tweets = Tweet.findByUsername(username); | ||
if(request().accepts("text/html")) | ||
return ok(views.html.wall.render(tweets, "bonjour " + username, tweetForm)); | ||
else if(request().accepts("application/json")) | ||
return ok(Json.toJson(tweets)); | ||
else if (request().accepts("application/rdf+xml")) | ||
{ | ||
Model model = ModelFactory.createDefaultModel(); | ||
String personURI = "http://www.natoine.fr#me"; | ||
String strgivenName = "Antoine"; | ||
String strfamilyName = "Seilles"; | ||
String strnickName = "Natoine"; | ||
String strfullName = strgivenName + " " + strfamilyName; | ||
|
||
//ajout d un namespace | ||
model.setNsPrefix("foaf", NS_FOAF); | ||
//creation des proprietes | ||
Property firstname = model.createProperty( NS_FOAF + "firstName" ); | ||
Property familyName = model.createProperty( NS_FOAF + "familyName" ); | ||
Property nick = model.createProperty( NS_FOAF + "nick" ); | ||
Property name = model.createProperty( NS_FOAF + "name" ); | ||
|
||
//TODO | ||
//need to create a foaf:Person not a generic resource | ||
Resource person = model.createResource(personURI); | ||
|
||
person.addProperty(firstname, strgivenName); | ||
person.addProperty(familyName, strfamilyName); | ||
person.addProperty(nick, strnickName); | ||
person.addProperty(name, strfullName); | ||
|
||
OutputStream out = new ByteArrayOutputStream(); | ||
|
||
model.write(out, "RDF/XML-ABBREV"); | ||
|
||
return ok(out.toString()); | ||
} | ||
return badRequest(); | ||
} | ||
|
||
public static Result submitTweet() | ||
{ | ||
Tweet tweet = tweetForm.bindFromRequest().get(); | ||
Tweet.create(tweet); | ||
return redirect(routes.Application.listTweets("visiteur")); | ||
} | ||
|
||
public static Result listTweetsFromTo() | ||
{ | ||
System.out.println(request().getHeader(ACCEPT)); | ||
if(request().accepts("application/json")) | ||
{ | ||
JsonNode body = request().body().asJson(); | ||
System.out.println(body); | ||
int from = body.get("from").asInt(); | ||
int to = body.get("to").asInt(); | ||
List<Tweet> tweets = Tweet.findNext(from, to); | ||
System.out.println(Json.toJson(tweets)); | ||
return ok(Json.toJson(tweets)); | ||
} | ||
return badRequest(); | ||
} | ||
} |
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,47 @@ | ||
package models; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
|
||
import com.avaje.ebean.PagingList; | ||
|
||
import play.db.ebean.Model; | ||
import play.db.ebean.Model.Finder; | ||
|
||
@Entity | ||
public class Tweet extends Model | ||
{ | ||
@Id | ||
public long id ; | ||
public String commentaire ; | ||
public String username ; | ||
public Date creationDate ; | ||
|
||
public static Finder<Long, Tweet> find = new Finder<Long, Tweet>(Long.class, Tweet.class); | ||
|
||
public static List<Tweet> all() | ||
{ | ||
//return find.all(); | ||
return find.setMaxRows(2).findList(); | ||
} | ||
|
||
public static List<Tweet> findByUsername(String username) | ||
{ | ||
return find.where().eq("username", username).findList(); | ||
} | ||
|
||
public static Tweet create(Tweet tweet) | ||
{ | ||
tweet.creationDate = new Date(); | ||
tweet.save(); | ||
return tweet; | ||
} | ||
|
||
public static List<Tweet> findNext(int from, int nb) | ||
{ | ||
return find.setFirstRow(from).setMaxRows(nb).findList(); | ||
} | ||
} |
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,6 @@ | ||
|
||
@main("Tweety") { | ||
|
||
<h1>Bienvenue sur l'application Tweety !!!</h1> | ||
|
||
} |
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,17 @@ | ||
@(title: String)(content: Html) | ||
|
||
<!DOCTYPE html> | ||
|
||
<html> | ||
<head> | ||
<title>@title</title> | ||
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")"> | ||
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/bootstrap.min.css")" /> | ||
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")"> | ||
<script src="@routes.Assets.at("javascripts/jquery-1.9.0.min.js")" type="text/javascript"></script> | ||
<script src="@routes.Assets.at("javascripts/bootstrap.min.js")" type="text/javascript"></script> | ||
</head> | ||
<body> | ||
@content | ||
</body> | ||
</html> |
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,75 @@ | ||
@(tweets: List[Tweet], message: String, tweetForm: Form[Tweet]) | ||
|
||
@main("Tweety") { | ||
|
||
<h1>@message</h1> | ||
|
||
<h2>Nouveau Tweet : </h2> | ||
|
||
@helper.form(action = routes.Application.submitTweet()) { | ||
|
||
@helper.inputText(tweetForm("commentaire")) | ||
@helper.inputText(tweetForm("username")) | ||
|
||
<input type="submit" class="btn primary" value="tweet !!!"> | ||
|
||
} | ||
|
||
<button class="btn btn-more" type ="button">More Tweets</button> | ||
|
||
<h2>Messages</h2> | ||
|
||
<table class="table table-striped" id="matable"> | ||
|
||
<tr> | ||
<td>nb Tweet</td> | ||
<td>ID</td> | ||
<td>Date</td> | ||
<td>Username</td> | ||
<td>Tweet</td> | ||
</tr> | ||
|
||
@for((tweet, i) <- tweets.zipWithIndex.reverse) { | ||
<tr> | ||
<td>@i</td> | ||
<td>@tweet.id</td> | ||
<td>@tweet.creationDate</td> | ||
<td>@tweet.username</td> | ||
<td>@tweet.commentaire</td> | ||
</tr> | ||
} | ||
</table> | ||
|
||
Il y a au total @tweets.size tweets. | ||
|
||
} | ||
<script type="text/javascript"> | ||
$(document).ready(function($){ | ||
|
||
$("body").ajaxError(function(event, jqXHR, ajaxSettings, thrownError){ | ||
alert("ERROR : " + thrownError); | ||
location.reload(); | ||
}); | ||
|
||
$btnMoreTweets = $(".btn-more"); | ||
|
||
$btnMoreTweets.click(function(event) { | ||
$this = $(this); | ||
alert("more button pressed"); | ||
$.ajax({ | ||
type: 'POST', | ||
url: "@routes.Application.listTweetsFromTo()", | ||
contentType: "application/json; charset=UTF-8", | ||
data: JSON.stringify({"from":@tweets.size(), "to":3}), | ||
success: function(data){ | ||
var obj = eval(data); | ||
for (var tw in obj) | ||
{ | ||
$('#matable').append('<tr><td>id</td><td>' + obj[tw].ID + '</td><td>'+ new Date (obj[tw].creationDate).toDateString()+ '</td><td>' + obj[tw].username +'</td><td>'+ obj[tw].commentaire+ '</td></tr>'); | ||
} | ||
} | ||
}) | ||
}); | ||
|
||
}); | ||
</script> |
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,13 @@ | ||
name := "tweetyServeur" | ||
|
||
version := "1.0-SNAPSHOT" | ||
|
||
libraryDependencies ++= Seq( | ||
javaJdbc, | ||
javaEbean, | ||
cache | ||
) | ||
|
||
libraryDependencies += "org.apache.jena" % "apache-jena-libs" % "2.11.0" | ||
|
||
play.Project.playJavaSettings |
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,70 @@ | ||
# This is the main configuration file for the application. | ||
# ~~~~~ | ||
|
||
# Secret key | ||
# ~~~~~ | ||
# The secret key is used to secure cryptographics functions. | ||
# If you deploy your application to several instances be sure to use the same key! | ||
application.secret="=sK[IQOAK9RugmHKeEGt@IS/MWopl>k;c4KwtGI0?<0ck3y95AGiEB:7hqugrHf5" | ||
|
||
# The application languages | ||
# ~~~~~ | ||
application.langs="en" | ||
|
||
# Global object class | ||
# ~~~~~ | ||
# Define the Global object class for this application. | ||
# Default to Global in the root package. | ||
# application.global=Global | ||
|
||
# Router | ||
# ~~~~~ | ||
# Define the Router object to use for this application. | ||
# This router will be looked up first when the application is starting up, | ||
# so make sure this is the entry point. | ||
# Furthermore, it's assumed your route file is named properly. | ||
# So for an application router like `conf/my.application.Router`, | ||
# you may need to define a router file `my.application.routes`. | ||
# Default to Routes in the root package (and `conf/routes`) | ||
# application.router=my.application.Routes | ||
|
||
# Database configuration | ||
# ~~~~~ | ||
# You can declare as many datasources as you want. | ||
# By convention, the default datasource is named `default` | ||
# | ||
db.default.driver=org.h2.Driver | ||
#db.default.url="jdbc:h2:mem:play" | ||
db.default.url="jdbc:h2:db/database" | ||
# db.default.user=sa | ||
# db.default.password="" | ||
# | ||
# You can expose this datasource via JNDI if needed (Useful for JPA) | ||
# db.default.jndiName=DefaultDS | ||
|
||
# Evolutions | ||
# ~~~~~ | ||
# You can disable evolutions if needed | ||
# evolutionplugin=disabled | ||
|
||
# Ebean configuration | ||
# ~~~~~ | ||
# You can declare as many Ebean servers as you want. | ||
# By convention, the default server is named `default` | ||
# | ||
ebean.default="models.*" | ||
|
||
# Logger | ||
# ~~~~~ | ||
# You can also configure logback (http://logback.qos.ch/), | ||
# by providing an application-logger.xml file in the conf directory. | ||
|
||
# Root logger: | ||
logger.root=ERROR | ||
|
||
# Logger used by the framework: | ||
logger.play=INFO | ||
|
||
# Logger provided to your application: | ||
logger.application=DEBUG | ||
|
Oops, something went wrong.