From 4e06ebc2a8342547b551431c7357cfa25403634a Mon Sep 17 00:00:00 2001
From: ThanKarab <tkarabatsis@hotmail.com>
Date: Thu, 20 Jul 2023 03:48:15 -0700
Subject: [PATCH] Code beautifications.
---
.../configurations/KeycloakConfiguration.java | 2 +-
.../configurations/SecurityConfiguration.java | 5 +++--
.../repositories/ExperimentSpecifications.java | 18 +++++++++---------
.../eu/hbp/mip/services/GalaxyService.java | 6 +++---
.../java/eu/hbp/mip/utils/ErrorMessage.java | 8 ++++----
src/main/java/eu/hbp/mip/utils/HTTPUtil.java | 2 +-
src/main/java/eu/hbp/mip/utils/Logger.java | 4 ++--
7 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/src/main/java/eu/hbp/mip/configurations/KeycloakConfiguration.java b/src/main/java/eu/hbp/mip/configurations/KeycloakConfiguration.java
index 390b1d653..e3097df3b 100644
--- a/src/main/java/eu/hbp/mip/configurations/KeycloakConfiguration.java
+++ b/src/main/java/eu/hbp/mip/configurations/KeycloakConfiguration.java
@@ -10,4 +10,4 @@ public class KeycloakConfiguration {
public KeycloakSpringBootConfigResolver KeycloakConfigResolver() {
return new KeycloakSpringBootConfigResolver();
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/eu/hbp/mip/configurations/SecurityConfiguration.java b/src/main/java/eu/hbp/mip/configurations/SecurityConfiguration.java
index f86270f45..c7c30ab55 100644
--- a/src/main/java/eu/hbp/mip/configurations/SecurityConfiguration.java
+++ b/src/main/java/eu/hbp/mip/configurations/SecurityConfiguration.java
@@ -1,6 +1,7 @@
package eu.hbp.mip.configurations;
import eu.hbp.mip.utils.CORSFilter;
+import org.jetbrains.annotations.NotNull;
import org.keycloak.adapters.springsecurity.KeycloakConfiguration;
import org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationProvider;
import org.keycloak.adapters.springsecurity.config.KeycloakWebSecurityConfigurerAdapter;
@@ -69,8 +70,8 @@ public class SecurityConfiguration extends KeycloakWebSecurityConfigurerAdapter
private Filter csrfHeaderFilter() {
return new OncePerRequestFilter() {
@Override
- protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
- FilterChain filterChain) throws ServletException, IOException {
+ protected void doFilterInternal(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response,
+ @NotNull FilterChain filterChain) throws ServletException, IOException {
CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
if (csrf != null) {
Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
diff --git a/src/main/java/eu/hbp/mip/repositories/ExperimentSpecifications.java b/src/main/java/eu/hbp/mip/repositories/ExperimentSpecifications.java
index 3379610d5..08423757f 100644
--- a/src/main/java/eu/hbp/mip/repositories/ExperimentSpecifications.java
+++ b/src/main/java/eu/hbp/mip/repositories/ExperimentSpecifications.java
@@ -12,7 +12,7 @@ import java.util.List;
public class ExperimentSpecifications {
public static class ExperimentWithName implements Specification<ExperimentDAO> {
- private String name;
+ private final String name;
private String regExp;
public ExperimentWithName(String name) {
@@ -33,7 +33,7 @@ public class ExperimentSpecifications {
public static class ExperimentWithAlgorithm implements Specification<ExperimentDAO> {
- private String algorithm;
+ private final String algorithm;
public ExperimentWithAlgorithm(String algorithm) {
this.algorithm = algorithm;
@@ -50,7 +50,7 @@ public class ExperimentSpecifications {
public static class ExperimentWithViewed implements Specification<ExperimentDAO> {
- private Boolean viewed;
+ private final Boolean viewed;
public ExperimentWithViewed(Boolean viewed) {
this.viewed = viewed;
@@ -66,7 +66,7 @@ public class ExperimentSpecifications {
public static class ExperimentWithShared implements Specification<ExperimentDAO> {
- private Boolean shared;
+ private final Boolean shared;
public ExperimentWithShared(Boolean shared) {
this.shared = shared;
@@ -82,7 +82,7 @@ public class ExperimentSpecifications {
public static class MyExperiment implements Specification<ExperimentDAO> {
- private String username;
+ private final String username;
public MyExperiment(String username) {
this.username = username;
@@ -99,14 +99,14 @@ public class ExperimentSpecifications {
public static class SharedExperiment implements Specification<ExperimentDAO> {
- private boolean shared;
+ private final boolean shared;
public SharedExperiment(boolean shared) {
this.shared = shared;
}
public Predicate toPredicate(Root<ExperimentDAO> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
- if (shared == false) {
+ if (!shared) {
return cb.isTrue(cb.literal(false));
}
return cb.equal(root.get("shared"), shared);
@@ -115,8 +115,8 @@ public class ExperimentSpecifications {
public static class ExperimentOrderBy implements Specification<ExperimentDAO> {
- private String orderBy;
- private Boolean descending;
+ private final String orderBy;
+ private final Boolean descending;
public ExperimentOrderBy(String orderBy, Boolean descending) {
if (properColumnToBeOrderedBy(orderBy))
diff --git a/src/main/java/eu/hbp/mip/services/GalaxyService.java b/src/main/java/eu/hbp/mip/services/GalaxyService.java
index 61d5629fd..23c15d710 100644
--- a/src/main/java/eu/hbp/mip/services/GalaxyService.java
+++ b/src/main/java/eu/hbp/mip/services/GalaxyService.java
@@ -173,7 +173,7 @@ public class GalaxyService {
Response<Object> response = call.execute();
if (response.code() >= 400) {
Logger.LogBackgroundAction(experimentName, experimentId, " Response code: "
- + response.code() + "" + " with body: " + (response.errorBody() != null ? response.errorBody().string() : " "));
+ + response.code() + " with body: " + (response.errorBody() != null ? response.errorBody().string() : " "));
return "internalError";
}
result = new Gson().toJson(response.body());
@@ -228,7 +228,7 @@ public class GalaxyService {
Response<List<GalaxyWorkflowResult>> response = call.execute();
if (response.code() >= 400) {
Logger.LogBackgroundAction(experimentName, experimentId, " Response code: "
- + response.code() + "" + " with body: " + (response.errorBody() != null ? response.errorBody().string() : " "));
+ + response.code() + " with body: " + (response.errorBody() != null ? response.errorBody().string() : " "));
return null;
}
getGalaxyWorkflowResultList = response.body();
@@ -266,7 +266,7 @@ public class GalaxyService {
Response<Object> response = call.execute();
if (response.code() >= 400) {
Logger.LogBackgroundAction(experimentName, experimentId, " Response code: "
- + response.code() + "" + " with body: " + (response.errorBody() != null ? response.errorBody().string() : " "));
+ + response.code() + " with body: " + (response.errorBody() != null ? response.errorBody().string() : " "));
return null;
}
resultJson = new Gson().toJson(response.body());
diff --git a/src/main/java/eu/hbp/mip/utils/ErrorMessage.java b/src/main/java/eu/hbp/mip/utils/ErrorMessage.java
index ef15c71ae..fdaac1592 100644
--- a/src/main/java/eu/hbp/mip/utils/ErrorMessage.java
+++ b/src/main/java/eu/hbp/mip/utils/ErrorMessage.java
@@ -4,10 +4,10 @@ package eu.hbp.mip.utils;
import java.util.Date;
public class ErrorMessage {
- private int statusCode;
- private Date timestamp;
- private String message;
- private String description;
+ private final int statusCode;
+ private final Date timestamp;
+ private final String message;
+ private final String description;
public ErrorMessage(int statusCode, Date timestamp, String message, String description) {
this.statusCode = statusCode;
diff --git a/src/main/java/eu/hbp/mip/utils/HTTPUtil.java b/src/main/java/eu/hbp/mip/utils/HTTPUtil.java
index cd3778a00..fdd7a9179 100644
--- a/src/main/java/eu/hbp/mip/utils/HTTPUtil.java
+++ b/src/main/java/eu/hbp/mip/utils/HTTPUtil.java
@@ -70,7 +70,7 @@ public class HTTPUtil {
response.append(inputLine);
}
in.close();
- resp.append(response.toString());
+ resp.append(response);
return respCode;
}
diff --git a/src/main/java/eu/hbp/mip/utils/Logger.java b/src/main/java/eu/hbp/mip/utils/Logger.java
index c21e2fdc9..7ea51d74f 100644
--- a/src/main/java/eu/hbp/mip/utils/Logger.java
+++ b/src/main/java/eu/hbp/mip/utils/Logger.java
@@ -8,8 +8,8 @@ import java.util.UUID;
public class Logger {
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Logger.class);
- private String username;
- private String endpoint;
+ private final String username;
+ private final String endpoint;
public Logger(String username, String endpoint){
this.username = username;
--
GitLab