r505 - in trunk: simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine simexplorer-is-sto
Author: glandais Date: 2008-01-24 18:00:48 +0000 (Thu, 24 Jan 2008) New Revision: 505 Added: trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/StorageException.java Modified: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/FileSystemAttachmentHandler.java trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/util/Config.java Log: StorageException Modified: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java =================================================================== --- trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java 2008-01-24 18:00:06 UTC (rev 504) +++ trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java 2008-01-24 18:00:48 UTC (rev 505) @@ -27,6 +27,7 @@ import fr.cemagref.simexplorer.is.entities.metadata.Version; import fr.cemagref.simexplorer.is.security.credentials.CredentialManager; import fr.cemagref.simexplorer.is.security.entities.Permission; +import fr.cemagref.simexplorer.is.storage.StorageException; public class StorageEngineSecuImpl extends StorageEngineImpl { @@ -35,27 +36,32 @@ @Override public void deleteElement(String token, String uuid, Version version) - throws Exception { + throws StorageException { Permission permission = credentialManager.getPermission(token, uuid); // TODO check candelete = canadmin if (permission != null && permission.isCanAdmin()) { super.deleteElement(token, uuid, version); + } else { + throw new StorageException("Permission denied"); } } @Override - public void deleteElements(String token, String uuid) throws Exception { + public void deleteElements(String token, String uuid) + throws StorageException { Permission permission = credentialManager.getPermission(token, uuid); // TODO check candelete = canadmin if (permission != null && permission.isCanAdmin()) { super.deleteElements(token, uuid); + } else { + throw new StorageException("Permission denied"); } } @Override public MetaDataEntity[] findElementsByType(String token, String type, boolean onlyLatest, int start, int count, int dateOrder) - throws Exception { + throws StorageException { MetaDataEntity[] list = super.findElementsByType(token, type, onlyLatest, start, count, dateOrder); // TODO how to filter without losing pagination? @@ -64,7 +70,7 @@ @Override public int findElementsByTypeCount(String token, String type, - boolean onlyLatest) throws Exception { + boolean onlyLatest) throws StorageException { // TODO how to filter without losing pagination? return super.findElementsByTypeCount(token, type, onlyLatest); } @@ -72,7 +78,7 @@ @Override public MetaDataEntity[] findFullText(String token, String query, boolean onlyLatest, int indexStart, int count, int dateOrder) - throws Exception { + throws StorageException { // TODO how to filter without losing pagination? return super.findFullText(token, query, onlyLatest, indexStart, count, dateOrder); @@ -80,64 +86,74 @@ @Override public int findFullTextCount(String token, String query, boolean onlyLatest) - throws Exception { + throws StorageException { // TODO how to filter without losing pagination? return super.findFullTextCount(token, query, onlyLatest); } @Override public MetaDataEntity getMetadata(String token, String uuid, Version version) - throws Exception { + throws StorageException { MetaDataEntity mde = null; Permission permission = credentialManager.getPermission(token, uuid); if (permission.isCanRead()) { mde = super.getMetadata(token, uuid, version); + } else { + throw new StorageException("Permission denied"); } return mde; } @Override public MetaDataEntity getMetadata(String token, String uuid) - throws Exception { + throws StorageException { MetaDataEntity mde = null; Permission permission = credentialManager.getPermission(token, uuid); if (permission.isCanRead()) { mde = super.getMetadata(token, uuid); + } else { + throw new StorageException("Permission denied"); } return mde; } @Override public List<Version> getVersions(String token, String uuid) - throws Exception { + throws StorageException { List<Version> versions = null; Permission permission = credentialManager.getPermission(token, uuid); if (permission.isCanRead()) { versions = super.getVersions(token, uuid); + } else { + throw new StorageException("Permission denied"); } return versions; } @Override public InputStream retrieveData(String token, MetaDataEntity entity, - String field) throws Exception { + String field) throws StorageException { InputStream stream = null; Permission permission = credentialManager.getPermission(token, entity .getUuid()); if (permission.isCanRead()) { stream = super.retrieveData(token, entity, field); + } else { + throw new StorageException("Permission denied"); } return stream; } @Override public void saveElement(String token, MetaDataEntity element, - Map<String, InputStream> attachments) throws Exception { + Map<String, InputStream> attachments) throws StorageException { Permission permission = credentialManager.getPermission(token, element .getUuid()); if (permission.isCanWrite()) { super.saveElement(token, element, attachments); credentialManager.saveElement(token, element.getUuid()); + } else { + throw new StorageException("Permission denied"); } } Added: trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/StorageException.java =================================================================== --- trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/StorageException.java (rev 0) +++ trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/StorageException.java 2008-01-24 18:00:48 UTC (rev 505) @@ -0,0 +1,40 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package fr.cemagref.simexplorer.is.storage; + +public class StorageException extends Exception { + + private static final long serialVersionUID = 4405447107690074844L; + + public StorageException() { + super(); + } + + public StorageException(String message) { + super(message); + } + + public StorageException(Throwable cause) { + super(cause); + } + + public StorageException(String message, Throwable cause) { + super(message, cause); + } + +} Modified: trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java =================================================================== --- trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java 2008-01-24 18:00:06 UTC (rev 504) +++ trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java 2008-01-24 18:00:48 UTC (rev 505) @@ -20,6 +20,7 @@ import java.io.InputStream; import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity; +import fr.cemagref.simexplorer.is.storage.StorageException; /** * Store, retrieve and delete content @@ -38,10 +39,10 @@ * Unique field for content * @param is * Content - * @throws Exception + * @throws StorageException */ public abstract void storeData(MetaDataEntity entity, String field, - InputStream is) throws Exception; + InputStream is) throws StorageException; /** * Retrieve content @@ -51,10 +52,10 @@ * @param field * Unique field for content * @return Content - * @throws Exception + * @throws StorageException */ public abstract InputStream retrieveData(MetaDataEntity entity, String field) - throws Exception; + throws StorageException; /** * Delete content @@ -63,9 +64,9 @@ * DataEntity related to content * @param field * Unique field for content - * @throws Exception + * @throws StorageException */ public abstract void deleteData(MetaDataEntity entity, String field) - throws Exception; + throws StorageException; } \ No newline at end of file Modified: trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/FileSystemAttachmentHandler.java =================================================================== --- trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/FileSystemAttachmentHandler.java 2008-01-24 18:00:06 UTC (rev 504) +++ trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/FileSystemAttachmentHandler.java 2008-01-24 18:00:48 UTC (rev 505) @@ -21,10 +21,13 @@ import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.IOException; import java.io.InputStream; import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity; +import fr.cemagref.simexplorer.is.storage.StorageException; import fr.cemagref.simexplorer.is.storage.util.Config; /** @@ -49,7 +52,6 @@ * @param field * Unique field for content * @return Instance of file - * @throws Exception */ private File getFile(MetaDataEntity entity, String field) { String resultPath = baseFolder; @@ -77,37 +79,48 @@ @Override public InputStream retrieveData(MetaDataEntity entity, String field) - throws Exception { + throws StorageException { // Simple stream on file - FileInputStream fis = new FileInputStream(getFile(entity, field)); + FileInputStream fis = null; + try { + fis = new FileInputStream(getFile(entity, field)); + } catch (FileNotFoundException e) { + throw new StorageException(e); + } return fis; } @Override public void storeData(MetaDataEntity entity, String field, InputStream is) - throws Exception { + throws StorageException { // Simple stream on file - FileOutputStream fos = new FileOutputStream(getFile(entity, field)); + try { + FileOutputStream fos = new FileOutputStream(getFile(entity, field)); - // Buffer copy stream to stream - BufferedInputStream bin = new BufferedInputStream(is); - BufferedOutputStream bout = new BufferedOutputStream(fos); + // Buffer copy stream to stream + BufferedInputStream bin = new BufferedInputStream(is); + BufferedOutputStream bout = new BufferedOutputStream(fos); - while (true) { - int datum = bin.read(); - if (datum == -1) - break; - bout.write(datum); + while (true) { + int datum = bin.read(); + if (datum == -1) + break; + bout.write(datum); + } + bout.flush(); + + // Close file + fos.close(); + } catch (FileNotFoundException e) { + throw new StorageException(e); + } catch (IOException e) { + throw new StorageException(e); } - bout.flush(); - - // Close file - fos.close(); } @Override public void deleteData(MetaDataEntity entity, String field) - throws Exception { + throws StorageException { // Simple delete on file getFile(entity, field).delete(); } Modified: trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java =================================================================== --- trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java 2008-01-24 18:00:06 UTC (rev 504) +++ trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java 2008-01-24 18:00:48 UTC (rev 505) @@ -25,6 +25,7 @@ import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity; import fr.cemagref.simexplorer.is.entities.metadata.Version; +import fr.cemagref.simexplorer.is.storage.StorageException; /** * Interface of a database able to manage metadata elements @@ -37,9 +38,9 @@ /** * Open database connection * - * @throws Exception + * @throws StorageException */ - public void open() throws Exception { + public void open() throws StorageException { open(false); } @@ -48,23 +49,23 @@ * * @param create * Create database - * @throws Exception + * @throws StorageException */ - public abstract void open(boolean create) throws Exception; + public abstract void open(boolean create) throws StorageException; /** * Close database connection * - * @throws Exception + * @throws StorageException */ - public abstract void close() throws Exception; + public abstract void close() throws StorageException; /** * Commit pending modifications * - * @throws Exception + * @throws StorageException */ - public abstract void commit() throws Exception; + public abstract void commit() throws StorageException; // Create / Update @@ -74,10 +75,11 @@ * * @param element * Element to insert - * @throws Exception + * @param readers + * @throws StorageException */ public abstract void insertElement(MetaDataEntity element, - List<Reader> readers) throws Exception; + List<Reader> readers) throws StorageException; // Read @@ -89,10 +91,10 @@ * @param version * version * @return Fund element, null if not fund - * @throws Exception + * @throws StorageException */ public abstract MetaDataEntity getElement(String uuid, Version version) - throws Exception; + throws StorageException; /** * Get all version of an element thanks to its id <br> @@ -101,20 +103,21 @@ * @param uuid * Id * @return Versions - * @throws Exception + * @throws StorageException */ - public abstract List<Version> getVersions(String uuid) throws Exception; + public abstract List<Version> getVersions(String uuid) throws StorageException; /** * Retrieve all elements by id Empty list if no element with this id * * @param uuid * Id + * @param onlyLatest * @return Element list - * @throws Exception + * @throws StorageException */ public abstract Set<MetaDataEntity> findElementsById(String uuid, - boolean onlyLatest) throws Exception; + boolean onlyLatest) throws StorageException; /** * Retrieve elements with specific properties<br> @@ -123,10 +126,10 @@ * @param properties * Matching properties needed * @return Element list - * @throws Exception + * @throws StorageException */ public Set<MetaDataEntity> findElementsByProperties( - Map<String, String> properties) throws Exception { + Map<String, String> properties) throws StorageException { return findElementsByProperties(properties, 0, -1, 0); } @@ -140,12 +143,13 @@ * Index of first element returned * @param count * Number of elements to return + * @param dateOrder * @return Element list - * @throws Exception + * @throws StorageException */ public abstract Set<MetaDataEntity> findElementsByProperties( Map<String, String> properties, int start, int count, int dateOrder) - throws Exception; + throws StorageException; /** * Retrieve element count specific properties @@ -153,10 +157,10 @@ * @param properties * Matching properties needed * @return Number of elements fund - * @throws Exception + * @throws StorageException */ public abstract int findElementsByPropertiesCount( - Map<String, String> properties) throws Exception; + Map<String, String> properties) throws StorageException; /** * Prepare properties for query @@ -191,11 +195,11 @@ * @param dateOrder * Sorting * @return Element list - * @throws Exception + * @throws StorageException */ public Set<MetaDataEntity> findElementsByType(String type, boolean onlyLatest, int start, int count, int dateOrder) - throws Exception { + throws StorageException { return findElementsByProperties(getPropertiesByType(type, onlyLatest), start, count, dateOrder); } @@ -208,10 +212,10 @@ * @param onlyLatest * Only latest elements * @return Number of elements - * @throws Exception + * @throws StorageException */ public int findElementsByTypeCount(String type, boolean onlyLatest) - throws Exception { + throws StorageException { return findElementsByPropertiesCount(getPropertiesByType(type, onlyLatest)); } @@ -222,27 +226,30 @@ * * @param queryText * Searched text + * @param onlyLatest * @param start * Index of first element returned * @param count * Number of elements to return + * @param dateOrder * @return Element list - * @throws Exception + * @throws StorageException */ public abstract Set<MetaDataEntity> findElementsByContentSearch( String queryText, boolean onlyLatest, int start, int count, - int dateOrder) throws Exception; + int dateOrder) throws StorageException; /** * Retrieve element count with specific content * * @param queryText * Searched text + * @param onlyLatest * @return Number of elements fund - * @throws Exception + * @throws StorageException */ public abstract int findElementsByContentSearchCount(String queryText, - boolean onlyLatest) throws Exception; + boolean onlyLatest) throws StorageException; // Delete @@ -251,9 +258,9 @@ * * @param element * Element to delete - * @throws Exception + * @throws StorageException */ - public void deleteElement(MetaDataEntity element) throws Exception { + public void deleteElement(MetaDataEntity element) throws StorageException { deleteElement(element.getUuid(), element.getVersion()); } @@ -264,9 +271,9 @@ * Id * @param version * Version - * @throws Exception + * @throws StorageException */ public abstract void deleteElement(String uuid, Version version) - throws Exception; + throws StorageException; } Modified: trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java =================================================================== --- trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2008-01-24 18:00:06 UTC (rev 504) +++ trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2008-01-24 18:00:48 UTC (rev 505) @@ -57,6 +57,7 @@ import fr.cemagref.simexplorer.is.contenttype.ContentTypeFactory; import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity; import fr.cemagref.simexplorer.is.entities.metadata.Version; +import fr.cemagref.simexplorer.is.storage.StorageException; import fr.cemagref.simexplorer.is.storage.database.Database; import fr.cemagref.simexplorer.is.storage.util.Config; @@ -114,15 +115,14 @@ } return searcherPool; } - + /** * Retrieve searcher for a new query * * @return Searcher - * @throws CorruptIndexException * @throws IOException */ - private Searcher getSearcher() throws CorruptIndexException, IOException { + private Searcher getSearcher() throws IOException { synchronized (searcherSynchronizer) { // If cached searcher is null (as after an index write) if (cachedSearcher == null) { @@ -165,7 +165,7 @@ } @Override - public void open(boolean create) throws Exception { + public void open(boolean create) throws StorageException { if (writer == null) { // Create an analyzer Analyzer analyzer = new SimpleAnalyzer(); @@ -177,43 +177,49 @@ resultFolder.mkdirs(); } - // Base directory index - directory = FSDirectory.getDirectory(indexDir, lockFactory); + try { + // Base directory index + directory = FSDirectory.getDirectory(indexDir, lockFactory); + // force creation if index doesn't exist + boolean realCreate = create; + if (!IndexReader.indexExists(directory)) { + realCreate = true; + } - // force creation if index doesn't exist - boolean realCreate = create; - if (!IndexReader.indexExists(directory)) { - realCreate = true; - } + // Instanciate unique writer + writer = new IndexWriter(directory, true, analyzer, realCreate); - // Instanciate unique writer - writer = new IndexWriter(directory, true, analyzer, realCreate); - - // Write index on create - if (realCreate) { - commit(); + // Write index on create + if (realCreate) { + commit(); + } + } catch (IOException e) { + throw new StorageException(e); } } } @Override - public void close() throws Exception { - synchronized (writerSynchronizer) { - // Close writer and invalidate reader - writer.close(); - writer = null; + public void close() throws StorageException { + try { + synchronized (writerSynchronizer) { + // Close writer and invalidate reader + writer.close(); + writer = null; + } + resetReader(); + } catch (IOException e) { + throw new StorageException(e); } - resetReader(); searcherPool = null; } /** * Push commit to db * - * @throws CorruptIndexException * @throws IOException */ - private void synchedCommit() throws CorruptIndexException, IOException { + private void synchedCommit() throws IOException { synchronized (writerSynchronizer) { // Flush in ram data writer.flush(); @@ -221,7 +227,8 @@ Date now = new Date(); long elapsed = now.getTime() - lastOptimize.getTime(); // One optimize per period, if readers are closed - if (elapsed > optimizePeriod * 1000 && getSearcherPool().allClosed()) { + if (elapsed > optimizePeriod * 1000 + && getSearcherPool().allClosed()) { writer.optimize(); lastOptimize = new Date(); } @@ -231,14 +238,18 @@ } @Override - public void commit() throws Exception { - // Allows concurent access - synchedCommit(); + public void commit() throws StorageException { + try { + // Allows concurent access + synchedCommit(); + } catch (IOException e) { + throw new StorageException(e); + } } @Override public void insertElement(MetaDataEntity element, List<Reader> readers) - throws Exception { + throws StorageException { // Save element to a Lucene document Document document = saveLuceneElement(element, readers); @@ -251,28 +262,36 @@ deleteElement(element); } - synchronized (writerSynchronizer) { - // add document to index - writer.addDocument(document); + try { + synchronized (writerSynchronizer) { + // add document to index + writer.addDocument(document); + } + } catch (IOException e) { + throw new StorageException(e); } } @Override public MetaDataEntity getElement(String uuid, Version version) - throws Exception { + throws StorageException { MetaDataEntity result = null; - // 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)); + // 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); } - } finally { - // Release searcher instance - releaseSearcher(searcher); + } catch (Exception e) { + throw new StorageException(e); } return result; @@ -298,28 +317,33 @@ } @Override - public List<Version> getVersions(String uuid) throws Exception { + public List<Version> getVersions(String uuid) throws StorageException { // Retrieve all document corresponding to id Map<String, String> properties = new HashMap<String, String>(); properties.put(KEY_UUID, uuid); List<Version> versions = null; - // Get current searcher instance - Searcher searcher = getSearcher(); + try { - Hits hits = findHits(properties, searcher, SORT_DATE_NONE); + // Get current searcher instance + Searcher searcher = getSearcher(); + try { + Hits hits = findHits(properties, searcher, SORT_DATE_NONE); - // 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))); + // 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); } - } finally { - // Release searcher instance - releaseSearcher(searcher); + } catch (Exception e) { + throw new StorageException(e); } return versions; @@ -327,7 +351,7 @@ @Override public Set<MetaDataEntity> findElementsById(String uuid, boolean onlyLatest) - throws Exception { + throws StorageException { // Create hash map with id Map<String, String> properties = new HashMap<String, String>(); properties.put(KEY_UUID, uuid); @@ -337,14 +361,18 @@ Set<MetaDataEntity> result = null; - // 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); + // 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); + } + } catch (Exception e) { + throw new StorageException(e); } // Return all elements parsed from documents fund @@ -353,17 +381,21 @@ @Override public int findElementsByPropertiesCount(Map<String, String> properties) - throws Exception { + throws StorageException { int result = 0; - // 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); + // 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); + } + } catch (Exception e) { + throw new StorageException(e); } // Return all elements parsed from documents fund @@ -373,17 +405,21 @@ @Override public Set<MetaDataEntity> findElementsByProperties( Map<String, String> properties, int start, int count, int dateOrder) - throws Exception { + throws StorageException { Set<MetaDataEntity> result = null; - // 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); + // 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); + } + } catch (Exception e) { + throw new StorageException(e); } // Return all elements parsed from documents fund @@ -392,21 +428,30 @@ @Override public int findElementsByContentSearchCount(String queryText, - boolean onlyLatest) throws Exception { - Query query = getQueryByContentSearch(queryText, onlyLatest); + boolean onlyLatest) throws StorageException { + Query query = null; + try { + query = getQueryByContentSearch(queryText, onlyLatest); + } catch (ParseException e) { + throw new StorageException(e); + } int result = 0; Hits hits; - // Get current searcher instance - Searcher searcher = getSearcher(); try { - hits = searcher.search(query); - // Return hits length - result = hits.length(); - } finally { - // Release searcher instance - releaseSearcher(searcher); + // Get current searcher instance + Searcher searcher = getSearcher(); + try { + hits = searcher.search(query); + // Return hits length + result = hits.length(); + } finally { + // Release searcher instance + releaseSearcher(searcher); + } + } catch (Exception e) { + throw new StorageException(e); } return result; @@ -434,21 +479,30 @@ @Override public Set<MetaDataEntity> findElementsByContentSearch(String queryText, boolean onlyLatest, int start, int count, int dateOrder) - throws Exception { - Query query = getQueryByContentSearch(queryText, onlyLatest); + throws StorageException { + Query query = null; + try { + query = getQueryByContentSearch(queryText, onlyLatest); + } catch (ParseException e) { + throw new StorageException(e); + } Set<MetaDataEntity> result = null; Hits hits; - // 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); + // 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); + } + } catch (Exception e) { + throw new StorageException(e); } return result; @@ -491,14 +545,19 @@ } @Override - public void deleteElement(String uuid, Version version) throws Exception { + public void deleteElement(String uuid, Version version) + throws StorageException { // 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()); - synchronized (writerSynchronizer) { - writer.deleteDocuments(terms); + try { + synchronized (writerSynchronizer) { + writer.deleteDocuments(terms); + } + } catch (Exception e) { + throw new StorageException(e); } } Modified: trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java =================================================================== --- trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2008-01-24 18:00:06 UTC (rev 504) +++ trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2008-01-24 18:00:48 UTC (rev 505) @@ -24,6 +24,7 @@ import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity; import fr.cemagref.simexplorer.is.entities.metadata.Version; +import fr.cemagref.simexplorer.is.storage.StorageException; public interface StorageEngine { @@ -32,21 +33,21 @@ * * @throws Exception */ - public abstract void open() throws Exception; + public abstract void open() throws StorageException; /** * Close storage * * @throws Exception */ - public abstract void close() throws Exception; + public abstract void close() throws StorageException; /** * Commit changes to storage * * @throws Exception */ - public abstract void commit() throws Exception; + public abstract void commit() throws StorageException; /** * Save an element to storage @@ -58,7 +59,7 @@ * @throws Exception */ public abstract void saveElement(String token, MetaDataEntity element, - Map<String, InputStream> attachments) throws Exception; + Map<String, InputStream> attachments) throws StorageException; /** * Retrieve an element @@ -69,7 +70,7 @@ * @throws Exception */ public abstract MetaDataEntity getMetadata(String token, String uuid) - throws Exception; + throws StorageException; /** * Retrieve versions of an element<br> @@ -82,7 +83,7 @@ * @throws Exception */ public abstract List<Version> getVersions(String token, String uuid) - throws Exception; + throws StorageException; /** * Retrieve all version of a metadata @@ -92,7 +93,7 @@ * @return */ public abstract Set<MetaDataEntity> getElementVersions(String token, - String uuid) throws Exception; + String uuid) throws StorageException; /** * Retrieve an element in a specific version @@ -103,7 +104,7 @@ * @throws Exception */ public abstract MetaDataEntity getMetadata(String token, String uuid, - Version version) throws Exception; + Version version) throws StorageException; /** * Get data associated to an element @@ -116,7 +117,7 @@ * @throws Exception */ public abstract InputStream retrieveData(String token, - MetaDataEntity entity, String field) throws Exception; + MetaDataEntity entity, String field) throws StorageException; /** * Get number of items corresponding to query @@ -127,7 +128,7 @@ * @throws Exception */ public abstract int findFullTextCount(String token, String query, - boolean onlyLatest) throws Exception; + boolean onlyLatest) throws StorageException; /** * Retrieve list of items corresponding to query @@ -142,7 +143,7 @@ */ public abstract MetaDataEntity[] findFullText(String token, String query, boolean onlyLatest, int indexStart, int count, int dateOrder) - throws Exception; + throws StorageException; /** * Retrieve list of items of type wanted @@ -157,7 +158,7 @@ */ public abstract MetaDataEntity[] findElementsByType(String token, String type, boolean onlyLatest, int start, int count, int dateOrder) - throws Exception; + throws StorageException; /** * Retrieve number of items of type wanted @@ -168,7 +169,7 @@ * @throws Exception */ public abstract int findElementsByTypeCount(String token, String type, - boolean onlyLatest) throws Exception; + boolean onlyLatest) throws StorageException; /** * Delete elements @@ -177,7 +178,7 @@ * @throws Exception */ public abstract void deleteElements(String token, String uuid) - throws Exception; + throws StorageException; /** * Delete one element @@ -187,7 +188,7 @@ * @throws Exception */ public abstract void deleteElement(String token, String uuid, - Version version) throws Exception; + Version version) throws StorageException; /** * Store temporary data, for stream duplication @@ -197,7 +198,7 @@ * @return id for retrieval * @throws Exception */ - public abstract String storeTempData(InputStream stream) throws Exception; + public abstract String storeTempData(InputStream stream) throws StorageException; /** * Retrieve temporary data @@ -207,7 +208,7 @@ * @return Data stream * @throws Exception */ - public abstract InputStream retrieveTempData(String id) throws Exception; + public abstract InputStream retrieveTempData(String id) throws StorageException; /** * Delete temporary data @@ -215,6 +216,6 @@ * @param id * @throws Exception */ - public abstract void deleteTempData(String id) throws Exception; + public abstract void deleteTempData(String id) throws StorageException; } \ No newline at end of file Modified: trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java =================================================================== --- trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java 2008-01-24 18:00:06 UTC (rev 504) +++ trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java 2008-01-24 18:00:48 UTC (rev 505) @@ -29,6 +29,7 @@ import fr.cemagref.simexplorer.is.contenttype.ContentType; import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity; import fr.cemagref.simexplorer.is.entities.metadata.Version; +import fr.cemagref.simexplorer.is.storage.StorageException; import fr.cemagref.simexplorer.is.storage.attachment.AttachmentHandler; import fr.cemagref.simexplorer.is.storage.attachment.FileSystemAttachmentHandler; import fr.cemagref.simexplorer.is.storage.database.Database; @@ -75,21 +76,21 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#open() */ - public void open() throws Exception { + public void open() throws StorageException { database.open(); } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#close() */ - public void close() throws Exception { + public void close() throws StorageException { database.close(); } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#commit() */ - public void commit() throws Exception { + public void commit() throws StorageException { database.commit(); } @@ -99,7 +100,7 @@ * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#saveElement(fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity, java.util.Map) */ public void saveElement(String token, MetaDataEntity element, - Map<String, InputStream> attachments) throws Exception { + Map<String, InputStream> attachments) throws StorageException { // Save all attachments in system for (Map.Entry<String, InputStream> entry : attachments.entrySet()) { @@ -116,9 +117,13 @@ if (element.getAttachments() != null) { ContentType contentType = element.getAttachments().get(field); if (contentType != null) { - // Transform stream into indexable text - Reader reader = contentType.renderToText(content); - readers.add(reader); + try { + // Transform stream into indexable text + Reader reader = contentType.renderToText(content); + readers.add(reader); + } catch (Exception e) { + throw new StorageException(e); + } } } } @@ -141,7 +146,8 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#getMetadata(java.lang.String) */ - public MetaDataEntity getMetadata(String token, String uuid) throws Exception { + public MetaDataEntity getMetadata(String token, String uuid) + throws StorageException { MetaDataEntity mde = null; Set<MetaDataEntity> set = database.findElementsById(uuid, true); if (!set.isEmpty()) { @@ -153,7 +159,8 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#getVersions(java.lang.String) */ - public List<Version> getVersions(String token, String uuid) throws Exception { + public List<Version> getVersions(String token, String uuid) + throws StorageException { return database.getVersions(uuid); } @@ -161,7 +168,7 @@ * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#getMetadata(java.lang.String, fr.cemagref.simexplorer.is.entities.metadata.Version) */ public MetaDataEntity getMetadata(String token, String uuid, Version version) - throws Exception { + throws StorageException { MetaDataEntity mde = database.getElement(uuid, version); return mde; } @@ -169,8 +176,8 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#retrieveData(fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity, java.lang.String) */ - public InputStream retrieveData(String token, MetaDataEntity entity, String field) - throws Exception { + public InputStream retrieveData(String token, MetaDataEntity entity, + String field) throws StorageException { InputStream result = attachmentHandler.retrieveData(entity, field); return result; } @@ -179,15 +186,16 @@ * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#findFullTextCount(java.lang.String, boolean) */ public int findFullTextCount(String token, String query, boolean onlyLatest) - throws Exception { + throws StorageException { return database.findElementsByContentSearchCount(query, onlyLatest); } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#findFullText(java.lang.String, boolean, int, int, int) */ - public MetaDataEntity[] findFullText(String token, String query, boolean onlyLatest, - int indexStart, int count, int dateOrder) throws Exception { + public MetaDataEntity[] findFullText(String token, String query, + boolean onlyLatest, int indexStart, int count, int dateOrder) + throws StorageException { MetaDataEntity[] result = database.findElementsByContentSearch(query, onlyLatest, indexStart, count, dateOrder).toArray( new MetaDataEntity[0]); @@ -197,8 +205,9 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#findElementsByType(java.lang.String, boolean, int, int, int) */ - public MetaDataEntity[] findElementsByType(String token, String type, boolean onlyLatest, - int start, int count, int dateOrder) throws Exception { + public MetaDataEntity[] findElementsByType(String token, String type, + boolean onlyLatest, int start, int count, int dateOrder) + throws StorageException { MetaDataEntity[] result = database.findElementsByType(type, onlyLatest, start, count, dateOrder).toArray(new MetaDataEntity[0]); return result; @@ -207,8 +216,8 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#findElementsByTypeCount(java.lang.String, boolean) */ - public int findElementsByTypeCount(String token, String type, boolean onlyLatest) - throws Exception { + public int findElementsByTypeCount(String token, String type, + boolean onlyLatest) throws StorageException { return database.findElementsByTypeCount(type, onlyLatest); } @@ -217,7 +226,8 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#deleteElements(java.lang.String) */ - public void deleteElements(String token, String uuid) throws Exception { + public void deleteElements(String token, String uuid) + throws StorageException { List<Version> versions = getVersions(token, uuid); for (Version version : versions) { deleteElement(token, uuid, version); @@ -227,7 +237,8 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#deleteElement(java.lang.String, fr.cemagref.simexplorer.is.entities.metadata.Version) */ - public void deleteElement(String token, String uuid, Version version) throws Exception { + public void deleteElement(String token, String uuid, Version version) + throws StorageException { MetaDataEntity element = getMetadata(token, uuid, version); Map<String, ContentType> attachments = element.getAttachments(); for (Map.Entry<String, ContentType> entry : attachments.entrySet()) { @@ -241,7 +252,7 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#storeTempData(java.io.InputStream) */ - public String storeTempData(InputStream stream) throws Exception { + public String storeTempData(InputStream stream) throws StorageException { String id = UUID.randomUUID().toString(); attachmentHandler.storeData(mdTmp, id, stream); return id; @@ -250,7 +261,7 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#retrieveTempData(java.lang.String) */ - public InputStream retrieveTempData(String id) throws Exception { + public InputStream retrieveTempData(String id) throws StorageException { InputStream is = attachmentHandler.retrieveData(mdTmp, id); return is; } @@ -258,11 +269,12 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#deleteTempData(java.lang.String) */ - public void deleteTempData(String id) throws Exception { + public void deleteTempData(String id) throws StorageException { attachmentHandler.deleteData(mdTmp, id); } - public Set<MetaDataEntity> getElementVersions(String token, String uuid) throws Exception { + public Set<MetaDataEntity> getElementVersions(String token, String uuid) + throws StorageException { return database.findElementsById(uuid, false); } Modified: trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/util/Config.java =================================================================== --- trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/util/Config.java 2008-01-24 18:00:06 UTC (rev 504) +++ trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/util/Config.java 2008-01-24 18:00:48 UTC (rev 505) @@ -26,7 +26,6 @@ public class Config { - /** to use log facility, just put in your code: log.info(\"...\"); */ private static final Log log = LogFactory.getLog(Config.class); private static Properties properties = null; @@ -34,7 +33,7 @@ private static void initProperties() throws IOException { log.info("Loading properties"); - + properties = new Properties(); URL inClasspath = ClassLoader.getSystemClassLoader().getResource(
participants (1)
-
glandais@users.labs.libre-entreprise.org