You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by ma...@apache.org on 2012/08/03 14:28:07 UTC

svn commit: r1368917 - in /ace/sandbox/marrs: org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/ org.apache.ace.client.repository.impl/test/org/apache/ace/client/repository/impl/ org.apache.ace.client.rest/src/org/apache/a...

Author: marrs
Date: Fri Aug  3 12:28:06 2012
New Revision: 1368917

URL: http://svn.apache.org/viewvc?rev=1368917&view=rev
Log:
ACE-287 Added new methods to the interfaces of Cached- and BackupRepository, implemented them and hooked everything up.

Modified:
    ace/sandbox/marrs/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java
    ace/sandbox/marrs/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/RepositorySet.java
    ace/sandbox/marrs/org.apache.ace.client.repository.impl/test/org/apache/ace/client/repository/impl/MockBackupRepository.java
    ace/sandbox/marrs/org.apache.ace.client.repository.impl/test/org/apache/ace/client/repository/impl/MockCachedRepository.java
    ace/sandbox/marrs/org.apache.ace.client.rest/src/org/apache/ace/client/rest/RESTClientServlet.java
    ace/sandbox/marrs/org.apache.ace.client.rest/src/org/apache/ace/client/rest/Workspace.java
    ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/BackupRepository.java
    ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/CachedRepository.java
    ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/impl/CachedRepositoryImpl.java
    ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/impl/FilebasedBackupRepository.java

Modified: ace/sandbox/marrs/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java?rev=1368917&r1=1368916&r2=1368917&view=diff
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java (original)
+++ ace/sandbox/marrs/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java Fri Aug  3 12:28:06 2012
@@ -388,6 +388,7 @@ public class RepositoryAdminImpl impleme
             for (RepositorySet set : m_repositorySets) {
                 set.clearRepositories();
                 set.unregisterHandler();
+                set.deleteLocal();
             }
 
             m_user = null;
@@ -472,11 +473,7 @@ public class RepositoryAdminImpl impleme
         String sessionLocation = PREFS_LOCAL_FILE_LOCATION + m_sessionID;
         String directory = repositoryPrefs.get(sessionLocation, "");
 
-        if ((directory == "") || !m_context.getDataFile(PREFS_LOCAL_FILE_ROOT + "/" + directory).isDirectory()) {
-            if (!m_context.getDataFile(PREFS_LOCAL_FILE_ROOT + "/" + directory).isDirectory() && (directory != "")) {
-                m_log.log(LogService.LOG_WARNING, "Directory '" + directory + "' should exist according to the preferences, but it does not.");
-            }
-            // The file did not exist, so create a new one.
+        if (directory == "") {
             File directoryFile = null;
             try {
                 File bundleDataDir = m_context.getDataFile(PREFS_LOCAL_FILE_ROOT);
@@ -486,22 +483,20 @@ public class RepositoryAdminImpl impleme
                     }
                 }
                 directoryFile = File.createTempFile("repo", "", bundleDataDir);
+                if (!directoryFile.delete()) {
+                    throw new IOException("Cannot delete temporary file: " + directoryFile.getName());
+                }
             }
             catch (IOException e) {
-                // We cannot create the temp file? Then something is seriously wrong, so rethrow.
+                // We cannot create or delete the temp file? Then something is seriously wrong, so rethrow.
                 throw e;
             }
-
-            directoryFile.delete(); // No problem if this goes wrong, it just means it wasn't there yet.
-            if (!directoryFile.mkdir()) {
-                throw new IOException("Error creating the local repository storage directory.");
-            }
             repositoryPrefs.put(sessionLocation, directoryFile.getName());
-            return new File(directoryFile, type);
+            return new File(directoryFile + "-" + type);
         }
         else {
             // Get the given file from that location.
-            return m_context.getDataFile(PREFS_LOCAL_FILE_ROOT + "/" + directory + "/" + type);
+            return m_context.getDataFile(PREFS_LOCAL_FILE_ROOT + "/" + directory + "-" + type);
         }
     }
 

Modified: ace/sandbox/marrs/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/RepositorySet.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/RepositorySet.java?rev=1368917&r1=1368916&r2=1368917&view=diff
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/RepositorySet.java (original)
+++ ace/sandbox/marrs/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/RepositorySet.java Fri Aug  3 12:28:06 2012
@@ -265,6 +265,16 @@ class RepositorySet {
             }
         }
     }
+    
+    void deleteLocal() {
+    	try {
+			m_repository.deleteLocal();
+		}
+    	catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+    }
 
     /* ********
      * Event handling

Modified: ace/sandbox/marrs/org.apache.ace.client.repository.impl/test/org/apache/ace/client/repository/impl/MockBackupRepository.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.client.repository.impl/test/org/apache/ace/client/repository/impl/MockBackupRepository.java?rev=1368917&r1=1368916&r2=1368917&view=diff
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.client.repository.impl/test/org/apache/ace/client/repository/impl/MockBackupRepository.java (original)
+++ ace/sandbox/marrs/org.apache.ace.client.repository.impl/test/org/apache/ace/client/repository/impl/MockBackupRepository.java Fri Aug  3 12:28:06 2012
@@ -52,4 +52,9 @@ public class MockBackupRepository implem
     public void write(InputStream data) throws IOException {
         m_current = AdminTestUtil.copy(data);
     }
+    
+    public void delete() throws IOException {
+    	m_current = null;
+    	m_backup = null;
+    }
 }

Modified: ace/sandbox/marrs/org.apache.ace.client.repository.impl/test/org/apache/ace/client/repository/impl/MockCachedRepository.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.client.repository.impl/test/org/apache/ace/client/repository/impl/MockCachedRepository.java?rev=1368917&r1=1368916&r2=1368917&view=diff
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.client.repository.impl/test/org/apache/ace/client/repository/impl/MockCachedRepository.java (original)
+++ ace/sandbox/marrs/org.apache.ace.client.repository.impl/test/org/apache/ace/client/repository/impl/MockCachedRepository.java Fri Aug  3 12:28:06 2012
@@ -82,4 +82,8 @@ public class MockCachedRepository implem
         return 0;
     }
 
+    @Override
+    public void deleteLocal() throws IOException {
+    	// TODO Auto-generated method stub
+    }
 }

Modified: ace/sandbox/marrs/org.apache.ace.client.rest/src/org/apache/ace/client/rest/RESTClientServlet.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.client.rest/src/org/apache/ace/client/rest/RESTClientServlet.java?rev=1368917&r1=1368916&r2=1368917&view=diff
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.client.rest/src/org/apache/ace/client/rest/RESTClientServlet.java (original)
+++ ace/sandbox/marrs/org.apache.ace.client.rest/src/org/apache/ace/client/rest/RESTClientServlet.java Fri Aug  3 12:28:06 2012
@@ -26,6 +26,7 @@ import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
@@ -111,6 +112,21 @@ public class RESTClientServlet extends H
         m_workspaces = new HashMap<String, Workspace>();
         m_workspaceComponents = new HashMap<String, Component>();
     }
+    
+    public void destroy() {
+    	Set<String> keySet = m_workspaces.keySet();
+    	if (!keySet.isEmpty()) {
+    		String[] keys = keySet.toArray(new String[keySet.size()]);
+    		for (String key : keys) {
+    			try {
+					removeWorkspace(key);
+				}
+    			catch (IOException e) {
+    				m_logger.log(LogService.LOG_WARNING, "Could not properly remove workspace.", e);
+				}
+    		}
+    	}
+    }
 
     public void updated(Dictionary properties) throws ConfigurationException {
         // First check whether all mandatory configuration keys are available...
@@ -227,7 +243,12 @@ public class RESTClientServlet extends H
         }
 
         if (pathElements.length == 2) {
-            removeWorkspace(id, resp);
+        	try {
+        		removeWorkspace(id);
+        	}
+        	catch (IOException ioe) {
+                resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Could not delete work area: " + ioe.getMessage());
+        	}
         }
         else if (pathElements.length == 4) {
             deleteRepositoryObject(workspace, pathElements[2], pathElements[3], resp);
@@ -615,7 +636,7 @@ public class RESTClientServlet extends H
      * @param resp the servlet response to write the response data to.
      * @throws IOException in case of I/O problems.
      */
-    private void removeWorkspace(final String id, HttpServletResponse resp) throws IOException {
+    private void removeWorkspace(final String id) throws IOException {
         final Workspace workspace;
         final Component component;
 
@@ -625,13 +646,13 @@ public class RESTClientServlet extends H
         }
 
         if ((workspace != null) && (component != null)) {
-            workspace.destroy();
-
-            m_dm.remove(component);
-            m_sessionFactory.destroySession(id);
-        }
-        else {
-            resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Could not delete work area.");
+            try {
+                workspace.logout();
+            }
+            finally {
+                m_dm.remove(component);
+                m_sessionFactory.destroySession(id);
+            }
         }
     }
 

Modified: ace/sandbox/marrs/org.apache.ace.client.rest/src/org/apache/ace/client/rest/Workspace.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.client.rest/src/org/apache/ace/client/rest/Workspace.java?rev=1368917&r1=1368916&r2=1368917&view=diff
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.client.rest/src/org/apache/ace/client/rest/Workspace.java (original)
+++ ace/sandbox/marrs/org.apache.ace.client.rest/src/org/apache/ace/client/rest/Workspace.java Fri Aug  3 12:28:06 2012
@@ -190,7 +190,16 @@ public class Workspace {
     }
 
     public void commit() throws IOException {
-        m_repositoryAdmin.commit();
+		m_repositoryAdmin.commit();
+    }
+    
+    public void logout() throws IOException {
+        try {
+            m_repositoryAdmin.logout(true);
+        }
+        catch (IllegalStateException ise) {
+            m_log.log(LogService.LOG_DEBUG, "Nobody was logged into this session, continuing.");
+        }
     }
 
     public RepositoryObject getRepositoryObject(String entityType, String entityId) {

Modified: ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/BackupRepository.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/BackupRepository.java?rev=1368917&r1=1368916&r2=1368917&view=diff
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/BackupRepository.java (original)
+++ ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/BackupRepository.java Fri Aug  3 12:28:06 2012
@@ -63,4 +63,10 @@ public interface BackupRepository
      */
     public boolean backup() throws IOException;
 
+    /**
+     * Deletes the whole repository.
+     * 
+     * @throws IOException when the repository could not be deleted.
+     */
+    public void delete() throws IOException;
 }
\ No newline at end of file

Modified: ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/CachedRepository.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/CachedRepository.java?rev=1368917&r1=1368916&r2=1368917&view=diff
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/CachedRepository.java (original)
+++ ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/CachedRepository.java Fri Aug  3 12:28:06 2012
@@ -84,4 +84,11 @@ public interface CachedRepository extend
      * @throws java.io.IOException Thrown when an error occurs communicating with the server.
      */
     public boolean isCurrent() throws IOException;
+    
+    /**
+     * Deletes the local repository.
+     * 
+     * @throws IOException when the local repository could not be deleted
+     */
+    public void deleteLocal() throws IOException;
 }
\ No newline at end of file

Modified: ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/impl/CachedRepositoryImpl.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/impl/CachedRepositoryImpl.java?rev=1368917&r1=1368916&r2=1368917&view=diff
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/impl/CachedRepositoryImpl.java (original)
+++ ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/impl/CachedRepositoryImpl.java Fri Aug  3 12:28:06 2012
@@ -129,6 +129,10 @@ public class CachedRepositoryImpl implem
     public boolean isCurrent() throws IOException {
         return highestRemoteVersion() == m_mostRecentVersion;
     }
+    
+    public void deleteLocal() throws IOException {
+    	m_local.delete();
+    }
 
     private long highestRemoteVersion() throws IOException {
         long result = 0;

Modified: ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/impl/FilebasedBackupRepository.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/impl/FilebasedBackupRepository.java?rev=1368917&r1=1368916&r2=1368917&view=diff
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/impl/FilebasedBackupRepository.java (original)
+++ ace/sandbox/marrs/org.apache.ace.repository.ext/src/org/apache/ace/repository/ext/impl/FilebasedBackupRepository.java Fri Aug  3 12:28:06 2012
@@ -59,7 +59,7 @@ public class FilebasedBackupRepository i
             return new FileInputStream(m_current);
         }
         catch (FileNotFoundException e) {
-            throw new IOException("Unable to open file:" + e.getMessage());
+            throw new IOException("Unable to open file: " + e.getMessage(), e);
         }
     }
 
@@ -70,7 +70,7 @@ public class FilebasedBackupRepository i
             }
         }
         catch (IOException e) {
-            throw new IOException("Unable to create file:" + e.getMessage());
+            throw new IOException("Unable to create file: " + e.getMessage(), e);
         }
 
         try {
@@ -79,7 +79,7 @@ public class FilebasedBackupRepository i
             out.close();
         }
         catch (FileNotFoundException e) {
-            throw new IOException("Unable to open file:" + e.getMessage());
+            throw new IOException("Unable to open file: " + e.getMessage(), e);
         }
     }
 
@@ -99,6 +99,19 @@ public class FilebasedBackupRepository i
         return true;
     }
 
+    public void delete() throws IOException {
+        boolean deletedCurrent = true, deletedBackup = true;
+        if (m_current.exists()) {
+            deletedCurrent = m_current.delete();
+        }
+        if (m_backup.exists()) {
+            deletedBackup = m_backup.delete();
+        }
+        if (!(deletedCurrent && deletedBackup)) {
+            throw new IOException("Could not delete: " + (deletedCurrent ? "" : "current ") + (deletedBackup ? "" : "backup"));
+        }
+    }
+
     /**
      * Helper function that writes the contents of one file to another.
      * @param source The source file.
@@ -114,9 +127,17 @@ public class FilebasedBackupRepository i
         FileOutputStream out = new FileOutputStream(destination);
         FileInputStream in = new FileInputStream(source);
 
-        copy(in, out);
-        in.close();
-        out.close();
+        try {
+            copy(in, out);
+        }
+        finally {
+            if (in != null) {
+                in.close();
+            }
+            if (out != null) {
+                out.close();
+            }
+        }
     }
 
     /**