From 9a6f3a7c27025eb2b164eedbed37692f7a25f307 Mon Sep 17 00:00:00 2001 From: car031 Date: Mon, 25 Nov 2024 07:36:15 +0100 Subject: [PATCH] removed code smells --- .../com/logicaldoc/core/lock/LockManager.java | 1 - .../core/searchengine/IndexerTask.java | 1 + .../logicaldoc/core/searchengine/Search.java | 1 - .../core/searchengine/TagSearch.java | 1 - .../searchengine/folder/FolderSearch.java | 1 - .../util/junit/AbstractTestCase.java | 8 ++----- .../java/com/logicaldoc/util/time/Pause.java | 23 +++++++++++++++++++ .../com/logicaldoc/util/time/PauseTest.java | 22 ++++++++++++++++++ 8 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 logicaldoc-util/src/main/java/com/logicaldoc/util/time/Pause.java create mode 100644 logicaldoc-util/src/test/java/com/logicaldoc/util/time/PauseTest.java diff --git a/logicaldoc-core/src/main/java/com/logicaldoc/core/lock/LockManager.java b/logicaldoc-core/src/main/java/com/logicaldoc/core/lock/LockManager.java index 679916dc5..198faad11 100644 --- a/logicaldoc-core/src/main/java/com/logicaldoc/core/lock/LockManager.java +++ b/logicaldoc-core/src/main/java/com/logicaldoc/core/lock/LockManager.java @@ -41,7 +41,6 @@ public class LockManager { * * @return the lists of transactions */ - @SuppressWarnings("unchecked") public List getAllTransactions() { try { return genericDao.queryForList( diff --git a/logicaldoc-core/src/main/java/com/logicaldoc/core/searchengine/IndexerTask.java b/logicaldoc-core/src/main/java/com/logicaldoc/core/searchengine/IndexerTask.java index 86c53147e..6cb57a18d 100644 --- a/logicaldoc-core/src/main/java/com/logicaldoc/core/searchengine/IndexerTask.java +++ b/logicaldoc-core/src/main/java/com/logicaldoc/core/searchengine/IndexerTask.java @@ -118,6 +118,7 @@ protected void runTask() throws TaskException { errors = 0; indexed = 0; indexingTime = 0; + parsingTime = 0; try { Integer max = getMax(); diff --git a/logicaldoc-core/src/main/java/com/logicaldoc/core/searchengine/Search.java b/logicaldoc-core/src/main/java/com/logicaldoc/core/searchengine/Search.java index 11cc68dd6..88c2d8665 100644 --- a/logicaldoc-core/src/main/java/com/logicaldoc/core/searchengine/Search.java +++ b/logicaldoc-core/src/main/java/com/logicaldoc/core/searchengine/Search.java @@ -265,7 +265,6 @@ protected Collection getAccessibleFolderIds() throws SearchException { * * @throws SearchException error in the data layer */ - @SuppressWarnings("unchecked") protected Set getDeniedDocIds(List hits, Collection accessibleFolderIds) throws SearchException { HashSet denied = new HashSet<>(); if (searchUser.isAdmin() || hits.isEmpty()) diff --git a/logicaldoc-core/src/main/java/com/logicaldoc/core/searchengine/TagSearch.java b/logicaldoc-core/src/main/java/com/logicaldoc/core/searchengine/TagSearch.java index 72e36cd8b..5ff8745e8 100644 --- a/logicaldoc-core/src/main/java/com/logicaldoc/core/searchengine/TagSearch.java +++ b/logicaldoc-core/src/main/java/com/logicaldoc/core/searchengine/TagSearch.java @@ -28,7 +28,6 @@ public class TagSearch extends Search { protected TagSearch() { } - @SuppressWarnings("unchecked") @Override public void internalSearch() throws SearchException { DocumentDAO dao = Context.get().getBean(DocumentDAO.class); diff --git a/logicaldoc-core/src/main/java/com/logicaldoc/core/searchengine/folder/FolderSearch.java b/logicaldoc-core/src/main/java/com/logicaldoc/core/searchengine/folder/FolderSearch.java index c34c6827e..da0a3e826 100644 --- a/logicaldoc-core/src/main/java/com/logicaldoc/core/searchengine/folder/FolderSearch.java +++ b/logicaldoc-core/src/main/java/com/logicaldoc/core/searchengine/folder/FolderSearch.java @@ -51,7 +51,6 @@ public class FolderSearch extends Search { private String query; - @SuppressWarnings("unchecked") @Override public void internalSearch() throws SearchException { UserDAO userDAO = Context.get().getBean(UserDAO.class); diff --git a/logicaldoc-util/src/main/java/com/logicaldoc/util/junit/AbstractTestCase.java b/logicaldoc-util/src/main/java/com/logicaldoc/util/junit/AbstractTestCase.java index b51d5f0c3..479d19d9e 100644 --- a/logicaldoc-util/src/main/java/com/logicaldoc/util/junit/AbstractTestCase.java +++ b/logicaldoc-util/src/main/java/com/logicaldoc/util/junit/AbstractTestCase.java @@ -1,6 +1,5 @@ package com.logicaldoc.util.junit; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import java.io.File; @@ -14,8 +13,6 @@ import java.util.List; import java.util.Map; import java.util.Properties; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; import javax.sql.DataSource; @@ -34,6 +31,7 @@ import com.logicaldoc.util.io.FileUtil; import com.logicaldoc.util.plugin.PluginException; import com.logicaldoc.util.plugin.PluginRegistry; +import com.logicaldoc.util.time.Pause; /** * Abstract test case that of database and context initialization. @@ -218,8 +216,6 @@ protected Connection getConnection() throws SQLException { } protected void waiting() throws InterruptedException { - final int secondsToWait = 5; - CountDownLatch latch = new CountDownLatch(1); - assertFalse(latch.await(secondsToWait, TimeUnit.SECONDS)); + Pause.doPause(5000L); } } \ No newline at end of file diff --git a/logicaldoc-util/src/main/java/com/logicaldoc/util/time/Pause.java b/logicaldoc-util/src/main/java/com/logicaldoc/util/time/Pause.java new file mode 100644 index 000000000..972824b19 --- /dev/null +++ b/logicaldoc-util/src/main/java/com/logicaldoc/util/time/Pause.java @@ -0,0 +1,23 @@ +package com.logicaldoc.util.time; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/** + * A simple class to pause the current thread + * + * @author Marco Meschieri - LogicalDOC + * @since 9.0.1 + */ +public abstract class Pause { + + private Pause() { + // Empty + } + + public static void doPause(long ms) throws InterruptedException { + CountDownLatch latch = new CountDownLatch(1); + if (latch.await(ms, TimeUnit.MILLISECONDS)) + throw new IllegalStateException("Unexpected latch status"); + } +} \ No newline at end of file diff --git a/logicaldoc-util/src/test/java/com/logicaldoc/util/time/PauseTest.java b/logicaldoc-util/src/test/java/com/logicaldoc/util/time/PauseTest.java new file mode 100644 index 000000000..8ed8e1dab --- /dev/null +++ b/logicaldoc-util/src/test/java/com/logicaldoc/util/time/PauseTest.java @@ -0,0 +1,22 @@ +package com.logicaldoc.util.time; + +import static org.junit.Assert.assertEquals; + +import java.util.Date; + +import org.junit.Test; + +import com.logicaldoc.util.junit.AbstractTestCase; +import com.logicaldoc.util.time.TimeDiff.TimeField; + +public class PauseTest extends AbstractTestCase { + + @Test + public void testDoPause() throws InterruptedException { + Date date1 = new Date(); + Pause.doPause(2000); + Date date2 = new Date(); + + assertEquals(2L, TimeDiff.getTimeDifference(date1, date2, TimeField.SECOND)); + } +} \ No newline at end of file