From ad2fb4e01c0ec528102f0ab7d3df6e8a42e57fcd Mon Sep 17 00:00:00 2001
From: Emmanuel Bruno <emmanuel.bruno@univ-tln.fr>
Date: Fri, 12 Mar 2021 09:24:37 +0100
Subject: [PATCH] cleans up.

---
 .../fr/univtln/bruno/samples/jaxrs/model/Library.java | 11 ++++++-----
 .../fr/univtln/bruno/samples/jaxrs/model/Page.java    |  2 +-
 .../bruno/samples/jaxrs/resources/AdminResource.java  |  4 ----
 3 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/src/main/java/fr/univtln/bruno/samples/jaxrs/model/Library.java b/src/main/java/fr/univtln/bruno/samples/jaxrs/model/Library.java
index 0adb954..c42b95e 100644
--- a/src/main/java/fr/univtln/bruno/samples/jaxrs/model/Library.java
+++ b/src/main/java/fr/univtln/bruno/samples/jaxrs/model/Library.java
@@ -44,6 +44,7 @@ public class Library {
     final MutableLongObjectMap<Author> authors = LongObjectMaps.mutable.empty();
     final MutableLongObjectMap<Book> books = LongObjectMaps.mutable.empty();
 
+    private static final String AUTHOR_NOT_FOUND = "Author not found";
     /**
      * used mainly to provide easy XML Serialization
      *
@@ -115,7 +116,7 @@ public class Library {
         if (author.id != 0)
             throw new BusinessException(Response.Status.INTERNAL_SERVER_ERROR, "Id shouldn't be given in data");
         author.id = id;
-        if (!authors.containsKey(id)) throw new BusinessException(Response.Status.NOT_FOUND, "Author not found");
+        if (!authors.containsKey(id)) throw new BusinessException(Response.Status.NOT_FOUND, AUTHOR_NOT_FOUND);
         authors.put(id, author);
         return author;
     }
@@ -127,7 +128,7 @@ public class Library {
      * @throws BusinessException if not found
      */
     public void removeAuthor(long id) throws BusinessException {
-        if (!authors.containsKey(id)) throw new BusinessException(Response.Status.NOT_FOUND, "Author not found");
+        if (!authors.containsKey(id)) throw new BusinessException(Response.Status.NOT_FOUND, AUTHOR_NOT_FOUND);
         authors.remove(id);
     }
 
@@ -139,7 +140,7 @@ public class Library {
      * @throws NotFoundException if not found exception
      */
     public Author getAuthor(long id) throws BusinessException {
-        if (!authors.containsKey(id)) throw new BusinessException(Response.Status.NOT_FOUND, "Author not found");
+        if (!authors.containsKey(id)) throw new BusinessException(Response.Status.NOT_FOUND, AUTHOR_NOT_FOUND);
         return authors.get(id);
     }
 
@@ -249,7 +250,7 @@ public class Library {
         @XmlElementWrapper(name = "books")
         @XmlElements({@XmlElement(name = "book")})
         @JsonIdentityReference(alwaysAsId = true)
-        Set<Book> books;
+        private Set<Book> books;
 
         @XmlID
         @XmlAttribute(name = "id")
@@ -286,7 +287,7 @@ public class Library {
         @XmlElementWrapper(name = "authors")
         @XmlElements({@XmlElement(name = "author")})
         @JsonIdentityReference(alwaysAsId = true)
-        Set<Author> authors;
+        private Set<Author> authors;
 
         @XmlID
         @XmlAttribute(name = "id")
diff --git a/src/main/java/fr/univtln/bruno/samples/jaxrs/model/Page.java b/src/main/java/fr/univtln/bruno/samples/jaxrs/model/Page.java
index ad20f7c..9e5ad41 100644
--- a/src/main/java/fr/univtln/bruno/samples/jaxrs/model/Page.java
+++ b/src/main/java/fr/univtln/bruno/samples/jaxrs/model/Page.java
@@ -24,6 +24,6 @@ public class Page<T> {
     }
 
     public static <V> Page<V> newInstance(long pageSize, long pageNumber, long elementTotal, List<V> content) {
-        return new Page(pageSize, pageNumber, elementTotal, content);
+        return new Page<>(pageSize, pageNumber, elementTotal, content);
     }
 }
diff --git a/src/main/java/fr/univtln/bruno/samples/jaxrs/resources/AdminResource.java b/src/main/java/fr/univtln/bruno/samples/jaxrs/resources/AdminResource.java
index df85a27..4e02ccf 100644
--- a/src/main/java/fr/univtln/bruno/samples/jaxrs/resources/AdminResource.java
+++ b/src/main/java/fr/univtln/bruno/samples/jaxrs/resources/AdminResource.java
@@ -16,7 +16,6 @@ import jakarta.ws.rs.core.*;
 import lombok.extern.java.Log;
 
 import javax.naming.AuthenticationException;
-import java.security.SecureRandom;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.time.temporal.ChronoUnit;
@@ -32,9 +31,6 @@ import java.util.Date;
 @Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
 public class AdminResource {
 
-    //A random number generator
-    private static final SecureRandom random = new SecureRandom();
-
     /**
      * A GET method to access the context of the request : The URI, the HTTP headers, the request and the security context (needs authentication see below).
      *
-- 
GitLab