Author: tchemit Date: 2008-01-24 21:30:16 +0000 (Thu, 24 Jan 2008) New Revision: 516 Modified: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java Log: ajout exception sp?\195?\169cifique couche service Modified: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java =================================================================== --- trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java 2008-01-24 21:29:37 UTC (rev 515) +++ trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java 2008-01-24 21:30:16 UTC (rev 516) @@ -58,7 +58,7 @@ return mockData; } - public void commit() throws Exception { + public void commit() throws SimExplorerServiceException { checkImplemented(); } @@ -66,45 +66,45 @@ throw new IllegalStateException("not implemented"); } - public MetaDataEntity saveElement(String token, RemoteInputStream zipRemoteStream) throws Exception { + public MetaDataEntity saveElement(String token, RemoteInputStream zipRemoteStream) throws SimExplorerServiceException { return (MetaDataEntity) checkImplemented(); } - public MetaDataEntity saveElement(String token, RemoteInputStream xmlRemoteStream, Map<String, RemoteInputStream> attachmentsRemoteStream) throws Exception { + public MetaDataEntity saveElement(String token, RemoteInputStream xmlRemoteStream, Map<String, RemoteInputStream> attachmentsRemoteStream) throws SimExplorerServiceException { return (MetaDataEntity) checkImplemented(); } - public MetaDataEntity getMetadata(String token, String uuid) throws Exception { + public MetaDataEntity getMetadata(String token, String uuid) throws SimExplorerServiceException { return mockData().get(uuid); } - public MetaDataEntity getMetadata(String token, String uuid, String version) throws Exception { + public MetaDataEntity getMetadata(String token, String uuid, String version) throws SimExplorerServiceException { return mockData().get(uuid); } - public void exportElement(String token, RemoteOutputStream xmlOutputStream, String uuid, String version) throws Exception { + public void exportElement(String token, RemoteOutputStream xmlOutputStream, String uuid, String version) throws SimExplorerServiceException { checkImplemented(); } - public RemoteInputStream retrieveData(String token, String uuid, String version, String dataKey) throws Exception { + public RemoteInputStream retrieveData(String token, String uuid, String version, String dataKey) throws SimExplorerServiceException { return null; } - public int findFullTextCount(String token, String query, boolean onlyLatest) throws Exception { + public int findFullTextCount(String token, String query, boolean onlyLatest) throws SimExplorerServiceException { //TODO Changer return findApplicationsCount(token,onlyLatest); } - 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 SimExplorerServiceException { //TODO Changer return findApplications(token,onlyLatest,indexStart,count,dateOrder); } - public int findApplicationsCount(String token, boolean onlyLatest) throws Exception { + public int findApplicationsCount(String token, boolean onlyLatest) throws SimExplorerServiceException { return mockData().size(); } - public MetaDataEntity[] findApplications(String token, boolean onlyLatest, int start, int count, int dateOrder) throws Exception { + public MetaDataEntity[] findApplications(String token, boolean onlyLatest, int start, int count, int dateOrder) throws SimExplorerServiceException { int last = start + count; System.out.println("ask data from " + start + " width:" + count); SortedMap<String, MetaDataEntity> map = mockData(); @@ -119,14 +119,18 @@ return result; } - public LoggableElement getElement(String token, String uuid, String version) throws Exception { - ExplorationApplication explorationApplication = getGenerator().generateRandomEA(); - explorationApplication.getMetaData().setUuid(uuid); - explorationApplication.getMetaData().setVersion(version); - return explorationApplication; + public LoggableElement getElement(String token, String uuid, String version) throws SimExplorerServiceException { + try { + ExplorationApplication explorationApplication = getGenerator().generateRandomEA(); + explorationApplication.getMetaData().setUuid(uuid); + explorationApplication.getMetaData().setVersion(version); + return explorationApplication; + } catch (Exception e) { + throw new SimExplorerServiceException(e); + } } - public MetaDataEntity[] getVersions(String token, String uuid) throws Exception { + public MetaDataEntity[] getVersions(String token, String uuid) throws SimExplorerServiceException { //TODO return new MetaDataEntity[0]; } Modified: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java =================================================================== --- trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-01-24 21:29:37 UTC (rev 515) +++ trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-01-24 21:30:16 UTC (rev 516) @@ -21,6 +21,7 @@ import java.io.BufferedOutputStream; import java.io.InputStream; import java.io.OutputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -28,6 +29,7 @@ import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +import java.rmi.RemoteException; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -46,6 +48,7 @@ import fr.cemagref.simexplorer.is.factories.MetaDataEntityFactory; import fr.cemagref.simexplorer.is.factories.XmlConstants; import fr.cemagref.simexplorer.is.storage.engine.StorageEngine; +import fr.cemagref.simexplorer.is.storage.StorageException; public abstract class StorageServiceCommon implements StorageService, XmlConstants { @@ -70,95 +73,137 @@ storageEngine.close(); } - public void commit() throws Exception { - storageEngine.commit(); + public void commit() throws SimExplorerServiceException { + try { + storageEngine.commit(); + } catch (StorageException e) { + throw new SimExplorerServiceException(e); + } } public MetaDataEntity saveElement(String token, RemoteInputStream zipRemoteStream) - throws Exception { - InputStream zipStream = RemoteInputStreamClient.wrap(zipRemoteStream); - return saveElement(token, zipStream); + throws SimExplorerServiceException { + InputStream zipStream; + try { + zipStream = RemoteInputStreamClient.wrap(zipRemoteStream); + return saveElement(token, zipStream); + } catch (IOException e) { + throw new SimExplorerServiceException(e); + } } public MetaDataEntity saveElement(String token, RemoteInputStream xmlRemoteStream, Map<String, RemoteInputStream> attachmentsRemoteStream) - throws Exception { - InputStream xmlStream = RemoteInputStreamClient.wrap(xmlRemoteStream); - Map<String, InputStream> attachmentStreams = new HashMap<String, InputStream>(); - for (Map.Entry<String, RemoteInputStream> entry : attachmentsRemoteStream - .entrySet()) { - InputStream stream = RemoteInputStreamClient.wrap(entry.getValue()); - attachmentStreams.put(entry.getKey(), stream); + throws SimExplorerServiceException { + try { + InputStream xmlStream = RemoteInputStreamClient.wrap(xmlRemoteStream); + Map<String, InputStream> attachmentStreams = new HashMap<String, InputStream>(); + for (Map.Entry<String, RemoteInputStream> entry : attachmentsRemoteStream + .entrySet()) { + InputStream stream = RemoteInputStreamClient.wrap(entry.getValue()); + attachmentStreams.put(entry.getKey(), stream); + } + return saveElement(token, xmlStream, attachmentStreams); + } catch (Exception e) { + throw new SimExplorerServiceException(e); } - return saveElement(token, xmlStream, attachmentStreams); } - public MetaDataEntity getMetadata(String token, String uuid) throws Exception { - return storageEngine.getMetadata(token, uuid); + public MetaDataEntity getMetadata(String token, String uuid) throws SimExplorerServiceException { + try { + return storageEngine.getMetadata(token, uuid); + } catch (StorageException e) { + throw new SimExplorerServiceException(e); + } } public MetaDataEntity getMetadata(String token, String uuid, String version) - throws Exception { - return storageEngine.getMetadata(token, uuid, new Version(version)); + throws SimExplorerServiceException { + try { + return storageEngine.getMetadata(token, uuid, new Version(version)); + } catch (StorageException e) { + throw new SimExplorerServiceException(e); + } } public MetaDataEntity[] findFullText(String token, String query, boolean onlyLatest, - int indexStart, int count, int dateOrder) throws Exception { - return storageEngine.findFullText(token, query, onlyLatest, indexStart, count, - dateOrder); + int indexStart, int count, int dateOrder) throws SimExplorerServiceException { + try { + return storageEngine.findFullText(token, query, onlyLatest, indexStart, count,dateOrder); + } catch (StorageException e) { + throw new SimExplorerServiceException(e); + } } public int findFullTextCount(String token, String query, boolean onlyLatest) - throws Exception { - return storageEngine.findFullTextCount(token, query, onlyLatest); + throws SimExplorerServiceException { + try { + return storageEngine.findFullTextCount(token, query, onlyLatest); + } catch (StorageException e) { + throw new SimExplorerServiceException(e); + } } - public int findApplicationsCount(String token, boolean onlyLatest) throws Exception { - return storageEngine.findElementsByTypeCount(token, VALUE_METADATA_TYPE_EA, - onlyLatest); + public int findApplicationsCount(String token, boolean onlyLatest) throws SimExplorerServiceException { + try { + return storageEngine.findElementsByTypeCount(token, VALUE_METADATA_TYPE_EA,onlyLatest); + } catch (StorageException e) { + throw new SimExplorerServiceException(e); + } } public MetaDataEntity[] findApplications(String token, boolean onlyLatest, int start, - int count, int dateOrder) throws Exception { - return storageEngine.findElementsByType(token, VALUE_METADATA_TYPE_EA, - onlyLatest, start, count, dateOrder); + int count, int dateOrder) throws SimExplorerServiceException { + try { + return storageEngine.findElementsByType(token, VALUE_METADATA_TYPE_EA,onlyLatest, start, count, dateOrder); + } catch (StorageException e) { + throw new SimExplorerServiceException(e); + } } public LoggableElement getElement(String token, String uuid, String version) - throws Exception { + throws SimExplorerServiceException { MetaDataEntity mde = getMetadata(token, uuid, version); - LoggableElement le = (LoggableElement) BaseEntityFactory.getFactory( - LoggableElement.class.getPackage().getName() + "." + mde.getType()) - .loadElement(storageEngine.retrieveData(token, mde, KEY_XML)); + try { + LoggableElement le; + le = (LoggableElement) BaseEntityFactory.getFactory( + LoggableElement.class.getPackage().getName() + "." + mde.getType()) + .loadElement(storageEngine.retrieveData(token, mde, KEY_XML)); - return le; + return le; + } catch (Exception e) { + throw new SimExplorerServiceException(e); + } } - private MetaDataEntity saveElement(String token, InputStream zipStream) throws Exception { + private MetaDataEntity saveElement(String token, InputStream zipStream) throws SimExplorerServiceException { String xmlFile = null; Map<String, String> attachments = new HashMap<String, String>(); ZipInputStream zis = new ZipInputStream(zipStream); - ZipEntry entry; - while ((entry = zis.getNextEntry()) != null) { - if (!entry.isDirectory()) { - String entryName = entry.getName(); - if (entryName.equals(FILE_XML)) { - xmlFile = storageEngine.storeTempData(zis); - } else { - if (entryName.startsWith(FILE_DATA_PREFIX)) { - String fileName = entryName.replace(FILE_DATA_PREFIX - + "/", ""); - String idFile = storageEngine.storeTempData(zis); - attachments.put(fileName, idFile); + try { + ZipEntry entry; + while ((entry = zis.getNextEntry()) != null) { + if (!entry.isDirectory()) { + String entryName = entry.getName(); + if (entryName.equals(FILE_XML)) { + xmlFile = storageEngine.storeTempData(zis); + } else { + if (entryName.startsWith(FILE_DATA_PREFIX)) { + String fileName = entryName.replace(FILE_DATA_PREFIX + + "/", ""); + String idFile = storageEngine.storeTempData(zis); + attachments.put(fileName, idFile); + } } } } + return saveElement(token, xmlFile, attachments); + } catch (Exception e) { + throw new SimExplorerServiceException(e); } - - return saveElement(token, xmlFile, attachments); } public MetaDataEntity saveElement(String token, InputStream xmlFile, @@ -174,30 +219,43 @@ } public RemoteInputStream retrieveData(String token, String uuid, - String version, String dataKey) throws Exception { - MetaDataEntity mde = getMetadata(token, uuid, version); - InputStream stream = storageEngine.retrieveData(token, mde, dataKey); - RemoteInputStreamServer remoteStream = new SimpleRemoteInputStream( - stream); - return remoteStream.export(); + String version, String dataKey) throws SimExplorerServiceException { + try { + MetaDataEntity mde = getMetadata(token, uuid, version); + InputStream stream = storageEngine.retrieveData(token, mde, dataKey); + RemoteInputStreamServer remoteStream = new SimpleRemoteInputStream( + stream); + return remoteStream.export(); + } catch (StorageException e) { + throw new SimExplorerServiceException(e); + } catch (RemoteException e) { + throw new SimExplorerServiceException(e); + } } public void exportElement(String token, RemoteOutputStream xmlOutputStream, String uuid, - String version) throws Exception { + String version) throws SimExplorerServiceException { MetaDataEntity mde = getMetadata(token, uuid, version); - InputStream xmlStream = storageEngine.retrieveData(token, mde, KEY_XML); - OutputStream os = RemoteOutputStreamClient.wrap(xmlOutputStream); + try { + InputStream xmlStream = storageEngine.retrieveData(token, 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); + // 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(); + } catch (StorageException e) { + throw new SimExplorerServiceException(e); + } catch (IOException e) { + throw new SimExplorerServiceException(e); } - bout.flush(); } @@ -213,8 +271,7 @@ private MetaDataEntity saveElement(String token, String idxml, Map<String, String> idsattachment) throws Exception { // Load metadata xml - MetaDataEntityFactory mdeFactory = (MetaDataEntityFactory) BaseEntityFactory - .getFactory(MetaDataEntity.class); + MetaDataEntityFactory mdeFactory = MetaDataEntityFactory.getFactory(MetaDataEntity.class); MetaDataEntity metaData = mdeFactory .loadElementFromParentXML(storageEngine.retrieveTempData(idxml)); @@ -303,8 +360,7 @@ Map<String, String> idsattachment, List<String> components, List<String[]> explorationDatas) throws Exception { - MetaDataEntityFactory<MetaDataEntity> elementFactory = (MetaDataEntityFactory) BaseEntityFactory - .getFactory(MetaDataEntity.class); + BaseEntityFactory<MetaDataEntity> elementFactory = MetaDataEntityFactory.getFactory(MetaDataEntity.class); Document document = BaseEntityFactory.getXMLBuilder().parse( storageEngine.retrieveTempData(idxml)); @@ -335,7 +391,7 @@ String result = elementFactory.getXMLProperty(element, KEY_RESULT_FILE); - String[] explorationDataArray = null; + String[] explorationDataArray; if (result != null) { explorationDataArray = new String[2]; explorationDataArray[1] = result; @@ -350,8 +406,12 @@ } - public MetaDataEntity[] getVersions(String token, String uuid) throws Exception { - Set<MetaDataEntity> versions = storageEngine.getElementVersions(token, uuid); - return versions.toArray(new MetaDataEntity[versions.size()]); + public MetaDataEntity[] getVersions(String token, String uuid) throws SimExplorerServiceException { + try { + Set<MetaDataEntity> versions = storageEngine.getElementVersions(token, uuid); + return versions.toArray(new MetaDataEntity[versions.size()]); + } catch (StorageException e) { + throw new SimExplorerServiceException(e); + } } }
participants (1)
-
tchemit@users.labs.libre-entreprise.org