Author: glandais Date: 2008-01-04 15:59:36 +0000 (Fri, 04 Jan 2008) New Revision: 94 Added: trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/service/StorageServiceMassInsert.java Removed: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/Content.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/xml/ Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/FileSystemAttachmentHandler.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/BaseEntity.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Code.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Component.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Constant.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ConstantValue.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/DataEntity.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ExplorationApplication.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ExplorationData.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Library.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Repository.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Result.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/metadata/MetaDataEntity.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/BaseEntityFactory.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/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/ExplorationApplicationFactory.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationDataFactory.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LoggableElementFactory.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/MetaDataEntityFactory.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/RepositoryFactory.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ResultFactory.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/XmlConstants.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/service/StorageService.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/service/StorageServiceImpl.java 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/MetaDataGenerator.java Log: Suppression de Content MAJ des factories Suppression du package Parser Export d'un EA Deleted: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/Content.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/Content.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/Content.java 2008-01-04 15:59:36 UTC (rev 94) @@ -1,28 +0,0 @@ -package fr.cemagref.simexplorer.is.storage.attachment; - -import java.io.InputStream; - -import fr.cemagref.simexplorer.is.storage.attachment.type.ContentType; - -public class Content { - - private ContentType type; - private InputStream content; - - public ContentType getType() { - return type; - } - - public void setType(ContentType type) { - this.type = type; - } - - public InputStream getContent() { - return content; - } - - public void setContent(InputStream content) { - this.content = content; - } - -} Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/FileSystemAttachmentHandler.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/FileSystemAttachmentHandler.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/handler/FileSystemAttachmentHandler.java 2008-01-04 15:59:36 UTC (rev 94) @@ -21,7 +21,7 @@ /** * Base folder FIXME config */ - private static String baseFolder = "./data/"; + private static String baseFolder = "/var/local/simexplorer/data1/"; /** * Retrieve file associated to content Create directories associated to file @@ -37,8 +37,18 @@ String resultPath = baseFolder; // Create file path - resultPath = resultPath + entity.getUuid() + "/" - + entity.getVersion().toString() + "/" + field; + if (entity.getUuid().length() > 2) { + resultPath = resultPath + + entity.getUuid().substring(0, 1) + + "/" + + entity.getUuid().substring(1, 2) + + "/" + + entity.getUuid(); + } else { + resultPath = resultPath + entity.getUuid(); + } + resultPath = resultPath + "/" + entity.getVersion().toString() + "/" + + field; File result = new File(resultPath); // Create directories Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2008-01-04 15:59:36 UTC (rev 94) @@ -36,7 +36,7 @@ import org.apache.lucene.store.LockFactory; import org.apache.lucene.store.NoLockFactory; -import fr.cemagref.simexplorer.is.storage.attachment.Content; +import fr.cemagref.simexplorer.is.storage.attachment.type.ContentType; import fr.cemagref.simexplorer.is.storage.attachment.type.ContentTypeFactory; import fr.cemagref.simexplorer.is.storage.database.Database; import fr.cemagref.simexplorer.is.storage.entities.metadata.MetaDataEntity; @@ -50,558 +50,558 @@ */ public class LuceneDatabase extends Database { - /** - * Lock factory for Lucene writer - */ - private static LockFactory lockFactory = new NoLockFactory(); - /** - * Location of index - */ - private Directory directory; - /** - * Index writer - */ - private IndexWriter writer = null; - /** - * Pool of searcher - */ - private SearcherPool searcherPool = new SearcherPool(); - /** - * Searcher that should be used for new queries - */ - private Searcher cachedSearcher = null; - /** - * Date of latest optimization - */ - private Date lastOptimize = new Date(); + /** + * Lock factory for Lucene writer + */ + private static LockFactory lockFactory = new NoLockFactory(); + /** + * Location of index + */ + private Directory directory; + /** + * Index writer + */ + private IndexWriter writer = null; + /** + * Pool of searcher + */ + private SearcherPool searcherPool = new SearcherPool(); + /** + * Searcher that should be used for new queries + */ + private Searcher cachedSearcher = null; + /** + * Date of latest optimization + */ + private Date lastOptimize = new Date(); - /** - * Retrieve searcher for a new query - * - * @return Searcher - * @throws CorruptIndexException - * @throws IOException - */ - private Searcher getSearcher() throws CorruptIndexException, IOException { - synchronized (this) { - // If cached searcher is null (as after an index write) - if (cachedSearcher == null) { - // Instanciate a new searcher - cachedSearcher = new IndexSearcher(directory); - } - // Mark searcher as being used in a new query - searcherPool.capture(cachedSearcher); - return cachedSearcher; - } - } + /** + * Retrieve searcher for a new query + * + * @return Searcher + * @throws CorruptIndexException + * @throws IOException + */ + private Searcher getSearcher() throws CorruptIndexException, IOException { + synchronized (this) { + // If cached searcher is null (as after an index write) + if (cachedSearcher == null) { + // Instanciate a new searcher + cachedSearcher = new IndexSearcher(directory); + } + // Mark searcher as being used in a new query + searcherPool.capture(cachedSearcher); + return cachedSearcher; + } + } - /** - * Release searcher, after the end of a query execution - * - * @param searcher - * Searcher to be released - * @throws IOException - */ - private void releaseSearcher(Searcher searcher) throws IOException { - synchronized (this) { - searcherPool.release(searcher); - } - } + /** + * Release searcher, after the end of a query execution + * + * @param searcher + * Searcher to be released + * @throws IOException + */ + private void releaseSearcher(Searcher searcher) throws IOException { + synchronized (this) { + searcherPool.release(searcher); + } + } - /** - * Called to invalidate reader - * - * @throws IOException - */ - private void resetReader() throws IOException { - synchronized (this) { - // Reset searcher - if (cachedSearcher != null) { - // Mark as should be closed asap - searcherPool.mark(cachedSearcher); - cachedSearcher = null; - } - } - } + /** + * Called to invalidate reader + * + * @throws IOException + */ + private void resetReader() throws IOException { + synchronized (this) { + // Reset searcher + if (cachedSearcher != null) { + // Mark as should be closed asap + searcherPool.mark(cachedSearcher); + cachedSearcher = null; + } + } + } - @Override - public void open(boolean create) throws Exception { - // Create an analyzer - Analyzer analyzer = new SimpleAnalyzer(); + @Override + public void open(boolean create) throws Exception { + // Create an analyzer + Analyzer analyzer = new SimpleAnalyzer(); - // FIXME index location - //File indexDir = new File("./index/"); - File indexDir = new File("/home/glandais/lucene/index.big"); + // FIXME index location + // File indexDir = new File("./index/"); + // File indexDir = new File("/home/glandais/lucene/index.big"); + File indexDir = new File("/var/local/simexplorer/db1"); - // Base directory index - directory = FSDirectory.getDirectory(indexDir, lockFactory); + // Base directory index + directory = FSDirectory.getDirectory(indexDir, lockFactory); - boolean realCreate = create; - if (!IndexReader.indexExists(directory)) { - realCreate = true; - } + boolean realCreate = create; + if (!IndexReader.indexExists(directory)) { + realCreate = true; + } - // Instanciate unique writer - writer = new IndexWriter(directory, true, analyzer, realCreate); - - if (realCreate) { - commit(); - } - } + // Instanciate unique writer + writer = new IndexWriter(directory, true, analyzer, realCreate); - @Override - public void close() throws Exception { - writer.close(); - resetReader(); - } + if (realCreate) { + commit(); + } + } - private synchronized void synchedCommit() throws CorruptIndexException, - IOException { - // Flush in ram data - writer.flush(); - // Check if an optimization is required - Date now = new Date(); - long elapsed = now.getTime() - lastOptimize.getTime(); - // FIXME One optimize per hour, if readers are closed - if (elapsed > 3600 * 1000 && searcherPool.allClosed()) { - writer.optimize(); - lastOptimize = new Date(); - } - // System.out.println(writer.docCount()); - // Invalidate reader - resetReader(); - } + @Override + public void close() throws Exception { + writer.close(); + resetReader(); + } - @Override - public void commit() throws Exception { - synchedCommit(); - } + private synchronized void synchedCommit() throws CorruptIndexException, + IOException { + // Flush in ram data + writer.flush(); + // Check if an optimization is required + Date now = new Date(); + long elapsed = now.getTime() - lastOptimize.getTime(); + // FIXME One optimize per hour, if readers are closed + if (elapsed > 3600 * 1000 && searcherPool.allClosed()) { + writer.optimize(); + lastOptimize = new Date(); + } + // System.out.println(writer.docCount()); + // Invalidate reader + resetReader(); + } - @Override - public void insertElement(MetaDataEntity element, List<Reader> readers) - throws Exception { - // Save element to a Lucene document - Document document = saveLuceneElement(element, readers); + @Override + public void commit() throws Exception { + synchedCommit(); + } - // Retrieve existing element with same id/version - MetaDataEntity oldElement = getElement(element.getUuid(), element - .getVersion()); - // Delete element if exists, for update - if (oldElement != null) { - // update - deleteElement(element); - } + @Override + public void insertElement(MetaDataEntity element, List<Reader> readers) + throws Exception { + // Save element to a Lucene document + Document document = saveLuceneElement(element, readers); - // add document to index - writer.addDocument(document); - } + // Retrieve existing element with same id/version + MetaDataEntity oldElement = getElement(element.getUuid(), element + .getVersion()); + // Delete element if exists, for update + if (oldElement != null) { + // update + deleteElement(element); + } - @Override - public MetaDataEntity getElement(String uuid, Version version) - throws Exception { - MetaDataEntity result = null; + // add document to index + writer.addDocument(document); + } - // Get current searcher instance - Searcher searcher = getSearcher(); - try { - Hits hits = getHitsByIdVersion(uuid, version, searcher); - if (hits != null && hits.length() != 0) { - // convert first document to element - result = loadLuceneElement(hits.doc(0)); - } - } finally { - // Release searcher instance - releaseSearcher(searcher); - } + @Override + public MetaDataEntity getElement(String uuid, Version version) + throws Exception { + MetaDataEntity result = null; - return result; - } + // Get current searcher instance + Searcher searcher = getSearcher(); + try { + Hits hits = getHitsByIdVersion(uuid, version, searcher); + if (hits != null && hits.length() != 0) { + // convert first document to element + result = loadLuceneElement(hits.doc(0)); + } + } finally { + // Release searcher instance + releaseSearcher(searcher); + } - /** - * @param uuid - * @param version - * @return - * @throws IOException - * @throws Exception - */ - private Hits getHitsByIdVersion(String uuid, Version version, - Searcher searcher) throws IOException { - // Retrieve element with id/version - Map<String, String> properties = new HashMap<String, String>(); - properties.put(KEY_UUID, uuid); - properties.put(KEY_VERSION, version.toString()); + return result; + } - // Search elements - Hits hits = findHits(properties, searcher, SORT_DATE_NONE); - return hits; - } + /** + * @param uuid + * @param version + * @return + * @throws IOException + * @throws Exception + */ + private Hits getHitsByIdVersion(String uuid, Version version, + Searcher searcher) throws IOException { + // Retrieve element with id/version + Map<String, String> properties = new HashMap<String, String>(); + properties.put(KEY_UUID, uuid); + properties.put(KEY_VERSION, version.toString()); - @Override - public List<Version> getVersions(String uuid) throws Exception { - // Retrieve all document corresponding to id - Map<String, String> properties = new HashMap<String, String>(); - properties.put(KEY_UUID, uuid); + // Search elements + Hits hits = findHits(properties, searcher, SORT_DATE_NONE); + return hits; + } - List<Version> versions = null; - // Get current searcher instance - Searcher searcher = getSearcher(); - try { - Hits hits = findHits(properties, searcher, SORT_DATE_NONE); + @Override + public List<Version> getVersions(String uuid) throws Exception { + // Retrieve all document corresponding to id + Map<String, String> properties = new HashMap<String, String>(); + properties.put(KEY_UUID, uuid); - // Add all versions to a list - versions = new ArrayList<Version>(); - if (hits != null) { - for (int i = 0; i < hits.length(); i++) { - Document doc = hits.doc(i); - versions.add(new Version(doc.get(KEY_VERSION))); - } - } - } finally { - // Release searcher instance - releaseSearcher(searcher); - } + List<Version> versions = null; + // Get current searcher instance + Searcher searcher = getSearcher(); + try { + Hits hits = findHits(properties, searcher, SORT_DATE_NONE); - return versions; - } + // Add all versions to a list + versions = new ArrayList<Version>(); + if (hits != null) { + for (int i = 0; i < hits.length(); i++) { + Document doc = hits.doc(i); + versions.add(new Version(doc.get(KEY_VERSION))); + } + } + } finally { + // Release searcher instance + releaseSearcher(searcher); + } - @Override - public Set<MetaDataEntity> findElementsById(String uuid, boolean onlyLatest) - throws Exception { - // Create hash map with id - Map<String, String> properties = new HashMap<String, String>(); - properties.put(KEY_UUID, uuid); - if (onlyLatest) { - properties.put(KEY_LATEST, "1"); - } + return versions; + } - Set<MetaDataEntity> result = null; + @Override + public Set<MetaDataEntity> findElementsById(String uuid, boolean onlyLatest) + throws Exception { + // Create hash map with id + Map<String, String> properties = new HashMap<String, String>(); + properties.put(KEY_UUID, uuid); + if (onlyLatest) { + properties.put(KEY_LATEST, "1"); + } - // Get current searcher instance - Searcher searcher = getSearcher(); - try { - Hits hits = findHits(properties, searcher, SORT_DATE_NONE); - result = convertHitsToElements(hits, 0, -1); - } finally { - // Release searcher instance - releaseSearcher(searcher); - } + Set<MetaDataEntity> result = null; - // Return all elements parsed from documents fund - return result; - } + // Get current searcher instance + Searcher searcher = getSearcher(); + try { + Hits hits = findHits(properties, searcher, SORT_DATE_NONE); + result = convertHitsToElements(hits, 0, -1); + } finally { + // Release searcher instance + releaseSearcher(searcher); + } - @Override - public int findElementsByPropertiesCount(Map<String, String> properties) - throws Exception { - int result = 0; + // Return all elements parsed from documents fund + return result; + } - // Get current searcher instance - Searcher searcher = getSearcher(); - try { - Hits hits = findHits(properties, searcher, SORT_DATE_NONE); - result = hits.length(); - } finally { - // Release searcher instance - releaseSearcher(searcher); - } + @Override + public int findElementsByPropertiesCount(Map<String, String> properties) + throws Exception { + int result = 0; - // Return all elements parsed from documents fund - return result; - } + // Get current searcher instance + Searcher searcher = getSearcher(); + try { + Hits hits = findHits(properties, searcher, SORT_DATE_NONE); + result = hits.length(); + } finally { + // Release searcher instance + releaseSearcher(searcher); + } - @Override - public Set<MetaDataEntity> findElementsByProperties( - Map<String, String> properties, int start, int count, int dateOrder) - throws Exception { - Set<MetaDataEntity> result = null; + // Return all elements parsed from documents fund + return result; + } - // Get current searcher instance - Searcher searcher = getSearcher(); - try { - Hits hits = findHits(properties, searcher, dateOrder); - result = convertHitsToElements(hits, start, count); - } finally { - // Release searcher instance - releaseSearcher(searcher); - } + @Override + public Set<MetaDataEntity> findElementsByProperties( + Map<String, String> properties, int start, int count, int dateOrder) + throws Exception { + Set<MetaDataEntity> result = null; - // Return all elements parsed from documents fund - return result; - } + // Get current searcher instance + Searcher searcher = getSearcher(); + try { + Hits hits = findHits(properties, searcher, dateOrder); + result = convertHitsToElements(hits, start, count); + } finally { + // Release searcher instance + releaseSearcher(searcher); + } - @Override - public int findElementsByContentSearchCount(String queryText, - boolean onlyLatest) throws Exception { - Query query = getQueryByContentSearch(queryText, onlyLatest); + // Return all elements parsed from documents fund + return result; + } - int result = 0; + @Override + public int findElementsByContentSearchCount(String queryText, + boolean onlyLatest) throws Exception { + Query query = getQueryByContentSearch(queryText, onlyLatest); - Hits hits = null; - // Get current searcher instance - Searcher searcher = getSearcher(); - try { - hits = searcher.search(query); - // Return hits length - result = hits.length(); - } finally { - // Release searcher instance - releaseSearcher(searcher); - } + int result = 0; - return result; - } + Hits hits = null; + // Get current searcher instance + Searcher searcher = getSearcher(); + try { + hits = searcher.search(query); + // Return hits length + result = hits.length(); + } finally { + // Release searcher instance + releaseSearcher(searcher); + } - private Sort getSortDate(int dateOrder) { - Sort sort = null; + return result; + } + + private Sort getSortDate(int dateOrder) { + Sort sort = null; if (dateOrder == SORT_DATE_DESCENDING) { sort = new Sort(SORT_DATE_FIELD, true); } if (dateOrder == SORT_DATE_ASCENDING) { sort = new Sort(SORT_DATE_FIELD); } - return sort; - } - - @Override - public Set<MetaDataEntity> findElementsByContentSearch(String queryText, - boolean onlyLatest, int start, int count, int dateOrder) throws Exception { - Query query = getQueryByContentSearch(queryText, onlyLatest); + return sort; + } - Set<MetaDataEntity> result = null; + @Override + public Set<MetaDataEntity> findElementsByContentSearch(String queryText, + boolean onlyLatest, int start, int count, int dateOrder) + throws Exception { + Query query = getQueryByContentSearch(queryText, onlyLatest); - Hits hits = null; - // Get current searcher instance - Searcher searcher = getSearcher(); - try { - hits = searcher.search(query, getSortDate(dateOrder)); - // Convert hits to elements - result = convertHitsToElements(hits, start, count); - } finally { - // Release searcher instance - releaseSearcher(searcher); - } + Set<MetaDataEntity> result = null; - return result; - } + Hits hits = null; + // Get current searcher instance + Searcher searcher = getSearcher(); + try { + hits = searcher.search(query, getSortDate(dateOrder)); + // Convert hits to elements + result = convertHitsToElements(hits, start, count); + } finally { + // Release searcher instance + releaseSearcher(searcher); + } - private Query getQueryByContentSearch(String queryText, boolean onlyLatest) - throws ParseException { - Query query; - Analyzer analyzer = new SimpleAnalyzer(); - QueryParser parser = new QueryParser(KEY_SEARCHABLE_CONTENT, analyzer); - Query searchQuery = parser.parse(queryText); - if (onlyLatest) { - query = new BooleanQuery(); - ((BooleanQuery) query).add(searchQuery, BooleanClause.Occur.MUST); - ((BooleanQuery) query).add( - new TermQuery(new Term(KEY_LATEST, "1")), - BooleanClause.Occur.MUST); - } else { - query = searchQuery; - } - return query; - } + return result; + } - @Override - public void deleteElement(String uuid, Version version) throws Exception { - // Delete element in db with term search - Term[] terms = new Term[2]; - terms[0] = new Term(KEY_UUID, uuid); - terms[1] = new Term(KEY_VERSION, version.toString()); + private Query getQueryByContentSearch(String queryText, boolean onlyLatest) + throws ParseException { + Query query; + Analyzer analyzer = new SimpleAnalyzer(); + QueryParser parser = new QueryParser(KEY_SEARCHABLE_CONTENT, analyzer); + Query searchQuery = parser.parse(queryText); + if (onlyLatest) { + query = new BooleanQuery(); + ((BooleanQuery) query).add(searchQuery, BooleanClause.Occur.MUST); + ((BooleanQuery) query).add( + new TermQuery(new Term(KEY_LATEST, "1")), + BooleanClause.Occur.MUST); + } else { + query = searchQuery; + } + return query; + } - writer.deleteDocuments(terms); - } + @Override + public void deleteElement(String uuid, Version version) throws Exception { + // Delete element in db with term search + Term[] terms = new Term[2]; + terms[0] = new Term(KEY_UUID, uuid); + terms[1] = new Term(KEY_VERSION, version.toString()); - /** - * Find all documents matching properties - * - * @param properties - * criteria - * @return Documents and search handle - * @throws IOException - * @throws Exception - */ - private Hits findHits(Map<String, String> properties, Searcher searcher, int dateOrder) - throws IOException { - // Create a query with all parameters - BooleanQuery query = new BooleanQuery(); - for (Entry<String, String> kv : properties.entrySet()) { - query.add(new TermQuery(new Term(kv.getKey(), kv.getValue())), - BooleanClause.Occur.MUST); - } + writer.deleteDocuments(terms); + } - Hits hits = searcher.search(query, getSortDate(dateOrder)); - return hits; - } + /** + * Find all documents matching properties + * + * @param properties + * criteria + * @return Documents and search handle + * @throws IOException + * @throws Exception + */ + private Hits findHits(Map<String, String> properties, Searcher searcher, + int dateOrder) throws IOException { + // Create a query with all parameters + BooleanQuery query = new BooleanQuery(); + for (Entry<String, String> kv : properties.entrySet()) { + query.add(new TermQuery(new Term(kv.getKey(), kv.getValue())), + BooleanClause.Occur.MUST); + } - /** - * Convert all Lucene documents to real entities - * - * @param hits - * Document collection - * @param start - * Index of first document to return - * @param count - * Number of documents to return - * @return Entities list - * @throws Exception - */ - private Set<MetaDataEntity> convertHitsToElements(Hits hits, int start, - int count) throws Exception { - Set<MetaDataEntity> elements = new HashSet<MetaDataEntity>(); - if (hits != null) { - // For documents in range - for (int i = start; i < hits.length() - && (i < start + count || count == -1); i++) { - Document document = hits.doc(i); - // Convert to element - elements.add(loadLuceneElement(document)); - } - } - return elements; - } + Hits hits = searcher.search(query, getSortDate(dateOrder)); + return hits; + } - /** - * Transform a Lucene document into a LoggableElement thanks to a factory - * - * @param factory - * The element factory - * @param document - * The document to transform - * @return Instance of element - * @throws Exception - */ - private MetaDataEntity loadLuceneElement(Document document) - throws Exception { - MetaDataEntity element = new MetaDataEntity(); - element.setUuid(document.get(KEY_UUID)); - element.setName(document.get(KEY_NAME)); - element.setType(document.get(KEY_TYPE)); - element.setDescription(document.get(KEY_DESCRIPTION)); - element.setVersion(document.get(KEY_VERSION)); - if ("1".equals(document.get(KEY_LATEST))) { - element.setLatest(true); - } else { - element.setLatest(false); - } - String creationDate = document.get(KEY_CREATIONDATE); - if (creationDate != null) { - long creationDateLong = new Long(creationDate); - Date date = new Date(creationDateLong); - element.setCreationDate(date); - } - element.setHash(document.get(KEY_HASH)); + /** + * Convert all Lucene documents to real entities + * + * @param hits + * Document collection + * @param start + * Index of first document to return + * @param count + * Number of documents to return + * @return Entities list + * @throws Exception + */ + private Set<MetaDataEntity> convertHitsToElements(Hits hits, int start, + int count) throws Exception { + Set<MetaDataEntity> elements = new HashSet<MetaDataEntity>(); + if (hits != null) { + // For documents in range + for (int i = start; i < hits.length() + && (i < start + count || count == -1); i++) { + Document document = hits.doc(i); + // Convert to element + elements.add(loadLuceneElement(document)); + } + } + return elements; + } - Map<String, String> descriptors = new HashMap<String, String>(); - Map<String, Content> attachments = new HashMap<String, Content>(); + /** + * Transform a Lucene document into a LoggableElement thanks to a factory + * + * @param factory + * The element factory + * @param document + * The document to transform + * @return Instance of element + * @throws Exception + */ + private MetaDataEntity loadLuceneElement(Document document) + throws Exception { + MetaDataEntity element = new MetaDataEntity(); + element.setUuid(document.get(KEY_UUID)); + element.setName(document.get(KEY_NAME)); + element.setType(document.get(KEY_TYPE)); + element.setDescription(document.get(KEY_DESCRIPTION)); + element.setVersion(document.get(KEY_VERSION)); + if ("1".equals(document.get(KEY_LATEST))) { + element.setLatest(true); + } else { + element.setLatest(false); + } + String creationDate = document.get(KEY_CREATIONDATE); + if (creationDate != null) { + long creationDateLong = new Long(creationDate); + Date date = new Date(creationDateLong); + element.setCreationDate(date); + } + element.setHash(document.get(KEY_HASH)); - List<Fieldable> fields = document.getFields(); - for (Fieldable fieldable : fields) { + Map<String, String> descriptors = new HashMap<String, String>(); + Map<String, ContentType> attachments = new HashMap<String, ContentType>(); - if (fieldable.name().startsWith(KEY_DESCRIPTOR)) { - String field = fieldable.name().replace(KEY_DESCRIPTOR + ".", - ""); - String value = fieldable.stringValue(); - descriptors.put(field, value); - } + List<Fieldable> fields = document.getFields(); + for (Fieldable fieldable : fields) { - if (fieldable.name().startsWith(KEY_ATTACHMENT)) { - String field = fieldable.name().replace(KEY_ATTACHMENT + ".", - ""); - String value = fieldable.stringValue(); - Content content = new Content(); - content.setType(ContentTypeFactory - .getContentTypeInstance(value)); - attachments.put(field, content); - } - } + if (fieldable.name().startsWith(KEY_DESCRIPTOR)) { + String field = fieldable.name().replace(KEY_DESCRIPTOR + ".", + ""); + String value = fieldable.stringValue(); + descriptors.put(field, value); + } - element.setDescriptors(descriptors); + if (fieldable.name().startsWith(KEY_ATTACHMENT)) { + String field = fieldable.name().replace(KEY_ATTACHMENT + ".", + ""); + String value = fieldable.stringValue(); + ContentType contentType = ContentTypeFactory + .getContentTypeInstance(value); + attachments.put(field, contentType); + } + } - element.setAttachments(attachments); + element.setDescriptors(descriptors); - element.setParentDataUuid(document.get(KEY_PARENTDATA_UUID)); - element.setParentDataVersion(document.get(KEY_PARENTDATA_VERSION)); + element.setAttachments(attachments); - element.setParentVersionUuid(document.get(KEY_PARENTVERSION_UUID)); - element - .setParentVersionVersion(document - .get(KEY_PARENTVERSION_VERSION)); + element.setParentDataUuid(document.get(KEY_PARENTDATA_UUID)); + element.setParentDataVersion(document.get(KEY_PARENTDATA_VERSION)); - return element; - } + element.setParentVersionUuid(document.get(KEY_PARENTVERSION_UUID)); + element + .setParentVersionVersion(document + .get(KEY_PARENTVERSION_VERSION)); - private void addSimpleField(Document document, String name, String value) { - if (value != null) { - Field f = new Field(name, value, Field.Store.YES, - Field.Index.UN_TOKENIZED); - document.add(f); - } - } + return element; + } - /** - * Transform an element to a Lucene document thanks to a factory - * - * @param factory - * @param element - * @return - * @throws Exception - */ - private Document saveLuceneElement(MetaDataEntity element, - List<Reader> readers) { - Document document = new Document(); + private void addSimpleField(Document document, String name, String value) { + if (value != null) { + Field f = new Field(name, value, Field.Store.YES, + Field.Index.UN_TOKENIZED); + document.add(f); + } + } - addSimpleField(document, KEY_UUID, element.getUuid()); - addSimpleField(document, KEY_NAME, element.getName()); - addSimpleField(document, KEY_TYPE, element.getType()); - addSimpleField(document, KEY_DESCRIPTION, element.getDescription()); - if (element.getVersion() != null) { - addSimpleField(document, KEY_VERSION, element.getVersion() - .toString()); - } - if (element.isLatest()) { - addSimpleField(document, KEY_LATEST, "1"); - } else { - addSimpleField(document, KEY_LATEST, "0"); - } + /** + * Transform an element to a Lucene document thanks to a factory + * + * @param factory + * @param element + * @return + * @throws Exception + */ + private Document saveLuceneElement(MetaDataEntity element, + List<Reader> readers) { + Document document = new Document(); - if (element.getCreationDate() != null) { - addSimpleField(document, KEY_CREATIONDATE, Long.toString(element - .getCreationDate().getTime())); - } - addSimpleField(document, KEY_HASH, element.getHash()); + addSimpleField(document, KEY_UUID, element.getUuid()); + addSimpleField(document, KEY_NAME, element.getName()); + addSimpleField(document, KEY_TYPE, element.getType()); + addSimpleField(document, KEY_DESCRIPTION, element.getDescription()); + if (element.getVersion() != null) { + addSimpleField(document, KEY_VERSION, element.getVersion() + .toString()); + } + if (element.isLatest()) { + addSimpleField(document, KEY_LATEST, "1"); + } else { + addSimpleField(document, KEY_LATEST, "0"); + } - Map<String, String> descriptors = element.getDescriptors(); - for (Map.Entry<String, String> entry : descriptors.entrySet()) { - String key = KEY_DESCRIPTOR + "." + entry.getKey(); - String value = entry.getValue(); - addSimpleField(document, key, value); - } + if (element.getCreationDate() != null) { + addSimpleField(document, KEY_CREATIONDATE, Long.toString(element + .getCreationDate().getTime())); + } + addSimpleField(document, KEY_HASH, element.getHash()); - Map<String, Content> attachments = element.getAttachments(); - for (Map.Entry<String, Content> entry : attachments.entrySet()) { - String key = KEY_ATTACHMENT + "." + entry.getKey(); - Content value = entry.getValue(); - if (value != null && value.getType() != null) { - addSimpleField(document, key, value.getType().getClass() - .getSimpleName()); - } - } + Map<String, String> descriptors = element.getDescriptors(); + for (Map.Entry<String, String> entry : descriptors.entrySet()) { + String key = KEY_DESCRIPTOR + "." + entry.getKey(); + String value = entry.getValue(); + addSimpleField(document, key, value); + } - addSimpleField(document, KEY_PARENTDATA_UUID, element - .getParentDataUuid()); - addSimpleField(document, KEY_PARENTDATA_VERSION, element - .getParentDataVersion()); - addSimpleField(document, KEY_PARENTVERSION_UUID, element - .getParentVersionUuid()); - addSimpleField(document, KEY_PARENTVERSION_VERSION, element - .getParentVersionVersion()); + Map<String, ContentType> attachments = element.getAttachments(); + for (Map.Entry<String, ContentType> entry : attachments.entrySet()) { + String key = KEY_ATTACHMENT + "." + entry.getKey(); + ContentType value = entry.getValue(); + if (value != null) { + addSimpleField(document, key, value.getClass().getSimpleName()); + } + } - for (Reader reader : readers) { - document.add(new Field(KEY_SEARCHABLE_CONTENT, reader)); - } + addSimpleField(document, KEY_PARENTDATA_UUID, element + .getParentDataUuid()); + addSimpleField(document, KEY_PARENTDATA_VERSION, element + .getParentDataVersion()); + addSimpleField(document, KEY_PARENTVERSION_UUID, element + .getParentVersionUuid()); + addSimpleField(document, KEY_PARENTVERSION_VERSION, element + .getParentVersionVersion()); - return document; - } + for (Reader reader : readers) { + document.add(new Field(KEY_SEARCHABLE_CONTENT, reader)); + } + return document; + } + } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2008-01-04 15:59:36 UTC (rev 94) @@ -8,7 +8,6 @@ import java.util.Set; import java.util.UUID; -import fr.cemagref.simexplorer.is.storage.attachment.Content; import fr.cemagref.simexplorer.is.storage.attachment.handler.AttachmentHandler; import fr.cemagref.simexplorer.is.storage.attachment.handler.FileSystemAttachmentHandler; import fr.cemagref.simexplorer.is.storage.attachment.type.ContentType; @@ -107,10 +106,8 @@ InputStream content = attachmentHandler .retrieveData(element, field); if (element.getAttachments() != null) { - Content contentInstance = element.getAttachments().get(field); - if (contentInstance != null - && contentInstance.getType() != null) { - ContentType contentType = contentInstance.getType(); + ContentType contentType = element.getAttachments().get(field); + if (contentType != null) { Reader reader = contentType.renderToText(content); readers.add(reader); } @@ -181,7 +178,8 @@ public MetaDataEntity[] findFullText(String query, boolean onlyLatest, int indexStart, int count, int dateOrder) throws Exception { MetaDataEntity[] result = database.findElementsByContentSearch(query, - onlyLatest, indexStart, count, dateOrder).toArray(new MetaDataEntity[0]); + onlyLatest, indexStart, count, dateOrder).toArray( + new MetaDataEntity[0]); return result; } @@ -208,8 +206,8 @@ public void deleteElement(String uuid, Version version) throws Exception { MetaDataEntity element = getMetadata(uuid, version); - Map<String, Content> attachments = element.getAttachments(); - for (Map.Entry<String, Content> entry : attachments.entrySet()) { + Map<String, ContentType> attachments = element.getAttachments(); + for (Map.Entry<String, ContentType> entry : attachments.entrySet()) { attachmentHandler.deleteData(element, entry.getKey()); } database.deleteElement(element); Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/BaseEntity.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/BaseEntity.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/BaseEntity.java 2008-01-04 15:59:36 UTC (rev 94) @@ -1,5 +1,7 @@ package fr.cemagref.simexplorer.is.storage.entities; -public abstract class BaseEntity { +import java.io.Serializable; +public abstract class BaseEntity implements Serializable { + } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Code.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Code.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Code.java 2008-01-04 15:59:36 UTC (rev 94) @@ -1,7 +1,11 @@ package fr.cemagref.simexplorer.is.storage.entities.data; -public class Code extends DataEntity { +import java.io.Serializable; +public class Code extends DataEntity implements Serializable { + + private static final long serialVersionUID = 1232989963544650014L; + private String language; private String code; Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Component.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Component.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Component.java 2008-01-04 15:59:36 UTC (rev 94) @@ -1,9 +1,12 @@ package fr.cemagref.simexplorer.is.storage.entities.data; +import java.io.Serializable; import java.util.Set; -public class Component extends LoggableElement { +public class Component extends LoggableElement implements Serializable { + private static final long serialVersionUID = -1759921918565071510L; + Set<Constant> constants; Set<Structure> structures; Set<Code> codes; Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Constant.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Constant.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Constant.java 2008-01-04 15:59:36 UTC (rev 94) @@ -1,7 +1,11 @@ package fr.cemagref.simexplorer.is.storage.entities.data; -public class Constant extends DataEntity { +import java.io.Serializable; +public class Constant extends DataEntity implements Serializable { + + private static final long serialVersionUID = 5473300963328292128L; + private String name; private Class<?> type; Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ConstantValue.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ConstantValue.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ConstantValue.java 2008-01-04 15:59:36 UTC (rev 94) @@ -1,7 +1,11 @@ package fr.cemagref.simexplorer.is.storage.entities.data; -public class ConstantValue extends DataEntity { +import java.io.Serializable; +public class ConstantValue extends DataEntity implements Serializable { + + private static final long serialVersionUID = -5434140706898012637L; + private String value; private Constant constant; Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/DataEntity.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/DataEntity.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/DataEntity.java 2008-01-04 15:59:36 UTC (rev 94) @@ -1,5 +1,7 @@ package fr.cemagref.simexplorer.is.storage.entities.data; +import java.io.Serializable; + import fr.cemagref.simexplorer.is.storage.entities.BaseEntity; public abstract class DataEntity extends BaseEntity { Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ExplorationApplication.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ExplorationApplication.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ExplorationApplication.java 2008-01-04 15:59:36 UTC (rev 94) @@ -1,9 +1,12 @@ package fr.cemagref.simexplorer.is.storage.entities.data; +import java.io.Serializable; import java.util.Set; -public class ExplorationApplication extends LoggableElement { +public class ExplorationApplication extends LoggableElement implements Serializable { + private static final long serialVersionUID = 122049347724394193L; + private Set<ExplorationData> explorations; private Set<Component> components; Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ExplorationData.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ExplorationData.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/ExplorationData.java 2008-01-04 15:59:36 UTC (rev 94) @@ -1,9 +1,12 @@ package fr.cemagref.simexplorer.is.storage.entities.data; +import java.io.Serializable; import java.util.Set; -public class ExplorationData extends LoggableElement { +public class ExplorationData extends LoggableElement implements Serializable { + private static final long serialVersionUID = -6439801837608358754L; + private Set<ConstantValue> valuesMap; private Result result; Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Library.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Library.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Library.java 2008-01-04 15:59:36 UTC (rev 94) @@ -1,5 +1,9 @@ package fr.cemagref.simexplorer.is.storage.entities.data; -public class Library extends LoggableElement { +import java.io.Serializable; +public class Library extends LoggableElement implements Serializable { + + private static final long serialVersionUID = -5635619075345573945L; + } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Repository.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Repository.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Repository.java 2008-01-04 15:59:36 UTC (rev 94) @@ -1,5 +1,9 @@ package fr.cemagref.simexplorer.is.storage.entities.data; -public class Repository extends DataEntity { +import java.io.Serializable; +public class Repository extends DataEntity implements Serializable { + + private static final long serialVersionUID = 1232065724338066924L; + } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Result.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Result.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/data/Result.java 2008-01-04 15:59:36 UTC (rev 94) @@ -1,5 +1,9 @@ package fr.cemagref.simexplorer.is.storage.entities.data; -public class Result extends DataEntity { +import java.io.Serializable; +public class Result extends DataEntity implements Serializable { + + private static final long serialVersionUID = 2111484866027162494L; + } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/metadata/MetaDataEntity.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/metadata/MetaDataEntity.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/entities/metadata/MetaDataEntity.java 2008-01-04 15:59:36 UTC (rev 94) @@ -4,229 +4,229 @@ import java.util.Date; import java.util.Map; -import fr.cemagref.simexplorer.is.storage.attachment.Content; +import fr.cemagref.simexplorer.is.storage.attachment.type.ContentType; import fr.cemagref.simexplorer.is.storage.entities.BaseEntity; public class MetaDataEntity extends BaseEntity implements Serializable { - private static final long serialVersionUID = -7916932464982315229L; - - private String uuid; - private String name; - private String type; - private String description; - private Version version; - private Date creationDate; - private String hash; - private Map<String, String> descriptors; - private Map<String, Content> attachments; - private String parentDataUuid; - private String parentDataVersion; - private String parentVersionUuid; - private String parentVersionVersion; - private boolean latest; + private static final long serialVersionUID = -7916932464982315229L; - /** - * @return the uuid - */ - public String getUuid() { - return uuid; - } + private String uuid; + private String name; + private String type; + private String description; + private Version version; + private Date creationDate; + private String hash; + private Map<String, String> descriptors; + private Map<String, ContentType> attachments; + private String parentDataUuid; + private String parentDataVersion; + private String parentVersionUuid; + private String parentVersionVersion; + private boolean latest; - /** - * @param uuid - * the uuid to set - */ - public void setUuid(String uuid) { - this.uuid = uuid; - } + /** + * @return the uuid + */ + public String getUuid() { + return uuid; + } - /** - * @return the name - */ - public String getName() { - return name; - } + /** + * @param uuid + * the uuid to set + */ + public void setUuid(String uuid) { + this.uuid = uuid; + } - /** - * @param name - * the name to set - */ - public void setName(String name) { - this.name = name; - } + /** + * @return the name + */ + public String getName() { + return name; + } - /** - * @return the type - */ - public String getType() { - return type; - } + /** + * @param name + * the name to set + */ + public void setName(String name) { + this.name = name; + } - /** - * @param type - * the type to set - */ - public void setType(String type) { - this.type = type; - } + /** + * @return the type + */ + public String getType() { + return type; + } - /** - * @return the description - */ - public String getDescription() { - return description; - } + /** + * @param type + * the type to set + */ + public void setType(String type) { + this.type = type; + } - /** - * @param description - * the description to set - */ - public void setDescription(String description) { - this.description = description; - } + /** + * @return the description + */ + public String getDescription() { + return description; + } - /** - * @return the version - */ - public Version getVersion() { - return version; - } + /** + * @param description + * the description to set + */ + public void setDescription(String description) { + this.description = description; + } - /** - * @param version - * the version to set - */ - public void setVersion(String version) { - this.version = new Version(version); - } + /** + * @return the version + */ + public Version getVersion() { + return version; + } - /** - * @return the creationDate - */ - public Date getCreationDate() { - return creationDate; - } + /** + * @param version + * the version to set + */ + public void setVersion(String version) { + this.version = new Version(version); + } - /** - * @param creationDate - * the creationDate to set - */ - public void setCreationDate(Date creationDate) { - this.creationDate = creationDate; - } + /** + * @return the creationDate + */ + public Date getCreationDate() { + return creationDate; + } - /** - * @return the hash - */ - public String getHash() { - return hash; - } + /** + * @param creationDate + * the creationDate to set + */ + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } - /** - * @param hash - * the hash to set - */ - public void setHash(String hash) { - this.hash = hash; - } + /** + * @return the hash + */ + public String getHash() { + return hash; + } - /** - * @return the descriptors - */ - public Map<String, String> getDescriptors() { - return descriptors; - } + /** + * @param hash + * the hash to set + */ + public void setHash(String hash) { + this.hash = hash; + } - /** - * @param descriptors - * the descriptors to set - */ - public void setDescriptors(Map<String, String> descriptors) { - this.descriptors = descriptors; - } + /** + * @return the descriptors + */ + public Map<String, String> getDescriptors() { + return descriptors; + } - /** - * @return the attachments - */ - public Map<String, Content> getAttachments() { - return attachments; - } + /** + * @param descriptors + * the descriptors to set + */ + public void setDescriptors(Map<String, String> descriptors) { + this.descriptors = descriptors; + } - /** - * @param attachments - * the attachments to set - */ - public void setAttachments(Map<String, Content> attachments) { - this.attachments = attachments; - } + /** + * @return the attachments + */ + public Map<String, ContentType> getAttachments() { + return attachments; + } - /** - * @return the parentDataUuid - */ - public String getParentDataUuid() { - return parentDataUuid; - } + /** + * @param attachments + * the attachments to set + */ + public void setAttachments(Map<String, ContentType> attachments) { + this.attachments = attachments; + } - /** - * @param parentDataUuid - * the parentDataUuid to set - */ - public void setParentDataUuid(String parentDataUuid) { - this.parentDataUuid = parentDataUuid; - } + /** + * @return the parentDataUuid + */ + public String getParentDataUuid() { + return parentDataUuid; + } - /** - * @return the parentDataVersion - */ - public String getParentDataVersion() { - return parentDataVersion; - } + /** + * @param parentDataUuid + * the parentDataUuid to set + */ + public void setParentDataUuid(String parentDataUuid) { + this.parentDataUuid = parentDataUuid; + } - /** - * @param parentDataVersion - * the parentDataVersion to set - */ - public void setParentDataVersion(String parentDataVersion) { - this.parentDataVersion = parentDataVersion; - } + /** + * @return the parentDataVersion + */ + public String getParentDataVersion() { + return parentDataVersion; + } - /** - * @return the parentVersionUuid - */ - public String getParentVersionUuid() { - return parentVersionUuid; - } + /** + * @param parentDataVersion + * the parentDataVersion to set + */ + public void setParentDataVersion(String parentDataVersion) { + this.parentDataVersion = parentDataVersion; + } - /** - * @param parentVersionUuid - * the parentVersionUuid to set - */ - public void setParentVersionUuid(String parentVersionUuid) { - this.parentVersionUuid = parentVersionUuid; - } + /** + * @return the parentVersionUuid + */ + public String getParentVersionUuid() { + return parentVersionUuid; + } - /** - * @return the parentVersionVersion - */ - public String getParentVersionVersion() { - return parentVersionVersion; - } + /** + * @param parentVersionUuid + * the parentVersionUuid to set + */ + public void setParentVersionUuid(String parentVersionUuid) { + this.parentVersionUuid = parentVersionUuid; + } - /** - * @param parentVersionVersion - * the parentVersionVersion to set - */ - public void setParentVersionVersion(String parentVersionVersion) { - this.parentVersionVersion = parentVersionVersion; - } + /** + * @return the parentVersionVersion + */ + public String getParentVersionVersion() { + return parentVersionVersion; + } - public boolean isLatest() { - return latest; - } + /** + * @param parentVersionVersion + * the parentVersionVersion to set + */ + public void setParentVersionVersion(String parentVersionVersion) { + this.parentVersionVersion = parentVersionVersion; + } - public void setLatest(boolean latest) { - this.latest = latest; - } + public boolean isLatest() { + return latest; + } + public void setLatest(boolean latest) { + this.latest = latest; + } + } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/BaseEntityFactory.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/BaseEntityFactory.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/BaseEntityFactory.java 2008-01-04 15:59:36 UTC (rev 94) @@ -1,7 +1,8 @@ package fr.cemagref.simexplorer.is.storage.factories; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.OutputStream; +import java.io.InputStream; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -23,33 +24,37 @@ import fr.cemagref.simexplorer.is.storage.entities.BaseEntity; import fr.cemagref.simexplorer.is.storage.entities.data.DataEntity; -public abstract class BaseEntityFactory<E extends BaseEntity> { +public abstract class BaseEntityFactory<E extends BaseEntity> implements + XmlConstants { private static DocumentBuilder documentBuilder = null; private static Map<String, BaseEntityFactory<? extends DataEntity>> factories = new HashMap<String, BaseEntityFactory<? extends DataEntity>>(); - private final static String PACKAGE_DAO = "fr.cemagref.simexplorer.is.storage.factories"; + /* + * Static methods - Retrieve factories, get XML document builder + */ - public static synchronized DocumentBuilder getBuilder() throws Exception { - if (documentBuilder == null) { - DocumentBuilderFactory factory = DocumentBuilderFactory - .newInstance(); - documentBuilder = factory.newDocumentBuilder(); - return documentBuilder; - } - return documentBuilder; - } - - // @SuppressWarnings("unchecked") + /** + * Retrieve instance of the factory + * + * @param <T> + * Factory spec. class + * @param entityClass + * Class wanted + * @return Factory + * @throws Exception + */ + @SuppressWarnings("unchecked") public static <T extends DataEntity> BaseEntityFactory<T> getFactory( Class entityClass) throws Exception { // FIXME Raw types and unchecked casts BaseEntityFactory<T> result = (BaseEntityFactory<T>) factories .get(entityClass.getSimpleName()); if (result == null) { - String elementFactoryClassName = PACKAGE_DAO + "." - + entityClass.getSimpleName() + "Factory"; + String elementFactoryClassName = BaseEntityFactory.class + .getPackage().getName() + + "." + entityClass.getSimpleName() + "Factory"; Class<? extends BaseEntityFactory<T>> factoryClass = (Class<? extends BaseEntityFactory<T>>) Class .forName(elementFactoryClassName).asSubclass( @@ -61,6 +66,13 @@ return result; } + /** + * Retrieve a factory with class name + * + * @param entityClassName + * @return + * @throws Exception + */ public static BaseEntityFactory<? extends DataEntity> getFactory( String entityClassName) throws Exception { Class<? extends DataEntity> entityClass = Class @@ -68,39 +80,52 @@ return getFactory(entityClass); } - public abstract E createInstance(); - - public Element getElementByTagName(Element xmlElement, String tagName) { - Set<Element> elements = getElementsByTagName(xmlElement, tagName); - if (elements.size() > 0) { - return elements.iterator().next(); - } else { - return null; + /** + * Retrieve an instance of document builder + * + * @return XML document builder + * @throws Exception + */ + public static synchronized DocumentBuilder getXMLBuilder() throws Exception { + if (documentBuilder == null) { + DocumentBuilderFactory factory = DocumentBuilderFactory + .newInstance(); + documentBuilder = factory.newDocumentBuilder(); + return documentBuilder; } + return documentBuilder; } - public Set<Element> getElementsByTagName(Element xmlElement, String tagName) { - Set<Element> elements = new HashSet<Element>(); + /* + * Entity methods - Instanciate, load and save to XML/streams + */ - 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; + /** + * Instanciate an element + * + * @return Element + */ + public abstract E createInstance(); + + public E loadElement(Element xmlElement) throws Exception { + E element = createInstance(); + return element; } - public String getElementXML(E element) throws Exception { - ByteArrayOutputStream writer = new ByteArrayOutputStream(); - getElementXML(element, writer); - return writer.toString(); + public E loadElement(InputStream stream) throws Exception { + Document document = getXMLBuilder().parse(stream); + Element rootElement = (Element) document.getFirstChild(); + E element = loadElement(rootElement); + return element; } - public void getElementXML(E element, OutputStream os) throws Exception { - org.w3c.dom.Document xmlDocument = getBuilder().newDocument(); + public abstract void saveElement(Document document, Element xmlElement, + E element) throws Exception; + + public InputStream saveElement(E element) throws Exception { + ByteArrayOutputStream os = new ByteArrayOutputStream(); + + org.w3c.dom.Document xmlDocument = getXMLBuilder().newDocument(); // Propriétés du DOM xmlDocument.setXmlVersion("1.0"); xmlDocument.setXmlStandalone(true); @@ -108,7 +133,7 @@ Element racine = xmlDocument.createElement(element.getClass() .getSimpleName()); - saveXMLElement(xmlDocument, racine, element); + saveElement(xmlDocument, racine, element); xmlDocument.appendChild(racine); DOMSource domSource = new DOMSource(xmlDocument); @@ -116,29 +141,28 @@ TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.transform(domSource, result); - } - public String getProperty(Element xmlElement, String tagName) { - Element element = getElementByTagName(xmlElement, tagName); - if (element != null) { - return element.getFirstChild().getNodeValue(); - } else { - return null; - } + InputStream is = new ByteArrayInputStream(os.toByteArray()); + + return is; } + /* + * Collection methods : Help load/save of inner collections + */ + public <T extends DataEntity> Set<T> loadCollection(String tagSetName, String tagName, Class<T> clazz, Element xmlElement, DataEntity parentData) throws Exception { Set<T> entities = new HashSet<T>(); - Element xmlCollection = getElementByTagName(xmlElement, tagSetName); + Element xmlCollection = getXMLElementByTagName(xmlElement, tagSetName); if (xmlCollection != null) { BaseEntityFactory<T> elementFactory = getFactory(clazz); - Set<Element> list = getElementsByTagName(xmlCollection, tagName); + Set<Element> list = getXMLElementsByTagName(xmlCollection, tagName); for (Element element : list) { - T entity = elementFactory.loadXMLElement(element); + T entity = elementFactory.loadElement(element); entity.setParentData(parentData); entities.add(entity); } @@ -147,11 +171,6 @@ return entities; } - public E loadXMLElement(Element xmlElement) throws Exception { - E element = createInstance(); - return element; - } - public <T extends DataEntity> void saveCollection(Set<T> entities, String tagSetName, String tagName, Class<T> clazz, Document document, Element xmlElement) throws Exception { @@ -163,17 +182,40 @@ // TODO // if (entity instanceof LoggableElement) { // elementFactory.saveXMLElementByReference - elementFactory.saveXMLElement(document, childElement, entity); + elementFactory.saveElement(document, childElement, entity); xmlCollection.appendChild(childElement); } xmlElement.appendChild(xmlCollection); } } - public abstract void saveXMLElement(Document document, Element xmlElement, - E element) throws Exception; + public static InputStream serializeElement(String rootNode, Element node) + throws Exception { + org.w3c.dom.Document xmlDocument = getXMLBuilder().newDocument(); + // Propriétés du DOM + xmlDocument.setXmlVersion("1.0"); + xmlDocument.setXmlStandalone(true); + // Création de l'arborescence du DOM + xmlDocument.appendChild(xmlDocument.importNode(node, true)); + DOMSource domSource = new DOMSource(xmlDocument); - protected void setProperty(Document document, Element xmlElement, + ByteArrayOutputStream os = new ByteArrayOutputStream(); + StreamResult result = new StreamResult(os); + TransformerFactory tf = TransformerFactory.newInstance(); + Transformer transformer = tf.newTransformer(); + transformer.transform(domSource, result); + + ByteArrayInputStream inputStream = new ByteArrayInputStream(os + .toByteArray()); + + return inputStream; + } + + /* + * XML methods : set, get properties + */ + + protected void setXMLProperty(Document document, Element xmlElement, String tagName, Object value) { if (value != null) { Element xmlProperty = document.createElement(tagName); @@ -183,4 +225,67 @@ } } + public String getXMLProperty(Element xmlElement, String tagName) { + Element element = getXMLElementByTagName(xmlElement, tagName); + if (element != null) { + return element.getFirstChild().getNodeValue(); + } else { + return null; + } + } + + /* + * XML methods : retrieve nodes + */ + + /** + * @param xmlElement + * @param tagName + * @return + */ + public Element getXMLElementByTagName(Element xmlElement, String tagName) { + Set<Element> elements = getXMLElementsByTagName(xmlElement, tagName); + if (elements.size() > 0) { + return elements.iterator().next(); + } else { + return null; + } + } + + public Set<Element> getXMLElementsByTagName(Element xmlElement, + String tagName) { + Set<Element> elements = new HashSet<Element>(); + + NodeList nodes = xmlElement.getChildNodes(); + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + if (node instanceof Element + && tagName.equals(((Element) node).getTagName())) { + elements.add((Element) node); + } + } + return elements; + } + + /* + * public void getXMLStream(E element, OutputStream os) throws Exception { + * org.w3c.dom.Document xmlDocument = getXMLBuilder().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()); + * + * saveElement(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 getXMLString(E element) throws Exception { + * ByteArrayOutputStream writer = new ByteArrayOutputStream(); + * getXMLStream(element, writer); return writer.toString(); } + */ + } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/CodeFactory.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/CodeFactory.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/CodeFactory.java 2008-01-04 15:59:36 UTC (rev 94) @@ -7,27 +7,25 @@ public class CodeFactory<E extends Code> extends BaseEntityFactory<Code> { - public static final String KEY_LANGUAGE = "language"; - public static final String KEY_CODE = "code"; - @Override public Code createInstance() { return new Code(); } @Override - public Code loadXMLElement(Element xmlElement) throws Exception { - Code code = super.loadXMLElement(xmlElement); - code.setLanguage(getProperty(xmlElement, KEY_LANGUAGE)); - code.setCode(getProperty(xmlElement, KEY_CODE)); + public Code loadElement(Element xmlElement) throws Exception { + Code code = super.loadElement(xmlElement); + code.setLanguage(getXMLProperty(xmlElement, KEY_CODE_LANGUAGE)); + code.setCode(getXMLProperty(xmlElement, KEY_CODE_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()); + public void saveElement(Document document, Element xmlElement, Code element) + throws Exception { + setXMLProperty(document, xmlElement, KEY_CODE_LANGUAGE, element + .getLanguage()); + setXMLProperty(document, xmlElement, KEY_CODE_CODE, element.getCode()); } } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ComponentFactory.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ComponentFactory.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ComponentFactory.java 2008-01-04 15:59:36 UTC (rev 94) @@ -10,49 +10,48 @@ import fr.cemagref.simexplorer.is.storage.entities.data.Structure; public class ComponentFactory<E extends Component> extends - BaseEntityFactory<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"; - @Override public Component createInstance() { return new Component(); } @Override - public Component loadXMLElement(Element xmlElement) throws Exception { - Component component = super.loadXMLElement(xmlElement); + public Component loadElement(Element xmlElement) throws Exception { + Component component = super.loadElement(xmlElement); - component.setConstants(loadCollection(KEY_CONSTANTS, KEY_CONSTANT_NODE, - Constant.class, xmlElement, component)); - component.setStructures(loadCollection(KEY_STRUCTURE, - KEY_STRUCTURE_NODE, Structure.class, xmlElement, component)); - component.setCodes(loadCollection(KEY_CODES, KEY_CODE_NODE, Code.class, - xmlElement, component)); - component.setLibraries(loadCollection(KEY_LIBRARIES, KEY_LIBRARY_NODE, - Library.class, xmlElement, component)); + component.setConstants(loadCollection(KEY_COMPONENT_CONSTANTS, + KEY_COMPONENT_CONSTANT_NODE, Constant.class, xmlElement, + component)); + component.setStructures(loadCollection(KEY_COMPONENT_STRUCTURE, + KEY_COMPONENT_STRUCTURE_NODE, Structure.class, xmlElement, + component)); + component.setCodes(loadCollection(KEY_COMPONENT_CODES, + KEY_COMPONENT_CODE_NODE, Code.class, xmlElement, component)); + component.setLibraries(loadCollection(KEY_COMPONENT_LIBRARIES, + KEY_COMPONENT_LIBRARY_NODE, Library.class, xmlElement, + component)); return component; } @Override - public void saveXMLElement(Document document, Element xmlElement, + public void saveElement(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.saveElement(document, xmlElement, element); + + saveCollection(element.getConstants(), KEY_COMPONENT_CONSTANTS, + KEY_COMPONENT_CONSTANT_NODE, Constant.class, document, + xmlElement); + saveCollection(element.getStructures(), KEY_COMPONENT_STRUCTURE, + KEY_COMPONENT_STRUCTURE_NODE, Structure.class, document, + xmlElement); + saveCollection(element.getCodes(), KEY_COMPONENT_CODES, + KEY_COMPONENT_CODE_NODE, Code.class, document, xmlElement); + saveCollection(element.getLibraries(), KEY_COMPONENT_LIBRARIES, + KEY_COMPONENT_LIBRARY_NODE, Library.class, document, xmlElement); } } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantFactory.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantFactory.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantFactory.java 2008-01-04 15:59:36 UTC (rev 94) @@ -8,29 +8,27 @@ public class ConstantFactory<E extends Constant> extends BaseEntityFactory<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); + public Constant loadElement(Element xmlElement) throws Exception { + Constant constant = super.loadElement(xmlElement); + constant.setName(getXMLProperty(xmlElement, KEY_CONSTANT_NAME)); + String className = getXMLProperty(xmlElement, KEY_CONSTANT_TYPE); constant.setType(Class.forName(className)); return constant; } @Override - public void saveXMLElement(Document document, Element xmlElement, + public void saveElement(Document document, Element xmlElement, Constant element) throws Exception { - setProperty(document, xmlElement, KEY_NAME, element.getName()); + setXMLProperty(document, xmlElement, KEY_CONSTANT_NAME, element + .getName()); String className = element.getType().getName(); - setProperty(document, xmlElement, KEY_TYPE, className); + setXMLProperty(document, xmlElement, KEY_CONSTANT_TYPE, className); } } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantValueFactory.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantValueFactory.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ConstantValueFactory.java 2008-01-04 15:59:36 UTC (rev 94) @@ -9,33 +9,35 @@ public class ConstantValueFactory<E extends ConstantValue> extends BaseEntityFactory<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); + public ConstantValue loadElement(Element xmlElement) throws Exception { + ConstantValue constantValue = super.loadElement(xmlElement); constantValue.setConstant((Constant) getFactory(Constant.class) - .loadXMLElement(getElementByTagName(xmlElement, KEY_CONSTANT))); - constantValue.setValue(getProperty(xmlElement, KEY_VALUE)); + .loadElement( + getXMLElementByTagName(xmlElement, + KEY_CONSTANTVALUE_CONSTANT))); + constantValue.setValue(getXMLProperty(xmlElement, + KEY_CONSTANTVALUE_VALUE)); return constantValue; } @Override - public void saveXMLElement(Document document, Element xmlElement, + public void saveElement(Document document, Element xmlElement, ConstantValue element) throws Exception { - Element xmlConstant = document.createElement(KEY_CONSTANT); - getFactory(Constant.class).saveXMLElement(document, xmlConstant, + Element xmlConstant = document + .createElement(KEY_CONSTANTVALUE_CONSTANT); + getFactory(Constant.class).saveElement(document, xmlConstant, element.getConstant()); xmlElement.appendChild(xmlConstant); - setProperty(document, xmlElement, KEY_VALUE, element.getValue()); + setXMLProperty(document, xmlElement, KEY_CONSTANTVALUE_VALUE, element + .getValue()); } } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationApplicationFactory.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationApplicationFactory.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationApplicationFactory.java 2008-01-04 15:59:36 UTC (rev 94) @@ -10,37 +10,33 @@ 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, + public ExplorationApplication createInstance() { + return new ExplorationApplication(); + } + + @Override + public void saveElement(Document document, Element xmlElement, ExplorationApplication element) throws Exception { - super.saveXMLElement(document, xmlElement, element); - saveCollection(element.getExplorations(), KEY_DATA, KEY_DATA_NODE, + super.saveElement(document, xmlElement, element); + saveCollection(element.getExplorations(), KEY_EXPLORATIONAPPLICATION_DATA, KEY_EXPLORATIONAPPLICATION_DATA_NODE, ExplorationData.class, document, xmlElement); - saveCollection(element.getComponents(), KEY_COMPONENTS, - KEY_COMPONENT_NODE, Component.class, document, xmlElement); + saveCollection(element.getComponents(), KEY_EXPLORATIONAPPLICATION_COMPONENTS, + KEY_EXPLORATIONAPPLICATION_COMPONENT_NODE, Component.class, document, xmlElement); } @Override - public ExplorationApplication loadXMLElement(Element xmlElement) + public ExplorationApplication loadElement(Element xmlElement) throws Exception { ExplorationApplication explorationApplication = super - .loadXMLElement(xmlElement); - explorationApplication.setExplorations(loadCollection(KEY_DATA, - KEY_DATA_NODE, ExplorationData.class, xmlElement, + .loadElement(xmlElement); + explorationApplication.setExplorations(loadCollection(KEY_EXPLORATIONAPPLICATION_DATA, + KEY_EXPLORATIONAPPLICATION_DATA_NODE, ExplorationData.class, xmlElement, explorationApplication)); - explorationApplication.setComponents(loadCollection(KEY_COMPONENTS, - KEY_COMPONENT_NODE, Component.class, xmlElement, + explorationApplication.setComponents(loadCollection(KEY_EXPLORATIONAPPLICATION_COMPONENTS, + KEY_EXPLORATIONAPPLICATION_COMPONENT_NODE, Component.class, xmlElement, explorationApplication)); 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/fr/cemagref/simexplorer/is/storage/factories/ExplorationDataFactory.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ExplorationDataFactory.java 2008-01-04 15:59:36 UTC (rev 94) @@ -10,38 +10,38 @@ public class ExplorationDataFactory extends LoggableElementFactory<ExplorationData> { - public static final String KEY_RESULT = "result"; - public static final String KEY_VALUES = "values"; - public static final String KEY_VALUE = "value"; + @Override + public ExplorationData createInstance() { + return new ExplorationData(); + } @Override - public ExplorationData loadXMLElement(Element xmlElement) throws Exception { - ExplorationData explorationData = super.loadXMLElement(xmlElement); + public ExplorationData loadElement(Element xmlElement) throws Exception { + ExplorationData explorationData = super.loadElement(xmlElement); explorationData.setResult((Result) getFactory(Result.class) - .loadXMLElement(getElementByTagName(xmlElement, KEY_RESULT))); - explorationData.setValuesMap(loadCollection(KEY_VALUES, KEY_VALUE, - ConstantValue.class, xmlElement, explorationData)); + .loadElement( + getXMLElementByTagName(xmlElement, + KEY_EXPLORATIONDATA_RESULT))); + explorationData.setValuesMap(loadCollection(KEY_EXPLORATIONDATA_VALUES, + KEY_EXPLORATIONDATA_VALUE, ConstantValue.class, xmlElement, + explorationData)); return explorationData; } @Override - public void saveXMLElement(Document document, Element xmlElement, + public void saveElement(Document document, Element xmlElement, ExplorationData element) throws Exception { - super.saveXMLElement(document, xmlElement, element); + super.saveElement(document, xmlElement, element); - Element xmlResult = document.createElement(KEY_RESULT); - getFactory(Result.class).saveXMLElement(document, xmlResult, + Element xmlResult = document.createElement(KEY_EXPLORATIONDATA_RESULT); + getFactory(Result.class).saveElement(document, xmlResult, element.getResult()); xmlElement.appendChild(xmlResult); - saveCollection(element.getValuesMap(), KEY_VALUES, KEY_VALUE, - ConstantValue.class, document, xmlElement); + saveCollection(element.getValuesMap(), KEY_EXPLORATIONDATA_VALUES, + KEY_EXPLORATIONDATA_VALUE, ConstantValue.class, document, + xmlElement); } - @Override - public ExplorationData createInstance() { - return new ExplorationData(); - } - } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LoggableElementFactory.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LoggableElementFactory.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/LoggableElementFactory.java 2008-01-04 15:59:36 UTC (rev 94) @@ -2,25 +2,35 @@ import org.w3c.dom.Element; -import fr.cemagref.simexplorer.is.storage.database.DatabaseConstants; import fr.cemagref.simexplorer.is.storage.entities.data.LoggableElement; +import fr.cemagref.simexplorer.is.storage.entities.metadata.MetaDataEntity; public abstract class LoggableElementFactory<E extends LoggableElement> extends - BaseEntityFactory<E> implements DatabaseConstants { + BaseEntityFactory<E> { - private static final String KEY_DESCRIPTION = "description"; + @Override + public E loadElement(Element xmlElement) throws Exception { + E element = super.loadElement(xmlElement); - @Override - public E loadXMLElement(Element xmlElement) throws Exception { - E element = super.loadXMLElement(xmlElement); - // FIXME Load metadata + MetaDataEntityFactory elementFactory = (MetaDataEntityFactory) BaseEntityFactory + .getFactory(MetaDataEntity.class); + + Element mdeElement = getXMLElementByTagName(xmlElement, KEY_METADATA); + MetaDataEntity metaData = elementFactory.loadElement(mdeElement); + element.setMetaData(metaData); + return element; } @Override - public void saveXMLElement(org.w3c.dom.Document document, - Element xmlElement, E element) throws Exception { - // FIXME save metadata + public void saveElement(org.w3c.dom.Document document, Element xmlElement, + E element) throws Exception { + MetaDataEntityFactory elementFactory = (MetaDataEntityFactory) BaseEntityFactory + .getFactory(MetaDataEntity.class); + + Element mdeElement = document.createElement(KEY_METADATA); + elementFactory.saveElement(document, mdeElement, element.getMetaData()); + xmlElement.appendChild(mdeElement); } } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/MetaDataEntityFactory.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/MetaDataEntityFactory.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/MetaDataEntityFactory.java 2008-01-04 15:59:36 UTC (rev 94) @@ -1,5 +1,6 @@ package fr.cemagref.simexplorer.is.storage.factories; +import java.io.InputStream; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -8,12 +9,12 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; -import fr.cemagref.simexplorer.is.storage.attachment.Content; +import fr.cemagref.simexplorer.is.storage.attachment.type.ContentType; import fr.cemagref.simexplorer.is.storage.attachment.type.ContentTypeFactory; import fr.cemagref.simexplorer.is.storage.entities.metadata.MetaDataEntity; public class MetaDataEntityFactory<E extends MetaDataEntity> extends - BaseEntityFactory<MetaDataEntity> implements XmlConstants { + BaseEntityFactory<MetaDataEntity> { @Override public MetaDataEntity createInstance() { @@ -26,17 +27,16 @@ * @see fr.cemagref.simexplorer.is.storage.factories.BaseEntityFactory#loadXMLElement(org.w3c.dom.Element) */ @Override - public MetaDataEntity loadXMLElement(Element xmlElement) throws Exception { - MetaDataEntity entity = super.loadXMLElement(xmlElement); - entity.setUuid(getProperty(xmlElement, KEY_METADATA_UUID)); - entity.setName(getProperty(xmlElement, KEY_METADATA_NAME)); - entity.setType(getProperty(xmlElement, KEY_METADATA_TYPE)); - entity - .setDescription(getProperty(xmlElement, - KEY_METADATA_DESCRIPTION)); - entity.setVersion(getProperty(xmlElement, KEY_METADATA_VERSION)); + public MetaDataEntity loadElement(Element xmlElement) throws Exception { + MetaDataEntity entity = super.loadElement(xmlElement); + entity.setUuid(getXMLProperty(xmlElement, KEY_METADATA_UUID)); + entity.setName(getXMLProperty(xmlElement, KEY_METADATA_NAME)); + entity.setType(getXMLProperty(xmlElement, KEY_METADATA_TYPE)); + entity.setDescription(getXMLProperty(xmlElement, + KEY_METADATA_DESCRIPTION)); + entity.setVersion(getXMLProperty(xmlElement, KEY_METADATA_VERSION)); - String latestVersion = getProperty(xmlElement, + String latestVersion = getXMLProperty(xmlElement, KEY_METADATA_LATESTVERSION); if (latestVersion != null && "1".equals(latestVersion)) { entity.setLatest(true); @@ -44,57 +44,56 @@ entity.setLatest(false); } - String creationDate = getProperty(xmlElement, KEY_METADATA_CREATIONDATE); + String creationDate = getXMLProperty(xmlElement, + KEY_METADATA_CREATIONDATE); if (creationDate != null) { long creationDateLong = new Long(creationDate); Date date = new Date(creationDateLong); entity.setCreationDate(date); } - entity.setHash(getProperty(xmlElement, KEY_METADATA_HASH)); - entity.setParentDataUuid(getProperty(xmlElement, + entity.setHash(getXMLProperty(xmlElement, KEY_METADATA_HASH)); + entity.setParentDataUuid(getXMLProperty(xmlElement, KEY_METADATA_PARENTDATA_UUID)); - entity.setParentDataVersion(getProperty(xmlElement, + entity.setParentDataVersion(getXMLProperty(xmlElement, KEY_METADATA_PARENTDATA_VERSION)); - entity.setParentVersionUuid(getProperty(xmlElement, + entity.setParentVersionUuid(getXMLProperty(xmlElement, KEY_METADATA_PARENTVERSION_UUID)); - entity.setParentVersionVersion(getProperty(xmlElement, + entity.setParentVersionVersion(getXMLProperty(xmlElement, KEY_METADATA_PARENTVERSION_VERSION)); Map<String, String> descriptors = new HashMap<String, String>(); - Element descriptorsElement = getElementByTagName(xmlElement, + Element descriptorsElement = getXMLElementByTagName(xmlElement, KEY_METADATA_DESCRIPTORS); if (descriptorsElement != null) { - Set<Element> descriptorElements = getElementsByTagName( + Set<Element> descriptorElements = getXMLElementsByTagName( descriptorsElement, KEY_METADATA_DESCRIPTOR); for (Element descriptorElement : descriptorElements) { - String name = getProperty(descriptorElement, - KEY_DESCRIPTOR_NAME); - String value = getProperty(descriptorElement, - KEY_DESCRIPTOR_VALUE); + String name = getXMLProperty(descriptorElement, + KEY_METADATA_DESCRIPTOR_NAME); + String value = getXMLProperty(descriptorElement, + KEY_METADATA_DESCRIPTOR_VALUE); descriptors.put(name, value); } } entity.setDescriptors(descriptors); - Map<String, Content> attachments = new HashMap<String, Content>(); + Map<String, ContentType> attachments = new HashMap<String, ContentType>(); - Element attachmentsElement = getElementByTagName(xmlElement, + Element attachmentsElement = getXMLElementByTagName(xmlElement, KEY_METADATA_ATTACHMENTS); if (attachmentsElement != null) { - Set<Element> attachmentElements = getElementsByTagName( + Set<Element> attachmentElements = getXMLElementsByTagName( attachmentsElement, KEY_METADATA_ATTACHMENT); for (Element attachmentElement : attachmentElements) { - String name = getProperty(attachmentElement, - KEY_ATTACHMENT_NAME); - String type = getProperty(attachmentElement, - KEY_ATTACHMENT_TYPE); - Content content = new Content(); - content - .setType(ContentTypeFactory - .getContentTypeInstance(type)); - attachments.put(name, content); + String name = getXMLProperty(attachmentElement, + KEY_METADATA_ATTACHMENT_NAME); + String type = getXMLProperty(attachmentElement, + KEY_METADATA_ATTACHMENT_TYPE); + ContentType contentType = ContentTypeFactory + .getContentTypeInstance(type); + attachments.put(name, contentType); } } @@ -104,10 +103,92 @@ } @Override - public void saveXMLElement(Document document, Element xmlElement, + public void saveElement(Document document, Element xmlElement, MetaDataEntity element) throws Exception { - // TODO Auto-generated method stub + setXMLProperty(document, xmlElement, KEY_METADATA_UUID, element + .getUuid()); + setXMLProperty(document, xmlElement, KEY_METADATA_NAME, element + .getName()); + setXMLProperty(document, xmlElement, KEY_METADATA_TYPE, element + .getType()); + setXMLProperty(document, xmlElement, KEY_METADATA_DESCRIPTION, element + .getDescription()); + setXMLProperty(document, xmlElement, KEY_METADATA_VERSION, element + .getVersion().toString()); + + if (element.isLatest()) { + setXMLProperty(document, xmlElement, KEY_METADATA_LATESTVERSION, + "1"); + } else { + setXMLProperty(document, xmlElement, KEY_METADATA_LATESTVERSION, + "0"); + } + + if (element.getCreationDate() != null) { + setXMLProperty(document, xmlElement, KEY_METADATA_CREATIONDATE, + element.getCreationDate().getTime()); + } + + setXMLProperty(document, xmlElement, KEY_METADATA_HASH, element + .getHash()); + setXMLProperty(document, xmlElement, KEY_METADATA_PARENTDATA_UUID, + element.getParentDataUuid()); + setXMLProperty(document, xmlElement, KEY_METADATA_PARENTDATA_VERSION, + element.getParentDataVersion()); + setXMLProperty(document, xmlElement, KEY_METADATA_PARENTVERSION_UUID, + element.getParentVersionUuid()); + setXMLProperty(document, xmlElement, + KEY_METADATA_PARENTVERSION_VERSION, element + .getParentVersionVersion()); + + Map<String, String> descriptors = element.getDescriptors(); + + Element descriptorsElement = document + .createElement(KEY_METADATA_DESCRIPTORS); + + for (Map.Entry<String, String> kv : descriptors.entrySet()) { + Element descriptorElement = document + .createElement(KEY_METADATA_DESCRIPTOR); + setXMLProperty(document, descriptorElement, + KEY_METADATA_DESCRIPTOR_NAME, kv.getKey()); + setXMLProperty(document, descriptorElement, + KEY_METADATA_DESCRIPTOR_VALUE, kv.getValue()); + descriptorsElement.appendChild(descriptorElement); + } + + xmlElement.appendChild(descriptorsElement); + + Map<String, ContentType> attachments = element.getAttachments(); + + if (attachments != null) { + + Element attachmentsElement = document + .createElement(KEY_METADATA_ATTACHMENTS); + + for (Map.Entry<String, ContentType> kv : attachments.entrySet()) { + Element attachmentElement = document + .createElement(KEY_METADATA_ATTACHMENT); + setXMLProperty(document, attachmentElement, + KEY_METADATA_ATTACHMENT_NAME, kv.getKey()); + setXMLProperty(document, attachmentElement, + KEY_METADATA_ATTACHMENT_TYPE, kv.getValue().getClass() + .getSimpleName()); + attachmentsElement.appendChild(attachmentElement); + } + xmlElement.appendChild(attachmentsElement); + + } + } + public MetaDataEntity loadElementFromParentXML(InputStream xmlStream) + throws Exception { + Document document = getXMLBuilder().parse(xmlStream); + Element rootElement = (Element) document.getFirstChild(); + Element mdeElement = getXMLElementByTagName(rootElement, KEY_METADATA); + MetaDataEntity mde = loadElement(mdeElement); + return mde; + } + } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/RepositoryFactory.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/RepositoryFactory.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/RepositoryFactory.java 2008-01-04 15:59:36 UTC (rev 94) @@ -14,7 +14,12 @@ } @Override - public void saveXMLElement(Document document, Element xmlElement, + public Repository loadElement(Element xmlElement) throws Exception { + return super.loadElement(xmlElement); + } + + @Override + public void saveElement(Document document, Element xmlElement, Repository element) throws Exception { } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ResultFactory.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ResultFactory.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/ResultFactory.java 2008-01-04 15:59:36 UTC (rev 94) @@ -13,7 +13,12 @@ } @Override - public void saveXMLElement(Document document, Element xmlElement, + public Result loadElement(Element xmlElement) throws Exception { + return super.loadElement(xmlElement); + } + + @Override + public void saveElement(Document document, Element xmlElement, Result element) throws Exception { } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/XmlConstants.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/XmlConstants.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/factories/XmlConstants.java 2008-01-04 15:59:36 UTC (rev 94) @@ -2,14 +2,44 @@ public interface XmlConstants { + public static final String KEY_CODE_LANGUAGE = "language"; + public static final String KEY_CODE_CODE = "code"; + + public static final String KEY_COMPONENT_CONSTANTS = "constants"; + public static final String KEY_COMPONENT_CONSTANT_NODE = "constant"; + public static final String KEY_COMPONENT_STRUCTURE = "structures"; + public static final String KEY_COMPONENT_STRUCTURE_NODE = "structure"; + public static final String KEY_COMPONENT_CODES = "codes"; + public static final String KEY_COMPONENT_CODE_NODE = "code"; + public static final String KEY_COMPONENT_LIBRARIES = "libraries"; + public static final String KEY_COMPONENT_LIBRARY_NODE = "library"; + + public static final String KEY_CONSTANT_NAME = "name"; + public static final String KEY_CONSTANT_TYPE = "type"; + + public static final String KEY_CONSTANTVALUE_CONSTANT = "constant"; + public static final String KEY_CONSTANTVALUE_VALUE = "value"; + + public static final String KEY_EXPLORATIONAPPLICATION_DATA = "data"; + public static final String KEY_EXPLORATIONAPPLICATION_DATA_NODE = "explorationdata"; + public static final String KEY_EXPLORATIONAPPLICATION_COMPONENTS = "components"; + public static final String KEY_EXPLORATIONAPPLICATION_COMPONENT_NODE = "component"; + + public static final String KEY_EXPLORATIONDATA_RESULT = "result"; + public static final String KEY_EXPLORATIONDATA_VALUES = "values"; + public static final String KEY_EXPLORATIONDATA_VALUE = "value"; + + public static final String KEY_RESULT_FILE = "file"; + + public static final String KEY_METADATA = "metadata"; + public static final String KEY_METADATA_UUID = "uuid"; public static final String KEY_METADATA_VERSION = "version"; public static final String KEY_METADATA_LATESTVERSION = "latestversion"; public static final String KEY_METADATA_NAME = "name"; public static final String KEY_METADATA_TYPE = "type"; - public static final String KEY_METADATA_TYPE_VALUE_EA = "LuceneDatabaseTestCase"; // FIXME - // EA + public static final String KEY_METADATA_TYPE_VALUE_EA = "ExplorationApplication"; public static final String KEY_METADATA_DESCRIPTION = "description"; public static final String KEY_METADATA_CREATIONDATE = "creationdate"; @@ -23,16 +53,18 @@ public static final String KEY_METADATA_ATTACHMENTS = "attachments"; public static final String KEY_METADATA_ATTACHMENT = "attachment"; - public static final String KEY_DESCRIPTOR_NAME = "name"; - public static final String KEY_DESCRIPTOR_VALUE = "value"; + public static final String KEY_METADATA_DESCRIPTOR_NAME = "name"; + public static final String KEY_METADATA_DESCRIPTOR_VALUE = "value"; - public static final String KEY_ATTACHMENT_NAME = "name"; - public static final String KEY_ATTACHMENT_TYPE = "type"; + public static final String KEY_METADATA_ATTACHMENT_NAME = "name"; + public static final String KEY_METADATA_ATTACHMENT_TYPE = "type"; + /* public static final String KEY_COMPONENT = "C"; public static final String KEY_ED = "ED"; public static final String KEY_RESULT = "R"; public static final String KEY_FILE = "FILE"; + */ public static final String FILE_XML = "data.xml"; public static final String FILE_DATA_PREFIX = "attachment"; Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/service/StorageService.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/service/StorageService.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/service/StorageService.java 2008-01-04 15:59:36 UTC (rev 94) @@ -5,7 +5,9 @@ import javax.ejb.Remote; import com.healthmarketscience.rmiio.RemoteInputStream; +import com.healthmarketscience.rmiio.RemoteOutputStream; +import fr.cemagref.simexplorer.is.storage.entities.data.ExplorationApplication; import fr.cemagref.simexplorer.is.storage.entities.metadata.MetaDataEntity; @Remote @@ -16,7 +18,7 @@ void close() throws Exception; void commit() throws Exception; - + MetaDataEntity saveElement(RemoteInputStream zipRemoteStream) throws Exception; @@ -28,6 +30,8 @@ MetaDataEntity getMetadata(String uuid, String version) throws Exception; + void exportElement(RemoteOutputStream xmlOutputStream, String uuid, String version) throws Exception; + int findFullTextCount(String query, boolean onlyLatest) throws Exception; MetaDataEntity[] findFullText(String query, boolean onlyLatest, @@ -37,5 +41,7 @@ MetaDataEntity[] findApplications(boolean onlyLatest, int start, int count, int dateOrder) throws Exception; + + ExplorationApplication getExplorationApplication(String uuid, String version) throws Exception; } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/service/StorageServiceImpl.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/service/StorageServiceImpl.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/service/StorageServiceImpl.java 2008-01-04 15:59:36 UTC (rev 94) @@ -1,6 +1,9 @@ package fr.cemagref.simexplorer.is.storage.service; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; import java.io.InputStream; +import java.io.OutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -18,15 +21,16 @@ import com.healthmarketscience.rmiio.RemoteInputStream; import com.healthmarketscience.rmiio.RemoteInputStreamClient; +import com.healthmarketscience.rmiio.RemoteOutputStream; +import com.healthmarketscience.rmiio.RemoteOutputStreamClient; import fr.cemagref.simexplorer.is.storage.engine.StorageEngine; +import fr.cemagref.simexplorer.is.storage.entities.data.ExplorationApplication; import fr.cemagref.simexplorer.is.storage.entities.metadata.MetaDataEntity; import fr.cemagref.simexplorer.is.storage.entities.metadata.Version; import fr.cemagref.simexplorer.is.storage.factories.BaseEntityFactory; import fr.cemagref.simexplorer.is.storage.factories.MetaDataEntityFactory; import fr.cemagref.simexplorer.is.storage.factories.XmlConstants; -import fr.cemagref.simexplorer.is.storage.xml.MetaDataParser; -import fr.cemagref.simexplorer.is.storage.xml.Parser; @Stateless(name = "StorageService") @Remote(StorageService.class) @@ -86,7 +90,8 @@ public MetaDataEntity[] findFullText(String query, boolean onlyLatest, int indexStart, int count, int dateOrder) throws Exception { - return storageEngine.findFullText(query, onlyLatest, indexStart, count, dateOrder); + return storageEngine.findFullText(query, onlyLatest, indexStart, count, + dateOrder); } public int findFullTextCount(String query, boolean onlyLatest) @@ -105,6 +110,15 @@ onlyLatest, start, count, dateOrder); } + public ExplorationApplication getExplorationApplication(String uuid, + String version) throws Exception { + MetaDataEntity mde = getMetadata(uuid, version); + ExplorationApplication ea = (ExplorationApplication) BaseEntityFactory + .getFactory(ExplorationApplication.class).loadElement( + storageEngine.retrieveData(mde, KEY_XML)); + return ea; + } + private MetaDataEntity saveElement(InputStream zipStream) throws Exception { String xmlFile = null; Map<String, String> attachments = new HashMap<String, String>(); @@ -131,7 +145,7 @@ return saveElement(xmlFile, attachments); } - private MetaDataEntity saveElement(InputStream xmlFile, + public MetaDataEntity saveElement(InputStream xmlFile, Map<String, InputStream> attachments) throws Exception { // Store temporary data String idxml = storageEngine.storeTempData(xmlFile); @@ -143,6 +157,25 @@ return saveElement(idxml, idsattachment); } + public void exportElement(RemoteOutputStream xmlOutputStream, String uuid, String version) + throws Exception { + MetaDataEntity mde = getMetadata(uuid, version); + InputStream xmlStream = storageEngine.retrieveData(mde, KEY_XML); + OutputStream os = RemoteOutputStreamClient.wrap(xmlOutputStream); + + // Buffer copy stream to stream + BufferedInputStream bin = new BufferedInputStream(xmlStream); + BufferedOutputStream bout = new BufferedOutputStream(os); + while (true) { + int datum = bin.read(); + if (datum == -1) + break; + bout.write(datum); + } + bout.flush(); + + } + /** * Real implementation of saveElement * @@ -153,17 +186,22 @@ */ private MetaDataEntity saveElement(String idxml, Map<String, String> idsattachment) throws Exception { - // Load xml metadata - MetaDataEntity metaData = MetaDataParser.parse(storageEngine - .retrieveTempData(idxml)); + // Load metadata xml + MetaDataEntityFactory mdeFactory = (MetaDataEntityFactory) BaseEntityFactory + .getFactory(MetaDataEntity.class); + MetaDataEntity metaData = mdeFactory + .loadElementFromParentXML(storageEngine.retrieveTempData(idxml)); - String uuid = metaData.getUuid(); + if (metaData.getType() != null + && KEY_METADATA_TYPE_VALUE_EA.equals(metaData.getType())) { - // If element is an EA, save inner Components and Data + /* + ExplorationApplication ea = (ExplorationApplication) BaseEntityFactory + .getFactory(ExplorationApplication.class).loadElement( + storageEngine.retrieveTempData(idxml)); + */ - if (metaData.getType() != null - && metaData.getType().equals(KEY_METADATA_TYPE_VALUE_EA)) { - + // If element is an EA, save inner Components and Data List<String> components = new ArrayList<String>(); List<String[]> explorationDatas = new ArrayList<String[]>(); @@ -191,14 +229,33 @@ saveElement(idComponent, new HashMap<String, String>()); } - // Don't save any file for an EA - idsattachment = new HashMap<String, String>(); + } + // Process version rules + processVersionRules(metaData); + + // Prepare saving + Map<String, InputStream> attachments = new HashMap<String, InputStream>(); + + attachments.put(KEY_XML, storageEngine.retrieveTempData(idxml)); + if (metaData.getType() != null + && !KEY_METADATA_TYPE_VALUE_EA.equals(metaData.getType())) { + for (Map.Entry<String, String> entry : idsattachment.entrySet()) { + attachments.put(entry.getKey(), storageEngine + .retrieveTempData(entry.getValue())); + } } + storageEngine.saveElement(metaData, attachments); + storageEngine.commit(); + return metaData; + } + + private void processVersionRules(MetaDataEntity metaData) throws Exception { + // Check existing version in storage - MetaDataEntity previousVersion = storageEngine.getMetadata(uuid, - metaData.getVersion()); + MetaDataEntity previousVersion = storageEngine.getMetadata(metaData + .getUuid(), metaData.getVersion()); /* * MetaDataEntity parentData = storageEngine.getElementVersion(metaData * .getParentData().getUuid(), metaData.getParentData() .getVersion()); @@ -210,55 +267,51 @@ // Version rules if (previousVersion != null) { - /* - * metaData.setParentVersion(storageEngine.getElementVersion(uuid, - * previousVersion.getVersion())); - */ metaData.setVersion(previousVersion.getVersion().incVersion(0) .toString()); } - // Prepare saving - Map<String, InputStream> attachments = new HashMap<String, InputStream>(); - - attachments.put(KEY_XML, storageEngine.retrieveTempData(idxml)); - for (Map.Entry<String, String> entry : idsattachment.entrySet()) { - attachments.put(entry.getKey(), storageEngine - .retrieveTempData(entry.getValue())); - } - storageEngine.saveElement(metaData, attachments); - storageEngine.commit(); - - return metaData; } private void extractChildren(String idxml, Map<String, String> idsattachment, List<String> components, List<String[]> explorationDatas) throws Exception { - MetaDataEntityFactory<MetaDataEntity> elementFactory = (MetaDataEntityFactory<MetaDataEntity>) BaseEntityFactory - .getFactory("MetaDataEntity"); - Document document = BaseEntityFactory.getBuilder().parse( + MetaDataEntityFactory<MetaDataEntity> elementFactory = (MetaDataEntityFactory) BaseEntityFactory + .getFactory(MetaDataEntity.class); + + Document document = BaseEntityFactory.getXMLBuilder().parse( storageEngine.retrieveTempData(idxml)); Element rootElement = (Element) document.getFirstChild(); // Components - Set<Element> componentElements = elementFactory.getElementsByTagName( - rootElement, KEY_COMPONENT); + Element componentsElement = elementFactory.getXMLElementByTagName( + rootElement, KEY_EXPLORATIONAPPLICATION_COMPONENTS); + Set<Element> componentElements = elementFactory + .getXMLElementsByTagName(componentsElement, + KEY_EXPLORATIONAPPLICATION_COMPONENT_NODE); for (Element element : componentElements) { - components.add(storageEngine.storeTempData(Parser - .serializeElement(element))); + components + .add(storageEngine.storeTempData(elementFactory + .serializeElement( + KEY_EXPLORATIONAPPLICATION_COMPONENT_NODE, + element))); } + Element applicationDatasElement = elementFactory + .getXMLElementByTagName(rootElement, + KEY_EXPLORATIONAPPLICATION_DATA); Set<Element> applicationDataElements = elementFactory - .getElementsByTagName(rootElement, KEY_ED); + .getXMLElementsByTagName(applicationDatasElement, + KEY_EXPLORATIONAPPLICATION_DATA_NODE); + for (Element elementAD : applicationDataElements) { + Element element = elementFactory.getXMLElementByTagName(elementAD, + KEY_EXPLORATIONDATA_RESULT); + String result = elementFactory.getXMLProperty(element, + KEY_RESULT_FILE); - Element element = elementFactory.getElementByTagName(elementAD, - KEY_RESULT); - String result = elementFactory.getProperty(element, KEY_FILE); - String[] explorationDataArray = null; if (result != null) { explorationDataArray = new String[2]; @@ -266,16 +319,13 @@ } else { explorationDataArray = new String[1]; } - explorationDataArray[0] = storageEngine.storeTempData(Parser - .serializeElement(elementAD)); + explorationDataArray[0] = storageEngine + .storeTempData(elementFactory.serializeElement( + KEY_EXPLORATIONAPPLICATION_DATA_NODE, elementAD)); + explorationDatas.add(explorationDataArray); } } - /* - * public MetaDataEntity loadElement(String idxml, Map<String, String> - * idsattachment) throws Exception { } - */ - } Modified: trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/ElementGenerator.java =================================================================== --- trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/ElementGenerator.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/ElementGenerator.java 2008-01-04 15:59:36 UTC (rev 94) @@ -33,15 +33,14 @@ metaData.setType(element.getClass().getSimpleName()); metaData.setDescription("test"); metaData.setVersion(Integer.toString(r.nextInt(100))); - metaData.setCreationDate(new Date(r.nextLong())); + metaData.setCreationDate(new Date()); metaData.setHash(UUID.randomUUID().toString()); metaData.setLatest(true); Map<String, String> descriptors = new HashMap<String, String>(); int i = 5 + r.nextInt(10); for (int j = 0; j < i; j++) { - descriptors.put(UUID.randomUUID().toString(), UUID.randomUUID() - .toString()); + descriptors.put(Integer.toString(j), UUID.randomUUID().toString()); } metaData.setDescriptors(descriptors); Modified: trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/MetaDataGenerator.java =================================================================== --- trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/MetaDataGenerator.java 2008-01-03 11:12:58 UTC (rev 93) +++ trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/MetaDataGenerator.java 2008-01-04 15:59:36 UTC (rev 94) @@ -6,7 +6,7 @@ import java.util.Random; import java.util.UUID; -import fr.cemagref.simexplorer.is.storage.attachment.Content; +import fr.cemagref.simexplorer.is.storage.attachment.type.ContentType; import fr.cemagref.simexplorer.is.storage.entities.metadata.MetaDataEntity; import fr.cemagref.simexplorer.is.storage.entities.metadata.Version; @@ -66,7 +66,7 @@ descriptors.put("descriptor" + j, UUID.randomUUID().toString()); } me.setDescriptors(descriptors); - me.setAttachments(new HashMap<String, Content>()); + me.setAttachments(new HashMap<String, ContentType>()); me.setParentDataUuid(null); me.setParentDataVersion(null); me.setParentVersionUuid(null); Added: trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/service/StorageServiceMassInsert.java =================================================================== --- trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/service/StorageServiceMassInsert.java (rev 0) +++ trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/service/StorageServiceMassInsert.java 2008-01-04 15:59:36 UTC (rev 94) @@ -0,0 +1,59 @@ +package fr.cemagref.simexplorer.is.storage.test.service; + +import java.io.InputStream; +import java.util.Date; +import java.util.HashMap; + +import junit.framework.TestCase; +import fr.cemagref.simexplorer.is.storage.entities.data.ExplorationApplication; +import fr.cemagref.simexplorer.is.storage.factories.BaseEntityFactory; +import fr.cemagref.simexplorer.is.storage.service.StorageServiceImpl; +import fr.cemagref.simexplorer.is.storage.test.ElementGenerator; + +public class StorageServiceMassInsert extends TestCase { + + private StorageServiceImpl storageService; + private ElementGenerator elementGenerator; + + protected void setUp() throws Exception { + super.setUp(); + elementGenerator = new ElementGenerator(); + + storageService = new StorageServiceImpl(); + storageService.open(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + storageService.close(); + } + + public void testMassInsert() throws Exception { + int c = 289747; + + Date begin = new Date(); + + ExplorationApplication ea = null; + for (int i = 0; i < c; i++) { + ea = elementGenerator.generateRandomEA(); + InputStream xmlStream = BaseEntityFactory.getFactory( + ExplorationApplication.class).saveElement(ea); + + storageService.saveElement(xmlStream, + new HashMap<String, InputStream>()); + + if (i > 0 && i % 100 == 0) { + Date end = new Date(); + long time = end.getTime() - begin.getTime(); + System.out.println("Insert " + i + " : Time taken : " + time + + "ms"); + double timePerElement = time / i; + System.out.println("Insert " + i + + " : Time taken per element : " + timePerElement + + "ms"); + } + + } + } + +}