diff options
4 files changed, 91 insertions, 6 deletions
diff --git a/src/net/java/sip/communicator/impl/history/HistoryServiceImpl.java b/src/net/java/sip/communicator/impl/history/HistoryServiceImpl.java index 50e857d..7a13337 100644 --- a/src/net/java/sip/communicator/impl/history/HistoryServiceImpl.java +++ b/src/net/java/sip/communicator/impl/history/HistoryServiceImpl.java @@ -18,6 +18,7 @@ import net.java.sip.communicator.util.*; /** * @author Alexander Pelov + * @author Damian Minkov */ public class HistoryServiceImpl implements HistoryService { @@ -223,7 +224,7 @@ public class HistoryServiceImpl implements HistoryService { /** * Set the configuration service. * - * @param configurationService + * @param configurationService ConfigurationService */ public void setConfigurationService( ConfigurationService configurationService) @@ -245,7 +246,7 @@ public class HistoryServiceImpl implements HistoryService { /** * Remove a configuration service. * - * @param configurationService + * @param configurationService ConfigurationService */ public void unsetConfigurationService( ConfigurationService configurationService) @@ -263,7 +264,7 @@ public class HistoryServiceImpl implements HistoryService { /** * Set the file access service. * - * @param fileAccessService + * @param fileAccessService FileAccessService */ public void setFileAccessService(FileAccessService fileAccessService) { @@ -277,7 +278,7 @@ public class HistoryServiceImpl implements HistoryService { /** * Remove the file access service. * - * @param fileAccessService + * @param fileAccessService FileAccessService */ public void unsetFileAccessService(FileAccessService fileAccessService) { @@ -300,4 +301,44 @@ public class HistoryServiceImpl implements HistoryService { return cacheEnabled; } + /** + * Permamently removes local stored History + * + * @param id HistoryID + * @throws IOException + */ + public void purgeLocallyStoredHistory(HistoryID id) + throws IOException + { + // get the history direcoty coresponding the given id + File dir = this.createHistoryDirectories(id); + log.trace("Removing history directory " + dir); + deleteDirAndContent(dir); + } + + /** + * Deletes given directory and its content + * + * @param dir File + * @throws IOException + */ + private void deleteDirAndContent(File dir) + throws IOException + { + if(!dir.isDirectory()) + return; + + File[] content = dir.listFiles(); + + File tmp; + for (int i = 0; i < content.length; i++) + { + tmp = content[i]; + if(tmp.isDirectory()) + deleteDirAndContent(tmp); + else + tmp.delete(); + } + dir.delete(); + } } diff --git a/src/net/java/sip/communicator/service/history/HistoryService.java b/src/net/java/sip/communicator/service/history/HistoryService.java index 36ca765..cac0a85 100644 --- a/src/net/java/sip/communicator/service/history/HistoryService.java +++ b/src/net/java/sip/communicator/service/history/HistoryService.java @@ -74,4 +74,13 @@ public interface HistoryService { */ History createHistory(HistoryID id, HistoryRecordStructure recordStructure) throws IllegalArgumentException, IOException; + + /** + * Permamently removes local stored History + * + * @param id HistoryID + * @throws IOException + * Thrown if the history could not be removed due to a IO error. + */ + public void purgeLocallyStoredHistory(HistoryID id) throws IOException; } diff --git a/test/net/java/sip/communicator/slick/history/HistoryServiceLick.java b/test/net/java/sip/communicator/slick/history/HistoryServiceLick.java index d74b685..f50581b 100644 --- a/test/net/java/sip/communicator/slick/history/HistoryServiceLick.java +++ b/test/net/java/sip/communicator/slick/history/HistoryServiceLick.java @@ -39,7 +39,7 @@ public class HistoryServiceLick extends TestSuite implements BundleActivator { Hashtable properties = new Hashtable(); properties.put("service.pid", getName()); - addTestSuite(TestHistoryService.class); + addTest(TestHistoryService.suite()); bundleContext.registerService(getClass().getName(), this, properties); logger.debug("Successfully registered " + getClass().getName()); diff --git a/test/net/java/sip/communicator/slick/history/TestHistoryService.java b/test/net/java/sip/communicator/slick/history/TestHistoryService.java index 9ca2833..dad96c1 100644 --- a/test/net/java/sip/communicator/slick/history/TestHistoryService.java +++ b/test/net/java/sip/communicator/slick/history/TestHistoryService.java @@ -30,11 +30,22 @@ public class TestHistoryService extends TestCase { private Random random = new Random(); public TestHistoryService(String name) - throws Exception { super(name); } + public static Test suite() + { + TestSuite suite = new TestSuite(); + + suite.addTest(new TestHistoryService("testCreateDB")); + suite.addTest(new TestHistoryService("testWriteRecords")); + suite.addTest(new TestHistoryService("testReadRecords")); + suite.addTest(new TestHistoryService("testPurgeLocallyStoredHistory")); + + return suite; + } + protected void setUp() throws Exception { @@ -110,6 +121,17 @@ public class TestHistoryService extends TestCase { { fail("Could not create database with id " + id + " with error " + e); } + + try + { + // after creating, remove it - do not leave content + this.historyService.purgeLocallyStoredHistory(id); + } + catch (Exception ex) + { + fail("Cannot delete local history with id " + this.history.getID() + + " : " + ex.getMessage()); + } } public void testWriteRecords() @@ -155,4 +177,17 @@ public class TestHistoryService extends TestCase { } } } + + public void testPurgeLocallyStoredHistory() + { + try + { + this.historyService.purgeLocallyStoredHistory(this.history.getID()); + } + catch (Exception ex) + { + fail("Cannot delete local history with id " + this.history.getID() + + " : " + ex.getMessage()); + } + } } |