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
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()); + + } + +}
participants (1)
-
glandais@users.labs.libre-entreprise.org