Simexplorer-si-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- 1607 discussions
r62 - trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test
by glandais@users.labs.libre-entreprise.org 10 Dec '07
by glandais@users.labs.libre-entreprise.org 10 Dec '07
10 Dec '07
Author: glandais
Date: 2007-12-10 15:21:40 +0000 (Mon, 10 Dec 2007)
New Revision: 62
Modified:
trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/ElementGenerator.java
trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/LuceneDatabaseTestCase.java
Log:
Tests database metadata
Modified: trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/ElementGenerator.java
===================================================================
--- trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/ElementGenerator.java 2007-12-10 15:21:14 UTC (rev 61)
+++ trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/ElementGenerator.java 2007-12-10 15:21:40 UTC (rev 62)
@@ -1,56 +1,58 @@
package fr.cemagref.simexplorer.is.storage.test;
import java.util.Date;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
-import fr.cemagref.simexplorer.is.storage.entities.Code;
-import fr.cemagref.simexplorer.is.storage.entities.Component;
-import fr.cemagref.simexplorer.is.storage.entities.Constant;
-import fr.cemagref.simexplorer.is.storage.entities.ConstantValue;
-import fr.cemagref.simexplorer.is.storage.entities.Descriptor;
-import fr.cemagref.simexplorer.is.storage.entities.Entity;
-import fr.cemagref.simexplorer.is.storage.entities.ExplorationApplication;
-import fr.cemagref.simexplorer.is.storage.entities.ExplorationData;
-import fr.cemagref.simexplorer.is.storage.entities.Library;
-import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
-import fr.cemagref.simexplorer.is.storage.entities.Result;
-import fr.cemagref.simexplorer.is.storage.entities.Structure;
-import fr.cemagref.simexplorer.is.storage.factories.EntityFactory;
+import fr.cemagref.simexplorer.is.storage.entities.data.Code;
+import fr.cemagref.simexplorer.is.storage.entities.data.Component;
+import fr.cemagref.simexplorer.is.storage.entities.data.Constant;
+import fr.cemagref.simexplorer.is.storage.entities.data.ConstantValue;
+import fr.cemagref.simexplorer.is.storage.entities.data.DataEntity;
+import fr.cemagref.simexplorer.is.storage.entities.data.ExplorationApplication;
+import fr.cemagref.simexplorer.is.storage.entities.data.ExplorationData;
+import fr.cemagref.simexplorer.is.storage.entities.data.Library;
+import fr.cemagref.simexplorer.is.storage.entities.data.LoggableElement;
+import fr.cemagref.simexplorer.is.storage.entities.data.Result;
+import fr.cemagref.simexplorer.is.storage.entities.data.Structure;
+import fr.cemagref.simexplorer.is.storage.entities.metadata.MetaDataEntity;
+import fr.cemagref.simexplorer.is.storage.factories.DataEntityFactory;
public class ElementGenerator {
private Random r = new Random();
private void update(LoggableElement element) throws Exception {
- element.setUuid(UUID.randomUUID().toString());
- element.setName(UUID.randomUUID().toString());
- element.setType(element.getClass().getSimpleName());
- element.setDescription("test");
- element.setVersion(Integer.toString(r.nextInt(100)));
- element.setCreationDate(new Date(r.nextLong()));
- element.setHash(UUID.randomUUID().toString());
+ MetaDataEntity metaData = new MetaDataEntity();
+ metaData.setUuid(UUID.randomUUID().toString());
+ metaData.setName(UUID.randomUUID().toString());
+ metaData.setType(element.getClass().getSimpleName());
+ metaData.setDescription("test");
+ metaData.setVersion(Integer.toString(r.nextInt(100)));
+ metaData.setCreationDate(new Date(r.nextLong()));
+ metaData.setHash(UUID.randomUUID().toString());
- Set<Descriptor> descriptors = generateArray(Descriptor.class);
- for (Object object : descriptors) {
- processDescriptor((Descriptor) object);
+ Map<String, String> descriptors = new HashMap<String, String>();
+ int i = 5 + r.nextInt(10);
+ for (int j = 0; j < i; j++) {
+ descriptors.put(UUID.randomUUID().toString(), UUID.randomUUID()
+ .toString());
}
- element.setDescriptors(descriptors);
- }
+ metaData.setDescriptors(descriptors);
- private void processDescriptor(Descriptor object) {
- object.setName(UUID.randomUUID().toString());
- object.setValue(UUID.randomUUID().toString());
+ element.setMetaData(metaData);
}
- private <T extends Entity> Set<T> generateArray(Class<T> clazz)
+ private <T extends DataEntity> Set<T> generateArray(Class<T> clazz)
throws Exception {
Set<T> elements = new HashSet<T>();
int i = 1 + r.nextInt(2);
for (int j = 0; j < i; j++) {
- T element = EntityFactory.getFactory(clazz).createInstance();
+ T element = DataEntityFactory.getFactory(clazz).createInstance();
if (element instanceof LoggableElement) {
update((LoggableElement) element);
}
Modified: trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/LuceneDatabaseTestCase.java
===================================================================
--- trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/LuceneDatabaseTestCase.java 2007-12-10 15:21:14 UTC (rev 61)
+++ trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/LuceneDatabaseTestCase.java 2007-12-10 15:21:40 UTC (rev 62)
@@ -1,28 +1,33 @@
package fr.cemagref.simexplorer.is.storage.test;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import java.util.Random;
import java.util.Set;
import java.util.UUID;
import junit.framework.TestCase;
-
-import fr.cemagref.simexplorer.is.storage.database.DatabaseConstants;
import fr.cemagref.simexplorer.is.storage.database.lucene.LuceneDatabase;
-import fr.cemagref.simexplorer.is.storage.entities.ExplorationData;
-import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
-import fr.cemagref.simexplorer.is.storage.entities.Version;
+import fr.cemagref.simexplorer.is.storage.entities.metadata.MetaDataEntity;
+import fr.cemagref.simexplorer.is.storage.entities.metadata.Version;
public class LuceneDatabaseTestCase extends TestCase {
private LuceneDatabase database;
- private ElementGenerator elementGenerator;
+ // private ElementGenerator elementGenerator;
+ private Random r = new Random();
protected void setUp() throws Exception {
super.setUp();
database = new LuceneDatabase();
database.open();
- elementGenerator = new ElementGenerator();
+ // elementGenerator = new ElementGenerator();
}
protected void tearDown() throws Exception {
@@ -30,224 +35,130 @@
database.close();
}
- public final void testPushFindElement() throws Exception {
+ private MetaDataEntity generateMetaDataEntity(String uuid, Version version,
+ MetaDataEntity parentVersion, MetaDataEntity parentData) {
+ MetaDataEntity me = generateMetaDataEntity(uuid, version, parentVersion);
+ me.setParentData(parentData);
+ return me;
+ }
- /*
- * database.pushElement(elementGenerator.generateRandomEA());
- *
- * Map<String, String> properties = new HashMap<String, String>();
- * properties.put(DatabaseConstants.KEY_DESCRIPTION, "test"); Set<LoggableElement>
- * elements = database .findElementsByProperties(properties); for
- * (LoggableElement loggableElement : elements) {
- * System.out.println(EntityFactory.getFactory(
- * loggableElement.getClass()).getElementXML(loggableElement)); }
- */
+ private MetaDataEntity generateMetaDataEntity(String uuid, Version version,
+ MetaDataEntity parentVersion) {
+ MetaDataEntity me = generateMetaDataEntity(uuid, version);
+ me.setParentVersion(parentVersion);
+ return me;
+ }
- String description1 = UUID.randomUUID().toString();
- String uuid1 = UUID.randomUUID().toString();
- ExplorationData explorationData1 = new ExplorationData();
- explorationData1.setUuid(uuid1);
- explorationData1.setVersion("5.12");
- explorationData1.setDescription(description1);
- database.insertElement(explorationData1);
+ private MetaDataEntity generateMetaDataEntity(String uuid, Version version) {
+ MetaDataEntity me = new MetaDataEntity();
- LoggableElement element = database.getElement(uuid1, new Version(
- "5.12"));
- assertNotNull(element);
- assertEquals(description1, element.getDescription());
+ me.setUuid(uuid);
+ me.setName(uuid);
+ me.setType("LuceneDatabaseTestCase");
+ me.setDescription(uuid + " " + version.toString());
+ me.setVersion(version.toString());
+ me.setCreationDate(new Date());
+ me.setHash(UUID.randomUUID().toString());
- String description2 = UUID.randomUUID().toString();
- ExplorationData explorationData2 = new ExplorationData();
- explorationData2.setUuid(uuid1);
- explorationData2.setVersion("5.12");
- explorationData2.setDescription(description2);
- database.insertElement(explorationData2);
+ Map<String, String> descriptors = new HashMap<String, String>();
+ descriptors.put("overallId", uuid);
+ int i = 5 + r.nextInt(10);
+ for (int j = 0; j < i; j++) {
+ descriptors.put(UUID.randomUUID().toString(), UUID.randomUUID()
+ .toString());
+ }
+ me.setDescriptors(descriptors);
+ me.setParentData(null);
+ me.setParentVersion(null);
- assertEquals(description2, database.getElement(uuid1,
- new Version("5.12")).getDescription());
+ return me;
+ }
- String description3 = UUID.randomUUID().toString();
- ExplorationData explorationData3 = new ExplorationData();
- explorationData3.setUuid(uuid1);
- explorationData3.setVersion("5.13");
- explorationData3.setDescription(description3);
- database.insertElement(explorationData3);
-
- assertEquals(description3, database.getElement(uuid1,
- new Version("5.13")).getDescription());
+ private MetaDataEntity generateMetaDataEntity() {
+ return generateMetaDataEntity(UUID.randomUUID().toString(),
+ new Version("1.0"));
}
- public final void testGetElementLatestVersion() throws Exception {
- String description1 = UUID.randomUUID().toString();
- String uuid1 = UUID.randomUUID().toString();
- ExplorationData explorationData1 = new ExplorationData();
- explorationData1.setUuid(uuid1);
- explorationData1.setVersion("5.12");
- explorationData1.setDescription(description1);
- database.insertElement(explorationData1);
+ private MetaDataEntity[] generateVersionnedMetaDataEntity() {
+ String uuid = UUID.randomUUID().toString();
- String description2 = UUID.randomUUID().toString();
- ExplorationData explorationData2 = new ExplorationData();
- explorationData2.setUuid(uuid1);
- explorationData2.setVersion("5.13");
- explorationData2.setDescription(description2);
- database.insertElement(explorationData2);
+ MetaDataEntity[] mes = new MetaDataEntity[4];
+ mes[0] = generateMetaDataEntity(uuid, new Version("1.0"));
+ mes[1] = generateMetaDataEntity(uuid, new Version("1.1"), mes[0]);
+ mes[2] = generateMetaDataEntity(uuid, new Version("1.2"), mes[1]);
+ mes[3] = generateMetaDataEntity(uuid, new Version("2.0"), mes[2]);
- assertEquals(description2, database.getElementLatestVersion(uuid1)
- .getDescription());
-
- String description3 = UUID.randomUUID().toString();
- ExplorationData explorationData3 = new ExplorationData();
- explorationData3.setUuid(uuid1);
- explorationData3.setVersion("6.0");
- explorationData3.setDescription(description3);
- database.insertElement(explorationData3);
-
- assertEquals(description3, database.getElementLatestVersion(uuid1)
- .getDescription());
+ return mes;
}
- public final void testFindElementsById() throws Exception {
- String description1 = UUID.randomUUID().toString();
- String uuid1 = UUID.randomUUID().toString();
- ExplorationData explorationData1 = new ExplorationData();
- explorationData1.setUuid(uuid1);
- explorationData1.setVersion("5.12");
- explorationData1.setDescription(description1);
- database.insertElement(explorationData1);
-
- String description2 = UUID.randomUUID().toString();
- ExplorationData explorationData2 = new ExplorationData();
- explorationData2.setUuid(uuid1);
- explorationData2.setVersion("5.13");
- explorationData2.setDescription(description2);
- database.insertElement(explorationData2);
-
- String description3 = UUID.randomUUID().toString();
- ExplorationData explorationData3 = new ExplorationData();
- explorationData3.setUuid(uuid1);
- explorationData3.setVersion("6.0");
- explorationData3.setDescription(description3);
- database.insertElement(explorationData3);
-
- Set<LoggableElement> elements = database.findElementsById(uuid1);
- assertEquals(3, elements.size());
-
+ public void testInsertElementGetElement() throws Exception {
+ MetaDataEntity me = generateMetaDataEntity();
+ database.insertElement(me);
+ MetaDataEntity me2 = database.getElement(me.getUuid(), me.getVersion());
+ assertEquals(me.getDescription(), me2.getDescription());
}
- public final void testFindElementsByPropertiesMapOfStringString()
- throws Exception {
+ public void testIndexAddFindElementsByContentSearch() throws Exception {
+ MetaDataEntity me = generateMetaDataEntity();
+ database.insertElement(me);
- String description1 = UUID.randomUUID().toString();
- String uuid1 = UUID.randomUUID().toString();
- ExplorationData explorationData1 = new ExplorationData();
- explorationData1.setUuid(uuid1);
- explorationData1.setVersion("5.12");
- explorationData1.setDescription(description1);
- database.insertElement(explorationData1);
+ String keyphrase = Long.toHexString(r.nextLong());
- ExplorationData explorationData2 = new ExplorationData();
- explorationData2.setUuid(uuid1);
- explorationData2.setVersion("5.13");
- explorationData2.setDescription(description1);
- database.insertElement(explorationData2);
+ StringReader reader = new StringReader("ogijeriog ergijergioj "
+ + keyphrase + " egiojergij ergijerogij");
- String description3 = UUID.randomUUID().toString();
- ExplorationData explorationData3 = new ExplorationData();
- explorationData3.setUuid(uuid1);
- explorationData3.setVersion("6.0");
- explorationData3.setDescription(description3);
- database.insertElement(explorationData3);
+ List<Reader> readers = new ArrayList<Reader>();
+ readers.add(reader);
+ database.indexAdd(me, readers);
- // TODO add some other classes in db
+ Set<MetaDataEntity> mes = database
+ .findElementsByContentSearch(keyphrase);
- Map<String, String> properties = new HashMap<String, String>();
- properties.put(DatabaseConstants.KEY_UUID, uuid1);
- properties.put(DatabaseConstants.KEY_DESCRIPTION, description1);
+ assertEquals(1, mes.size());
+ }
- Set<LoggableElement> elements = database
- .findElementsByProperties(properties);
- assertEquals(2, elements.size());
+ public void testGetVersions() throws Exception {
+ MetaDataEntity[] mes = generateVersionnedMetaDataEntity();
+ for (int i = 0; i < mes.length; i++) {
+ database.insertElement(mes[i]);
+ }
+ List<Version> versions = database.getVersions(mes[0].getUuid());
+ assertEquals(mes.length, versions.size());
+ Collections.sort(versions);
+ assertEquals("1.0", versions.get(0).toString());
+ assertEquals("1.1", versions.get(1).toString());
+ assertEquals("1.2", versions.get(2).toString());
+ assertEquals("2.0", versions.get(3).toString());
+ }
+ public void testFindElementsById() throws Exception {
+ MetaDataEntity[] mes = generateVersionnedMetaDataEntity();
+ for (int i = 0; i < mes.length; i++) {
+ database.insertElement(mes[i]);
+ }
+ Set<MetaDataEntity> elements = database.findElementsById(mes[0]
+ .getUuid());
+ assertEquals(elements.size(), mes.length);
}
- public final void testFindElementsByPropertiesMapOfStringStringClass()
- throws Exception {
+ public void testFindElementsByProperties() {
+ fail("Not yet implemented");
+ }
- String description1 = UUID.randomUUID().toString();
- String uuid1 = UUID.randomUUID().toString();
- ExplorationData explorationData1 = new ExplorationData();
- explorationData1.setUuid(uuid1);
- explorationData1.setVersion("5.12");
- explorationData1.setDescription(description1);
- database.insertElement(explorationData1);
+ public void testDeleteElements() {
+ fail("Not yet implemented");
+ }
- ExplorationData explorationData2 = new ExplorationData();
- explorationData2.setUuid(uuid1);
- explorationData2.setVersion("5.13");
- explorationData2.setDescription(description1);
- database.insertElement(explorationData2);
-
- String description3 = UUID.randomUUID().toString();
- ExplorationData explorationData3 = new ExplorationData();
- explorationData3.setUuid(uuid1);
- explorationData3.setVersion("6.0");
- explorationData3.setDescription(description3);
- database.insertElement(explorationData3);
-
- Map<String, String> properties = new HashMap<String, String>();
- properties.put(DatabaseConstants.KEY_UUID, uuid1);
- properties.put(DatabaseConstants.KEY_DESCRIPTION, description1);
-
- Set<LoggableElement> elements = database.findElementsByProperties(
- properties, ExplorationData.class);
- assertEquals(2, elements.size());
-
+ public void testDeleteElementStringVersion() {
+ fail("Not yet implemented");
}
- public final void testDeleteElement() throws Exception {
-
- String description1 = UUID.randomUUID().toString();
- String uuid1 = UUID.randomUUID().toString();
- ExplorationData explorationData1 = new ExplorationData();
- explorationData1.setUuid(uuid1);
- explorationData1.setVersion("5.12");
- explorationData1.setDescription(description1);
- database.insertElement(explorationData1);
-
- database.deleteElement(explorationData1);
- assertNull(database.getElement(uuid1, new Version("5.12")));
-
+ public void testGetElementLatestVersion() {
+ fail("Not yet implemented");
}
- public final void testDeleteElements() throws Exception {
-
- String description1 = UUID.randomUUID().toString();
- String uuid1 = UUID.randomUUID().toString();
- ExplorationData explorationData1 = new ExplorationData();
- explorationData1.setUuid(uuid1);
- explorationData1.setVersion("5.12");
- explorationData1.setDescription(description1);
- database.insertElement(explorationData1);
-
- String description2 = UUID.randomUUID().toString();
- ExplorationData explorationData2 = new ExplorationData();
- explorationData2.setUuid(uuid1);
- explorationData2.setVersion("5.13");
- explorationData2.setDescription(description2);
- database.insertElement(explorationData2);
-
- String description3 = UUID.randomUUID().toString();
- ExplorationData explorationData3 = new ExplorationData();
- explorationData3.setUuid(uuid1);
- explorationData3.setVersion("6.0");
- explorationData3.setDescription(description3);
- database.insertElement(explorationData3);
-
- database.deleteElements(uuid1);
-
- assertEquals(0, database.findElementsById(uuid1).size());
-
+ public void testDeleteElementMetaDataEntity() {
+ fail("Not yet implemented");
}
}
1
0
r61 - trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories
by glandais@users.labs.libre-entreprise.org 10 Dec '07
by glandais@users.labs.libre-entreprise.org 10 Dec '07
10 Dec '07
Author: glandais
Date: 2007-12-10 15:21:14 +0000 (Mon, 10 Dec 2007)
New Revision: 61
Added:
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/CodeFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ComponentFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantValueFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/DataEntityFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationApplicationFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationDataFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LibraryFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LoggableElementFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/RepositoryFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ResultFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/StructureFactory.java
Removed:
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/CodeFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ComponentFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantValueFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/DescriptorFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/EntityFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationApplicationFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationDataFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/FileEntityFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LibraryFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LoggableElementFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/RepositoryFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ResultFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/StructureFactory.java
Log:
Refactoring des factories
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/CodeFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/CodeFactory.java 2007-12-10 15:20:48 UTC (rev 60)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/CodeFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -1,33 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.factories;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import fr.cemagref.simexplorer.is.storage.entities.Code;
-
-public class CodeFactory<E extends Code> extends EntityFactory<Code> {
-
- public static final String KEY_LANGUAGE = "language";
- public static final String KEY_CODE = "code";
-
- @Override
- public Code createInstance() {
- return new Code();
- }
-
- @Override
- public Code loadXMLElement(Element xmlElement) throws Exception {
- Code code = super.loadXMLElement(xmlElement);
- code.setLanguage(getProperty(xmlElement, KEY_LANGUAGE));
- code.setCode(getProperty(xmlElement, KEY_CODE));
- return code;
- }
-
- @Override
- public void saveXMLElement(Document document, Element xmlElement,
- Code element) throws Exception {
- setProperty(document, xmlElement, KEY_LANGUAGE, element.getLanguage());
- setProperty(document, xmlElement, KEY_CODE, element.getCode());
- }
-
-}
Added: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/CodeFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/CodeFactory.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/CodeFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -0,0 +1,33 @@
+package fr.cemagref.simexplorer.is.storage.factories;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import fr.cemagref.simexplorer.is.storage.entities.data.Code;
+
+public class CodeFactory<E extends Code> extends DataEntityFactory<Code> {
+
+ public static final String KEY_LANGUAGE = "language";
+ public static final String KEY_CODE = "code";
+
+ @Override
+ public Code createInstance() {
+ return new Code();
+ }
+
+ @Override
+ public Code loadXMLElement(Element xmlElement) throws Exception {
+ Code code = super.loadXMLElement(xmlElement);
+ code.setLanguage(getProperty(xmlElement, KEY_LANGUAGE));
+ code.setCode(getProperty(xmlElement, KEY_CODE));
+ return code;
+ }
+
+ @Override
+ public void saveXMLElement(Document document, Element xmlElement,
+ Code element) throws Exception {
+ setProperty(document, xmlElement, KEY_LANGUAGE, element.getLanguage());
+ setProperty(document, xmlElement, KEY_CODE, element.getCode());
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ComponentFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ComponentFactory.java 2007-12-10 15:20:48 UTC (rev 60)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ComponentFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -1,59 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.factories;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import fr.cemagref.simexplorer.is.storage.entities.Code;
-import fr.cemagref.simexplorer.is.storage.entities.Component;
-import fr.cemagref.simexplorer.is.storage.entities.Constant;
-import fr.cemagref.simexplorer.is.storage.entities.Library;
-import fr.cemagref.simexplorer.is.storage.entities.Structure;
-
-public class ComponentFactory<E extends Component> extends
- LoggableElementFactory<Component> {
-
- public static final String KEY_CONSTANTS = "constants";
- public static final String KEY_CONSTANT_NODE = "constant";
- public static final String KEY_STRUCTURE = "structures";
- public static final String KEY_STRUCTURE_NODE = "structure";
- public static final String KEY_CODES = "codes";
- public static final String KEY_CODE_NODE = "code";
- public static final String KEY_LIBRARIES = "libraries";
- public static final String KEY_LIBRARY_NODE = "library";
-
- @Override
- public Component createInstance() {
- return new Component();
- }
-
- @Override
- public Component loadXMLElement(Element xmlElement) throws Exception {
- Component component = super.loadXMLElement(xmlElement);
-
- component.setConstants(loadCollection(KEY_CONSTANTS, KEY_CONSTANT_NODE,
- Constant.class, xmlElement));
- component.setStructures(loadCollection(KEY_STRUCTURE,
- KEY_STRUCTURE_NODE, Structure.class, xmlElement));
- component.setCodes(loadCollection(KEY_CODES, KEY_CODE_NODE, Code.class,
- xmlElement));
- component.setLibraries(loadCollection(KEY_LIBRARIES, KEY_LIBRARY_NODE,
- Library.class, xmlElement));
-
- return component;
- }
-
- @Override
- public void saveXMLElement(Document document, Element xmlElement,
- Component element) throws Exception {
- saveCollection(element.getConstants(), KEY_CONSTANTS,
- KEY_CONSTANT_NODE, Constant.class, document, xmlElement);
- saveCollection(element.getStructures(), KEY_STRUCTURE,
- KEY_STRUCTURE_NODE, Structure.class, document, xmlElement);
- saveCollection(element.getCodes(), KEY_CODES, KEY_CODE_NODE,
- Code.class, document, xmlElement);
- saveCollection(element.getLibraries(), KEY_LIBRARIES, KEY_LIBRARY_NODE,
- Library.class, document, xmlElement);
- super.saveXMLElement(document, xmlElement, element);
- }
-
-}
Added: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ComponentFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ComponentFactory.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ComponentFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -0,0 +1,58 @@
+package fr.cemagref.simexplorer.is.storage.factories;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import fr.cemagref.simexplorer.is.storage.entities.data.Code;
+import fr.cemagref.simexplorer.is.storage.entities.data.Component;
+import fr.cemagref.simexplorer.is.storage.entities.data.Constant;
+import fr.cemagref.simexplorer.is.storage.entities.data.Library;
+import fr.cemagref.simexplorer.is.storage.entities.data.Structure;
+
+public class ComponentFactory<E extends Component> extends
+ DataEntityFactory<Component> {
+
+ public static final String KEY_CONSTANTS = "constants";
+ public static final String KEY_CONSTANT_NODE = "constant";
+ public static final String KEY_STRUCTURE = "structures";
+ public static final String KEY_STRUCTURE_NODE = "structure";
+ public static final String KEY_CODES = "codes";
+ public static final String KEY_CODE_NODE = "code";
+ public static final String KEY_LIBRARIES = "libraries";
+ public static final String KEY_LIBRARY_NODE = "library";
+
+ @Override
+ public Component createInstance() {
+ return new Component();
+ }
+
+ @Override
+ public Component loadXMLElement(Element xmlElement) throws Exception {
+ Component component = super.loadXMLElement(xmlElement);
+
+ component.setConstants(loadCollection(KEY_CONSTANTS, KEY_CONSTANT_NODE,
+ Constant.class, xmlElement, component));
+ component.setStructures(loadCollection(KEY_STRUCTURE,
+ KEY_STRUCTURE_NODE, Structure.class, xmlElement, component));
+ component.setCodes(loadCollection(KEY_CODES, KEY_CODE_NODE, Code.class,
+ xmlElement, component));
+ component.setLibraries(loadCollection(KEY_LIBRARIES, KEY_LIBRARY_NODE,
+ Library.class, xmlElement, component));
+
+ return component;
+ }
+
+ @Override
+ public void saveXMLElement(Document document, Element xmlElement,
+ Component element) throws Exception {
+ saveCollection(element.getConstants(), KEY_CONSTANTS,
+ KEY_CONSTANT_NODE, Constant.class, document, xmlElement);
+ saveCollection(element.getStructures(), KEY_STRUCTURE,
+ KEY_STRUCTURE_NODE, Structure.class, document, xmlElement);
+ saveCollection(element.getCodes(), KEY_CODES, KEY_CODE_NODE,
+ Code.class, document, xmlElement);
+ saveCollection(element.getLibraries(), KEY_LIBRARIES, KEY_LIBRARY_NODE,
+ Library.class, document, xmlElement);
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantFactory.java 2007-12-10 15:20:48 UTC (rev 60)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -1,36 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.factories;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import fr.cemagref.simexplorer.is.storage.entities.Constant;
-
-public class ConstantFactory<E extends Constant> extends
- EntityFactory<Constant> {
-
- public static final String KEY_NAME = "name";
- public static final String KEY_TYPE = "type";
-
- @Override
- public Constant createInstance() {
- return new Constant();
- }
-
- @Override
- public Constant loadXMLElement(Element xmlElement) throws Exception {
- Constant constant = super.loadXMLElement(xmlElement);
- constant.setName(getProperty(xmlElement, KEY_NAME));
- String className = getProperty(xmlElement, KEY_TYPE);
- constant.setType(Class.forName(className));
- return constant;
- }
-
- @Override
- public void saveXMLElement(Document document, Element xmlElement,
- Constant element) throws Exception {
- setProperty(document, xmlElement, KEY_NAME, element.getName());
- String className = element.getType().getName();
- setProperty(document, xmlElement, KEY_TYPE, className);
- }
-
-}
Added: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantFactory.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -0,0 +1,36 @@
+package fr.cemagref.simexplorer.is.storage.factories;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import fr.cemagref.simexplorer.is.storage.entities.data.Constant;
+
+public class ConstantFactory<E extends Constant> extends
+ DataEntityFactory<Constant> {
+
+ public static final String KEY_NAME = "name";
+ public static final String KEY_TYPE = "type";
+
+ @Override
+ public Constant createInstance() {
+ return new Constant();
+ }
+
+ @Override
+ public Constant loadXMLElement(Element xmlElement) throws Exception {
+ Constant constant = super.loadXMLElement(xmlElement);
+ constant.setName(getProperty(xmlElement, KEY_NAME));
+ String className = getProperty(xmlElement, KEY_TYPE);
+ constant.setType(Class.forName(className));
+ return constant;
+ }
+
+ @Override
+ public void saveXMLElement(Document document, Element xmlElement,
+ Constant element) throws Exception {
+ setProperty(document, xmlElement, KEY_NAME, element.getName());
+ String className = element.getType().getName();
+ setProperty(document, xmlElement, KEY_TYPE, className);
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantValueFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantValueFactory.java 2007-12-10 15:20:48 UTC (rev 60)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantValueFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -1,41 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.factories;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import fr.cemagref.simexplorer.is.storage.entities.Constant;
-import fr.cemagref.simexplorer.is.storage.entities.ConstantValue;
-
-public class ConstantValueFactory<E extends ConstantValue> extends
- EntityFactory<ConstantValue> {
-
- public static final String KEY_CONSTANT = "constant";
- public static final String KEY_VALUE = "value";
-
- @Override
- public ConstantValue createInstance() {
- return new ConstantValue();
- }
-
- @Override
- public ConstantValue loadXMLElement(Element xmlElement) throws Exception {
- ConstantValue constantValue = super.loadXMLElement(xmlElement);
- constantValue.setConstant((Constant) getFactory(Constant.class)
- .loadXMLElement(getElementByTagName(xmlElement, KEY_CONSTANT)));
- constantValue.setValue(getProperty(xmlElement, KEY_VALUE));
- return constantValue;
- }
-
- @Override
- public void saveXMLElement(Document document, Element xmlElement,
- ConstantValue element) throws Exception {
-
- Element xmlConstant = document.createElement(KEY_CONSTANT);
- getFactory(Constant.class).saveXMLElement(document, xmlConstant,
- element.getConstant());
- xmlElement.appendChild(xmlConstant);
-
- setProperty(document, xmlElement, KEY_VALUE, element.getValue());
- }
-
-}
Added: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantValueFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantValueFactory.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantValueFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -0,0 +1,41 @@
+package fr.cemagref.simexplorer.is.storage.factories;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import fr.cemagref.simexplorer.is.storage.entities.data.Constant;
+import fr.cemagref.simexplorer.is.storage.entities.data.ConstantValue;
+
+public class ConstantValueFactory<E extends ConstantValue> extends
+ DataEntityFactory<ConstantValue> {
+
+ public static final String KEY_CONSTANT = "constant";
+ public static final String KEY_VALUE = "value";
+
+ @Override
+ public ConstantValue createInstance() {
+ return new ConstantValue();
+ }
+
+ @Override
+ public ConstantValue loadXMLElement(Element xmlElement) throws Exception {
+ ConstantValue constantValue = super.loadXMLElement(xmlElement);
+ constantValue.setConstant((Constant) getFactory(Constant.class)
+ .loadXMLElement(getElementByTagName(xmlElement, KEY_CONSTANT)));
+ constantValue.setValue(getProperty(xmlElement, KEY_VALUE));
+ return constantValue;
+ }
+
+ @Override
+ public void saveXMLElement(Document document, Element xmlElement,
+ ConstantValue element) throws Exception {
+
+ Element xmlConstant = document.createElement(KEY_CONSTANT);
+ getFactory(Constant.class).saveXMLElement(document, xmlConstant,
+ element.getConstant());
+ xmlElement.appendChild(xmlConstant);
+
+ setProperty(document, xmlElement, KEY_VALUE, element.getValue());
+ }
+
+}
Added: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/DataEntityFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/DataEntityFactory.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/DataEntityFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -0,0 +1,186 @@
+package fr.cemagref.simexplorer.is.storage.factories;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+import fr.cemagref.simexplorer.is.storage.entities.data.DataEntity;
+
+public abstract class DataEntityFactory<E extends DataEntity> {
+
+ private static DocumentBuilder documentBuilder = null;
+
+ private static Map<String, DataEntityFactory<? extends DataEntity>> factories = new HashMap<String, DataEntityFactory<? extends DataEntity>>();
+
+ private final static String PACKAGE_DAO = "fr.cemagref.simexplorer.is.storage.factories";
+
+ public static synchronized DocumentBuilder getBuilder() throws Exception {
+ if (documentBuilder == null) {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ documentBuilder = factory.newDocumentBuilder();
+ return documentBuilder;
+ }
+ return documentBuilder;
+ }
+
+ // @SuppressWarnings("unchecked")
+ public static <T extends DataEntity> DataEntityFactory<T> getFactory(
+ Class<T> entityClass) throws Exception {
+ // FIXME Raw types and unchecked casts
+ DataEntityFactory<T> result = (DataEntityFactory<T>) factories
+ .get(entityClass.getSimpleName());
+ if (result == null) {
+ String elementFactoryClassName = PACKAGE_DAO + "."
+ + entityClass.getSimpleName() + "Factory";
+
+ Class<? extends DataEntityFactory<T>> factoryClass = (Class<? extends DataEntityFactory<T>>) Class
+ .forName(elementFactoryClassName).asSubclass(
+ DataEntityFactory.class);
+
+ result = factoryClass.newInstance();
+ factories.put(entityClass.getSimpleName(), result);
+ }
+ return result;
+ }
+
+ public static DataEntityFactory<? extends DataEntity> getFactory(
+ String entityClassName) throws Exception {
+ Class<? extends DataEntity> entityClass = Class
+ .forName(entityClassName).asSubclass(DataEntity.class);
+ return getFactory(entityClass);
+ }
+
+ public abstract E createInstance();
+
+ protected Element getElementByTagName(Element xmlElement, String tagName) {
+ Set<Element> elements = getElementsByTagName(xmlElement, tagName);
+ if (elements.size() > 0) {
+ return elements.iterator().next();
+ } else {
+ return null;
+ }
+ }
+
+ protected Set<Element> getElementsByTagName(Element xmlElement,
+ String tagName) {
+ Set<Element> elements = new HashSet<Element>();
+
+ NodeList nodes = xmlElement.getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Node node = nodes.item(i);
+ if (node instanceof Element
+ && tagName.equals(((Element) node).getTagName())) {
+ elements.add((Element) node);
+ }
+ }
+ return elements;
+ }
+
+ public String getElementXML(E element) throws Exception {
+ ByteArrayOutputStream writer = new ByteArrayOutputStream();
+ getElementXML(element, writer);
+ return writer.toString();
+ }
+
+ public void getElementXML(E element, OutputStream os) throws Exception {
+ org.w3c.dom.Document xmlDocument = getBuilder().newDocument();
+ // Propriétés du DOM
+ xmlDocument.setXmlVersion("1.0");
+ xmlDocument.setXmlStandalone(true);
+ // Création de l'arborescence du DOM
+ Element racine = xmlDocument.createElement(element.getClass()
+ .getSimpleName());
+
+ saveXMLElement(xmlDocument, racine, element);
+
+ xmlDocument.appendChild(racine);
+ DOMSource domSource = new DOMSource(xmlDocument);
+ StreamResult result = new StreamResult(os);
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer transformer = tf.newTransformer();
+ transformer.transform(domSource, result);
+ }
+
+ protected String getProperty(Element xmlElement, String tagName) {
+ Element element = getElementByTagName(xmlElement, tagName);
+ if (element != null) {
+ return element.getFirstChild().getNodeValue();
+ } else {
+ return null;
+ }
+ }
+
+ public <T extends DataEntity> Set<T> loadCollection(String tagSetName,
+ String tagName, Class<T> clazz, Element xmlElement,
+ DataEntity parentData) throws Exception {
+ Set<T> entities = new HashSet<T>();
+
+ Element xmlCollection = getElementByTagName(xmlElement, tagSetName);
+ if (xmlCollection != null) {
+ DataEntityFactory<T> elementFactory = getFactory(clazz);
+
+ Set<Element> list = getElementsByTagName(xmlCollection, tagName);
+ for (Element element : list) {
+ T entity = elementFactory.loadXMLElement(element);
+ entity.setParentData(parentData);
+ entities.add(entity);
+ }
+ }
+
+ return entities;
+ }
+
+ public E loadXMLElement(Element xmlElement) throws Exception {
+ E element = createInstance();
+ return element;
+ }
+
+ public <T extends DataEntity> void saveCollection(Set<T> entities,
+ String tagSetName, String tagName, Class<T> clazz,
+ Document document, Element xmlElement) throws Exception {
+ if (entities != null && entities.size() > 0) {
+ Element xmlCollection = document.createElement(tagSetName);
+ DataEntityFactory<T> elementFactory = getFactory(clazz);
+ for (T entity : entities) {
+ Element childElement = document.createElement(tagName);
+ // TODO
+ // if (entity instanceof LoggableElement) {
+ // elementFactory.saveXMLElementByReference
+ elementFactory.saveXMLElement(document, childElement, entity);
+ xmlCollection.appendChild(childElement);
+ }
+ xmlElement.appendChild(xmlCollection);
+ }
+ }
+
+ public abstract void saveXMLElement(Document document, Element xmlElement,
+ E element) throws Exception;
+
+ protected void setProperty(Document document, Element xmlElement,
+ String tagName, Object value) {
+ if (value != null) {
+ Element xmlProperty = document.createElement(tagName);
+ Text xmlDescriptionText = document.createTextNode(value.toString());
+ xmlProperty.appendChild(xmlDescriptionText);
+ xmlElement.appendChild(xmlProperty);
+ }
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/DescriptorFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/DescriptorFactory.java 2007-12-10 15:20:48 UTC (rev 60)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/DescriptorFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -1,30 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.factories;
-
-import org.w3c.dom.Element;
-
-import fr.cemagref.simexplorer.is.storage.entities.Descriptor;
-
-public class DescriptorFactory<E extends Descriptor> extends
- EntityFactory<Descriptor> {
-
- public static final String KEY_NAME = "name";
- public static final String KEY_VALUE = "value";
-
- public Descriptor createInstance() {
- return new Descriptor();
- }
-
- public Descriptor loadXMLElement(Element xmlElement) throws Exception {
- Descriptor descriptor = super.loadXMLElement(xmlElement);
- descriptor.setName(xmlElement.getAttribute(KEY_NAME));
- descriptor.setValue(xmlElement.getAttribute(KEY_VALUE));
- return descriptor;
- }
-
- public void saveXMLElement(org.w3c.dom.Document document,
- Element xmlElement, Descriptor element) throws Exception {
- xmlElement.setAttribute(KEY_NAME, element.getName());
- xmlElement.setAttribute(KEY_VALUE, element.getValue());
- }
-
-}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/EntityFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/EntityFactory.java 2007-12-10 15:20:48 UTC (rev 60)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/EntityFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -1,185 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.factories;
-
-import java.io.ByteArrayOutputStream;
-import java.io.OutputStream;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
-
-import fr.cemagref.simexplorer.is.storage.entities.Entity;
-
-public abstract class EntityFactory<E extends Entity> {
-
- private final static String PACKAGE_DAO = "fr.cemagref.simexplorer.is.storage.factories";
-
- private static Map<String, EntityFactory<? extends Entity>> factories = new HashMap<String, EntityFactory<? extends Entity>>();
-
- private static DocumentBuilder documentBuilder = null;
-
- public static synchronized DocumentBuilder getBuilder() throws Exception {
- if (documentBuilder == null) {
- DocumentBuilderFactory factory = DocumentBuilderFactory
- .newInstance();
- documentBuilder = factory.newDocumentBuilder();
- return documentBuilder;
- }
- return documentBuilder;
- }
-
- public static EntityFactory<? extends Entity> getFactory(
- String entityClassName) throws Exception {
- Class<? extends Entity> entityClass = Class.forName(entityClassName)
- .asSubclass(Entity.class);
- return getFactory(entityClass);
- }
-
- // @SuppressWarnings("unchecked")
- public static <T extends Entity> EntityFactory<T> getFactory(
- Class<T> entityClass) throws Exception {
- // FIXME Raw types and unchecked casts
- EntityFactory<T> result = (EntityFactory<T>) factories.get(entityClass
- .getSimpleName());
- if (result == null) {
- String elementFactoryClassName = PACKAGE_DAO + "."
- + entityClass.getSimpleName() + "Factory";
-
- Class<? extends EntityFactory<T>> factoryClass = (Class<? extends EntityFactory<T>>) Class
- .forName(elementFactoryClassName).asSubclass(
- EntityFactory.class);
-
- result = factoryClass.newInstance();
- factories.put(entityClass.getSimpleName(), result);
- }
- return result;
- }
-
- public abstract E createInstance();
-
- public E loadXMLElement(Element xmlElement) throws Exception {
- E element = createInstance();
- return element;
- }
-
- protected Set<Element> getElementsByTagName(Element xmlElement,
- String tagName) {
- Set<Element> elements = new HashSet<Element>();
-
- NodeList nodes = xmlElement.getChildNodes();
- for (int i = 0; i < nodes.getLength(); i++) {
- Node node = nodes.item(i);
- if (node instanceof Element
- && tagName.equals(((Element) node).getTagName())) {
- elements.add((Element) node);
- }
- }
- return elements;
- }
-
- protected Element getElementByTagName(Element xmlElement, String tagName) {
- Set<Element> elements = getElementsByTagName(xmlElement, tagName);
- if (elements.size() > 0) {
- return elements.iterator().next();
- } else {
- return null;
- }
- }
-
- protected void setProperty(Document document, Element xmlElement,
- String tagName, Object value) {
- if (value != null) {
- Element xmlProperty = document.createElement(tagName);
- Text xmlDescriptionText = document.createTextNode(value.toString());
- xmlProperty.appendChild(xmlDescriptionText);
- xmlElement.appendChild(xmlProperty);
- }
- }
-
- protected String getProperty(Element xmlElement, String tagName) {
- Element element = getElementByTagName(xmlElement, tagName);
- if (element != null) {
- return element.getFirstChild().getNodeValue();
- } else {
- return null;
- }
- }
-
- public abstract void saveXMLElement(Document document, Element xmlElement,
- E element) throws Exception;
-
- public void getElementXML(E element, OutputStream os) throws Exception {
- org.w3c.dom.Document xmlDocument = getBuilder().newDocument();
- // Propriétés du DOM
- xmlDocument.setXmlVersion("1.0");
- xmlDocument.setXmlStandalone(true);
- // Création de l'arborescence du DOM
- Element racine = xmlDocument.createElement(element.getClass()
- .getSimpleName());
-
- saveXMLElement(xmlDocument, racine, element);
-
- xmlDocument.appendChild(racine);
- DOMSource domSource = new DOMSource(xmlDocument);
- StreamResult result = new StreamResult(os);
- TransformerFactory tf = TransformerFactory.newInstance();
- Transformer transformer = tf.newTransformer();
- transformer.transform(domSource, result);
- }
-
- public String getElementXML(E element) throws Exception {
- ByteArrayOutputStream writer = new ByteArrayOutputStream();
- getElementXML(element, writer);
- return writer.toString();
- }
-
- public <T extends Entity> Set<T> loadCollection(String tagSetName,
- String tagName, Class<T> clazz, Element xmlElement)
- throws Exception {
- Set<T> entities = new HashSet<T>();
-
- Element xmlCollection = getElementByTagName(xmlElement, tagSetName);
- if (xmlCollection != null) {
- EntityFactory<T> elementFactory = getFactory(clazz);
-
- Set<Element> list = getElementsByTagName(xmlCollection, tagName);
- for (Element element : list) {
- T entity = elementFactory.loadXMLElement(element);
- entities.add(entity);
- }
- }
-
- return entities;
- }
-
- public <T extends Entity> void saveCollection(Set<T> entities,
- String tagSetName, String tagName, Class<T> clazz,
- Document document, Element xmlElement) throws Exception {
- if (entities != null && entities.size() > 0) {
- Element xmlCollection = document.createElement(tagSetName);
- EntityFactory<T> elementFactory = getFactory(clazz);
- for (T entity : entities) {
- Element childElement = document.createElement(tagName);
- // TODO
- // if (entity instanceof LoggableElement) {
- // elementFactory.saveXMLElementByReference
- elementFactory.saveXMLElement(document, childElement, entity);
- xmlCollection.appendChild(childElement);
- }
- xmlElement.appendChild(xmlCollection);
- }
- }
-
-}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationApplicationFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationApplicationFactory.java 2007-12-10 15:20:48 UTC (rev 60)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationApplicationFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -1,44 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.factories;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import fr.cemagref.simexplorer.is.storage.entities.Component;
-import fr.cemagref.simexplorer.is.storage.entities.ExplorationApplication;
-import fr.cemagref.simexplorer.is.storage.entities.ExplorationData;
-
-public class ExplorationApplicationFactory extends
- LoggableElementFactory<ExplorationApplication> {
-
- public static final String KEY_DATA = "data";
- public static final String KEY_DATA_NODE = "explorationdata";
- public static final String KEY_COMPONENTS = "components";
- public static final String KEY_COMPONENT_NODE = "component";
-
- @Override
- public void saveXMLElement(Document document, Element xmlElement,
- ExplorationApplication element) throws Exception {
- super.saveXMLElement(document, xmlElement, element);
- saveCollection(element.getExplorations(), KEY_DATA, KEY_DATA_NODE,
- ExplorationData.class, document, xmlElement);
- saveCollection(element.getComponents(), KEY_COMPONENTS,
- KEY_COMPONENT_NODE, Component.class, document, xmlElement);
- }
-
- @Override
- public ExplorationApplication loadXMLElement(Element xmlElement)
- throws Exception {
- ExplorationApplication explorationApplication = super
- .loadXMLElement(xmlElement);
- explorationApplication.setExplorations(loadCollection(KEY_DATA,
- KEY_DATA_NODE, ExplorationData.class, xmlElement));
- explorationApplication.setComponents(loadCollection(KEY_COMPONENTS,
- KEY_COMPONENT_NODE, Component.class, xmlElement));
- return explorationApplication;
- }
-
- public ExplorationApplication createInstance() {
- return new ExplorationApplication();
- }
-
-}
Added: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationApplicationFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationApplicationFactory.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationApplicationFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -0,0 +1,46 @@
+package fr.cemagref.simexplorer.is.storage.factories;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import fr.cemagref.simexplorer.is.storage.entities.data.Component;
+import fr.cemagref.simexplorer.is.storage.entities.data.ExplorationApplication;
+import fr.cemagref.simexplorer.is.storage.entities.data.ExplorationData;
+
+public class ExplorationApplicationFactory extends
+ LoggableElementFactory<ExplorationApplication> {
+
+ public static final String KEY_DATA = "data";
+ public static final String KEY_DATA_NODE = "explorationdata";
+ public static final String KEY_COMPONENTS = "components";
+ public static final String KEY_COMPONENT_NODE = "component";
+
+ @Override
+ public void saveXMLElement(Document document, Element xmlElement,
+ ExplorationApplication element) throws Exception {
+ super.saveXMLElement(document, xmlElement, element);
+ saveCollection(element.getExplorations(), KEY_DATA, KEY_DATA_NODE,
+ ExplorationData.class, document, xmlElement);
+ saveCollection(element.getComponents(), KEY_COMPONENTS,
+ KEY_COMPONENT_NODE, Component.class, document, xmlElement);
+ }
+
+ @Override
+ public ExplorationApplication loadXMLElement(Element xmlElement)
+ throws Exception {
+ ExplorationApplication explorationApplication = super
+ .loadXMLElement(xmlElement);
+ explorationApplication.setExplorations(loadCollection(KEY_DATA,
+ KEY_DATA_NODE, ExplorationData.class, xmlElement,
+ explorationApplication));
+ explorationApplication.setComponents(loadCollection(KEY_COMPONENTS,
+ KEY_COMPONENT_NODE, Component.class, xmlElement,
+ explorationApplication));
+ return explorationApplication;
+ }
+
+ public ExplorationApplication createInstance() {
+ return new ExplorationApplication();
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationDataFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationDataFactory.java 2007-12-10 15:20:48 UTC (rev 60)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationDataFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -1,47 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.factories;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import fr.cemagref.simexplorer.is.storage.entities.ConstantValue;
-import fr.cemagref.simexplorer.is.storage.entities.ExplorationData;
-import fr.cemagref.simexplorer.is.storage.entities.Result;
-
-public class ExplorationDataFactory extends
- LoggableElementFactory<ExplorationData> {
-
- public static final String KEY_RESULT = "result";
- public static final String KEY_VALUES = "values";
- public static final String KEY_VALUE = "value";
-
- @Override
- public ExplorationData loadXMLElement(Element xmlElement) throws Exception {
- ExplorationData explorationData = super.loadXMLElement(xmlElement);
- explorationData.setResult((Result) getFactory(Result.class)
- .loadXMLElement(getElementByTagName(xmlElement, KEY_RESULT)));
- explorationData.setValuesMap(loadCollection(KEY_VALUES, KEY_VALUE,
- ConstantValue.class, xmlElement));
- return explorationData;
- }
-
- @Override
- public void saveXMLElement(Document document, Element xmlElement,
- ExplorationData element) throws Exception {
- super.saveXMLElement(document, xmlElement, element);
-
- Element xmlResult = document.createElement(KEY_RESULT);
- getFactory(Result.class).saveXMLElement(document, xmlResult,
- element.getResult());
- xmlElement.appendChild(xmlResult);
-
- saveCollection(element.getValuesMap(), KEY_VALUES, KEY_VALUE,
- ConstantValue.class, document, xmlElement);
-
- }
-
- @Override
- public ExplorationData createInstance() {
- return new ExplorationData();
- }
-
-}
Added: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationDataFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationDataFactory.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationDataFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -0,0 +1,47 @@
+package fr.cemagref.simexplorer.is.storage.factories;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import fr.cemagref.simexplorer.is.storage.entities.data.ConstantValue;
+import fr.cemagref.simexplorer.is.storage.entities.data.ExplorationData;
+import fr.cemagref.simexplorer.is.storage.entities.data.Result;
+
+public class ExplorationDataFactory extends
+ LoggableElementFactory<ExplorationData> {
+
+ public static final String KEY_RESULT = "result";
+ public static final String KEY_VALUES = "values";
+ public static final String KEY_VALUE = "value";
+
+ @Override
+ public ExplorationData loadXMLElement(Element xmlElement) throws Exception {
+ ExplorationData explorationData = super.loadXMLElement(xmlElement);
+ explorationData.setResult((Result) getFactory(Result.class)
+ .loadXMLElement(getElementByTagName(xmlElement, KEY_RESULT)));
+ explorationData.setValuesMap(loadCollection(KEY_VALUES, KEY_VALUE,
+ ConstantValue.class, xmlElement, explorationData));
+ return explorationData;
+ }
+
+ @Override
+ public void saveXMLElement(Document document, Element xmlElement,
+ ExplorationData element) throws Exception {
+ super.saveXMLElement(document, xmlElement, element);
+
+ Element xmlResult = document.createElement(KEY_RESULT);
+ getFactory(Result.class).saveXMLElement(document, xmlResult,
+ element.getResult());
+ xmlElement.appendChild(xmlResult);
+
+ saveCollection(element.getValuesMap(), KEY_VALUES, KEY_VALUE,
+ ConstantValue.class, document, xmlElement);
+
+ }
+
+ @Override
+ public ExplorationData createInstance() {
+ return new ExplorationData();
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/FileEntityFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/FileEntityFactory.java 2007-12-10 15:20:48 UTC (rev 60)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/FileEntityFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -1,11 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.factories;
-
-import fr.cemagref.simexplorer.is.storage.attachment.AttachmentHandler;
-import fr.cemagref.simexplorer.is.storage.attachment.fs.FileSystemAttachmentHandler;
-import fr.cemagref.simexplorer.is.storage.database.DatabaseConstants;
-import fr.cemagref.simexplorer.is.storage.entities.FileEntity;
-
-public abstract class FileEntityFactory<E extends FileEntity> extends
- EntityFactory<E> implements DatabaseConstants {
-
-}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LibraryFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LibraryFactory.java 2007-12-10 15:20:48 UTC (rev 60)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LibraryFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -1,12 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.factories;
-
-import fr.cemagref.simexplorer.is.storage.entities.Library;
-
-public class LibraryFactory extends LoggableElementFactory<Library> {
-
- @Override
- public Library createInstance() {
- return new Library();
- }
-
-}
Added: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LibraryFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LibraryFactory.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LibraryFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -0,0 +1,12 @@
+package fr.cemagref.simexplorer.is.storage.factories;
+
+import fr.cemagref.simexplorer.is.storage.entities.data.Library;
+
+public class LibraryFactory extends LoggableElementFactory<Library> {
+
+ @Override
+ public Library createInstance() {
+ return new Library();
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LoggableElementFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LoggableElementFactory.java 2007-12-10 15:20:48 UTC (rev 60)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LoggableElementFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -1,50 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.factories;
-
-import org.w3c.dom.Element;
-
-import fr.cemagref.simexplorer.is.storage.database.DatabaseConstants;
-import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
-
-public abstract class LoggableElementFactory<E extends LoggableElement> extends
- FileEntityFactory<E> implements DatabaseConstants {
-
- private static final String KEY_DESCRIPTION = "description";
-
- @Override
- public E loadXMLElement(Element xmlElement) throws Exception {
- E element = super.loadXMLElement(xmlElement);
- element.setUuid(getProperty(xmlElement, KEY_UUID));
- element.setName(getProperty(xmlElement, KEY_NAME));
- element.setType(getProperty(xmlElement, KEY_TYPE));
- element.setDescription(getProperty(xmlElement, KEY_DESCRIPTION));
- element.setVersion(getProperty(xmlElement, KEY_VERSION));
-
- // FIXME Convert
- /*
- * element.setCreationDate(new Date(getProperty(xmlElement,
- * KEY_CREATIONDATE)));
- */
-
- element.setHash(getProperty(xmlElement, KEY_HASH));
- return element;
- }
-
- @Override
- public void saveXMLElement(org.w3c.dom.Document document,
- Element xmlElement, E element) throws Exception {
-
- setProperty(document, xmlElement, KEY_UUID, element.getUuid());
- setProperty(document, xmlElement, KEY_NAME, element.getName());
- setProperty(document, xmlElement, KEY_TYPE, element.getType());
- setProperty(document, xmlElement, KEY_DESCRIPTION, element
- .getDescription());
- setProperty(document, xmlElement, KEY_VERSION, element.getVersion());
- /*
- * setProperty(document, xmlElement, KEY_CREATIONDATE,
- * element.getCreationDate());
- */
- setProperty(document, xmlElement, KEY_HASH, element.getHash());
-
- }
-
-}
Added: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LoggableElementFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LoggableElementFactory.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LoggableElementFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -0,0 +1,54 @@
+package fr.cemagref.simexplorer.is.storage.factories;
+
+import org.w3c.dom.Element;
+
+import fr.cemagref.simexplorer.is.storage.database.DatabaseConstants;
+import fr.cemagref.simexplorer.is.storage.entities.data.LoggableElement;
+
+public abstract class LoggableElementFactory<E extends LoggableElement> extends
+ DataEntityFactory<E> implements DatabaseConstants {
+
+ private static final String KEY_DESCRIPTION = "description";
+
+ @Override
+ public E loadXMLElement(Element xmlElement) throws Exception {
+ E element = super.loadXMLElement(xmlElement);
+ /*
+ * element.setUuid(getProperty(xmlElement, KEY_UUID));
+ * element.setName(getProperty(xmlElement, KEY_NAME));
+ * element.setType(getProperty(xmlElement, KEY_TYPE));
+ * element.setDescription(getProperty(xmlElement, KEY_DESCRIPTION));
+ * element.setVersion(getProperty(xmlElement, KEY_VERSION));
+ */
+ // FIXME Load metadata
+ /*
+ * element.setCreationDate(new Date(getProperty(xmlElement,
+ * KEY_CREATIONDATE)));
+ */
+
+ // element.setHash(getProperty(xmlElement, KEY_HASH));
+ return element;
+ }
+
+ @Override
+ public void saveXMLElement(org.w3c.dom.Document document,
+ Element xmlElement, E element) throws Exception {
+
+ // FIXME save metadata
+
+ /*
+ * setProperty(document, xmlElement, KEY_UUID, element.getUuid());
+ * setProperty(document, xmlElement, KEY_NAME, element.getName());
+ * setProperty(document, xmlElement, KEY_TYPE, element.getType());
+ * setProperty(document, xmlElement, KEY_DESCRIPTION, element
+ * .getDescription()); setProperty(document, xmlElement, KEY_VERSION,
+ * element.getVersion()); /* setProperty(document, xmlElement,
+ * KEY_CREATIONDATE, element.getCreationDate());
+ */
+ /*
+ * setProperty(document, xmlElement, KEY_HASH, element.getHash());
+ */
+
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/RepositoryFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/RepositoryFactory.java 2007-12-10 15:20:48 UTC (rev 60)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/RepositoryFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -1,22 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.factories;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import fr.cemagref.simexplorer.is.storage.entities.Repository;
-
-public class RepositoryFactory<E extends Repository> extends
- EntityFactory<Repository> {
-
- @Override
- public Repository createInstance() {
- return new Repository();
- }
-
- @Override
- public void saveXMLElement(Document document, Element xmlElement,
- Repository element) throws Exception {
-
- }
-
-}
Added: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/RepositoryFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/RepositoryFactory.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/RepositoryFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -0,0 +1,22 @@
+package fr.cemagref.simexplorer.is.storage.factories;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import fr.cemagref.simexplorer.is.storage.entities.data.Repository;
+
+public class RepositoryFactory<E extends Repository> extends
+ DataEntityFactory<Repository> {
+
+ @Override
+ public Repository createInstance() {
+ return new Repository();
+ }
+
+ @Override
+ public void saveXMLElement(Document document, Element xmlElement,
+ Repository element) throws Exception {
+
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ResultFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ResultFactory.java 2007-12-10 15:20:48 UTC (rev 60)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ResultFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -1,21 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.factories;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import fr.cemagref.simexplorer.is.storage.entities.Result;
-
-public class ResultFactory<E extends Result> extends FileEntityFactory<Result> {
-
- @Override
- public Result createInstance() {
- return new Result();
- }
-
- @Override
- public void saveXMLElement(Document document, Element xmlElement,
- Result element) throws Exception {
-
- }
-
-}
Added: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ResultFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ResultFactory.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ResultFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -0,0 +1,21 @@
+package fr.cemagref.simexplorer.is.storage.factories;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import fr.cemagref.simexplorer.is.storage.entities.data.Result;
+
+public class ResultFactory<E extends Result> extends DataEntityFactory<Result> {
+
+ @Override
+ public Result createInstance() {
+ return new Result();
+ }
+
+ @Override
+ public void saveXMLElement(Document document, Element xmlElement,
+ Result element) throws Exception {
+
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/StructureFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/StructureFactory.java 2007-12-10 15:20:48 UTC (rev 60)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/StructureFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -1,8 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.factories;
-
-import fr.cemagref.simexplorer.is.storage.entities.Structure;
-
-public abstract class StructureFactory<E extends Structure> extends
- EntityFactory<Structure> {
-
-}
Added: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/StructureFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/StructureFactory.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/StructureFactory.java 2007-12-10 15:21:14 UTC (rev 61)
@@ -0,0 +1,8 @@
+package fr.cemagref.simexplorer.is.storage.factories;
+
+import fr.cemagref.simexplorer.is.storage.entities.data.Structure;
+
+public abstract class StructureFactory<E extends Structure> extends
+ DataEntityFactory<Structure> {
+
+}
1
0
r60 - trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine
by glandais@users.labs.libre-entreprise.org 10 Dec '07
by glandais@users.labs.libre-entreprise.org 10 Dec '07
10 Dec '07
Author: glandais
Date: 2007-12-10 15:20:48 +0000 (Mon, 10 Dec 2007)
New Revision: 60
Modified:
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/FSStorageEngine.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java
Log:
Pour compilation
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/FSStorageEngine.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/FSStorageEngine.java 2007-12-10 15:20:06 UTC (rev 59)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/FSStorageEngine.java 2007-12-10 15:20:48 UTC (rev 60)
@@ -1,26 +1,107 @@
package fr.cemagref.simexplorer.is.storage.engine;
-import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collections;
import java.util.List;
-import org.apache.lucene.document.Field;
-import org.w3c.dom.Element;
-
-import fr.cemagref.simexplorer.is.storage.attachment.AttachmentHandler;
-import fr.cemagref.simexplorer.is.storage.attachment.fs.FileSystemAttachmentHandler;
+import fr.cemagref.simexplorer.is.storage.attachment.handler.AttachmentHandler;
+import fr.cemagref.simexplorer.is.storage.attachment.handler.FileSystemAttachmentHandler;
import fr.cemagref.simexplorer.is.storage.database.lucene.LuceneDatabase;
-import fr.cemagref.simexplorer.is.storage.entities.FileEntity;
-import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
-import fr.cemagref.simexplorer.is.storage.entities.Version;
-import fr.cemagref.simexplorer.is.storage.factories.EntityFactory;
-import fr.cemagref.simexplorer.is.storage.factories.FileEntityFactory;
+import fr.cemagref.simexplorer.is.storage.entities.data.LoggableElement;
+import fr.cemagref.simexplorer.is.storage.entities.metadata.Version;
+import fr.cemagref.simexplorer.is.storage.factories.DataEntityFactory;
import fr.cemagref.simexplorer.is.storage.factories.LoggableElementFactory;
public class FSStorageEngine extends StorageEngine {
+ @Override
+ public void close() throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void deleteData(LoggableElement entity, String field)
+ throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void exportElement(LoggableElement element, OutputStream os)
+ throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public LoggableElement getElement(String uuid) throws Exception {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public LoggableElement getElementVersion(String uuid, Version version)
+ throws Exception {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<Version> getVersions(String uuid) throws Exception {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public LoggableElement importElement(InputStream inputStream)
+ throws Exception {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public LoggableElement newElement(LoggableElement element) throws Exception {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void open() throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public InputStream retrieveData(LoggableElement entity, String field)
+ throws Exception {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public LoggableElement saveElement(LoggableElement element)
+ throws Exception {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void storeData(LoggableElement entity, String field, InputStream is)
+ throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public LoggableElement synchronizeElement(LoggableElement element)
+ throws Exception {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
private static AttachmentHandler handler;
private static boolean handlerInit = false;
@@ -37,9 +118,9 @@
}
@Override
- public void storeData(FileEntity entity, String field, InputStream is)
+ public void storeData(LoggableElement entity, String field, InputStream is)
throws Exception {
- getHandler().storeData(entity, field, is);
+ getHandler().storeData(database, entity, field, is);
}
@@ -48,7 +129,7 @@
throws Exception {
LoggableElement completeElement = database.getElement(element
.getUuid(), element.getVersion());
- LoggableElementFactory<LoggableElement> factory = (LoggableElementFactory<LoggableElement>) EntityFactory
+ LoggableElementFactory<LoggableElement> factory = (LoggableElementFactory<LoggableElement>) DataEntityFactory
.getFactory(completeElement.getClass());
factory.getElementXML(element, os);
}
@@ -62,15 +143,15 @@
public LoggableElement getElementVersion(String uuid, Version version)
throws Exception {
- /*
+
// FIXME
String strXMLElement = document.get(KEY_XML);
InputStream is = new ByteArrayInputStream(strXMLElement.getBytes());
- org.w3c.dom.Document xmlDocument = EntityFactory.getBuilder().parse(is);
+ org.w3c.dom.Document xmlDocument = DataEntityFactory.getBuilder().parse(is);
LoggableElement element = factory.loadXMLElement((Element) xmlDocument
.getFirstChild());
- */
+
return database.getElement(uuid, version);
}
@@ -94,12 +175,12 @@
throw new Exception(element.getUuid() + " already exist");
}
element.setVersion("1");
- /*
- * FIXME
- document.add(new Field(KEY_XML, factory.getElementXML(element),
- Field.Store.COMPRESS, Field.Index.NO));
- */
+ // FIXME
+ //document.add(new Field(KEY_XML, factory.getElementXML(element),
+ // Field.Store.COMPRESS, Field.Index.NO));
+
+
database.insertElement(element);
return getElement(element.getUuid());
}
@@ -127,11 +208,10 @@
element.setVersion(version.toString());
- /*
- * FIXME
- document.add(new Field(KEY_XML, factory.getElementXML(element),
- Field.Store.COMPRESS, Field.Index.NO));
- */
+ // FIXME
+ //document.add(new Field(KEY_XML, factory.getElementXML(element),
+ // Field.Store.COMPRESS, Field.Index.NO));
+
database.insertElement(element);
return getElement(element.getUuid());
@@ -146,7 +226,7 @@
@Override
public void deleteData(FileEntity entity, String field) throws Exception {
- getHandler().deleteData(entity, field);
+ getHandler().deleteData(database, entity, field);
}
@Override
@@ -154,6 +234,6 @@
throws Exception {
return getHandler().retrieveData(entity, field);
}
-
+*/
}
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2007-12-10 15:20:06 UTC (rev 59)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2007-12-10 15:20:48 UTC (rev 60)
@@ -5,9 +5,8 @@
import java.util.List;
import fr.cemagref.simexplorer.is.storage.database.Database;
-import fr.cemagref.simexplorer.is.storage.entities.FileEntity;
-import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
-import fr.cemagref.simexplorer.is.storage.entities.Version;
+import fr.cemagref.simexplorer.is.storage.entities.data.LoggableElement;
+import fr.cemagref.simexplorer.is.storage.entities.metadata.Version;
public abstract class StorageEngine {
@@ -50,32 +49,32 @@
* Content
* @throws Exception
*/
- public abstract void storeData(FileEntity entity, String field,
+ public abstract void storeData(LoggableElement entity, String field,
InputStream is) throws Exception;
/**
* Retrieve content
*
* @param entity
- * Entity related to content
+ * DataEntity related to content
* @param field
* Unique field for content
* @return Content
* @throws Exception
*/
- public abstract InputStream retrieveData(FileEntity entity, String field)
+ public abstract InputStream retrieveData(LoggableElement entity, String field)
throws Exception;
/**
* Delete content
*
* @param entity
- * Entity related to content
+ * DataEntity related to content
* @param field
* Unique field for content
* @throws Exception
*/
- public abstract void deleteData(FileEntity entity, String field)
+ public abstract void deleteData(LoggableElement entity, String field)
throws Exception;
}
1
0
r59 - in trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database: . lucene
by glandais@users.labs.libre-entreprise.org 10 Dec '07
by glandais@users.labs.libre-entreprise.org 10 Dec '07
10 Dec '07
Author: glandais
Date: 2007-12-10 15:20:06 +0000 (Mon, 10 Dec 2007)
New Revision: 59
Modified:
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java
Log:
Database ne traite plus que les metadata
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java 2007-12-10 15:19:28 UTC (rev 58)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java 2007-12-10 15:20:06 UTC (rev 59)
@@ -1,16 +1,16 @@
package fr.cemagref.simexplorer.is.storage.database;
+import java.io.Reader;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import fr.cemagref.simexplorer.is.storage.entities.Entity;
-import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
-import fr.cemagref.simexplorer.is.storage.entities.Version;
+import fr.cemagref.simexplorer.is.storage.entities.metadata.MetaDataEntity;
+import fr.cemagref.simexplorer.is.storage.entities.metadata.Version;
/**
- * Interface of a dabase able to manage elements
+ * Interface of a database able to manage metadata elements
*
* @author landais
*
@@ -40,8 +40,20 @@
* Element to insert
* @throws Exception
*/
- public abstract void insertElement(LoggableElement element) throws Exception;
+ public abstract void insertElement(MetaDataEntity element) throws Exception;
+ /**
+ * Index content for an element
+ *
+ * @param entity
+ * Related entity
+ * @param field
+ * Related field
+ * @param is
+ * Content
+ */
+ public abstract void indexAdd(MetaDataEntity entity, List<Reader> readers)
+ throws Exception;
// Read
@@ -55,7 +67,7 @@
* @return Fund element, null if not fund
* @throws Exception
*/
- public abstract LoggableElement getElement(String uuid, Version version)
+ public abstract MetaDataEntity getElement(String uuid, Version version)
throws Exception;
/**
@@ -77,9 +89,8 @@
* exists
* @throws Exception
*/
- public LoggableElement getElementLatestVersion(String uuid)
- throws Exception {
- LoggableElement result = null;
+ public MetaDataEntity getElementLatestVersion(String uuid) throws Exception {
+ MetaDataEntity result = null;
// Get all versions
List<Version> versions = getVersions(uuid);
@@ -109,7 +120,7 @@
* @return Element list
* @throws Exception
*/
- public abstract Set<LoggableElement> findElementsById(String uuid)
+ public abstract Set<MetaDataEntity> findElementsById(String uuid)
throws Exception;
/**
@@ -120,24 +131,10 @@
* @return Element list
* @throws Exception
*/
- public abstract Set<LoggableElement> findElementsByProperties(
+ public abstract Set<MetaDataEntity> findElementsByProperties(
Map<String, String> properties) throws Exception;
/**
- * Retrieve elements of a class with specific properties
- *
- * @param properties
- * Matching properties needed
- * @param entityClass
- * Class searched
- * @return Element list
- * @throws Exception
- */
- public abstract Set<LoggableElement> findElementsByProperties(
- Map<String, String> properties, Class<? extends Entity> entityClass)
- throws Exception;
-
- /**
* Retrieve elements by content search
*
* @param searchedText
@@ -145,7 +142,7 @@
* @return Element list
* @throws Exception
*/
- public abstract Set<LoggableElement> findElementsByContentSearch(
+ public abstract Set<MetaDataEntity> findElementsByContentSearch(
String queryText) throws Exception;
// Delete
@@ -157,7 +154,7 @@
* Element to delete
* @throws Exception
*/
- public void deleteElement(LoggableElement element) throws Exception {
+ public void deleteElement(MetaDataEntity element) throws Exception {
deleteElement(element.getUuid(), element.getVersion());
}
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java 2007-12-10 15:19:28 UTC (rev 58)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java 2007-12-10 15:20:06 UTC (rev 59)
@@ -9,10 +9,6 @@
public interface DatabaseConstants {
/**
- * Field name for class name
- */
- public static final String KEY_CLASSNAME = "simexplorer.classname";
- /**
* Field name for id
*/
public static final String KEY_UUID = "simexplorer.uuid";
@@ -21,9 +17,9 @@
*/
public static final String KEY_NAME = "simexplorer.name";
/**
- * Field name for hash
+ * Field name for type
*/
- public static final String KEY_HASH = "simexplorer.hash";
+ public static final String KEY_TYPE = "simexplorer.type";
/**
* Field name for description
*/
@@ -33,20 +29,36 @@
*/
public static final String KEY_VERSION = "simexplorer.version";
/**
- * Field name for type
- */
- public static final String KEY_TYPE = "simexplorer.type";
- /**
* Field name for creation date
*/
public static final String KEY_CREATIONDATE = "simexplorer.creationdate";
/**
+ * Field name for hash
+ */
+ public static final String KEY_HASH = "simexplorer.hash";
+ /**
+ * Field name for descriptor
+ */
+ public static final String KEY_DESCRIPTOR = "simexplorer.descriptor";
+ /**
* Field name for id
*/
+ public static final String KEY_PARENTDATA_UUID = "simexplorer.parentdata.uuid";
+ /**
+ * Field name for id
+ */
+ public static final String KEY_PARENTDATA_VERSION = "simexplorer.parentdata.version";
+ /**
+ * Field name for id
+ */
public static final String KEY_PARENTVERSION_UUID = "simexplorer.parentversion.uuid";
/**
* Field name for id
*/
public static final String KEY_PARENTVERSION_VERSION = "simexplorer.parentversion.version";
+ /**
+ * Field name for searchable content
+ */
+ public static final String KEY_SEARCHABLE_CONTENT = "simexplorer.searchablecontent";
}
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2007-12-10 15:19:28 UTC (rev 58)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2007-12-10 15:20:06 UTC (rev 59)
@@ -1,8 +1,9 @@
package fr.cemagref.simexplorer.is.storage.database.lucene;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringReader;
import java.util.ArrayList;
+import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -15,6 +16,7 @@
import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
+import org.apache.lucene.document.Fieldable;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
@@ -27,14 +29,10 @@
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
-import org.w3c.dom.Element;
import fr.cemagref.simexplorer.is.storage.database.Database;
-import fr.cemagref.simexplorer.is.storage.entities.Entity;
-import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
-import fr.cemagref.simexplorer.is.storage.entities.Version;
-import fr.cemagref.simexplorer.is.storage.factories.EntityFactory;
-import fr.cemagref.simexplorer.is.storage.factories.LoggableElementFactory;
+import fr.cemagref.simexplorer.is.storage.entities.metadata.MetaDataEntity;
+import fr.cemagref.simexplorer.is.storage.entities.metadata.Version;
/**
* Lucene implementation
@@ -96,23 +94,12 @@
}
@Override
- public void insertElement(LoggableElement element) throws Exception {
- // Add all children to database
- Set<LoggableElement> children = element.getChildren();
- for (LoggableElement loggableElement : children) {
- insertElement(loggableElement);
- }
-
- // Retrieve element factory
- Class<? extends LoggableElement> clazz = element.getClass();
- LoggableElementFactory<LoggableElement> elementFactory = (LoggableElementFactory<LoggableElement>) LoggableElementFactory
- .getFactory(clazz);
-
+ public void insertElement(MetaDataEntity element) throws Exception {
// Save element to a Lucene document
- Document document = saveLuceneElement(elementFactory, element);
+ Document document = saveLuceneElement(element);
// Retrieve existing element with same id/version
- LoggableElement oldElement = getElement(element.getUuid(), element
+ MetaDataEntity oldElement = getElement(element.getUuid(), element
.getVersion());
// Delete element if exists, for update
if (oldElement != null) {
@@ -120,7 +107,6 @@
deleteElement(element);
}
- // FIXME thread safe
// add document to index
writer.addDocument(document);
// write index
@@ -128,20 +114,14 @@
}
@Override
- public LoggableElement getElement(String uuid, Version version)
+ public MetaDataEntity getElement(String uuid, Version version)
throws Exception {
- LoggableElement result = null;
+ MetaDataEntity result = null;
- // Retrieve element with id/version
- Map<String, String> properties = new HashMap<String, String>();
- properties.put(KEY_UUID, uuid);
- properties.put(KEY_VERSION, version.toString());
-
- // Search elements
- LuceneHits hits = findHits(properties);
+ LuceneHits hits = getHitsByIdVersion(uuid, version);
if (hits.getHits().length() != 0) {
// convert first document to element
- result = convertDocumentToElement(hits.getHits().doc(0));
+ result = loadLuceneElement(hits.getHits().doc(0));
}
hits.closeSearcher();
@@ -149,6 +129,24 @@
return result;
}
+ /**
+ * @param uuid
+ * @param version
+ * @return
+ * @throws Exception
+ */
+ private LuceneHits getHitsByIdVersion(String uuid, Version version)
+ throws Exception {
+ // Retrieve element with id/version
+ Map<String, String> properties = new HashMap<String, String>();
+ properties.put(KEY_UUID, uuid);
+ properties.put(KEY_VERSION, version.toString());
+
+ // Search elements
+ LuceneHits hits = findHits(properties);
+ return hits;
+ }
+
@Override
public List<Version> getVersions(String uuid) throws Exception {
// Retrieve all document corresponding to id
@@ -165,9 +163,9 @@
return versions;
}
-
+
@Override
- public Set<LoggableElement> findElementsById(String uuid) throws Exception {
+ public Set<MetaDataEntity> findElementsById(String uuid) throws Exception {
// Create hash map with id
Map<String, String> properties = new HashMap<String, String>();
properties.put(KEY_UUID, uuid);
@@ -176,43 +174,31 @@
}
@Override
- public Set<LoggableElement> findElementsByProperties(
+ public Set<MetaDataEntity> findElementsByProperties(
Map<String, String> properties) throws Exception {
// Return all elements parsed from documents fund
return convertHitsToElements(findHits(properties));
}
@Override
- public Set<LoggableElement> findElementsByProperties(
- Map<String, String> properties, Class<? extends Entity> entityClass)
- throws Exception {
- // Create hash map with properties and entity class name
- Map<String, String> props = new HashMap<String, String>();
- props.putAll(properties);
- props.put(KEY_CLASSNAME, entityClass.getName());
- // Return all elements parsed from documents fund
- return convertHitsToElements(findHits(properties));
- }
-
- @Override
- public Set<LoggableElement> findElementsByContentSearch(String queryText)
- throws Exception {
+ public Set<MetaDataEntity> findElementsByContentSearch(String queryText) throws Exception {
// Create a searcher
Searcher searcher = new IndexSearcher(indexDirectory);
Analyzer analyzer = new SimpleAnalyzer();
- QueryParser parser = new QueryParser("__all__", analyzer);
+ QueryParser parser = new QueryParser(KEY_SEARCHABLE_CONTENT, analyzer);
Query luceneQuery = parser.parse(queryText);
-
+
// Create a bean with hits and searcher
- LuceneHits luceneHits = new LuceneHits(searcher.search(luceneQuery), searcher);
-
+ LuceneHits luceneHits = new LuceneHits(searcher.search(luceneQuery),
+ searcher);
+
// Convert hits to elements
- Set<LoggableElement> result = convertHitsToElements(luceneHits);
-
- return result;
+ Set<MetaDataEntity> result = convertHitsToElements(luceneHits);
+
+ return result;
}
-
+
@Override
public void deleteElements(String uuid) throws Exception {
// Delete all documents by term search
@@ -223,7 +209,7 @@
@Override
public void deleteElement(String uuid, Version version) throws Exception {
// Delete element in db with term search
- Term[] terms = new Term[3];
+ Term[] terms = new Term[2];
terms[0] = new Term(KEY_UUID, uuid);
terms[1] = new Term(KEY_VERSION, version.toString());
writer.deleteDocuments(terms);
@@ -232,7 +218,9 @@
/**
* Find all documents matching properties
- * @param properties criteria
+ *
+ * @param properties
+ * criteria
* @return Documents and search handle
* @throws Exception
*/
@@ -254,35 +242,21 @@
}
/**
- * Convert a Lucene Document to a real entity
- * @param document Storage
- * @return Element
- * @throws Exception
- */
- private LoggableElement convertDocumentToElement(Document document)
- throws Exception {
- // Retrieve element factory via class name
- String className = document.get(KEY_CLASSNAME);
- LoggableElementFactory<LoggableElement> factory = (LoggableElementFactory<LoggableElement>) LoggableElementFactory
- .getFactory(className);
- // Rebuild element
- return loadLuceneElement(factory, document);
- }
-
- /**
* Convert all Lucene documents to real entities
- * @param hits Document collection
+ *
+ * @param hits
+ * Document collection
* @return Entities list
* @throws Exception
*/
- private Set<LoggableElement> convertHitsToElements(LuceneHits hits)
+ private Set<MetaDataEntity> convertHitsToElements(LuceneHits hits)
throws Exception {
// For all document
- Set<LoggableElement> elements = new HashSet<LoggableElement>();
+ Set<MetaDataEntity> elements = new HashSet<MetaDataEntity>();
for (int i = 0; i < hits.getHits().length(); i++) {
Document document = hits.getHits().doc(i);
// Convert to element
- elements.add(convertDocumentToElement(document));
+ elements.add(loadLuceneElement(document));
}
// Close handle
hits.closeSearcher();
@@ -291,47 +265,143 @@
/**
* Transform a Lucene document into a LoggableElement thanks to a factory
- * @param factory The element factory
- * @param document The document to transform
+ *
+ * @param factory
+ * The element factory
+ * @param document
+ * The document to transform
* @return Instance of element
* @throws Exception
*/
- private LoggableElement loadLuceneElement(
- LoggableElementFactory<LoggableElement> factory, Document document)
- throws Exception {
- LoggableElement element = factory.createInstance();
+ private MetaDataEntity loadLuceneElement(Document document)
+ throws Exception {
+ MetaDataEntity element = new MetaDataEntity();
+ element.setUuid(document.get(KEY_UUID));
element.setName(document.get(KEY_NAME));
- // FIXME toutes les metadonnées
-
+ element.setType(document.get(KEY_TYPE));
+ element.setDescription(document.get(KEY_DESCRIPTION));
+ element.setVersion(document.get(KEY_VERSION));
+ String creationDate = document.get(KEY_CREATIONDATE);
+ long creationDateLong = new Long(creationDate);
+ Date date = new Date(creationDateLong);
+ element.setCreationDate(date);
+ element.setHash(document.get(KEY_HASH));
+
+ Map<String, String> descriptors = new HashMap<String, String>();
+ List<Fieldable> fields = document.getFields();
+ for (Fieldable fieldable : fields) {
+ if (fieldable.name().startsWith(KEY_DESCRIPTOR)) {
+ String field = fieldable.name().replace(KEY_DESCRIPTOR + ".",
+ "");
+ String value = fieldable.stringValue();
+ descriptors.put(field, value);
+ }
+ }
+ element.setDescriptors(descriptors);
+
+ String parentId = document.get(KEY_PARENTDATA_UUID);
+ String parentVersion = document.get(KEY_PARENTDATA_VERSION);
+ if (parentId != null && parentVersion != null) {
+ MetaDataEntity parentData = getElement(parentId, new Version(
+ parentVersion));
+ element.setParentData(parentData);
+ }
+
+ parentId = document.get(KEY_PARENTVERSION_UUID);
+ parentVersion = document.get(KEY_PARENTVERSION_VERSION);
+ if (parentId != null && parentVersion != null) {
+ MetaDataEntity parentByVersion = getElement(document
+ .get(KEY_PARENTVERSION_UUID), new Version(document
+ .get(KEY_PARENTVERSION_VERSION)));
+ element.setParentVersion(parentByVersion);
+ }
+
return element;
}
+ private Field simpleField(String name, String value) {
+ return new Field(name, value, Field.Store.YES, Field.Index.UN_TOKENIZED);
+ }
+
/**
* Transform an element to a Lucene document thanks to a factory
+ *
* @param factory
* @param element
* @return
* @throws Exception
*/
- private Document saveLuceneElement(
- LoggableElementFactory<LoggableElement> factory,
- LoggableElement element) throws Exception {
+ private Document saveLuceneElement(MetaDataEntity element) throws Exception {
Document document = new Document();
- // FIXME save searchable/metadata fields
- document.add(new Field(KEY_UUID, element.getUuid(), Field.Store.YES,
- Field.Index.UN_TOKENIZED));
- document.add(new Field(KEY_DESCRIPTION, element.getDescription(),
- Field.Store.YES, Field.Index.UN_TOKENIZED));
- document.add(new Field(KEY_CLASSNAME, element.getClass().getName(),
- Field.Store.YES, Field.Index.UN_TOKENIZED));
- document.add(new Field(KEY_VERSION, element.getVersion().toString()
- .toString(), Field.Store.YES, Field.Index.UN_TOKENIZED));
+ document.add(simpleField(KEY_UUID, element.getUuid()));
+ document.add(simpleField(KEY_NAME, element.getName()));
+ document.add(simpleField(KEY_TYPE, element.getType()));
+ document.add(simpleField(KEY_DESCRIPTION, element.getDescription()));
+ document.add(simpleField(KEY_VERSION, element.getVersion().toString()));
+ document.add(simpleField(KEY_CREATIONDATE, Long.toString(element
+ .getCreationDate().getTime())));
+ document.add(simpleField(KEY_HASH, element.getHash()));
- // FIXME ne pas serializer
- // Serialize element into document
+ Map<String, String> descriptors = element.getDescriptors();
+ for (Map.Entry<String, String> entry : descriptors.entrySet()) {
+ String key = KEY_DESCRIPTOR + "." + entry.getKey();
+ String value = entry.getValue();
+ document.add(simpleField(key, value));
+ }
+ if (element.getParentData() != null) {
+ document.add(simpleField(KEY_PARENTDATA_UUID, element
+ .getParentData().getUuid()));
+ document.add(simpleField(KEY_PARENTDATA_VERSION, element
+ .getParentData().getVersion().toString()));
+ }
+ if (element.getParentVersion() != null) {
+ document.add(simpleField(KEY_PARENTVERSION_UUID, element
+ .getParentVersion().getUuid()));
+ document.add(simpleField(KEY_PARENTVERSION_VERSION, element
+ .getParentVersion().getVersion().toString()));
+ }
+
return document;
}
+ @Override
+ public void indexAdd(MetaDataEntity entity, List<Reader> readers)
+ throws Exception {
+
+ // search associated document
+ LuceneHits hits = getHitsByIdVersion(entity.getUuid(), entity
+ .getVersion());
+
+ if (hits.getHits().length() > 0) {
+
+ // retrieve document
+ Document document = hits.getHits().doc(0);
+
+ StringBuffer buf = new StringBuffer();
+ for (Reader reader : readers) {
+ for(int c = reader.read(); c != -1; c = reader.read()) {
+ buf.append((char)c);
+ }
+ }
+
+ Reader reader = new StringReader(buf.toString());
+ document.add(new Field(KEY_SEARCHABLE_CONTENT, reader));
+
+ hits.closeSearcher();
+
+ // update document
+ // delete old document
+ deleteElement(document.get(KEY_UUID), new Version(document
+ .get(KEY_VERSION)));
+ // add document to index
+ writer.addDocument(document);
+ // write index
+ writer.flush();
+
+ }
+
+ }
+
}
1
0
r58 - in trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities: . data metadata
by glandais@users.labs.libre-entreprise.org 10 Dec '07
by glandais@users.labs.libre-entreprise.org 10 Dec '07
10 Dec '07
Author: glandais
Date: 2007-12-10 15:19:28 +0000 (Mon, 10 Dec 2007)
New Revision: 58
Added:
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/BaseEntity.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Code.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Component.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Constant.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ConstantValue.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/DataEntity.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ExplorationApplication.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ExplorationData.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Library.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/LoggableElement.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Repository.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Result.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Structure.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/metadata/
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/metadata/MetaDataEntity.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/metadata/Version.java
Removed:
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Code.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Component.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Constant.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ConstantValue.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Descriptor.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Entity.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationApplication.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationData.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/FileEntity.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Library.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/LoggableElement.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Repository.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Result.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Structure.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Version.java
Log:
Extraction des Metadata
Added: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/BaseEntity.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/BaseEntity.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/BaseEntity.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -0,0 +1,5 @@
+package fr.cemagref.simexplorer.is.storage.entities;
+
+public abstract class BaseEntity {
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Code.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Code.java 2007-12-10 15:18:35 UTC (rev 57)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Code.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -1,24 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.entities;
-
-public class Code extends Entity {
-
- private String language;
- private String code;
-
- public String getLanguage() {
- return language;
- }
-
- public void setLanguage(String language) {
- this.language = language;
- }
-
- public String getCode() {
- return code;
- }
-
- public void setCode(String code) {
- this.code = code;
- }
-
-}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Component.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Component.java 2007-12-10 15:18:35 UTC (rev 57)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Component.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -1,62 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.entities;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import fr.cemagref.simexplorer.is.storage.attachment.type.ContentType;
-
-public class Component extends LoggableElement {
-
- Set<Constant> constants;
- Set<Structure> structures;
- Set<Code> codes;
- Set<Library> libraries;
-
- public Set<Constant> getConstants() {
- return constants;
- }
-
- public void setConstants(Set<Constant> constants) {
- this.constants = constants;
- }
-
- public Set<Structure> getStructures() {
- return structures;
- }
-
- public void setStructures(Set<Structure> structures) {
- this.structures = structures;
- }
-
- public Set<Code> getCodes() {
- return codes;
- }
-
- public void setCodes(Set<Code> codes) {
- this.codes = codes;
- }
-
- public Set<Library> getLibraries() {
- return libraries;
- }
-
- public void setLibraries(Set<Library> libraries) {
- this.libraries = libraries;
- }
-
- @Override
- public Set<LoggableElement> getChildren() {
- Set<LoggableElement> elements = new HashSet<LoggableElement>();
- elements.addAll(libraries);
- return elements;
- }
-
- @Override
- public Map<String, ContentType> getContentTypes() throws Exception {
- Map<String, ContentType> contentTypes = new HashMap<String, ContentType>();
- return contentTypes;
- }
-
-}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Constant.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Constant.java 2007-12-10 15:18:35 UTC (rev 57)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Constant.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -1,24 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.entities;
-
-public class Constant extends Entity {
-
- private String name;
- private Class<?> type;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Class<?> getType() {
- return type;
- }
-
- public void setType(Class<?> type) {
- this.type = type;
- }
-
-}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ConstantValue.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ConstantValue.java 2007-12-10 15:18:35 UTC (rev 57)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ConstantValue.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -1,24 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.entities;
-
-public class ConstantValue extends Entity {
-
- private String value;
- private Constant constant;
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- public Constant getConstant() {
- return constant;
- }
-
- public void setConstant(Constant constant) {
- this.constant = constant;
- }
-
-}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Descriptor.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Descriptor.java 2007-12-10 15:18:35 UTC (rev 57)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Descriptor.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -1,24 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.entities;
-
-public class Descriptor extends Entity {
-
- private String name;
- private String value;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
-}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Entity.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Entity.java 2007-12-10 15:18:35 UTC (rev 57)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Entity.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -1,15 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.entities;
-
-public abstract class Entity {
-
- private LoggableElement owner;
-
- public LoggableElement getOwner() {
- return owner;
- }
-
- public void setOwner(LoggableElement owner) {
- this.owner = owner;
- }
-
-}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationApplication.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationApplication.java 2007-12-10 15:18:35 UTC (rev 57)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationApplication.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -1,49 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.entities;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import fr.cemagref.simexplorer.is.storage.attachment.type.ContentType;
-import fr.cemagref.simexplorer.is.storage.attachment.type.ContentTypeFactory;
-import fr.cemagref.simexplorer.is.storage.attachment.type.RawType;
-
-public class ExplorationApplication extends LoggableElement {
-
- private Set<ExplorationData> explorations;
- private Set<Component> components;
-
- public Set<ExplorationData> getExplorations() {
- return explorations;
- }
-
- public void setExplorations(Set<ExplorationData> explorations) {
- this.explorations = explorations;
- }
-
- public Set<Component> getComponents() {
- return components;
- }
-
- public void setComponents(Set<Component> components) {
- this.components = components;
- }
-
- @Override
- public Set<LoggableElement> getChildren() {
- Set<LoggableElement> elements = new HashSet<LoggableElement>();
- elements.addAll(explorations);
- elements.addAll(components);
- return elements;
- }
-
- @Override
- public Map<String, ContentType> getContentTypes() throws Exception {
- Map<String, ContentType> contentTypes = new HashMap<String, ContentType>();
- contentTypes.put("xml", ContentTypeFactory
- .getContentTypeInstance(RawType.class));
- return contentTypes;
- }
-
-}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationData.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationData.java 2007-12-10 15:18:35 UTC (rev 57)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationData.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -1,75 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.entities;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import fr.cemagref.simexplorer.is.storage.attachment.type.ContentType;
-import fr.cemagref.simexplorer.is.storage.attachment.type.ContentTypeFactory;
-import fr.cemagref.simexplorer.is.storage.attachment.type.RawType;
-
-public class ExplorationData extends LoggableElement {
-
- private Set<ConstantValue> valuesMap;
- private Result result;
-
- private ConstantValue findConstantValue(Constant c) {
- for (ConstantValue constantValue : valuesMap) {
- if (c.equals(constantValue.getConstant())) {
- return constantValue;
- }
- }
- return null;
- }
-
- public void setConstantValue(Constant c, String value) {
- ConstantValue constantValue = findConstantValue(c);
- if (constantValue == null) {
- constantValue = new ConstantValue();
- constantValue.setConstant(c);
- valuesMap.add(constantValue);
- }
- constantValue.setValue(value);
- }
-
- public Object getConstantValue(Constant c) {
- ConstantValue constantValue = findConstantValue(c);
- if (constantValue == null) {
- return null;
- } else {
- return constantValue.getValue();
- }
- }
-
- public Result getResult() {
- return result;
- }
-
- public void setResult(Result result) {
- this.result = result;
- }
-
- public Set<ConstantValue> getValuesMap() {
- return valuesMap;
- }
-
- public void setValuesMap(Set<ConstantValue> valuesMap) {
- this.valuesMap = valuesMap;
- }
-
- @Override
- public Set<LoggableElement> getChildren() {
- Set<LoggableElement> elements = new HashSet<LoggableElement>();
- return elements;
- }
-
- @Override
- public Map<String, ContentType> getContentTypes() throws Exception {
- Map<String, ContentType> contentTypes = new HashMap<String, ContentType>();
- contentTypes.put("xml", ContentTypeFactory
- .getContentTypeInstance(RawType.class));
- return contentTypes;
- }
-
-}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/FileEntity.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/FileEntity.java 2007-12-10 15:18:35 UTC (rev 57)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/FileEntity.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -1,11 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.entities;
-
-import java.util.Map;
-
-import fr.cemagref.simexplorer.is.storage.attachment.type.ContentType;
-
-public abstract class FileEntity extends Entity {
-
- public abstract Map<String, ContentType> getContentTypes() throws Exception;
-
-}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Library.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Library.java 2007-12-10 15:18:35 UTC (rev 57)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Library.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -1,28 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.entities;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import fr.cemagref.simexplorer.is.storage.attachment.type.ContentType;
-import fr.cemagref.simexplorer.is.storage.attachment.type.ContentTypeFactory;
-import fr.cemagref.simexplorer.is.storage.attachment.type.RawType;
-
-public class Library extends LoggableElement {
-
- @Override
- public Set<LoggableElement> getChildren() {
- Set<LoggableElement> elements = new HashSet<LoggableElement>();
- return elements;
- }
-
- @Override
- public Map<String, ContentType> getContentTypes() throws Exception {
- Map<String, ContentType> contentTypes = new HashMap<String, ContentType>();
- contentTypes.put("library", ContentTypeFactory
- .getContentTypeInstance(RawType.class));
- return contentTypes;
- }
-
-}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/LoggableElement.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/LoggableElement.java 2007-12-10 15:18:35 UTC (rev 57)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/LoggableElement.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -1,148 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.entities;
-
-import java.util.Date;
-import java.util.Set;
-
-public abstract class LoggableElement extends FileEntity {
-
- private String uuid;
- private String name;
- private String type;
- private String description;
- private Version version;
- private Date creationDate;
- private String hash;
- private Set<Descriptor> descriptors;
- private LoggableElement parentVersion;
-
- public abstract Set<LoggableElement> getChildren();
-
- /**
- * @return the uuid
- */
- public String getUuid() {
- return uuid;
- }
-
- /**
- * @param uuid the uuid to set
- */
- public void setUuid(String uuid) {
- this.uuid = uuid;
- }
-
- /**
- * @return the name
- */
- public String getName() {
- return name;
- }
-
- /**
- * @param name the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * @return the type
- */
- public String getType() {
- return type;
- }
-
- /**
- * @param type the type to set
- */
- public void setType(String type) {
- this.type = type;
- }
-
- /**
- * @return the description
- */
- public String getDescription() {
- return description;
- }
-
- /**
- * @param description the description to set
- */
- public void setDescription(String description) {
- this.description = description;
- }
-
- /**
- * @return the version
- */
- public Version getVersion() {
- return version;
- }
-
- /**
- * @param version the version to set
- */
- public void setVersion(String version) {
- this.version = new Version(version);
- }
-
- /**
- * @return the creationDate
- */
- public Date getCreationDate() {
- return creationDate;
- }
-
- /**
- * @param creationDate the creationDate to set
- */
- public void setCreationDate(Date creationDate) {
- this.creationDate = creationDate;
- }
-
- /**
- * @return the hash
- */
- public String getHash() {
- return hash;
- }
-
- /**
- * @param hash the hash to set
- */
- public void setHash(String hash) {
- this.hash = hash;
- }
-
- /**
- * @return the descriptors
- */
- public Set<Descriptor> getDescriptors() {
- return descriptors;
- }
-
- /**
- * @param descriptors the descriptors to set
- */
- public void setDescriptors(Set<Descriptor> descriptors) {
- this.descriptors = descriptors;
- }
-
- /**
- * @return the parentVersion
- */
- public LoggableElement getParentVersion() {
- return parentVersion;
- }
-
- /**
- * @param parentVersion the parentVersion to set
- */
- public void setParentVersion(LoggableElement parentVersion) {
- this.parentVersion = parentVersion;
- }
-
-
-
-}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Repository.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Repository.java 2007-12-10 15:18:35 UTC (rev 57)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Repository.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -1,5 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.entities;
-
-public class Repository extends Entity {
-
-}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Result.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Result.java 2007-12-10 15:18:35 UTC (rev 57)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Result.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -1,20 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.entities;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import fr.cemagref.simexplorer.is.storage.attachment.type.ContentType;
-import fr.cemagref.simexplorer.is.storage.attachment.type.ContentTypeFactory;
-import fr.cemagref.simexplorer.is.storage.attachment.type.RawType;
-
-public class Result extends FileEntity {
-
- @Override
- public Map<String, ContentType> getContentTypes() throws Exception {
- Map<String, ContentType> contentTypes = new HashMap<String, ContentType>();
- contentTypes.put("result", ContentTypeFactory
- .getContentTypeInstance(RawType.class));
- return contentTypes;
- }
-
-}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Structure.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Structure.java 2007-12-10 15:18:35 UTC (rev 57)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Structure.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -1,5 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.entities;
-
-public abstract class Structure extends Entity {
-
-}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Version.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Version.java 2007-12-10 15:18:35 UTC (rev 57)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Version.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -1,86 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.entities;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.StringTokenizer;
-
-public class Version implements Comparable<Version> {
-
- private List<Integer> pointedVersion;
-
- public Version(String version) {
- super();
- pointedVersion = new ArrayList<Integer>();
- StringTokenizer st = new StringTokenizer(version, ".");
- while (st.hasMoreTokens()) {
- pointedVersion.add(new Integer(st.nextToken()));
- }
- }
-
- public Integer getVersion(int position) {
- if (position < pointedVersion.size()) {
- return pointedVersion.get(position);
- } else {
- return null;
- }
- }
-
- public void setVersion(int position, int subVersion) {
- while (getVersion(position) == null) {
- addSubVersion(0);
- }
- pointedVersion.set(position, subVersion);
- }
-
- public void addSubVersion(int subVersion) {
- pointedVersion.add(subVersion);
- }
-
- public Version incVersion(int position) {
- Version result = new Version(toString());
- while (result.getVersion(position) == null) {
- result.addSubVersion(0);
- }
- result.setVersion(position, result.getVersion(position) + 1);
- return result;
- }
-
- @Override
- public String toString() {
- StringBuffer result = new StringBuffer("");
- for (Integer i : pointedVersion) {
- result.append(i).append(".");
- }
- result.setLength(result.length() - 1);
- return result.toString();
- }
-
- public int compareTo(Version v) {
- int result = 0;
- int position = 0;
- boolean compared = false;
- while (!compared) {
- if (getVersion(position) == null && v.getVersion(position) == null) {
- result = 0;
- compared = true;
- } else {
- if (getVersion(position) == null) {
- result = -1;
- compared = true;
- } else {
- if (v.getVersion(position) == null) {
- result = 1;
- compared = true;
- } else {
- result = getVersion(position).compareTo(
- v.getVersion(position));
- compared = (result != 0);
- }
- }
- }
- position++;
- }
- return result;
- }
-
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Code.java (from rev 55, trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Code.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Code.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Code.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -0,0 +1,24 @@
+package fr.cemagref.simexplorer.is.storage.entities.data;
+
+public class Code extends DataEntity {
+
+ private String language;
+ private String code;
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public void setLanguage(String language) {
+ this.language = language;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Component.java (from rev 55, trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Component.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Component.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Component.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -0,0 +1,50 @@
+package fr.cemagref.simexplorer.is.storage.entities.data;
+
+import java.util.Set;
+
+public class Component extends LoggableElement {
+
+ Set<Constant> constants;
+ Set<Structure> structures;
+ Set<Code> codes;
+ Set<Library> libraries;
+
+ public Set<Constant> getConstants() {
+ return constants;
+ }
+
+ public void setConstants(Set<Constant> constants) {
+ this.constants = constants;
+ }
+
+ public Set<Structure> getStructures() {
+ return structures;
+ }
+
+ public void setStructures(Set<Structure> structures) {
+ this.structures = structures;
+ }
+
+ public Set<Code> getCodes() {
+ return codes;
+ }
+
+ public void setCodes(Set<Code> codes) {
+ this.codes = codes;
+ }
+
+ public Set<Library> getLibraries() {
+ return libraries;
+ }
+
+ public void setLibraries(Set<Library> libraries) {
+ this.libraries = libraries;
+ }
+
+ /*
+ * @Override public Set<LoggableElement> getChildren() { Set<LoggableElement>
+ * elements = new HashSet<LoggableElement>(); elements.addAll(libraries);
+ * return elements; }
+ */
+
+}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Constant.java (from rev 55, trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Constant.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Constant.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Constant.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -0,0 +1,24 @@
+package fr.cemagref.simexplorer.is.storage.entities.data;
+
+public class Constant extends DataEntity {
+
+ private String name;
+ private Class<?> type;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Class<?> getType() {
+ return type;
+ }
+
+ public void setType(Class<?> type) {
+ this.type = type;
+ }
+
+}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ConstantValue.java (from rev 55, trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ConstantValue.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ConstantValue.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ConstantValue.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -0,0 +1,24 @@
+package fr.cemagref.simexplorer.is.storage.entities.data;
+
+public class ConstantValue extends DataEntity {
+
+ private String value;
+ private Constant constant;
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public Constant getConstant() {
+ return constant;
+ }
+
+ public void setConstant(Constant constant) {
+ this.constant = constant;
+ }
+
+}
Added: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/DataEntity.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/DataEntity.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/DataEntity.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -0,0 +1,39 @@
+package fr.cemagref.simexplorer.is.storage.entities.data;
+
+import fr.cemagref.simexplorer.is.storage.entities.BaseEntity;
+
+public abstract class DataEntity extends BaseEntity {
+
+ private DataEntity parentData;
+
+ public LoggableElement getParentLoggableElement() {
+ LoggableElement parentLoggableElement = null;
+ if (getParentData() instanceof LoggableElement) {
+ parentLoggableElement = (LoggableElement) getParentData();
+ } else {
+ if (getParentData() == null) {
+ parentLoggableElement = null;
+ } else {
+ parentLoggableElement = getParentData()
+ .getParentLoggableElement();
+ }
+ }
+ return parentLoggableElement;
+ }
+
+ /**
+ * @return the parentData
+ */
+ public DataEntity getParentData() {
+ return parentData;
+ }
+
+ /**
+ * @param parentData
+ * the parentData to set
+ */
+ public void setParentData(DataEntity parentData) {
+ this.parentData = parentData;
+ }
+
+}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ExplorationApplication.java (from rev 55, trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationApplication.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ExplorationApplication.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ExplorationApplication.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -0,0 +1,33 @@
+package fr.cemagref.simexplorer.is.storage.entities.data;
+
+import java.util.Set;
+
+public class ExplorationApplication extends LoggableElement {
+
+ private Set<ExplorationData> explorations;
+ private Set<Component> components;
+
+ public Set<ExplorationData> getExplorations() {
+ return explorations;
+ }
+
+ public void setExplorations(Set<ExplorationData> explorations) {
+ this.explorations = explorations;
+ }
+
+ public Set<Component> getComponents() {
+ return components;
+ }
+
+ public void setComponents(Set<Component> components) {
+ this.components = components;
+ }
+
+ /*
+ * @Override public Set<LoggableElement> getChildren() { Set<LoggableElement>
+ * elements = new HashSet<LoggableElement>();
+ * elements.addAll(explorations); elements.addAll(components); return
+ * elements; }
+ */
+
+}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ExplorationData.java (from rev 55, trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationData.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ExplorationData.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ExplorationData.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -0,0 +1,60 @@
+package fr.cemagref.simexplorer.is.storage.entities.data;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class ExplorationData extends LoggableElement {
+
+ private Set<ConstantValue> valuesMap;
+ private Result result;
+
+ private ConstantValue findConstantValue(Constant c) {
+ for (ConstantValue constantValue : valuesMap) {
+ if (c.equals(constantValue.getConstant())) {
+ return constantValue;
+ }
+ }
+ return null;
+ }
+
+ public void setConstantValue(Constant c, String value) {
+ ConstantValue constantValue = findConstantValue(c);
+ if (constantValue == null) {
+ constantValue = new ConstantValue();
+ constantValue.setConstant(c);
+ valuesMap.add(constantValue);
+ }
+ constantValue.setValue(value);
+ }
+
+ public Object getConstantValue(Constant c) {
+ ConstantValue constantValue = findConstantValue(c);
+ if (constantValue == null) {
+ return null;
+ } else {
+ return constantValue.getValue();
+ }
+ }
+
+ public Result getResult() {
+ return result;
+ }
+
+ public void setResult(Result result) {
+ this.result = result;
+ }
+
+ public Set<ConstantValue> getValuesMap() {
+ return valuesMap;
+ }
+
+ public void setValuesMap(Set<ConstantValue> valuesMap) {
+ this.valuesMap = valuesMap;
+ }
+
+ /*
+ * @Override public Set<LoggableElement> getChildren() { Set<LoggableElement>
+ * elements = new HashSet<LoggableElement>(); return elements; }
+ */
+
+}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Library.java (from rev 55, trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Library.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Library.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Library.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -0,0 +1,15 @@
+package fr.cemagref.simexplorer.is.storage.entities.data;
+
+public class Library extends LoggableElement {
+
+ /*
+ * @Override public Set<LoggableElement> getChildren() { Set<LoggableElement>
+ * elements = new HashSet<LoggableElement>(); return elements; }
+ *
+ * @Override public Map<String, ContentType> getContentTypes() throws
+ * Exception { Map<String, ContentType> contentTypes =
+ * super.getContentTypes(); contentTypes.put("library", ContentTypeFactory
+ * .getContentTypeInstance(RawType.class)); return contentTypes; }
+ */
+
+}
Added: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/LoggableElement.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/LoggableElement.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/LoggableElement.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -0,0 +1,28 @@
+package fr.cemagref.simexplorer.is.storage.entities.data;
+
+import java.util.Set;
+
+import fr.cemagref.simexplorer.is.storage.entities.metadata.MetaDataEntity;
+
+public abstract class LoggableElement extends DataEntity {
+
+ private MetaDataEntity metaData;
+
+ //public abstract Set<LoggableElement> getChildren();
+
+ /**
+ * @return the metaData
+ */
+ public MetaDataEntity getMetaData() {
+ return metaData;
+ }
+
+ /**
+ * @param metaData
+ * the metaData to set
+ */
+ public void setMetaData(MetaDataEntity metaData) {
+ this.metaData = metaData;
+ }
+
+}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Repository.java (from rev 55, trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Repository.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Repository.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Repository.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -0,0 +1,5 @@
+package fr.cemagref.simexplorer.is.storage.entities.data;
+
+public class Repository extends DataEntity {
+
+}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Result.java (from rev 55, trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Result.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Result.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Result.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -0,0 +1,5 @@
+package fr.cemagref.simexplorer.is.storage.entities.data;
+
+public class Result extends DataEntity {
+
+}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Structure.java (from rev 55, trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Structure.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Structure.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Structure.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -0,0 +1,5 @@
+package fr.cemagref.simexplorer.is.storage.entities.data;
+
+public abstract class Structure extends DataEntity {
+
+}
Added: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/metadata/MetaDataEntity.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/metadata/MetaDataEntity.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/metadata/MetaDataEntity.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -0,0 +1,182 @@
+package fr.cemagref.simexplorer.is.storage.entities.metadata;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import fr.cemagref.simexplorer.is.storage.attachment.type.ContentType;
+import fr.cemagref.simexplorer.is.storage.attachment.type.ContentTypeFactory;
+import fr.cemagref.simexplorer.is.storage.attachment.type.RawType;
+import fr.cemagref.simexplorer.is.storage.entities.BaseEntity;
+
+public class MetaDataEntity extends BaseEntity {
+
+ private String uuid;
+ private String name;
+ private String type;
+ private String description;
+ private Version version;
+ private Date creationDate;
+ private String hash;
+ private Map<String, String> descriptors;
+ private MetaDataEntity parentData;
+ private MetaDataEntity parentVersion;
+
+ /**
+ * @return the uuid
+ */
+ public String getUuid() {
+ return uuid;
+ }
+
+ /**
+ * @param uuid
+ * the uuid to set
+ */
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name
+ * the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the type
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * @param type
+ * the type to set
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ /**
+ * @return the description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * @param description
+ * the description to set
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * @return the version
+ */
+ public Version getVersion() {
+ return version;
+ }
+
+ /**
+ * @param version
+ * the version to set
+ */
+ public void setVersion(String version) {
+ this.version = new Version(version);
+ }
+
+ /**
+ * @return the creationDate
+ */
+ public Date getCreationDate() {
+ return creationDate;
+ }
+
+ /**
+ * @param creationDate
+ * the creationDate to set
+ */
+ public void setCreationDate(Date creationDate) {
+ this.creationDate = creationDate;
+ }
+
+ /**
+ * @return the hash
+ */
+ public String getHash() {
+ return hash;
+ }
+
+ /**
+ * @param hash
+ * the hash to set
+ */
+ public void setHash(String hash) {
+ this.hash = hash;
+ }
+
+ /**
+ * @return the descriptors
+ */
+ public Map<String, String> getDescriptors() {
+ return descriptors;
+ }
+
+ /**
+ * @param descriptors
+ * the descriptors to set
+ */
+ public void setDescriptors(Map<String, String> descriptors) {
+ this.descriptors = descriptors;
+ }
+
+ /**
+ * @return the parentData
+ */
+ public MetaDataEntity getParentData() {
+ return parentData;
+ }
+
+ /**
+ * @param parentData
+ * the parentData to set
+ */
+ public void setParentData(MetaDataEntity parentData) {
+ this.parentData = parentData;
+ }
+
+ /**
+ * @return the parentVersion
+ */
+ public MetaDataEntity getParentVersion() {
+ return parentVersion;
+ }
+
+ /**
+ * @param parentVersion
+ * the parentVersion to set
+ */
+ public void setParentVersion(MetaDataEntity parentVersion) {
+ this.parentVersion = parentVersion;
+ }
+
+ public Map<String, ContentType> getContentTypes() throws Exception {
+ Map<String, ContentType> contentTypes = new HashMap<String, ContentType>();
+ contentTypes.put("xml", ContentTypeFactory
+ .getContentTypeInstance(RawType.class));
+ return contentTypes;
+ }
+
+}
Added: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/metadata/Version.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/metadata/Version.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/metadata/Version.java 2007-12-10 15:19:28 UTC (rev 58)
@@ -0,0 +1,90 @@
+package fr.cemagref.simexplorer.is.storage.entities.metadata;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+public class Version implements Comparable<Version> {
+
+ private List<Integer> pointedVersion;
+
+ public Version(String version) {
+ super();
+ pointedVersion = new ArrayList<Integer>();
+ if (version != null) {
+ StringTokenizer st = new StringTokenizer(version, ".");
+ while (st.hasMoreTokens()) {
+ pointedVersion.add(new Integer(st.nextToken()));
+ }
+ }
+ }
+
+ public Integer getVersion(int position) {
+ if (position < pointedVersion.size()) {
+ return pointedVersion.get(position);
+ } else {
+ return null;
+ }
+ }
+
+ public void setVersion(int position, int subVersion) {
+ while (getVersion(position) == null) {
+ addSubVersion(0);
+ }
+ pointedVersion.set(position, subVersion);
+ }
+
+ public void addSubVersion(int subVersion) {
+ pointedVersion.add(subVersion);
+ }
+
+ public Version incVersion(int position) {
+ Version result = new Version(toString());
+ while (result.getVersion(position) == null) {
+ result.addSubVersion(0);
+ }
+ result.setVersion(position, result.getVersion(position) + 1);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer result = new StringBuffer("");
+ for (Integer i : pointedVersion) {
+ result.append(i).append(".");
+ }
+ if (result.length() > 0) {
+ result.setLength(result.length() - 1);
+ }
+ return result.toString();
+ }
+
+ public int compareTo(Version v) {
+ int result = 0;
+ int position = 0;
+ boolean compared = false;
+ while (!compared) {
+ if (getVersion(position) == null && v.getVersion(position) == null) {
+ result = 0;
+ compared = true;
+ } else {
+ if (getVersion(position) == null) {
+ result = -1;
+ compared = true;
+ } else {
+ if (v.getVersion(position) == null) {
+ result = 1;
+ compared = true;
+ } else {
+ result = getVersion(position).compareTo(
+ v.getVersion(position));
+ compared = (result != 0);
+ }
+ }
+ }
+ position++;
+ }
+ return result;
+ }
+
+}
1
0
r57 - in trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment: . handler type
by glandais@users.labs.libre-entreprise.org 10 Dec '07
by glandais@users.labs.libre-entreprise.org 10 Dec '07
10 Dec '07
Author: glandais
Date: 2007-12-10 15:18:35 +0000 (Mon, 10 Dec 2007)
New Revision: 57
Added:
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/AttachmentHandler.java
Removed:
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/fs/
Modified:
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/FileSystemAttachmentHandler.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentType.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/RawType.java
Log:
Refactoring
Conversion des Data en Metadata
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java 2007-12-07 16:39:19 UTC (rev 56)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java 2007-12-10 15:18:35 UTC (rev 57)
@@ -1,54 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.attachment;
-
-import java.io.InputStream;
-
-import fr.cemagref.simexplorer.is.storage.entities.FileEntity;
-
-/**
- * Store, retrieve and delete content
- *
- * @author landais
- *
- */
-public abstract class AttachmentHandler {
-
- /**
- * Store content
- *
- * @param entity
- * Entity related to content
- * @param field
- * Unique field for content
- * @param is
- * Content
- * @throws Exception
- */
- public abstract void storeData(FileEntity entity, String field,
- InputStream is) throws Exception;
-
- /**
- * Retrieve content
- *
- * @param entity
- * Entity related to content
- * @param field
- * Unique field for content
- * @return Content
- * @throws Exception
- */
- public abstract InputStream retrieveData(FileEntity entity, String field)
- throws Exception;
-
- /**
- * Delete content
- *
- * @param entity
- * Entity related to content
- * @param field
- * Unique field for content
- * @throws Exception
- */
- public abstract void deleteData(FileEntity entity, String field)
- throws Exception;
-
-}
\ No newline at end of file
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler (from rev 55, trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/fs)
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/AttachmentHandler.java (from rev 55, trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/AttachmentHandler.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/AttachmentHandler.java 2007-12-10 15:18:35 UTC (rev 57)
@@ -0,0 +1,55 @@
+package fr.cemagref.simexplorer.is.storage.attachment.handler;
+
+import java.io.InputStream;
+
+import fr.cemagref.simexplorer.is.storage.database.Database;
+import fr.cemagref.simexplorer.is.storage.entities.metadata.MetaDataEntity;
+
+/**
+ * Store, retrieve and delete content
+ *
+ * @author landais
+ *
+ */
+public abstract class AttachmentHandler {
+
+ /**
+ * Store content
+ *
+ * @param entity
+ * DataEntity related to content
+ * @param field
+ * Unique field for content
+ * @param is
+ * Content
+ * @throws Exception
+ */
+ public abstract void storeData(Database database, MetaDataEntity entity, String field,
+ InputStream is) throws Exception;
+
+ /**
+ * Retrieve content
+ *
+ * @param entity
+ * DataEntity related to content
+ * @param field
+ * Unique field for content
+ * @return Content
+ * @throws Exception
+ */
+ public abstract InputStream retrieveData(MetaDataEntity entity, String field)
+ throws Exception;
+
+ /**
+ * Delete content
+ *
+ * @param entity
+ * DataEntity related to content
+ * @param field
+ * Unique field for content
+ * @throws Exception
+ */
+ public abstract void deleteData(Database database, MetaDataEntity entity, String field)
+ throws Exception;
+
+}
\ No newline at end of file
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/FileSystemAttachmentHandler.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/fs/FileSystemAttachmentHandler.java 2007-12-07 14:36:43 UTC (rev 55)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/FileSystemAttachmentHandler.java 2007-12-10 15:18:35 UTC (rev 57)
@@ -1,4 +1,4 @@
-package fr.cemagref.simexplorer.is.storage.attachment.fs;
+package fr.cemagref.simexplorer.is.storage.attachment.handler;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@@ -7,9 +7,9 @@
import java.io.FileOutputStream;
import java.io.InputStream;
-import fr.cemagref.simexplorer.is.storage.attachment.AttachmentHandler;
-import fr.cemagref.simexplorer.is.storage.entities.FileEntity;
-import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
+import fr.cemagref.simexplorer.is.storage.database.Database;
+import fr.cemagref.simexplorer.is.storage.entities.data.LoggableElement;
+import fr.cemagref.simexplorer.is.storage.entities.metadata.MetaDataEntity;
/**
* File system implementation
@@ -28,26 +28,18 @@
* Retrieve file associated to content Create directories associated to file
*
* @param entity
- * Entity related to content
+ * DataEntity related to content
* @param field
* Unique field for content
* @return Instance of file
* @throws Exception
*/
- private File getFile(FileEntity entity, String field) throws Exception {
+ private File getFile(MetaDataEntity entity, String field) throws Exception {
String resultPath = baseFolder;
- // If entity has no metadata, use metadata of parent
- LoggableElement loggableElement = null;
- if (entity instanceof LoggableElement) {
- loggableElement = (LoggableElement) entity;
- } else {
- loggableElement = entity.getOwner();
- }
-
// Create file path
- resultPath = resultPath + loggableElement.getUuid() + "/"
- + loggableElement.getVersion().toString() + "/" + field;
+ resultPath = resultPath + entity.getUuid() + "/"
+ + entity.getVersion().toString() + "/" + field;
File result = new File(resultPath);
// Create directories
@@ -60,7 +52,7 @@
}
@Override
- public InputStream retrieveData(FileEntity entity, String field)
+ public InputStream retrieveData(MetaDataEntity entity, String field)
throws Exception {
// Simple stream on file
FileInputStream fis = new FileInputStream(getFile(entity, field));
@@ -68,8 +60,8 @@
}
@Override
- public void storeData(FileEntity entity, String field, InputStream is)
- throws Exception {
+ public void storeData(Database database, MetaDataEntity entity,
+ String field, InputStream is) throws Exception {
// Simple stream on file
FileOutputStream fos = new FileOutputStream(getFile(entity, field));
@@ -90,7 +82,8 @@
}
@Override
- public void deleteData(FileEntity entity, String field) throws Exception {
+ public void deleteData(Database database, MetaDataEntity entity,
+ String field) throws Exception {
// Simple delete on file
getFile(entity, field).delete();
}
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentType.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentType.java 2007-12-07 16:39:19 UTC (rev 56)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentType.java 2007-12-10 15:18:35 UTC (rev 57)
@@ -1,6 +1,7 @@
package fr.cemagref.simexplorer.is.storage.attachment.type;
import java.io.InputStream;
+import java.io.Reader;
/**
* Content handler
@@ -26,7 +27,7 @@
* Input stream
* @return Indexable text
*/
- public abstract InputStream renderToText(InputStream is);
+ public abstract Reader renderToText(InputStream is);
/**
* @return the mimeType
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/RawType.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/RawType.java 2007-12-07 16:39:19 UTC (rev 56)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/RawType.java 2007-12-10 15:18:35 UTC (rev 57)
@@ -1,6 +1,8 @@
package fr.cemagref.simexplorer.is.storage.attachment.type;
import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
/**
* Raw content type
@@ -20,9 +22,9 @@
}
@Override
- public InputStream renderToText(InputStream is) {
+ public Reader renderToText(InputStream is) {
// No parsing
- return is;
+ return new InputStreamReader(is);
}
}
1
0
r56 - in trunk/simexplorer-si-storage/src: java/fr/cemagref/simexplorer/is/storage/attachment/type java/fr/cemagref/simexplorer/is/storage/database java/fr/cemagref/simexplorer/is/storage/database/lucene java/fr/cemagref/simexplorer/is/storage/engine java/fr/cemagref/simexplorer/is/storage/entities java/fr/cemagref/simexplorer/is/storage/factories test/fr/cemagref/simexplorer/is/storage/test
by glandais@users.labs.libre-entreprise.org 07 Dec '07
by glandais@users.labs.libre-entreprise.org 07 Dec '07
07 Dec '07
Author: glandais
Date: 2007-12-07 16:39:19 +0000 (Fri, 07 Dec 2007)
New Revision: 56
Added:
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentType.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/FSStorageEngine.java
Removed:
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentType.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/LuceneStorageEngine.java
Modified:
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneHits.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/LoggableElement.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/EntityFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/FileEntityFactory.java
trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/LuceneDatabaseTestCase.java
Log:
Commentaires et refactoring
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentType.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentType.java 2007-12-07 14:36:43 UTC (rev 55)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentType.java 2007-12-07 16:39:19 UTC (rev 56)
@@ -1,61 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.attachment.type;
-
-import java.io.InputStream;
-
-/**
- * Content handler
- *
- * @author landais
- *
- */
-public abstract class ContentType {
-
- /**
- * MIME type
- */
- private String mimeType;
- /**
- * Text description
- */
- private String description;
-
- /**
- * Index content
- *
- * @param is
- * Input stream
- * @return Indexable text
- */
- public abstract InputStream renderToText(InputStream is);
-
- /**
- * @return the mimeType
- */
- public String getMimeType() {
- return mimeType;
- }
-
- /**
- * @param mimeType
- * the mimeType to set
- */
- public void setMimeType(String mimeType) {
- this.mimeType = mimeType;
- }
-
- /**
- * @return the description
- */
- public String getDescription() {
- return description;
- }
-
- /**
- * @param description
- * the description to set
- */
- public void setDescription(String description) {
- this.description = description;
- }
-
-}
Added: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentType.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentType.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentType.java 2007-12-07 16:39:19 UTC (rev 56)
@@ -0,0 +1,61 @@
+package fr.cemagref.simexplorer.is.storage.attachment.type;
+
+import java.io.InputStream;
+
+/**
+ * Content handler
+ *
+ * @author landais
+ *
+ */
+public abstract class ContentType {
+
+ /**
+ * MIME type
+ */
+ private String mimeType;
+ /**
+ * Text description
+ */
+ private String description;
+
+ /**
+ * Index content
+ *
+ * @param is
+ * Input stream
+ * @return Indexable text
+ */
+ public abstract InputStream renderToText(InputStream is);
+
+ /**
+ * @return the mimeType
+ */
+ public String getMimeType() {
+ return mimeType;
+ }
+
+ /**
+ * @param mimeType
+ * the mimeType to set
+ */
+ public void setMimeType(String mimeType) {
+ this.mimeType = mimeType;
+ }
+
+ /**
+ * @return the description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * @param description
+ * the description to set
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+}
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java 2007-12-07 14:36:43 UTC (rev 55)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java 2007-12-07 16:39:19 UTC (rev 56)
@@ -1,13 +1,11 @@
package fr.cemagref.simexplorer.is.storage.database;
-import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import fr.cemagref.simexplorer.is.storage.entities.Entity;
-import fr.cemagref.simexplorer.is.storage.entities.FileEntity;
import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
import fr.cemagref.simexplorer.is.storage.entities.Version;
@@ -42,21 +40,8 @@
* Element to insert
* @throws Exception
*/
- public abstract void pushElement(LoggableElement element) throws Exception;
+ public abstract void insertElement(LoggableElement element) throws Exception;
- /**
- * Attatch content to an element FIXME move to storage engine
- *
- * @param entity
- * Related entity
- * @param field
- * Target field
- * @param is
- * Content
- * @throws Exception
- */
- public abstract void storeData(FileEntity entity, String field,
- InputStream is) throws Exception;
// Read
@@ -70,7 +55,7 @@
* @return Fund element, null if not fund
* @throws Exception
*/
- public abstract LoggableElement findElement(String uuid, Version version)
+ public abstract LoggableElement getElement(String uuid, Version version)
throws Exception;
/**
@@ -108,7 +93,7 @@
if (versions.size() > 0) {
Version version = versions.get(0);
// get element corresponding to latest version
- result = findElement(uuid, version);
+ result = getElement(uuid, version);
} else {
result = null;
}
@@ -161,21 +146,8 @@
* @throws Exception
*/
public abstract Set<LoggableElement> findElementsByContentSearch(
- String searchedText) throws Exception;
+ String queryText) throws Exception;
- /**
- * Retrieve content
- *
- * @param entity
- * Entity related to content
- * @param field
- * Unique field for content
- * @return Content
- * @throws Exception
- */
- public abstract InputStream retrieveData(FileEntity entity, String field)
- throws Exception;
-
// Delete
/**
@@ -190,18 +162,6 @@
}
/**
- * Delete content
- *
- * @param entity
- * Entity related to content
- * @param field
- * Unique field for content
- * @throws Exception
- */
- public abstract void deleteData(FileEntity entity, String field)
- throws Exception;
-
- /**
* Delete all elements by id
*
* @param uuid
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java 2007-12-07 14:36:43 UTC (rev 55)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java 2007-12-07 16:39:19 UTC (rev 56)
@@ -41,8 +41,12 @@
*/
public static final String KEY_CREATIONDATE = "simexplorer.creationdate";
/**
- * Field name for xml content
+ * Field name for id
*/
- public static final String KEY_XML = "simexplorer.xml";
+ public static final String KEY_PARENTVERSION_UUID = "simexplorer.parentversion.uuid";
+ /**
+ * Field name for id
+ */
+ public static final String KEY_PARENTVERSION_VERSION = "simexplorer.parentversion.version";
}
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2007-12-07 14:36:43 UTC (rev 55)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2007-12-07 16:39:19 UTC (rev 56)
@@ -18,9 +18,11 @@
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
+import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
import org.apache.lucene.search.Searcher;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.Directory;
@@ -29,36 +31,59 @@
import fr.cemagref.simexplorer.is.storage.database.Database;
import fr.cemagref.simexplorer.is.storage.entities.Entity;
-import fr.cemagref.simexplorer.is.storage.entities.FileEntity;
import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
import fr.cemagref.simexplorer.is.storage.entities.Version;
import fr.cemagref.simexplorer.is.storage.factories.EntityFactory;
-import fr.cemagref.simexplorer.is.storage.factories.FileEntityFactory;
import fr.cemagref.simexplorer.is.storage.factories.LoggableElementFactory;
+/**
+ * Lucene implementation
+ *
+ * @author landais
+ *
+ */
public class LuceneDatabase extends Database {
+ /**
+ * Content analyzer
+ */
private Analyzer analyser;
+ /**
+ * Index location
+ */
private String indexDirectory;
+ /**
+ * Database writer
+ */
private IndexWriter writer;
+ /**
+ * Init flag
+ */
private boolean initok = false;
@Override
public void open() throws Exception {
if (!initok) {
+ // Create a per field analyze
analyser = new PerFieldAnalyzerWrapper(new SimpleAnalyzer());
+
+ // Specific analyzers
// analyser.addAnalyzer("firstname", new KeywordAnalyzer());
// analyser.addAnalyzer("lastname", new KeywordAnalyzer());
+ // FIXME index location
indexDirectory = "./index/";
+ // Create index if it does not exist
boolean create = false;
if (!IndexReader.indexExists(indexDirectory)) {
create = true;
}
+ // Create a Store for Lucene DB
Directory dir = FSDirectory.getDirectory(indexDirectory);
+ // Create Lucene indexer
writer = new IndexWriter(dir, true, analyser, create);
initok = true;
}
@@ -66,65 +91,94 @@
@Override
public void close() throws Exception {
+ // Close writer
writer.close();
}
@Override
- public void pushElement(LoggableElement element) throws Exception {
+ public void insertElement(LoggableElement element) throws Exception {
+ // Add all children to database
Set<LoggableElement> children = element.getChildren();
for (LoggableElement loggableElement : children) {
- pushElement(loggableElement);
+ insertElement(loggableElement);
}
+ // Retrieve element factory
Class<? extends LoggableElement> clazz = element.getClass();
-
LoggableElementFactory<LoggableElement> elementFactory = (LoggableElementFactory<LoggableElement>) LoggableElementFactory
.getFactory(clazz);
+
+ // Save element to a Lucene document
Document document = saveLuceneElement(elementFactory, element);
- LoggableElement oldElement = findElement(element.getUuid(), element
+ // Retrieve existing element with same id/version
+ LoggableElement oldElement = getElement(element.getUuid(), element
.getVersion());
+ // Delete element if exists, for update
if (oldElement != null) {
// update
deleteElement(element);
}
- InputStream is = new ByteArrayInputStream(document.get(KEY_XML)
- .getBytes());
- FileEntityFactory.getHandler().storeData(element, KEY_XML, is);
-
+ // FIXME thread safe
+ // add document to index
writer.addDocument(document);
+ // write index
writer.flush();
}
@Override
- public LoggableElement findElement(String uuid, Version version)
+ public LoggableElement getElement(String uuid, Version version)
throws Exception {
LoggableElement result = null;
+ // Retrieve element with id/version
Map<String, String> properties = new HashMap<String, String>();
properties.put(KEY_UUID, uuid);
properties.put(KEY_VERSION, version.toString());
+ // Search elements
LuceneHits hits = findHits(properties);
if (hits.getHits().length() != 0) {
+ // convert first document to element
result = convertDocumentToElement(hits.getHits().doc(0));
}
+
hits.closeSearcher();
return result;
}
@Override
+ public List<Version> getVersions(String uuid) throws Exception {
+ // Retrieve all document corresponding to id
+ Map<String, String> properties = new HashMap<String, String>();
+ properties.put(KEY_UUID, uuid);
+ LuceneHits hits = findHits(properties);
+
+ // Add all versions to a list
+ List<Version> versions = new ArrayList<Version>();
+ for (int i = 0; i < hits.getHits().length(); i++) {
+ Document doc = hits.getHits().doc(i);
+ versions.add(new Version(doc.get(KEY_VERSION)));
+ }
+
+ return versions;
+ }
+
+ @Override
public Set<LoggableElement> findElementsById(String uuid) throws Exception {
+ // Create hash map with id
Map<String, String> properties = new HashMap<String, String>();
properties.put(KEY_UUID, uuid);
+ // Return all elements parsed from documents fund
return convertHitsToElements(findHits(properties));
}
@Override
public Set<LoggableElement> findElementsByProperties(
Map<String, String> properties) throws Exception {
+ // Return all elements parsed from documents fund
return convertHitsToElements(findHits(properties));
}
@@ -132,26 +186,43 @@
public Set<LoggableElement> findElementsByProperties(
Map<String, String> properties, Class<? extends Entity> entityClass)
throws Exception {
+ // Create hash map with properties and entity class name
Map<String, String> props = new HashMap<String, String>();
props.putAll(properties);
props.put(KEY_CLASSNAME, entityClass.getName());
+ // Return all elements parsed from documents fund
return convertHitsToElements(findHits(properties));
}
+ @Override
+ public Set<LoggableElement> findElementsByContentSearch(String queryText)
+ throws Exception {
+ // Create a searcher
+ Searcher searcher = new IndexSearcher(indexDirectory);
+
+ Analyzer analyzer = new SimpleAnalyzer();
+ QueryParser parser = new QueryParser("__all__", analyzer);
+ Query luceneQuery = parser.parse(queryText);
+
+ // Create a bean with hits and searcher
+ LuceneHits luceneHits = new LuceneHits(searcher.search(luceneQuery), searcher);
+
+ // Convert hits to elements
+ Set<LoggableElement> result = convertHitsToElements(luceneHits);
+
+ return result;
+ }
+
+ @Override
public void deleteElements(String uuid) throws Exception {
- Set<LoggableElement> set = findElementsById(uuid);
- for (LoggableElement loggableElement : set) {
- deleteData(loggableElement, KEY_XML);
- }
+ // Delete all documents by term search
writer.deleteDocuments(new Term(KEY_UUID, uuid));
writer.flush();
}
+ @Override
public void deleteElement(String uuid, Version version) throws Exception {
-
- LoggableElement loggableElement = findElement(uuid, version);
- deleteData(loggableElement, KEY_XML);
-
+ // Delete element in db with term search
Term[] terms = new Term[3];
terms[0] = new Term(KEY_UUID, uuid);
terms[1] = new Term(KEY_VERSION, version.toString());
@@ -159,55 +230,89 @@
writer.flush();
}
+ /**
+ * Find all documents matching properties
+ * @param properties criteria
+ * @return Documents and search handle
+ * @throws Exception
+ */
private LuceneHits findHits(Map<String, String> properties)
throws Exception {
+ // Create a searcher
Searcher searcher = new IndexSearcher(indexDirectory);
- // FIXME disablecoords?
- BooleanQuery query = new BooleanQuery(false);
+ // Create a query with all parameters
+ BooleanQuery query = new BooleanQuery();
for (Entry<String, String> kv : properties.entrySet()) {
query.add(new TermQuery(new Term(kv.getKey(), kv.getValue())),
BooleanClause.Occur.MUST);
}
+ // Create a bean with hits and searcher
LuceneHits luceneHits = new LuceneHits(searcher.search(query), searcher);
return luceneHits;
}
+ /**
+ * Convert a Lucene Document to a real entity
+ * @param document Storage
+ * @return Element
+ * @throws Exception
+ */
private LoggableElement convertDocumentToElement(Document document)
throws Exception {
+ // Retrieve element factory via class name
String className = document.get(KEY_CLASSNAME);
LoggableElementFactory<LoggableElement> factory = (LoggableElementFactory<LoggableElement>) LoggableElementFactory
.getFactory(className);
+ // Rebuild element
return loadLuceneElement(factory, document);
}
+ /**
+ * Convert all Lucene documents to real entities
+ * @param hits Document collection
+ * @return Entities list
+ * @throws Exception
+ */
private Set<LoggableElement> convertHitsToElements(LuceneHits hits)
throws Exception {
+ // For all document
Set<LoggableElement> elements = new HashSet<LoggableElement>();
for (int i = 0; i < hits.getHits().length(); i++) {
Document document = hits.getHits().doc(i);
+ // Convert to element
elements.add(convertDocumentToElement(document));
}
+ // Close handle
hits.closeSearcher();
return elements;
}
+ /**
+ * Transform a Lucene document into a LoggableElement thanks to a factory
+ * @param factory The element factory
+ * @param document The document to transform
+ * @return Instance of element
+ * @throws Exception
+ */
private LoggableElement loadLuceneElement(
LoggableElementFactory<LoggableElement> factory, Document document)
- throws Exception {
- String strXMLElement = document.get(KEY_XML);
-
- InputStream is = new ByteArrayInputStream(strXMLElement.getBytes());
-
- org.w3c.dom.Document xmlDocument = EntityFactory.getBuilder().parse(is);
-
- LoggableElement element = factory.loadXMLElement((Element) xmlDocument
- .getFirstChild());
-
+ throws Exception {
+ LoggableElement element = factory.createInstance();
+ element.setName(document.get(KEY_NAME));
+ // FIXME toutes les metadonnées
+
return element;
}
+ /**
+ * Transform an element to a Lucene document thanks to a factory
+ * @param factory
+ * @param element
+ * @return
+ * @throws Exception
+ */
private Document saveLuceneElement(
LoggableElementFactory<LoggableElement> factory,
LoggableElement element) throws Exception {
@@ -223,49 +328,10 @@
document.add(new Field(KEY_VERSION, element.getVersion().toString()
.toString(), Field.Store.YES, Field.Index.UN_TOKENIZED));
- document.add(new Field(KEY_XML, factory.getElementXML(element),
- Field.Store.COMPRESS, Field.Index.NO));
+ // FIXME ne pas serializer
+ // Serialize element into document
return document;
}
- @Override
- public List<Version> getVersions(String uuid) throws Exception {
- Map<String, String> properties = new HashMap<String, String>();
- properties.put(KEY_UUID, uuid);
- LuceneHits hits = findHits(properties);
-
- List<Version> versions = new ArrayList<Version>();
- for (int i = 0; i < hits.getHits().length(); i++) {
- Document doc = hits.getHits().doc(i);
- versions.add(new Version(doc.get(KEY_VERSION)));
- }
-
- return versions;
- }
-
- @Override
- public void deleteData(FileEntity entity, String field) throws Exception {
- FileEntityFactory.getHandler().deleteData(entity, field);
- }
-
- @Override
- public InputStream retrieveData(FileEntity entity, String field)
- throws Exception {
- return FileEntityFactory.getHandler().retrieveData(entity, field);
- }
-
- @Override
- public void storeData(FileEntity entity, String field, InputStream is)
- throws Exception {
- FileEntityFactory.getHandler().storeData(entity, field, is);
- }
-
- @Override
- public Set<LoggableElement> findElementsByContentSearch(String searchedText)
- throws Exception {
- // TODO Auto-generated method stub
- return null;
- }
-
}
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneHits.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneHits.java 2007-12-07 14:36:43 UTC (rev 55)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneHits.java 2007-12-07 16:39:19 UTC (rev 56)
@@ -3,33 +3,70 @@
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.Searcher;
+/**
+ * Bean handling hits collection and searcher handle
+ *
+ * @author landais
+ *
+ */
public class LuceneHits {
+ /**
+ * Hits collection
+ */
private Hits hits;
+ /**
+ * Searcher handle
+ */
private Searcher searcher;
+ /**
+ * Default constructor
+ *
+ * @param hits
+ * @param searcher
+ */
public LuceneHits(Hits hits, Searcher searcher) {
super();
this.hits = hits;
this.searcher = searcher;
}
+ /**
+ * Close handle
+ *
+ * @throws Exception
+ */
public void closeSearcher() throws Exception {
searcher.close();
}
+ /**
+ * @return the hits
+ */
public Hits getHits() {
return hits;
}
+ /**
+ * @param hits
+ * the hits to set
+ */
public void setHits(Hits hits) {
this.hits = hits;
}
+ /**
+ * @return the searcher
+ */
public Searcher getSearcher() {
return searcher;
}
+ /**
+ * @param searcher
+ * the searcher to set
+ */
public void setSearcher(Searcher searcher) {
this.searcher = searcher;
}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/FSStorageEngine.java (from rev 55, trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/LuceneStorageEngine.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/FSStorageEngine.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/FSStorageEngine.java 2007-12-07 16:39:19 UTC (rev 56)
@@ -0,0 +1,159 @@
+package fr.cemagref.simexplorer.is.storage.engine;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.lucene.document.Field;
+import org.w3c.dom.Element;
+
+import fr.cemagref.simexplorer.is.storage.attachment.AttachmentHandler;
+import fr.cemagref.simexplorer.is.storage.attachment.fs.FileSystemAttachmentHandler;
+import fr.cemagref.simexplorer.is.storage.database.lucene.LuceneDatabase;
+import fr.cemagref.simexplorer.is.storage.entities.FileEntity;
+import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
+import fr.cemagref.simexplorer.is.storage.entities.Version;
+import fr.cemagref.simexplorer.is.storage.factories.EntityFactory;
+import fr.cemagref.simexplorer.is.storage.factories.FileEntityFactory;
+import fr.cemagref.simexplorer.is.storage.factories.LoggableElementFactory;
+
+public class FSStorageEngine extends StorageEngine {
+
+ private static AttachmentHandler handler;
+ private static boolean handlerInit = false;
+
+ public static AttachmentHandler getHandler() {
+ if (!handlerInit) {
+ handler = new FileSystemAttachmentHandler();
+ }
+ return handler;
+ }
+
+ @Override
+ public void close() throws Exception {
+ database.close();
+ }
+
+ @Override
+ public void storeData(FileEntity entity, String field, InputStream is)
+ throws Exception {
+ getHandler().storeData(entity, field, is);
+ }
+
+
+ @Override
+ public void exportElement(LoggableElement element, OutputStream os)
+ throws Exception {
+ LoggableElement completeElement = database.getElement(element
+ .getUuid(), element.getVersion());
+ LoggableElementFactory<LoggableElement> factory = (LoggableElementFactory<LoggableElement>) EntityFactory
+ .getFactory(completeElement.getClass());
+ factory.getElementXML(element, os);
+ }
+
+ @Override
+ public LoggableElement getElement(String uuid) throws Exception {
+ return database.getElementLatestVersion(uuid);
+ }
+
+ @Override
+ public LoggableElement getElementVersion(String uuid, Version version)
+ throws Exception {
+
+ /*
+ // FIXME
+ String strXMLElement = document.get(KEY_XML);
+ InputStream is = new ByteArrayInputStream(strXMLElement.getBytes());
+ org.w3c.dom.Document xmlDocument = EntityFactory.getBuilder().parse(is);
+ LoggableElement element = factory.loadXMLElement((Element) xmlDocument
+ .getFirstChild());
+ */
+
+ return database.getElement(uuid, version);
+ }
+
+ @Override
+ public List<Version> getVersions(String uuid) throws Exception {
+ return database.getVersions(uuid);
+ }
+
+ @Override
+ public LoggableElement importElement(InputStream inputStream)
+ throws Exception {
+ LoggableElement importedElement = null;
+
+ database.insertElement(importedElement);
+ return importedElement;
+ }
+
+ @Override
+ public LoggableElement newElement(LoggableElement element) throws Exception {
+ if (getElement(element.getUuid()) != null) {
+ throw new Exception(element.getUuid() + " already exist");
+ }
+ element.setVersion("1");
+ /*
+ * FIXME
+ document.add(new Field(KEY_XML, factory.getElementXML(element),
+ Field.Store.COMPRESS, Field.Index.NO));
+ */
+
+ database.insertElement(element);
+ return getElement(element.getUuid());
+ }
+
+ @Override
+ public void open() throws Exception {
+ database = new LuceneDatabase();
+ database.open();
+ }
+
+ @Override
+ public LoggableElement saveElement(LoggableElement element)
+ throws Exception {
+ Version version = null;
+ List<Version> versions = getVersions(element.getUuid());
+ if (versions.size() > 0) {
+ Collections.sort(versions);
+ Collections.reverse(versions);
+
+ version = versions.get(0);
+ version.incVersion(0);
+ } else {
+ version = new Version("1");
+ }
+
+ element.setVersion(version.toString());
+
+ /*
+ * FIXME
+ document.add(new Field(KEY_XML, factory.getElementXML(element),
+ Field.Store.COMPRESS, Field.Index.NO));
+ */
+
+ database.insertElement(element);
+ return getElement(element.getUuid());
+ }
+
+ @Override
+ public LoggableElement synchronizeElement(LoggableElement element)
+ throws Exception {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void deleteData(FileEntity entity, String field) throws Exception {
+ getHandler().deleteData(entity, field);
+ }
+
+ @Override
+ public InputStream retrieveData(FileEntity entity, String field)
+ throws Exception {
+ return getHandler().retrieveData(entity, field);
+ }
+
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/LuceneStorageEngine.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/LuceneStorageEngine.java 2007-12-07 14:36:43 UTC (rev 55)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/LuceneStorageEngine.java 2007-12-07 16:39:19 UTC (rev 56)
@@ -1,100 +0,0 @@
-package fr.cemagref.simexplorer.is.storage.engine;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Collections;
-import java.util.List;
-
-import fr.cemagref.simexplorer.is.storage.database.lucene.LuceneDatabase;
-import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
-import fr.cemagref.simexplorer.is.storage.entities.Version;
-import fr.cemagref.simexplorer.is.storage.factories.EntityFactory;
-import fr.cemagref.simexplorer.is.storage.factories.LoggableElementFactory;
-
-public class LuceneStorageEngine extends StorageEngine {
-
- @Override
- public void close() throws Exception {
- database.close();
- }
-
- @Override
- public void exportElement(LoggableElement element, OutputStream os)
- throws Exception {
- LoggableElement completeElement = database.findElement(element
- .getUuid(), element.getVersion());
- LoggableElementFactory<LoggableElement> factory = (LoggableElementFactory<LoggableElement>) EntityFactory
- .getFactory(completeElement.getClass());
- factory.getElementXML(element, os);
- }
-
- @Override
- public LoggableElement getElement(String uuid) throws Exception {
- return database.getElementLatestVersion(uuid);
- }
-
- @Override
- public LoggableElement getElementVersion(String uuid, Version version)
- throws Exception {
- return database.findElement(uuid, version);
- }
-
- @Override
- public List<Version> getVersions(String uuid) throws Exception {
- return database.getVersions(uuid);
- }
-
- @Override
- public LoggableElement importElement(InputStream inputStream)
- throws Exception {
- LoggableElement importedElement = null;
-
- database.pushElement(importedElement);
- return importedElement;
- }
-
- @Override
- public LoggableElement newElement(LoggableElement element) throws Exception {
- if (getElement(element.getUuid()) != null) {
- throw new Exception(element.getUuid() + " already exist");
- }
- element.setVersion("1");
- database.pushElement(element);
- return getElement(element.getUuid());
- }
-
- @Override
- public void open() throws Exception {
- database = new LuceneDatabase();
- database.open();
- }
-
- @Override
- public LoggableElement saveElement(LoggableElement element)
- throws Exception {
- Version version = null;
- List<Version> versions = getVersions(element.getUuid());
- if (versions.size() > 0) {
- Collections.sort(versions);
- Collections.reverse(versions);
-
- version = versions.get(0);
- version.incVersion(0);
- } else {
- version = new Version("1");
- }
-
- element.setVersion(version.toString());
-
- database.pushElement(element);
- return getElement(element.getUuid());
- }
-
- @Override
- public LoggableElement synchronizeElement(LoggableElement element)
- throws Exception {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2007-12-07 14:36:43 UTC (rev 55)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2007-12-07 16:39:19 UTC (rev 56)
@@ -5,6 +5,7 @@
import java.util.List;
import fr.cemagref.simexplorer.is.storage.database.Database;
+import fr.cemagref.simexplorer.is.storage.entities.FileEntity;
import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
import fr.cemagref.simexplorer.is.storage.entities.Version;
@@ -38,4 +39,43 @@
public abstract LoggableElement importElement(InputStream inputStream)
throws Exception;
+ /**
+ * Attatch content to an element FIXME move to storage engine
+ *
+ * @param entity
+ * Related entity
+ * @param field
+ * Target field
+ * @param is
+ * Content
+ * @throws Exception
+ */
+ public abstract void storeData(FileEntity entity, String field,
+ InputStream is) throws Exception;
+
+ /**
+ * Retrieve content
+ *
+ * @param entity
+ * Entity related to content
+ * @param field
+ * Unique field for content
+ * @return Content
+ * @throws Exception
+ */
+ public abstract InputStream retrieveData(FileEntity entity, String field)
+ throws Exception;
+
+ /**
+ * Delete content
+ *
+ * @param entity
+ * Entity related to content
+ * @param field
+ * Unique field for content
+ * @throws Exception
+ */
+ public abstract void deleteData(FileEntity entity, String field)
+ throws Exception;
+
}
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/LoggableElement.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/LoggableElement.java 2007-12-07 14:36:43 UTC (rev 55)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/LoggableElement.java 2007-12-07 16:39:19 UTC (rev 56)
@@ -13,86 +13,136 @@
private Date creationDate;
private String hash;
private Set<Descriptor> descriptors;
+ private LoggableElement parentVersion;
- /*
- * private LoggableElement parent; private Set<LoggableElement> children;
+ public abstract Set<LoggableElement> getChildren();
+
+ /**
+ * @return the uuid
*/
-
public String getUuid() {
return uuid;
}
+ /**
+ * @param uuid the uuid to set
+ */
public void setUuid(String uuid) {
this.uuid = uuid;
}
+ /**
+ * @return the name
+ */
public String getName() {
return name;
}
+ /**
+ * @param name the name to set
+ */
public void setName(String name) {
this.name = name;
}
+ /**
+ * @return the type
+ */
public String getType() {
return type;
}
+ /**
+ * @param type the type to set
+ */
public void setType(String type) {
this.type = type;
}
+ /**
+ * @return the description
+ */
public String getDescription() {
return description;
}
+ /**
+ * @param description the description to set
+ */
public void setDescription(String description) {
this.description = description;
}
+ /**
+ * @return the version
+ */
public Version getVersion() {
return version;
}
+ /**
+ * @param version the version to set
+ */
public void setVersion(String version) {
this.version = new Version(version);
}
+ /**
+ * @return the creationDate
+ */
public Date getCreationDate() {
return creationDate;
}
+ /**
+ * @param creationDate the creationDate to set
+ */
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
+ /**
+ * @return the hash
+ */
public String getHash() {
return hash;
}
+ /**
+ * @param hash the hash to set
+ */
public void setHash(String hash) {
this.hash = hash;
}
+ /**
+ * @return the descriptors
+ */
public Set<Descriptor> getDescriptors() {
return descriptors;
}
+ /**
+ * @param descriptors the descriptors to set
+ */
public void setDescriptors(Set<Descriptor> descriptors) {
this.descriptors = descriptors;
}
- public abstract Set<LoggableElement> getChildren();
+ /**
+ * @return the parentVersion
+ */
+ public LoggableElement getParentVersion() {
+ return parentVersion;
+ }
- /*
- * public LoggableElement getParent() { return parent; }
- *
- * public void setParent(LoggableElement parent) { this.parent = parent; }
- *
- * public Set<LoggableElement> getVersionChildren() { return children; }
- *
- * public void setVersionChildren(Set<LoggableElement> children) {
- * this.children = children; }
+ /**
+ * @param parentVersion the parentVersion to set
*/
+ public void setParentVersion(LoggableElement parentVersion) {
+ this.parentVersion = parentVersion;
+ }
+
+
}
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/EntityFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/EntityFactory.java 2007-12-07 14:36:43 UTC (rev 55)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/EntityFactory.java 2007-12-07 16:39:19 UTC (rev 56)
@@ -128,7 +128,9 @@
// Création de l'arborescence du DOM
Element racine = xmlDocument.createElement(element.getClass()
.getSimpleName());
+
saveXMLElement(xmlDocument, racine, element);
+
xmlDocument.appendChild(racine);
DOMSource domSource = new DOMSource(xmlDocument);
StreamResult result = new StreamResult(os);
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/FileEntityFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/FileEntityFactory.java 2007-12-07 14:36:43 UTC (rev 55)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/FileEntityFactory.java 2007-12-07 16:39:19 UTC (rev 56)
@@ -8,14 +8,4 @@
public abstract class FileEntityFactory<E extends FileEntity> extends
EntityFactory<E> implements DatabaseConstants {
- private static AttachmentHandler handler;
- private static boolean handlerInit = false;
-
- public static AttachmentHandler getHandler() {
- if (!handlerInit) {
- handler = new FileSystemAttachmentHandler();
- }
- return handler;
- }
-
}
Modified: trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/LuceneDatabaseTestCase.java
===================================================================
--- trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/LuceneDatabaseTestCase.java 2007-12-07 14:36:43 UTC (rev 55)
+++ trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/LuceneDatabaseTestCase.java 2007-12-07 16:39:19 UTC (rev 56)
@@ -49,9 +49,9 @@
explorationData1.setUuid(uuid1);
explorationData1.setVersion("5.12");
explorationData1.setDescription(description1);
- database.pushElement(explorationData1);
+ database.insertElement(explorationData1);
- LoggableElement element = database.findElement(uuid1, new Version(
+ LoggableElement element = database.getElement(uuid1, new Version(
"5.12"));
assertNotNull(element);
assertEquals(description1, element.getDescription());
@@ -61,9 +61,9 @@
explorationData2.setUuid(uuid1);
explorationData2.setVersion("5.12");
explorationData2.setDescription(description2);
- database.pushElement(explorationData2);
+ database.insertElement(explorationData2);
- assertEquals(description2, database.findElement(uuid1,
+ assertEquals(description2, database.getElement(uuid1,
new Version("5.12")).getDescription());
String description3 = UUID.randomUUID().toString();
@@ -71,9 +71,9 @@
explorationData3.setUuid(uuid1);
explorationData3.setVersion("5.13");
explorationData3.setDescription(description3);
- database.pushElement(explorationData3);
+ database.insertElement(explorationData3);
- assertEquals(description3, database.findElement(uuid1,
+ assertEquals(description3, database.getElement(uuid1,
new Version("5.13")).getDescription());
}
@@ -84,14 +84,14 @@
explorationData1.setUuid(uuid1);
explorationData1.setVersion("5.12");
explorationData1.setDescription(description1);
- database.pushElement(explorationData1);
+ database.insertElement(explorationData1);
String description2 = UUID.randomUUID().toString();
ExplorationData explorationData2 = new ExplorationData();
explorationData2.setUuid(uuid1);
explorationData2.setVersion("5.13");
explorationData2.setDescription(description2);
- database.pushElement(explorationData2);
+ database.insertElement(explorationData2);
assertEquals(description2, database.getElementLatestVersion(uuid1)
.getDescription());
@@ -101,7 +101,7 @@
explorationData3.setUuid(uuid1);
explorationData3.setVersion("6.0");
explorationData3.setDescription(description3);
- database.pushElement(explorationData3);
+ database.insertElement(explorationData3);
assertEquals(description3, database.getElementLatestVersion(uuid1)
.getDescription());
@@ -114,21 +114,21 @@
explorationData1.setUuid(uuid1);
explorationData1.setVersion("5.12");
explorationData1.setDescription(description1);
- database.pushElement(explorationData1);
+ database.insertElement(explorationData1);
String description2 = UUID.randomUUID().toString();
ExplorationData explorationData2 = new ExplorationData();
explorationData2.setUuid(uuid1);
explorationData2.setVersion("5.13");
explorationData2.setDescription(description2);
- database.pushElement(explorationData2);
+ database.insertElement(explorationData2);
String description3 = UUID.randomUUID().toString();
ExplorationData explorationData3 = new ExplorationData();
explorationData3.setUuid(uuid1);
explorationData3.setVersion("6.0");
explorationData3.setDescription(description3);
- database.pushElement(explorationData3);
+ database.insertElement(explorationData3);
Set<LoggableElement> elements = database.findElementsById(uuid1);
assertEquals(3, elements.size());
@@ -144,20 +144,20 @@
explorationData1.setUuid(uuid1);
explorationData1.setVersion("5.12");
explorationData1.setDescription(description1);
- database.pushElement(explorationData1);
+ database.insertElement(explorationData1);
ExplorationData explorationData2 = new ExplorationData();
explorationData2.setUuid(uuid1);
explorationData2.setVersion("5.13");
explorationData2.setDescription(description1);
- database.pushElement(explorationData2);
+ database.insertElement(explorationData2);
String description3 = UUID.randomUUID().toString();
ExplorationData explorationData3 = new ExplorationData();
explorationData3.setUuid(uuid1);
explorationData3.setVersion("6.0");
explorationData3.setDescription(description3);
- database.pushElement(explorationData3);
+ database.insertElement(explorationData3);
// TODO add some other classes in db
@@ -180,20 +180,20 @@
explorationData1.setUuid(uuid1);
explorationData1.setVersion("5.12");
explorationData1.setDescription(description1);
- database.pushElement(explorationData1);
+ database.insertElement(explorationData1);
ExplorationData explorationData2 = new ExplorationData();
explorationData2.setUuid(uuid1);
explorationData2.setVersion("5.13");
explorationData2.setDescription(description1);
- database.pushElement(explorationData2);
+ database.insertElement(explorationData2);
String description3 = UUID.randomUUID().toString();
ExplorationData explorationData3 = new ExplorationData();
explorationData3.setUuid(uuid1);
explorationData3.setVersion("6.0");
explorationData3.setDescription(description3);
- database.pushElement(explorationData3);
+ database.insertElement(explorationData3);
Map<String, String> properties = new HashMap<String, String>();
properties.put(DatabaseConstants.KEY_UUID, uuid1);
@@ -213,10 +213,10 @@
explorationData1.setUuid(uuid1);
explorationData1.setVersion("5.12");
explorationData1.setDescription(description1);
- database.pushElement(explorationData1);
+ database.insertElement(explorationData1);
database.deleteElement(explorationData1);
- assertNull(database.findElement(uuid1, new Version("5.12")));
+ assertNull(database.getElement(uuid1, new Version("5.12")));
}
@@ -228,21 +228,21 @@
explorationData1.setUuid(uuid1);
explorationData1.setVersion("5.12");
explorationData1.setDescription(description1);
- database.pushElement(explorationData1);
+ database.insertElement(explorationData1);
String description2 = UUID.randomUUID().toString();
ExplorationData explorationData2 = new ExplorationData();
explorationData2.setUuid(uuid1);
explorationData2.setVersion("5.13");
explorationData2.setDescription(description2);
- database.pushElement(explorationData2);
+ database.insertElement(explorationData2);
String description3 = UUID.randomUUID().toString();
ExplorationData explorationData3 = new ExplorationData();
explorationData3.setUuid(uuid1);
explorationData3.setVersion("6.0");
explorationData3.setDescription(description3);
- database.pushElement(explorationData3);
+ database.insertElement(explorationData3);
database.deleteElements(uuid1);
1
0
r55 - in trunk/simexplorer-si-storage/src: java java/fr java/fr/cemagref java/fr/cemagref/simexplorer java/fr/cemagref/simexplorer/is java/fr/cemagref/simexplorer/is/storage java/fr/cemagref/simexplorer/is/storage/attachment java/fr/cemagref/simexplorer/is/storage/attachment/fs java/fr/cemagref/simexplorer/is/storage/attachment/type java/fr/cemagref/simexplorer/is/storage/database java/fr/cemagref/simexplorer/is/storage/database/lucene java/fr/cemagref/simexplorer/is/storage/engine
by glandais@users.labs.libre-entreprise.org 07 Dec '07
by glandais@users.labs.libre-entreprise.org 07 Dec '07
07 Dec '07
Author: glandais
Date: 2007-12-07 14:36:43 +0000 (Fri, 07 Dec 2007)
New Revision: 55
Added:
trunk/simexplorer-si-storage/src/java/fr/
trunk/simexplorer-si-storage/src/java/fr/cemagref/
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/fs/
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneHits.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Code.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Component.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Constant.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ConstantValue.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Descriptor.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Entity.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationApplication.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationData.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/FileEntity.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Library.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/LoggableElement.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Repository.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Result.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Structure.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Version.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantValueFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/EntityFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationApplicationFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/FileEntityFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LoggableElementFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ResultFactory.java
trunk/simexplorer-si-storage/src/test/fr/
trunk/simexplorer-si-storage/src/test/fr/cemagref/
trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/
trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/
trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/
trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/
trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/ElementGenerator.java
trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/LuceneDatabaseTestCase.java
Removed:
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneConstants.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Code.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Component.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Constant.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ConstantValue.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Descriptor.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Entity.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationApplication.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationData.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Library.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/LoggableElement.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Repository.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Result.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Structure.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantValueFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/EntityFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationApplicationFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LoggableElementFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ResultFactory.java
trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/LuceneDatabaseTestCase.java
Modified:
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/fs/FileSystemAttachmentHandler.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentType.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentTypeFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/RawType.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/LuceneStorageEngine.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/CodeFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ComponentFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/DescriptorFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationDataFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LibraryFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/RepositoryFactory.java
trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/StructureFactory.java
Log:
Refactoring package name
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java (from rev 48, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/attachment/AttachmentHandler.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,54 @@
+package fr.cemagref.simexplorer.is.storage.attachment;
+
+import java.io.InputStream;
+
+import fr.cemagref.simexplorer.is.storage.entities.FileEntity;
+
+/**
+ * Store, retrieve and delete content
+ *
+ * @author landais
+ *
+ */
+public abstract class AttachmentHandler {
+
+ /**
+ * Store content
+ *
+ * @param entity
+ * Entity related to content
+ * @param field
+ * Unique field for content
+ * @param is
+ * Content
+ * @throws Exception
+ */
+ public abstract void storeData(FileEntity entity, String field,
+ InputStream is) throws Exception;
+
+ /**
+ * Retrieve content
+ *
+ * @param entity
+ * Entity related to content
+ * @param field
+ * Unique field for content
+ * @return Content
+ * @throws Exception
+ */
+ public abstract InputStream retrieveData(FileEntity entity, String field)
+ throws Exception;
+
+ /**
+ * Delete content
+ *
+ * @param entity
+ * Entity related to content
+ * @param field
+ * Unique field for content
+ * @throws Exception
+ */
+ public abstract void deleteData(FileEntity entity, String field)
+ throws Exception;
+
+}
\ No newline at end of file
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/fs (from rev 48, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/attachment/fs)
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/fs/FileSystemAttachmentHandler.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/attachment/fs/FileSystemAttachmentHandler.java 2007-12-06 18:32:23 UTC (rev 48)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/fs/FileSystemAttachmentHandler.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,4 +1,4 @@
-package org.cemagref.simexplorer.si.storage.attachment.fs;
+package fr.cemagref.simexplorer.is.storage.attachment.fs;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@@ -7,66 +7,92 @@
import java.io.FileOutputStream;
import java.io.InputStream;
-import org.cemagref.simexplorer.si.storage.attachment.AttachmentHandler;
-import org.cemagref.simexplorer.si.storage.entities.FileEntity;
-import org.cemagref.simexplorer.si.storage.entities.LoggableElement;
+import fr.cemagref.simexplorer.is.storage.attachment.AttachmentHandler;
+import fr.cemagref.simexplorer.is.storage.entities.FileEntity;
+import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
+/**
+ * File system implementation
+ *
+ * @author landais
+ *
+ */
public class FileSystemAttachmentHandler extends AttachmentHandler {
- private static String baseFolder = "./data/";
+ /**
+ * Base folder FIXME config
+ */
+ private static String baseFolder = "./data/";
- private File getFile(FileEntity entity, String field) throws Exception {
- String resultPath = baseFolder;
+ /**
+ * Retrieve file associated to content Create directories associated to file
+ *
+ * @param entity
+ * Entity related to content
+ * @param field
+ * Unique field for content
+ * @return Instance of file
+ * @throws Exception
+ */
+ private File getFile(FileEntity entity, String field) throws Exception {
+ String resultPath = baseFolder;
- LoggableElement loggableElement = null;
- if (entity instanceof LoggableElement) {
- loggableElement = (LoggableElement) entity;
- } else {
- loggableElement = entity.getOwner();
- }
+ // If entity has no metadata, use metadata of parent
+ LoggableElement loggableElement = null;
+ if (entity instanceof LoggableElement) {
+ loggableElement = (LoggableElement) entity;
+ } else {
+ loggableElement = entity.getOwner();
+ }
- resultPath = resultPath + loggableElement.getUuid() + "/"
- + loggableElement.getVersion().toString() + "/" + field;
+ // Create file path
+ resultPath = resultPath + loggableElement.getUuid() + "/"
+ + loggableElement.getVersion().toString() + "/" + field;
- File result = new File(resultPath);
- File resultFolder = new File(result.getParent());
- if (!resultFolder.exists()) {
- resultFolder.mkdirs();
- //result.createNewFile();
- }
-
- return result;
- }
+ File result = new File(resultPath);
+ // Create directories
+ File resultFolder = new File(result.getParent());
+ if (!resultFolder.exists()) {
+ resultFolder.mkdirs();
+ }
- @Override
- public InputStream retrieveData(FileEntity entity, String field)
- throws Exception {
- FileInputStream fis = new FileInputStream(getFile(entity, field));
- return fis;
- }
+ return result;
+ }
- @Override
- public void storeData(FileEntity entity, String field, InputStream is)
- throws Exception {
- FileOutputStream fos = new FileOutputStream(getFile(entity, field));
+ @Override
+ public InputStream retrieveData(FileEntity entity, String field)
+ throws Exception {
+ // Simple stream on file
+ FileInputStream fis = new FileInputStream(getFile(entity, field));
+ return fis;
+ }
- BufferedInputStream bin = new BufferedInputStream(is);
- BufferedOutputStream bout = new BufferedOutputStream(fos);
+ @Override
+ public void storeData(FileEntity entity, String field, InputStream is)
+ throws Exception {
+ // Simple stream on file
+ FileOutputStream fos = new FileOutputStream(getFile(entity, field));
- while (true) {
- int datum = bin.read();
- if (datum == -1)
- break;
- bout.write(datum);
- }
- bout.flush();
+ // Buffer copy stream to stream
+ BufferedInputStream bin = new BufferedInputStream(is);
+ BufferedOutputStream bout = new BufferedOutputStream(fos);
- fos.close();
- }
+ while (true) {
+ int datum = bin.read();
+ if (datum == -1)
+ break;
+ bout.write(datum);
+ }
+ bout.flush();
- @Override
- public void deleteData(FileEntity entity, String field) throws Exception {
- getFile(entity, field).delete();
- }
+ // Close file
+ fos.close();
+ }
+ @Override
+ public void deleteData(FileEntity entity, String field) throws Exception {
+ // Simple delete on file
+ getFile(entity, field).delete();
+ }
+
}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type (from rev 48, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/attachment/type)
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentType.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/attachment/type/ContentType.java 2007-12-06 18:32:23 UTC (rev 48)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentType.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,28 +1,61 @@
-package org.cemagref.simexplorer.si.storage.attachment.type;
+package fr.cemagref.simexplorer.is.storage.attachment.type;
import java.io.InputStream;
+/**
+ * Content handler
+ *
+ * @author landais
+ *
+ */
public abstract class ContentType {
- private String mimeType;
- private String description;
-
- public abstract InputStream renderToText(InputStream is);
+ /**
+ * MIME type
+ */
+ private String mimeType;
+ /**
+ * Text description
+ */
+ private String description;
- public String getMimeType() {
- return mimeType;
- }
+ /**
+ * Index content
+ *
+ * @param is
+ * Input stream
+ * @return Indexable text
+ */
+ public abstract InputStream renderToText(InputStream is);
- public void setMimeType(String mimeType) {
- this.mimeType = mimeType;
- }
+ /**
+ * @return the mimeType
+ */
+ public String getMimeType() {
+ return mimeType;
+ }
- public String getDescription() {
- return description;
- }
+ /**
+ * @param mimeType
+ * the mimeType to set
+ */
+ public void setMimeType(String mimeType) {
+ this.mimeType = mimeType;
+ }
- public void setDescription(String description) {
- this.description = description;
- }
-
+ /**
+ * @return the description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * @param description
+ * the description to set
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
}
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentTypeFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/attachment/type/ContentTypeFactory.java 2007-12-06 18:32:23 UTC (rev 48)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/ContentTypeFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,22 +1,43 @@
-package org.cemagref.simexplorer.si.storage.attachment.type;
+package fr.cemagref.simexplorer.is.storage.attachment.type;
import java.util.HashMap;
import java.util.Map;
+/**
+ * Cache content types
+ *
+ * @author landais
+ *
+ */
public class ContentTypeFactory {
- private static Map<String, ContentType> contentTypes = null;
-
- public static ContentType getContentTypeInstance(Class<? extends ContentType> contentTypeClass) throws Exception {
- if (contentTypes == null) {
- contentTypes = new HashMap<String, ContentType>();
- }
- ContentType result = contentTypes.get(contentTypeClass.getSimpleName());
- if (result == null) {
- result = contentTypeClass.newInstance();
- contentTypes.put(contentTypeClass.getSimpleName(), result);
- }
- return result;
- }
-
+ /**
+ * Content type cache
+ */
+ private static Map<String, ContentType> contentTypes = null;
+
+ /**
+ * Retrieve a content type instance
+ *
+ * @param contentTypeClass
+ * Class required
+ * @return Instance
+ * @throws Exception
+ */
+ public static ContentType getContentTypeInstance(
+ Class<? extends ContentType> contentTypeClass) throws Exception {
+ // Create cache if doesn't exist
+ if (contentTypes == null) {
+ contentTypes = new HashMap<String, ContentType>();
+ }
+ // Check cache
+ ContentType result = contentTypes.get(contentTypeClass.getSimpleName());
+ // Create instance if doesn't exist, and puts it in cache
+ if (result == null) {
+ result = contentTypeClass.newInstance();
+ contentTypes.put(contentTypeClass.getSimpleName(), result);
+ }
+ return result;
+ }
+
}
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/RawType.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/attachment/type/RawType.java 2007-12-06 18:32:23 UTC (rev 48)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/type/RawType.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,18 +1,28 @@
-package org.cemagref.simexplorer.si.storage.attachment.type;
+package fr.cemagref.simexplorer.is.storage.attachment.type;
import java.io.InputStream;
+/**
+ * Raw content type
+ *
+ * @author landais
+ *
+ */
public class RawType extends ContentType {
- public RawType() {
- super();
- setDescription("rawtype");
- setMimeType("text/text");
- }
+ /**
+ * Set inner properties
+ */
+ public RawType() {
+ super();
+ setDescription("rawtype");
+ setMimeType("text/text");
+ }
- @Override
- public InputStream renderToText(InputStream is) {
- return is;
- }
+ @Override
+ public InputStream renderToText(InputStream is) {
+ // No parsing
+ return is;
+ }
}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java (from rev 50, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/database/Database.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,225 @@
+package fr.cemagref.simexplorer.is.storage.database;
+
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import fr.cemagref.simexplorer.is.storage.entities.Entity;
+import fr.cemagref.simexplorer.is.storage.entities.FileEntity;
+import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
+import fr.cemagref.simexplorer.is.storage.entities.Version;
+
+/**
+ * Interface of a dabase able to manage elements
+ *
+ * @author landais
+ *
+ */
+public abstract class Database implements DatabaseConstants {
+
+ /**
+ * Open database connection
+ *
+ * @throws Exception
+ */
+ public abstract void open() throws Exception;
+
+ /**
+ * Close database connection
+ *
+ * @throws Exception
+ */
+ public abstract void close() throws Exception;
+
+ // Create / Update
+
+ /**
+ * Insert an element into database
+ *
+ * @param element
+ * Element to insert
+ * @throws Exception
+ */
+ public abstract void pushElement(LoggableElement element) throws Exception;
+
+ /**
+ * Attatch content to an element FIXME move to storage engine
+ *
+ * @param entity
+ * Related entity
+ * @param field
+ * Target field
+ * @param is
+ * Content
+ * @throws Exception
+ */
+ public abstract void storeData(FileEntity entity, String field,
+ InputStream is) throws Exception;
+
+ // Read
+
+ /**
+ * Get an element from its id and its version
+ *
+ * @param uuid
+ * Id
+ * @param version
+ * version
+ * @return Fund element, null if not fund
+ * @throws Exception
+ */
+ public abstract LoggableElement findElement(String uuid, Version version)
+ throws Exception;
+
+ /**
+ * Get all version of an element thanks to its id
+ *
+ * @param uuid
+ * Id
+ * @return Versions
+ * @throws Exception
+ */
+ public abstract List<Version> getVersions(String uuid) throws Exception;
+
+ /**
+ * Retrieve an element in its latest version
+ *
+ * @param uuid
+ * Id
+ * @return Element in its latest version, null if no element with this id
+ * exists
+ * @throws Exception
+ */
+ public LoggableElement getElementLatestVersion(String uuid)
+ throws Exception {
+ LoggableElement result = null;
+
+ // Get all versions
+ List<Version> versions = getVersions(uuid);
+
+ // Sort versions ascending
+ Collections.sort(versions);
+ // Revert, first is latest
+ Collections.reverse(versions);
+
+ // If at least a version exists
+ if (versions.size() > 0) {
+ Version version = versions.get(0);
+ // get element corresponding to latest version
+ result = findElement(uuid, version);
+ } else {
+ result = null;
+ }
+
+ return result;
+ }
+
+ /**
+ * Retrieve all elements by id
+ *
+ * @param uuid
+ * Id
+ * @return Element list
+ * @throws Exception
+ */
+ public abstract Set<LoggableElement> findElementsById(String uuid)
+ throws Exception;
+
+ /**
+ * Retrieve elements with specific properties
+ *
+ * @param properties
+ * Matching properties needed
+ * @return Element list
+ * @throws Exception
+ */
+ public abstract Set<LoggableElement> findElementsByProperties(
+ Map<String, String> properties) throws Exception;
+
+ /**
+ * Retrieve elements of a class with specific properties
+ *
+ * @param properties
+ * Matching properties needed
+ * @param entityClass
+ * Class searched
+ * @return Element list
+ * @throws Exception
+ */
+ public abstract Set<LoggableElement> findElementsByProperties(
+ Map<String, String> properties, Class<? extends Entity> entityClass)
+ throws Exception;
+
+ /**
+ * Retrieve elements by content search
+ *
+ * @param searchedText
+ * Searched text
+ * @return Element list
+ * @throws Exception
+ */
+ public abstract Set<LoggableElement> findElementsByContentSearch(
+ String searchedText) throws Exception;
+
+ /**
+ * Retrieve content
+ *
+ * @param entity
+ * Entity related to content
+ * @param field
+ * Unique field for content
+ * @return Content
+ * @throws Exception
+ */
+ public abstract InputStream retrieveData(FileEntity entity, String field)
+ throws Exception;
+
+ // Delete
+
+ /**
+ * Delete an a specific element
+ *
+ * @param element
+ * Element to delete
+ * @throws Exception
+ */
+ public void deleteElement(LoggableElement element) throws Exception {
+ deleteElement(element.getUuid(), element.getVersion());
+ }
+
+ /**
+ * Delete content
+ *
+ * @param entity
+ * Entity related to content
+ * @param field
+ * Unique field for content
+ * @throws Exception
+ */
+ public abstract void deleteData(FileEntity entity, String field)
+ throws Exception;
+
+ /**
+ * Delete all elements by id
+ *
+ * @param uuid
+ * Id
+ * @throws Exception
+ */
+ public abstract void deleteElements(String uuid) throws Exception;
+
+ /**
+ * Delete an element by id and version
+ *
+ * @param uuid
+ * Id
+ * @param version
+ * Version
+ * @throws Exception
+ */
+ public abstract void deleteElement(String uuid, Version version)
+ throws Exception;
+
+}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java (from rev 50, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/database/DatabaseConstants.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,48 @@
+package fr.cemagref.simexplorer.is.storage.database;
+
+/**
+ * Constants for database implementations
+ *
+ * @author landais
+ *
+ */
+public interface DatabaseConstants {
+
+ /**
+ * Field name for class name
+ */
+ public static final String KEY_CLASSNAME = "simexplorer.classname";
+ /**
+ * Field name for id
+ */
+ public static final String KEY_UUID = "simexplorer.uuid";
+ /**
+ * Field name for name
+ */
+ public static final String KEY_NAME = "simexplorer.name";
+ /**
+ * Field name for hash
+ */
+ public static final String KEY_HASH = "simexplorer.hash";
+ /**
+ * Field name for description
+ */
+ public static final String KEY_DESCRIPTION = "simexplorer.description";
+ /**
+ * Field name for version
+ */
+ public static final String KEY_VERSION = "simexplorer.version";
+ /**
+ * Field name for type
+ */
+ public static final String KEY_TYPE = "simexplorer.type";
+ /**
+ * Field name for creation date
+ */
+ public static final String KEY_CREATIONDATE = "simexplorer.creationdate";
+ /**
+ * Field name for xml content
+ */
+ public static final String KEY_XML = "simexplorer.xml";
+
+}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene (from rev 36, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/database/lucene)
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneConstants.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/database/lucene/LuceneConstants.java 2007-12-04 18:31:27 UTC (rev 36)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneConstants.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,11 +0,0 @@
-package org.cemagref.simexplorer.si.storage.database.lucene;
-
-public interface LuceneConstants {
-
- public static final String KEY_CLASSNAME = "simexplorer.classname";
- public static final String KEY_UUID = "simexplorer.uuid";
- public static final String KEY_DESCRIPTION = "simexplorer.description";
- public static final String KEY_MAJORVERSION = "simexplorer.version.major";
- public static final String KEY_MINORVERSION = "simexplorer.version.minor";
-
-}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/database/lucene/LuceneDatabase.java 2007-12-04 18:31:27 UTC (rev 36)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,250 +0,0 @@
-package org.cemagref.simexplorer.si.storage.database.lucene;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.analysis.PerFieldAnalyzerWrapper;
-import org.apache.lucene.analysis.SimpleAnalyzer;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
-import org.apache.lucene.index.CorruptIndexException;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.BooleanClause;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.Hits;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Searcher;
-import org.apache.lucene.search.TermQuery;
-import org.cemagref.simexplorer.si.storage.dao.ElementDAOFactory;
-import org.cemagref.simexplorer.si.storage.dao.factories.LoggableElementFactory;
-import org.cemagref.simexplorer.si.storage.database.Database;
-import org.cemagref.simexplorer.si.storage.entities.LoggableElement;
-import org.cemagref.simexplorer.si.storage.tools.Version;
-import org.w3c.dom.Element;
-
-public class LuceneDatabase extends Database implements LuceneConstants {// implements
- // LuceneDatabaseInterface
- // {
-
- private static Analyzer analyser;
- private static IndexWriter writer;
- private static Searcher searcher;
- private static boolean initok = false;
-
- public LuceneDatabase() throws Throwable {
- super();
- }
-
- protected void init() throws Throwable {
- if (!initok) {
- analyser = new PerFieldAnalyzerWrapper(new SimpleAnalyzer());
- // analyser.addAnalyzer("firstname", new KeywordAnalyzer());
- // analyser.addAnalyzer("lastname", new KeywordAnalyzer());
-
- String directory = "./index/";
-
- boolean create = false;
- if (!IndexReader.indexExists(directory)) {
- // si l'index n'existe pas, on force la creation
- create = true;
- }
- writer = new IndexWriter(directory, analyser, create);
- searcher = new IndexSearcher(directory);
- initok = true;
- }
- }
-
- @Override
- public void pushElement(LoggableElement element) throws Throwable {
- LoggableElementFactory elementFactory = (LoggableElementFactory) ElementDAOFactory
- .getFactory(element.getClass());
- Document document = saveLuceneElement(elementFactory, element);
-
- LoggableElement oldElement = findElement(element.getUuid(), element
- .getMajorVersion(), element.getMinorVersion());
- if (oldElement != null) {
- // update
- deleteElement(element);
- }
-
- writer.addDocument(document);
- }
-
- @Override
- public LoggableElement findElement(String uuid, Integer majorVersion,
- Integer minorVersion) throws Throwable {
-
- Map<String, String> properties = new HashMap<String, String>();
- properties.put(KEY_UUID, uuid);
- properties.put(KEY_MAJORVERSION, majorVersion.toString());
- properties.put(KEY_MINORVERSION, minorVersion.toString());
-
- Hits hits = findHits(properties);
- if (hits.length() == 0) {
- return null;
- } else {
- return convertDocumentToElement(hits.doc(0));
- }
- }
-
- @Override
- public LoggableElement getElementLatestVersion(String uuid)
- throws Throwable {
- LoggableElement element = null;
-
- Map<String, String> properties = new HashMap<String, String>();
- properties.put(KEY_UUID, uuid);
- Hits hits = findHits(properties);
- if (hits.length() > 0) {
- List<Version> versions = new ArrayList<Version>();
- for (int i = 0; i < hits.length(); i++) {
- Document doc = hits.doc(i);
- Version version = new Version();
- version.setMajorVersion(new Integer(doc.get(KEY_MAJORVERSION)));
- version.setMinorVersion(new Integer(doc.get(KEY_MINORVERSION)));
- version.setVersionnedObject(doc);
- }
- Collections.sort(versions);
- Collections.reverse(versions);
-
- Document latestDoc = (Document) versions.get(0)
- .getVersionnedObject();
- LoggableElementFactory elementFactory = (LoggableElementFactory) ElementDAOFactory
- .getFactory(latestDoc.get(KEY_CLASSNAME));
- element = loadLuceneElement(elementFactory, latestDoc);
- }
-
- return element;
- }
-
- @Override
- public Set<LoggableElement> findElementsById(String uuid) throws Throwable {
- Map<String, String> properties = new HashMap<String, String>();
- properties.put(KEY_UUID, uuid);
- return convertHitsToElements(findHits(properties));
- }
-
- @Override
- public Set<LoggableElement> findElementsByProperties(
- Map<String, String> properties) throws Throwable {
- return convertHitsToElements(findHits(properties));
- }
-
- @Override
- public Set<LoggableElement> findElementsByProperties(
- Map<String, String> properties, Class entityClass) throws Throwable {
- Map<String, String> props = new HashMap<String, String>();
- props.putAll(properties);
- props.put(KEY_CLASSNAME, entityClass.getName());
- return convertHitsToElements(findHits(properties));
- }
-
- public void deleteElement(String uuid) throws Throwable {
- writer.deleteDocuments(new Term(KEY_UUID, uuid));
- }
-
- public void deleteElement(String uuid, Integer majorVersion,
- Integer minorVersion) throws Throwable {
- Term[] terms = new Term[3];
- terms[0] = new Term(KEY_UUID, uuid);
- terms[1] = new Term(KEY_MAJORVERSION, uuid);
- terms[2] = new Term(KEY_MINORVERSION, uuid);
- writer.deleteDocuments(terms);
- }
-
- private Hits findHits(Map<String, String> properties) throws Throwable {
- // FIXME disablecoords?
- BooleanQuery query = new BooleanQuery(false);
- for (Entry<String, String> kv : properties.entrySet()) {
- query.add(new TermQuery(new Term(kv.getKey(), kv.getValue())),
- BooleanClause.Occur.MUST);
- }
- return searcher.search(query);
- }
-
- private LoggableElement convertDocumentToElement(Document document)
- throws Throwable {
- String className = document.get(KEY_CLASSNAME);
- LoggableElementFactory factory = (LoggableElementFactory) ElementDAOFactory
- .getFactory(className);
- return loadLuceneElement(factory, document);
- }
-
- private Set<LoggableElement> convertHitsToElements(Hits hits)
- throws Throwable {
- Set<LoggableElement> elements = new HashSet<LoggableElement>();
- for (int i = 0; i < hits.length(); i++) {
- Document document = hits.doc(i);
- elements.add(convertDocumentToElement(document));
- }
- return elements;
- }
-
- private LoggableElement loadLuceneElement(LoggableElementFactory factory, Document document) throws Throwable {
- String strXMLElement = document.get("xmlElement");
-
- InputStream is = new ByteArrayInputStream(strXMLElement.getBytes());
- org.w3c.dom.Document xmlDocument = factory.getBuilder().parse(is);
-
- LoggableElement element = factory.loadXMLElement((Element) xmlDocument.getFirstChild());
-
- return element;
- }
-
- private Document saveLuceneElement(LoggableElementFactory factory, LoggableElement element) throws Throwable {
- Document document = new Document();
-
- // FIXME save searchable/metadata fields
- document.add(new Field(KEY_UUID, element.getUuid().getBytes(),
- Field.Store.YES));
- document.add(new Field(KEY_DESCRIPTION, element.getDescription().getBytes(),
- Field.Store.YES));
- document.add(new Field(KEY_CLASSNAME, element.getClass().getName().getBytes(),
- Field.Store.YES));
- document.add(new Field(KEY_MINORVERSION, element.getMinorVersion().toString().getBytes(),
- Field.Store.YES));
- document.add(new Field(KEY_MAJORVERSION, element.getMajorVersion().toString().getBytes(),
- Field.Store.YES));
-
- org.w3c.dom.Document xmlDocument = factory.getBuilder().newDocument();
- // Propriétés du DOM
- xmlDocument.setXmlVersion("1.0");
- xmlDocument.setXmlStandalone(true);
- // Création de l'arborescence du DOM
- Element racine = xmlDocument.createElement(element.getClass().getName());
- factory.saveXMLElement(xmlDocument, racine, element);
- xmlDocument.appendChild(racine);
- DOMSource domSource = new DOMSource(xmlDocument);
- StringWriter writer = new StringWriter();
- StreamResult result = new StreamResult(writer);
- TransformerFactory tf = TransformerFactory.newInstance();
- Transformer transformer = tf.newTransformer();
- transformer.transform(domSource, result);
- String stringResult = writer.toString();
- document.add(new Field("xmlElement", stringResult, Field.Store.COMPRESS, Field.Index.NO));
-
- return document;
- }
-
- public void shutDown() throws Throwable {
- writer.close();
- }
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java (from rev 50, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/database/lucene/LuceneDatabase.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,271 @@
+package fr.cemagref.simexplorer.is.storage.database.lucene;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.PerFieldAnalyzerWrapper;
+import org.apache.lucene.analysis.SimpleAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Searcher;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FSDirectory;
+import org.w3c.dom.Element;
+
+import fr.cemagref.simexplorer.is.storage.database.Database;
+import fr.cemagref.simexplorer.is.storage.entities.Entity;
+import fr.cemagref.simexplorer.is.storage.entities.FileEntity;
+import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
+import fr.cemagref.simexplorer.is.storage.entities.Version;
+import fr.cemagref.simexplorer.is.storage.factories.EntityFactory;
+import fr.cemagref.simexplorer.is.storage.factories.FileEntityFactory;
+import fr.cemagref.simexplorer.is.storage.factories.LoggableElementFactory;
+
+public class LuceneDatabase extends Database {
+
+ private Analyzer analyser;
+ private String indexDirectory;
+ private IndexWriter writer;
+ private boolean initok = false;
+
+ @Override
+ public void open() throws Exception {
+ if (!initok) {
+ analyser = new PerFieldAnalyzerWrapper(new SimpleAnalyzer());
+ // analyser.addAnalyzer("firstname", new KeywordAnalyzer());
+ // analyser.addAnalyzer("lastname", new KeywordAnalyzer());
+
+ indexDirectory = "./index/";
+
+ boolean create = false;
+ if (!IndexReader.indexExists(indexDirectory)) {
+ create = true;
+ }
+
+ Directory dir = FSDirectory.getDirectory(indexDirectory);
+
+ writer = new IndexWriter(dir, true, analyser, create);
+ initok = true;
+ }
+ }
+
+ @Override
+ public void close() throws Exception {
+ writer.close();
+ }
+
+ @Override
+ public void pushElement(LoggableElement element) throws Exception {
+ Set<LoggableElement> children = element.getChildren();
+ for (LoggableElement loggableElement : children) {
+ pushElement(loggableElement);
+ }
+
+ Class<? extends LoggableElement> clazz = element.getClass();
+
+ LoggableElementFactory<LoggableElement> elementFactory = (LoggableElementFactory<LoggableElement>) LoggableElementFactory
+ .getFactory(clazz);
+ Document document = saveLuceneElement(elementFactory, element);
+
+ LoggableElement oldElement = findElement(element.getUuid(), element
+ .getVersion());
+ if (oldElement != null) {
+ // update
+ deleteElement(element);
+ }
+
+ InputStream is = new ByteArrayInputStream(document.get(KEY_XML)
+ .getBytes());
+ FileEntityFactory.getHandler().storeData(element, KEY_XML, is);
+
+ writer.addDocument(document);
+ writer.flush();
+ }
+
+ @Override
+ public LoggableElement findElement(String uuid, Version version)
+ throws Exception {
+ LoggableElement result = null;
+
+ Map<String, String> properties = new HashMap<String, String>();
+ properties.put(KEY_UUID, uuid);
+ properties.put(KEY_VERSION, version.toString());
+
+ LuceneHits hits = findHits(properties);
+ if (hits.getHits().length() != 0) {
+ result = convertDocumentToElement(hits.getHits().doc(0));
+ }
+ hits.closeSearcher();
+
+ return result;
+ }
+
+ @Override
+ public Set<LoggableElement> findElementsById(String uuid) throws Exception {
+ Map<String, String> properties = new HashMap<String, String>();
+ properties.put(KEY_UUID, uuid);
+ return convertHitsToElements(findHits(properties));
+ }
+
+ @Override
+ public Set<LoggableElement> findElementsByProperties(
+ Map<String, String> properties) throws Exception {
+ return convertHitsToElements(findHits(properties));
+ }
+
+ @Override
+ public Set<LoggableElement> findElementsByProperties(
+ Map<String, String> properties, Class<? extends Entity> entityClass)
+ throws Exception {
+ Map<String, String> props = new HashMap<String, String>();
+ props.putAll(properties);
+ props.put(KEY_CLASSNAME, entityClass.getName());
+ return convertHitsToElements(findHits(properties));
+ }
+
+ public void deleteElements(String uuid) throws Exception {
+ Set<LoggableElement> set = findElementsById(uuid);
+ for (LoggableElement loggableElement : set) {
+ deleteData(loggableElement, KEY_XML);
+ }
+ writer.deleteDocuments(new Term(KEY_UUID, uuid));
+ writer.flush();
+ }
+
+ public void deleteElement(String uuid, Version version) throws Exception {
+
+ LoggableElement loggableElement = findElement(uuid, version);
+ deleteData(loggableElement, KEY_XML);
+
+ Term[] terms = new Term[3];
+ terms[0] = new Term(KEY_UUID, uuid);
+ terms[1] = new Term(KEY_VERSION, version.toString());
+ writer.deleteDocuments(terms);
+ writer.flush();
+ }
+
+ private LuceneHits findHits(Map<String, String> properties)
+ throws Exception {
+ Searcher searcher = new IndexSearcher(indexDirectory);
+
+ // FIXME disablecoords?
+ BooleanQuery query = new BooleanQuery(false);
+ for (Entry<String, String> kv : properties.entrySet()) {
+ query.add(new TermQuery(new Term(kv.getKey(), kv.getValue())),
+ BooleanClause.Occur.MUST);
+ }
+
+ LuceneHits luceneHits = new LuceneHits(searcher.search(query), searcher);
+ return luceneHits;
+ }
+
+ private LoggableElement convertDocumentToElement(Document document)
+ throws Exception {
+ String className = document.get(KEY_CLASSNAME);
+ LoggableElementFactory<LoggableElement> factory = (LoggableElementFactory<LoggableElement>) LoggableElementFactory
+ .getFactory(className);
+ return loadLuceneElement(factory, document);
+ }
+
+ private Set<LoggableElement> convertHitsToElements(LuceneHits hits)
+ throws Exception {
+ Set<LoggableElement> elements = new HashSet<LoggableElement>();
+ for (int i = 0; i < hits.getHits().length(); i++) {
+ Document document = hits.getHits().doc(i);
+ elements.add(convertDocumentToElement(document));
+ }
+ hits.closeSearcher();
+ return elements;
+ }
+
+ private LoggableElement loadLuceneElement(
+ LoggableElementFactory<LoggableElement> factory, Document document)
+ throws Exception {
+ String strXMLElement = document.get(KEY_XML);
+
+ InputStream is = new ByteArrayInputStream(strXMLElement.getBytes());
+
+ org.w3c.dom.Document xmlDocument = EntityFactory.getBuilder().parse(is);
+
+ LoggableElement element = factory.loadXMLElement((Element) xmlDocument
+ .getFirstChild());
+
+ return element;
+ }
+
+ private Document saveLuceneElement(
+ LoggableElementFactory<LoggableElement> factory,
+ LoggableElement element) throws Exception {
+ Document document = new Document();
+
+ // FIXME save searchable/metadata fields
+ document.add(new Field(KEY_UUID, element.getUuid(), Field.Store.YES,
+ Field.Index.UN_TOKENIZED));
+ document.add(new Field(KEY_DESCRIPTION, element.getDescription(),
+ Field.Store.YES, Field.Index.UN_TOKENIZED));
+ document.add(new Field(KEY_CLASSNAME, element.getClass().getName(),
+ Field.Store.YES, Field.Index.UN_TOKENIZED));
+ document.add(new Field(KEY_VERSION, element.getVersion().toString()
+ .toString(), Field.Store.YES, Field.Index.UN_TOKENIZED));
+
+ document.add(new Field(KEY_XML, factory.getElementXML(element),
+ Field.Store.COMPRESS, Field.Index.NO));
+
+ return document;
+ }
+
+ @Override
+ public List<Version> getVersions(String uuid) throws Exception {
+ Map<String, String> properties = new HashMap<String, String>();
+ properties.put(KEY_UUID, uuid);
+ LuceneHits hits = findHits(properties);
+
+ List<Version> versions = new ArrayList<Version>();
+ for (int i = 0; i < hits.getHits().length(); i++) {
+ Document doc = hits.getHits().doc(i);
+ versions.add(new Version(doc.get(KEY_VERSION)));
+ }
+
+ return versions;
+ }
+
+ @Override
+ public void deleteData(FileEntity entity, String field) throws Exception {
+ FileEntityFactory.getHandler().deleteData(entity, field);
+ }
+
+ @Override
+ public InputStream retrieveData(FileEntity entity, String field)
+ throws Exception {
+ return FileEntityFactory.getHandler().retrieveData(entity, field);
+ }
+
+ @Override
+ public void storeData(FileEntity entity, String field, InputStream is)
+ throws Exception {
+ FileEntityFactory.getHandler().storeData(entity, field, is);
+ }
+
+ @Override
+ public Set<LoggableElement> findElementsByContentSearch(String searchedText)
+ throws Exception {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneHits.java (from rev 41, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/database/lucene/LuceneHits.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneHits.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneHits.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,37 @@
+package fr.cemagref.simexplorer.is.storage.database.lucene;
+
+import org.apache.lucene.search.Hits;
+import org.apache.lucene.search.Searcher;
+
+public class LuceneHits {
+
+ private Hits hits;
+ private Searcher searcher;
+
+ public LuceneHits(Hits hits, Searcher searcher) {
+ super();
+ this.hits = hits;
+ this.searcher = searcher;
+ }
+
+ public void closeSearcher() throws Exception {
+ searcher.close();
+ }
+
+ public Hits getHits() {
+ return hits;
+ }
+
+ public void setHits(Hits hits) {
+ this.hits = hits;
+ }
+
+ public Searcher getSearcher() {
+ return searcher;
+ }
+
+ public void setSearcher(Searcher searcher) {
+ this.searcher = searcher;
+ }
+
+}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine (from rev 51, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/engine)
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/LuceneStorageEngine.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/engine/LuceneStorageEngine.java 2007-12-06 18:37:03 UTC (rev 51)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/LuceneStorageEngine.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,98 +1,100 @@
-package org.cemagref.simexplorer.si.storage.engine;
+package fr.cemagref.simexplorer.is.storage.engine;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collections;
import java.util.List;
-import org.cemagref.simexplorer.si.storage.database.lucene.LuceneDatabase;
-import org.cemagref.simexplorer.si.storage.entities.LoggableElement;
-import org.cemagref.simexplorer.si.storage.entities.Version;
-import org.cemagref.simexplorer.si.storage.factories.EntityFactory;
+import fr.cemagref.simexplorer.is.storage.database.lucene.LuceneDatabase;
+import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
+import fr.cemagref.simexplorer.is.storage.entities.Version;
+import fr.cemagref.simexplorer.is.storage.factories.EntityFactory;
+import fr.cemagref.simexplorer.is.storage.factories.LoggableElementFactory;
public class LuceneStorageEngine extends StorageEngine {
- @Override
- public void close() throws Exception {
- database.close();
- }
+ @Override
+ public void close() throws Exception {
+ database.close();
+ }
- @Override
- public void exportElement(LoggableElement element, OutputStream os)
- throws Exception {
- LoggableElement completeElement = database.findElement(element
- .getUuid(), element.getVersion());
- EntityFactory.getFactory(completeElement.getClass()).getElementXML(
- element, os);
- }
+ @Override
+ public void exportElement(LoggableElement element, OutputStream os)
+ throws Exception {
+ LoggableElement completeElement = database.findElement(element
+ .getUuid(), element.getVersion());
+ LoggableElementFactory<LoggableElement> factory = (LoggableElementFactory<LoggableElement>) EntityFactory
+ .getFactory(completeElement.getClass());
+ factory.getElementXML(element, os);
+ }
- @Override
- public LoggableElement getElement(String uuid) throws Exception {
- return database.getElementLatestVersion(uuid);
- }
+ @Override
+ public LoggableElement getElement(String uuid) throws Exception {
+ return database.getElementLatestVersion(uuid);
+ }
- @Override
- public LoggableElement getElementVersion(String uuid, Version version)
- throws Exception {
- return database.findElement(uuid, version);
- }
+ @Override
+ public LoggableElement getElementVersion(String uuid, Version version)
+ throws Exception {
+ return database.findElement(uuid, version);
+ }
- @Override
- public List<Version> getVersions(String uuid) throws Exception {
- return database.getVersions(uuid);
- }
+ @Override
+ public List<Version> getVersions(String uuid) throws Exception {
+ return database.getVersions(uuid);
+ }
- @Override
- public LoggableElement importElement(InputStream inputStream)
- throws Exception {
- LoggableElement importedElement = null;
+ @Override
+ public LoggableElement importElement(InputStream inputStream)
+ throws Exception {
+ LoggableElement importedElement = null;
- database.pushElement(importedElement);
- return importedElement;
- }
+ database.pushElement(importedElement);
+ return importedElement;
+ }
- @Override
- public LoggableElement newElement(LoggableElement element) throws Exception {
- if (getElement(element.getUuid()) != null) {
- throw new Exception(element.getUuid() + " already exist");
- }
- element.setVersion("1");
- database.pushElement(element);
- return getElement(element.getUuid());
- }
+ @Override
+ public LoggableElement newElement(LoggableElement element) throws Exception {
+ if (getElement(element.getUuid()) != null) {
+ throw new Exception(element.getUuid() + " already exist");
+ }
+ element.setVersion("1");
+ database.pushElement(element);
+ return getElement(element.getUuid());
+ }
- @Override
- public void open() throws Exception {
- database = new LuceneDatabase();
- database.open();
- }
+ @Override
+ public void open() throws Exception {
+ database = new LuceneDatabase();
+ database.open();
+ }
- @Override
- public LoggableElement saveElement(LoggableElement element)
- throws Exception {
- Version version = null;
- List<Version> versions = getVersions(element.getUuid());
- if (versions.size() > 0) {
- Collections.sort(versions);
- Collections.reverse(versions);
+ @Override
+ public LoggableElement saveElement(LoggableElement element)
+ throws Exception {
+ Version version = null;
+ List<Version> versions = getVersions(element.getUuid());
+ if (versions.size() > 0) {
+ Collections.sort(versions);
+ Collections.reverse(versions);
- version = versions.get(0);
- version.incVersion(0);
- } else {
- version = new Version("1");
- }
+ version = versions.get(0);
+ version.incVersion(0);
+ } else {
+ version = new Version("1");
+ }
- element.setVersion(version.toString());
+ element.setVersion(version.toString());
- database.pushElement(element);
- return getElement(element.getUuid());
- }
+ database.pushElement(element);
+ return getElement(element.getUuid());
+ }
- @Override
- public LoggableElement synchronizeElement(LoggableElement element)
- throws Exception {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public LoggableElement synchronizeElement(LoggableElement element)
+ throws Exception {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/engine/StorageEngine.java 2007-12-06 18:37:03 UTC (rev 51)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,41 +1,41 @@
-package org.cemagref.simexplorer.si.storage.engine;
+package fr.cemagref.simexplorer.is.storage.engine;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
-import org.cemagref.simexplorer.si.storage.database.Database;
-import org.cemagref.simexplorer.si.storage.entities.LoggableElement;
-import org.cemagref.simexplorer.si.storage.entities.Version;
+import fr.cemagref.simexplorer.is.storage.database.Database;
+import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
+import fr.cemagref.simexplorer.is.storage.entities.Version;
public abstract class StorageEngine {
- protected Database database;
+ protected Database database;
- public abstract void open() throws Exception;
+ public abstract void open() throws Exception;
- public abstract void close() throws Exception;
+ public abstract void close() throws Exception;
- public abstract LoggableElement getElement(String uuid) throws Exception;
+ public abstract LoggableElement getElement(String uuid) throws Exception;
- public abstract List<Version> getVersions(String uuid) throws Exception;
+ public abstract List<Version> getVersions(String uuid) throws Exception;
- public abstract LoggableElement getElementVersion(String uuid,
- Version version) throws Exception;
+ public abstract LoggableElement getElementVersion(String uuid,
+ Version version) throws Exception;
- public abstract LoggableElement newElement(LoggableElement element)
- throws Exception;
+ public abstract LoggableElement newElement(LoggableElement element)
+ throws Exception;
- public abstract LoggableElement saveElement(LoggableElement element)
- throws Exception;
+ public abstract LoggableElement saveElement(LoggableElement element)
+ throws Exception;
- public abstract LoggableElement synchronizeElement(LoggableElement element)
- throws Exception;
+ public abstract LoggableElement synchronizeElement(LoggableElement element)
+ throws Exception;
- public abstract void exportElement(LoggableElement element, OutputStream os)
- throws Exception;
+ public abstract void exportElement(LoggableElement element, OutputStream os)
+ throws Exception;
- public abstract LoggableElement importElement(InputStream inputStream)
- throws Exception;
+ public abstract LoggableElement importElement(InputStream inputStream)
+ throws Exception;
}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities (from rev 31, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities)
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Code.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/Code.java 2007-12-03 17:37:30 UTC (rev 31)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Code.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,21 +0,0 @@
-package org.cemagref.simexplorer.si.storage.entities;
-
-public class Code implements Entity {
-
- private String language;
- private String code;
-
- public String getLanguage() {
- return language;
- }
- public void setLanguage(String language) {
- this.language = language;
- }
- public String getCode() {
- return code;
- }
- public void setCode(String code) {
- this.code = code;
- }
-
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Code.java (from rev 49, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/Code.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Code.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Code.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,24 @@
+package fr.cemagref.simexplorer.is.storage.entities;
+
+public class Code extends Entity {
+
+ private String language;
+ private String code;
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public void setLanguage(String language) {
+ this.language = language;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Component.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/Component.java 2007-12-03 17:37:30 UTC (rev 31)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Component.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,22 +0,0 @@
-package org.cemagref.simexplorer.si.storage.entities;
-
-import java.util.HashSet;
-import java.util.Set;
-
-public class Component extends LoggableElement {
-
- Set<Constant> constants;
- Set<Structure> structures;
- Set<Code> codes;
- Set<Library> libraries;
-
- @Override
- public Set<LoggableElement> getChildren() {
- Set<LoggableElement> children = new HashSet<LoggableElement>();
- if (libraries != null) {
- children.addAll(libraries);
- }
- return children;
- }
-
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Component.java (from rev 49, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/Component.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Component.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Component.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,62 @@
+package fr.cemagref.simexplorer.is.storage.entities;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import fr.cemagref.simexplorer.is.storage.attachment.type.ContentType;
+
+public class Component extends LoggableElement {
+
+ Set<Constant> constants;
+ Set<Structure> structures;
+ Set<Code> codes;
+ Set<Library> libraries;
+
+ public Set<Constant> getConstants() {
+ return constants;
+ }
+
+ public void setConstants(Set<Constant> constants) {
+ this.constants = constants;
+ }
+
+ public Set<Structure> getStructures() {
+ return structures;
+ }
+
+ public void setStructures(Set<Structure> structures) {
+ this.structures = structures;
+ }
+
+ public Set<Code> getCodes() {
+ return codes;
+ }
+
+ public void setCodes(Set<Code> codes) {
+ this.codes = codes;
+ }
+
+ public Set<Library> getLibraries() {
+ return libraries;
+ }
+
+ public void setLibraries(Set<Library> libraries) {
+ this.libraries = libraries;
+ }
+
+ @Override
+ public Set<LoggableElement> getChildren() {
+ Set<LoggableElement> elements = new HashSet<LoggableElement>();
+ elements.addAll(libraries);
+ return elements;
+ }
+
+ @Override
+ public Map<String, ContentType> getContentTypes() throws Exception {
+ Map<String, ContentType> contentTypes = new HashMap<String, ContentType>();
+ return contentTypes;
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Constant.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/Constant.java 2007-12-03 17:37:30 UTC (rev 31)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Constant.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,21 +0,0 @@
-package org.cemagref.simexplorer.si.storage.entities;
-
-public class Constant implements Entity {
-
- private String name;
- private Class type;
-
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public Class getType() {
- return type;
- }
- public void setType(Class type) {
- this.type = type;
- }
-
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Constant.java (from rev 49, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/Constant.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Constant.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Constant.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,24 @@
+package fr.cemagref.simexplorer.is.storage.entities;
+
+public class Constant extends Entity {
+
+ private String name;
+ private Class<?> type;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Class<?> getType() {
+ return type;
+ }
+
+ public void setType(Class<?> type) {
+ this.type = type;
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ConstantValue.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/ConstantValue.java 2007-12-03 17:37:30 UTC (rev 31)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ConstantValue.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,21 +0,0 @@
-package org.cemagref.simexplorer.si.storage.entities;
-
-public class ConstantValue implements Entity {
-
- private Object value;
- private Constant constant;
-
- public Object getValue() {
- return value;
- }
- public void setValue(Object value) {
- this.value = value;
- }
- public Constant getConstant() {
- return constant;
- }
- public void setConstant(Constant constant) {
- this.constant = constant;
- }
-
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ConstantValue.java (from rev 49, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/ConstantValue.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ConstantValue.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ConstantValue.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,24 @@
+package fr.cemagref.simexplorer.is.storage.entities;
+
+public class ConstantValue extends Entity {
+
+ private String value;
+ private Constant constant;
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public Constant getConstant() {
+ return constant;
+ }
+
+ public void setConstant(Constant constant) {
+ this.constant = constant;
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Descriptor.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/Descriptor.java 2007-12-03 17:37:30 UTC (rev 31)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Descriptor.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,21 +0,0 @@
-package org.cemagref.simexplorer.si.storage.entities;
-
-public class Descriptor implements Entity {
-
- private String name;
- private String value;
-
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getValue() {
- return value;
- }
- public void setValue(String value) {
- this.value = value;
- }
-
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Descriptor.java (from rev 49, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/Descriptor.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Descriptor.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Descriptor.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,24 @@
+package fr.cemagref.simexplorer.is.storage.entities;
+
+public class Descriptor extends Entity {
+
+ private String name;
+ private String value;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Entity.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/Entity.java 2007-12-03 17:37:30 UTC (rev 31)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Entity.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,5 +0,0 @@
-package org.cemagref.simexplorer.si.storage.entities;
-
-public interface Entity {
-
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Entity.java (from rev 49, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/Entity.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Entity.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Entity.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,15 @@
+package fr.cemagref.simexplorer.is.storage.entities;
+
+public abstract class Entity {
+
+ private LoggableElement owner;
+
+ public LoggableElement getOwner() {
+ return owner;
+ }
+
+ public void setOwner(LoggableElement owner) {
+ this.owner = owner;
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationApplication.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/ExplorationApplication.java 2007-12-03 17:37:30 UTC (rev 31)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationApplication.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,38 +0,0 @@
-package org.cemagref.simexplorer.si.storage.entities;
-
-import java.util.HashSet;
-import java.util.Set;
-
-
-public class ExplorationApplication extends LoggableElement {
-
- private Set<ExplorationData> explorations;
- private Set<Component> components;
-
- public Set<ExplorationData> getExplorations() {
- return explorations;
- }
- public void setExplorations(Set<ExplorationData> explorations) {
- this.explorations = explorations;
- }
- public Set<Component> getComponents() {
- return components;
- }
- public void setComponents(Set<Component> components) {
- this.components = components;
- }
-
- @Override
- public Set<LoggableElement> getChildren() {
- Set<LoggableElement> children = new HashSet<LoggableElement>();
- if (explorations != null) {
- children.addAll(explorations);
- }
- if (components != null) {
- children.addAll(components);
- }
- return children;
- }
-
-
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationApplication.java (from rev 49, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/ExplorationApplication.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationApplication.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationApplication.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,49 @@
+package fr.cemagref.simexplorer.is.storage.entities;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import fr.cemagref.simexplorer.is.storage.attachment.type.ContentType;
+import fr.cemagref.simexplorer.is.storage.attachment.type.ContentTypeFactory;
+import fr.cemagref.simexplorer.is.storage.attachment.type.RawType;
+
+public class ExplorationApplication extends LoggableElement {
+
+ private Set<ExplorationData> explorations;
+ private Set<Component> components;
+
+ public Set<ExplorationData> getExplorations() {
+ return explorations;
+ }
+
+ public void setExplorations(Set<ExplorationData> explorations) {
+ this.explorations = explorations;
+ }
+
+ public Set<Component> getComponents() {
+ return components;
+ }
+
+ public void setComponents(Set<Component> components) {
+ this.components = components;
+ }
+
+ @Override
+ public Set<LoggableElement> getChildren() {
+ Set<LoggableElement> elements = new HashSet<LoggableElement>();
+ elements.addAll(explorations);
+ elements.addAll(components);
+ return elements;
+ }
+
+ @Override
+ public Map<String, ContentType> getContentTypes() throws Exception {
+ Map<String, ContentType> contentTypes = new HashMap<String, ContentType>();
+ contentTypes.put("xml", ContentTypeFactory
+ .getContentTypeInstance(RawType.class));
+ return contentTypes;
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationData.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/ExplorationData.java 2007-12-03 17:37:30 UTC (rev 31)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationData.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,51 +0,0 @@
-package org.cemagref.simexplorer.si.storage.entities;
-
-import java.util.HashSet;
-import java.util.Set;
-
-public class ExplorationData extends LoggableElement {
-
- private Set<ConstantValue> valuesMap;
- private Result result;
-
- private ConstantValue findConstantValue(Constant c) {
- for (ConstantValue constantValue : valuesMap) {
- if (c.equals(constantValue.getConstant())) {
- return constantValue;
- }
- }
- return null;
- }
-
- public void setConstantValue(Constant c, Object value) {
- ConstantValue constantValue = findConstantValue(c);
- if (constantValue == null) {
- constantValue = new ConstantValue();
- constantValue.setConstant(c);
- valuesMap.add(constantValue);
- }
- constantValue.setValue(value);
- }
-
- public Object getConstantValue(Constant c) {
- ConstantValue constantValue = findConstantValue(c);
- if (constantValue == null) {
- return null;
- } else {
- return constantValue.getValue();
- }
- }
-
- public Result getResult() {
- return result;
- }
-
- public void setResult(Result result) {
- this.result = result;
- }
-
- @Override
- public Set<LoggableElement> getChildren() {
- return new HashSet<LoggableElement>();
- }
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationData.java (from rev 49, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/ExplorationData.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationData.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/ExplorationData.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,75 @@
+package fr.cemagref.simexplorer.is.storage.entities;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import fr.cemagref.simexplorer.is.storage.attachment.type.ContentType;
+import fr.cemagref.simexplorer.is.storage.attachment.type.ContentTypeFactory;
+import fr.cemagref.simexplorer.is.storage.attachment.type.RawType;
+
+public class ExplorationData extends LoggableElement {
+
+ private Set<ConstantValue> valuesMap;
+ private Result result;
+
+ private ConstantValue findConstantValue(Constant c) {
+ for (ConstantValue constantValue : valuesMap) {
+ if (c.equals(constantValue.getConstant())) {
+ return constantValue;
+ }
+ }
+ return null;
+ }
+
+ public void setConstantValue(Constant c, String value) {
+ ConstantValue constantValue = findConstantValue(c);
+ if (constantValue == null) {
+ constantValue = new ConstantValue();
+ constantValue.setConstant(c);
+ valuesMap.add(constantValue);
+ }
+ constantValue.setValue(value);
+ }
+
+ public Object getConstantValue(Constant c) {
+ ConstantValue constantValue = findConstantValue(c);
+ if (constantValue == null) {
+ return null;
+ } else {
+ return constantValue.getValue();
+ }
+ }
+
+ public Result getResult() {
+ return result;
+ }
+
+ public void setResult(Result result) {
+ this.result = result;
+ }
+
+ public Set<ConstantValue> getValuesMap() {
+ return valuesMap;
+ }
+
+ public void setValuesMap(Set<ConstantValue> valuesMap) {
+ this.valuesMap = valuesMap;
+ }
+
+ @Override
+ public Set<LoggableElement> getChildren() {
+ Set<LoggableElement> elements = new HashSet<LoggableElement>();
+ return elements;
+ }
+
+ @Override
+ public Map<String, ContentType> getContentTypes() throws Exception {
+ Map<String, ContentType> contentTypes = new HashMap<String, ContentType>();
+ contentTypes.put("xml", ContentTypeFactory
+ .getContentTypeInstance(RawType.class));
+ return contentTypes;
+ }
+
+}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/FileEntity.java (from rev 49, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/FileEntity.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/FileEntity.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/FileEntity.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,11 @@
+package fr.cemagref.simexplorer.is.storage.entities;
+
+import java.util.Map;
+
+import fr.cemagref.simexplorer.is.storage.attachment.type.ContentType;
+
+public abstract class FileEntity extends Entity {
+
+ public abstract Map<String, ContentType> getContentTypes() throws Exception;
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Library.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/Library.java 2007-12-03 17:37:30 UTC (rev 31)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Library.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,14 +0,0 @@
-package org.cemagref.simexplorer.si.storage.entities;
-
-import java.util.HashSet;
-import java.util.Set;
-
-
-public class Library extends LoggableElement {
-
- @Override
- public Set<LoggableElement> getChildren() {
- return new HashSet<LoggableElement>();
- }
-
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Library.java (from rev 49, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/Library.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Library.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Library.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,28 @@
+package fr.cemagref.simexplorer.is.storage.entities;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import fr.cemagref.simexplorer.is.storage.attachment.type.ContentType;
+import fr.cemagref.simexplorer.is.storage.attachment.type.ContentTypeFactory;
+import fr.cemagref.simexplorer.is.storage.attachment.type.RawType;
+
+public class Library extends LoggableElement {
+
+ @Override
+ public Set<LoggableElement> getChildren() {
+ Set<LoggableElement> elements = new HashSet<LoggableElement>();
+ return elements;
+ }
+
+ @Override
+ public Map<String, ContentType> getContentTypes() throws Exception {
+ Map<String, ContentType> contentTypes = new HashMap<String, ContentType>();
+ contentTypes.put("library", ContentTypeFactory
+ .getContentTypeInstance(RawType.class));
+ return contentTypes;
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/LoggableElement.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/LoggableElement.java 2007-12-03 17:37:30 UTC (rev 31)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/LoggableElement.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,117 +0,0 @@
-package org.cemagref.simexplorer.si.storage.entities;
-
-import java.util.Date;
-import java.util.Set;
-
-import org.apache.lucene.document.Document;
-
-public abstract class LoggableElement implements Entity {
-
- private String uuid;
- private String name;
- private String type;
- private String description;
- private Integer majorVersion;
- private Integer minorVersion;
- private Date creationDate;
- private String hash;
- private Set<Descriptor> descriptors;
- private LoggableElement parent;
- private Set<LoggableElement> children;
-
- public String getUuid() {
- return uuid;
- }
-
- public void setUuid(String uuid) {
- this.uuid = uuid;
- }
-
- 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;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public Integer getMajorVersion() {
- return majorVersion;
- }
-
- public void setMajorVersion(Integer majorVersion) {
- this.majorVersion = majorVersion;
- }
-
- public Integer getMinorVersion() {
- return minorVersion;
- }
-
- public void setMinorVersion(Integer minorVersion) {
- this.minorVersion = minorVersion;
- }
-
- public Date getCreationDate() {
- return creationDate;
- }
-
- public void setCreationDate(Date creationDate) {
- this.creationDate = creationDate;
- }
-
- public String getHash() {
- return hash;
- }
-
- public void setHash(String hash) {
- this.hash = hash;
- }
-
- public Set<Descriptor> getDescriptors() {
- return descriptors;
- }
-
- public void setDescriptors(Set<Descriptor> descriptors) {
- this.descriptors = descriptors;
- }
-
- public LoggableElement getParent() {
- return parent;
- }
-
- public void setParent(LoggableElement parent) {
- this.parent = parent;
- }
-
- public Set<LoggableElement> getVersionChildren() {
- return children;
- }
-
- public void setVersionChildren(Set<LoggableElement> children) {
- this.children = children;
- }
-
- /**
- * Returns children list
- * Should not be null
- * @return Children list
- */
- public abstract Set<LoggableElement> getChildren();
-
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/LoggableElement.java (from rev 49, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/LoggableElement.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/LoggableElement.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/LoggableElement.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,98 @@
+package fr.cemagref.simexplorer.is.storage.entities;
+
+import java.util.Date;
+import java.util.Set;
+
+public abstract class LoggableElement extends FileEntity {
+
+ private String uuid;
+ private String name;
+ private String type;
+ private String description;
+ private Version version;
+ private Date creationDate;
+ private String hash;
+ private Set<Descriptor> descriptors;
+
+ /*
+ * private LoggableElement parent; private Set<LoggableElement> children;
+ */
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ 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;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Version getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = new Version(version);
+ }
+
+ public Date getCreationDate() {
+ return creationDate;
+ }
+
+ public void setCreationDate(Date creationDate) {
+ this.creationDate = creationDate;
+ }
+
+ public String getHash() {
+ return hash;
+ }
+
+ public void setHash(String hash) {
+ this.hash = hash;
+ }
+
+ public Set<Descriptor> getDescriptors() {
+ return descriptors;
+ }
+
+ public void setDescriptors(Set<Descriptor> descriptors) {
+ this.descriptors = descriptors;
+ }
+
+ public abstract Set<LoggableElement> getChildren();
+
+ /*
+ * public LoggableElement getParent() { return parent; }
+ *
+ * public void setParent(LoggableElement parent) { this.parent = parent; }
+ *
+ * public Set<LoggableElement> getVersionChildren() { return children; }
+ *
+ * public void setVersionChildren(Set<LoggableElement> children) {
+ * this.children = children; }
+ */
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Repository.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/Repository.java 2007-12-03 17:37:30 UTC (rev 31)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Repository.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,5 +0,0 @@
-package org.cemagref.simexplorer.si.storage.entities;
-
-public class Repository implements Entity {
-
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Repository.java (from rev 49, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/Repository.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Repository.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Repository.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,5 @@
+package fr.cemagref.simexplorer.is.storage.entities;
+
+public class Repository extends Entity {
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Result.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/Result.java 2007-12-03 17:37:30 UTC (rev 31)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Result.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,5 +0,0 @@
-package org.cemagref.simexplorer.si.storage.entities;
-
-public class Result implements Entity {
-
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Result.java (from rev 49, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/Result.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Result.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Result.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,20 @@
+package fr.cemagref.simexplorer.is.storage.entities;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import fr.cemagref.simexplorer.is.storage.attachment.type.ContentType;
+import fr.cemagref.simexplorer.is.storage.attachment.type.ContentTypeFactory;
+import fr.cemagref.simexplorer.is.storage.attachment.type.RawType;
+
+public class Result extends FileEntity {
+
+ @Override
+ public Map<String, ContentType> getContentTypes() throws Exception {
+ Map<String, ContentType> contentTypes = new HashMap<String, ContentType>();
+ contentTypes.put("result", ContentTypeFactory
+ .getContentTypeInstance(RawType.class));
+ return contentTypes;
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Structure.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/Structure.java 2007-12-03 17:37:30 UTC (rev 31)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Structure.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,5 +0,0 @@
-package org.cemagref.simexplorer.si.storage.entities;
-
-public interface Structure extends Entity {
-
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Structure.java (from rev 49, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/Structure.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Structure.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Structure.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,5 @@
+package fr.cemagref.simexplorer.is.storage.entities;
+
+public abstract class Structure extends Entity {
+
+}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Version.java (from rev 49, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/entities/Version.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Version.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/Version.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,86 @@
+package fr.cemagref.simexplorer.is.storage.entities;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+public class Version implements Comparable<Version> {
+
+ private List<Integer> pointedVersion;
+
+ public Version(String version) {
+ super();
+ pointedVersion = new ArrayList<Integer>();
+ StringTokenizer st = new StringTokenizer(version, ".");
+ while (st.hasMoreTokens()) {
+ pointedVersion.add(new Integer(st.nextToken()));
+ }
+ }
+
+ public Integer getVersion(int position) {
+ if (position < pointedVersion.size()) {
+ return pointedVersion.get(position);
+ } else {
+ return null;
+ }
+ }
+
+ public void setVersion(int position, int subVersion) {
+ while (getVersion(position) == null) {
+ addSubVersion(0);
+ }
+ pointedVersion.set(position, subVersion);
+ }
+
+ public void addSubVersion(int subVersion) {
+ pointedVersion.add(subVersion);
+ }
+
+ public Version incVersion(int position) {
+ Version result = new Version(toString());
+ while (result.getVersion(position) == null) {
+ result.addSubVersion(0);
+ }
+ result.setVersion(position, result.getVersion(position) + 1);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer result = new StringBuffer("");
+ for (Integer i : pointedVersion) {
+ result.append(i).append(".");
+ }
+ result.setLength(result.length() - 1);
+ return result.toString();
+ }
+
+ public int compareTo(Version v) {
+ int result = 0;
+ int position = 0;
+ boolean compared = false;
+ while (!compared) {
+ if (getVersion(position) == null && v.getVersion(position) == null) {
+ result = 0;
+ compared = true;
+ } else {
+ if (getVersion(position) == null) {
+ result = -1;
+ compared = true;
+ } else {
+ if (v.getVersion(position) == null) {
+ result = 1;
+ compared = true;
+ } else {
+ result = getVersion(position).compareTo(
+ v.getVersion(position));
+ compared = (result != 0);
+ }
+ }
+ }
+ position++;
+ }
+ return result;
+ }
+
+}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories (from rev 39, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories)
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/CodeFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/CodeFactory.java 2007-12-05 15:22:53 UTC (rev 39)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/CodeFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,32 +1,33 @@
-package org.cemagref.simexplorer.si.storage.factories;
+package fr.cemagref.simexplorer.is.storage.factories;
-import org.cemagref.simexplorer.si.storage.entities.Code;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import fr.cemagref.simexplorer.is.storage.entities.Code;
+
public class CodeFactory<E extends Code> extends EntityFactory<Code> {
- public static final String KEY_LANGUAGE = "language";
- public static final String KEY_CODE = "code";
-
- @Override
- public Code createInstance() {
- return new Code();
- }
+ public static final String KEY_LANGUAGE = "language";
+ public static final String KEY_CODE = "code";
- @Override
- public Code loadXMLElement(Element xmlElement) throws Exception {
- Code code = super.loadXMLElement(xmlElement);
- code.setLanguage(getProperty(xmlElement, KEY_LANGUAGE));
- code.setCode(getProperty(xmlElement, KEY_CODE));
- return code;
- }
-
- @Override
- public void saveXMLElement(Document document, Element xmlElement,
- Code element) throws Exception {
- setProperty(document, xmlElement, KEY_LANGUAGE, element.getLanguage());
- setProperty(document, xmlElement, KEY_CODE, element.getCode());
- }
+ @Override
+ public Code createInstance() {
+ return new Code();
+ }
+ @Override
+ public Code loadXMLElement(Element xmlElement) throws Exception {
+ Code code = super.loadXMLElement(xmlElement);
+ code.setLanguage(getProperty(xmlElement, KEY_LANGUAGE));
+ code.setCode(getProperty(xmlElement, KEY_CODE));
+ return code;
+ }
+
+ @Override
+ public void saveXMLElement(Document document, Element xmlElement,
+ Code element) throws Exception {
+ setProperty(document, xmlElement, KEY_LANGUAGE, element.getLanguage());
+ setProperty(document, xmlElement, KEY_CODE, element.getCode());
+ }
+
}
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ComponentFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/ComponentFactory.java 2007-12-05 15:22:53 UTC (rev 39)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ComponentFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,58 +1,59 @@
-package org.cemagref.simexplorer.si.storage.factories;
+package fr.cemagref.simexplorer.is.storage.factories;
-import org.cemagref.simexplorer.si.storage.entities.Code;
-import org.cemagref.simexplorer.si.storage.entities.Component;
-import org.cemagref.simexplorer.si.storage.entities.Constant;
-import org.cemagref.simexplorer.si.storage.entities.Library;
-import org.cemagref.simexplorer.si.storage.entities.Structure;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import fr.cemagref.simexplorer.is.storage.entities.Code;
+import fr.cemagref.simexplorer.is.storage.entities.Component;
+import fr.cemagref.simexplorer.is.storage.entities.Constant;
+import fr.cemagref.simexplorer.is.storage.entities.Library;
+import fr.cemagref.simexplorer.is.storage.entities.Structure;
+
public class ComponentFactory<E extends Component> extends
- LoggableElementFactory<Component> {
+ LoggableElementFactory<Component> {
- public static final String KEY_CONSTANTS = "constants";
- public static final String KEY_CONSTANT_NODE = "constant";
- public static final String KEY_STRUCTURE = "structures";
- public static final String KEY_STRUCTURE_NODE = "structure";
- public static final String KEY_CODES = "codes";
- public static final String KEY_CODE_NODE = "code";
- public static final String KEY_LIBRARIES = "libraries";
- public static final String KEY_LIBRARY_NODE = "library";
+ public static final String KEY_CONSTANTS = "constants";
+ public static final String KEY_CONSTANT_NODE = "constant";
+ public static final String KEY_STRUCTURE = "structures";
+ public static final String KEY_STRUCTURE_NODE = "structure";
+ public static final String KEY_CODES = "codes";
+ public static final String KEY_CODE_NODE = "code";
+ public static final String KEY_LIBRARIES = "libraries";
+ public static final String KEY_LIBRARY_NODE = "library";
- @Override
- public Component createInstance() {
- return new Component();
- }
+ @Override
+ public Component createInstance() {
+ return new Component();
+ }
- @Override
- public Component loadXMLElement(Element xmlElement) throws Exception {
- Component component = super.loadXMLElement(xmlElement);
+ @Override
+ public Component loadXMLElement(Element xmlElement) throws Exception {
+ Component component = super.loadXMLElement(xmlElement);
- component.setConstants(loadCollection(KEY_CONSTANTS, KEY_CONSTANT_NODE,
- Constant.class, xmlElement));
- component.setStructures(loadCollection(KEY_STRUCTURE,
- KEY_STRUCTURE_NODE, Structure.class, xmlElement));
- component.setCodes(loadCollection(KEY_CODES, KEY_CODE_NODE, Code.class,
- xmlElement));
- component.setLibraries(loadCollection(KEY_LIBRARIES, KEY_LIBRARY_NODE,
- Library.class, xmlElement));
+ component.setConstants(loadCollection(KEY_CONSTANTS, KEY_CONSTANT_NODE,
+ Constant.class, xmlElement));
+ component.setStructures(loadCollection(KEY_STRUCTURE,
+ KEY_STRUCTURE_NODE, Structure.class, xmlElement));
+ component.setCodes(loadCollection(KEY_CODES, KEY_CODE_NODE, Code.class,
+ xmlElement));
+ component.setLibraries(loadCollection(KEY_LIBRARIES, KEY_LIBRARY_NODE,
+ Library.class, xmlElement));
- return component;
- }
+ return component;
+ }
- @Override
- public void saveXMLElement(Document document, Element xmlElement,
- Component element) throws Exception {
- saveCollection(element.getConstants(), KEY_CONSTANTS,
- KEY_CONSTANT_NODE, Constant.class, document, xmlElement);
- saveCollection(element.getStructures(), KEY_STRUCTURE,
- KEY_STRUCTURE_NODE, Structure.class, document, xmlElement);
- saveCollection(element.getCodes(), KEY_CODES, KEY_CODE_NODE,
- Code.class, document, xmlElement);
- saveCollection(element.getLibraries(), KEY_LIBRARIES, KEY_LIBRARY_NODE,
- Library.class, document, xmlElement);
- super.saveXMLElement(document, xmlElement, element);
- }
+ @Override
+ public void saveXMLElement(Document document, Element xmlElement,
+ Component element) throws Exception {
+ saveCollection(element.getConstants(), KEY_CONSTANTS,
+ KEY_CONSTANT_NODE, Constant.class, document, xmlElement);
+ saveCollection(element.getStructures(), KEY_STRUCTURE,
+ KEY_STRUCTURE_NODE, Structure.class, document, xmlElement);
+ saveCollection(element.getCodes(), KEY_CODES, KEY_CODE_NODE,
+ Code.class, document, xmlElement);
+ saveCollection(element.getLibraries(), KEY_LIBRARIES, KEY_LIBRARY_NODE,
+ Library.class, document, xmlElement);
+ super.saveXMLElement(document, xmlElement, element);
+ }
}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/ConstantFactory.java 2007-12-05 15:22:53 UTC (rev 39)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,32 +0,0 @@
-package org.cemagref.simexplorer.si.storage.factories;
-
-import org.cemagref.simexplorer.si.storage.entities.Constant;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-public class ConstantFactory<E extends Constant> extends EntityFactory<Constant> {
-
- public static final String KEY_NAME = "name";
- public static final String KEY_TYPE = "type";
-
- @Override
- public Constant createInstance() {
- return new Constant();
- }
-
- @Override
- public Constant loadXMLElement(Element xmlElement) throws Exception {
- Constant constant = super.loadXMLElement(xmlElement);
- constant.setName(getProperty(xmlElement, KEY_NAME));
- constant.setType(Class.forName(getProperty(xmlElement, KEY_TYPE)));
- return constant;
- }
-
- @Override
- public void saveXMLElement(Document document, Element xmlElement,
- Constant element) throws Exception {
- setProperty(document, xmlElement, KEY_NAME, element.getName());
- setProperty(document, xmlElement, KEY_TYPE, element.getClass().getName());
- }
-
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantFactory.java (from rev 47, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/ConstantFactory.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantFactory.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,36 @@
+package fr.cemagref.simexplorer.is.storage.factories;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import fr.cemagref.simexplorer.is.storage.entities.Constant;
+
+public class ConstantFactory<E extends Constant> extends
+ EntityFactory<Constant> {
+
+ public static final String KEY_NAME = "name";
+ public static final String KEY_TYPE = "type";
+
+ @Override
+ public Constant createInstance() {
+ return new Constant();
+ }
+
+ @Override
+ public Constant loadXMLElement(Element xmlElement) throws Exception {
+ Constant constant = super.loadXMLElement(xmlElement);
+ constant.setName(getProperty(xmlElement, KEY_NAME));
+ String className = getProperty(xmlElement, KEY_TYPE);
+ constant.setType(Class.forName(className));
+ return constant;
+ }
+
+ @Override
+ public void saveXMLElement(Document document, Element xmlElement,
+ Constant element) throws Exception {
+ setProperty(document, xmlElement, KEY_NAME, element.getName());
+ String className = element.getType().getName();
+ setProperty(document, xmlElement, KEY_TYPE, className);
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantValueFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/ConstantValueFactory.java 2007-12-05 15:22:53 UTC (rev 39)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantValueFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,40 +0,0 @@
-package org.cemagref.simexplorer.si.storage.factories;
-
-import org.cemagref.simexplorer.si.storage.entities.Constant;
-import org.cemagref.simexplorer.si.storage.entities.ConstantValue;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Text;
-
-public class ConstantValueFactory<E extends ConstantValue> extends EntityFactory<ConstantValue> {
-
- public static final String KEY_CONSTANT = "constant";
- public static final String KEY_VALUE = "value";
-
- @Override
- public ConstantValue createInstance() {
- return new ConstantValue();
- }
-
- @Override
- public ConstantValue loadXMLElement(Element xmlElement) throws Exception {
- ConstantValue constantValue = super.loadXMLElement(xmlElement);
- constantValue.setConstant((Constant) getFactory(Constant.class).loadXMLElement(getElementByTagName(xmlElement, KEY_CONSTANT)));
- constantValue.setValue(getProperty(xmlElement, KEY_VALUE));
- return constantValue;
- }
-
- @Override
- public void saveXMLElement(Document document, Element xmlElement,
- ConstantValue element) throws Exception {
-
- Element xmlConstant = document.createElement(KEY_CONSTANT);
- getFactory(Constant.class).saveXMLElement(document, xmlElement, element.getConstant());
- xmlElement.appendChild(xmlConstant);
-
- setProperty(document, xmlElement, KEY_VALUE, element.getValue());
- }
-
-
-
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantValueFactory.java (from rev 47, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/ConstantValueFactory.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantValueFactory.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantValueFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,41 @@
+package fr.cemagref.simexplorer.is.storage.factories;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import fr.cemagref.simexplorer.is.storage.entities.Constant;
+import fr.cemagref.simexplorer.is.storage.entities.ConstantValue;
+
+public class ConstantValueFactory<E extends ConstantValue> extends
+ EntityFactory<ConstantValue> {
+
+ public static final String KEY_CONSTANT = "constant";
+ public static final String KEY_VALUE = "value";
+
+ @Override
+ public ConstantValue createInstance() {
+ return new ConstantValue();
+ }
+
+ @Override
+ public ConstantValue loadXMLElement(Element xmlElement) throws Exception {
+ ConstantValue constantValue = super.loadXMLElement(xmlElement);
+ constantValue.setConstant((Constant) getFactory(Constant.class)
+ .loadXMLElement(getElementByTagName(xmlElement, KEY_CONSTANT)));
+ constantValue.setValue(getProperty(xmlElement, KEY_VALUE));
+ return constantValue;
+ }
+
+ @Override
+ public void saveXMLElement(Document document, Element xmlElement,
+ ConstantValue element) throws Exception {
+
+ Element xmlConstant = document.createElement(KEY_CONSTANT);
+ getFactory(Constant.class).saveXMLElement(document, xmlConstant,
+ element.getConstant());
+ xmlElement.appendChild(xmlConstant);
+
+ setProperty(document, xmlElement, KEY_VALUE, element.getValue());
+ }
+
+}
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/DescriptorFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/DescriptorFactory.java 2007-12-05 15:22:53 UTC (rev 39)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/DescriptorFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,28 +1,30 @@
-package org.cemagref.simexplorer.si.storage.factories;
+package fr.cemagref.simexplorer.is.storage.factories;
-import org.cemagref.simexplorer.si.storage.entities.Descriptor;
import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-public class DescriptorFactory<E extends Descriptor> extends EntityFactory<Descriptor> {
+import fr.cemagref.simexplorer.is.storage.entities.Descriptor;
- public static final String KEY_NAME = "name";
- public static final String KEY_VALUE = "value";
-
- public Descriptor createInstance() {
- return new Descriptor();
- }
+public class DescriptorFactory<E extends Descriptor> extends
+ EntityFactory<Descriptor> {
- public Descriptor loadXMLElement(Element xmlElement) throws Exception {
- Descriptor descriptor = super.loadXMLElement(xmlElement);
- descriptor.setName(xmlElement.getAttribute(KEY_NAME));
- descriptor.setValue(xmlElement.getAttribute(KEY_VALUE));
- return descriptor;
- }
+ public static final String KEY_NAME = "name";
+ public static final String KEY_VALUE = "value";
- public void saveXMLElement(org.w3c.dom.Document document, Element xmlElement, Descriptor element) throws Exception {
- xmlElement.setAttribute(KEY_NAME, element.getName());
- xmlElement.setAttribute(KEY_VALUE, element.getValue());
- }
+ public Descriptor createInstance() {
+ return new Descriptor();
+ }
+ public Descriptor loadXMLElement(Element xmlElement) throws Exception {
+ Descriptor descriptor = super.loadXMLElement(xmlElement);
+ descriptor.setName(xmlElement.getAttribute(KEY_NAME));
+ descriptor.setValue(xmlElement.getAttribute(KEY_VALUE));
+ return descriptor;
+ }
+
+ public void saveXMLElement(org.w3c.dom.Document document,
+ Element xmlElement, Descriptor element) throws Exception {
+ xmlElement.setAttribute(KEY_NAME, element.getName());
+ xmlElement.setAttribute(KEY_VALUE, element.getValue());
+ }
+
}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/EntityFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/EntityFactory.java 2007-12-05 15:22:53 UTC (rev 39)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/EntityFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,146 +0,0 @@
-package org.cemagref.simexplorer.si.storage.factories;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
-
-import org.cemagref.simexplorer.si.storage.entities.Entity;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
-
-public abstract class EntityFactory<E extends Entity> {
-
- private final static String PACKAGE_DAO = "org.cemagref.simexplorer.si.storage.factories";
-
- private static Map<String, EntityFactory> factories = new HashMap<String, EntityFactory>();
-
- public static EntityFactory getFactory(String entityClassName)
- throws Exception {
- EntityFactory entityFactory = factories.get(entityClassName);
- if (entityFactory == null) {
-
- StringTokenizer st = new StringTokenizer(entityClassName, ".");
- String simpleClassName = null;
- while (st.hasMoreTokens()) {
- simpleClassName = st.nextToken();
- }
-
- String elementFactoryClassName = simpleClassName + "Factory";
-
- Class elementFactoryClass = Class.forName(PACKAGE_DAO + "."
- + elementFactoryClassName);
-
- entityFactory = (EntityFactory) elementFactoryClass.newInstance();
- factories.put(entityClassName, entityFactory);
- }
-
- return entityFactory;
- }
-
- /**
- * @param entityClass
- * @return
- * @throws Throwable
- */
- public static EntityFactory getFactory(Class entityClass) throws Exception {
- return getFactory(entityClass.getName());
- }
-
- public abstract E createInstance();
-
- public E loadXMLElement(Element xmlElement) throws Exception {
- E element = createInstance();
- return element;
- }
-
- protected Set<Element> getElementsByTagName(Element xmlElement,
- String tagName) {
- Set<Element> elements = new HashSet<Element>();
-
- NodeList nodes = xmlElement.getChildNodes();
- for (int i = 0; i < nodes.getLength(); i++) {
- Node node = nodes.item(i);
- if (node instanceof Element
- && tagName.equals(((Element) node).getTagName())) {
- elements.add((Element) node);
- }
- }
- return elements;
- }
-
- protected Element getElementByTagName(Element xmlElement, String tagName) {
- Set<Element> elements = getElementsByTagName(xmlElement, tagName);
- if (elements.size() > 0) {
- return elements.iterator().next();
- } else {
- return null;
- }
- }
-
- protected void setProperty(Document document, Element xmlElement,
- String tagName, Object value) {
- if (value != null) {
- Element xmlProperty = document.createElement(tagName);
- Text xmlDescriptionText = document.createTextNode(value.toString());
- xmlProperty.appendChild(xmlDescriptionText);
- xmlElement.appendChild(xmlProperty);
- }
- }
-
- protected String getProperty(Element xmlElement, String tagName) {
- Element element = getElementByTagName(xmlElement, tagName);
- if (element != null) {
- return element.getFirstChild().getNodeValue();
- } else {
- return null;
- }
- }
-
- public abstract void saveXMLElement(Document document, Element xmlElement,
- E element) throws Exception;
-
- public Set loadCollection(String tagSetName, String tagName, Class clazz,
- Element xmlElement) throws Exception {
- Set entities = new HashSet();
-
- Element xmlCollection = getElementByTagName(xmlElement, tagSetName);
- if (xmlCollection != null) {
- EntityFactory elementFactory = getFactory(clazz);
-
- Set<Element> list = getElementsByTagName(xmlCollection, tagName);
- for (Iterator iterator = list.iterator(); iterator.hasNext();) {
- Element element = (Element) iterator.next();
- Entity entity = elementFactory.loadXMLElement(element);
- entities.add(entity);
- }
- }
-
- return entities;
- }
-
- public void saveCollection(Set entities, String tagSetName, String tagName,
- Class clazz, Document document, Element xmlElement)
- throws Exception {
- if (entities != null && entities.size() > 0) {
- Element xmlCollection = document.createElement(tagSetName);
- EntityFactory elementFactory = getFactory(clazz);
- for (Object entity : entities) {
- Element childElement = document.createElement(tagName);
- // TODO
- // if (entity instanceof LoggableElement) {
- // elementFactory.saveXMLElementByReference
- elementFactory.saveXMLElement(document, childElement,
- (Entity) entity);
- xmlCollection.appendChild(childElement);
- }
- xmlElement.appendChild(xmlCollection);
- }
- }
-
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/EntityFactory.java (from rev 49, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/EntityFactory.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/EntityFactory.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/EntityFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,183 @@
+package fr.cemagref.simexplorer.is.storage.factories;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+import fr.cemagref.simexplorer.is.storage.entities.Entity;
+
+public abstract class EntityFactory<E extends Entity> {
+
+ private final static String PACKAGE_DAO = "fr.cemagref.simexplorer.is.storage.factories";
+
+ private static Map<String, EntityFactory<? extends Entity>> factories = new HashMap<String, EntityFactory<? extends Entity>>();
+
+ private static DocumentBuilder documentBuilder = null;
+
+ public static synchronized DocumentBuilder getBuilder() throws Exception {
+ if (documentBuilder == null) {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ documentBuilder = factory.newDocumentBuilder();
+ return documentBuilder;
+ }
+ return documentBuilder;
+ }
+
+ public static EntityFactory<? extends Entity> getFactory(
+ String entityClassName) throws Exception {
+ Class<? extends Entity> entityClass = Class.forName(entityClassName)
+ .asSubclass(Entity.class);
+ return getFactory(entityClass);
+ }
+
+ // @SuppressWarnings("unchecked")
+ public static <T extends Entity> EntityFactory<T> getFactory(
+ Class<T> entityClass) throws Exception {
+ // FIXME Raw types and unchecked casts
+ EntityFactory<T> result = (EntityFactory<T>) factories.get(entityClass
+ .getSimpleName());
+ if (result == null) {
+ String elementFactoryClassName = PACKAGE_DAO + "."
+ + entityClass.getSimpleName() + "Factory";
+
+ Class<? extends EntityFactory<T>> factoryClass = (Class<? extends EntityFactory<T>>) Class
+ .forName(elementFactoryClassName).asSubclass(
+ EntityFactory.class);
+
+ result = factoryClass.newInstance();
+ factories.put(entityClass.getSimpleName(), result);
+ }
+ return result;
+ }
+
+ public abstract E createInstance();
+
+ public E loadXMLElement(Element xmlElement) throws Exception {
+ E element = createInstance();
+ return element;
+ }
+
+ protected Set<Element> getElementsByTagName(Element xmlElement,
+ String tagName) {
+ Set<Element> elements = new HashSet<Element>();
+
+ NodeList nodes = xmlElement.getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Node node = nodes.item(i);
+ if (node instanceof Element
+ && tagName.equals(((Element) node).getTagName())) {
+ elements.add((Element) node);
+ }
+ }
+ return elements;
+ }
+
+ protected Element getElementByTagName(Element xmlElement, String tagName) {
+ Set<Element> elements = getElementsByTagName(xmlElement, tagName);
+ if (elements.size() > 0) {
+ return elements.iterator().next();
+ } else {
+ return null;
+ }
+ }
+
+ protected void setProperty(Document document, Element xmlElement,
+ String tagName, Object value) {
+ if (value != null) {
+ Element xmlProperty = document.createElement(tagName);
+ Text xmlDescriptionText = document.createTextNode(value.toString());
+ xmlProperty.appendChild(xmlDescriptionText);
+ xmlElement.appendChild(xmlProperty);
+ }
+ }
+
+ protected String getProperty(Element xmlElement, String tagName) {
+ Element element = getElementByTagName(xmlElement, tagName);
+ if (element != null) {
+ return element.getFirstChild().getNodeValue();
+ } else {
+ return null;
+ }
+ }
+
+ public abstract void saveXMLElement(Document document, Element xmlElement,
+ E element) throws Exception;
+
+ public void getElementXML(E element, OutputStream os) throws Exception {
+ org.w3c.dom.Document xmlDocument = getBuilder().newDocument();
+ // Propriétés du DOM
+ xmlDocument.setXmlVersion("1.0");
+ xmlDocument.setXmlStandalone(true);
+ // Création de l'arborescence du DOM
+ Element racine = xmlDocument.createElement(element.getClass()
+ .getSimpleName());
+ saveXMLElement(xmlDocument, racine, element);
+ xmlDocument.appendChild(racine);
+ DOMSource domSource = new DOMSource(xmlDocument);
+ StreamResult result = new StreamResult(os);
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer transformer = tf.newTransformer();
+ transformer.transform(domSource, result);
+ }
+
+ public String getElementXML(E element) throws Exception {
+ ByteArrayOutputStream writer = new ByteArrayOutputStream();
+ getElementXML(element, writer);
+ return writer.toString();
+ }
+
+ public <T extends Entity> Set<T> loadCollection(String tagSetName,
+ String tagName, Class<T> clazz, Element xmlElement)
+ throws Exception {
+ Set<T> entities = new HashSet<T>();
+
+ Element xmlCollection = getElementByTagName(xmlElement, tagSetName);
+ if (xmlCollection != null) {
+ EntityFactory<T> elementFactory = getFactory(clazz);
+
+ Set<Element> list = getElementsByTagName(xmlCollection, tagName);
+ for (Element element : list) {
+ T entity = elementFactory.loadXMLElement(element);
+ entities.add(entity);
+ }
+ }
+
+ return entities;
+ }
+
+ public <T extends Entity> void saveCollection(Set<T> entities,
+ String tagSetName, String tagName, Class<T> clazz,
+ Document document, Element xmlElement) throws Exception {
+ if (entities != null && entities.size() > 0) {
+ Element xmlCollection = document.createElement(tagSetName);
+ EntityFactory<T> elementFactory = getFactory(clazz);
+ for (T entity : entities) {
+ Element childElement = document.createElement(tagName);
+ // TODO
+ // if (entity instanceof LoggableElement) {
+ // elementFactory.saveXMLElementByReference
+ elementFactory.saveXMLElement(document, childElement, entity);
+ xmlCollection.appendChild(childElement);
+ }
+ xmlElement.appendChild(xmlCollection);
+ }
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationApplicationFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/ExplorationApplicationFactory.java 2007-12-05 15:22:53 UTC (rev 39)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationApplicationFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,44 +0,0 @@
-package org.cemagref.simexplorer.si.storage.factories;
-
-import org.cemagref.simexplorer.si.storage.entities.Component;
-import org.cemagref.simexplorer.si.storage.entities.ExplorationApplication;
-import org.cemagref.simexplorer.si.storage.entities.ExplorationData;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-public class ExplorationApplicationFactory extends
- LoggableElementFactory<ExplorationApplication> {
-
- public static final String KEY_DATA = "data";
- public static final String KEY_DATA_NODE = "explorationdata";
- public static final String KEY_COMPONENTS = "components";
- public static final String KEY_COMPONENT_NODE = "component";
-
- @Override
- public void saveXMLElement(Document document, Element xmlElement,
- ExplorationApplication element) throws Exception {
- super.saveXMLElement(document, xmlElement, element);
- saveCollection(element.getExplorations(), KEY_DATA, KEY_DATA_NODE,
- ExplorationData.class.getClass(), document, xmlElement);
- saveCollection(element.getComponents(), KEY_COMPONENTS,
- KEY_COMPONENT_NODE, Component.class.getClass(), document,
- xmlElement);
- }
-
- @Override
- public ExplorationApplication loadXMLElement(Element xmlElement)
- throws Exception {
- ExplorationApplication explorationApplication = super
- .loadXMLElement(xmlElement);
- explorationApplication.setExplorations(loadCollection(KEY_DATA,
- KEY_DATA_NODE, ExplorationData.class.getClass(), xmlElement));
- explorationApplication.setComponents(loadCollection(KEY_COMPONENTS,
- KEY_COMPONENT_NODE, Component.class.getClass(), xmlElement));
- return explorationApplication;
- }
-
- public ExplorationApplication createInstance() {
- return new ExplorationApplication();
- }
-
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationApplicationFactory.java (from rev 47, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/ExplorationApplicationFactory.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationApplicationFactory.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationApplicationFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,44 @@
+package fr.cemagref.simexplorer.is.storage.factories;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import fr.cemagref.simexplorer.is.storage.entities.Component;
+import fr.cemagref.simexplorer.is.storage.entities.ExplorationApplication;
+import fr.cemagref.simexplorer.is.storage.entities.ExplorationData;
+
+public class ExplorationApplicationFactory extends
+ LoggableElementFactory<ExplorationApplication> {
+
+ public static final String KEY_DATA = "data";
+ public static final String KEY_DATA_NODE = "explorationdata";
+ public static final String KEY_COMPONENTS = "components";
+ public static final String KEY_COMPONENT_NODE = "component";
+
+ @Override
+ public void saveXMLElement(Document document, Element xmlElement,
+ ExplorationApplication element) throws Exception {
+ super.saveXMLElement(document, xmlElement, element);
+ saveCollection(element.getExplorations(), KEY_DATA, KEY_DATA_NODE,
+ ExplorationData.class, document, xmlElement);
+ saveCollection(element.getComponents(), KEY_COMPONENTS,
+ KEY_COMPONENT_NODE, Component.class, document, xmlElement);
+ }
+
+ @Override
+ public ExplorationApplication loadXMLElement(Element xmlElement)
+ throws Exception {
+ ExplorationApplication explorationApplication = super
+ .loadXMLElement(xmlElement);
+ explorationApplication.setExplorations(loadCollection(KEY_DATA,
+ KEY_DATA_NODE, ExplorationData.class, xmlElement));
+ explorationApplication.setComponents(loadCollection(KEY_COMPONENTS,
+ KEY_COMPONENT_NODE, Component.class, xmlElement));
+ return explorationApplication;
+ }
+
+ public ExplorationApplication createInstance() {
+ return new ExplorationApplication();
+ }
+
+}
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationDataFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/ExplorationDataFactory.java 2007-12-05 15:22:53 UTC (rev 39)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationDataFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,44 +1,47 @@
-package org.cemagref.simexplorer.si.storage.factories;
+package fr.cemagref.simexplorer.is.storage.factories;
-import org.cemagref.simexplorer.si.storage.entities.Constant;
-import org.cemagref.simexplorer.si.storage.entities.ConstantValue;
-import org.cemagref.simexplorer.si.storage.entities.ExplorationData;
-import org.cemagref.simexplorer.si.storage.entities.Result;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import fr.cemagref.simexplorer.is.storage.entities.ConstantValue;
+import fr.cemagref.simexplorer.is.storage.entities.ExplorationData;
+import fr.cemagref.simexplorer.is.storage.entities.Result;
+
public class ExplorationDataFactory extends
- LoggableElementFactory<ExplorationData> {
+ LoggableElementFactory<ExplorationData> {
- public static final String KEY_RESULT = "result";
- public static final String KEY_VALUES = "values";
- public static final String KEY_VALUE = "value";
-
- @Override
- public ExplorationData loadXMLElement(Element xmlElement) throws Exception {
- ExplorationData explorationData = super.loadXMLElement(xmlElement);
- explorationData.setResult((Result) getFactory(Result.class).loadXMLElement(
- getElementByTagName(xmlElement, KEY_RESULT)));
- explorationData.setValuesMap(loadCollection(KEY_VALUES, KEY_VALUE, ConstantValue.class, xmlElement));
- return explorationData;
- }
+ public static final String KEY_RESULT = "result";
+ public static final String KEY_VALUES = "values";
+ public static final String KEY_VALUE = "value";
- @Override
- public void saveXMLElement(Document document, Element xmlElement,
- ExplorationData element) throws Exception {
- super.saveXMLElement(document, xmlElement, element);
-
- Element xmlResult = document.createElement(KEY_RESULT);
- getFactory(Result.class).saveXMLElement(document, xmlResult, element.getResult());
- xmlElement.appendChild(xmlResult);
-
- saveCollection(element.getValuesMap(), KEY_VALUES, KEY_VALUE, ConstantValue.class, document, xmlElement);
-
- }
+ @Override
+ public ExplorationData loadXMLElement(Element xmlElement) throws Exception {
+ ExplorationData explorationData = super.loadXMLElement(xmlElement);
+ explorationData.setResult((Result) getFactory(Result.class)
+ .loadXMLElement(getElementByTagName(xmlElement, KEY_RESULT)));
+ explorationData.setValuesMap(loadCollection(KEY_VALUES, KEY_VALUE,
+ ConstantValue.class, xmlElement));
+ return explorationData;
+ }
- @Override
- public ExplorationData createInstance() {
- return new ExplorationData();
- }
+ @Override
+ public void saveXMLElement(Document document, Element xmlElement,
+ ExplorationData element) throws Exception {
+ super.saveXMLElement(document, xmlElement, element);
+ Element xmlResult = document.createElement(KEY_RESULT);
+ getFactory(Result.class).saveXMLElement(document, xmlResult,
+ element.getResult());
+ xmlElement.appendChild(xmlResult);
+
+ saveCollection(element.getValuesMap(), KEY_VALUES, KEY_VALUE,
+ ConstantValue.class, document, xmlElement);
+
+ }
+
+ @Override
+ public ExplorationData createInstance() {
+ return new ExplorationData();
+ }
+
}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/FileEntityFactory.java (from rev 49, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/FileEntityFactory.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/FileEntityFactory.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/FileEntityFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,21 @@
+package fr.cemagref.simexplorer.is.storage.factories;
+
+import fr.cemagref.simexplorer.is.storage.attachment.AttachmentHandler;
+import fr.cemagref.simexplorer.is.storage.attachment.fs.FileSystemAttachmentHandler;
+import fr.cemagref.simexplorer.is.storage.database.DatabaseConstants;
+import fr.cemagref.simexplorer.is.storage.entities.FileEntity;
+
+public abstract class FileEntityFactory<E extends FileEntity> extends
+ EntityFactory<E> implements DatabaseConstants {
+
+ private static AttachmentHandler handler;
+ private static boolean handlerInit = false;
+
+ public static AttachmentHandler getHandler() {
+ if (!handlerInit) {
+ handler = new FileSystemAttachmentHandler();
+ }
+ return handler;
+ }
+
+}
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LibraryFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/LibraryFactory.java 2007-12-05 15:22:53 UTC (rev 39)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LibraryFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,12 +1,12 @@
-package org.cemagref.simexplorer.si.storage.factories;
+package fr.cemagref.simexplorer.is.storage.factories;
-import org.cemagref.simexplorer.si.storage.entities.Library;
+import fr.cemagref.simexplorer.is.storage.entities.Library;
public class LibraryFactory extends LoggableElementFactory<Library> {
- @Override
- public Library createInstance() {
- return new Library();
- }
+ @Override
+ public Library createInstance() {
+ return new Library();
+ }
}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LoggableElementFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/LoggableElementFactory.java 2007-12-05 15:22:53 UTC (rev 39)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LoggableElementFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,65 +0,0 @@
-package org.cemagref.simexplorer.si.storage.factories;
-
-import java.util.Date;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.cemagref.simexplorer.si.storage.database.DatabaseConstants;
-import org.cemagref.simexplorer.si.storage.entities.LoggableElement;
-import org.w3c.dom.Element;
-
-public abstract class LoggableElementFactory<E extends LoggableElement> extends
- EntityFactory<E> implements DatabaseConstants {
-
- private static final String KEY_DESCRIPTION = "description";
-
- private static DocumentBuilder documentBuilder = null;
-
- public static synchronized DocumentBuilder getBuilder() throws Exception {
- if (documentBuilder == null) {
- DocumentBuilderFactory factory = DocumentBuilderFactory
- .newInstance();
- documentBuilder = factory.newDocumentBuilder();
- return documentBuilder;
- }
- return documentBuilder;
- }
-
- @Override
- public E loadXMLElement(Element xmlElement) throws Exception {
- E element = super.loadXMLElement(xmlElement);
- element.setUuid(getProperty(xmlElement, KEY_UUID));
- element.setName(getProperty(xmlElement, KEY_NAME));
- element.setType(getProperty(xmlElement, KEY_TYPE));
- element.setDescription(getProperty(xmlElement, KEY_DESCRIPTION));
-
- // FIXME Convert
- /*
- element.setMajorVersion(new Integer(getProperty(xmlElement, KEY_MAJORVERSION)));
- element.setMinorVersion(new Integer(getProperty(xmlElement, KEY_MINORVERSION)));
- element.setCreationDate(new Date(getProperty(xmlElement, KEY_CREATIONDATE)));
- */
-
- element.setHash(getProperty(xmlElement, KEY_HASH));
- return element;
- }
-
- @Override
- public void saveXMLElement(org.w3c.dom.Document document,
- Element xmlElement, E element) throws Exception {
-
- setProperty(document, xmlElement, KEY_UUID, element.getUuid());
- setProperty(document, xmlElement, KEY_NAME, element.getName());
- setProperty(document, xmlElement, KEY_TYPE, element.getType());
- setProperty(document, xmlElement, KEY_DESCRIPTION, element.getDescription());
- /*
- setProperty(document, xmlElement, KEY_CREATIONDATE, element.getCreationDate());
- setProperty(document, xmlElement, KEY_MAJORVERSION, element.getMajorVersion());
- setProperty(document, xmlElement, KEY_MINORVERSION, element.getMinorVersion());
- */
- setProperty(document, xmlElement, KEY_HASH, element.getHash());
-
- }
-
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LoggableElementFactory.java (from rev 49, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/LoggableElementFactory.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LoggableElementFactory.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LoggableElementFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,50 @@
+package fr.cemagref.simexplorer.is.storage.factories;
+
+import org.w3c.dom.Element;
+
+import fr.cemagref.simexplorer.is.storage.database.DatabaseConstants;
+import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
+
+public abstract class LoggableElementFactory<E extends LoggableElement> extends
+ FileEntityFactory<E> implements DatabaseConstants {
+
+ private static final String KEY_DESCRIPTION = "description";
+
+ @Override
+ public E loadXMLElement(Element xmlElement) throws Exception {
+ E element = super.loadXMLElement(xmlElement);
+ element.setUuid(getProperty(xmlElement, KEY_UUID));
+ element.setName(getProperty(xmlElement, KEY_NAME));
+ element.setType(getProperty(xmlElement, KEY_TYPE));
+ element.setDescription(getProperty(xmlElement, KEY_DESCRIPTION));
+ element.setVersion(getProperty(xmlElement, KEY_VERSION));
+
+ // FIXME Convert
+ /*
+ * element.setCreationDate(new Date(getProperty(xmlElement,
+ * KEY_CREATIONDATE)));
+ */
+
+ element.setHash(getProperty(xmlElement, KEY_HASH));
+ return element;
+ }
+
+ @Override
+ public void saveXMLElement(org.w3c.dom.Document document,
+ Element xmlElement, E element) throws Exception {
+
+ setProperty(document, xmlElement, KEY_UUID, element.getUuid());
+ setProperty(document, xmlElement, KEY_NAME, element.getName());
+ setProperty(document, xmlElement, KEY_TYPE, element.getType());
+ setProperty(document, xmlElement, KEY_DESCRIPTION, element
+ .getDescription());
+ setProperty(document, xmlElement, KEY_VERSION, element.getVersion());
+ /*
+ * setProperty(document, xmlElement, KEY_CREATIONDATE,
+ * element.getCreationDate());
+ */
+ setProperty(document, xmlElement, KEY_HASH, element.getHash());
+
+ }
+
+}
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/RepositoryFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/RepositoryFactory.java 2007-12-05 15:22:53 UTC (rev 39)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/RepositoryFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,20 +1,22 @@
-package org.cemagref.simexplorer.si.storage.factories;
+package fr.cemagref.simexplorer.is.storage.factories;
-import org.cemagref.simexplorer.si.storage.entities.Repository;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-public class RepositoryFactory<E extends Repository> extends EntityFactory<Repository> {
+import fr.cemagref.simexplorer.is.storage.entities.Repository;
- @Override
- public Repository createInstance() {
- return new Repository();
- }
+public class RepositoryFactory<E extends Repository> extends
+ EntityFactory<Repository> {
- @Override
- public void saveXMLElement(Document document, Element xmlElement,
- Repository element) throws Exception {
-
- }
+ @Override
+ public Repository createInstance() {
+ return new Repository();
+ }
+ @Override
+ public void saveXMLElement(Document document, Element xmlElement,
+ Repository element) throws Exception {
+
+ }
+
}
Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ResultFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/ResultFactory.java 2007-12-05 15:22:53 UTC (rev 39)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ResultFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,20 +0,0 @@
-package org.cemagref.simexplorer.si.storage.factories;
-
-import org.cemagref.simexplorer.si.storage.entities.Result;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-public class ResultFactory<E extends Result> extends EntityFactory<Result> {
-
- @Override
- public Result createInstance() {
- return new Result();
- }
-
- @Override
- public void saveXMLElement(Document document, Element xmlElement,
- Result element) throws Exception {
-
- }
-
-}
Copied: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ResultFactory.java (from rev 49, trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/ResultFactory.java)
===================================================================
--- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ResultFactory.java (rev 0)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ResultFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,21 @@
+package fr.cemagref.simexplorer.is.storage.factories;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import fr.cemagref.simexplorer.is.storage.entities.Result;
+
+public class ResultFactory<E extends Result> extends FileEntityFactory<Result> {
+
+ @Override
+ public Result createInstance() {
+ return new Result();
+ }
+
+ @Override
+ public void saveXMLElement(Document document, Element xmlElement,
+ Result element) throws Exception {
+
+ }
+
+}
Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/StructureFactory.java
===================================================================
--- trunk/simexplorer-si-storage/src/java/org/cemagref/simexplorer/si/storage/factories/StructureFactory.java 2007-12-05 15:22:53 UTC (rev 39)
+++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/StructureFactory.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,7 +1,8 @@
-package org.cemagref.simexplorer.si.storage.factories;
+package fr.cemagref.simexplorer.is.storage.factories;
-import org.cemagref.simexplorer.si.storage.entities.Structure;
+import fr.cemagref.simexplorer.is.storage.entities.Structure;
-public abstract class StructureFactory<E extends Structure> extends EntityFactory<Structure> {
-
+public abstract class StructureFactory<E extends Structure> extends
+ EntityFactory<Structure> {
+
}
Copied: trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test (from rev 38, trunk/simexplorer-si-storage/src/test/org/cemagref/simexplorer/si/storage/test)
Copied: trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/ElementGenerator.java (from rev 52, trunk/simexplorer-si-storage/src/test/org/cemagref/simexplorer/si/storage/test/ElementGenerator.java)
===================================================================
--- trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/ElementGenerator.java (rev 0)
+++ trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/ElementGenerator.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,136 @@
+package fr.cemagref.simexplorer.is.storage.test;
+
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Random;
+import java.util.Set;
+import java.util.UUID;
+
+import fr.cemagref.simexplorer.is.storage.entities.Code;
+import fr.cemagref.simexplorer.is.storage.entities.Component;
+import fr.cemagref.simexplorer.is.storage.entities.Constant;
+import fr.cemagref.simexplorer.is.storage.entities.ConstantValue;
+import fr.cemagref.simexplorer.is.storage.entities.Descriptor;
+import fr.cemagref.simexplorer.is.storage.entities.Entity;
+import fr.cemagref.simexplorer.is.storage.entities.ExplorationApplication;
+import fr.cemagref.simexplorer.is.storage.entities.ExplorationData;
+import fr.cemagref.simexplorer.is.storage.entities.Library;
+import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
+import fr.cemagref.simexplorer.is.storage.entities.Result;
+import fr.cemagref.simexplorer.is.storage.entities.Structure;
+import fr.cemagref.simexplorer.is.storage.factories.EntityFactory;
+
+public class ElementGenerator {
+
+ private Random r = new Random();
+
+ private void update(LoggableElement element) throws Exception {
+ element.setUuid(UUID.randomUUID().toString());
+ element.setName(UUID.randomUUID().toString());
+ element.setType(element.getClass().getSimpleName());
+ element.setDescription("test");
+ element.setVersion(Integer.toString(r.nextInt(100)));
+ element.setCreationDate(new Date(r.nextLong()));
+ element.setHash(UUID.randomUUID().toString());
+
+ Set<Descriptor> descriptors = generateArray(Descriptor.class);
+ for (Object object : descriptors) {
+ processDescriptor((Descriptor) object);
+ }
+ element.setDescriptors(descriptors);
+ }
+
+ private void processDescriptor(Descriptor object) {
+ object.setName(UUID.randomUUID().toString());
+ object.setValue(UUID.randomUUID().toString());
+ }
+
+ private <T extends Entity> Set<T> generateArray(Class<T> clazz)
+ throws Exception {
+ Set<T> elements = new HashSet<T>();
+ int i = 1 + r.nextInt(2);
+ for (int j = 0; j < i; j++) {
+ T element = EntityFactory.getFactory(clazz).createInstance();
+ if (element instanceof LoggableElement) {
+ update((LoggableElement) element);
+ }
+ elements.add(element);
+ }
+ return elements;
+ }
+
+ public ExplorationApplication generateRandomEA() throws Exception {
+ ExplorationApplication ea = new ExplorationApplication();
+ update(ea);
+ Set<ExplorationData> datas = generateArray(ExplorationData.class);
+ for (ExplorationData object : datas) {
+ processExplorationData(object);
+ }
+ ea.setExplorations(datas);
+ Set<Component> components = generateArray(Component.class);
+ for (Component object : components) {
+ processComponent(object);
+ }
+ ea.setComponents(components);
+ return ea;
+ }
+
+ private void processComponent(Component component) throws Exception {
+ Set<Constant> constants = generateArray(Constant.class);
+ for (Constant constant : constants) {
+ processConstant(constant);
+ }
+ component.setConstants(constants);
+
+ component.setStructures(new HashSet<Structure>());
+
+ Set<Code> codes = generateArray(Code.class);
+ for (Code code : codes) {
+ processCode(code);
+ }
+ component.setCodes(codes);
+
+ Set<Library> libraries = generateArray(Library.class);
+ for (Library library : libraries) {
+ processLibrary(library);
+ }
+ component.setLibraries(libraries);
+
+ }
+
+ private void processLibrary(Library library) {
+ }
+
+ private void processCode(Code code) {
+ code.setCode(UUID.randomUUID().toString());
+ code.setLanguage(UUID.randomUUID().toString());
+ }
+
+ private void processConstant(Constant constant) {
+ constant.setName(UUID.randomUUID().toString());
+ constant.setType(String.class);
+ }
+
+ private void processExplorationData(ExplorationData explorationData)
+ throws Exception {
+ Result result = new Result();
+ explorationData.setResult(result);
+
+ Set<ConstantValue> constantValues = generateArray(ConstantValue.class);
+ for (ConstantValue constantValue : constantValues) {
+ processConstantValue(constantValue);
+ }
+ explorationData.setValuesMap(constantValues);
+
+ }
+
+ private void processConstantValue(ConstantValue constantValue) {
+ Constant constant = new Constant();
+ constant.setName(UUID.randomUUID().toString());
+ constant.setType(Integer.class);
+
+ constantValue.setConstant(constant);
+ constantValue.setValue(Integer.toString(r.nextInt()));
+ }
+
+}
Deleted: trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/LuceneDatabaseTestCase.java
===================================================================
--- trunk/simexplorer-si-storage/src/test/org/cemagref/simexplorer/si/storage/test/LuceneDatabaseTestCase.java 2007-12-04 18:32:09 UTC (rev 38)
+++ trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/LuceneDatabaseTestCase.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -1,113 +0,0 @@
-package org.cemagref.simexplorer.si.storage.test;
-
-import java.util.UUID;
-
-import junit.framework.TestCase;
-
-import org.cemagref.simexplorer.si.storage.database.lucene.LuceneDatabase;
-import org.cemagref.simexplorer.si.storage.entities.ExplorationData;
-import org.cemagref.simexplorer.si.storage.entities.LoggableElement;
-
-public class LuceneDatabaseTestCase extends TestCase {
-
- private LuceneDatabase database;
-
- protected void setUp() throws Exception {
- super.setUp();
- try {
- database = new LuceneDatabase();
- } catch (Throwable e) {
- throw new Exception(e);
- }
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- try {
- database.shutDown();
- } catch (Throwable e) {
- throw new Exception(e);
- }
- }
-
- public final void testPushElement() {
- try {
- String description1 = UUID.randomUUID().toString();
- String uuid1 = UUID.randomUUID().toString();
- Integer majorVersion1 = 5;
- Integer minorVersion1 = 12;
- ExplorationData explorationData1 = new ExplorationData();
- explorationData1.setUuid(uuid1);
- explorationData1.setMajorVersion(majorVersion1);
- explorationData1.setMinorVersion(minorVersion1);
- explorationData1.setDescription(description1);
- database.pushElement(explorationData1);
-
- LoggableElement element = database.findElement(uuid1, majorVersion1, minorVersion1);
- assertNotNull(element);
- assertEquals(description1, element.getDescription());
-
- String description2 = UUID.randomUUID().toString();
- ExplorationData explorationData2 = new ExplorationData();
- explorationData2.setUuid(uuid1);
- explorationData2.setMajorVersion(majorVersion1);
- explorationData2.setMinorVersion(minorVersion1);
- explorationData2.setDescription(description2);
- database.pushElement(explorationData2);
-
- assertEquals(description2, database.findElement(uuid1, majorVersion1, minorVersion1).getDescription());
-
- String description3 = UUID.randomUUID().toString();
- Integer minorVersion3 = minorVersion1 + 1;
- ExplorationData explorationData3 = new ExplorationData();
- explorationData3.setUuid(uuid1);
- explorationData3.setMajorVersion(majorVersion1);
- explorationData3.setMinorVersion(minorVersion3);
- explorationData3.setDescription(description3);
- database.pushElement(explorationData3);
-
- assertEquals(description3, database.findElement(uuid1, majorVersion1, minorVersion3).getDescription());
-
- } catch (Throwable e) {
- fail(e.toString());
- }
- }
-
- public final void testFindElement() {
- fail("Not yet implemented"); // TODO
- }
-
- public final void testGetElementLatestVersion() {
- fail("Not yet implemented"); // TODO
- }
-
- public final void testFindElementsById() {
- fail("Not yet implemented"); // TODO
- }
-
- public final void testFindElementsByPropertiesMapOfStringString() {
- fail("Not yet implemented"); // TODO
- }
-
- public final void testFindElementsByPropertiesMapOfStringStringClass() {
- fail("Not yet implemented"); // TODO
- }
-
- public final void testDeleteElementString() {
- fail("Not yet implemented"); // TODO
- }
-
- public final void testDeleteElementStringIntegerInteger() {
- fail("Not yet implemented"); // TODO
- }
-
- public final void testLuceneDatabase() {
- try {
- LuceneDatabase database = new LuceneDatabase();
- } catch (Throwable e) {
- fail(e.toString());
- }
-
- }
-
-}
Copied: trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/LuceneDatabaseTestCase.java (from rev 52, trunk/simexplorer-si-storage/src/test/org/cemagref/simexplorer/si/storage/test/LuceneDatabaseTestCase.java)
===================================================================
--- trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/LuceneDatabaseTestCase.java (rev 0)
+++ trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/LuceneDatabaseTestCase.java 2007-12-07 14:36:43 UTC (rev 55)
@@ -0,0 +1,253 @@
+package fr.cemagref.simexplorer.is.storage.test;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+import fr.cemagref.simexplorer.is.storage.database.DatabaseConstants;
+import fr.cemagref.simexplorer.is.storage.database.lucene.LuceneDatabase;
+import fr.cemagref.simexplorer.is.storage.entities.ExplorationData;
+import fr.cemagref.simexplorer.is.storage.entities.LoggableElement;
+import fr.cemagref.simexplorer.is.storage.entities.Version;
+
+public class LuceneDatabaseTestCase extends TestCase {
+
+ private LuceneDatabase database;
+ private ElementGenerator elementGenerator;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ database = new LuceneDatabase();
+ database.open();
+ elementGenerator = new ElementGenerator();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ database.close();
+ }
+
+ public final void testPushFindElement() throws Exception {
+
+ /*
+ * database.pushElement(elementGenerator.generateRandomEA());
+ *
+ * Map<String, String> properties = new HashMap<String, String>();
+ * properties.put(DatabaseConstants.KEY_DESCRIPTION, "test"); Set<LoggableElement>
+ * elements = database .findElementsByProperties(properties); for
+ * (LoggableElement loggableElement : elements) {
+ * System.out.println(EntityFactory.getFactory(
+ * loggableElement.getClass()).getElementXML(loggableElement)); }
+ */
+
+ String description1 = UUID.randomUUID().toString();
+ String uuid1 = UUID.randomUUID().toString();
+ ExplorationData explorationData1 = new ExplorationData();
+ explorationData1.setUuid(uuid1);
+ explorationData1.setVersion("5.12");
+ explorationData1.setDescription(description1);
+ database.pushElement(explorationData1);
+
+ LoggableElement element = database.findElement(uuid1, new Version(
+ "5.12"));
+ assertNotNull(element);
+ assertEquals(description1, element.getDescription());
+
+ String description2 = UUID.randomUUID().toString();
+ ExplorationData explorationData2 = new ExplorationData();
+ explorationData2.setUuid(uuid1);
+ explorationData2.setVersion("5.12");
+ explorationData2.setDescription(description2);
+ database.pushElement(explorationData2);
+
+ assertEquals(description2, database.findElement(uuid1,
+ new Version("5.12")).getDescription());
+
+ String description3 = UUID.randomUUID().toString();
+ ExplorationData explorationData3 = new ExplorationData();
+ explorationData3.setUuid(uuid1);
+ explorationData3.setVersion("5.13");
+ explorationData3.setDescription(description3);
+ database.pushElement(explorationData3);
+
+ assertEquals(description3, database.findElement(uuid1,
+ new Version("5.13")).getDescription());
+ }
+
+ public final void testGetElementLatestVersion() throws Exception {
+ String description1 = UUID.randomUUID().toString();
+ String uuid1 = UUID.randomUUID().toString();
+ ExplorationData explorationData1 = new ExplorationData();
+ explorationData1.setUuid(uuid1);
+ explorationData1.setVersion("5.12");
+ explorationData1.setDescription(description1);
+ database.pushElement(explorationData1);
+
+ String description2 = UUID.randomUUID().toString();
+ ExplorationData explorationData2 = new ExplorationData();
+ explorationData2.setUuid(uuid1);
+ explorationData2.setVersion("5.13");
+ explorationData2.setDescription(description2);
+ database.pushElement(explorationData2);
+
+ assertEquals(description2, database.getElementLatestVersion(uuid1)
+ .getDescription());
+
+ String description3 = UUID.randomUUID().toString();
+ ExplorationData explorationData3 = new ExplorationData();
+ explorationData3.setUuid(uuid1);
+ explorationData3.setVersion("6.0");
+ explorationData3.setDescription(description3);
+ database.pushElement(explorationData3);
+
+ assertEquals(description3, database.getElementLatestVersion(uuid1)
+ .getDescription());
+ }
+
+ public final void testFindElementsById() throws Exception {
+ String description1 = UUID.randomUUID().toString();
+ String uuid1 = UUID.randomUUID().toString();
+ ExplorationData explorationData1 = new ExplorationData();
+ explorationData1.setUuid(uuid1);
+ explorationData1.setVersion("5.12");
+ explorationData1.setDescription(description1);
+ database.pushElement(explorationData1);
+
+ String description2 = UUID.randomUUID().toString();
+ ExplorationData explorationData2 = new ExplorationData();
+ explorationData2.setUuid(uuid1);
+ explorationData2.setVersion("5.13");
+ explorationData2.setDescription(description2);
+ database.pushElement(explorationData2);
+
+ String description3 = UUID.randomUUID().toString();
+ ExplorationData explorationData3 = new ExplorationData();
+ explorationData3.setUuid(uuid1);
+ explorationData3.setVersion("6.0");
+ explorationData3.setDescription(description3);
+ database.pushElement(explorationData3);
+
+ Set<LoggableElement> elements = database.findElementsById(uuid1);
+ assertEquals(3, elements.size());
+
+ }
+
+ public final void testFindElementsByPropertiesMapOfStringString()
+ throws Exception {
+
+ String description1 = UUID.randomUUID().toString();
+ String uuid1 = UUID.randomUUID().toString();
+ ExplorationData explorationData1 = new ExplorationData();
+ explorationData1.setUuid(uuid1);
+ explorationData1.setVersion("5.12");
+ explorationData1.setDescription(description1);
+ database.pushElement(explorationData1);
+
+ ExplorationData explorationData2 = new ExplorationData();
+ explorationData2.setUuid(uuid1);
+ explorationData2.setVersion("5.13");
+ explorationData2.setDescription(description1);
+ database.pushElement(explorationData2);
+
+ String description3 = UUID.randomUUID().toString();
+ ExplorationData explorationData3 = new ExplorationData();
+ explorationData3.setUuid(uuid1);
+ explorationData3.setVersion("6.0");
+ explorationData3.setDescription(description3);
+ database.pushElement(explorationData3);
+
+ // TODO add some other classes in db
+
+ Map<String, String> properties = new HashMap<String, String>();
+ properties.put(DatabaseConstants.KEY_UUID, uuid1);
+ properties.put(DatabaseConstants.KEY_DESCRIPTION, description1);
+
+ Set<LoggableElement> elements = database
+ .findElementsByProperties(properties);
+ assertEquals(2, elements.size());
+
+ }
+
+ public final void testFindElementsByPropertiesMapOfStringStringClass()
+ throws Exception {
+
+ String description1 = UUID.randomUUID().toString();
+ String uuid1 = UUID.randomUUID().toString();
+ ExplorationData explorationData1 = new ExplorationData();
+ explorationData1.setUuid(uuid1);
+ explorationData1.setVersion("5.12");
+ explorationData1.setDescription(description1);
+ database.pushElement(explorationData1);
+
+ ExplorationData explorationData2 = new ExplorationData();
+ explorationData2.setUuid(uuid1);
+ explorationData2.setVersion("5.13");
+ explorationData2.setDescription(description1);
+ database.pushElement(explorationData2);
+
+ String description3 = UUID.randomUUID().toString();
+ ExplorationData explorationData3 = new ExplorationData();
+ explorationData3.setUuid(uuid1);
+ explorationData3.setVersion("6.0");
+ explorationData3.setDescription(description3);
+ database.pushElement(explorationData3);
+
+ Map<String, String> properties = new HashMap<String, String>();
+ properties.put(DatabaseConstants.KEY_UUID, uuid1);
+ properties.put(DatabaseConstants.KEY_DESCRIPTION, description1);
+
+ Set<LoggableElement> elements = database.findElementsByProperties(
+ properties, ExplorationData.class);
+ assertEquals(2, elements.size());
+
+ }
+
+ public final void testDeleteElement() throws Exception {
+
+ String description1 = UUID.randomUUID().toString();
+ String uuid1 = UUID.randomUUID().toString();
+ ExplorationData explorationData1 = new ExplorationData();
+ explorationData1.setUuid(uuid1);
+ explorationData1.setVersion("5.12");
+ explorationData1.setDescription(description1);
+ database.pushElement(explorationData1);
+
+ database.deleteElement(explorationData1);
+ assertNull(database.findElement(uuid1, new Version("5.12")));
+
+ }
+
+ public final void testDeleteElements() throws Exception {
+
+ String description1 = UUID.randomUUID().toString();
+ String uuid1 = UUID.randomUUID().toString();
+ ExplorationData explorationData1 = new ExplorationData();
+ explorationData1.setUuid(uuid1);
+ explorationData1.setVersion("5.12");
+ explorationData1.setDescription(description1);
+ database.pushElement(explorationData1);
+
+ String description2 = UUID.randomUUID().toString();
+ ExplorationData explorationData2 = new ExplorationData();
+ explorationData2.setUuid(uuid1);
+ explorationData2.setVersion("5.13");
+ explorationData2.setDescription(description2);
+ database.pushElement(explorationData2);
+
+ String description3 = UUID.randomUUID().toString();
+ ExplorationData explorationData3 = new ExplorationData();
+ explorationData3.setUuid(uuid1);
+ explorationData3.setVersion("6.0");
+ explorationData3.setDescription(description3);
+ database.pushElement(explorationData3);
+
+ database.deleteElements(uuid1);
+
+ assertEquals(0, database.findElementsById(uuid1).size());
+
+ }
+
+}
1
0
07 Dec '07
Author: glandais
Date: 2007-12-07 14:34:34 +0000 (Fri, 07 Dec 2007)
New Revision: 54
Removed:
trunk/simexplorer-si-storage/src/test/org/
Log:
Refactoring package name
1
0
07 Dec '07
Author: glandais
Date: 2007-12-07 14:34:19 +0000 (Fri, 07 Dec 2007)
New Revision: 53
Removed:
trunk/simexplorer-si-storage/src/java/org/
Log:
Refactoring package name
1
0