--- a/WebContent/WEB-INF/templates/info.ftl Fri Apr 09 18:22:40 2010 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-<html>
-<head>
- <title>Info on </title>
-</head>
-<body>
- <h1>Informations</h1>
- <table>
- <thead>
- <tr>
- <th>Text</th>
- <th>Value</th>
- </tr>
- </thead>
- <tr>
- <td>DATABASE PATH</td>
- <td>${dbpath}</td>
- </tr>
- <tr>
- <td>Segments</td>
- <td>${segments_nb}</td>
- </tr>
- <tr>
- <td>Segments in db</td>
- <td>${segments_db_nb}</td>
- </tr>
- <tr>
- <td>Tags</td>
- <td>${tags_nb}</td>
- </tr>
- </table>
-</body>
-</html>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/WebContent/WEB-INF/templates/status.ftl Wed Apr 14 16:18:19 2010 +0200
@@ -0,0 +1,32 @@
+<html>
+<head>
+ <title>Info on </title>
+</head>
+<body>
+ <h1>Informations</h1>
+ <table>
+ <thead>
+ <tr>
+ <th>Text</th>
+ <th>Value</th>
+ </tr>
+ </thead>
+ <tr>
+ <td>DATABASE PATH</td>
+ <td>${dbpath}</td>
+ </tr>
+ <tr>
+ <td>Segments</td>
+ <td>${segments_nb}</td>
+ </tr>
+ <tr>
+ <td>Segments in db</td>
+ <td>${segments_db_nb}</td>
+ </tr>
+ <tr>
+ <td>Tags</td>
+ <td>${tags_nb}</td>
+ </tr>
+ </table>
+</body>
+</html>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fr/iri/thd/sonyengine/core/SonyengineException.java Wed Apr 14 16:18:19 2010 +0200
@@ -0,0 +1,25 @@
+package fr.iri.thd.sonyengine.core;
+
+public class SonyengineException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -8891243561994161034L;
+
+ public SonyengineException() {
+ }
+
+ public SonyengineException(String message) {
+ super(message);
+ }
+
+ public SonyengineException(Throwable cause) {
+ super(cause);
+ }
+
+ public SonyengineException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
--- a/src/fr/iri/thd/sonyengine/test/TestEngineResource.java Fri Apr 09 18:22:40 2010 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,390 +0,0 @@
-package fr.iri.thd.sonyengine.test.old;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.ws.rs.core.MediaType;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.representation.Form;
-
-import fr.iri.thd.sonyengine.core.DataAccessor;
-import fr.iri.thd.sonyengine.core.DbEnv;
-
-/*
- *
- * import java.io.File;
-
-import core.Tag;
-
-/**
- * A class to test ThdEngine
- *
- * @author pachet
- *
-public class ThdEngineTest {
-
- public static void main(String[] args) {
- testSimpleExampleManual();
-// testSimpleExampleFile();
- // testUniversCineFile();
- }
-
- /**
- * Tests the engine with a small set of movies and tags, entered
-"manually", one by one
- private static void testSimpleExampleManual() {
- ThdEngine engine = ThdEngine.getEngine();
- engine.createMovieFragment("ref1");
- engine.createMovieFragment("ref2");
- engine.createMovieFragment("ref3");
- engine.createMovieFragment("ref4");
- engine.createMovieFragment("ref5");
- engine.createMovieFragment("ref6");
- engine.createMovieFragment("ref7");
-
- engine.addTag("crayon", "ref1");
- engine.addTag("carte", "ref1");
- engine.addTag("bateau", "ref1");
- engine.addTag("voiture", "ref1");
- engine.addTag("car", "ref1");
-
- engine.addTag("enfant", "ref2");
- engine.addTag("famille", "ref2");
- engine.addTag("violon", "ref2");
- engine.addTag("maison", "ref2");
- engine.addTag("hopital", "ref2");
-
- engine.addTag("enfant", "ref3");
- engine.addTag("famille", "ref3");
- engine.addTag("violon", "ref3");
- engine.addTag("maison", "ref3");
- engine.addTag("ordinateur", "ref3");
- engine.addTag("fenetre", "ref3");
- engine.addTag("voiture", "ref3");
- engine.addTag("guitare", "ref3");
- engine.addTag("carte", "ref3");
-
- engine.addTag("enfant", "ref4");
- engine.addTag("famille", "ref4");
- engine.addTag("violon", "ref4");
- engine.addTag("bateau", "ref4");
- engine.addTag("ordinateur", "ref4");
- engine.addTag("fenetre", "ref4");
- engine.addTag("stylo", "ref4");
- engine.addTag("perroquet", "ref4");
- engine.addTag("crayon", "ref4");
- engine.addTag("tele", "ref4");
- engine.addTag("bateau", "ref4");
-
- engine.addTag("ordinateur", "ref5");
- engine.addTag("crayon", "ref5");
- engine.addTag("fenetre", "ref5");
- engine.addTag("hopital", "ref5");
- engine.addTag("carte", "ref5");
- engine.addTag("tele", "ref5");
- engine.addTag("stylo", "ref5");
- engine.addTag("perroquet", "ref5");
- engine.addTag("bateau", "ref5");
- engine.addTag("guitare", "ref5");
-
- engine.addTag("maison", "ref6");
- engine.addTag("perroquet", "ref6");
- engine.addTag("stylo", "ref6");
- engine.addTag("guitare", "ref6");
- engine.addTag("hopital", "ref6");
- engine.addTag("tele", "ref6");
- engine.addTag("car", "ref6");
- engine.addTag("voiture", "ref6");
- engine.addTag("fenetre", "ref6");
-
- engine.addTag("car", "ref7");
- engine.addTag("voiture", "ref7");
-
- engine.reTrain();
- engine.showAllTagValues();
-
- //Neighbor neighbor = engine.findMore("ref1", "enfant", .05f, true);
-
- while (neighbor != null) {
- System.out.println(neighbor.getMovieRef() + " distance: "
- + neighbor.getDistance());
- neighbor = engine.findMore(neighbor.getMovieRef(), "enfant", .05f,
- true);
- }
- System.out.println("cannot find any better");
- }
-
- /**
- * Tests the engine with a xcl file containing references of movies and
- * their tags. esult should be the same than testSimpleExampleManual()
- public static void testSimpleExampleFile() {
- ThdEngine engine = ThdEngine.getEngine();
- engine.loadFromTextFile(new File("./Sessions/Essai.csv"));
- System.out.println("number of movies read: "
- + engine.getAllMovieFragments().size());
-
- engine.reTrain();
- engine.showAllTagValues();
-
- Neighbor neighbor = engine.findMore("ref1", "enfant", .05f, true);
-
- while (neighbor != null) {
- System.out.println(neighbor.getMovieRef() + " distance: "
- + neighbor.getDistance());
- neighbor = engine.findMore(neighbor.getMovieRef(), "enfant", .05f,
- true);
- }
- System.out.println("cannot find any better");
- }
-
- /**
- * Tests the engine with a xcl file containing references of movies and
- * their tags
- public static void testUniversCineFile() {
- ThdEngine engine = ThdEngine.getEngine();
- engine.loadFromTextFile(new File("./Sessions/MovieFrame2.csv"));
- System.out.println("number of movies read: "
- + engine.getAllMovieFragments().size());
- ThdMovieFragment sobibor = engine
- .movieFragmentNamed("Sobibor, 14 octobre 1943, 16 heures");
- engine.reTrain();
-
- Tag T_enfant = engine.tagNamed("Enfant");
- System.out.println(sobibor);
- System.out.println(T_enfant);
-
- engine.tagNamed("Enfant").valueFor(sobibor);
-
- Neighbor neighbor = engine.findMore(sobibor.getName(), "Enfant", .05f,
- true);
-
- while (neighbor != null) {
- System.out.println(neighbor.getMovieRef() + " distance: "
- + neighbor.getDistance());
- neighbor = engine.findMore(neighbor.getMovieRef(), "Enfant", .05f,
- true);
- }
- System.out.println("cannot find any better");
- }
-
-}
-
- *
- *
- *
- *
- *
- */
-
-
-
-public class TestEngineResource {
-
- public static final String BASE_URL = "http://localhost:9080/sonyengine/";
- public static final String DATABASE_PATH = "/Users/ymh/dev/tmp/db";
-
- private DbEnv dbenv = null;
- private File databasePathFile = null;
- private String baseurl = null;
-
- @Before
- public void setup()
- {
- String databasepath = System.getProperty("database_path");
- if(databasepath == null)
- databasepath = DATABASE_PATH;
- databasePathFile = new File(databasepath);
-
- this.baseurl = System.getProperty("baseurl");
- if(this.baseurl == null)
- this.baseurl = BASE_URL;
- }
-
- @After
- public void teardown() {
-
- if(dbenv != null)
- dbenv.close();
- }
-
-
-
-
-
- @Test
- public void testCreateSequenceList() {
-
- List<String> movieIds = new ArrayList<String>();
-
- for(int i=0; i< 10; i++) {
- try {
- Thread.sleep(1);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- movieIds.add("movie" + System.currentTimeMillis());
- }
-
- String xml = "<segments>";
- for(String sequenceId: movieIds) {
- xml += String.format("<segment id=\"%s\"/>", sequenceId);
- }
- xml += "</segments>";
-
- Client c = Client.create();
- WebResource res = c.resource(this.baseurl).path("segment").path("createall");
- Form form = new Form();
- form.add("xml", xml);
- String response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML_TYPE).post(String.class, form);
-
- Assert.assertNotNull(response);
-
- dbenv = new DbEnv();
- dbenv.setup(databasePathFile, true, true);
-
- DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
-
- for(String sequenceId: movieIds) {
- Assert.assertTrue(da.movieFragmentById.contains(sequenceId));
- }
-
- }
-
-
- @Test
- public void testReset() {
- Client c = Client.create();
- WebResource res = c.resource(this.baseurl);
- String response = res.path("engine").path("reset").accept(MediaType.TEXT_PLAIN).post(String.class);
-
- Assert.assertEquals(response, "ok");
-
- dbenv = new DbEnv();
- dbenv.setup(databasePathFile, true, true);
-
- DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
-
- Assert.assertEquals(0, da.movieFragmentById.count());
- Assert.assertEquals(0, da.tagById.count());
- Assert.assertEquals(0, da.tagByName.count());
- Assert.assertEquals(0, da.tagBySegment.count());
-
- }
-
-
- @Test
- public void testClearTagsForm() {
-
- String movieName = "movie" + System.currentTimeMillis();
-
- List<String> tagNames = new ArrayList<String>();
-
- for(int i=0; i< 10; i++) {
- try {
- Thread.sleep(1);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- tagNames.add("tag" + System.currentTimeMillis());
- }
-
- Client c = Client.create();
- WebResource res = c.resource(this.baseurl + "segment/create/" + movieName);
- String response = res.accept(MediaType.APPLICATION_XML_TYPE).post(String.class);
-
- Assert.assertNotNull(response);
-
- String xml = "<tags>";
- for(String tagName: tagNames) {
- xml += String.format("<tag name=\"%s\" segment=\"%s\"/>", tagName, movieName);
- }
- xml += "</tags>";
-
- res = c.resource(this.baseurl).path("tag").path("add");
- Form form = new Form();
- form.add("xml", xml);
- response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML_TYPE).post(String.class, form);
-
- Assert.assertNotNull(response);
-
- form = new Form();
- form.add("id", movieName);
-
- res = c.resource(this.baseurl).path("segment").path("cleartags");
- response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.TEXT_PLAIN).post(String.class,form);
-
- Assert.assertEquals("ok", response);
-
-
- dbenv = new DbEnv();
- dbenv.setup(databasePathFile, true, true);
-
- DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
-
-
- da = new DataAccessor(this.dbenv.getEntityStore());
-
- Assert.assertFalse(da.tagBySegment.contains(movieName));
-
-
- }
-
- @Test
- public void testClearTagsPath() {
-
- String movieName = "movie" + System.currentTimeMillis();
-
- List<String> tagNames = new ArrayList<String>();
-
- for(int i=0; i< 10; i++) {
- try {
- Thread.sleep(1);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- tagNames.add("tag" + System.currentTimeMillis());
- }
-
- Client c = Client.create();
- WebResource res = c.resource(this.baseurl + "segment/create/" + movieName);
- String response = res.accept(MediaType.APPLICATION_XML_TYPE).post(String.class);
-
- Assert.assertNotNull(response);
-
- String xml = "<tags>";
- for(String tagName: tagNames) {
- xml += String.format("<tag name=\"%s\" segment=\"%s\"/>", tagName, movieName);
- }
- xml += "</tags>";
-
- res = c.resource(this.baseurl).path("tag").path("add");
- Form form = new Form();
- form.add("xml", xml);
- response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML_TYPE).post(String.class, form);
-
- Assert.assertNotNull(response);
-
- res = c.resource(this.baseurl).path("segment").path("cleartags").path(movieName);
- response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.TEXT_PLAIN).post(String.class);
-
- Assert.assertEquals("ok", response);
-
- dbenv = new DbEnv();
- dbenv.setup(databasePathFile, true, true);
-
- DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
-
- Assert.assertFalse(da.tagBySegment.contains(movieName));
-
- }
-
-
-}
--- a/src/fr/iri/thd/sonyengine/test/TestMovieFragmentResource.java Fri Apr 09 18:22:40 2010 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,323 +0,0 @@
-package fr.iri.thd.sonyengine.test.old;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.ws.rs.core.MediaType;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.w3c.dom.Document;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import com.sleepycat.persist.EntityCursor;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.representation.Form;
-
-import fr.iri.thd.sonyengine.core.DataAccessor;
-import fr.iri.thd.sonyengine.core.DbEnv;
-
-
-public class TestMovieFragmentResource {
-
- public static final String BASE_URL = "http://localhost:9080/sonyengine/";
- public static final String DATABASE_PATH = "/Users/ymh/dev/tmp/db";
-
- private DbEnv dbenv = null;
- private File databasePathFile = null;
- private String baseurl = null;
-
- @Before
- public void setup()
- {
- String databasepath = System.getProperty("database_path");
- if(databasepath == null)
- databasepath = DATABASE_PATH;
- this.databasePathFile = new File(databasepath);
-
- this.baseurl = System.getProperty("baseurl");
- if(this.baseurl == null)
- this.baseurl = BASE_URL;
- }
-
- @After
- public void teardown() {
-
- if(dbenv != null)
- dbenv.close();
- }
-
- @Test
- public void testCreateMovieFragment() {
-
- String movieName = "movie" + System.currentTimeMillis();
-
- Client c = Client.create();
- WebResource res = c.resource(this.baseurl + "segment/create/" + movieName);
-
- String response = res.accept(MediaType.APPLICATION_XML_TYPE).post(String.class);
-
- Assert.assertNotNull(response);
-
-
- dbenv = new DbEnv();
- dbenv.setup(databasePathFile, true, true);
-
- DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
-
-
- EntityCursor<String> cursor = da.movieFragmentById.keys();
-
- for (String key : cursor) {
- Assert.assertNotNull(key);
- }
-
- cursor.close();
-
- Assert.assertTrue(da.movieFragmentById.contains(movieName));
-
- }
-
- @Test
- public void testCreateMovieFragmentForm() {
-
- String movieName = "movie" + System.currentTimeMillis();
-
- Client c = Client.create();
-
- Form form = new Form();
- form.add("id", movieName);
-
- WebResource res = c.resource(this.baseurl + "segment/create");
-
- String response = res.type(MediaType.APPLICATION_FORM_URLENCODED).post(String.class, form);
-
- Assert.assertNotNull(response);
-
- dbenv = new DbEnv();
- dbenv.setup(databasePathFile, true, true);
-
- DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
-
-
- EntityCursor<String> cursor = da.movieFragmentById.keys();
-
- for (String key : cursor) {
- Assert.assertNotNull(key);
- }
-
- cursor.close();
-
- Assert.assertTrue(da.movieFragmentById.contains(movieName));
-
- }
-
- @Test
- public void testCreateMovieFragmentFormRetrain() throws InterruptedException {
-
- Client c = Client.create();
- WebResource.Builder res = c.resource(this.baseurl + "segment/create").type(MediaType.APPLICATION_FORM_URLENCODED);
- List<String> movieNames = new ArrayList<String>();
-
- String movieName = "movie" + System.currentTimeMillis();
- movieNames.add(movieName);
-
- Form form = new Form();
- form.add("id", movieName);
- form.add("retrain", "true");
-
- String response = res.post(String.class, form);
-
- Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><movieFragment><id>"+movieName+"</id></movieFragment>",response);
-
- Thread.sleep(1);
- movieName = "movie" + System.currentTimeMillis();
- movieNames.add(movieName);
-
- form = new Form();
- form.add("id", movieName);
- form.add("retrain", "false");
-
- response = res.post(String.class, form);
-
- Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><movieFragment><id>"+movieName+"</id></movieFragment>",response);
-
- Thread.sleep(1);
- movieName = "movie" + System.currentTimeMillis();
- movieNames.add(movieName);
-
- form = new Form();
- form.add("id", movieName);
- form.add("retrain", "foo");
-
- response = res.post(String.class, form);
-
- Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><movieFragment><id>"+movieName+"</id></movieFragment>",response);
-
- Thread.sleep(1);
- movieName = "movie" + System.currentTimeMillis();
- movieNames.add(movieName);
-
- form = new Form();
- form.add("id", movieName);
- form.add("retrain", "1");
-
- response = res.post(String.class, form);
-
- Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><movieFragment><id>"+movieName+"</id></movieFragment>",response);
-
-
- dbenv = new DbEnv();
- dbenv.setup(databasePathFile, true, true);
-
- DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
-
-
- EntityCursor<String> cursor = da.movieFragmentById.keys();
-
- for (String key : cursor) {
- Assert.assertNotNull(key);
- }
-
- cursor.close();
-
- for (String name : movieNames) {
- Assert.assertTrue(da.movieFragmentById.contains(name));
- }
-
-
- }
-
- @Test
- public void testTrain() {
-
- Client c = Client.create();
- WebResource res = c.resource(this.baseurl);
- String response = res.path("engine").path("reset").accept(MediaType.TEXT_PLAIN).post(String.class);
-
- String[] ids = new String[]{"ref1","ref2","ref3","ref4","ref5","ref6", "ref7"};
-
- String xmlSegment = "<segments>";
- for(String sequenceId: ids) {
- xmlSegment += String.format("<segment id=\"%s\"/>", sequenceId);
- }
- xmlSegment += "</segments>";
-
- c = Client.create();
- res = c.resource(this.baseurl).path("segment").path("createall");
- Form form = new Form();
- form.add("xml", xmlSegment);
- response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML_TYPE).post(String.class, form);
-
- Assert.assertNotNull(response);
-
-
- ArrayList<String[]> tags = new ArrayList<String[]>();
- tags.add(new String[]{"crayon", "ref1"});
- tags.add(new String[]{"carte", "ref1"});
- tags.add(new String[]{"bateau", "ref1"});
- tags.add(new String[]{"voiture", "ref1"});
- tags.add(new String[]{"car", "ref1"});
-
- tags.add(new String[]{"enfant", "ref2"});
- tags.add(new String[]{"famille", "ref2"});
- tags.add(new String[]{"violon", "ref2"});
- tags.add(new String[]{"maison", "ref2"});
- tags.add(new String[]{"hopital", "ref2"});
-
- tags.add(new String[]{"enfant", "ref3"});
- tags.add(new String[]{"famille", "ref3"});
- tags.add(new String[]{"violon", "ref3"});
- tags.add(new String[]{"maison", "ref3"});
- tags.add(new String[]{"ordinateur", "ref3"});
- tags.add(new String[]{"fenetre", "ref3"});
- tags.add(new String[]{"voiture", "ref3"});
- tags.add(new String[]{"guitare", "ref3"});
- tags.add(new String[]{"carte", "ref3"});
-
- tags.add(new String[]{"enfant", "ref4"});
- tags.add(new String[]{"famille", "ref4"});
- tags.add(new String[]{"violon", "ref4"});
- tags.add(new String[]{"bateau", "ref4"});
- tags.add(new String[]{"ordinateur", "ref4"});
- tags.add(new String[]{"fenetre", "ref4"});
- tags.add(new String[]{"stylo", "ref4"});
- tags.add(new String[]{"perroquet", "ref4"});
- tags.add(new String[]{"crayon", "ref4"});
- tags.add(new String[]{"tele", "ref4"});
- tags.add(new String[]{"bateau", "ref4"});
-
- tags.add(new String[]{"ordinateur", "ref5"});
- tags.add(new String[]{"crayon", "ref5"});
- tags.add(new String[]{"fenetre", "ref5"});
- tags.add(new String[]{"hopital", "ref5"});
- tags.add(new String[]{"carte", "ref5"});
- tags.add(new String[]{"tele", "ref5"});
- tags.add(new String[]{"stylo", "ref5"});
- tags.add(new String[]{"perroquet", "ref5"});
- tags.add(new String[]{"bateau", "ref5"});
- tags.add(new String[]{"guitare", "ref5"});
-
- tags.add(new String[]{"maison", "ref6"});
- tags.add(new String[]{"perroquet", "ref6"});
- tags.add(new String[]{"stylo", "ref6"});
- tags.add(new String[]{"guitare", "ref6"});
- tags.add(new String[]{"hopital", "ref6"});
- tags.add(new String[]{"tele", "ref6"});
- tags.add(new String[]{"car", "ref6"});
- tags.add(new String[]{"voiture", "ref6"});
- tags.add(new String[]{"fenetre", "ref6"});
-
- tags.add(new String[]{"car", "ref7"});
- tags.add(new String[]{"voiture", "ref7"});
-
- String xmlTags = "<tags>";
- for(String[] tagdef: tags) {
- xmlTags += String.format("<tag name=\"%s\" segment=\"%s\"/>", (Object[])tagdef);
- }
- xmlTags += "</tags>";
-
- res = c.resource(this.baseurl).path("tag").path("add");
- form = new Form();
- form.add("xml", xmlTags);
- response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML_TYPE).post(String.class, form);
-
- Assert.assertNotNull(response);
-
- //"engine/find/{segment}/{tag}/{percent}/{more}"
- //Neighbor neighbor = engine.findMore("ref1", "enfant", .05f, true);
- res = c.resource(this.baseurl).path("engine").path("find").path("ref1").path("enfant").path("0.05").path("true");
- response = res.accept(MediaType.APPLICATION_XML_TYPE).get(String.class);
- Assert.assertNotNull(response);
-
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- InputSource source = new InputSource(new StringReader(response));
- Document doc = null;
- try {
- doc = factory.newDocumentBuilder().parse(source);
- } catch (SAXException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (ParserConfigurationException e) {
- e.printStackTrace();
- }
-
- NodeList nodes = doc.getElementsByTagName("neighbor");
-
- Assert.assertEquals(1, nodes.getLength());
-
- }
-
-
-}
--- a/src/fr/iri/thd/sonyengine/test/TestTagResource.java Fri Apr 09 18:22:40 2010 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,224 +0,0 @@
-package fr.iri.thd.sonyengine.test.old;
-
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.ws.rs.core.MediaType;
-
-import org.codehaus.jackson.JsonFactory;
-import org.codehaus.jackson.JsonLocation;
-import org.codehaus.jackson.JsonParseException;
-import org.codehaus.jackson.JsonParser;
-import org.codehaus.jackson.map.JsonMappingException;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.type.TypeReference;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.representation.Form;
-
-import fr.iri.thd.sonyengine.core.DataAccessor;
-import fr.iri.thd.sonyengine.core.DbEnv;
-
-public class TestTagResource {
-
- public static final String BASE_URL = "http://localhost:9080/sonyengine/";
- public static final String DATABASE_PATH = "/Users/ymh/dev/tmp/db";
-
- private DbEnv dbenv = null;
- private File databasePathFile = null;
- private String baseurl = null;
-
- @Before
- public void setup()
- {
- String databasepath = System.getProperty("database_path");
- if(databasepath == null)
- databasepath = DATABASE_PATH;
- databasePathFile = new File(databasepath);
-
- this.baseurl = System.getProperty("baseurl");
- if(this.baseurl == null)
- this.baseurl = BASE_URL;
- }
-
- @After
- public void teardown() {
-
- if(dbenv != null)
- dbenv.close();
- }
-
- @Test
- public void testCreateTag() {
-
- String movieName = "movie" + System.currentTimeMillis();
- String tagName = "tag" + System.currentTimeMillis();;
-
- Client c = Client.create();
- WebResource res = c.resource(this.baseurl + "segment/create/" + movieName);
- String response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
-
- Assert.assertNotNull(response);
-
- res = c.resource(this.baseurl).path("tag").path("add").path(tagName).path(movieName);
- response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
-
- Assert.assertNotNull(response);
-
- dbenv = new DbEnv();
- dbenv.setup(databasePathFile, true, true);
-
- DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
-
- Assert.assertTrue(da.tagByName.contains(tagName));
-
- }
-
- @Test
- public void testCreateTagRetrain() throws InterruptedException, JsonParseException, JsonMappingException, IOException {
-
- List<String> tagNames = new ArrayList<String>();
-
- Client c = Client.create();
- ObjectMapper mapper = new ObjectMapper();
-
- WebResource res = null;
- String response = null;
- String tagName = null;
- Map<String, Object> resMap = null;
-
- String movieName = "movie" + System.currentTimeMillis();
- tagName = "tag" + System.currentTimeMillis();
- tagNames.add(tagName);
-
- res = c.resource(this.baseurl + "segment/create/" + movieName);
- response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
-
- Assert.assertNotNull(response);
- resMap = mapper.readValue(response, new TypeReference<Map<String, Object>>(){} );
- Assert.assertEquals(movieName, resMap.get("id"));
-
- res = c.resource(this.baseurl).path("tag").path("add").path(tagName).path(movieName).path("true");
- response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
-
- Assert.assertNotNull(response);
- resMap = mapper.readValue(response, new TypeReference<Map<String, Object>>(){} );
- Assert.assertEquals(tagName,resMap.get("name"));
- Assert.assertEquals(movieName, resMap.get("segment"));
-
- Thread.sleep(1);
- tagName = "tag" + System.currentTimeMillis();
- tagNames.add(tagName);
-
- res = c.resource(this.baseurl).path("tag").path("add").path(tagName).path(movieName).path("false");
- response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
-
- Assert.assertNotNull(response);
- resMap = mapper.readValue(response, new TypeReference<Map<String, Object>>(){} );
- Assert.assertEquals(tagName,resMap.get("name"));
- Assert.assertEquals(movieName, resMap.get("segment"));
-
- Thread.sleep(1);
- tagName = "tag" + System.currentTimeMillis();
- tagNames.add(tagName);
-
- res = c.resource(this.baseurl).path("tag").path("add").path(tagName).path(movieName).path("foo");
- response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
-
- Assert.assertNotNull(response);
- resMap = mapper.readValue(response, new TypeReference<Map<String, Object>>(){} );
- Assert.assertEquals(tagName,resMap.get("name"));
- Assert.assertEquals(movieName, resMap.get("segment"));
-
- Thread.sleep(1);
- tagName = "tag" + System.currentTimeMillis();
- tagNames.add(tagName);
-
- res = c.resource(this.baseurl).path("tag").path("add").path(tagName).path(movieName).path("1");
- response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
-
- Assert.assertNotNull(response);
- resMap = mapper.readValue(response, new TypeReference<Map<String, Object>>(){} );
- Assert.assertEquals(tagName,resMap.get("name"));
- Assert.assertEquals(movieName, resMap.get("segment"));
-
-
- dbenv = new DbEnv();
- dbenv.setup(databasePathFile, true, true);
-
- DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
-
- for (String tag : tagNames) {
- Assert.assertTrue(da.tagByName.contains(tag));
- }
-
- }
-
-
- @Test
- public void testCreateTagList() throws JsonParseException, JsonMappingException, IOException {
-
- String movieName = "movie" + System.currentTimeMillis();
-
- List<String> tagNames = new ArrayList<String>();
-
- for(int i=0; i< 10; i++) {
- try {
- Thread.sleep(1);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- tagNames.add("tag" + System.currentTimeMillis());
- }
-
- Client c = Client.create();
- WebResource res = c.resource(this.baseurl + "segment/create/" + movieName);
- String response = res.accept(MediaType.APPLICATION_XML_TYPE).post(String.class);
-
- Assert.assertNotNull(response);
-
- String xml = "<tags>";
- for(String tagName: tagNames) {
- xml += String.format("<tag name=\"%s\" segment=\"%s\"/>", tagName, movieName);
- }
- xml += "</tags>";
-
- res = c.resource(this.baseurl).path("tag").path("add");
- Form form = new Form();
- form.add("xml", xml);
- response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_JSON_TYPE).post(String.class, form);
-
- Assert.assertNotNull(response);
-
- ObjectMapper mapper = new ObjectMapper();
- List<Map<String,Object>> resList = mapper.readValue(response, new TypeReference<List<Map<String, Object>>>(){});
-
- Assert.assertEquals(tagNames, resList.size());
- for (Map<String, Object> map : resList) {
- Assert.assertEquals(movieName,map.get("segment"));
- Assert.assertTrue(tagNames.contains(map.get("name")));
- }
-
- dbenv = new DbEnv();
- dbenv.setup(databasePathFile, true, true);
-
- DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
-
- Assert.assertTrue(da.tagBySegment.contains(movieName));
-
- for(String tagName: tagNames) {
- Assert.assertTrue(da.tagByName.contains(tagName));
- }
-
- }
-
-}
--- a/src/fr/iri/thd/sonyengine/web/InfoResource.java Fri Apr 09 18:22:40 2010 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-package fr.iri.thd.sonyengine.web;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.servlet.ServletContext;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-
-import thd.ThdEngine;
-
-import com.sun.jersey.api.view.Viewable;
-
-import fr.iri.thd.sonyengine.core.DataAccessor;
-import fr.iri.thd.sonyengine.core.DbEnv;
-
-@Path("info")
-public class InfoResource {
-
- @GET
- @Produces(MediaType.TEXT_HTML)
- public Viewable info(@Context ServletContext context) {
- String dbpath = (String)context.getAttribute(ServletContainer.DB_PATH_ATTRIBUTE);
-
- final int segments_nb = ThdEngine.getEngine().getAllMovieFragments().size();
-
- final DbEnv dbenv = (DbEnv)context.getAttribute(ServletContainer.DB_ENV_ATTRIBUTE);
- final DataAccessor da = new DataAccessor(dbenv.getEntityStore());
- final long segments_db_nb = da.movieFragmentById.count();
- final long tags_nb = da.tagById.count();
-
-
- final Map<String,Object> vars = new HashMap<String, Object>();
-
- vars.put("dbpath", dbpath);
- vars.put("segments_nb", segments_nb);
- vars.put("segments_db_nb", segments_db_nb);
- vars.put("tags_nb", tags_nb);
-
-
- Viewable view = new Viewable("/info", vars);
-
- return view;
- }
-
-}
--- a/src/fr/iri/thd/sonyengine/web/MovieFragmentResource.java Fri Apr 09 18:22:40 2010 +0200
+++ b/src/fr/iri/thd/sonyengine/web/MovieFragmentResource.java Wed Apr 14 16:18:19 2010 +0200
@@ -27,11 +27,11 @@
import fr.iri.thd.sonyengine.core.DataAccessor;
import fr.iri.thd.sonyengine.core.DbEnv;
import fr.iri.thd.sonyengine.core.MovieFragment;
+import fr.iri.thd.sonyengine.core.SonyengineException;
@Path ("segment")
public class MovieFragmentResource {
-
private MovieFragment create(String id, boolean retrain, ServletContext context) {
ThdEngine.getEngine().createMovieFragment(id);
@@ -80,7 +80,7 @@
@Path("createall")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
- public List<MovieFragment> createAll(@FormParam("xml") String xmldocstr, @FormParam("retrain") Boolean retrain ,@Context ServletContext context) {
+ public List<MovieFragment> createAll(@FormParam("xml") String xmldocstr, @FormParam("retrain") Boolean retrain ,@Context ServletContext context) throws SonyengineException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
InputSource source = new InputSource(new StringReader(xmldocstr));
@@ -89,10 +89,13 @@
doc = factory.newDocumentBuilder().parse(source);
} catch (SAXException e) {
e.printStackTrace();
+ throw new SonyengineException("Exception when parsing " + xmldocstr, e);
} catch (IOException e) {
e.printStackTrace();
+ throw new SonyengineException("Exception when parsing " + xmldocstr, e);
} catch (ParserConfigurationException e) {
e.printStackTrace();
+ throw new SonyengineException("Exception when parsing " + xmldocstr, e);
}
DbEnv dbenv = (DbEnv)context.getAttribute(ServletContainer.DB_ENV_ATTRIBUTE);
DataAccessor da = new DataAccessor(dbenv.getEntityStore());
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fr/iri/thd/sonyengine/web/StatusResource.java Wed Apr 14 16:18:19 2010 +0200
@@ -0,0 +1,49 @@
+package fr.iri.thd.sonyengine.web;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+
+import thd.ThdEngine;
+
+import com.sun.jersey.api.view.Viewable;
+
+import fr.iri.thd.sonyengine.core.DataAccessor;
+import fr.iri.thd.sonyengine.core.DbEnv;
+
+@Path("status")
+public class StatusResource {
+
+ @GET
+ @Produces(MediaType.TEXT_HTML)
+ public Viewable info(@Context ServletContext context) {
+ String dbpath = (String)context.getAttribute(ServletContainer.DB_PATH_ATTRIBUTE);
+
+ final int segments_nb = ThdEngine.getEngine().getAllMovieFragments().size();
+
+ final DbEnv dbenv = (DbEnv)context.getAttribute(ServletContainer.DB_ENV_ATTRIBUTE);
+ final DataAccessor da = new DataAccessor(dbenv.getEntityStore());
+ final long segments_db_nb = da.movieFragmentById.count();
+ final long tags_nb = da.tagById.count();
+
+
+ final Map<String,Object> vars = new HashMap<String, Object>();
+
+ vars.put("dbpath", dbpath);
+ vars.put("segments_nb", segments_nb);
+ vars.put("segments_db_nb", segments_db_nb);
+ vars.put("tags_nb", tags_nb);
+
+
+ Viewable view = new Viewable("/status", vars);
+
+ return view;
+ }
+
+}
--- a/src/fr/iri/thd/sonyengine/web/TagResource.java Fri Apr 09 18:22:40 2010 +0200
+++ b/src/fr/iri/thd/sonyengine/web/TagResource.java Wed Apr 14 16:18:19 2010 +0200
@@ -25,6 +25,7 @@
import fr.iri.thd.sonyengine.core.DataAccessor;
import fr.iri.thd.sonyengine.core.DbEnv;
+import fr.iri.thd.sonyengine.core.SonyengineException;
import fr.iri.thd.sonyengine.core.Tag;
import thd.ThdEngine;
@@ -67,7 +68,7 @@
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
- public List<Tag> add(@FormParam("xml") String xmldocstr, @FormParam("retrain") Boolean retrain, @Context ServletContext context) {
+ public List<Tag> add(@FormParam("xml") String xmldocstr, @FormParam("retrain") Boolean retrain, @Context ServletContext context) throws SonyengineException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
InputSource source = new InputSource(new StringReader(xmldocstr));
@@ -76,10 +77,13 @@
doc = factory.newDocumentBuilder().parse(source);
} catch (SAXException e) {
e.printStackTrace();
+ throw new SonyengineException("Error when parsing xml with string " + xmldocstr, e);
} catch (IOException e) {
e.printStackTrace();
+ throw new SonyengineException("Error when parsing xml with string " + xmldocstr, e);
} catch (ParserConfigurationException e) {
e.printStackTrace();
+ throw new SonyengineException("Error when parsing xml with string " + xmldocstr, e);
}
DbEnv dbenv = (DbEnv)context.getAttribute(ServletContainer.DB_ENV_ATTRIBUTE);
DataAccessor da = new DataAccessor(dbenv.getEntityStore());