diff --git a/out/production/infrastructureLogicielleClient/crossTests/CrossAddItemFilmTest.class b/out/production/infrastructureLogicielleClient/crossTests/CrossAddItemFilmTest.class new file mode 100644 index 0000000000000000000000000000000000000000..d52d9fcafb70e7815b4480cd2403195dd945178d Binary files /dev/null and b/out/production/infrastructureLogicielleClient/crossTests/CrossAddItemFilmTest.class differ diff --git a/out/production/infrastructureLogicielleClient/opinion/Film.class b/out/production/infrastructureLogicielleClient/opinion/Film.class new file mode 100644 index 0000000000000000000000000000000000000000..2b435d872e634aa0b491fda15642cdd430aaeea3 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/opinion/Film.class differ diff --git a/out/production/infrastructureLogicielleClient/opinion/Item.class b/out/production/infrastructureLogicielleClient/opinion/Item.class new file mode 100644 index 0000000000000000000000000000000000000000..fe0b23da819c7d4040c6869645b168c875f02ff3 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/opinion/Item.class differ diff --git a/out/production/infrastructureLogicielleClient/opinion/Review.class b/out/production/infrastructureLogicielleClient/opinion/Review.class new file mode 100644 index 0000000000000000000000000000000000000000..8bab288f8a534a4a3c7ea57068acafd0b18b1e61 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/opinion/Review.class differ diff --git a/out/production/infrastructureLogicielleClient/tests/AddItemFilmTest.class b/out/production/infrastructureLogicielleClient/tests/AddItemFilmTest.class new file mode 100644 index 0000000000000000000000000000000000000000..257c8accc5ea9d01faa31a501a9b7bbffcd3c051 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/tests/AddItemFilmTest.class differ diff --git a/out/production/infrastructureLogicielleClient/tests/ConsultItemBookTest.class b/out/production/infrastructureLogicielleClient/tests/ConsultItemBookTest.class new file mode 100644 index 0000000000000000000000000000000000000000..2be38e72217c0aa409a727e141843be9be81a5b4 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/tests/ConsultItemBookTest.class differ diff --git a/out/production/infrastructureLogicielleClient/tests/ConsultItemFilmTest.class b/out/production/infrastructureLogicielleClient/tests/ConsultItemFilmTest.class new file mode 100644 index 0000000000000000000000000000000000000000..1c88d3792376d5552647b1ca936b19c4d9a98ace Binary files /dev/null and b/out/production/infrastructureLogicielleClient/tests/ConsultItemFilmTest.class differ diff --git a/out/production/infrastructureLogicielleClient/tests/RenderingTest.class b/out/production/infrastructureLogicielleClient/tests/RenderingTest.class new file mode 100644 index 0000000000000000000000000000000000000000..2953abdab081e9883640ef1350a136612980d6db Binary files /dev/null and b/out/production/infrastructureLogicielleClient/tests/RenderingTest.class differ diff --git a/out/production/infrastructureLogicielleClient/tests/ReviewItemBookTest.class b/out/production/infrastructureLogicielleClient/tests/ReviewItemBookTest.class new file mode 100644 index 0000000000000000000000000000000000000000..cb60a5de23b4ab5c4ff7de01b51b38e86025525b Binary files /dev/null and b/out/production/infrastructureLogicielleClient/tests/ReviewItemBookTest.class differ diff --git a/out/production/infrastructureLogicielleClient/tests/ReviewItemFilmTest.class b/out/production/infrastructureLogicielleClient/tests/ReviewItemFilmTest.class new file mode 100644 index 0000000000000000000000000000000000000000..fbb32fbadb81d969707a77905f2910903136104c Binary files /dev/null and b/out/production/infrastructureLogicielleClient/tests/ReviewItemFilmTest.class differ diff --git a/out/production/infrastructureLogicielleClient/tests/Tools.class b/out/production/infrastructureLogicielleClient/tests/Tools.class new file mode 100644 index 0000000000000000000000000000000000000000..763d5aee42c5ce34b97f2cabfde34447edf56b77 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/tests/Tools.class differ diff --git a/src/opinion/Film.java b/src/opinion/Film.java index 6dd31b12ce3be43b8df82378af03cacf31bbab6c..4326e7215514633ef7d6b85a305433a81ea59ae2 100644 --- a/src/opinion/Film.java +++ b/src/opinion/Film.java @@ -26,7 +26,8 @@ public class Film extends Item { @Override public String toString() { - return "Film Title: " + title + "\nKind: " + kind + "\nDirector: " + director + - "\nScenarist: " + scenarist + "\nDuration: " + duration + " minutes"; + return "Film Title: " + getTitle() + "\nKind: " + getKind() + "\nDirector: " + getDirector() + + "\nScenarist: " + getScenarist() + "\nDuration: " + getDuration() + " minutes"; } + } diff --git a/src/opinion/Item.java b/src/opinion/Item.java index ceaeba516f2027dffdf9ce3c9f84e37066ed8273..3677f4a72cdde4acb41343029a177ec5f1000f90 100644 --- a/src/opinion/Item.java +++ b/src/opinion/Item.java @@ -34,10 +34,13 @@ public abstract class Item { public boolean compareTitle(String title2) { if (this.title == null || title2 == null) return false; - String formattedTitle = this.title.trim().toUpperCase(); - String formattedTitle2 = title2.trim().toUpperCase(); - return formattedTitle.equals(formattedTitle2); + return normalize(this.title).equals(normalize(title2)); } + + private String normalize(String s) { + return s.trim().replaceAll("\\s+", "").toLowerCase(); + } + public void addOrUpdateReview(String login, float mark, String comment) { for (Review r : reviews) { if (r.getReviewerLogin().equalsIgnoreCase(login)) { diff --git a/src/opinion/SocialNetwork.java b/src/opinion/SocialNetwork.java index eb49d9e71c09fb6cdf01a40a912966712b973fc0..ac80da7880335ff9710d2fbfc27cfd9aaffcc33d 100644 --- a/src/opinion/SocialNetwork.java +++ b/src/opinion/SocialNetwork.java @@ -34,6 +34,14 @@ public class SocialNetwork implements ISocialNetwork { nbfilms = 0; } + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + /** * Returns number of registered members. * @@ -44,9 +52,6 @@ public class SocialNetwork implements ISocialNetwork { return nbmembers; } - - - /** * Returns number of books. * @@ -75,7 +80,7 @@ public class SocialNetwork implements ISocialNetwork { /** * Validates the format of a user's login and password (not empty or too short) * - * @param login the login to be validated + * @param login the login to be validated * @param password the password to be validated * @return true if login and password are valid * @throws BadEntryException if either login or password is invalid @@ -94,7 +99,7 @@ public class SocialNetwork implements ISocialNetwork { /** * Authenticates a user's login and password * - * @param login the login of the user + * @param login the login of the user * @param password the password of the user * @return true if password corresponds to registered login, false if wrong password */ @@ -130,10 +135,10 @@ public class SocialNetwork implements ISocialNetwork { /** * Adds a new member to the social network. * - * @param login the new member's login + * @param login the new member's login * @param password the new member's password - * @param profile a free String describing the new member's profile - * @throws BadEntryException if parameter is null or too short + * @param profile a free String describing the new member's profile + * @throws BadEntryException if parameter is null or too short * @throws MemberAlreadyExistsException if login already exists */ @Override @@ -150,13 +155,16 @@ public class SocialNetwork implements ISocialNetwork { nbmembers++; } - @Override public void addItemFilm(String login, String password, String title, String kind, String director, String scriptwriter, int duration) throws BadEntryException, NotMemberException, ItemFilmAlreadyExistsException { validateUser(login, password); + if (login == null || login.trim().isEmpty()) + throw new BadEntryException("Error: Login is null or empty"); + if (password == null || password.trim().length() < 4) + throw new BadEntryException("Error: Password is null or too short"); if (title == null || title.trim().isEmpty()) throw new BadEntryException("Error: Title is null or empty"); if (kind == null || kind.trim().isEmpty()) @@ -180,6 +188,7 @@ public class SocialNetwork implements ISocialNetwork { listFilm.add(film); nbfilms++; } + /** * Returns number of films. * @@ -211,23 +220,27 @@ public class SocialNetwork implements ISocialNetwork { throw new NotItemException("Error: Film not found"); } - + /** * Adds a new book to the social network. * - * @param login login of the member adding the book + * @param login login of the member adding the book * @param password password of the member adding the book - * @param title the new book's title - * @param kind the new book's kind - * @param author the new book's author - * @param nbPages number of pages of the new book's - * @throws BadEntryException if any input is invalid (empty or number pages equal or less than 0) - * @throws NotMemberException if login or password is wrong + * @param title the new book's title + * @param kind the new book's kind + * @param author the new book's author + * @param nbPages number of pages of the new book's + * @throws BadEntryException if any input is invalid (empty or number pages equal or less than 0) + * @throws NotMemberException if login or password is wrong * @throws ItemBookAlreadyExistsException if book already exists in system */ @Override public void addItemBook(String login, String password, String title, String kind, String author, int nbPages) throws BadEntryException, NotMemberException, ItemBookAlreadyExistsException { - validateUser(login, password); + // Validación de entrada + if (login == null || login.trim().length() < 1) + throw new BadEntryException("Error: login is null or empty"); + if (password == null || password.trim().length() < 4) + throw new BadEntryException("Error: password is null or too short"); if (title == null || title.trim().isEmpty()) throw new BadEntryException("Error: Title is null or empty"); if (kind == null || kind.trim().isEmpty()) @@ -235,32 +248,42 @@ public class SocialNetwork implements ISocialNetwork { if (author == null || author.trim().isEmpty()) throw new BadEntryException("Error: Author is null or empty"); if (nbPages <= 0) - throw new BadEntryException("Error: Page number is null or less"); - if (!authenticateUser(login, password)) + throw new BadEntryException("Error: Page number must be positive"); + + // Normalización + String trimmedLogin = login.trim(); + String trimmedPassword = password.trim(); + String trimmedTitle = title.trim(); + String trimmedAuthor = author.trim(); + + // Verificación de miembro + if (!authenticateUser(trimmedLogin, trimmedPassword)) throw new NotMemberException("Error: Invalid login or password"); + + // Verificación de duplicado de libro (título + autor) for (Book b : listBook) { - if (b.compareTitle(title)) { + if (b.compareTitle(trimmedTitle) && + b.getAuthor().trim().equalsIgnoreCase(trimmedAuthor)) { throw new ItemBookAlreadyExistsException(); } } - book = new Book(title.trim(), kind.trim(), author.trim(), nbPages); - listBook.add(book); + + // Agregar libro nuevo + Book newBook = new Book(trimmedTitle, kind.trim(), trimmedAuthor, nbPages); + listBook.add(newBook); nbbooks++; } - - /** - * - * @param login login of the member adding the review + * @param login login of the member adding the review * @param password password of the member adding the review - * @param title the reviewed book's title - * @param mark the mark given by the member for this book - * @param comment the comment given by the member for this book + * @param title the reviewed book's title + * @param mark the mark given by the member for this book + * @param comment the comment given by the member for this book * @return average mark of current book - * @throws BadEntryException if any input is invalid (mark is out of range) + * @throws BadEntryException if any input is invalid (mark is out of range) * @throws NotMemberException if login or password is wrong - * @throws NotItemException if book doesn't exist + * @throws NotItemException if book doesn't exist */ @Override public float reviewItemBook(String login, String password, String title, float mark, String comment) @@ -294,7 +317,6 @@ public class SocialNetwork implements ISocialNetwork { } /** - * * @param title title of searched item(s) * @return the search result of book or film added * @throws BadEntryException if any input is invalid (title is empty or too short) @@ -342,12 +364,4 @@ public class SocialNetwork implements ISocialNetwork { } return ret.trim(); } - - /** - * @param args - */ - public static void main(String[] args) { - // TODO Auto-generated method stub - - } }