Author: glandais Date: 2008-02-11 18:04:20 +0000 (Mon, 11 Feb 2008) New Revision: 820 Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageService.java trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceServer.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementHistory.java Log: getVersions returns an array of Version (instead of MetaData) Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageService.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageService.java 2008-02-11 17:14:08 UTC (rev 819) +++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageService.java 2008-02-11 18:04:20 UTC (rev 820) @@ -311,7 +311,7 @@ * @throws SimExplorerServiceException * the sim explorer service exception */ - MetaData[] getVersions(String token, String uuid) + Version[] getVersions(String token, String uuid) throws SimExplorerServiceException; /** Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-02-11 17:14:08 UTC (rev 819) +++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-02-11 18:04:20 UTC (rev 820) @@ -23,8 +23,8 @@ import java.io.InputStream; import java.io.PipedInputStream; import java.io.PipedOutputStream; -import java.rmi.RemoteException; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -39,8 +39,6 @@ import com.healthmarketscience.rmiio.RemoteInputStream; import com.healthmarketscience.rmiio.RemoteInputStreamClient; -import com.healthmarketscience.rmiio.RemoteInputStreamServer; -import com.healthmarketscience.rmiio.SimpleRemoteInputStream; import fr.cemagref.simexplorer.is.attachment.Attachment; import fr.cemagref.simexplorer.is.entities.data.DataEntity; @@ -67,8 +65,7 @@ * * @return the storage engine * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ protected abstract StorageEngine getStorageEngine() throws SimExplorerStorageException; @@ -228,15 +225,12 @@ /** * Save element. * - * @param token - * the token - * @param zipStream - * the zip stream + * @param token the token + * @param zipStream the zip stream * * @return the meta data * - * @throws SimExplorerServiceException - * the sim explorer service exception + * @throws SimExplorerServiceException the sim explorer service exception */ private MetaData saveElement(String token, InputStream zipStream) throws SimExplorerServiceException { @@ -298,17 +292,13 @@ /** * Save element. * - * @param token - * the token - * @param xmlFile - * the xml file - * @param attachments - * the attachments + * @param token the token + * @param xmlFile the xml file + * @param attachments the attachments * * @return the meta data * - * @throws Exception - * the exception + * @throws Exception the exception */ private MetaData saveElement(String token, InputStream xmlFile, Map<Attachment, InputStream> attachments) throws Exception { @@ -328,6 +318,18 @@ return elementSaved; } + /** + * Retrieve element data common. + * + * @param token the token + * @param uuid the uuid + * @param version the version + * @param attachment the attachment + * + * @return the input stream + * + * @throws SimExplorerServiceException the sim explorer service exception + */ protected InputStream retrieveElementDataCommon(String token, String uuid, String version, Attachment attachment) throws SimExplorerServiceException { @@ -342,6 +344,17 @@ } } + /** + * Retrieve element xml common. + * + * @param token the token + * @param uuid the uuid + * @param version the version + * + * @return the input stream + * + * @throws SimExplorerServiceException the sim explorer service exception + */ public InputStream retrieveElementXMLCommon(String token, String uuid, String version) throws SimExplorerServiceException { MetaData mde = getMetadata(token, uuid, version); @@ -355,6 +368,17 @@ } + /** + * Retrieve element full common. + * + * @param token the token + * @param uuid the uuid + * @param version the version + * + * @return the input stream + * + * @throws SimExplorerServiceException the sim explorer service exception + */ public InputStream retrieveElementFullCommon(String token, String uuid, String version) throws SimExplorerServiceException { LoggableElement element = getLoggableElement(token, uuid, version); @@ -394,17 +418,13 @@ /** * Real implementation of saveElement. * - * @param token - * the token - * @param idxml - * the idxml - * @param idsattachment - * the idsattachment + * @param token the token + * @param idxml the idxml + * @param idsattachment the idsattachment * * @return the meta data * - * @throws Exception - * the exception + * @throws Exception the exception */ private MetaData saveElement(String token, String idxml, Map<Attachment, String> idsattachment) throws Exception { @@ -466,19 +486,13 @@ /** * Save sub elements. * - * @param token - * the token - * @param idxml - * the idxml - * @param entitiesNode - * the entities node - * @param entityNode - * the entity node - * @param idsattachment - * the idsattachment + * @param token the token + * @param idxml the idxml + * @param entitiesNode the entities node + * @param entityNode the entity node + * @param idsattachment the idsattachment * - * @throws Exception - * the exception + * @throws Exception the exception */ private void saveSubElements(String token, String idxml, String entitiesNode, String entityNode, @@ -509,17 +523,12 @@ /** * Update. * - * @param token - * the token - * @param oldVersion - * the old version - * @param newVersion - * the new version - * @param oldUuid - * the old uuid + * @param token the token + * @param oldVersion the old version + * @param newVersion the new version + * @param oldUuid the old uuid * - * @throws SimExplorerServiceException - * the sim explorer service exception + * @throws SimExplorerServiceException the sim explorer service exception */ protected void update(String token, String oldUuid, Version oldVersion, MetaData newVersion) throws SimExplorerServiceException { @@ -557,13 +566,10 @@ /** * Process version rules. * - * @param token - * the token - * @param metaData - * the meta data + * @param token the token + * @param metaData the meta data * - * @throws Exception - * the exception + * @throws Exception the exception */ protected abstract void processVersionRules(String token, MetaData metaData) throws Exception; @@ -571,12 +577,19 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.StorageService#getVersions(java.lang.String, java.lang.String) */ - public MetaData[] getVersions(String token, String uuid) + public Version[] getVersions(String token, String uuid) throws SimExplorerServiceException { try { Set<MetaData> versions = getStorageEngine().getElementVersions( - token, uuid); - return versions.toArray(new MetaData[versions.size()]); + token, uuid); + Iterator<MetaData> iterator = versions.iterator(); + Version[] result = new Version[versions.size()]; + int i = 0; + for (MetaData metaData : versions) { + result[i] = metaData.getVersion(); + i++; + } + return result; } catch (SimExplorerStorageException e) { throw new SimExplorerServiceException(e); } Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceServer.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceServer.java 2008-02-11 17:14:08 UTC (rev 819) +++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceServer.java 2008-02-11 18:04:20 UTC (rev 820) @@ -81,8 +81,8 @@ // Version rules if (previousVersion != null) { previousVersion.setLatest(false); - update(token, previousVersion.getUuid(), previousVersion - .getVersion(), previousVersion); +// update(token, previousVersion.getUuid(), previousVersion +// .getVersion(), previousVersion); metaData.setLatest(true); metaData.setVersion(previousVersion.getVersion().incVersion(0) Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java 2008-02-11 17:14:08 UTC (rev 819) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java 2008-02-11 18:04:20 UTC (rev 820) @@ -135,6 +135,10 @@ Reader reader = new StringReader(element.getDescription()); readers.add(reader); } + Map<String, String> descriptors = element.getDescriptors(); + for (Map.Entry<String, String> descriptor : descriptors.entrySet()) { + readers.add(new StringReader(descriptor.getValue())); + } // Insert element in database database.insertElement(element, readers); @@ -251,8 +255,7 @@ /** * Gets the tmp attachment. * - * @param id - * the id + * @param id the id * * @return the tmp attachment */ Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementHistory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementHistory.java 2008-02-11 17:14:08 UTC (rev 819) +++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementHistory.java 2008-02-11 18:04:20 UTC (rev 820) @@ -27,6 +27,7 @@ import fr.cemagref.simexplorer.is.entities.metadata.MetaData; import fr.cemagref.simexplorer.is.entities.metadata.Version; +import fr.cemagref.simexplorer.is.service.SimExplorerServiceException; import fr.cemagref.simexplorer.is.ui.web.SimExplorerWebException; import fr.cemagref.simexplorer.is.ui.web.services.RemoteStorageService; @@ -35,23 +36,9 @@ */ public class ElementHistory extends ElementPageDetail { - /** - * The Class MetadataVersionComparator. - */ - public class MetadataVersionComparator implements Comparator<MetaData> { - - /* (non-Javadoc) - * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) - */ - public int compare(MetaData arg0, MetaData arg1) { - return arg0.getVersion().compareTo(arg1.getVersion()); - } - - } - /** The versions. */ @Persist - private MetaData[] versions; + private Version[] versions; /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.ui.web.pages.ElementPage#setup(java.lang.String, java.lang.String) @@ -92,8 +79,10 @@ * Gets the versions. * * @return the versions + * + * @throws SimExplorerServiceException the sim explorer service exception */ - public List<TreeNode> getVersions() { + public List<TreeNode> getVersions() throws SimExplorerServiceException { List<TreeNode> nodes = new ArrayList<TreeNode>(); nodes.add(generateNodes()); return nodes; @@ -103,17 +92,19 @@ * Generate nodes. * * @return the tree node + * + * @throws SimExplorerServiceException the sim explorer service exception */ - private TreeNode generateNodes() { - Arrays.sort(versions, new MetadataVersionComparator()); + private TreeNode generateNodes() throws SimExplorerServiceException { + Arrays.sort(versions); TreeNode rootNode = new TreeNode(); rootNode.setType(TreeNode.TYPE_FOLDER); rootNode.setColumns(generateStringArray(getMessages().get( "simexplorer.ui.web.history"))); rootNode.setObject(new Version("")); rootNode.setChildren(new ArrayList<TreeNode>()); - for (MetaData mde : versions) { - insertNode(mde, 0, rootNode); + for (Version version : versions) { + insertNode(version, 0, rootNode); } return rootNode; } @@ -121,50 +112,46 @@ /** * Insert node. * - * @param mde - * the mde - * @param pos - * the pos - * @param parent - * the parent + * @param pos the pos + * @param parent the parent + * @param version the version + * + * @throws SimExplorerServiceException the sim explorer service exception */ - private void insertNode(MetaData mde, int pos, TreeNode parent) { + private void insertNode(Version version, int pos, TreeNode parent) throws SimExplorerServiceException { List<TreeNode> nodes = parent.getChildren(); - if (pos == mde.getVersion().getLength()) { - nodes.add(generateLeaf(mde)); + if (pos == version.getLength()) { + nodes.add(generateLeaf(version)); } else { TreeNode parentNode = null; for (TreeNode treeNode : nodes) { if (getVersion(treeNode).getVersion(pos) != null && getVersion(treeNode).getVersion(pos).equals( - mde.getVersion().getVersion(pos))) { + version.getVersion(pos))) { parentNode = treeNode; } } if (parentNode == null) { - parentNode = generateFolder(mde, pos, parent); + parentNode = generateFolder(version, pos, parent); nodes.add(parentNode); } - insertNode(mde, pos + 1, parentNode); + insertNode(version, pos + 1, parentNode); } } /** * Generate folder. * - * @param mde - * the mde - * @param pos - * the pos - * @param parent - * the parent + * @param pos the pos + * @param parent the parent + * @param version the version * * @return the tree node */ - private TreeNode generateFolder(MetaData mde, int pos, TreeNode parent) { + private TreeNode generateFolder(Version version, int pos, TreeNode parent) { TreeNode node = new TreeNode(); node.setChildren(new ArrayList<TreeNode>()); - Version v = generateVersion(mde.getVersion(), pos); + Version v = generateVersion(version, pos); node.setColumns(generateStringArray(v.toString())); node.setObject(v); node.setType(TreeNode.TYPE_FOLDER); @@ -174,10 +161,8 @@ /** * Generate version. * - * @param version - * the version - * @param pos - * the pos + * @param version the version + * @param pos the pos * * @return the version */ @@ -192,13 +177,16 @@ /** * Generate leaf. * - * @param mde - * the mde + * @param version the version * * @return the tree node + * + * @throws SimExplorerServiceException the sim explorer service exception */ - private TreeNode generateLeaf(MetaData mde) { + private TreeNode generateLeaf(Version version) throws SimExplorerServiceException { TreeNode node = new TreeNode(); + MetaData mde = RemoteStorageService.getStorageService().getMetadata( + getToken(), getMetadata().getUuid(), version.toString()); // FIXME date tostring node.setColumns(generateStringArray(mde.getVersion().toString(), mde .getDescription(), mde.getCreationDate().toString(), mde, @@ -211,8 +199,7 @@ /** * Gets the version. * - * @param treeNode - * the tree node + * @param treeNode the tree node * * @return the version */