From 7ddfed8ef66cffaf649cd19991a29132569134ea Mon Sep 17 00:00:00 2001
From: Olivier Maury <Olivier.Maury@inrae.fr>
Date: Fri, 31 Jan 2025 14:10:13 +0100
Subject: [PATCH] fix: supprimer des avertissements PMD

---
 .../fr/soeretempo/sido/gwt/client/SidoData.java     |  2 +-
 .../sido/gwt/server/dao/DatasetDaoImpl.java         | 13 ++++---------
 .../server/downloadfile/FileDownloadServlet.java    |  1 -
 .../sido/gwt/server/metadata/IdentifierScheme.java  | 10 +++++++++-
 .../sido/gwt/server/model/oauth2/Scope.java         |  4 ++--
 .../gwt/server/openid/OIDCSessionAttributes.java    |  2 +-
 .../gwt/server/openid/OpenIdCallbackServlet.java    |  2 +-
 .../fr/soeretempo/sido/gwt/shared/StringUtils.java  |  3 +--
 8 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/client/SidoData.java b/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/client/SidoData.java
index b79d7e14..42eecd56 100644
--- a/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/client/SidoData.java
+++ b/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/client/SidoData.java
@@ -37,7 +37,7 @@ public final class SidoData {
      * @return instance singleton.
      */
     public static SidoData getInstance() {
-        return SidoData.instance;
+        return instance;
     }
 
     /**
diff --git a/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/dao/DatasetDaoImpl.java b/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/dao/DatasetDaoImpl.java
index b961af33..e2745464 100644
--- a/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/dao/DatasetDaoImpl.java
+++ b/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/dao/DatasetDaoImpl.java
@@ -263,15 +263,10 @@ public final class DatasetDaoImpl extends DaoHibernate implements DatasetDao {
     @Override
     public Set<User> getOwners(final long datasetId) {
         LOGGER.traceEntry("datasetId: " + datasetId);
-        try (ScopedEntityManager em = getScopedEntityManager()) {
-            final Dataset dataset = findById(datasetId);
-            final Set<User> result = dataset.getUsers();
-            LOGGER.traceExit(result);
-            return result;
-        } catch (final javax.persistence.NoResultException e) {
-            LOGGER.traceExit();
-            return new HashSet<>();
-        }
+        final Dataset dataset = findById(datasetId);
+        final Set<User> result = dataset.getUsers();
+        LOGGER.traceExit(result);
+        return result;
     }
 
 
diff --git a/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/downloadfile/FileDownloadServlet.java b/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/downloadfile/FileDownloadServlet.java
index 3d2878e6..ad428adc 100644
--- a/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/downloadfile/FileDownloadServlet.java
+++ b/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/downloadfile/FileDownloadServlet.java
@@ -89,7 +89,6 @@ public class FileDownloadServlet extends AbstractServlet {
                 response.setContentType(CONTENT_TYPE_TEXT_PLAIN);
                 response.sendError(HttpServletResponse.SC_UNAUTHORIZED,
                         i18n.get("msgSessionExpired"));
-                return;
             } else {
                 final String fileName;
                 final String filePath;
diff --git a/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/metadata/IdentifierScheme.java b/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/metadata/IdentifierScheme.java
index 25ba9701..f3218e9a 100644
--- a/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/metadata/IdentifierScheme.java
+++ b/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/metadata/IdentifierScheme.java
@@ -32,11 +32,19 @@ public enum IdentifierScheme {
      */
     private final String identifierValue;
 
+    /**
+     * Constructor.
+     *
+     * @param value identifier value
+     */
     IdentifierScheme(final String value) {
         identifierValue = value;
     }
 
-    public final String getValue() {
+    /**
+     * @return identifier value
+     */
+    public String getValue() {
         return identifierValue;
     }
 
diff --git a/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/model/oauth2/Scope.java b/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/model/oauth2/Scope.java
index e23f6cb8..1d5b20dd 100644
--- a/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/model/oauth2/Scope.java
+++ b/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/model/oauth2/Scope.java
@@ -37,7 +37,7 @@ public enum Scope {
      * @return Scope according to the name
      */
     public static Scope fromName(final String name) {
-        for (final Scope scope : Scope.values()) {
+        for (final Scope scope : values()) {
             if (scope.getName().equals(name)) {
                 return scope;
             }
@@ -52,7 +52,7 @@ public enum Scope {
     public static int getScopeSum(final List<String> names) {
         int sum = 0;
         for (final String name: names) {
-            sum += Scope.fromName(name).getId();
+            sum += fromName(name).getId();
         }
         return sum;
     }
diff --git a/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/openid/OIDCSessionAttributes.java b/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/openid/OIDCSessionAttributes.java
index 86c9f528..c22b3bfd 100644
--- a/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/openid/OIDCSessionAttributes.java
+++ b/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/openid/OIDCSessionAttributes.java
@@ -53,7 +53,7 @@ public enum OIDCSessionAttributes {
      * Getter for the attribute constant.
      * @return the constant as a String
      */
-    public final String getAttribute() {
+    public String getAttribute() {
         return sessionAttribute;
     }
 
diff --git a/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/openid/OpenIdCallbackServlet.java b/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/openid/OpenIdCallbackServlet.java
index 8331972b..5ccfdfb3 100644
--- a/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/openid/OpenIdCallbackServlet.java
+++ b/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/server/openid/OpenIdCallbackServlet.java
@@ -185,7 +185,7 @@ public class OpenIdCallbackServlet extends HttpServlet {
         final OIDCProviderMetadata providerMetadata = oidcHandler.getProvidersMetadata().get(oidcIdp.getId());
         URI redirectURI;
         try {
-            redirectURI = new URI(config.get(Key.APP_URL) + OpenIdCallbackServlet.REDIRECTURL);
+            redirectURI = new URI(config.get(Key.APP_URL) + REDIRECTURL);
         } catch (final URISyntaxException e) {
             LOGGER.error(e);
             throw new IOException("SIDO redirection URI was broken !");
diff --git a/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/shared/StringUtils.java b/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/shared/StringUtils.java
index 1d741136..b12dd61a 100644
--- a/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/shared/StringUtils.java
+++ b/sido-gwt/src/main/java/fr/soeretempo/sido/gwt/shared/StringUtils.java
@@ -64,9 +64,8 @@ public final class StringUtils {
             final Long parsed = Long.valueOf(value);
             return Optional.of(parsed);
         } catch (final Exception e) {
-
+            return Optional.empty();
         }
-        return Optional.empty();
     }
 
     /**
-- 
GitLab