Skip to content
Snippets Groups Projects
Commit ad2fb4e0 authored by Emmanuel Bruno's avatar Emmanuel Bruno
Browse files

cleans up.

parent 90bb0156
No related branches found
No related tags found
No related merge requests found
......@@ -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")
......
......@@ -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);
}
}
......@@ -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).
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment