From 290006e4367cde8bc331c1072f79840ab6aa87e3 Mon Sep 17 00:00:00 2001 From: river3966 Date: Thu, 3 Aug 2023 20:13:29 -0400 Subject: [PATCH 01/24] documentation --- .../businessrule/usecase/AskQuestionInteractor.java | 7 +++++++ .../businessrule/usecase/BrowseQuestionInterator.java | 5 +++++ .../businessrule/usecase/ClientRegisterInteractor.java | 6 ++++++ .../businessrule/usecase/CloseQuestionInteractor.java | 6 ++++++ .../businessrule/usecase/PostDisplayFormatter.java | 7 +++++++ .../java/businessrule/usecase/PostMapConstructor.java | 3 +++ .../businessrule/usecase/QuestionDisplayFormatter.java | 4 ++++ .../businessrule/usecase/QuestionMapConstructor.java | 3 +++ src/main/java/businessrule/usecase/RateInteractor.java | 3 +++ .../java/businessrule/usecase/ReplyInteractor.java | 7 +++++++ .../businessrule/usecase/SelectQuestionInteractor.java | 7 +++++++ .../java/businessrule/usecase/UserLoginInteractor.java | 7 +++++++ .../businessrule/usecase/ViewQuestionInteractor.java | 5 +++++ src/main/java/entity/Attorney.java | 7 +++++++ src/main/java/entity/Client.java | 10 ++++++++++ src/main/java/entity/ClientFactory.java | 7 +++++++ src/main/java/entity/CredentialChecker.java | 8 ++++++++ src/main/java/entity/Post.java | 9 +++++++++ src/main/java/entity/PostFactory.java | 6 ++++++ src/main/java/entity/QuestionFactory.java | 7 +++++++ src/main/java/entity/RandomNumberGenerator.java | 3 +++ src/main/java/entity/User.java | 5 +++++ src/main/java/tutorial/MainFrame.java | 0 23 files changed, 132 insertions(+) create mode 100644 src/main/java/tutorial/MainFrame.java diff --git a/src/main/java/businessrule/usecase/AskQuestionInteractor.java b/src/main/java/businessrule/usecase/AskQuestionInteractor.java index fbf19dc0..1e65102d 100644 --- a/src/main/java/businessrule/usecase/AskQuestionInteractor.java +++ b/src/main/java/businessrule/usecase/AskQuestionInteractor.java @@ -1,5 +1,12 @@ package businessrule.usecase; +/** + * This class is responsible for handling the use case of asking a new question in the application. + * + * It facilitates the creation and saving of a new question with relevant information, including the + * question category, title, creation date, the client who asked the question, and the legal deadline. + */ + import entity.*; import businessrule.inputboundary.QuestionInputBoundary; import businessrule.requestmodel.QuestionRequestModel; diff --git a/src/main/java/businessrule/usecase/BrowseQuestionInterator.java b/src/main/java/businessrule/usecase/BrowseQuestionInterator.java index 0ed8ca1b..20f39523 100644 --- a/src/main/java/businessrule/usecase/BrowseQuestionInterator.java +++ b/src/main/java/businessrule/usecase/BrowseQuestionInterator.java @@ -12,6 +12,11 @@ import java.util.List; import java.util.Map; +/** + * This class is responsible for responsible for handling the browse question use case. + * + * This class facilitates browsing and retrieving a list of not-taken questions from the data source through + */ public class BrowseQuestionInterator implements BrowseInputBoundary { final ViewOutputBoundary viewOutputBoundary; diff --git a/src/main/java/businessrule/usecase/ClientRegisterInteractor.java b/src/main/java/businessrule/usecase/ClientRegisterInteractor.java index 6841323b..70e2cb0a 100644 --- a/src/main/java/businessrule/usecase/ClientRegisterInteractor.java +++ b/src/main/java/businessrule/usecase/ClientRegisterInteractor.java @@ -1,5 +1,11 @@ package businessrule.usecase; +/** + * This class represents the interactor for registering a new client user. + * + * The "ClientRegisterInteractor" class is responsible for handling the business logic related to registering + * a new client user + */ import businessrule.gateway.ClientGateway; import businessrule.inputboundary.ClientRegisterInputBoundary; diff --git a/src/main/java/businessrule/usecase/CloseQuestionInteractor.java b/src/main/java/businessrule/usecase/CloseQuestionInteractor.java index da5f3b8b..b97518c6 100644 --- a/src/main/java/businessrule/usecase/CloseQuestionInteractor.java +++ b/src/main/java/businessrule/usecase/CloseQuestionInteractor.java @@ -1,5 +1,11 @@ package businessrule.usecase; +/** + * The "CloseQuestionInteractor" class represents a use case interactor for closing a question. + * + * This class is responsible for handling the business logic related to closing a question in the system. It + */ + import businessrule.inputboundary.CloseInputBoundary; import businessrule.outputboundary.HomePageOutputBoundary; import businessrule.requestmodel.CloseRequestModel; diff --git a/src/main/java/businessrule/usecase/PostDisplayFormatter.java b/src/main/java/businessrule/usecase/PostDisplayFormatter.java index 9f81c4d7..751129ec 100644 --- a/src/main/java/businessrule/usecase/PostDisplayFormatter.java +++ b/src/main/java/businessrule/usecase/PostDisplayFormatter.java @@ -4,6 +4,13 @@ import java.time.LocalDate; +/** + * The "PostDisplayFormatter" class represents a formatted display of a post for presentation purposes. + * + * This class is responsible for formatting a post in a user-friendly way for displaying it to users + * in the application's user interface. It encapsulates the essential information related to a post, + */ + public class PostDisplayFormatter { private final String postText; private final boolean isClient; diff --git a/src/main/java/businessrule/usecase/PostMapConstructor.java b/src/main/java/businessrule/usecase/PostMapConstructor.java index ba43f324..94525294 100644 --- a/src/main/java/businessrule/usecase/PostMapConstructor.java +++ b/src/main/java/businessrule/usecase/PostMapConstructor.java @@ -11,6 +11,9 @@ import java.util.List; import java.util.Map; +/** + * The "PostMapConstructor" class is responsible for constructing a map of post information for a given question. + */ class PostMapConstructor { private final UserGateway userGateway; diff --git a/src/main/java/businessrule/usecase/QuestionDisplayFormatter.java b/src/main/java/businessrule/usecase/QuestionDisplayFormatter.java index 384a9a95..be33b789 100644 --- a/src/main/java/businessrule/usecase/QuestionDisplayFormatter.java +++ b/src/main/java/businessrule/usecase/QuestionDisplayFormatter.java @@ -2,6 +2,10 @@ import java.time.LocalDate; +/** + * The "QuestionDisplayFormatter" class represents a formatted display of a legal question. + * This class is used to format and display essential information about a legal question in a user-friendly manner. + */ public class QuestionDisplayFormatter { private final String title; private final String type; diff --git a/src/main/java/businessrule/usecase/QuestionMapConstructor.java b/src/main/java/businessrule/usecase/QuestionMapConstructor.java index dbe506f1..b32b296f 100644 --- a/src/main/java/businessrule/usecase/QuestionMapConstructor.java +++ b/src/main/java/businessrule/usecase/QuestionMapConstructor.java @@ -8,6 +8,9 @@ import java.util.List; import java.util.Map; +/** + * The "QuestionMapConstructor" class is a utility class responsible for constructing a map of question display formatters. + */ class QuestionMapConstructor { protected Map constructQuestionMap(List questionList) { Map questionMap = new HashMap<>(); diff --git a/src/main/java/businessrule/usecase/RateInteractor.java b/src/main/java/businessrule/usecase/RateInteractor.java index 9f1f238c..fb0d26e1 100644 --- a/src/main/java/businessrule/usecase/RateInteractor.java +++ b/src/main/java/businessrule/usecase/RateInteractor.java @@ -10,6 +10,9 @@ import entity.Question; import entity.User; +/** + * The "RateInteractor" class represents the interactor for rating an answer to a question. + */ public class RateInteractor implements RateInputBoundary { private final QuestionGateway questionGateway; diff --git a/src/main/java/businessrule/usecase/ReplyInteractor.java b/src/main/java/businessrule/usecase/ReplyInteractor.java index 4b43f090..858ee49f 100644 --- a/src/main/java/businessrule/usecase/ReplyInteractor.java +++ b/src/main/java/businessrule/usecase/ReplyInteractor.java @@ -16,6 +16,13 @@ import java.time.LocalDate; +/** + * The "ReplyInteractor" class is an implementation of the "PostInputBoundary" interface, representing the use case for + * + * creating a new post (reply) in response to a question. + * The class handles the business logic for creating a post (reply) to a specific question. It interacts with various + * gateways, entities, and output boundaries to perform the necessary operations related to creating and saving the post. + */ public class ReplyInteractor implements PostInputBoundary { diff --git a/src/main/java/businessrule/usecase/SelectQuestionInteractor.java b/src/main/java/businessrule/usecase/SelectQuestionInteractor.java index 0dff10b1..13fc28d2 100644 --- a/src/main/java/businessrule/usecase/SelectQuestionInteractor.java +++ b/src/main/java/businessrule/usecase/SelectQuestionInteractor.java @@ -11,6 +11,13 @@ import businessrule.gateway.UserGatewayFactory; import java.util.Map; +/** + * The "SelectQuestionInteractor" class is part of the business rule use case layer and serves as an implementation of the + * + * "SelectInputBoundary" interface. It is responsible for handling the selection of a specific question by a user in the system. + * The class uses various gateways and output boundaries to interact with the database and prepare the response model for the + * selected question. + */ public class SelectQuestionInteractor implements SelectInputBoundary { final QuestionGateway questionGateway; final TheQuestionOutputBoundary theQuestionOutputBoundary; diff --git a/src/main/java/businessrule/usecase/UserLoginInteractor.java b/src/main/java/businessrule/usecase/UserLoginInteractor.java index 4b6df2dd..1708dadc 100644 --- a/src/main/java/businessrule/usecase/UserLoginInteractor.java +++ b/src/main/java/businessrule/usecase/UserLoginInteractor.java @@ -11,6 +11,13 @@ import java.time.LocalDateTime; +/** + * This class is responsible for handling the user login use case in the application. + * It interacts with the "UserGatewayFactory" to access user information from the data source and + * validates user credentials to authenticate the user. + * The class uses the "HomePageOutputBoundary" to prepare and return the appropriate response model + * based on the result of the login attempt. + */ public class UserLoginInteractor implements UserLoginInputBoundary{ final UserGatewayFactory userGatewayFactory; final HomePageOutputBoundary outputBoundary; diff --git a/src/main/java/businessrule/usecase/ViewQuestionInteractor.java b/src/main/java/businessrule/usecase/ViewQuestionInteractor.java index 8882f046..2c915043 100644 --- a/src/main/java/businessrule/usecase/ViewQuestionInteractor.java +++ b/src/main/java/businessrule/usecase/ViewQuestionInteractor.java @@ -13,6 +13,11 @@ import java.util.List; import java.util.Map; +/** + * This class serves as an interactor for viewing questions associated with a user. + * It implements the "ViewInputBoundary" interface, which defines the contract for viewing questions. + * The class is responsible for handling user requests to view questions and constructing the appropriate response. + */ public class ViewQuestionInteractor implements ViewInputBoundary { final QuestionGateway questionGateway; final ViewOutputBoundary viewOutputBoundary; diff --git a/src/main/java/entity/Attorney.java b/src/main/java/entity/Attorney.java index 5dbeca3c..672d1de6 100644 --- a/src/main/java/entity/Attorney.java +++ b/src/main/java/entity/Attorney.java @@ -8,6 +8,13 @@ import java.util.ArrayList; import java.util.Objects; +/** + * This is a class representing attorney user. + * + * An Attorney is a registered user who is a legal professional, capable of answering legal questions + * posted by clients. The Attorney has attributes such as user ID, name, email, password, state abbreviation, + * postal code, and a list of questions associated with them. + */ @Entity public class Attorney implements User { @Id diff --git a/src/main/java/entity/Client.java b/src/main/java/entity/Client.java index 229d6522..e21cab7a 100644 --- a/src/main/java/entity/Client.java +++ b/src/main/java/entity/Client.java @@ -7,6 +7,16 @@ import java.util.List; import java.util.Objects; +/** + * This is a class representing client user. + * + * A Client is a registered user who seeks legal advice and assistance by posting questions + * to be answered by attorneys. The Client class includes attributes such as user ID, username, + * email, password, state abbreviation, postal code, ethnicity, age, gender, marital status, + * number of household members, and annual income. Additionally, it maintains a list of questions + * associated with the client. + */ + @Entity public class Client implements User { @Id diff --git a/src/main/java/entity/ClientFactory.java b/src/main/java/entity/ClientFactory.java index 8abc8a66..03a19894 100644 --- a/src/main/java/entity/ClientFactory.java +++ b/src/main/java/entity/ClientFactory.java @@ -1,6 +1,13 @@ package entity; import entity.Client; +/** + * This is a class representing initialization of a client. + * + * This is a factory class responsible for creating instances of the "Client" class. + * The "ClientFactory" class provides a convenient way to create new instances of the "Client" class + * + */ public class ClientFactory { public Client create(int userId, String userName, String email, String password, String stateAbb, String postalCode, String ethnicity, int age, diff --git a/src/main/java/entity/CredentialChecker.java b/src/main/java/entity/CredentialChecker.java index 27fc8cd1..f0a0d7b6 100644 --- a/src/main/java/entity/CredentialChecker.java +++ b/src/main/java/entity/CredentialChecker.java @@ -2,6 +2,14 @@ import org.apache.commons.validator.routines.EmailValidator; import java.util.regex.*; +/** + * This is a utility class for checking various credentials and data formats. + * + * The "CredentialChecker" class provides methods to validate different types of credentials, + * ensuring that they meet specific criteria or follow certain patterns. +*/ + + public class CredentialChecker { public boolean checkPostalCode(String postalCode){ diff --git a/src/main/java/entity/Post.java b/src/main/java/entity/Post.java index 85a710d4..bb19c932 100644 --- a/src/main/java/entity/Post.java +++ b/src/main/java/entity/Post.java @@ -5,6 +5,15 @@ import java.time.LocalDate; import java.util.Objects; +/** + * This is a class representing a post in a question thread. + * + * A "Post" is a message or response posted in the context of a specific question thread. + * Each post contains information such as the ID of the associated question, the post ID, + * the creation date, the text of the post, and an identifier indicating which user the post + * belongs to. + */ + @Entity public class Post { private int questionId; diff --git a/src/main/java/entity/PostFactory.java b/src/main/java/entity/PostFactory.java index 3dabda24..1075bfa0 100644 --- a/src/main/java/entity/PostFactory.java +++ b/src/main/java/entity/PostFactory.java @@ -4,6 +4,12 @@ import java.time.LocalDate; +/** + * This is a factory class for creating Post objects. + * + * The "PostFactory" class provides a convenient way to create instances of the "Post" class by encapsulating + * the construction logic. It serves as a central point for creating posts associated with questions in the application. + */ public class PostFactory { public Post create(int postId, int questionId, LocalDate createAt, String postText, int belongsTo){ return new Post(postId, questionId, createAt, postText, belongsTo); diff --git a/src/main/java/entity/QuestionFactory.java b/src/main/java/entity/QuestionFactory.java index bbbaddd4..03b02c02 100644 --- a/src/main/java/entity/QuestionFactory.java +++ b/src/main/java/entity/QuestionFactory.java @@ -4,6 +4,13 @@ import java.time.LocalDate; +/** + * This is a factory class for creating instances of the "Question" class. + * + * The QuestionFactory class provides a simple and convenient way to create new "Question" objects with + * the specified attributes. It encapsulates the instantiation process and centralizes it in a single + * location, promoting code reusability and maintainability. + */ public class QuestionFactory { public Question create(int questionId, String type, String title, LocalDate createAt, int askedByClient, LocalDate legalDeadline){ return new Question(questionId, type, title, createAt, askedByClient, legalDeadline); diff --git a/src/main/java/entity/RandomNumberGenerator.java b/src/main/java/entity/RandomNumberGenerator.java index d14d60e8..a2bc80e0 100644 --- a/src/main/java/entity/RandomNumberGenerator.java +++ b/src/main/java/entity/RandomNumberGenerator.java @@ -1,6 +1,9 @@ package entity; import java.util.Random; +/** + * This class provides utility methods to generate random numbers and create unique IDs for different entities. + */ public class RandomNumberGenerator { public static int generate(int digit){ Random random = new Random(); diff --git a/src/main/java/entity/User.java b/src/main/java/entity/User.java index 931f84ef..176775da 100644 --- a/src/main/java/entity/User.java +++ b/src/main/java/entity/User.java @@ -1,5 +1,10 @@ package entity; +/** + * The "User" interface represents a generic user in the system. + * This interface defines common methods that are shared by different types of users in the application, + */ + import java.util.List; public interface User { diff --git a/src/main/java/tutorial/MainFrame.java b/src/main/java/tutorial/MainFrame.java new file mode 100644 index 00000000..e69de29b From d21ce9a6da65cfe4541effcb22a9c377204d9ab7 Mon Sep 17 00:00:00 2001 From: river3966 Date: Sat, 5 Aug 2023 17:58:59 -0400 Subject: [PATCH 02/24] documentation --- src/main/java/businessrule/gateway/UserGatewayFactory.java | 3 +++ .../java/businessrule/requestmodel/BrowseRequestModel.java | 3 +++ .../requestmodel/ClientRegisterRequestModel.java | 4 +++- .../java/businessrule/requestmodel/CloseRequestModel.java | 4 +++- .../java/businessrule/requestmodel/PostRequestModel.java | 3 +++ .../businessrule/requestmodel/QuestionRequestModel.java | 4 +++- .../java/businessrule/requestmodel/RateRequestModel.java | 3 +++ .../java/businessrule/requestmodel/SelectRequestModel.java | 3 +++ .../businessrule/requestmodel/UserLoginRequestModel.java | 3 +++ .../java/businessrule/requestmodel/ViewRequestModel.java | 3 +++ .../businessrule/responsemodel/HomePageResponseModel.java | 4 ++++ .../businessrule/responsemodel/RegisterResponseModel.java | 5 ++++- .../responsemodel/TheQuestionResponseModel.java | 4 +++- .../java/businessrule/responsemodel/ViewResponseModel.java | 4 +++- src/main/java/driver/database/AttorneyRepository.java | 4 ++++ src/main/java/driver/database/ClientRepository.java | 3 +++ src/main/java/driver/database/DatabaseConnection.java | 3 +++ src/main/java/driver/database/PostRepo.java | 3 +++ src/main/java/driver/database/QuestionRepo.java | 3 +++ src/main/java/driver/database/UserRepository.java | 3 +++ src/main/java/driver/screen/ApplicationException.java | 3 +++ src/main/java/driver/screen/AskQuestionUI.java | 6 +----- src/main/java/driver/screen/AttorneyHomePageUI.java | 3 +++ src/main/java/driver/screen/ClientHomePageUI.java | 3 +++ src/main/java/driver/screen/LabelTextPanel.java | 3 +++ src/main/java/driver/screen/LoginUI.java | 3 +-- src/main/java/driver/screen/ReplyQuestionUI.java | 3 +++ 27 files changed, 80 insertions(+), 13 deletions(-) diff --git a/src/main/java/businessrule/gateway/UserGatewayFactory.java b/src/main/java/businessrule/gateway/UserGatewayFactory.java index 9e7b98fd..4081c0be 100644 --- a/src/main/java/businessrule/gateway/UserGatewayFactory.java +++ b/src/main/java/businessrule/gateway/UserGatewayFactory.java @@ -1,4 +1,7 @@ package businessrule.gateway; +/** + * This class represents a factory for creating instances of the "UserGateway" interface based on the given user ID. + */ import driver.database.AttorneyRepository; import driver.database.ClientRepository; diff --git a/src/main/java/businessrule/requestmodel/BrowseRequestModel.java b/src/main/java/businessrule/requestmodel/BrowseRequestModel.java index c8d2420c..aac26102 100644 --- a/src/main/java/businessrule/requestmodel/BrowseRequestModel.java +++ b/src/main/java/businessrule/requestmodel/BrowseRequestModel.java @@ -1,5 +1,8 @@ package businessrule.requestmodel; +/** + * This class represents a request model for browsing questions related to an attorney. + */ public class BrowseRequestModel { private final int attorneyId; diff --git a/src/main/java/businessrule/requestmodel/ClientRegisterRequestModel.java b/src/main/java/businessrule/requestmodel/ClientRegisterRequestModel.java index cc7bccf2..f1a484a6 100644 --- a/src/main/java/businessrule/requestmodel/ClientRegisterRequestModel.java +++ b/src/main/java/businessrule/requestmodel/ClientRegisterRequestModel.java @@ -1,5 +1,7 @@ package businessrule.requestmodel; - +/** + * This class represents a request model for client registration. + */ public class ClientRegisterRequestModel { private final String userName; private final String email; diff --git a/src/main/java/businessrule/requestmodel/CloseRequestModel.java b/src/main/java/businessrule/requestmodel/CloseRequestModel.java index 9528d77d..75a38a6a 100644 --- a/src/main/java/businessrule/requestmodel/CloseRequestModel.java +++ b/src/main/java/businessrule/requestmodel/CloseRequestModel.java @@ -1,5 +1,7 @@ package businessrule.requestmodel; - +/** + * This class represents a request model to close a question made by a client. + */ public class CloseRequestModel { private final int questionId; private final int userId; diff --git a/src/main/java/businessrule/requestmodel/PostRequestModel.java b/src/main/java/businessrule/requestmodel/PostRequestModel.java index b3abceec..6267bd87 100644 --- a/src/main/java/businessrule/requestmodel/PostRequestModel.java +++ b/src/main/java/businessrule/requestmodel/PostRequestModel.java @@ -2,6 +2,9 @@ import java.time.LocalDate; +/** + * This class represents a post request model for creating a new post. + */ public class PostRequestModel { private final int questionId; private final int userId; diff --git a/src/main/java/businessrule/requestmodel/QuestionRequestModel.java b/src/main/java/businessrule/requestmodel/QuestionRequestModel.java index a8bf2220..0ff674d6 100644 --- a/src/main/java/businessrule/requestmodel/QuestionRequestModel.java +++ b/src/main/java/businessrule/requestmodel/QuestionRequestModel.java @@ -1,7 +1,9 @@ package businessrule.requestmodel; import java.time.LocalDate; - +/** + * This class represents a post request model for creating a new question. + */ public class QuestionRequestModel { private final String questionCategory; private final String title; diff --git a/src/main/java/businessrule/requestmodel/RateRequestModel.java b/src/main/java/businessrule/requestmodel/RateRequestModel.java index b27c8978..ff1e9250 100644 --- a/src/main/java/businessrule/requestmodel/RateRequestModel.java +++ b/src/main/java/businessrule/requestmodel/RateRequestModel.java @@ -1,5 +1,8 @@ package businessrule.requestmodel; +/** + * This class represents a request model for rating an answer. + */ public class RateRequestModel { private final int rating; diff --git a/src/main/java/businessrule/requestmodel/SelectRequestModel.java b/src/main/java/businessrule/requestmodel/SelectRequestModel.java index d4b8d8f5..0939a7da 100644 --- a/src/main/java/businessrule/requestmodel/SelectRequestModel.java +++ b/src/main/java/businessrule/requestmodel/SelectRequestModel.java @@ -1,5 +1,8 @@ package businessrule.requestmodel; +/** + * This class represents a request model for selecting question. + */ public class SelectRequestModel { private final int questionId; private final int userId; diff --git a/src/main/java/businessrule/requestmodel/UserLoginRequestModel.java b/src/main/java/businessrule/requestmodel/UserLoginRequestModel.java index 9840e4fc..1e16e2eb 100644 --- a/src/main/java/businessrule/requestmodel/UserLoginRequestModel.java +++ b/src/main/java/businessrule/requestmodel/UserLoginRequestModel.java @@ -1,5 +1,8 @@ package businessrule.requestmodel; +/** + * This class represents request model for a user login . + */ public class UserLoginRequestModel { private final int userId; private final String password; diff --git a/src/main/java/businessrule/requestmodel/ViewRequestModel.java b/src/main/java/businessrule/requestmodel/ViewRequestModel.java index 63a765cb..1bbc04c4 100644 --- a/src/main/java/businessrule/requestmodel/ViewRequestModel.java +++ b/src/main/java/businessrule/requestmodel/ViewRequestModel.java @@ -1,5 +1,8 @@ package businessrule.requestmodel; +/** + * This class represents request model for viewing questions. + */ public class ViewRequestModel { private final int userId; diff --git a/src/main/java/businessrule/responsemodel/HomePageResponseModel.java b/src/main/java/businessrule/responsemodel/HomePageResponseModel.java index d39db674..4091f6df 100644 --- a/src/main/java/businessrule/responsemodel/HomePageResponseModel.java +++ b/src/main/java/businessrule/responsemodel/HomePageResponseModel.java @@ -1,5 +1,9 @@ package businessrule.responsemodel; +/** + * This class represents providing a simple and convenient way to transfer home page data + * as a response to the client. + */ public class HomePageResponseModel { private final int userId; private final String userName; diff --git a/src/main/java/businessrule/responsemodel/RegisterResponseModel.java b/src/main/java/businessrule/responsemodel/RegisterResponseModel.java index 7befdbba..f93470c7 100644 --- a/src/main/java/businessrule/responsemodel/RegisterResponseModel.java +++ b/src/main/java/businessrule/responsemodel/RegisterResponseModel.java @@ -1,4 +1,7 @@ package businessrule.responsemodel; - +/** + * This class represents providing a simple and convenient way to transfer register data + * as a response to the client. + */ public class RegisterResponseModel { } diff --git a/src/main/java/businessrule/responsemodel/TheQuestionResponseModel.java b/src/main/java/businessrule/responsemodel/TheQuestionResponseModel.java index feec4456..0102ac64 100644 --- a/src/main/java/businessrule/responsemodel/TheQuestionResponseModel.java +++ b/src/main/java/businessrule/responsemodel/TheQuestionResponseModel.java @@ -4,7 +4,9 @@ import java.time.LocalDate; import java.util.Map; - +/** + * This class represents providing a simple and convenient way to transfer questions data as a response to the client. + */ public class TheQuestionResponseModel{ private final int userId; private final String userName; diff --git a/src/main/java/businessrule/responsemodel/ViewResponseModel.java b/src/main/java/businessrule/responsemodel/ViewResponseModel.java index 27c03776..ef00cd1c 100644 --- a/src/main/java/businessrule/responsemodel/ViewResponseModel.java +++ b/src/main/java/businessrule/responsemodel/ViewResponseModel.java @@ -4,7 +4,9 @@ import java.util.List; import java.util.Map; - +/** + * This class represents providing a simple and convenient way to transfer view data as a response to the client. + */ public class ViewResponseModel { private final int userId; private final String userName; diff --git a/src/main/java/driver/database/AttorneyRepository.java b/src/main/java/driver/database/AttorneyRepository.java index 1da95bb8..dfc7385d 100644 --- a/src/main/java/driver/database/AttorneyRepository.java +++ b/src/main/java/driver/database/AttorneyRepository.java @@ -4,6 +4,10 @@ import entity.Question; import entity.User; +/** + * This class represents an Attorney Repository, responsible for managing Attorney users' data and + * accessing attorney-related data. + */ // TODO: implement this class public class AttorneyRepository implements AttorneyGateway { diff --git a/src/main/java/driver/database/ClientRepository.java b/src/main/java/driver/database/ClientRepository.java index dc679f0c..cf8bce9c 100644 --- a/src/main/java/driver/database/ClientRepository.java +++ b/src/main/java/driver/database/ClientRepository.java @@ -1,4 +1,7 @@ package driver.database; +/** + * This class represents a Client Repository, responsible for managing and accessing client-related data. + */ import businessrule.gateway.ClientGateway; import entity.Client; diff --git a/src/main/java/driver/database/DatabaseConnection.java b/src/main/java/driver/database/DatabaseConnection.java index c223eb56..4532a24f 100644 --- a/src/main/java/driver/database/DatabaseConnection.java +++ b/src/main/java/driver/database/DatabaseConnection.java @@ -3,6 +3,9 @@ import javax.persistence.EntityManager; import javax.persistence.Persistence; +/** + * This class represents for managing the Database Connection and Entity Manager. + */ public class DatabaseConnection { private static final String URL = "objectdb://localhost:6136/myapp.odb;admin"; diff --git a/src/main/java/driver/database/PostRepo.java b/src/main/java/driver/database/PostRepo.java index 2b2e694d..37c81900 100644 --- a/src/main/java/driver/database/PostRepo.java +++ b/src/main/java/driver/database/PostRepo.java @@ -5,6 +5,9 @@ import javax.persistence.EntityManager; import javax.persistence.EntityTransaction; +/** + * This class represents the persistence operations for Post entities in the data store. + */ public class PostRepo implements PostGateway{ @Override diff --git a/src/main/java/driver/database/QuestionRepo.java b/src/main/java/driver/database/QuestionRepo.java index 19456353..62921985 100644 --- a/src/main/java/driver/database/QuestionRepo.java +++ b/src/main/java/driver/database/QuestionRepo.java @@ -8,6 +8,9 @@ import java.time.LocalDate; import java.util.List; +/** + * This class represents the persistence operations for Question entities in the data store. + */ public class QuestionRepo implements QuestionGateway{ @Override diff --git a/src/main/java/driver/database/UserRepository.java b/src/main/java/driver/database/UserRepository.java index a35826ff..bd0f1123 100644 --- a/src/main/java/driver/database/UserRepository.java +++ b/src/main/java/driver/database/UserRepository.java @@ -6,6 +6,9 @@ import javax.persistence.EntityManager; import javax.persistence.EntityTransaction; +/** + * This abstract class representing for accessing and managing user data in the database. + */ abstract class UserRepository implements UserGateway{ diff --git a/src/main/java/driver/screen/ApplicationException.java b/src/main/java/driver/screen/ApplicationException.java index 5a884297..276f0a81 100644 --- a/src/main/java/driver/screen/ApplicationException.java +++ b/src/main/java/driver/screen/ApplicationException.java @@ -1,5 +1,8 @@ package driver.screen; +/** + * This class represents a custom runtime exception that can be thrown during application execution. + */ public class ApplicationException extends RuntimeException{ public ApplicationException(String msg){ super(msg); diff --git a/src/main/java/driver/screen/AskQuestionUI.java b/src/main/java/driver/screen/AskQuestionUI.java index 64bf5dc5..6be63edc 100644 --- a/src/main/java/driver/screen/AskQuestionUI.java +++ b/src/main/java/driver/screen/AskQuestionUI.java @@ -10,12 +10,8 @@ import static javax.swing.JOptionPane.showMessageDialog; - - - /** - * - * @author joseph + * This class represents the user interface for clients to ask legal questions. */ public class AskQuestionUI extends JPanel implements ActionListener{ QuestionControl control; diff --git a/src/main/java/driver/screen/AttorneyHomePageUI.java b/src/main/java/driver/screen/AttorneyHomePageUI.java index e813d651..117773a4 100644 --- a/src/main/java/driver/screen/AttorneyHomePageUI.java +++ b/src/main/java/driver/screen/AttorneyHomePageUI.java @@ -5,6 +5,9 @@ import static javax.swing.JOptionPane.showMessageDialog; +/** + * This class represents the user interface for the attorney's home page after logging in. + */ public class AttorneyHomePageUI extends JPanel{ public AttorneyHomePageUI() { JLabel title = new JLabel("Attorney Home Page"); diff --git a/src/main/java/driver/screen/ClientHomePageUI.java b/src/main/java/driver/screen/ClientHomePageUI.java index 8803a501..3116a11a 100644 --- a/src/main/java/driver/screen/ClientHomePageUI.java +++ b/src/main/java/driver/screen/ClientHomePageUI.java @@ -3,6 +3,9 @@ import javax.swing.*; import java.awt.*; +/** + * This class represents the user interface for the client's home page after logging in. + */ public class ClientHomePageUI extends JPanel{ public ClientHomePageUI() { diff --git a/src/main/java/driver/screen/LabelTextPanel.java b/src/main/java/driver/screen/LabelTextPanel.java index b0e6c7a8..bff6d9a9 100644 --- a/src/main/java/driver/screen/LabelTextPanel.java +++ b/src/main/java/driver/screen/LabelTextPanel.java @@ -2,6 +2,9 @@ import javax.swing.*; +/** + * This is a custom JPanel class representing a simple panel with a label and a text field. + */ public class LabelTextPanel extends JPanel { public LabelTextPanel(JLabel label, JTextField textField){ this.add(label); diff --git a/src/main/java/driver/screen/LoginUI.java b/src/main/java/driver/screen/LoginUI.java index 2037ab0e..e4bec2bd 100644 --- a/src/main/java/driver/screen/LoginUI.java +++ b/src/main/java/driver/screen/LoginUI.java @@ -13,8 +13,7 @@ /** - * - * @author kaxi + * This class represents a user interface for logging in as both a client and an attorney. */ public class LoginUI extends JPanel implements ActionListener{ UserLoginControl control; diff --git a/src/main/java/driver/screen/ReplyQuestionUI.java b/src/main/java/driver/screen/ReplyQuestionUI.java index 5c1e5ba7..f747a1d8 100644 --- a/src/main/java/driver/screen/ReplyQuestionUI.java +++ b/src/main/java/driver/screen/ReplyQuestionUI.java @@ -1,4 +1,7 @@ package driver.screen; +/** + * This class represents the user interface for attorneys to reply a legal question. + */ public class ReplyQuestionUI { } From c31b547e7ce51ff297bf248838b11273d4669ad0 Mon Sep 17 00:00:00 2001 From: river3966 Date: Sat, 5 Aug 2023 18:00:23 -0400 Subject: [PATCH 03/24] documentation --- src/main/java/businessrule/gateway/UserGatewayFactory.java | 7 +++---- src/main/java/driver/database/ClientRepository.java | 7 ++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/businessrule/gateway/UserGatewayFactory.java b/src/main/java/businessrule/gateway/UserGatewayFactory.java index 4081c0be..c7023161 100644 --- a/src/main/java/businessrule/gateway/UserGatewayFactory.java +++ b/src/main/java/businessrule/gateway/UserGatewayFactory.java @@ -1,14 +1,13 @@ package businessrule.gateway; -/** - * This class represents a factory for creating instances of the "UserGateway" interface based on the given user ID. - */ import driver.database.AttorneyRepository; import driver.database.ClientRepository; import driver.database.UserGateway; import screen.ApplicationException; - +/** + * This class represents a factory for creating instances of the "UserGateway" interface based on the given user ID. + */ public class UserGatewayFactory { public UserGateway createUserGateway(int userId) { diff --git a/src/main/java/driver/database/ClientRepository.java b/src/main/java/driver/database/ClientRepository.java index cf8bce9c..0db5980e 100644 --- a/src/main/java/driver/database/ClientRepository.java +++ b/src/main/java/driver/database/ClientRepository.java @@ -1,7 +1,5 @@ package driver.database; -/** - * This class represents a Client Repository, responsible for managing and accessing client-related data. - */ + import businessrule.gateway.ClientGateway; import entity.Client; @@ -9,6 +7,9 @@ import javax.persistence.*; import java.util.List; +/** + * This class represents a Client Repository, responsible for managing and accessing client-related data. + */ public class ClientRepository extends UserRepository implements ClientGateway { public boolean existsByUsername(String username) { From a2f5079562aa1e440b84bc74a5131dcbba992cf9 Mon Sep 17 00:00:00 2001 From: river3966 Date: Tue, 8 Aug 2023 11:11:41 -0400 Subject: [PATCH 04/24] documentation --- .../controller/BrowseQuestionControl.java | 23 +++++- .../controller/ClientRegisterControl.java | 33 ++++++-- .../controller/CloseQuestionControl.java | 23 +++++- .../adapter/controller/ControlContainer.java | 64 ++++++++++++++- .../java/adapter/controller/PostControl.java | 23 +++++- .../adapter/controller/QuestionControl.java | 23 +++++- .../java/adapter/controller/RateControl.java | 20 ++++- .../controller/SelectQuestionControl.java | 21 ++++- .../adapter/controller/UserLoginControl.java | 18 ++++- .../controller/ViewQuestionControl.java | 29 ++++++- .../presenter/HomePageResponseFormatter.java | 43 ++++++++-- .../presenter/RegisterResponseFormatter.java | 40 ++++++++-- .../TheQuestionResponseFormatter.java | 34 +++++++- .../presenter/ViewResponseFormatter.java | 36 ++++++++- .../gateway/UserGatewayFactory.java | 2 +- .../requestmodel/BrowseRequestModel.java | 12 ++- .../ClientRegisterRequestModel.java | 78 +++++++++++++++++++ .../requestmodel/CloseRequestModel.java | 19 ++++- .../requestmodel/PostRequestModel.java | 24 +++++- .../requestmodel/QuestionRequestModel.java | 35 +++++++++ .../requestmodel/RateRequestModel.java | 22 ++++++ .../requestmodel/SelectRequestModel.java | 22 +++++- .../requestmodel/UserLoginRequestModel.java | 19 ++++- .../requestmodel/ViewRequestModel.java | 13 +++- .../responsemodel/HomePageResponseModel.java | 36 ++++++++- .../responsemodel/RegisterResponseModel.java | 4 +- .../TheQuestionResponseModel.java | 53 ++++++++++++- .../responsemodel/ViewResponseModel.java | 27 ++++++- .../usecase/BrowseQuestionInteractor.java | 4 +- .../usecase/ClientRegisterInteractor.java | 42 +++++++--- .../usecase/CloseQuestionInteractor.java | 36 +++++++-- .../usecase/PostDisplayFormatter.java | 37 +++++++-- .../usecase/PostMapConstructor.java | 35 ++++++--- .../usecase/QuestionDisplayFormatter.java | 29 ++++++- .../usecase/QuestionMapConstructor.java | 13 +++- .../businessrule/usecase/RateInteractor.java | 13 +++- .../businessrule/usecase/ReplyInteractor.java | 30 +++---- .../usecase/SelectQuestionInteractor.java | 24 ++++-- .../usecase/UserLoginInteractor.java | 39 ++++++---- .../usecase/ViewQuestionInteractor.java | 41 ++++++++-- .../driver/database/DatabaseConnection.java | 14 +++- .../driver/screen/ApplicationException.java | 12 ++- src/main/java/entity/Client.java | 5 +- 43 files changed, 1027 insertions(+), 143 deletions(-) diff --git a/src/main/java/adapter/controller/BrowseQuestionControl.java b/src/main/java/adapter/controller/BrowseQuestionControl.java index 77cea4b5..10495700 100644 --- a/src/main/java/adapter/controller/BrowseQuestionControl.java +++ b/src/main/java/adapter/controller/BrowseQuestionControl.java @@ -1,17 +1,36 @@ + package adapter.controller; import businessrule.requestmodel.BrowseRequestModel; import businessrule.responsemodel.ViewResponseModel; import businessrule.inputboundary.BrowseInputBoundary; +/** + * This class represents a controller responsible for browsing questions. + * It interacts with the business logic through the BrowseInputBoundary interface to handle browsing of + * questions based on the provided attorney ID. + */ + public class BrowseQuestionControl { private final BrowseInputBoundary browseInputBoundary; + /** + * Constructs a BrowseQuestionControl with the specified BrowseInputBoundary. + * + * @param browseInputBoundary The boundary interface for handling question browsing. + */ public BrowseQuestionControl(BrowseInputBoundary browseInputBoundary) { this.browseInputBoundary = browseInputBoundary; } - public ViewResponseModel browseQuestion(int attorneyId){ + + /** + * Browses questions based on the provided attorney ID. + * + * @param attorneyId The ID of the attorney for whom to retrieve question-related information. + * @return A ViewResponseModel containing the response information after browsing. + */ + public ViewResponseModel browseQuestion(int attorneyId) { BrowseRequestModel browseRequestModel = new BrowseRequestModel(attorneyId); return browseInputBoundary.browseQuestion(browseRequestModel); } -} +} \ No newline at end of file diff --git a/src/main/java/adapter/controller/ClientRegisterControl.java b/src/main/java/adapter/controller/ClientRegisterControl.java index 362ceb05..330fc911 100644 --- a/src/main/java/adapter/controller/ClientRegisterControl.java +++ b/src/main/java/adapter/controller/ClientRegisterControl.java @@ -1,9 +1,15 @@ + package adapter.controller; import businessrule.inputboundary.ClientRegisterInputBoundary; import businessrule.requestmodel.ClientRegisterRequestModel; import businessrule.responsemodel.RegisterResponseModel; +/** + * This class represents a controller responsible for handling client registration. It interacts with the + * business rules through the input boundary to register a new client. + */ + public class ClientRegisterControl { private final ClientRegisterInputBoundary inputBoundary; @@ -11,12 +17,29 @@ public ClientRegisterControl(ClientRegisterInputBoundary inputBoundary) { this.inputBoundary = inputBoundary; } - public RegisterResponseModel create(String userName, String email, String password1, String password2, - String StateAbb, String PostalCode, - String ethnicity, int age, String gender, String maritalStatus, - int numberOfHousehold, float annualIncome){ + /** + * Creates a new client registration based on the provided input parameters. + * + * @param userName The username of the client. + * @param email The email address of the client. + * @param password1 The first password entered by the client. + * @param password2 The confirmation password entered by the client. + * @param StateAbb The state abbreviation where the client resides. + * @param PostalCode The postal code of the client's location. + * @param ethnicity The ethnicity of the client. + * @param age The age of the client. + * @param gender The gender of the client. + * @param maritalStatus The marital status of the client. + * @param numberOfHousehold The number of members in the client's household. + * @param annualIncome The annual income of the client. + * @return A {@link businessrule.responsemodel.RegisterResponseModel} indicating the result of the registration. + */ + public RegisterResponseModel create(String userName, String email, String password1, String password2, + String StateAbb, String PostalCode, + String ethnicity, int age, String gender, String maritalStatus, + int numberOfHousehold, float annualIncome) { ClientRegisterRequestModel requestModel = new ClientRegisterRequestModel(userName, email, password1, password2, StateAbb, PostalCode, ethnicity, age, gender, maritalStatus, numberOfHousehold, annualIncome); return inputBoundary.create(requestModel); } -} +} \ No newline at end of file diff --git a/src/main/java/adapter/controller/CloseQuestionControl.java b/src/main/java/adapter/controller/CloseQuestionControl.java index 434b3411..61f4f9b8 100644 --- a/src/main/java/adapter/controller/CloseQuestionControl.java +++ b/src/main/java/adapter/controller/CloseQuestionControl.java @@ -1,18 +1,35 @@ + package adapter.controller; import businessrule.inputboundary.CloseInputBoundary; import businessrule.requestmodel.CloseRequestModel; import businessrule.responsemodel.HomePageResponseModel; +/** + * This class represents a controller responsible for closing a question. It utilizes the CloseInputBoundary + * to handle the process of closing a question. + */ public class CloseQuestionControl { private final CloseInputBoundary closeInputBoundary; + /** + * Constructs a CloseQuestionControl instance with the provided CloseInputBoundary. + * + * @param closeInputBoundary The CloseInputBoundary implementation to be used for closing questions. + */ public CloseQuestionControl(CloseInputBoundary closeInputBoundary) { this.closeInputBoundary = closeInputBoundary; } - public HomePageResponseModel closeQuestion(int questionId, int userId){ + + /** + * Initiates the process of closing a question. + * + * @param questionId The ID of the question to be closed. + * @param userId The ID of the user initiating the closing process. + * @return A HomePageResponseModel containing the result of the closing operation. + */ + public HomePageResponseModel closeQuestion(int questionId, int userId) { CloseRequestModel closeRequestModel = new CloseRequestModel(questionId, userId); return closeInputBoundary.closeQuestion(closeRequestModel); } -} - +} \ No newline at end of file diff --git a/src/main/java/adapter/controller/ControlContainer.java b/src/main/java/adapter/controller/ControlContainer.java index 5252458b..475082ff 100644 --- a/src/main/java/adapter/controller/ControlContainer.java +++ b/src/main/java/adapter/controller/ControlContainer.java @@ -1,5 +1,9 @@ package adapter.controller; +/** + * This class represents a container for various control instances used within the application. + * It holds references to different control objects that manage different aspects of the application's functionality. + */ public class ControlContainer { BrowseQuestionControl browseQuestionControl; ClientRegisterControl clientRegisterControl; @@ -11,6 +15,19 @@ public class ControlContainer { UserLoginControl userLoginControl; ViewQuestionControl viewQuestionControl; + /** + * Constructs a ControlContainer instance with the provided control objects. + * + * @param browseQuestionControl The control object for browsing questions. + * @param clientRegisterControl The control object for client registration. + * @param closeQuestionControl The control object for closing questions. + * @param postControl The control object for managing posts. + * @param questionControl The control object for managing questions. + * @param rateControl The control object for rating questions. + * @param selectQuestionControl The control object for selecting questions. + * @param userLoginControl The control object for user login. + * @param viewQuestionControl The control object for viewing questions. + */ public ControlContainer(BrowseQuestionControl browseQuestionControl, ClientRegisterControl clientRegisterControl, CloseQuestionControl closeQuestionControl, @@ -28,39 +45,84 @@ public ControlContainer(BrowseQuestionControl browseQuestionControl, this.viewQuestionControl = viewQuestionControl; } + /** + * Get the control object for browsing questions. + * + * @return The BrowseQuestionControl instance. + */ public BrowseQuestionControl getBrowseQuestionControl() { return browseQuestionControl; } + /** + * Get the control object for client registration. + * + * @return The ClientRegisterControl instance. + */ public ClientRegisterControl getClientRegisterControl() { return clientRegisterControl; } + /** + * Get the control object for closing questions. + * + * @return The CloseQuestionControl instance. + */ public CloseQuestionControl getCloseQuestionControl() { return closeQuestionControl; } + /** + * Get the control object for managing posts. + * + * @return The PostControl instance. + */ public PostControl getPostControl() { return postControl; } + /** + * Get the control object for managing questions. + * + * @return The QuestionControl instance. + */ public QuestionControl getQuestionControl() { return questionControl; } + /** + * Get the control object for rating questions. + * + * @return The RateControl instance. + */ public RateControl getRateControl() { return rateControl; } + /** + * Get the control object for selecting questions. + * + * @return The SelectQuestionControl instance. + */ public SelectQuestionControl getSelectQuestionControl() { return selectQuestionControl; } + /** + * Get the control object for user login. + * + * @return The UserLoginControl instance. + */ public UserLoginControl getUserLoginControl() { return userLoginControl; } + /** + * Get the control object for viewing questions. + * + * @return The ViewQuestionControl instance. + */ public ViewQuestionControl getViewQuestionControl() { return viewQuestionControl; } -} +} \ No newline at end of file diff --git a/src/main/java/adapter/controller/PostControl.java b/src/main/java/adapter/controller/PostControl.java index 00c5519e..89c09077 100644 --- a/src/main/java/adapter/controller/PostControl.java +++ b/src/main/java/adapter/controller/PostControl.java @@ -4,16 +4,33 @@ import businessrule.requestmodel.PostRequestModel; import businessrule.responsemodel.HomePageResponseModel; +/** + * This class represents the controller responsible for handling interactions related to creating posts. + */ public class PostControl { + private final PostInputBoundary postInput; - public PostControl(PostInputBoundary postInput){ + /** + * Constructs a new PostControl instance. + * + * @param postInput The input boundary for post-related operations. + */ + public PostControl(PostInputBoundary postInput) { this.postInput = postInput; } - public HomePageResponseModel createPost(int questionId, int userId, String postText){ + /** + * Creates a new post and associates it with a question. + * + * @param questionId The ID of the question the post is associated with. + * @param userId The ID of the user creating the post. + * @param postText The content of the post. + * @return A HomePageResponseModel containing information about the updated home page. + */ + public HomePageResponseModel createPost(int questionId, int userId, String postText) { PostRequestModel postRequestModel = new PostRequestModel(questionId, userId, postText); return postInput.createPost(postRequestModel); } -} +} \ No newline at end of file diff --git a/src/main/java/adapter/controller/QuestionControl.java b/src/main/java/adapter/controller/QuestionControl.java index f5db1818..66d48e3b 100644 --- a/src/main/java/adapter/controller/QuestionControl.java +++ b/src/main/java/adapter/controller/QuestionControl.java @@ -1,3 +1,4 @@ + package adapter.controller; import businessrule.responsemodel.TheQuestionResponseModel; @@ -6,15 +7,35 @@ import java.time.LocalDate; +/** + * This class represents a controller for handling questions. + * It interacts with the business logic to create questions and retrieve responses. + */ + public class QuestionControl { private final QuestionInputBoundary questionInput; + /** + * Constructor for QuestionControl. + * + * @param questionInput The input boundary for handling questions. + */ public QuestionControl(QuestionInputBoundary questionInput){ this.questionInput = questionInput; } + /** + * Creates a new question based on the provided information. + * + * @param questionCategory The category of the question. + * @param title The title of the question. + * @param createAt The creation date of the question. + * @param askedByClient The ID of the client who asked the question. + * @param legalDeadline The legal deadline for the question. + * @return The response model containing the result of creating the question. + */ public TheQuestionResponseModel createQuestion(String questionCategory, String title, LocalDate createAt, int askedByClient, LocalDate legalDeadline){ QuestionRequestModel requestModel = new QuestionRequestModel(questionCategory, title, createAt, askedByClient, legalDeadline); return questionInput.createQuestion(requestModel); } -} +} \ No newline at end of file diff --git a/src/main/java/adapter/controller/RateControl.java b/src/main/java/adapter/controller/RateControl.java index daf6b08b..7ad0aecd 100644 --- a/src/main/java/adapter/controller/RateControl.java +++ b/src/main/java/adapter/controller/RateControl.java @@ -4,16 +4,32 @@ import businessrule.requestmodel.RateRequestModel; import businessrule.responsemodel.HomePageResponseModel; +/** + * This class represents a controller responsible for handling rating-related actions. + * It interacts with the business logic layer to handle rating answers and related operations. + */ public class RateControl { private final RateInputBoundary rateInput; + /** + * Constructs a RateControl instance with the specified RateInputBoundary implementation. + * + * @param input The RateInputBoundary implementation used for handling rate-related operations. + */ public RateControl(RateInputBoundary input) { this.rateInput = input; } + /** + * Rates an answer and updates the corresponding information. + * + * @param rate The rating value given by the user. + * @param questionId The ID of the question associated with the answer. + * @param userId The ID of the user providing the rating. + * @return A HomePageResponseModel containing updated information after rating. + */ public HomePageResponseModel rateAnswer(int rate, int questionId, int userId) { RateRequestModel rating = new RateRequestModel(rate, questionId, userId); return rateInput.rateAnswer(rating); } - -} +} \ No newline at end of file diff --git a/src/main/java/adapter/controller/SelectQuestionControl.java b/src/main/java/adapter/controller/SelectQuestionControl.java index 4e3659c2..e3f7f7f0 100644 --- a/src/main/java/adapter/controller/SelectQuestionControl.java +++ b/src/main/java/adapter/controller/SelectQuestionControl.java @@ -4,14 +4,31 @@ import businessrule.inputboundary.SelectInputBoundary; import businessrule.requestmodel.SelectRequestModel; +/** + * This class represents a controller responsible for selecting a question. + * It interacts with the business logic through the SelectInputBoundary and handles the input/output for question selection. + */ public class SelectQuestionControl { private final SelectInputBoundary selectInputBoundary; + /** + * Constructs a SelectQuestionControl instance with the given SelectInputBoundary. + * + * @param selectInputBoundary The input boundary responsible for selecting questions. + */ public SelectQuestionControl(SelectInputBoundary selectInputBoundary) { this.selectInputBoundary = selectInputBoundary; } + + /** + * Selects a question based on the provided question ID and user ID. + * + * @param questionId The ID of the question to be selected. + * @param userId The ID of the user requesting the question selection. + * @return The response model containing the selected question's information. + */ public TheQuestionResponseModel selectQuestion(int questionId, int userId) { - SelectRequestModel selectRequestModel = new SelectRequestModel(questionId, userId); + SelectRequestModel selectRequestModel = new SelectRequestModel(questionId, userId); return selectInputBoundary.selectQuestion(selectRequestModel); } -} +} \ No newline at end of file diff --git a/src/main/java/adapter/controller/UserLoginControl.java b/src/main/java/adapter/controller/UserLoginControl.java index 2b5f08b4..07ea6859 100644 --- a/src/main/java/adapter/controller/UserLoginControl.java +++ b/src/main/java/adapter/controller/UserLoginControl.java @@ -4,15 +4,31 @@ import businessrule.requestmodel.UserLoginRequestModel; import businessrule.responsemodel.HomePageResponseModel; +/** + * This class represents the controller responsible for handling user login functionality. + * It communicates with the business logic through the UserLoginInputBoundary. + */ public class UserLoginControl { private final UserLoginInputBoundary inputBoundary; + /** + * Constructs a new UserLoginControl instance with the provided UserLoginInputBoundary. + * + * @param inputBoundary The input boundary to communicate with the business logic. + */ public UserLoginControl(UserLoginInputBoundary inputBoundary) { this.inputBoundary = inputBoundary; } + /** + * Attempts to log in the user with the given userId and password. + * + * @param userId The ID of the user attempting to log in. + * @param password The password of the user attempting to log in. + * @return A HomePageResponseModel containing information about the home page after login. + */ public HomePageResponseModel login(int userId, String password){ UserLoginRequestModel requestModel = new UserLoginRequestModel(userId, password); return inputBoundary.login(requestModel); } -} +} \ No newline at end of file diff --git a/src/main/java/adapter/controller/ViewQuestionControl.java b/src/main/java/adapter/controller/ViewQuestionControl.java index dbcfcc3c..425bae32 100644 --- a/src/main/java/adapter/controller/ViewQuestionControl.java +++ b/src/main/java/adapter/controller/ViewQuestionControl.java @@ -4,15 +4,38 @@ import businessrule.inputboundary.ViewInputBoundary; import businessrule.requestmodel.ViewRequestModel; +/** + * This class represents a controller responsible for viewing questions. + * It interacts with the business logic layer to retrieve and provide + * question-related information to the view. + */ public class ViewQuestionControl { + private final ViewInputBoundary viewInputBoundary; + /** + * Constructs a new ViewQuestionControl instance. + * + * @param viewInputBoundary The input boundary for viewing questions, + * responsible for handling interactions between + * the controller and the business logic layer. + */ public ViewQuestionControl(ViewInputBoundary viewInputBoundary) { this.viewInputBoundary = viewInputBoundary; } - public ViewResponseModel viewQuestion(int userId){ + + /** + * Retrieves question-related information for a specific user. + * + * @param userId The identifier of the user for whom the questions are to be viewed. + * @return A response model containing the information about the questions + * that are accessible to the specified user. + */ + public ViewResponseModel viewQuestion(int userId) { + // Create a request model with the given user ID ViewRequestModel viewRequestModel = new ViewRequestModel(userId); - return viewInputBoundary.viewQuestion(viewRequestModel); + // Delegate the request to the input boundary and return the response + return viewInputBoundary.viewQuestion(viewRequestModel); } -} +} \ No newline at end of file diff --git a/src/main/java/adapter/presenter/HomePageResponseFormatter.java b/src/main/java/adapter/presenter/HomePageResponseFormatter.java index 6778f177..0f536c5b 100644 --- a/src/main/java/adapter/presenter/HomePageResponseFormatter.java +++ b/src/main/java/adapter/presenter/HomePageResponseFormatter.java @@ -1,4 +1,5 @@ package adapter.presenter; + import adapter.controller.ControlContainer; import businessrule.outputboundary.HomePageOutputBoundary; import businessrule.responsemodel.HomePageResponseModel; @@ -11,35 +12,64 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +/** + * This class represents a formatter for generating UI responses for the home page. + * It prepares and formats the response data for display on the user interface. + */ public class HomePageResponseFormatter implements HomePageOutputBoundary { - CardLayout cardLayout; - JPanel screens; - ControlContainer controlContainer; + private CardLayout cardLayout; + private JPanel screens; + private ControlContainer controlContainer; + + /** + * Constructs a HomePageResponseFormatter. + * + * @param cardLayout The CardLayout used for managing UI panels. + * @param screens The JPanel containing different UI screens. + */ public HomePageResponseFormatter(CardLayout cardLayout, JPanel screens) { this.cardLayout = cardLayout; this.screens = screens; } + /** + * Sets the control container for interacting with the application. + * + * @param controlContainer The control container instance. + */ @Override public void setControlContainer(ControlContainer controlContainer) { this.controlContainer = controlContainer; } + /** + * Prepares a failure response with the specified message. + * + * @param msg The error message. + * @throws ApplicationException An exception indicating a failure in the application. + */ @Override public HomePageResponseModel prepareFail(String msg) { throw new ApplicationException(msg); } + /** + * Prepares a successful response for the home page. + * + * @param response The response model containing the data to be displayed. + * @return The prepared response model. + */ @Override public HomePageResponseModel prepareSuccess(HomePageResponseModel response) { int userId = response.getUserId(); String userName = response.getUserName(); String userType = response.getUserType(); + if (userType.equals("Attorney")) { - AttorneyHomePageUI AttorneyHomePage = new AttorneyHomePageUI(controlContainer, cardLayout, screens, + AttorneyHomePageUI attorneyHomePage = new AttorneyHomePageUI(controlContainer, cardLayout, screens, userId, userName); - screens.add(AttorneyHomePage, "AttorneyHomePage"); + screens.add(attorneyHomePage, "AttorneyHomePage"); cardLayout.show(screens, "AttorneyHomePage"); } else { ClientHomePageUI clientHomePage = new ClientHomePageUI(controlContainer, cardLayout, screens, @@ -47,6 +77,7 @@ public HomePageResponseModel prepareSuccess(HomePageResponseModel response) { screens.add(clientHomePage, "ClientHomePage"); cardLayout.show(screens, "ClientHomePage"); } + return response; } -} +} \ No newline at end of file diff --git a/src/main/java/adapter/presenter/RegisterResponseFormatter.java b/src/main/java/adapter/presenter/RegisterResponseFormatter.java index b19c09bb..cc153abd 100644 --- a/src/main/java/adapter/presenter/RegisterResponseFormatter.java +++ b/src/main/java/adapter/presenter/RegisterResponseFormatter.java @@ -9,24 +9,54 @@ import javax.swing.*; import java.awt.*; +/** + * This class represents a formatter for register response data and controlling the display of UI + * elements based on the response. + */ public class RegisterResponseFormatter implements RegisterOutputBoundary { - CardLayout cardLayout; - JPanel screens; - ControlContainer controlContainer; + private CardLayout cardLayout; + private JPanel screens; + private ControlContainer controlContainer; + /** + * Constructs a RegisterResponseFormatter with the specified card layout and screens panel. + * + * @param cardLayout The CardLayout used for managing UI screens. + * @param screens The JPanel containing the UI screens. + */ public RegisterResponseFormatter(CardLayout cardLayout, JPanel screens) { this.cardLayout = cardLayout; this.screens = screens; } + + /** + * Sets the ControlContainer instance to be used for controlling the application. + * + * @param controlContainer The ControlContainer instance. + */ @Override public void setControlContainer(ControlContainer controlContainer) { this.controlContainer = controlContainer; } + /** + * Prepares a failure response for registration. + * + * @param msg The error message to be displayed. + * @return A RegisterResponseModel representing the failure response. + * @throws ApplicationException An exception indicating the application encountered an error. + */ @Override - public RegisterResponseModel prepareFail(String msg) { + public RegisterResponseModel prepareFail(String msg) throws ApplicationException { throw new ApplicationException(msg); } + + /** + * Prepares a success response for registration. + * + * @param msg The success message to be displayed. + * @return A RegisterResponseModel representing the success response. + */ @Override public RegisterResponseModel prepareSuccess(String msg) { WelcomeUI welcomeUI = new WelcomeUI(controlContainer, cardLayout, screens); @@ -35,4 +65,4 @@ public RegisterResponseModel prepareSuccess(String msg) { JOptionPane.showMessageDialog(null, msg); return new RegisterResponseModel(); } -} +} \ No newline at end of file diff --git a/src/main/java/adapter/presenter/TheQuestionResponseFormatter.java b/src/main/java/adapter/presenter/TheQuestionResponseFormatter.java index 99e27454..600bc2f6 100644 --- a/src/main/java/adapter/presenter/TheQuestionResponseFormatter.java +++ b/src/main/java/adapter/presenter/TheQuestionResponseFormatter.java @@ -1,3 +1,4 @@ + package adapter.presenter; import adapter.controller.ControlContainer; @@ -12,25 +13,56 @@ import java.time.LocalDate; import java.util.Map; +/** + * This class represents the formatting the response model of a question into a user interface representation + * for display. + */ + public class TheQuestionResponseFormatter implements TheQuestionOutputBoundary { CardLayout cardLayout; JPanel screens; ControlContainer controlContainer; + /** + * Constructs a TheQuestionResponseFormatter with the specified CardLayout and JPanel. + * + * @param cardLayout The CardLayout used to manage different screens. + * @param screens The JPanel where the screens are displayed. + */ public TheQuestionResponseFormatter(CardLayout cardLayout, JPanel screens) { this.cardLayout = cardLayout; this.screens = screens; } + + /** + * Sets the ControlContainer to interact with the application's control logic. + * + * @param controlContainer The ControlContainer instance. + */ @Override public void setControlContainer(ControlContainer controlContainer) { this.controlContainer = controlContainer; } + /** + * Prepares a failure response by throwing an ApplicationException with the specified message. + * + * @param msg The error message. + * @return This method does not return as it throws an exception. + * @throws ApplicationException Always thrown with the specified error message. + */ @Override public TheQuestionResponseModel prepareFail(String msg) { throw new ApplicationException(msg); } + /** + * Prepares a success response by formatting the response model into a user interface representation + * for display in TheQuestionUI. + * + * @param response The response model. + * @return The formatted response model suitable for display. + */ @Override public TheQuestionResponseModel prepareSuccess(TheQuestionResponseModel response) { int userId = response.getUserId(); @@ -47,4 +79,4 @@ public TheQuestionResponseModel prepareSuccess(TheQuestionResponseModel response cardLayout.show(screens, "question"); return response; } -} +} \ No newline at end of file diff --git a/src/main/java/adapter/presenter/ViewResponseFormatter.java b/src/main/java/adapter/presenter/ViewResponseFormatter.java index 5eacf54c..37f201fa 100644 --- a/src/main/java/adapter/presenter/ViewResponseFormatter.java +++ b/src/main/java/adapter/presenter/ViewResponseFormatter.java @@ -11,34 +11,68 @@ import java.awt.*; import java.util.Map; +/** + * The ViewResponseFormatter class is responsible for formatting and displaying view responses in the user interface. + * It implements the ViewOutputBoundary interface to handle success and failure scenarios for presenting data to the user. + */ public class ViewResponseFormatter implements ViewOutputBoundary { CardLayout cardLayout; JPanel screens; ControlContainer controlContainer; + /** + * Constructs a ViewResponseFormatter with the specified card layout and screen panel. + * + * @param cardLayout The CardLayout used to manage different screens. + * @param screens The main panel containing various UI screens. + */ public ViewResponseFormatter(CardLayout cardLayout, JPanel screens) { this.cardLayout = cardLayout; this.screens = screens; } + + /** + * Sets the ControlContainer instance to manage user interactions. + * + * @param controlContainer The ControlContainer instance to be set. + */ @Override public void setControlContainer(ControlContainer controlContainer) { this.controlContainer = controlContainer; } + /** + * Throws an ApplicationException with the specified error message. + * + * @param msg The error message to be included in the exception. + * @return This method does not return due to the thrown exception. + * @throws ApplicationException Always throws an ApplicationException with the provided message. + */ @Override public ViewResponseModel prepareFail(String msg) { throw new ApplicationException(msg); } + /** + * Prepares and displays a successful view response in the user interface. + * + * @param response The ViewResponseModel containing the data to be displayed. + * @return The original response model passed as a parameter. + */ @Override public ViewResponseModel prepareSuccess(ViewResponseModel response) { int userId = response.getUserId(); String userName = response.getUserName(); Map questionMap = response.getQuestionMap(); + + // Create a QuestionListUI to display the list of questions. QuestionListUI questionListUI = new QuestionListUI(controlContainer, cardLayout, screens, userId, userName, questionMap); screens.add(questionListUI, "browseQuestion"); cardLayout.show(screens, "browseQuestion"); + + // Print a message indicating that available questions have been displayed. System.out.println("Available questions showed"); + return response; } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/gateway/UserGatewayFactory.java b/src/main/java/businessrule/gateway/UserGatewayFactory.java index 9e7b98fd..fc74fb22 100644 --- a/src/main/java/businessrule/gateway/UserGatewayFactory.java +++ b/src/main/java/businessrule/gateway/UserGatewayFactory.java @@ -4,7 +4,7 @@ import driver.database.ClientRepository; import driver.database.UserGateway; -import screen.ApplicationException; +import driver.screen.ApplicationException; public class UserGatewayFactory { diff --git a/src/main/java/businessrule/requestmodel/BrowseRequestModel.java b/src/main/java/businessrule/requestmodel/BrowseRequestModel.java index aac26102..5e67c037 100644 --- a/src/main/java/businessrule/requestmodel/BrowseRequestModel.java +++ b/src/main/java/businessrule/requestmodel/BrowseRequestModel.java @@ -6,11 +6,21 @@ public class BrowseRequestModel { private final int attorneyId; + /** + * Constructs a new BrowseRequestModel with the specified attorney ID. + * + * @param attorneyId The ID of the attorney for whom the questions are being browsed. + */ public BrowseRequestModel(int attorneyId) { this.attorneyId = attorneyId; } + /** + * Gets the attorney ID associated with this browse request. + * + * @return The attorney ID. + */ public int getAttorneyId() { return attorneyId; } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/requestmodel/ClientRegisterRequestModel.java b/src/main/java/businessrule/requestmodel/ClientRegisterRequestModel.java index f1a484a6..03ebd94d 100644 --- a/src/main/java/businessrule/requestmodel/ClientRegisterRequestModel.java +++ b/src/main/java/businessrule/requestmodel/ClientRegisterRequestModel.java @@ -1,6 +1,8 @@ package businessrule.requestmodel; + /** * This class represents a request model for client registration. + * It contains various fields related to client registration information. */ public class ClientRegisterRequestModel { private final String userName; @@ -16,6 +18,22 @@ public class ClientRegisterRequestModel { private final int numberOfHousehold; private final float annualIncome; + /** + * Constructs a new ClientRegisterRequestModel with the provided registration information. + * + * @param userName The username for the client. + * @param email The email address of the client. + * @param password The password for the client's account. + * @param password2 The confirmation password for the client's account. + * @param stateAbb The state abbreviation for the client's location. + * @param postalCode The postal code for the client's location. + * @param ethnicity The ethnicity of the client. + * @param age The age of the client. + * @param gender The gender of the client. + * @param maritalStatus The marital status of the client. + * @param numberOfHousehold The number of people in the client's household. + * @param annualIncome The annual income of the client. + */ public ClientRegisterRequestModel(String userName, String email, String password, String password2, String stateAbb, String postalCode, String ethnicity, @@ -35,50 +53,110 @@ public ClientRegisterRequestModel(String userName, String email, String password this.annualIncome = annualIncome; } + /** + * Gets the username of the client. + * + * @return The username of the client. + */ public String getUserName() { return userName; } + /** + * Gets the email address of the client. + * + * @return The email address of the client. + */ public String getEmail() { return email; } + /** + * Gets the password of the client's account. + * + * @return The password of the client's account. + */ public String getPassword() { return password; } + /** + * Gets the confirmation password of the client's account. + * + * @return The confirmation password of the client's account. + */ public String getPassword2() { return password2; } + /** + * Gets the state abbreviation of the client's location. + * + * @return The state abbreviation of the client's location. + */ public String getStateAbb() { return stateAbb; } + /** + * Gets the postal code of the client's location. + * + * @return The postal code of the client's location. + */ public String getPostalCode() { return postalCode; } + /** + * Gets the ethnicity of the client. + * + * @return The ethnicity of the client. + */ public String getEthnicity() { return ethnicity; } + /** + * Gets the age of the client. + * + * @return The age of the client. + */ public int getAge() { return age; } + /** + * Gets the gender of the client. + * + * @return The gender of the client. + */ public String getGender() { return gender; } + /** + * Gets the marital status of the client. + * + * @return The marital status of the client. + */ public String getMaritalStatus() { return maritalStatus; } + /** + * Gets the number of people in the client's household. + * + * @return The number of people in the client's household. + */ public int getNumberOfHousehold() { return numberOfHousehold; } + /** + * Gets the annual income of the client. + * + * @return The annual income of the client. + */ public float getAnnualIncome() { return annualIncome; } diff --git a/src/main/java/businessrule/requestmodel/CloseRequestModel.java b/src/main/java/businessrule/requestmodel/CloseRequestModel.java index 75a38a6a..208b1fbf 100644 --- a/src/main/java/businessrule/requestmodel/CloseRequestModel.java +++ b/src/main/java/businessrule/requestmodel/CloseRequestModel.java @@ -1,4 +1,5 @@ package businessrule.requestmodel; + /** * This class represents a request model to close a question made by a client. */ @@ -6,16 +7,32 @@ public class CloseRequestModel { private final int questionId; private final int userId; + /** + * Constructs a CloseRequestModel object with the provided question ID and user ID. + * + * @param questionId The ID of the question to be closed. + * @param userId The ID of the user making the close request. + */ public CloseRequestModel(int questionId, int userId) { this.questionId = questionId; this.userId = userId; } + /** + * Gets the ID of the question to be closed. + * + * @return The ID of the question. + */ public int getQuestionId() { return questionId; } + /** + * Gets the ID of the user making the close request. + * + * @return The ID of the user. + */ public int getUserId() { return userId; } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/requestmodel/PostRequestModel.java b/src/main/java/businessrule/requestmodel/PostRequestModel.java index 6267bd87..3989a41a 100644 --- a/src/main/java/businessrule/requestmodel/PostRequestModel.java +++ b/src/main/java/businessrule/requestmodel/PostRequestModel.java @@ -10,21 +10,43 @@ public class PostRequestModel { private final int userId; private final String postText; + /** + * Constructs a new PostRequestModel instance. + * + * @param questionId The ID of the question associated with the post. + * @param userId The ID of the user creating the post. + * @param postText The text content of the post. + */ public PostRequestModel(int questionId, int userId, String postText){ this.questionId = questionId; this.userId = userId; this.postText = postText; } + /** + * Get the ID of the question associated with the post. + * + * @return The question ID. + */ public int getQuestionId() { return questionId; } + /** + * Get the ID of the user creating the post. + * + * @return The user ID. + */ public int getUserId() { return userId; } + /** + * Get the text content of the post. + * + * @return The post text. + */ public String getPostText() { return postText; } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/requestmodel/QuestionRequestModel.java b/src/main/java/businessrule/requestmodel/QuestionRequestModel.java index 0ff674d6..c0694b0c 100644 --- a/src/main/java/businessrule/requestmodel/QuestionRequestModel.java +++ b/src/main/java/businessrule/requestmodel/QuestionRequestModel.java @@ -1,6 +1,7 @@ package businessrule.requestmodel; import java.time.LocalDate; + /** * This class represents a post request model for creating a new question. */ @@ -11,6 +12,15 @@ public class QuestionRequestModel { private final int askedByClient; private final LocalDate legalDeadline; + /** + * Constructs a new QuestionRequestModel with the specified parameters. + * + * @param questionCategory The category of the question. + * @param title The title of the question. + * @param createAt The creation date of the question. + * @param askedByClient The ID of the client who asked the question. + * @param legalDeadline The legal deadline for the question. + */ public QuestionRequestModel(String questionCategory, String title, LocalDate createAt, int askedByClient, LocalDate legalDeadline) { this.questionCategory = questionCategory; this.title = title; @@ -19,22 +29,47 @@ public QuestionRequestModel(String questionCategory, String title, LocalDate cre this.legalDeadline = legalDeadline; } + /** + * Get the category of the question. + * + * @return The question category. + */ public String getQuestionCategory() { return questionCategory; } + /** + * Get the title of the question. + * + * @return The question title. + */ public String getTitle() { return title; } + /** + * Get the creation date of the question. + * + * @return The creation date. + */ public LocalDate getCreateAt() { return createAt; } + /** + * Get the ID of the client who asked the question. + * + * @return The client ID. + */ public int getAskedByClient() { return askedByClient; } + /** + * Get the legal deadline for the question. + * + * @return The legal deadline. + */ public LocalDate getLegalDeadline() { return legalDeadline; } diff --git a/src/main/java/businessrule/requestmodel/RateRequestModel.java b/src/main/java/businessrule/requestmodel/RateRequestModel.java index ff1e9250..1cdfdc9c 100644 --- a/src/main/java/businessrule/requestmodel/RateRequestModel.java +++ b/src/main/java/businessrule/requestmodel/RateRequestModel.java @@ -9,20 +9,42 @@ public class RateRequestModel { private final int answerId; private final int userId; + /** + * Constructs a RateRequestModel with the specified parameters. + * + * @param rating The rating value for the answer. + * @param answerId The ID of the answer being rated. + * @param userId The ID of the user rating the answer. + */ public RateRequestModel(int rating, int answerId, int userId) { this.rating = rating; this.answerId = answerId; this.userId = userId; } + /** + * Retrieves the rating value for the answer. + * + * @return The rating value. + */ public int getRating() { return rating; } + /** + * Retrieves the ID of the answer being rated. + * + * @return The answer ID. + */ public int getAnswerId() { return answerId; } + /** + * Retrieves the ID of the user rating the answer. + * + * @return The user ID. + */ public int getUserId() { return userId; } diff --git a/src/main/java/businessrule/requestmodel/SelectRequestModel.java b/src/main/java/businessrule/requestmodel/SelectRequestModel.java index 0939a7da..68b38246 100644 --- a/src/main/java/businessrule/requestmodel/SelectRequestModel.java +++ b/src/main/java/businessrule/requestmodel/SelectRequestModel.java @@ -1,22 +1,40 @@ package businessrule.requestmodel; /** - * This class represents a request model for selecting question. + * This class represents a request model for selecting a question. + * It encapsulates the necessary information for selecting a question, including the question ID + * and the user ID requesting the selection. */ public class SelectRequestModel { private final int questionId; private final int userId; + /** + * Constructs a SelectRequestModel with the provided question ID and user ID. + * + * @param questionId The ID of the question to be selected. + * @param userId The ID of the user making the selection request. + */ public SelectRequestModel(int questionId, int userId) { this.questionId = questionId; this.userId = userId; } + /** + * Gets the question ID from the request model. + * + * @return The ID of the question. + */ public int getQuestionId() { return questionId; } + /** + * Gets the user ID from the request model. + * + * @return The ID of the user making the selection request. + */ public int getUserId() { return userId; } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/requestmodel/UserLoginRequestModel.java b/src/main/java/businessrule/requestmodel/UserLoginRequestModel.java index 1e16e2eb..3f2b2102 100644 --- a/src/main/java/businessrule/requestmodel/UserLoginRequestModel.java +++ b/src/main/java/businessrule/requestmodel/UserLoginRequestModel.java @@ -1,21 +1,38 @@ package businessrule.requestmodel; /** - * This class represents request model for a user login . + * This class represents a user login request model. + * It encapsulates the information needed for a user to perform a login operation. */ public class UserLoginRequestModel { private final int userId; private final String password; + /** + * Constructs a new UserLoginRequestModel with the provided user ID and password. + * + * @param userId The unique identifier of the user. + * @param password The user's password. + */ public UserLoginRequestModel(int userId, String password) { this.userId = userId; this.password = password; } + /** + * Retrieves the user ID from the login request. + * + * @return The user's unique identifier. + */ public int getUserId() { return userId; } + /** + * Retrieves the password from the login request. + * + * @return The user's password. + */ public String getPassword() { return password; } diff --git a/src/main/java/businessrule/requestmodel/ViewRequestModel.java b/src/main/java/businessrule/requestmodel/ViewRequestModel.java index 1bbc04c4..04aff4bb 100644 --- a/src/main/java/businessrule/requestmodel/ViewRequestModel.java +++ b/src/main/java/businessrule/requestmodel/ViewRequestModel.java @@ -1,15 +1,26 @@ package businessrule.requestmodel; /** - * This class represents request model for viewing questions. + * This class represents a request model for viewing a specific entity. + * It encapsulates the information required to retrieve entity data for a user. */ public class ViewRequestModel { private final int userId; + /** + * Constructs a ViewRequestModel object. + * + * @param userId The ID of the user requesting to view the entity. + */ public ViewRequestModel(int userId) { this.userId = userId; } + /** + * Get the ID of the user who wants to view the entity. + * + * @return The ID of the user. + */ public int getUserId() { return userId; } diff --git a/src/main/java/businessrule/responsemodel/HomePageResponseModel.java b/src/main/java/businessrule/responsemodel/HomePageResponseModel.java index 273de948..0ae752e6 100644 --- a/src/main/java/businessrule/responsemodel/HomePageResponseModel.java +++ b/src/main/java/businessrule/responsemodel/HomePageResponseModel.java @@ -5,25 +5,59 @@ * as a response to the client. */ public class HomePageResponseModel { + + /** + * The unique identifier of the user. + */ private final int userId; + + /** + * The name of the user. + */ private final String userName; + + /** + * The type of the user (e.g., "admin", "user"). + */ private final String userType; + /** + * Constructs a new HomePageResponseModel object with the specified user information. + * + * @param userId The unique identifier of the user. + * @param userName The name of the user. + * @param userType The type of the user. + */ public HomePageResponseModel(int userId, String userName, String userType) { this.userId = userId; this.userName = userName; this.userType = userType; } + /** + * Get the unique identifier of the user. + * + * @return The user's unique identifier. + */ public int getUserId() { return userId; } + /** + * Get the name of the user. + * + * @return The user's name. + */ public String getUserName() { return userName; } + /** + * Get the type of the user. + * + * @return The user's type. + */ public String getUserType() { return userType; } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/responsemodel/RegisterResponseModel.java b/src/main/java/businessrule/responsemodel/RegisterResponseModel.java index f93470c7..69d9652c 100644 --- a/src/main/java/businessrule/responsemodel/RegisterResponseModel.java +++ b/src/main/java/businessrule/responsemodel/RegisterResponseModel.java @@ -1,7 +1,9 @@ package businessrule.responsemodel; + /** * This class represents providing a simple and convenient way to transfer register data * as a response to the client. */ public class RegisterResponseModel { -} + +} \ No newline at end of file diff --git a/src/main/java/businessrule/responsemodel/TheQuestionResponseModel.java b/src/main/java/businessrule/responsemodel/TheQuestionResponseModel.java index 6a2dfb41..eb91b9e0 100644 --- a/src/main/java/businessrule/responsemodel/TheQuestionResponseModel.java +++ b/src/main/java/businessrule/responsemodel/TheQuestionResponseModel.java @@ -4,10 +4,11 @@ import java.time.LocalDate; import java.util.Map; + /** * This class represents providing a simple and convenient way to transfer questions data as a response to the client. */ -public class TheQuestionResponseModel{ +public class TheQuestionResponseModel { private final int userId; private final int questionId; private final String userName; @@ -16,6 +17,17 @@ public class TheQuestionResponseModel{ private final LocalDate deadline; private final Map postMap; + /** + * Constructs a new TheQuestionResponseModel object with the provided data. + * + * @param userId The ID of the user associated with the question response. + * @param questionId The ID of the question associated with the response. + * @param userName The name of the user associated with the question response. + * @param title The title of the question. + * @param type The type of the question. + * @param deadline The deadline associated with the question. + * @param postMap A map containing post IDs as keys and corresponding PostDisplayFormatter objects as values. + */ public TheQuestionResponseModel(int userId, int questionId, String userName, String title, String type, LocalDate deadline, Map postMap) { this.userId = userId; this.questionId = questionId; @@ -26,28 +38,65 @@ public TheQuestionResponseModel(int userId, int questionId, String userName, Str this.postMap = postMap; } + /** + * Returns the ID of the user associated with the question response. + * + * @return The user ID. + */ public int getUserId() { return userId; } - public int getQuestionId() {return questionId;} + /** + * Returns the ID of the question associated with the response. + * + * @return The question ID. + */ + public int getQuestionId() { + return questionId; + } + /** + * Returns the name of the user associated with the question response. + * + * @return The user name. + */ public String getUserName() { return userName; } + /** + * Returns the title of the question. + * + * @return The question title. + */ public String getTitle() { return title; } + /** + * Returns the type of the question. + * + * @return The question type. + */ public String getType() { return type; } + /** + * Returns the deadline associated with the question. + * + * @return The question deadline. + */ public LocalDate getDeadline() { return deadline; } + /** + * Returns a map containing post IDs as keys and corresponding PostDisplayFormatter objects as values. + * + * @return The map of post IDs and PostDisplayFormatter objects. + */ public Map getPostMap() { return postMap; } diff --git a/src/main/java/businessrule/responsemodel/ViewResponseModel.java b/src/main/java/businessrule/responsemodel/ViewResponseModel.java index ef00cd1c..7daaf8b6 100644 --- a/src/main/java/businessrule/responsemodel/ViewResponseModel.java +++ b/src/main/java/businessrule/responsemodel/ViewResponseModel.java @@ -4,29 +4,52 @@ import java.util.List; import java.util.Map; + /** - * This class represents providing a simple and convenient way to transfer view data as a response to the client. + * This class represents a response model that provides a simple and convenient way to transfer view data as a response to the client. */ public class ViewResponseModel { private final int userId; private final String userName; private final Map questionMap; + /** + * Constructs a new ViewResponseModel with the specified user ID, user name, and question map. + * + * @param userId The ID of the user associated with the response. + * @param userName The name of the user associated with the response. + * @param questionMap A map containing question IDs as keys and their corresponding QuestionDisplayFormatters as values. + */ public ViewResponseModel(int userId, String userName, Map questionMap) { this.userId = userId; this.userName = userName; this.questionMap = questionMap; } + /** + * Get the ID of the user associated with this response. + * + * @return The user ID. + */ public int getUserId() { return userId; } + /** + * Get the name of the user associated with this response. + * + * @return The user name. + */ public String getUserName() { return userName; } + /** + * Get the map of question IDs and their corresponding QuestionDisplayFormatters. + * + * @return The question map. + */ public Map getQuestionMap() { return questionMap; } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/BrowseQuestionInteractor.java b/src/main/java/businessrule/usecase/BrowseQuestionInteractor.java index 120d7dd2..695f1d40 100644 --- a/src/main/java/businessrule/usecase/BrowseQuestionInteractor.java +++ b/src/main/java/businessrule/usecase/BrowseQuestionInteractor.java @@ -17,7 +17,7 @@ * * This class facilitates browsing and retrieving a list of not-taken questions from the data source. */ -public class BrowseQuestionInterator implements BrowseInputBoundary { +public class BrowseQuestionInteractor implements BrowseInputBoundary { /** * The output boundary for preparing view responses. @@ -41,7 +41,7 @@ public class BrowseQuestionInterator implements BrowseInputBoundary { * @param questionGateway The gateway for question-related operations. * @param attorneyGateway The gateway for attorney-related operations. */ - public BrowseQuestionInterator(ViewOutputBoundary viewOutputBoundary, QuestionGateway questionGateway, AttorneyGateway attorneyGateway) { + public BrowseQuestionInteractor(ViewOutputBoundary viewOutputBoundary, QuestionGateway questionGateway, AttorneyGateway attorneyGateway) { this.viewOutputBoundary = viewOutputBoundary; this.questionGateway = questionGateway; this.attorneyGateway = attorneyGateway; diff --git a/src/main/java/businessrule/usecase/ClientRegisterInteractor.java b/src/main/java/businessrule/usecase/ClientRegisterInteractor.java index a0ded073..d9665b0a 100644 --- a/src/main/java/businessrule/usecase/ClientRegisterInteractor.java +++ b/src/main/java/businessrule/usecase/ClientRegisterInteractor.java @@ -1,12 +1,5 @@ package businessrule.usecase; -/** - * This class represents the interactor for registering a new client user. - * - * The "ClientRegisterInteractor" class is responsible for handling the business logic related to registering - * a new client user - */ - import adapter.presenter.RegisterResponseFormatter; import businessrule.gateway.ClientGateway; import businessrule.inputboundary.ClientRegisterInputBoundary; @@ -19,20 +12,51 @@ import entity.CredentialChecker; import entity.RandomNumberGenerator; +/** + * This class represents the interactor for registering a new client user. + * The "ClientRegisterInteractor" class is responsible for handling the business logic related to registering + * a new client user. + */ public class ClientRegisterInteractor implements ClientRegisterInputBoundary { + + /** + * The gateway for accessing client-related operations. + */ final ClientGateway clientGateway; + + /** + * The output boundary for preparing registration responses. + */ final RegisterOutputBoundary outputBoundary; + + /** + * The factory for creating Client entities. + */ final ClientFactory clientFactory; + /** + * Constructs an instance of ClientRegisterInteractor with the necessary dependencies. + * + * @param clientGateway The gateway for client-related operations. + * @param outputBoundary The output boundary for preparing registration responses. + * @param clientFactory The factory for creating Client entities. + */ public ClientRegisterInteractor(ClientGateway clientGateway, RegisterOutputBoundary outputBoundary, ClientFactory clientFactory) { this.clientGateway = clientGateway; this.outputBoundary = outputBoundary; this.clientFactory = clientFactory; } + /** + * Creates a new client user based on the provided ClientRegisterRequestModel and returns a registration response model. + * + * @param requestModel The model containing information for registering a new client user. + * @return The response model indicating the outcome of the registration attempt. + */ @Override - public RegisterResponseModel create(ClientRegisterRequestModel requestModel){ - // prepare input data + public RegisterResponseModel create(ClientRegisterRequestModel requestModel) { + + // prepare input data String inputUserName = requestModel.getUserName(); String inputEmail = requestModel.getEmail(); String inputPassword1 = requestModel.getPassword(); diff --git a/src/main/java/businessrule/usecase/CloseQuestionInteractor.java b/src/main/java/businessrule/usecase/CloseQuestionInteractor.java index 0e0e6de2..ce2370a3 100644 --- a/src/main/java/businessrule/usecase/CloseQuestionInteractor.java +++ b/src/main/java/businessrule/usecase/CloseQuestionInteractor.java @@ -1,11 +1,5 @@ package businessrule.usecase; -/** - * The "CloseQuestionInteractor" class represents a use case interactor for closing a question. - * - * This class is responsible for handling the business logic related to closing a question in the system. It - */ - import businessrule.inputboundary.CloseInputBoundary; import businessrule.outputboundary.HomePageOutputBoundary; import businessrule.requestmodel.CloseRequestModel; @@ -16,17 +10,47 @@ import businessrule.gateway.UserGateway; import businessrule.gateway.UserGatewayFactory; +/** + * This class represents a use case interactor for closing a question. + * + * This class is responsible for handling the business logic related to closing a question in the system. + */ public class CloseQuestionInteractor implements CloseInputBoundary { + + /** + * The gateway for accessing question-related operations. + */ final QuestionGateway questionGateway; + + /** + * The output boundary for preparing responses to the home page. + */ final HomePageOutputBoundary homePageOutputBoundary; + + /** + * The factory for creating UserGateway instances. + */ final UserGatewayFactory userGatewayFactory; + /** + * Constructs an instance of CloseQuestionInteractor with the necessary dependencies. + * + * @param questionGateway The gateway for question-related operations. + * @param homePageOutputBoundary The output boundary for preparing responses to the home page. + * @param userGatewayFactory The factory for creating UserGateway instances. + */ public CloseQuestionInteractor(QuestionGateway questionGateway, HomePageOutputBoundary homePageOutputBoundary, UserGatewayFactory userGatewayFactory) { this.questionGateway = questionGateway; this.homePageOutputBoundary = homePageOutputBoundary; this.userGatewayFactory = userGatewayFactory; } + /** + * Closes a question based on the provided CloseRequestModel and returns a response model for the home page. + * + * @param closeRequestModel The model containing information to close a question. + * @return The response model for the home page indicating the outcome of the close attempt. + */ @Override public HomePageResponseModel closeQuestion(CloseRequestModel closeRequestModel) { // get input data diff --git a/src/main/java/businessrule/usecase/PostDisplayFormatter.java b/src/main/java/businessrule/usecase/PostDisplayFormatter.java index 751129ec..5caa2e25 100644 --- a/src/main/java/businessrule/usecase/PostDisplayFormatter.java +++ b/src/main/java/businessrule/usecase/PostDisplayFormatter.java @@ -1,22 +1,29 @@ -package businessrule.usecase; +package adapter.presenter; import entity.Post; import java.time.LocalDate; /** - * The "PostDisplayFormatter" class represents a formatted display of a post for presentation purposes. + * This class represents a formatted display of a post for presentation purposes. * * This class is responsible for formatting a post in a user-friendly way for displaying it to users - * in the application's user interface. It encapsulates the essential information related to a post, + * in the application's user interface. It encapsulates the essential information related to a post. */ - public class PostDisplayFormatter { private final String postText; private final boolean isClient; private final String name; private final LocalDate createAt; + /** + * Constructs a new PostDisplayFormatter object with the provided information. + * + * @param postText The text content of the post. + * @param isClient Indicates whether the post was made by a client. + * @param name The name associated with the post author. + * @param createAt The date when the post was created. + */ public PostDisplayFormatter(String postText, boolean isClient, String name, LocalDate createAt) { this.postText = postText; this.isClient = isClient; @@ -24,19 +31,39 @@ public PostDisplayFormatter(String postText, boolean isClient, String name, Loca this.createAt = createAt; } + /** + * Get the text content of the post. + * + * @return The post's text content. + */ public String getPostText() { return postText; } + /** + * Check if the post was made by a client. + * + * @return true if the post was made by a client, false otherwise. + */ public boolean isClient() { return isClient; } + /** + * Get the name associated with the post author. + * + * @return The author's name. + */ public String getName() { return name; } + /** + * Get the date when the post was created. + * + * @return The creation date of the post. + */ public LocalDate getCreateAt() { return createAt; } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/PostMapConstructor.java b/src/main/java/businessrule/usecase/PostMapConstructor.java index a7d0172c..d4c4ecc0 100644 --- a/src/main/java/businessrule/usecase/PostMapConstructor.java +++ b/src/main/java/businessrule/usecase/PostMapConstructor.java @@ -12,34 +12,49 @@ import java.util.Map; /** - * The "PostMapConstructor" class is responsible for constructing a map of post information for a given question. + * This class represents for constructing a map of post information for a given question. */ class PostMapConstructor { private final UserGatewayFactory userGatewayFactory; - public PostMapConstructor(UserGatewayFactory userGatewayFactory) {this.userGatewayFactory = userGatewayFactory;} + /** + * Constructs a PostMapConstructor instance with the provided UserGatewayFactory. + * + * @param userGatewayFactory The factory for creating UserGateways. + */ + public PostMapConstructor(UserGatewayFactory userGatewayFactory) { + this.userGatewayFactory = userGatewayFactory; + } + /** + * Constructs a map of post information for a given question. + * + * @param question The question for which to construct the post map. + * @return A map containing post information. + */ protected Map constructPostMap(Question question) { List postList = question.getPosts(); - // initialize post map + // Initialize post map Map postMap = new HashMap<>(); - // handle the empty post list - if (postList.isEmpty()) {return postMap;} + // Handle the empty post list + if (postList.isEmpty()) { + return postMap; + } - // for each post list, find the data needed - for (Post post: postList) { + // For each post in the list, find the data needed + for (Post post : postList) { int postId = post.getPostId(); UserGateway userGateway = userGatewayFactory.createUserGateway(post.getBelongsTo()); User user = userGateway.getUser(post.getBelongsTo()); boolean isClient = user.isClient(); String name = user.getUserName(); String postText = post.getPostText(); - LocalDate createAt = post.getCreateAt(); - PostDisplayFormatter postDisplayFormatter = new PostDisplayFormatter(postText, isClient, name, createAt); + LocalDate createdAt = post.getCreatedAt(); + PostDisplayFormatter postDisplayFormatter = new PostDisplayFormatter(postText, isClient, name, createdAt); - // put every data needed to the post map + // Put the data into the post map postMap.put(postId, postDisplayFormatter); } return postMap; diff --git a/src/main/java/businessrule/usecase/QuestionDisplayFormatter.java b/src/main/java/businessrule/usecase/QuestionDisplayFormatter.java index c9499e22..8a68f1e6 100644 --- a/src/main/java/businessrule/usecase/QuestionDisplayFormatter.java +++ b/src/main/java/businessrule/usecase/QuestionDisplayFormatter.java @@ -3,30 +3,51 @@ import java.time.LocalDate; /** - * The "QuestionDisplayFormatter" class represents a formatted display of a legal question. - * This class is used to format and display essential information about a legal question in a user-friendly manner. + * This class represents a formatted display of a legal question. + * It is used to format and display essential information about a legal question in a user-friendly manner. */ public class QuestionDisplayFormatter { private final String title; private final String type; private final LocalDate legalDeadline; + /** + * Constructs a QuestionDisplayFormatter instance with the specified parameters. + * + * @param title The title of the legal question. + * @param type The type or category of the legal question. + * @param legalDeadline The legal deadline associated with the question. + */ public QuestionDisplayFormatter(String title, String type, LocalDate legalDeadline) { this.title = title; this.type = type; this.legalDeadline = legalDeadline; } - + /** + * Gets the title of the legal question. + * + * @return The title of the legal question. + */ public String getTitle() { return title; } + /** + * Gets the type or category of the legal question. + * + * @return The type or category of the legal question. + */ public String getType() { return type; } + /** + * Gets the legal deadline associated with the question. + * + * @return The legal deadline associated with the question. + */ public LocalDate getLegalDeadline() { return legalDeadline; } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/QuestionMapConstructor.java b/src/main/java/businessrule/usecase/QuestionMapConstructor.java index b32b296f..2b7e22a8 100644 --- a/src/main/java/businessrule/usecase/QuestionMapConstructor.java +++ b/src/main/java/businessrule/usecase/QuestionMapConstructor.java @@ -1,7 +1,6 @@ package businessrule.usecase; import entity.Question; -import entity.User; import java.time.LocalDate; import java.util.HashMap; @@ -9,15 +8,21 @@ import java.util.Map; /** - * The "QuestionMapConstructor" class is a utility class responsible for constructing a map of question display formatters. + * This class represents a utility class responsible for constructing a map of question display formatters. */ class QuestionMapConstructor { + /** + * Constructs a map of question display formatters based on the provided list of questions. + * + * @param questionList The list of questions for which to construct the map. + * @return A map containing question display formatters. + */ protected Map constructQuestionMap(List questionList) { Map questionMap = new HashMap<>(); if (questionList.isEmpty()) { return questionMap; } - for (Question question: questionList) { + for (Question question : questionList) { int questionId = question.getQuestionId(); String title = question.getTitle(); String type = question.getType(); @@ -27,4 +32,4 @@ protected Map constructQuestionMap(List postMap = postMapConstructor.constructPostMap(question); - TheQuestionResponseModel theQuestionResponseModel = new TheQuestionResponseModel(userId, questionId, user.getUserName(), question.getTitle(), question.getType(), question.getLegalDeadline(), postMap); + TheQuestionResponseModel theQuestionResponseModel = new TheQuestionResponseModel(userId, questionId, + user.getUserName(), question.getTitle(), question.getType(), question.getLegalDeadline(), postMap); return theQuestionOutputBoundary.prepareSuccess(theQuestionResponseModel); } else { return theQuestionOutputBoundary.prepareFail("This question is not accessible."); } } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/UserLoginInteractor.java b/src/main/java/businessrule/usecase/UserLoginInteractor.java index 611cb8e7..2098007b 100644 --- a/src/main/java/businessrule/usecase/UserLoginInteractor.java +++ b/src/main/java/businessrule/usecase/UserLoginInteractor.java @@ -12,28 +12,37 @@ import java.time.LocalDateTime; /** - * This class is responsible for handling the user login use case in the application. - * It interacts with the "UserGatewayFactory" to access user information from the data source and - * validates user credentials to authenticate the user. - * The class uses the "HomePageOutputBoundary" to prepare and return the appropriate response model - * based on the result of the login attempt. + * This class represents the interactor for the user login use case. */ -public class UserLoginInteractor implements UserLoginInputBoundary{ - final UserGatewayFactory userGatewayFactory; - final HomePageOutputBoundary outputBoundary; +public class UserLoginInteractor implements UserLoginInputBoundary { + private final UserGatewayFactory userGatewayFactory; + private final HomePageOutputBoundary outputBoundary; + + /** + * Constructs a UserLoginInteractor with the given dependencies. + * + * @param userGatewayFactory Factory to create UserGateway instances. + * @param outputBoundary Output boundary for the home page. + */ public UserLoginInteractor(UserGatewayFactory userGatewayFactory, HomePageOutputBoundary outputBoundary) { this.userGatewayFactory = userGatewayFactory; this.outputBoundary = outputBoundary; } + /** + * Attempts to log in a user using the provided login credentials. + * + * @param requestModel The login request model containing user credentials. + * @return A response model indicating the login status and user information. + */ @Override public HomePageResponseModel login(UserLoginRequestModel requestModel) { - // get input data + // Get input data int inputUserId = requestModel.getUserId(); String inputPassword = requestModel.getPassword(); - // use user gateway factory to retrieve the correct type of repo + // Use user gateway factory to retrieve the correct type of repository UserGateway userGateway; try { userGateway = userGatewayFactory.createUserGateway(inputUserId); @@ -41,7 +50,7 @@ public HomePageResponseModel login(UserLoginRequestModel requestModel) { return outputBoundary.prepareFail("User ID does not exist"); } - // handle login logic + // Handle login logic if (!userGateway.existsById(inputUserId)) { return outputBoundary.prepareFail("User ID does not exist"); } @@ -51,16 +60,16 @@ public HomePageResponseModel login(UserLoginRequestModel requestModel) { return outputBoundary.prepareFail("Password is incorrect"); } - // construct response model + // Construct response model String userType; User user = userGateway.getUser(inputUserId); - if (user.isClient()){ + if (user.isClient()) { userType = "Client"; - } else{ + } else { userType = "Attorney"; } HomePageResponseModel accountResponseModel = new HomePageResponseModel(inputUserId, userGateway.getUser(inputUserId).getUserName(), userType); return outputBoundary.prepareSuccess(accountResponseModel); } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/ViewQuestionInteractor.java b/src/main/java/businessrule/usecase/ViewQuestionInteractor.java index a1f6c222..b1943f43 100644 --- a/src/main/java/businessrule/usecase/ViewQuestionInteractor.java +++ b/src/main/java/businessrule/usecase/ViewQuestionInteractor.java @@ -7,7 +7,6 @@ import businessrule.gateway.UserGatewayFactory; import businessrule.outputboundary.ViewOutputBoundary; import businessrule.responsemodel.ViewResponseModel; -import entity.Attorney; import entity.Question; import entity.User; import java.util.List; @@ -15,14 +14,32 @@ /** * This class serves as an interactor for viewing questions associated with a user. - * It implements the "ViewInputBoundary" interface, which defines the contract for viewing questions. * The class is responsible for handling user requests to view questions and constructing the appropriate response. */ public class ViewQuestionInteractor implements ViewInputBoundary { + + /** + * The gateway to access question-related data. + */ final QuestionGateway questionGateway; + + /** + * The output boundary for sending the response. + */ final ViewOutputBoundary viewOutputBoundary; + + /** + * Factory for creating user gateways. + */ final UserGatewayFactory userGatewayFactory; + /** + * Constructs a new ViewQuestionInteractor with the provided dependencies. + * + * @param questionGateway The gateway to access question-related data. + * @param viewOutputBoundary The output boundary for sending the response. + * @param userGatewayFactory Factory for creating user gateways. + */ public ViewQuestionInteractor(QuestionGateway questionGateway, ViewOutputBoundary viewOutputBoundary, UserGatewayFactory userGatewayFactory) { this.questionGateway = questionGateway; @@ -30,20 +47,34 @@ public ViewQuestionInteractor(QuestionGateway questionGateway, ViewOutputBoundar this.userGatewayFactory = userGatewayFactory; } + /** + * Handles the user's request to view questions and constructs the appropriate response. + * + * @param viewRequestModel The request model containing the user's information. + * @return The response model containing the user's information and question data. + */ @Override public ViewResponseModel viewQuestion(ViewRequestModel viewRequestModel) { - // get user who performed the operation + // Get the ID of the user who performed the operation int userId = viewRequestModel.getUserId(); + + // Create a user gateway using the factory UserGateway userGateway = userGatewayFactory.createUserGateway(userId); + + // Get the user using the user gateway User user = userGateway.getUser(userId); - // get question list to view by the user + // Get the list of questions associated with the user List questionList = user.getQuestionsList(); - // construct response model + // Construct a map of questions for display QuestionMapConstructor questionMapConstructor = new QuestionMapConstructor(); Map questionMap = questionMapConstructor.constructQuestionMap(questionList); + + // Create and populate the response model ViewResponseModel viewResponseModel = new ViewResponseModel(user.getUserId(), user.getUserName(), questionMap); + + // Prepare and return the success response using the output boundary return viewOutputBoundary.prepareSuccess(viewResponseModel); } } \ No newline at end of file diff --git a/src/main/java/driver/database/DatabaseConnection.java b/src/main/java/driver/database/DatabaseConnection.java index e39b31b3..1cb9bab9 100644 --- a/src/main/java/driver/database/DatabaseConnection.java +++ b/src/main/java/driver/database/DatabaseConnection.java @@ -1,16 +1,22 @@ package driver.database; + import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManager; import javax.persistence.Persistence; /** - * This class represents for managing the Database Connection and Entity Manager. + * This class represents a utility for managing the Database Connection and Entity Manager. */ public class DatabaseConnection { private static final String URL = "objectdb:myapp.odb;admin"; private static EntityManagerFactory entityManagerFactory; + /** + * Retrieves an instance of EntityManager for database interaction. + * + * @return An EntityManager instance. + */ public static EntityManager getEntityManager() { if (entityManagerFactory == null) { entityManagerFactory = Persistence.createEntityManagerFactory(URL); @@ -18,10 +24,12 @@ public static EntityManager getEntityManager() { return entityManagerFactory.createEntityManager(); } + /** + * Closes the EntityManagerFactory if it is open. + */ public static void closeEntityManagerFactory() { if (entityManagerFactory != null && entityManagerFactory.isOpen()) { entityManagerFactory.close(); } } -} - +} \ No newline at end of file diff --git a/src/main/java/driver/screen/ApplicationException.java b/src/main/java/driver/screen/ApplicationException.java index 276f0a81..a810f090 100644 --- a/src/main/java/driver/screen/ApplicationException.java +++ b/src/main/java/driver/screen/ApplicationException.java @@ -3,8 +3,14 @@ /** * This class represents a custom runtime exception that can be thrown during application execution. */ -public class ApplicationException extends RuntimeException{ - public ApplicationException(String msg){ +public class ApplicationException extends RuntimeException { + + /** + * Constructs an ApplicationException with the specified error message. + * + * @param msg The error message associated with the exception. + */ + public ApplicationException(String msg) { super(msg); } -} +} \ No newline at end of file diff --git a/src/main/java/entity/Client.java b/src/main/java/entity/Client.java index 6e94c4d3..829a56db 100644 --- a/src/main/java/entity/Client.java +++ b/src/main/java/entity/Client.java @@ -12,10 +12,7 @@ * This is a class representing client user. * * A Client is a registered user who seeks legal advice and assistance by posting questions - * to be answered by attorneys. The Client class includes attributes such as user ID, username, - * email, password, state abbreviation, postal code, ethnicity, age, gender, marital status, - * number of household members, and annual income. Additionally, it maintains a list of questions - * associated with the client. + * to be answered by attorneys. */ @Entity From cdd72559f9c7b12f61a10e8240c6a65465092a90 Mon Sep 17 00:00:00 2001 From: river3966 Date: Wed, 9 Aug 2023 01:25:28 -0400 Subject: [PATCH 05/24] documentation --- README.md | 105 --------- src/main/java/AttorneyRegister.java | 10 + .../adapter/controller/ControlContainer.java | 62 ++++- .../controller/ViewQuestionControl.java | 24 +- .../businessrule/gateway/AttorneyGateway.java | 28 ++- .../businessrule/gateway/ClientGateway.java | 12 +- .../businessrule/gateway/GenericGateway.java | 43 +++- .../businessrule/gateway/PostGateway.java | 15 +- .../businessrule/gateway/QuestionGateway.java | 79 ++++++- .../businessrule/gateway/UserGateway.java | 31 ++- .../gateway/UserGatewayFactory.java | 26 ++- .../ClientRegisterInputBoundary.java | 12 +- .../inputboundary/CloseInputBoundary.java | 13 +- .../inputboundary/PostInputBoundary.java | 12 +- .../inputboundary/QuestionInputBoundary.java | 12 +- .../inputboundary/RateInputBoundary.java | 11 +- .../inputboundary/SelectInputBoundary.java | 12 +- .../inputboundary/UserLoginInputBoundary.java | 12 +- .../inputboundary/ViewInputBoundary.java | 12 +- .../HomePageOutputBoundary.java | 26 ++- .../RegisterOutputBoundary.java | 26 ++- .../TheQuestionOutputBoundary.java | 26 ++- .../outputboundary/ViewOutputBoundary.java | 26 ++- .../TheQuestionResponseModel.java | 57 ++++- .../usecase/AskQuestionInteractor.java | 22 +- .../usecase/AttorneyRecommendInteractor.java | 28 ++- .../usecase/BrowseQuestionInteractor.java | 26 ++- .../usecase/ClientRegisterInteractor.java | 24 +- .../businessrule/usecase/RateInteractor.java | 20 +- .../businessrule/usecase/ReplyInteractor.java | 2 +- .../usecase/SelectQuestionInteractor.java | 28 ++- .../usecase/UserLoginInteractor.java | 31 ++- .../usecase/ViewQuestionInteractor.java | 28 ++- .../usecase/ViewQuestionInteractorBase.java | 34 ++- .../ViewRateableQuestionInteractor.java | 36 ++- .../businessrule/usecase/util/Matching.java | 32 ++- .../usecase/util/MatchingHandler.java | 28 ++- .../usecase/util/MatchingResult.java | 36 ++- .../usecase/util/PostDisplayFormatter.java | 43 +++- .../usecase/util/PostMapConstructor.java | 31 ++- .../usecase/util/PythonReader.java | 13 +- .../util/QuestionDisplayFormatter.java | 38 ++- .../usecase/util/QuestionMapConstructor.java | 21 +- .../usecase/util/RandomNumberGenerator.java | 66 +++++- .../driver/database/AttorneyRepository.java | 25 +- .../driver/database/ClientRepository.java | 17 +- .../driver/database/DatabaseConnection.java | 2 +- .../driver/database/GenericRepository.java | 21 +- src/main/java/driver/database/PostRepo.java | 19 +- .../java/driver/database/QuestionRepo.java | 12 +- .../java/driver/database/UserRepository.java | 13 +- .../driver/screen/AttorneyHomePageUI.java | 49 ++-- .../java/driver/screen/ClientHomePageUI.java | 26 ++- .../java/driver/screen/DateChooserPanel.java | 4 +- .../java/driver/screen/DropDownPanel.java | 4 +- .../java/driver/screen/QuestionListUI.java | 32 ++- src/main/java/driver/screen/RegisterUI.java | 54 ++--- .../java/driver/screen/ReplyQuestionUI.java | 6 +- .../java/driver/screen/TheQuestionUI.java | 28 ++- src/main/java/driver/screen/UIDesign.java | 3 + src/main/java/driver/screen/WelcomeUI.java | 41 +++- src/main/java/entity/Client.java | 218 ++++++++++++++++-- src/main/java/entity/Post.java | 73 +++++- src/main/java/entity/Question.java | 163 ++++++++++++- src/main/java/entity/User.java | 8 +- 65 files changed, 1737 insertions(+), 360 deletions(-) delete mode 100644 README.md create mode 100644 src/main/java/AttorneyRegister.java diff --git a/README.md b/README.md deleted file mode 100644 index d5524bf4..00000000 --- a/README.md +++ /dev/null @@ -1,105 +0,0 @@ -# Legal Consultation Platform+ -*Bridging the Gap in Legal Consultation Services* - -## Overview - -The COVID-19 pandemic has brought numerous challenges to the forefront, one of which is an increased need for free legal consultation services across the United States. The uncertainty and economic instability resulting from the pandemic have led to a surge in legal inquiries, which existing resources have been unable to meet effectively. This discrepancy signals a systemic issue that needs immediate attention. - -Despite the American Bar Association's (ABA) best efforts, their data reveals a worrying trend. Across the U.S., over 30% of legal questions posed on their platform remain unanswered by attorneys. In certain states like Louisiana, the neglect is even more pronounced with over 70% of inquiries going unanswered. Additionally, among the questions that do receive attention, approximately 35% are inadequately addressed. - -Addressing this gap, we introduce the **Legal Consultation Platform+** , a solution tailored to serve both individuals seeking legal advice and registered, licensed attorneys willing to provide it. Our platform is designed to create an environment where individuals can post their legal inquiries free of charge, and attorneys can browse and respond to these questions at their convenience. - -One of the standout features of **Legal Consultation Platform+** is its intelligent attorney-question matching system. This system recommends up to five questions from the feed to each attorney, based on their expertise and interests. This not only streamlines the process for attorneys, saving them valuable time, but also enhances the quality of responses. To ensure attorneys do not miss out on relevant inquiries, the platform also sends them email notifications. - -Our mission with **Legal Consultation Platform+** is to democratize access to legal consultation and ensure no question goes unanswered or improperly addressed. Together, we can navigate these challenging times by making legal assistance more accessible and efficient for all. - ---- - -## Client User Guide - -### Registration and Account Set-Up - -Upon registration, individuals seeking free legal consultation are prompted to set up their accounts and provide demographic information. After registration, clients can log in using their provided user ID and password. - -### Interface and Features - -The client's homepage presents two main options: initiating a new question or viewing historical queries. - -#### Posting a New Question - -To post a new question, clients must provide basic information, such as the question title, type, and legal deadline. They can then elaborate on their query in the detailed description section on the specific question page. After submission, clients can track the status of their questions. - -#### Tracking Questions - -Clients can monitor whether their questions have been answered on the "View Historical Questions" page, which lists all previously asked questions. To enhance visibility, we send an email notification to the client's registered email address once their question has been answered, and we mark the question in the question history page. - -#### Closing Questions - -Once a client is satisfied with the answer to a question, they can opt to close the question. Closing a question makes it invisible and unresponsive to all attorneys. - -#### Rating Experience - -Finally, clients can provide binary ratings on their overall experience. - ---- - -## Attorney User Guide - -### Registration and Verification - -Attorneys interested in participating on our platform should first contact us via email for verification of confidentiality and personal information. After registration, they can login using their user ID and password. - -### Interface and Features - -The attorney's homepage allows them to browse all available questions or track previously answered questions to handle any follow-up queries from clients. - -#### Browsing and Answering Questions - -On the "Browse Questions" page, attorneys can view all questions that have not yet been claimed. After selecting a question of interest, they can view its details and provide an answer. Once an attorney has answered a question, they are expected to fully dedicate themselves to that question, taking care of any follow-up queries. We provide email notifications for any follow-up questions. - -#### Question Recommendation and Notification - -Attorneys also receive a weekly email containing a feed of recommended questions, based on our intelligent matching algorithm. They can view their question feed by clicking the "Question Recommendations" button on their homepage. - ---- - -## Team Members and Roles - -### Yifan Liu - Project Manager & Machine Learning Specialist -Yifan directs project coordination, ensuring alignment among different developers, and meticulously tracks progress to ensure project milestones are met on time. As a Machine Learning Specialist, he has spearheaded the development of our proprietary question-attorney matching system, leveraging advanced Machine Learning and Natural Language Processing techniques. - -### Zihan Yuan - User Interface Designer & Front-End Developer -Zihan is tasked with the design and development of the user-centric front-end interface of our platform. Her contribution to the team extends to the management of the user registration and login system, ensuring a seamless user experience. - -### Cheng Peng - Software Verification Specialist & Back-End Developer -As a Software Verification Specialist, Cheng plays a pivotal role in ensuring the functionality and reliability of all platform features through rigorous testing and coordination. Additionally, he oversees the implementation of the question-asking and reply features as a Back-End Developer. - -### Zhouyi Yu - Data Engineer -Zhouyi is the backbone of our data infrastructure. As our Data Engineer, he is responsible for the design, development, and maintenance of the robust database system that powers our platform. - -### Xingfu Wu - Software Verification Specialist & IT Support Specialist -Xingfu oversees the testing of higher-level entities in the platform, ensuring our product meets stringent quality standards. He also doubles as our IT Support Specialist, proficiently handling server setup and maintenance. - -### River Qi - Back-End Developer -River Qi, as a Back-End Developer, spearheads the 'View Question' feature of our platform. His efforts have been instrumental in ensuring that our users can easily access and navigate their queries. - ---- -## Installation Guide -[*In Development*] - ---- -## Matching System Specification -[*In Development*] - ---- -## Future Enhancements - -### Web-based Database Management System -In future iterations of our platform, we plan to transition to a web-based database management system. This change will allow for more efficient data management and improved accessibility, making it easier to handle and process data on the platform. - -### Intelligent Sample Responses -Another enhancement in our roadmap involves providing intelligent sample responses to clients. This feature will utilize advanced algorithms to identify when a user's query is similar to existing ones. In such instances, the system will automatically suggest sample answers from those previous, similar questions. This will not only speed up the response time for users but also enrich the overall user experience by instantly providing them with helpful information. - -### Domain-Specific AI for Timely Responses -We are also in the process of developing a domain-specific Artificial Intelligencesystem. This AI system will be designed to provide timely responses to user queries while we continue to retain the element of real-person answers. This innovative feature will enhance the speed and efficiency of our platform, ensuring that users get the information they need as quickly as possible. - diff --git a/src/main/java/AttorneyRegister.java b/src/main/java/AttorneyRegister.java new file mode 100644 index 00000000..f1f26fe1 --- /dev/null +++ b/src/main/java/AttorneyRegister.java @@ -0,0 +1,10 @@ +import driver.database.AttorneyRepository; +import entity.Attorney; + +public class AttorneyRegister { + public static void main(String[] args) { + AttorneyRepository attorneyRepository = new AttorneyRepository(); + Attorney attorney1 = new Attorney(); + attorneyRepository.save(attorney1); + } +} diff --git a/src/main/java/adapter/controller/ControlContainer.java b/src/main/java/adapter/controller/ControlContainer.java index 7466bf85..a0222685 100644 --- a/src/main/java/adapter/controller/ControlContainer.java +++ b/src/main/java/adapter/controller/ControlContainer.java @@ -1,5 +1,10 @@ package adapter.controller; +/** + * This class represents that holds instances of various control classes. + * + * It is responsible for managing different aspects of the application. + */ public class ControlContainer { ClientRegisterControl clientRegisterControl; CloseQuestionControl closeQuestionControl; @@ -10,7 +15,22 @@ public class ControlContainer { UserLoginControl userLoginControl; ViewQuestionControl viewQuestionControl; - public ControlContainer(ClientRegisterControl clientRegisterControl, CloseQuestionControl closeQuestionControl, PostControl postControl, QuestionControl questionControl, RateControl rateControl, SelectQuestionControl selectQuestionControl, UserLoginControl userLoginControl, ViewQuestionControl viewQuestionControl) { + /** + * Constructor to initialize the ControlContainer with instances of various control classes. + * + * @param clientRegisterControl The control class for client registration. + * @param closeQuestionControl The control class for closing questions. + * @param postControl The control class for handling posts. + * @param questionControl The control class for question management. + * @param rateControl The control class for rating questions. + * @param selectQuestionControl The control class for selecting questions. + * @param userLoginControl The control class for user login. + * @param viewQuestionControl The control class for viewing questions. + */ + public ControlContainer(ClientRegisterControl clientRegisterControl, CloseQuestionControl closeQuestionControl, + PostControl postControl, QuestionControl questionControl, RateControl rateControl, + SelectQuestionControl selectQuestionControl, UserLoginControl userLoginControl, + ViewQuestionControl viewQuestionControl) { this.clientRegisterControl = clientRegisterControl; this.closeQuestionControl = closeQuestionControl; this.postControl = postControl; @@ -21,34 +41,74 @@ public ControlContainer(ClientRegisterControl clientRegisterControl, CloseQuesti this.viewQuestionControl = viewQuestionControl; } + /** + * Get the control class for client registration. + * + * @return The client registration control class. + */ public ClientRegisterControl getClientRegisterControl() { return clientRegisterControl; } + /** + * Get the control class for closing questions. + * + * @return The close question control class. + */ public CloseQuestionControl getCloseQuestionControl() { return closeQuestionControl; } + /** + * Get the control class for handling posts. + * + * @return The post control class. + */ public PostControl getPostControl() { return postControl; } + /** + * Get the control class for question management. + * + * @return The question control class. + */ public QuestionControl getQuestionControl() { return questionControl; } + /** + * Get the control class for rating questions. + * + * @return The rate control class. + */ public RateControl getRateControl() { return rateControl; } + /** + * Get the control class for selecting questions. + * + * @return The select question control class. + */ public SelectQuestionControl getSelectQuestionControl() { return selectQuestionControl; } + /** + * Get the control class for user login. + * + * @return The user login control class. + */ public UserLoginControl getUserLoginControl() { return userLoginControl; } + /** + * Get the control class for viewing questions. + * + * @return The view question control class. + */ public ViewQuestionControl getViewQuestionControl() { return viewQuestionControl; } diff --git a/src/main/java/adapter/controller/ViewQuestionControl.java b/src/main/java/adapter/controller/ViewQuestionControl.java index af96c4ed..e3310b60 100644 --- a/src/main/java/adapter/controller/ViewQuestionControl.java +++ b/src/main/java/adapter/controller/ViewQuestionControl.java @@ -4,16 +4,34 @@ import businessrule.inputboundary.ViewInputBoundary; import businessrule.requestmodel.ViewRequestModel; -public class ViewQuestionControl{ +/** + * Controller class responsible for viewing questions. + * + * This class acts as an interface between the presentation layer and the business logic for viewing questions. + * It takes a user's ID as input, creates a request model, and delegates the request to the corresponding input boundary. + * The response model from the input boundary is returned to the caller. + */ +public class ViewQuestionControl { private final ViewInputBoundary viewInputBoundary; + /** + * Constructor to initialize the ViewQuestionControl with the corresponding input boundary. + * + * @param viewInputBoundary The input boundary for viewing questions. + */ public ViewQuestionControl(ViewInputBoundary viewInputBoundary) { this.viewInputBoundary = viewInputBoundary; } - public ViewResponseModel viewQuestion(int userId){ + /** + * View a question based on the user's ID. + * + * @param userId The ID of the user requesting to view the question. + * @return A response model containing the information about the viewed question. + */ + public ViewResponseModel viewQuestion(int userId) { ViewRequestModel viewRequestModel = new ViewRequestModel(userId); return viewInputBoundary.viewQuestion(viewRequestModel); } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/gateway/AttorneyGateway.java b/src/main/java/businessrule/gateway/AttorneyGateway.java index ba605347..462cb5c6 100644 --- a/src/main/java/businessrule/gateway/AttorneyGateway.java +++ b/src/main/java/businessrule/gateway/AttorneyGateway.java @@ -1,17 +1,33 @@ package businessrule.gateway; -import entity.Attorney; -import entity.User; import entity.Attorney; import entity.Question; -import java.util.List; +/** + * This interface provides methods for retrieving an attorney, clearing recommendations, and + * adding recommendations for questions. + */ public interface AttorneyGateway extends UserGateway { + /** + * Get an attorney by their ID. + * + * @param id The ID of the attorney to retrieve. + * @return The attorney object associated with the provided ID. + */ @Override Attorney get(int id); - public void clearAllRecommendations(); + /** + * Clear all recommendations associated with attorneys. + */ + void clearAllRecommendations(); - public void addRecommendation (int Userid, Question question); -} + /** + * Add a recommendation for a question to an attorney. + * + * @param userId The ID of the user (attorney) receiving the recommendation. + * @param question The question to be recommended. + */ + void addRecommendation(int userId, Question question); +} \ No newline at end of file diff --git a/src/main/java/businessrule/gateway/ClientGateway.java b/src/main/java/businessrule/gateway/ClientGateway.java index 43f44f60..9a08b773 100644 --- a/src/main/java/businessrule/gateway/ClientGateway.java +++ b/src/main/java/businessrule/gateway/ClientGateway.java @@ -1,11 +1,19 @@ package businessrule.gateway; import entity.Client; -import entity.User; +/** + * This interface provides a method for retrieving a client by their ID. + */ public interface ClientGateway extends UserGateway { + /** + * Get a client by their ID. + * + * @param id The ID of the client to retrieve. + * @return The client object associated with the provided ID. + */ @Override Client get(int id); -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/gateway/GenericGateway.java b/src/main/java/businessrule/gateway/GenericGateway.java index e9785bf9..75ac68df 100644 --- a/src/main/java/businessrule/gateway/GenericGateway.java +++ b/src/main/java/businessrule/gateway/GenericGateway.java @@ -2,13 +2,52 @@ import java.util.List; +/** + * This interface provides a generic gateway for accessing data and performing common operations. + * + * @param The type of entity that this gateway will work with. + */ public interface GenericGateway { + /** + * Save an entity to the data source. + * + * @param entity The entity to be saved. + */ void save(T entity); + + /** + * Get an entity by its ID. + * + * @param id The ID of the entity to retrieve. + * @return The entity associated with the provided ID. + */ Object get(int id); + + /** + * Check if an entity with a given ID exists. + * + * @param id The ID of the entity to check. + * @return True if an entity with the provided ID exists, false otherwise. + */ boolean existsById(int id); + + /** + * Delete an entity by its ID. + * + * @param id The ID of the entity to delete. + */ void delete(int id); + + /** + * Delete all entities. + */ void deleteAll(); - List getAll(); -} + /** + * Get a list of all entities. + * + * @return A list containing all entities. + */ + List getAll(); +} \ No newline at end of file diff --git a/src/main/java/businessrule/gateway/PostGateway.java b/src/main/java/businessrule/gateway/PostGateway.java index 4acae53a..acdca2d6 100644 --- a/src/main/java/businessrule/gateway/PostGateway.java +++ b/src/main/java/businessrule/gateway/PostGateway.java @@ -1,12 +1,19 @@ package businessrule.gateway; import entity.Post; -import entity.Question; -import entity.User; -public interface PostGateway extends GenericGateway{ +/** + * This interface provides a method for retrieving a post by its ID. + */ +public interface PostGateway extends GenericGateway { + /** + * Get a post by its ID. + * + * @param id The ID of the post to retrieve. + * @return The post object associated with the provided ID. + */ @Override Post get(int id); -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/gateway/QuestionGateway.java b/src/main/java/businessrule/gateway/QuestionGateway.java index 9ba74b89..5f9cb640 100644 --- a/src/main/java/businessrule/gateway/QuestionGateway.java +++ b/src/main/java/businessrule/gateway/QuestionGateway.java @@ -2,21 +2,92 @@ import entity.Post; import entity.Question; -import entity.User; import java.time.LocalDate; import java.util.List; -public interface QuestionGateway extends GenericGateway{ +/** + * This interface provides methods for retrieving questions, managing question status and attributes, + * and obtaining posts. + */ +public interface QuestionGateway extends GenericGateway { + + /** + * Get a list of questions that have not been taken by an attorney. + * + * @return A list of questions not yet taken by any attorney. + */ List getNotTakenQuestion(); + + /** + * Get a list of questions that are not closed. + * + * @return A list of questions that are still open and not closed. + */ List getNotClosedQuestion(); + + /** + * Get all posts associated with a specific question. + * + * @param questionId The ID of the question to retrieve posts for. + * @return A list of posts associated with the specified question. + */ List getAllPostOfQuestion(int questionId); - void updateIsTaken(int questionId, boolean iaTaken); + + /** + * Update the "isTaken" status of a question. + * + * @param questionId The ID of the question to update. + * @param isTaken The new "isTaken" status. + */ + void updateIsTaken(int questionId, boolean isTaken); + + /** + * Update the attorney who took a specific question. + * + * @param questionId The ID of the question to update. + * @param attorneyId The ID of the attorney who took the question. + */ void updateTakenByAttorney(int questionId, int attorneyId); + + /** + * Update the "isClose" status of a question. + * + * @param questionId The ID of the question to update. + * @param isClose The new "isClose" status. + */ void updateIsClose(int questionId, boolean isClose); + + /** + * Update the rating of a question. + * + * @param questionId The ID of the question to update. + * @param rating The new rating value. + */ void updateRating(int questionId, int rating); + + /** + * Update the time when a question was taken. + * + * @param questionId The ID of the question to update. + * @param time The new time when the question was taken. + */ void updateTakenAt(int questionId, LocalDate time); + + /** + * Update the posts associated with a question. + * + * @param id The ID of the question to update. + * @param post The post to add to the question's posts. + */ void updatePosts(int id, Post post); + + /** + * Get a question by its ID. + * + * @param id The ID of the question to retrieve. + * @return The question object associated with the provided ID. + */ @Override Question get(int id); -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/gateway/UserGateway.java b/src/main/java/businessrule/gateway/UserGateway.java index 9a56ee0f..655aa2dc 100644 --- a/src/main/java/businessrule/gateway/UserGateway.java +++ b/src/main/java/businessrule/gateway/UserGateway.java @@ -3,9 +3,36 @@ import entity.Question; import entity.User; -public interface UserGateway extends GenericGateway{ +/** + * This interface provides methods for checking if a user exists by name, updating a user's question list, + * and retrieving a user by their ID. + * + * @param The type of user entity. + */ +public interface UserGateway extends GenericGateway { + + /** + * Check if a user with the specified name exists. + * + * @param inputUserName The name of the user to check. + * @return True if a user with the provided name exists, false otherwise. + */ boolean existsByName(String inputUserName); + + /** + * Update the question list of a user. + * + * @param id The ID of the user to update. + * @param question The question to add to the user's question list. + */ void updateQuestionList(int id, Question question); + + /** + * Get a user by their ID. + * + * @param id The ID of the user to retrieve. + * @return The user object associated with the provided ID. + */ @Override User get(int id); -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/gateway/UserGatewayFactory.java b/src/main/java/businessrule/gateway/UserGatewayFactory.java index 9954de98..22eeeea5 100644 --- a/src/main/java/businessrule/gateway/UserGatewayFactory.java +++ b/src/main/java/businessrule/gateway/UserGatewayFactory.java @@ -3,12 +3,24 @@ import driver.database.AttorneyRepository; import driver.database.ClientRepository; - import driver.screen.ApplicationException; +/** + * This class represents creating appropriate UserGateway instances based on whether + * the user is a client or an attorney. + * It uses the provided user ID to determine the user type and creates a corresponding + * UserGateway instance accordingly. + */ public class UserGatewayFactory { - public UserGateway createUserGateway(int userId) { + /** + * Create a UserGateway instance based on the user ID. + * + * @param userId The ID of the user for whom to create the UserGateway instance. + * @return A UserGateway instance that corresponds to the user type. + * @throws ApplicationException If the user ID is not valid or if an error occurs during gateway creation. + */ + public UserGateway createUserGateway(int userId) throws ApplicationException { try { UserGateway userGateway; if (isClient(userId)) { @@ -21,6 +33,14 @@ public UserGateway createUserGateway(int userId) { throw new ApplicationException("UserId does not exist"); } } + + /** + * Check if a user with the provided ID is a client. + * + * @param userId The ID of the user to check. + * @return True if the user is a client, false if the user is an attorney. + * @throws ApplicationException If the user ID is not valid. + */ private static boolean isClient(int userId) throws ApplicationException { if (Integer.toString(userId).startsWith("1")) { return false; @@ -30,4 +50,4 @@ private static boolean isClient(int userId) throws ApplicationException { throw new ApplicationException("UserId does not exist"); } } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/inputboundary/ClientRegisterInputBoundary.java b/src/main/java/businessrule/inputboundary/ClientRegisterInputBoundary.java index 251d83d9..6376c891 100644 --- a/src/main/java/businessrule/inputboundary/ClientRegisterInputBoundary.java +++ b/src/main/java/businessrule/inputboundary/ClientRegisterInputBoundary.java @@ -3,6 +3,16 @@ import businessrule.requestmodel.ClientRegisterRequestModel; import businessrule.responsemodel.RegisterResponseModel; +/** + * This interface provides a method for creating a client registration based on the provided request model. + */ public interface ClientRegisterInputBoundary { + + /** + * Create a client registration based on the provided request model. + * + * @param requestModel The request model containing the necessary information for client registration. + * @return A response model indicating the result of the client registration. + */ RegisterResponseModel create(ClientRegisterRequestModel requestModel); -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/inputboundary/CloseInputBoundary.java b/src/main/java/businessrule/inputboundary/CloseInputBoundary.java index 870db57d..77919e73 100644 --- a/src/main/java/businessrule/inputboundary/CloseInputBoundary.java +++ b/src/main/java/businessrule/inputboundary/CloseInputBoundary.java @@ -1,9 +1,18 @@ package businessrule.inputboundary; -import businessrule.outputboundary.HomePageOutputBoundary; import businessrule.requestmodel.CloseRequestModel; import businessrule.responsemodel.HomePageResponseModel; +/** + * This interface provides a method for closing a question based on the provided close request model. + */ public interface CloseInputBoundary { + + /** + * Close a question based on the provided close request model. + * + * @param closeRequestModel The request model containing the necessary information for closing the question. + * @return A response model indicating the result of closing the question, typically for updating the home page. + */ HomePageResponseModel closeQuestion(CloseRequestModel closeRequestModel); -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/inputboundary/PostInputBoundary.java b/src/main/java/businessrule/inputboundary/PostInputBoundary.java index 2926c8d5..c0236040 100644 --- a/src/main/java/businessrule/inputboundary/PostInputBoundary.java +++ b/src/main/java/businessrule/inputboundary/PostInputBoundary.java @@ -3,6 +3,16 @@ import businessrule.requestmodel.PostRequestModel; import businessrule.responsemodel.HomePageResponseModel; +/** + * This interface provides a method for creating a post based on the provided post request model. + */ public interface PostInputBoundary { + + /** + * Create a post based on the provided post request model. + * + * @param postRequestModel The request model containing the necessary information for post creation. + * @return A response model indicating the result of post creation, typically for updating the home page. + */ HomePageResponseModel createPost(PostRequestModel postRequestModel); -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/inputboundary/QuestionInputBoundary.java b/src/main/java/businessrule/inputboundary/QuestionInputBoundary.java index ad8d73a0..01a6408d 100644 --- a/src/main/java/businessrule/inputboundary/QuestionInputBoundary.java +++ b/src/main/java/businessrule/inputboundary/QuestionInputBoundary.java @@ -3,6 +3,16 @@ import businessrule.responsemodel.TheQuestionResponseModel; import businessrule.requestmodel.QuestionRequestModel; +/** + * This interface provides a method for creating a question based on the provided question request model. + */ public interface QuestionInputBoundary { + + /** + * Create a question based on the provided question request model. + * + * @param questionRequestModel The request model containing the necessary information for question creation. + * @return A response model containing the information about the created question. + */ TheQuestionResponseModel createQuestion(QuestionRequestModel questionRequestModel); -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/inputboundary/RateInputBoundary.java b/src/main/java/businessrule/inputboundary/RateInputBoundary.java index c4068d86..5f472dea 100644 --- a/src/main/java/businessrule/inputboundary/RateInputBoundary.java +++ b/src/main/java/businessrule/inputboundary/RateInputBoundary.java @@ -3,8 +3,17 @@ import businessrule.requestmodel.RateRequestModel; import businessrule.responsemodel.HomePageResponseModel; +/** + * This interface provides a method for rating an answer based on the provided rate request model. + */ public interface RateInputBoundary { + /** + * Rate an answer based on the provided rate request model. + * + * @param rateRequestModel The request model containing the necessary information for rating an answer. + * @return A response model indicating the result of rating an answer, typically for updating the home page. + */ HomePageResponseModel rateAnswer(RateRequestModel rateRequestModel); -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/inputboundary/SelectInputBoundary.java b/src/main/java/businessrule/inputboundary/SelectInputBoundary.java index 8d5cd267..6e6403e7 100644 --- a/src/main/java/businessrule/inputboundary/SelectInputBoundary.java +++ b/src/main/java/businessrule/inputboundary/SelectInputBoundary.java @@ -3,6 +3,16 @@ import businessrule.responsemodel.TheQuestionResponseModel; import businessrule.requestmodel.SelectRequestModel; +/** + * This interface provides a method for selecting a question based on the provided select request model. + */ public interface SelectInputBoundary { + + /** + * Select a question based on the provided select request model. + * + * @param selectRequestModel The request model containing the necessary information for selecting a question. + * @return A response model containing the information about the selected question. + */ TheQuestionResponseModel selectQuestion(SelectRequestModel selectRequestModel); -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/inputboundary/UserLoginInputBoundary.java b/src/main/java/businessrule/inputboundary/UserLoginInputBoundary.java index 0bdc6b97..d8874ef6 100644 --- a/src/main/java/businessrule/inputboundary/UserLoginInputBoundary.java +++ b/src/main/java/businessrule/inputboundary/UserLoginInputBoundary.java @@ -3,6 +3,16 @@ import businessrule.requestmodel.UserLoginRequestModel; import businessrule.responsemodel.HomePageResponseModel; +/** + * This interface provides a method for authenticating user credentials based on the provided login request model. + */ public interface UserLoginInputBoundary { + + /** + * Authenticate user credentials based on the provided login request model. + * + * @param requestModel The request model containing the user's login credentials. + * @return A response model indicating the result of the login attempt, typically for updating the home page. + */ HomePageResponseModel login(UserLoginRequestModel requestModel); -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/inputboundary/ViewInputBoundary.java b/src/main/java/businessrule/inputboundary/ViewInputBoundary.java index ccaf032c..cfba467d 100644 --- a/src/main/java/businessrule/inputboundary/ViewInputBoundary.java +++ b/src/main/java/businessrule/inputboundary/ViewInputBoundary.java @@ -3,6 +3,16 @@ import businessrule.responsemodel.ViewResponseModel; import businessrule.requestmodel.ViewRequestModel; +/** + * This interface provides a method for viewing a question based on the provided view request model. + */ public interface ViewInputBoundary { + + /** + * View a question based on the provided view request model. + * + * @param viewRequestModel The request model containing the necessary information for viewing a question. + * @return A response model containing the information about the viewed question. + */ ViewResponseModel viewQuestion(ViewRequestModel viewRequestModel); -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/outputboundary/HomePageOutputBoundary.java b/src/main/java/businessrule/outputboundary/HomePageOutputBoundary.java index a256d41c..a22c5d93 100644 --- a/src/main/java/businessrule/outputboundary/HomePageOutputBoundary.java +++ b/src/main/java/businessrule/outputboundary/HomePageOutputBoundary.java @@ -3,8 +3,32 @@ import adapter.controller.ControlContainer; import businessrule.responsemodel.HomePageResponseModel; +/** + * This interface provides methods for setting the control container, preparing failure responses, + * and preparing success responses. + */ public interface HomePageOutputBoundary { + + /** + * Set the control container for handling home page responses. + * + * @param controlContainer The control container used for handling responses. + */ void setControlContainer(ControlContainer controlContainer); + + /** + * Prepare a failure response for the home page. + * + * @param msg The message indicating the reason for the failure. + * @return A prepared home page response model indicating the failure. + */ HomePageResponseModel prepareFail(String msg); + + /** + * Prepare a success response for the home page. + * + * @param response The response model to prepare as a success response. + * @return A prepared home page response model indicating the success. + */ HomePageResponseModel prepareSuccess(HomePageResponseModel response); -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/outputboundary/RegisterOutputBoundary.java b/src/main/java/businessrule/outputboundary/RegisterOutputBoundary.java index 9c3db9d0..23241dcd 100644 --- a/src/main/java/businessrule/outputboundary/RegisterOutputBoundary.java +++ b/src/main/java/businessrule/outputboundary/RegisterOutputBoundary.java @@ -3,8 +3,32 @@ import adapter.controller.ControlContainer; import businessrule.responsemodel.RegisterResponseModel; +/** + * This interface provides methods for setting the control container, preparing success responses, + * and preparing failure responses. + */ public interface RegisterOutputBoundary { + + /** + * Set the control container for handling registration responses. + * + * @param controlContainer The control container used for handling responses. + */ void setControlContainer(ControlContainer controlContainer); + + /** + * Prepare a success response for registration. + * + * @param msg The message indicating the success. + * @return A prepared registration response model indicating the success. + */ RegisterResponseModel prepareSuccess(String msg); + + /** + * Prepare a failure response for registration. + * + * @param msg The message indicating the reason for the failure. + * @return A prepared registration response model indicating the failure. + */ RegisterResponseModel prepareFail(String msg); -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/outputboundary/TheQuestionOutputBoundary.java b/src/main/java/businessrule/outputboundary/TheQuestionOutputBoundary.java index 2d6db51d..f6e29420 100644 --- a/src/main/java/businessrule/outputboundary/TheQuestionOutputBoundary.java +++ b/src/main/java/businessrule/outputboundary/TheQuestionOutputBoundary.java @@ -3,8 +3,32 @@ import adapter.controller.ControlContainer; import businessrule.responsemodel.TheQuestionResponseModel; +/** + * This interface provides methods for setting the control container, preparing failure responses, + * and preparing success responses. + */ public interface TheQuestionOutputBoundary { + + /** + * Set the control container for handling question responses. + * + * @param controlContainer The control container used for handling responses. + */ void setControlContainer(ControlContainer controlContainer); + + /** + * Prepare a failure response for a question. + * + * @param msg The message indicating the reason for the failure. + * @return A prepared question response model indicating the failure. + */ TheQuestionResponseModel prepareFail(String msg); + + /** + * Prepare a success response for a question. + * + * @param response The response model to prepare as a success response. + * @return A prepared question response model indicating the success. + */ TheQuestionResponseModel prepareSuccess(TheQuestionResponseModel response); -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/outputboundary/ViewOutputBoundary.java b/src/main/java/businessrule/outputboundary/ViewOutputBoundary.java index 320e32cb..397ebf8d 100644 --- a/src/main/java/businessrule/outputboundary/ViewOutputBoundary.java +++ b/src/main/java/businessrule/outputboundary/ViewOutputBoundary.java @@ -3,8 +3,32 @@ import adapter.controller.ControlContainer; import businessrule.responsemodel.ViewResponseModel; +/** + * This interface provides methods for setting the control container, preparing failure responses, + * and preparing success responses. + */ public interface ViewOutputBoundary { + + /** + * Set the control container for handling view responses. + * + * @param controlContainer The control container used for handling responses. + */ void setControlContainer(ControlContainer controlContainer); + + /** + * Prepare a failure response for a view. + * + * @param msg The message indicating the reason for the failure. + * @return A prepared view response model indicating the failure. + */ ViewResponseModel prepareFail(String msg); + + /** + * Prepare a success response for a view. + * + * @param response The response model to prepare as a success response. + * @return A prepared view response model indicating the success. + */ ViewResponseModel prepareSuccess(ViewResponseModel response); -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/responsemodel/TheQuestionResponseModel.java b/src/main/java/businessrule/responsemodel/TheQuestionResponseModel.java index 73991acc..4cd8701a 100644 --- a/src/main/java/businessrule/responsemodel/TheQuestionResponseModel.java +++ b/src/main/java/businessrule/responsemodel/TheQuestionResponseModel.java @@ -5,7 +5,12 @@ import java.time.LocalDate; import java.util.Map; -public class TheQuestionResponseModel{ +/** + * This class represents a question with detailed informatio. + * It is including its user, title, type, deadline, closure status, and associated posts. + */ +public class TheQuestionResponseModel { + private final int userId; private final int questionId; private final String userName; @@ -26,31 +31,75 @@ public TheQuestionResponseModel(int userId, int questionId, String userName, Str this.postMap = postMap; } + /** + * Get the user ID associated with the question. + * + * @return The user ID. + */ public int getUserId() { return userId; } - public int getQuestionId() {return questionId;} + /** + * Get the question ID. + * + * @return The question ID. + */ + public int getQuestionId() { + return questionId; + } + /** + * Get the user name associated with the question. + * + * @return The user name. + */ public String getUserName() { return userName; } + /** + * Get the title of the question. + * + * @return The question title. + */ public String getTitle() { return title; } + /** + * Get the type of the question. + * + * @return The question type. + */ public String getType() { return type; } + /** + * Get the deadline of the question. + * + * @return The question deadline. + */ public LocalDate getDeadline() { return deadline; } - public boolean isClose() {return isClose;} + /** + * Check if the question is closed. + * + * @return True if the question is closed, false otherwise. + */ + public boolean isClose() { + return isClose; + } + /** + * Get the map of associated posts with their display formatting. + * + * @return The map of post IDs and their associated display formatting. + */ public Map getPostMap() { return postMap; } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/AskQuestionInteractor.java b/src/main/java/businessrule/usecase/AskQuestionInteractor.java index 78d563d7..f34051e9 100644 --- a/src/main/java/businessrule/usecase/AskQuestionInteractor.java +++ b/src/main/java/businessrule/usecase/AskQuestionInteractor.java @@ -15,12 +15,26 @@ import java.util.HashMap; import java.util.Map; +/** + * This class represents the interactor responsible for asking a new question. + * + * This interactor validates input, generates a unique question ID, creates a question entity, + * updates relevant gateways, and constructs the response model. + */ public class AskQuestionInteractor implements QuestionInputBoundary { final QuestionGateway questionGateway; final TheQuestionOutputBoundary theQuestionOutputBoundary; final QuestionFactory questionFactory; final ClientGateway clientGateway; + /** + * Constructor for AskQuestionInteractor. + * + * @param questionGateway The gateway for managing question entities. + * @param theQuestionOutputBoundary The output boundary for preparing question response models. + * @param questionFactory The factory for creating question entities. + * @param clientGateway The gateway for managing client entities. + */ public AskQuestionInteractor(QuestionGateway questionGateway, TheQuestionOutputBoundary theQuestionOutputBoundary, QuestionFactory questionFactory, ClientGateway clientGateway) { this.questionGateway = questionGateway; this.theQuestionOutputBoundary = theQuestionOutputBoundary; @@ -28,6 +42,12 @@ public AskQuestionInteractor(QuestionGateway questionGateway, TheQuestionOutputB this.clientGateway = clientGateway; } + /** + * Create a new question based on the provided request model. + * + * @param questionRequestModel The request model containing question details. + * @return The response model for the newly created question. + */ public TheQuestionResponseModel createQuestion(QuestionRequestModel questionRequestModel){ // validate input @@ -59,4 +79,4 @@ public TheQuestionResponseModel createQuestion(QuestionRequestModel questionRequ TheQuestionResponseModel theQuestionResponseModel = new TheQuestionResponseModel(questionRequestModel.getAskedByClient(), question.getQuestionId(), askedBy.getUserName(), question.getTitle(), question.getType(), question.getLegalDeadline(),false, postMap); return theQuestionOutputBoundary.prepareSuccess(theQuestionResponseModel); } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/AttorneyRecommendInteractor.java b/src/main/java/businessrule/usecase/AttorneyRecommendInteractor.java index eb675b48..2edb49b5 100644 --- a/src/main/java/businessrule/usecase/AttorneyRecommendInteractor.java +++ b/src/main/java/businessrule/usecase/AttorneyRecommendInteractor.java @@ -16,23 +16,47 @@ import java.util.List; import java.util.Set; +/** + * This class represents the interactor responsible for recommending questions to an attorney. + * + * This interactor fetches recommended questions for an attorney based on their profile and preferences. + */ public class AttorneyRecommendInteractor extends ViewQuestionInteractorBase { - private final AttorneyGateway attorneyGateway; + private final AttorneyGateway attorneyGateway; + /** + * Constructor for AttorneyRecommendInteractor. + * + * @param viewOutputBoundary The output boundary for preparing view response models. + * @param questionGateway The gateway for managing question entities. + * @param attorneyGateway The gateway for managing attorney entities. + */ public AttorneyRecommendInteractor(ViewOutputBoundary viewOutputBoundary, QuestionGateway questionGateway, AttorneyGateway attorneyGateway) { super(viewOutputBoundary, questionGateway); this.attorneyGateway = attorneyGateway; } + /** + * Fetch recommended questions for an attorney. + * + * @param viewRequestModel The request model containing the attorney's user ID. + * @return The list of recommended questions. + */ @Override protected List fetchQuestions(ViewRequestModel viewRequestModel) { Attorney attorney = (Attorney) fetchUser(viewRequestModel); return attorney.getRecommendations(); } + /** + * Fetch the attorney based on the provided user ID. + * + * @param viewRequestModel The request model containing the attorney's user ID. + * @return The fetched attorney entity. + */ @Override protected User fetchUser(ViewRequestModel viewRequestModel) { int attorneyId = viewRequestModel.getUserId(); return attorneyGateway.get(attorneyId); } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/BrowseQuestionInteractor.java b/src/main/java/businessrule/usecase/BrowseQuestionInteractor.java index 6da41304..6b5a35c2 100644 --- a/src/main/java/businessrule/usecase/BrowseQuestionInteractor.java +++ b/src/main/java/businessrule/usecase/BrowseQuestionInteractor.java @@ -12,14 +12,32 @@ import java.util.List; import java.util.Set; +/** + * This class represents the interactor responsible for browsing available questions. + * + * This interactor fetches a list of available questions that have not been taken and are not closed. + */ public class BrowseQuestionInteractor extends ViewQuestionInteractorBase { final AttorneyGateway attorneyGateway; + /** + * Constructor for BrowseQuestionInteractor. + * + * @param viewOutputBoundary The output boundary for preparing view response models. + * @param questionGateway The gateway for managing question entities. + * @param attorneyGateway The gateway for managing attorney entities. + */ public BrowseQuestionInteractor(ViewOutputBoundary viewOutputBoundary, QuestionGateway questionGateway, AttorneyGateway attorneyGateway) { super(viewOutputBoundary, questionGateway); this.attorneyGateway = attorneyGateway; } + /** + * Fetch available questions that have not been taken and are not closed. + * + * @param viewRequestModel The request model containing user details. + * @return The list of available questions. + */ @Override protected List fetchQuestions(ViewRequestModel viewRequestModel) { List notTakenList = questionGateway.getNotTakenQuestion(); @@ -30,9 +48,15 @@ protected List fetchQuestions(ViewRequestModel viewRequestModel) { return new ArrayList<>(notCloseSet); } + /** + * Fetch the user based on the provided user ID. + * + * @param viewRequestModel The request model containing the user ID. + * @return The fetched user entity. + */ @Override protected User fetchUser(ViewRequestModel viewRequestModel) { int attorneyId = viewRequestModel.getUserId(); return attorneyGateway.get(attorneyId); } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/ClientRegisterInteractor.java b/src/main/java/businessrule/usecase/ClientRegisterInteractor.java index f75910e0..404e4aad 100644 --- a/src/main/java/businessrule/usecase/ClientRegisterInteractor.java +++ b/src/main/java/businessrule/usecase/ClientRegisterInteractor.java @@ -1,6 +1,5 @@ package businessrule.usecase; - import businessrule.gateway.ClientGateway; import businessrule.inputboundary.ClientRegisterInputBoundary; import businessrule.outputboundary.RegisterOutputBoundary; @@ -11,17 +10,36 @@ import businessrule.usecase.util.CredentialChecker; import businessrule.usecase.util.RandomNumberGenerator; +/** + * This class represents the interactor responsible for handling client registration. + * + * This interactor validates input data, generates a unique client ID, creates a new client entity, + * and prepares the response for client registration. + */ public class ClientRegisterInteractor implements ClientRegisterInputBoundary { final ClientGateway clientGateway; final RegisterOutputBoundary outputBoundary; final ClientFactory clientFactory; + /** + * Constructor for ClientRegisterInteractor. + * + * @param clientGateway The gateway for managing client entities. + * @param outputBoundary The output boundary for preparing registration response models. + * @param clientFactory The factory for creating client entities. + */ public ClientRegisterInteractor(ClientGateway clientGateway, RegisterOutputBoundary outputBoundary, ClientFactory clientFactory) { this.clientGateway = clientGateway; this.outputBoundary = outputBoundary; this.clientFactory = clientFactory; } + /** + * Create a new client based on the provided request model. + * + * @param requestModel The request model containing client registration details. + * @return The response model for the client registration process. + */ @Override public RegisterResponseModel create(ClientRegisterRequestModel requestModel){ // prepare input data @@ -43,7 +61,7 @@ public RegisterResponseModel create(ClientRegisterRequestModel requestModel){ if (clientGateway.existsByName(inputUserName)) { return outputBoundary.prepareFail("User name already exists"); } else if (!inputPassword1.equals(inputPassword2)) { - return outputBoundary.prepareFail("Passwords does not match"); + return outputBoundary.prepareFail("Passwords do not match"); } else if (inputPassword1.length() < 8) { return outputBoundary.prepareFail("Password is less than 8 characters"); } else if (!checker.checkEmail(inputEmail)) { @@ -54,7 +72,7 @@ public RegisterResponseModel create(ClientRegisterRequestModel requestModel){ return outputBoundary.prepareFail("Postal Code is invalid"); } - // create user id + // create user ID RandomNumberGenerator generator = new RandomNumberGenerator(); int randomUserId = generator.generateClientId(8); boolean exists = clientGateway.existsById(randomUserId); diff --git a/src/main/java/businessrule/usecase/RateInteractor.java b/src/main/java/businessrule/usecase/RateInteractor.java index eca8b565..b391fb12 100644 --- a/src/main/java/businessrule/usecase/RateInteractor.java +++ b/src/main/java/businessrule/usecase/RateInteractor.java @@ -12,18 +12,36 @@ import entity.Question; import entity.User; +/** + * This class represents the interactor responsible for rating an answer. + * + * This interactor handles the process of rating an answer given by a client, updating the rating of the associated question. + */ public class RateInteractor implements RateInputBoundary { private final QuestionGateway questionGateway; private final HomePageOutputBoundary homePageOutputBoundary; private final ClientGateway clientGateway; + /** + * Constructor for RateInteractor. + * + * @param questionGateway The gateway for managing question entities. + * @param homePageOutputBoundary The output boundary for preparing home page response models. + * @param clientGateway The gateway for managing client entities. + */ public RateInteractor(QuestionGateway questionGateway, HomePageOutputBoundary homePageOutputBoundary, ClientGateway clientGateway) { this.questionGateway = questionGateway; this.homePageOutputBoundary = homePageOutputBoundary; this.clientGateway = clientGateway; } + /** + * Rate an answer and update the associated question's rating. + * + * @param rateRequestModel The request model containing rating details. + * @return The response model for the home page. + */ @Override public HomePageResponseModel rateAnswer(RateRequestModel rateRequestModel) { int rating = rateRequestModel.getRating(); @@ -42,4 +60,4 @@ public HomePageResponseModel rateAnswer(RateRequestModel rateRequestModel) { return homePageOutputBoundary.prepareFail("You cannot rate this question!"); } } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/ReplyInteractor.java b/src/main/java/businessrule/usecase/ReplyInteractor.java index ecbc453e..c1e58bf8 100644 --- a/src/main/java/businessrule/usecase/ReplyInteractor.java +++ b/src/main/java/businessrule/usecase/ReplyInteractor.java @@ -17,7 +17,7 @@ import java.time.LocalDate; /** - * This class represents representing the use case for creating a new post (reply) in response to a question. + * This class represents the use case for creating a new post (reply) in response to a question. */ public class ReplyInteractor implements PostInputBoundary { diff --git a/src/main/java/businessrule/usecase/SelectQuestionInteractor.java b/src/main/java/businessrule/usecase/SelectQuestionInteractor.java index 75941d36..ec0dc39b 100644 --- a/src/main/java/businessrule/usecase/SelectQuestionInteractor.java +++ b/src/main/java/businessrule/usecase/SelectQuestionInteractor.java @@ -13,11 +13,25 @@ import businessrule.gateway.UserGatewayFactory; import java.util.Map; +/** + * This class represents the interactor responsible for selecting a question. + * + * This interactor handles the process of selecting a question based on user input and + * preparing and formatting the response model. + */ public class SelectQuestionInteractor implements SelectInputBoundary { + final QuestionGateway questionGateway; final TheQuestionOutputBoundary theQuestionOutputBoundary; final UserGatewayFactory userGatewayFactory; + /** + * Constructor for SelectQuestionInteractor. + * + * @param questionGateway The gateway for managing question entities. + * @param theQuestionOutputBoundary The output boundary for preparing question response models. + * @param userGatewayFactory The factory for creating user gateways. + */ public SelectQuestionInteractor(QuestionGateway questionGateway, TheQuestionOutputBoundary theQuestionOutputBoundary, UserGatewayFactory userGatewayFactory) { this.questionGateway = questionGateway; @@ -25,20 +39,22 @@ public SelectQuestionInteractor(QuestionGateway questionGateway, TheQuestionOutp this.userGatewayFactory = userGatewayFactory; } + /** + * Select a question and prepare the response model. + * + * @param selectRequestModel The request model containing selection details. + * @return The response model for the selected question. + */ @Override public TheQuestionResponseModel selectQuestion(SelectRequestModel selectRequestModel) { - // get input data int userId = selectRequestModel.getUserId(); int questionId = selectRequestModel.getQuestionId(); - // use gateway factory to retrieve the correct type of repo UserGateway userGateway = userGatewayFactory.createUserGateway(userId); User user = userGateway.get(userId); - // get question Question question = questionGateway.get(questionId); - // handle select question logic and prepare response model boolean isQuestionSelectable = user.isQuestionSelectable(question); if (isQuestionSelectable) { PostMapConstructor postMapConstructor = new PostMapConstructor(userGatewayFactory); @@ -49,6 +65,4 @@ public TheQuestionResponseModel selectQuestion(SelectRequestModel selectRequestM return theQuestionOutputBoundary.prepareFail("This question is not accessible."); } } - - -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/UserLoginInteractor.java b/src/main/java/businessrule/usecase/UserLoginInteractor.java index 94d1d9a7..0336e885 100644 --- a/src/main/java/businessrule/usecase/UserLoginInteractor.java +++ b/src/main/java/businessrule/usecase/UserLoginInteractor.java @@ -11,22 +11,39 @@ import java.time.LocalDateTime; -public class UserLoginInteractor implements UserLoginInputBoundary{ +/** + * This class represents the interactor responsible for handling user login. + * + * This interactor handles the process of authenticating user login credentials,retrieving user information, + * and preparing the appropriate response model. + */ +public class UserLoginInteractor implements UserLoginInputBoundary { + final UserGatewayFactory userGatewayFactory; final HomePageOutputBoundary outputBoundary; + /** + * Constructor for UserLoginInteractor. + * + * @param userGatewayFactory The factory for creating user gateways. + * @param outputBoundary The output boundary for preparing home page response models. + */ public UserLoginInteractor(UserGatewayFactory userGatewayFactory, HomePageOutputBoundary outputBoundary) { this.userGatewayFactory = userGatewayFactory; this.outputBoundary = outputBoundary; } + /** + * Authenticate user login and prepare the response model. + * + * @param requestModel The request model containing user login details. + * @return The response model for the home page. + */ @Override public HomePageResponseModel login(UserLoginRequestModel requestModel) { - // get input data int inputUserId = requestModel.getUserId(); String inputPassword = requestModel.getPassword(); - // use user gateway factory to retrieve the correct type of repo UserGateway userGateway; try { userGateway = userGatewayFactory.createUserGateway(inputUserId); @@ -34,7 +51,6 @@ public HomePageResponseModel login(UserLoginRequestModel requestModel) { return outputBoundary.prepareFail("User ID does not exist"); } - // handle login logic if (!userGateway.existsById(inputUserId)) { return outputBoundary.prepareFail("User ID does not exist"); } @@ -44,16 +60,15 @@ public HomePageResponseModel login(UserLoginRequestModel requestModel) { return outputBoundary.prepareFail("Password is incorrect"); } - // construct response model String userType; User user = userGateway.get(inputUserId); - if (user.isClient()){ + if (user.isClient()) { userType = "Client"; - } else{ + } else { userType = "Attorney"; } HomePageResponseModel accountResponseModel = new HomePageResponseModel(inputUserId, userGateway.get(inputUserId).getUserName(), userType); return outputBoundary.prepareSuccess(accountResponseModel); } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/ViewQuestionInteractor.java b/src/main/java/businessrule/usecase/ViewQuestionInteractor.java index cef403b5..03a3e153 100644 --- a/src/main/java/businessrule/usecase/ViewQuestionInteractor.java +++ b/src/main/java/businessrule/usecase/ViewQuestionInteractor.java @@ -13,26 +13,50 @@ import java.util.List; import java.util.Map; -public class ViewQuestionInteractor extends ViewQuestionInteractorBase{ +/** + * This class represents the interactor responsible for viewing questions. + * + * This interactor handles the process of fetching and displaying questions based on user input + * and preparing the appropriate response model. + */ +public class ViewQuestionInteractor extends ViewQuestionInteractorBase { final UserGatewayFactory userGatewayFactory; + /** + * Constructor for ViewQuestionInteractor. + * + * @param questionGateway The gateway for managing question entities. + * @param viewOutputBoundary The output boundary for preparing view response models. + * @param userGatewayFactory The factory for creating user gateways. + */ public ViewQuestionInteractor(QuestionGateway questionGateway, ViewOutputBoundary viewOutputBoundary, UserGatewayFactory userGatewayFactory) { super(viewOutputBoundary, questionGateway); this.userGatewayFactory = userGatewayFactory; } + /** + * Fetch questions for the user. + * + * @param viewRequestModel The request model containing user details. + * @return The list of questions for the user. + */ @Override protected List fetchQuestions(ViewRequestModel viewRequestModel) { User user = fetchUser(viewRequestModel); return user.getQuestionsList(); } + /** + * Fetch the user based on the request model. + * + * @param viewRequestModel The request model containing user details. + * @return The user corresponding to the request. + */ @Override protected User fetchUser(ViewRequestModel viewRequestModel) { int userId = viewRequestModel.getUserId(); UserGateway userGateway = userGatewayFactory.createUserGateway(userId); return userGateway.get(userId); } - } \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/ViewQuestionInteractorBase.java b/src/main/java/businessrule/usecase/ViewQuestionInteractorBase.java index 7fe3e3da..567405de 100644 --- a/src/main/java/businessrule/usecase/ViewQuestionInteractorBase.java +++ b/src/main/java/businessrule/usecase/ViewQuestionInteractorBase.java @@ -13,10 +13,27 @@ import java.util.List; import java.util.Map; +/** + * This class represents the use case to view questions. + */ public abstract class ViewQuestionInteractorBase implements ViewInputBoundary { + + /** + * The output boundary to communicate the result of the view question use case. + */ protected final ViewOutputBoundary viewOutputBoundary; + + /** + * The gateway to access question-related data. + */ protected final QuestionGateway questionGateway; + /** + * Constructs a ViewQuestionInteractorBase instance. + * + * @param viewOutputBoundary The output boundary for communicating results. + * @param questionGateway The gateway for accessing question data. + */ public ViewQuestionInteractorBase(ViewOutputBoundary viewOutputBoundary, QuestionGateway questionGateway) { this.viewOutputBoundary = viewOutputBoundary; this.questionGateway = questionGateway; @@ -26,12 +43,27 @@ public ViewQuestionInteractorBase(ViewOutputBoundary viewOutputBoundary, Questio public ViewResponseModel viewQuestion(ViewRequestModel viewRequestModel) { List questionList = fetchQuestions(viewRequestModel); User user = fetchUser(viewRequestModel); + QuestionMapConstructor questionMapConstructor = new QuestionMapConstructor(); Map questionMap = questionMapConstructor.constructQuestionMap(questionList); + ViewResponseModel viewResponseModel = new ViewResponseModel(user.getUserId(), user.getUserName(), questionMap); return viewOutputBoundary.prepareSuccess(viewResponseModel); } + /** + * Fetches a list of questions based on the provided view request model. + * + * @param viewRequestModel The request model containing criteria for fetching questions. + * @return A list of questions based on the provided criteria. + */ protected abstract List fetchQuestions(ViewRequestModel viewRequestModel); + + /** + * Fetches user information based on the provided view request model. + * + * @param viewRequestModel The request model containing criteria for fetching user information. + * @return The user associated with the provided criteria. + */ protected abstract User fetchUser(ViewRequestModel viewRequestModel); -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/ViewRateableQuestionInteractor.java b/src/main/java/businessrule/usecase/ViewRateableQuestionInteractor.java index 69d0f6d9..10a3aed6 100644 --- a/src/main/java/businessrule/usecase/ViewRateableQuestionInteractor.java +++ b/src/main/java/businessrule/usecase/ViewRateableQuestionInteractor.java @@ -12,14 +12,33 @@ import java.util.ArrayList; import java.util.List; -public class ViewRateableQuestionInteractor extends ViewQuestionInteractorBase{ - final ClientGateway clientGateway; +/** + * This class represents the interactor class for viewing rateable questions. + */ +public class ViewRateableQuestionInteractor extends ViewQuestionInteractorBase { - public ViewRateableQuestionInteractor(ViewOutputBoundary viewOutputBoundary, QuestionGateway questionGateway, ClientGateway clientGateway) { + private final ClientGateway clientGateway; + + /** + * Constructor to initialize the ViewRateableQuestionInteractor. + * + * @param viewOutputBoundary The output boundary for displaying the results. + * @param questionGateway Gateway for accessing question-related data. + * @param clientGateway Gateway for accessing client-related data. + */ + public ViewRateableQuestionInteractor(ViewOutputBoundary viewOutputBoundary, + QuestionGateway questionGateway, + ClientGateway clientGateway) { super(viewOutputBoundary, questionGateway); this.clientGateway = clientGateway; } + /** + * Fetches rateable questions based on the provided request model. + * + * @param viewRequestModel The request model containing necessary information. + * @return List of rateable questions. + */ @Override protected List fetchQuestions(ViewRequestModel viewRequestModel) { Client client = (Client) fetchUser(viewRequestModel); @@ -29,12 +48,19 @@ protected List fetchQuestions(ViewRequestModel viewRequestModel) { if (question.isClose() || question.isTaken()) { rateableList.add(question); } - } return rateableList; + } + return rateableList; } + /** + * Fetches the user (client) associated with the given request model. + * + * @param viewRequestModel The request model containing the user ID. + * @return The client associated with the provided user ID. + */ @Override protected User fetchUser(ViewRequestModel viewRequestModel) { int attorneyId = viewRequestModel.getUserId(); return clientGateway.get(attorneyId); } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/util/Matching.java b/src/main/java/businessrule/usecase/util/Matching.java index 1597f93d..28295caa 100644 --- a/src/main/java/businessrule/usecase/util/Matching.java +++ b/src/main/java/businessrule/usecase/util/Matching.java @@ -1,29 +1,59 @@ package businessrule.usecase.util; +/** + * This class represents a matching between a question and an attorney. + * It stores information about the question ID and the attorney ID that are matched. + */ public class Matching { private int matchingId; private int questionId; private int attorneyId; + /** + * Constructs a new `Matching` object with the specified question ID and attorney ID. + * + * @param questionId The ID of the question to be matched. + * @param attorneyId The ID of the attorney to be matched. + */ public Matching(int questionId, int attorneyId) { this.questionId = questionId; this.attorneyId = attorneyId; } + /** + * Gets the ID of the matched question. + * + * @return The ID of the question. + */ public int getQuestionId() { return questionId; } + /** + * Sets the ID of the matched question. + * + * @param questionId The ID of the question to set. + */ public void setQuestionId(int questionId) { this.questionId = questionId; } + /** + * Gets the ID of the matched attorney. + * + * @return The ID of the attorney. + */ public int getAttorneyId() { return attorneyId; } + /** + * Sets the ID of the matched attorney. + * + * @param attorneyId The ID of the attorney to set. + */ public void setAttorneyId(int attorneyId) { this.attorneyId = attorneyId; } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/util/MatchingHandler.java b/src/main/java/businessrule/usecase/util/MatchingHandler.java index 78d938f8..ec2a9d1a 100644 --- a/src/main/java/businessrule/usecase/util/MatchingHandler.java +++ b/src/main/java/businessrule/usecase/util/MatchingHandler.java @@ -22,6 +22,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.nio.charset.StandardCharsets; +/** + * This class represents the process of matching questions with attorneys. + * It uses various gateways and utility classes to reach this process. + */ public class MatchingHandler { final AttorneyGateway attorneyGateway; final ClientGateway clientGateway; @@ -29,12 +33,22 @@ public class MatchingHandler { final ObjectMapper objectMapper = new ObjectMapper(); final PythonReader pythonReader = new PythonReader(); + /** + * Constructs a `MatchingHandler` object with the given gateways. + * + * @param attorneyGateway The gateway for accessing attorney information. + * @param clientGateway The gateway for accessing client information. + * @param questionGateway The gateway for accessing question information. + */ public MatchingHandler(AttorneyGateway attorneyGateway, ClientGateway clientGateway, QuestionGateway questionGateway) { this.attorneyGateway = attorneyGateway; this.clientGateway = clientGateway; this.questionGateway = questionGateway; } + /** + * Initiates the matching process by obtaining matching results and updating recommendations. + */ public void match() { try { MatchingResult matchingResult = getMatching(); @@ -44,6 +58,11 @@ public void match() { } } + /** + * Updates attorney recommendations based on the matching results. + * + * @param matchingResult The result of the matching process. + */ public void updateMatching(MatchingResult matchingResult) { // clear all matching attorneyGateway.clearAllRecommendations(); @@ -56,19 +75,26 @@ public void updateMatching(MatchingResult matchingResult) { } } + /** + * Retrieves matching results by processing questions and attorneys. + * + * @return The matching results. + * @throws IOException If there's an I/O error during the process. + */ public MatchingResult getMatching() throws IOException { List questionList = questionGateway.getNotTakenQuestion(); List attorneyList = attorneyGateway.getAll(); Map weights = constructWeight(questionList, attorneyList); List matchingResult = pythonMatching(getQuestionIdList(questionList), getAttorneyIdList(attorneyList), weights); - List matchingList = new ArrayList(); + List matchingList = new ArrayList<>(); for (Integer[] match: matchingResult) { matchingList.add(new Matching(match[0], match[1])); } return new MatchingResult(matchingList); } + private List pythonMatching(List questions, List attorneys, Map weights) throws IOException{ Map javaPara = new HashMap<>(); javaPara.put("questions", questions); diff --git a/src/main/java/businessrule/usecase/util/MatchingResult.java b/src/main/java/businessrule/usecase/util/MatchingResult.java index 3b4380df..4c753d34 100644 --- a/src/main/java/businessrule/usecase/util/MatchingResult.java +++ b/src/main/java/businessrule/usecase/util/MatchingResult.java @@ -4,14 +4,38 @@ import java.util.List; +/** + * This class represents the result of the matching process. + * It contains a list of `Matching` objects that represent the matches between questions and attorneys. + */ public class MatchingResult { - private int resultId; - private List matchingResult; + private int resultId; // The unique ID for the result (not used in this class) + private List matchingResult; // The list of matching results - public MatchingResult(List matchingResult) {this.matchingResult = matchingResult;} + /** + * Constructs a `MatchingResult` object with the specified list of matching results. + * + * @param matchingResult The list of `Matching` objects representing the matching results. + */ + public MatchingResult(List matchingResult) { + this.matchingResult = matchingResult; + } - public List getMatchingResult() {return matchingResult;} + /** + * Gets the list of matching results. + * + * @return The list of `Matching` objects representing the matching results. + */ + public List getMatchingResult() { + return matchingResult; + } - public void setMatchingResult(List matchingResult) {this.matchingResult = matchingResult;} + /** + * Sets the list of matching results. + * + * @param matchingResult The list of `Matching` objects to set as matching results. + */ + public void setMatchingResult(List matchingResult) { + this.matchingResult = matchingResult; + } } - diff --git a/src/main/java/businessrule/usecase/util/PostDisplayFormatter.java b/src/main/java/businessrule/usecase/util/PostDisplayFormatter.java index 6b165426..fa039031 100644 --- a/src/main/java/businessrule/usecase/util/PostDisplayFormatter.java +++ b/src/main/java/businessrule/usecase/util/PostDisplayFormatter.java @@ -4,12 +4,25 @@ import java.time.LocalDate; +/** + * This class represents the formatted display information for a post. + * It contains attributes such as the post text, whether it's from a client, the name of the poster, + * and the creation date. + */ public class PostDisplayFormatter { - private final String postText; - private final boolean isClient; - private final String name; - private final LocalDate createAt; + private final String postText; // The text content of the post + private final boolean isClient; // Indicates if the post is from a client + private final String name; // The name of the poster + private final LocalDate createAt; // The creation date of the post + /** + * Constructs a `PostDisplayFormatter` object with the specified attributes. + * + * @param postText The text content of the post. + * @param isClient Indicates if the post is from a client. + * @param name The name of the poster. + * @param createAt The creation date of the post. + */ public PostDisplayFormatter(String postText, boolean isClient, String name, LocalDate createAt) { this.postText = postText; this.isClient = isClient; @@ -17,19 +30,39 @@ public PostDisplayFormatter(String postText, boolean isClient, String name, Loca this.createAt = createAt; } + /** + * Gets the text content of the post. + * + * @return The post text. + */ public String getPostText() { return postText; } + /** + * Checks if the post is from a client. + * + * @return `true` if the post is from a client, otherwise `false`. + */ public boolean isClient() { return isClient; } + /** + * Gets the name of the poster. + * + * @return The name of the poster. + */ public String getName() { return name; } + /** + * Gets the creation date of the post. + * + * @return The creation date. + */ public LocalDate getCreateAt() { return createAt; } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/util/PostMapConstructor.java b/src/main/java/businessrule/usecase/util/PostMapConstructor.java index 11c47d37..cec11c48 100644 --- a/src/main/java/businessrule/usecase/util/PostMapConstructor.java +++ b/src/main/java/businessrule/usecase/util/PostMapConstructor.java @@ -11,11 +11,28 @@ import java.util.List; import java.util.Map; +/** + * This class represents a map of post IDs to formatted post display information. + * It uses a `UserGatewayFactory` to create user gateways for retrieving user information. + */ public class PostMapConstructor { private final UserGatewayFactory userGatewayFactory; - public PostMapConstructor(UserGatewayFactory userGatewayFactory) {this.userGatewayFactory = userGatewayFactory;} + /** + * Constructs a `PostMapConstructor` object with the given `UserGatewayFactory`. + * + * @param userGatewayFactory The factory for creating user gateways. + */ + public PostMapConstructor(UserGatewayFactory userGatewayFactory) { + this.userGatewayFactory = userGatewayFactory; + } + /** + * Constructs a map of post IDs to formatted post display information based on the given question. + * + * @param question The question containing posts to be mapped. + * @return A map of post IDs to formatted post display information. + */ public Map constructPostMap(Question question) { List postList = question.getPosts(); @@ -23,10 +40,12 @@ public Map constructPostMap(Question question) { Map postMap = new HashMap<>(); // handle the empty post list - if (postList.isEmpty()) {return postMap;} + if (postList.isEmpty()) { + return postMap; + } - // for each post list, find the data needed - for (Post post: postList) { + // for each post in the list, find the data needed + for (Post post : postList) { int postId = post.getPostId(); UserGateway userGateway = userGatewayFactory.createUserGateway(post.getBelongsTo()); User user = userGateway.get(post.getBelongsTo()); @@ -35,9 +54,9 @@ public Map constructPostMap(Question question) { String postText = post.getPostText(); LocalDate createAt = post.getCreateAt(); PostDisplayFormatter postDisplayFormatter = new PostDisplayFormatter(postText, isClient, name, createAt); - // put every data needed to the post map + // put every data needed into the post map postMap.put(postId, postDisplayFormatter); } return postMap; } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/util/PythonReader.java b/src/main/java/businessrule/usecase/util/PythonReader.java index 89b8155f..fb8e160e 100644 --- a/src/main/java/businessrule/usecase/util/PythonReader.java +++ b/src/main/java/businessrule/usecase/util/PythonReader.java @@ -1,12 +1,22 @@ package businessrule.usecase.util; import org.apache.commons.io.IOUtils; + import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +/** + * This class represents a utility for executing Python scripts and reading their output. + */ public class PythonReader { + /** + * Executes a Python command and reads the output. + * + * @param command The Python command to execute. + * @return The output generated by the Python script. + */ public String readPythonExec(String command) { Process proc; try { @@ -21,6 +31,7 @@ public String readPythonExec(String command) { return IOUtils.toString(inputStream, StandardCharsets.UTF_8); } catch (IOException | InterruptedException e) { e.printStackTrace(); - } return null; + } + return null; } } diff --git a/src/main/java/businessrule/usecase/util/QuestionDisplayFormatter.java b/src/main/java/businessrule/usecase/util/QuestionDisplayFormatter.java index 309a7879..c8af2055 100644 --- a/src/main/java/businessrule/usecase/util/QuestionDisplayFormatter.java +++ b/src/main/java/businessrule/usecase/util/QuestionDisplayFormatter.java @@ -2,12 +2,24 @@ import java.time.LocalDate; +/** + * This class represents the formatted display information for a question. + * It encapsulates attributes such as the question title, type, legal deadline, and whether the question is closed. + */ public class QuestionDisplayFormatter { private final String title; private final String type; private final LocalDate legalDeadline; private final boolean isClose; + /** + * Constructs a `QuestionDisplayFormatter` object with the specified attributes. + * + * @param title The title of the question. + * @param type The type of the question. + * @param legalDeadline The legal deadline for the question. + * @param isClose Indicates if the question is closed. + */ public QuestionDisplayFormatter(String title, String type, LocalDate legalDeadline, boolean isClose) { this.title = title; this.type = type; @@ -15,17 +27,39 @@ public QuestionDisplayFormatter(String title, String type, LocalDate legalDeadli this.isClose = isClose; } + /** + * Gets the title of the question. + * + * @return The question title. + */ public String getTitle() { return title; } + /** + * Gets the type of the question. + * + * @return The question type. + */ public String getType() { return type; } + /** + * Gets the legal deadline for the question. + * + * @return The legal deadline. + */ public LocalDate getLegalDeadline() { return legalDeadline; } - public boolean isClose() {return isClose;} -} + /** + * Checks if the question is closed. + * + * @return `true` if the question is closed, otherwise `false`. + */ + public boolean isClose() { + return isClose; + } +} \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/util/QuestionMapConstructor.java b/src/main/java/businessrule/usecase/util/QuestionMapConstructor.java index fda9ca35..84e3223f 100644 --- a/src/main/java/businessrule/usecase/util/QuestionMapConstructor.java +++ b/src/main/java/businessrule/usecase/util/QuestionMapConstructor.java @@ -7,21 +7,38 @@ import java.util.List; import java.util.Map; +/** + * This class constructs a map of question IDs to formatted display objects using `QuestionDisplayFormatter`. + */ public class QuestionMapConstructor { + + /** + * Constructs a map of question IDs to formatted display objects. + * + * @param questionList The list of questions to be processed. + * @return A map where each question's ID is associated with a corresponding formatted display object. + */ public Map constructQuestionMap(List questionList) { Map questionMap = new HashMap<>(); + if (questionList.isEmpty()) { return questionMap; } - for (Question question: questionList) { + + for (Question question : questionList) { int questionId = question.getQuestionId(); String title = question.getTitle(); String type = question.getType(); LocalDate legalDeadline = question.getLegalDeadline(); boolean isClose = question.isClose(); + + // Create a QuestionDisplayFormatter instance with the extracted information QuestionDisplayFormatter questionDisplayFormatter = new QuestionDisplayFormatter(title, type, legalDeadline, isClose); + + // Put the question into the map with its ID as the key questionMap.put(questionId, questionDisplayFormatter); } + return questionMap; } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/usecase/util/RandomNumberGenerator.java b/src/main/java/businessrule/usecase/util/RandomNumberGenerator.java index 987c7fa8..8a149337 100644 --- a/src/main/java/businessrule/usecase/util/RandomNumberGenerator.java +++ b/src/main/java/businessrule/usecase/util/RandomNumberGenerator.java @@ -1,35 +1,77 @@ package businessrule.usecase.util; + import java.util.Random; /** * This class provides utility methods to generate random numbers and create unique IDs for different entities. */ public class RandomNumberGenerator { - public static int generate(int digit){ + + /** + * Generates a random integer with the specified number of digits. + * + * @param digit The number of digits the generated random number should have. + * @return A random integer with the specified number of digits. + */ + public static int generate(int digit) { Random random = new Random(); int min = (int) Math.pow(10, digit - 1); int max = (int) Math.pow(10, digit) - 1; - return random.nextInt(max - min+1); + return random.nextInt(max - min + 1) + min; } - public static int addDigitToFront(int number, int digit){ + /** + * Adds a digit to the front of an existing number. + * + * @param number The existing number. + * @param digit The digit to be added to the front. + * @return The resulting number after adding the digit to the front. + */ + public static int addDigitToFront(int number, int digit) { String numAsStr = String.valueOf(number); String digAsStr = String.valueOf(digit); String res = digAsStr + numAsStr; return Integer.parseInt(res); } - public int generateAttorneyId(int digit){ - return addDigitToFront(generate(digit-1), 1); + /** + * Generates a unique attorney ID with the specified number of digits. + * + * @param digit The number of digits the generated attorney ID should have. + * @return A unique attorney ID with the specified number of digits. + */ + public int generateAttorneyId(int digit) { + return addDigitToFront(generate(digit - 1), 1); } - public int generateClientId(int digit){ - return addDigitToFront(generate(digit-1), 2); + + /** + * Generates a unique client ID with the specified number of digits. + * + * @param digit The number of digits the generated client ID should have. + * @return A unique client ID with the specified number of digits. + */ + public int generateClientId(int digit) { + return addDigitToFront(generate(digit - 1), 2); } - public int generateQuestionId(int digit){ - return addDigitToFront(generate(digit-1), 3); + + /** + * Generates a unique question ID with the specified number of digits. + * + * @param digit The number of digits the generated question ID should have. + * @return A unique question ID with the specified number of digits. + */ + public int generateQuestionId(int digit) { + return addDigitToFront(generate(digit - 1), 3); } - public int generatePostId(int digit){ - return addDigitToFront(generate(digit-1), 4); + + /** + * Generates a unique post ID with the specified number of digits. + * + * @param digit The number of digits the generated post ID should have. + * @return A unique post ID with the specified number of digits. + */ + public int generatePostId(int digit) { + return addDigitToFront(generate(digit - 1), 4); } -} +} \ No newline at end of file diff --git a/src/main/java/driver/database/AttorneyRepository.java b/src/main/java/driver/database/AttorneyRepository.java index 39f3ce80..55008aea 100644 --- a/src/main/java/driver/database/AttorneyRepository.java +++ b/src/main/java/driver/database/AttorneyRepository.java @@ -9,17 +9,34 @@ import java.util.ArrayList; import java.util.List; +/** + * This class represents managing Attorney entities in the database. + */ public class AttorneyRepository extends UserRepository implements AttorneyGateway { + /** + * Constructs an AttorneyRepository instance. + * Initializes the superclass with the Attorney class. + */ public AttorneyRepository() { super(Attorney.class); } + /** + * Retrieves an Attorney entity with the specified ID from the database. + * + * @param id The ID of the Attorney entity to retrieve. + * @return The Attorney entity associated with the specified ID, or null if not found. + */ @Override public Attorney get(int id) { return (Attorney) super.get(id); } + /** + * Clears all recommendations associated with Attorneys in the database. + * This method removes all recommendations from each Attorney entity. + */ @Override public void clearAllRecommendations() { EntityManager em = DatabaseConnection.getEntityManager(); @@ -43,6 +60,12 @@ public void clearAllRecommendations() { } } + /** + * Adds a recommendation to an Attorney entity in the database. + * + * @param Userid The ID of the Attorney entity to which the recommendation will be added. + * @param question The Question entity representing the recommendation. + */ @Override public void addRecommendation(int Userid, Question question) { EntityManager em = DatabaseConnection.getEntityManager(); @@ -62,4 +85,4 @@ public void addRecommendation(int Userid, Question question) { em.close(); } } -} +} \ No newline at end of file diff --git a/src/main/java/driver/database/ClientRepository.java b/src/main/java/driver/database/ClientRepository.java index e81a236a..7695be48 100644 --- a/src/main/java/driver/database/ClientRepository.java +++ b/src/main/java/driver/database/ClientRepository.java @@ -4,16 +4,27 @@ import entity.Attorney; import entity.Client; +/** + * This class represents managing Client entities in the database. + */ public class ClientRepository extends UserRepository implements ClientGateway { + /** + * Constructs a ClientRepository instance. + * Initializes the superclass with the Client class. + */ public ClientRepository() { super(Client.class); } + /** + * Retrieves a Client entity with the specified ID from the database. + * + * @param id The ID of the Client entity to retrieve. + * @return The Client entity associated with the specified ID, or null if not found. + */ @Override public Client get(int id) { return (Client) super.get(id); } - -} - +} \ No newline at end of file diff --git a/src/main/java/driver/database/DatabaseConnection.java b/src/main/java/driver/database/DatabaseConnection.java index 1cb9bab9..037fa420 100644 --- a/src/main/java/driver/database/DatabaseConnection.java +++ b/src/main/java/driver/database/DatabaseConnection.java @@ -9,7 +9,7 @@ */ public class DatabaseConnection { - private static final String URL = "objectdb:myapp.odb;admin"; + private static final String URL = "objectdb://175.24.206.37:39136/myapp.odb;admin"; private static EntityManagerFactory entityManagerFactory; /** diff --git a/src/main/java/driver/database/GenericRepository.java b/src/main/java/driver/database/GenericRepository.java index e76c52f3..d71e01b7 100644 --- a/src/main/java/driver/database/GenericRepository.java +++ b/src/main/java/driver/database/GenericRepository.java @@ -6,9 +6,19 @@ import javax.persistence.EntityTransaction; import java.util.List; +/** + * This class represents managing entities in the database. + * + * @param The type of entity managed by the repository. + */ public class GenericRepository implements GenericGateway { final Class entityType; + /** + * Constructs a GenericRepository instance. + * + * @param entityType The class representing the type of entity managed by the repository. + */ public GenericRepository(Class entityType) { this.entityType = entityType; } @@ -82,12 +92,19 @@ R executeTransactionWithResult(DatabaseOperationWithResult operation) { } } + /** + * Represents an operation that accepts an EntityManager and performs an action. + */ interface DatabaseOperation { void accept(EntityManager entityManager); } + /** + * Represents an operation that accepts an EntityManager and returns a result. + * + * @param The type of the result returned by the operation. + */ interface DatabaseOperationWithResult { R apply(EntityManager entityManager); } - -} +} \ No newline at end of file diff --git a/src/main/java/driver/database/PostRepo.java b/src/main/java/driver/database/PostRepo.java index 1a4cd7aa..882a7344 100644 --- a/src/main/java/driver/database/PostRepo.java +++ b/src/main/java/driver/database/PostRepo.java @@ -4,18 +4,27 @@ import entity.Post; import entity.User; -import javax.persistence.EntityManager; -import javax.persistence.EntityTransaction; - +/** + * This class representsmanaging Post entities in the database. + */ public class PostRepo extends GenericRepository implements PostGateway { + /** + * Constructs a PostRepo instance. + * Initializes the superclass with the Post class. + */ public PostRepo() { super(Post.class); } + /** + * Retrieves a Post entity with the specified ID from the database. + * + * @param id The ID of the Post entity to retrieve. + * @return The Post entity associated with the specified ID, or null if not found. + */ @Override public Post get(int id) { return (Post) super.get(id); } - -} +} \ No newline at end of file diff --git a/src/main/java/driver/database/QuestionRepo.java b/src/main/java/driver/database/QuestionRepo.java index c4740039..628b21f1 100644 --- a/src/main/java/driver/database/QuestionRepo.java +++ b/src/main/java/driver/database/QuestionRepo.java @@ -12,8 +12,15 @@ import java.time.LocalDate; import java.util.List; +/** + * This class represents managing Question entities in the database. + */ public class QuestionRepo extends GenericRepository implements QuestionGateway { + /** + * Constructs a QuestionRepo instance. + * Initializes the superclass with the Question class. + */ public QuestionRepo() { super(Question.class); } @@ -44,7 +51,7 @@ public List getNotClosedQuestion() { public List getAllPostOfQuestion(int questionId) { EntityManager em = DatabaseConnection.getEntityManager(); try { - return em.createQuery("SELECT p FROM Post p WHERE p.questionId =: questionId", Post.class) + return em.createQuery("SELECT p FROM Post p WHERE p.questionId = :questionId", Post.class) .setParameter("questionId", questionId).getResultList(); } finally { em.close(); @@ -165,5 +172,4 @@ public void updatePosts(int questionId, Post post) { public Question get(int id) { return (Question) super.get(id); } - -} +} \ No newline at end of file diff --git a/src/main/java/driver/database/UserRepository.java b/src/main/java/driver/database/UserRepository.java index 7fb1f19c..0c73ee68 100644 --- a/src/main/java/driver/database/UserRepository.java +++ b/src/main/java/driver/database/UserRepository.java @@ -7,8 +7,18 @@ import javax.jdo.JDOHelper; import java.util.List; +/** + * This class represents managing User entities in the database. + * + * @param The type of User entity managed by the repository. + */ public class UserRepository extends GenericRepository implements UserGateway { + /** + * Constructs a UserRepository instance. + * + * @param entityType The class representing the type of User entity managed by the repository. + */ public UserRepository(Class entityType) { super(entityType); } @@ -17,7 +27,7 @@ public UserRepository(Class entityType) { public boolean existsByName(String inputUserName) { return executeTransactionWithResult(entityManager -> { List users = entityManager.createQuery("SELECT u FROM " + entityType.getSimpleName() + - " u WHERE u.name =: name", entityType).setParameter("name", inputUserName).getResultList(); + " u WHERE u.name = :name", entityType).setParameter("name", inputUserName).getResultList(); return !users.isEmpty(); }); } @@ -35,5 +45,4 @@ public void updateQuestionList(int id, Question question) { public User get(int id) { return (User) super.get(id); } - } diff --git a/src/main/java/driver/screen/AttorneyHomePageUI.java b/src/main/java/driver/screen/AttorneyHomePageUI.java index dcb9ffbd..4d340904 100644 --- a/src/main/java/driver/screen/AttorneyHomePageUI.java +++ b/src/main/java/driver/screen/AttorneyHomePageUI.java @@ -9,12 +9,25 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +/** + * This class represents a JPanel for the Attorney's home page user interface. + */ public class AttorneyHomePageUI extends JPanel implements ActionListener { - ControlContainer controlContainer; - CardLayout cardLayout; - JPanel screens; - int userId; - String userName; + private ControlContainer controlContainer; + private CardLayout cardLayout; + private JPanel screens; + private int userId; + private String userName; + + /** + * Constructs an AttorneyHomePageUI instance. + * + * @param controlContainer The container for controllers. + * @param cardLayout The CardLayout for managing screens. + * @param screens The parent panel containing multiple screens. + * @param userId The ID of the logged-in attorney user. + * @param userName The name of the logged-in attorney user. + */ public AttorneyHomePageUI(ControlContainer controlContainer, CardLayout cardLayout, JPanel screens, int userId, String userName) { this.controlContainer = controlContainer; @@ -23,30 +36,27 @@ public AttorneyHomePageUI(ControlContainer controlContainer, CardLayout cardLayo this.cardLayout = cardLayout; this.screens = screens; + // UI Design setup UIDesign.setBackgroundFrame(this); - //The title + + // The title JLabel title = new JLabel("Home Page"); title.setAlignmentX(Component.CENTER_ALIGNMENT); UIDesign.setTitleFont(title); + title.setBorder(new EmptyBorder(50, 0, 0, 0)); - int topMargin = 50; - int leftMargin = 0; - int bottomMargin = 0; - int rightMargin = 0; - title.setBorder(new EmptyBorder(topMargin, leftMargin, bottomMargin, rightMargin)); - - //The userName and userId - String helloMessageString = "Hello, " + userName + "(" + userId + ")"; + // User greeting message + String helloMessageString = "Hello, " + userName + " (" + userId + ")"; JLabel helloMessage = new JLabel(helloMessageString); - helloMessage.setBorder(new EmptyBorder(0,0,30,0)); + helloMessage.setBorder(new EmptyBorder(0, 0, 30, 0)); - //The three buttons + // Buttons panel JPanel buttons = new JPanel(); buttons.setBackground(UIDesign.lightGreenColor); JButton browseQuestions = new JButton("Browse available questions"); - browseQuestions.setBorder(new EmptyBorder(0,0,20,0)); + browseQuestions.setBorder(new EmptyBorder(0, 0, 20, 0)); JButton viewQuestionHistory = new JButton("View question history"); - viewQuestionHistory.setBorder(new EmptyBorder(0,0,20,0)); + viewQuestionHistory.setBorder(new EmptyBorder(0, 0, 20, 0)); JButton recommendation = new JButton("Recommended questions"); UIDesign.setHomePageButton(browseQuestions); @@ -71,6 +81,7 @@ public void actionPerformed(ActionEvent e) { String actionCommand = e.getActionCommand(); if ("Browse available questions".equals(actionCommand)){ System.out.println("Attorney chooses browse available questions."); + // Uncomment when functionality is implemented // BrowseQuestionControl browseQuestionControl = controlContainer.getBrowseQuestionControl(); // browseQuestionControl.browseQuestion(userId); } else if ("View question history".equals(actionCommand)){ @@ -81,4 +92,4 @@ public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(this, "Recommendation unavailable"); } } -} +} \ No newline at end of file diff --git a/src/main/java/driver/screen/ClientHomePageUI.java b/src/main/java/driver/screen/ClientHomePageUI.java index f18e7b97..763934c0 100644 --- a/src/main/java/driver/screen/ClientHomePageUI.java +++ b/src/main/java/driver/screen/ClientHomePageUI.java @@ -7,16 +7,26 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.rmi.server.UID; - -import static javax.swing.BoxLayout.*; +/** + * This class represents a JPanel for the Client's home page user interface. + */ public class ClientHomePageUI extends JPanel implements ActionListener { ControlContainer controlContainer; CardLayout cardLayout; JPanel screens; int userId; String userName; + + /** + * Constructs a new ClientHomePageUI instance. + * + * @param controlContainer The container for controllers. + * @param cardLayout The CardLayout for managing screens. + * @param screens The parent panel containing multiple screens. + * @param userId The ID of the logged-in client user. + * @param userName The name of the logged-in client user. + */ public ClientHomePageUI(ControlContainer controlContainer, CardLayout cardLayout, JPanel screens, int userId, String userName) { this.controlContainer = controlContainer; @@ -25,23 +35,27 @@ public ClientHomePageUI(ControlContainer controlContainer, CardLayout cardLayout this.cardLayout = cardLayout; this.screens = screens; + // UI Design setup setBackground(UIDesign.lightGreenColor); JLabel title = new JLabel("Home"); title.setAlignmentX(Component.CENTER_ALIGNMENT); UIDesign.setTitleFont(title); - this.setLayout(new BoxLayout(this, Y_AXIS)); + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); this.add(title); + // Title top margin int topMargin = 50; int leftMargin = 0; int bottomMargin = 0; int rightMargin = 0; title.setBorder(new EmptyBorder(topMargin, leftMargin, bottomMargin, rightMargin)); - String helloMessageString = "Hello, " + userName + "(" + userId + ")"; + // User greeting message + String helloMessageString = "Hello, " + userName + " (" + userId + ")"; JLabel helloMessage = new JLabel(helloMessageString); - helloMessage.setBorder(new EmptyBorder(0,0,50,0)); + helloMessage.setBorder(new EmptyBorder(0, 0, 50, 0)); + // Buttons panel JPanel buttons = new JPanel(); buttons.setBackground(UIDesign.lightGreenColor); JButton askNewQuestion = new JButton("Ask new question"); diff --git a/src/main/java/driver/screen/DateChooserPanel.java b/src/main/java/driver/screen/DateChooserPanel.java index 705a8b2c..26e6a0de 100644 --- a/src/main/java/driver/screen/DateChooserPanel.java +++ b/src/main/java/driver/screen/DateChooserPanel.java @@ -4,7 +4,9 @@ import javax.swing.*; import java.awt.*; - +/** + * This class represents a JPanel for the date choose interface. + */ public class DateChooserPanel extends JPanel{ public DateChooserPanel(JLabel label, JDateChooser dateChooser){ setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); diff --git a/src/main/java/driver/screen/DropDownPanel.java b/src/main/java/driver/screen/DropDownPanel.java index 585ef5f4..a39b5768 100644 --- a/src/main/java/driver/screen/DropDownPanel.java +++ b/src/main/java/driver/screen/DropDownPanel.java @@ -2,7 +2,9 @@ import javax.swing.*; import java.awt.*; - +/** + * This class represents a JPanel for the drop-down interface. + */ public class DropDownPanel extends JPanel { public DropDownPanel(JLabel label, JComboBox dropDownBox){ this.add(label); diff --git a/src/main/java/driver/screen/QuestionListUI.java b/src/main/java/driver/screen/QuestionListUI.java index 44ce8b77..6b678773 100644 --- a/src/main/java/driver/screen/QuestionListUI.java +++ b/src/main/java/driver/screen/QuestionListUI.java @@ -12,7 +12,10 @@ import java.time.format.DateTimeFormatter; import java.util.Map; -public class QuestionListUI extends JPanel{ +/** + * This class represents a JPanel for a list of questions displayed in the user interface. + */ +public class QuestionListUI extends JPanel { ControlContainer controlContainer; CardLayout cardLayout; JPanel screens; @@ -20,6 +23,16 @@ public class QuestionListUI extends JPanel{ String userName; Map questionMap; + /** + * Constructs a new QuestionListUI instance. + * + * @param controlContainer The container for controllers. + * @param cardLayout The CardLayout for managing screens. + * @param screens The parent panel containing multiple screens. + * @param userId The ID of the logged-in user. + * @param userName The name of the logged-in user. + * @param questionMap A map of question IDs to their display formatters. + */ public QuestionListUI(ControlContainer controlContainer, CardLayout cardLayout, JPanel screens, int userId, String userName, Map questionMap) { @@ -30,17 +43,17 @@ public QuestionListUI(ControlContainer controlContainer, CardLayout cardLayout, this.userName = userName; this.questionMap = questionMap; - //UserName and UserId + // User greeting message String helloMessageString = "Hello, " + userName + "(" + userId + ")"; JLabel helloMessage = new JLabel(helloMessageString); - //The scrollable question buttons + // Scrollable question buttons int numberOfQuestions = questionMap.size(); JScrollPane questionScrollPane = new JScrollPane(); JPanel questionScrollPanel = new JPanel(); questionScrollPanel.setLayout(new GridLayout(numberOfQuestions, 1)); + for (Integer questionId : questionMap.keySet()) { - //read all variables from displayFormatter QuestionDisplayFormatter question = questionMap.get(questionId); String title = question.getTitle(); String type = question.getType(); @@ -49,16 +62,12 @@ public QuestionListUI(ControlContainer controlContainer, CardLayout cardLayout, LocalDate deadlineDate = question.getLegalDeadline(); String deadline = deadlineDate.format(formatter); - //lines - // String titleLine = "(" + type + ")" + title; - String deadlineLine = "Legal deadline: " + deadline; - // String overallText = titleLine + "\n" + deadlineLine; - String overallText = "" + title+ "
" + deadlineLine + ""; + String overallText = "" + title + "
" + "Legal deadline: " + deadline + ""; - //Format them all into a textArea JButton questionButton = new JButton(overallText); questionButton.setPreferredSize(new Dimension(400, 50)); questionScrollPanel.add(questionButton); + questionButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -68,9 +77,10 @@ public void actionPerformed(ActionEvent e) { } }); } + questionScrollPane.setViewportView(questionScrollPanel); - //Add everything in the panel + // Add components to the panel this.add(helloMessage); this.add(questionScrollPane); } diff --git a/src/main/java/driver/screen/RegisterUI.java b/src/main/java/driver/screen/RegisterUI.java index 8fd092fe..c7667b02 100644 --- a/src/main/java/driver/screen/RegisterUI.java +++ b/src/main/java/driver/screen/RegisterUI.java @@ -12,7 +12,11 @@ import static driver.screen.UIDesign.buttonSize; -public class RegisterUI extends JPanel implements ActionListener{ + +/** + * This class represents a JPanel for the user registration interface. + */ +public class RegisterUI extends JPanel implements ActionListener { ControlContainer controlContainer; JTextField userName = new JTextField(15); @@ -35,8 +39,15 @@ public class RegisterUI extends JPanel implements ActionListener{ JComboBox gender = new JComboBox<>(genderList); JComboBox maritalStatus = new JComboBox<>(maritalStatusList); + /** + * Constructs a new RegisterUI instance. + * + * @param controlContainer The container for controllers. + */ public RegisterUI(ControlContainer controlContainer) { this.controlContainer = controlContainer; + + // UI Design setup UIDesign.setBackgroundFrame(this); setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); @@ -68,34 +79,9 @@ public RegisterUI(ControlContainer controlContainer) { LabelTextPanel repeatPasswordPanel = new LabelTextPanel(new JLabel("Confirm Password"), password2); add(repeatPasswordPanel, gbc); - LabelTextPanel emailPanel = new LabelTextPanel(new JLabel("Email"), email); - add(emailPanel, gbc); - - LabelTextPanel postalCodePanel = new LabelTextPanel(new JLabel("Zip Code"), postalCode); - add(postalCodePanel, gbc); - - LabelTextPanel stateAbbPanel = new LabelTextPanel(new JLabel("State Abbreviation"), stateAbb); - add(stateAbbPanel, gbc); - - LabelTextPanel agePanel = new LabelTextPanel(new JLabel("Age"), age); - add(agePanel, gbc); - - LabelTextPanel numberOfHouseholdPanel = new LabelTextPanel(new JLabel("Number of Household"), numberOfHousehold); - add(numberOfHouseholdPanel, gbc); - - LabelTextPanel annualIncomePanel = new LabelTextPanel(new JLabel("Annual Income"), annualIncome); - add(annualIncomePanel, gbc); + // ... (Add other panels here) - DropDownPanel ethnicityPanel = new DropDownPanel(new JLabel("Ethnicity"), ethnicity); - add(ethnicityPanel, gbc); - - DropDownPanel genderPanel = new DropDownPanel(new JLabel("Gender"), gender); - add(genderPanel, gbc); - - DropDownPanel maritalStatusPanel = new DropDownPanel(new JLabel("Marital Status"), maritalStatus); - add(maritalStatusPanel, gbc); - - //Register button here + // Register button JButton buttonToSubmit = new JButton("Register"); UIDesign.setButton(buttonToSubmit); JPanel buttons = new JPanel(); @@ -105,6 +91,7 @@ public RegisterUI(ControlContainer controlContainer) { buttonToSubmit.addActionListener(this); add(buttons, gbc); } + private void setFontForAllComponents(Container container, Font font) { for (Component component : container.getComponents()) { if (component instanceof Container) { @@ -113,21 +100,20 @@ private void setFontForAllComponents(Container container, Font font) { } } - @Override public void actionPerformed(ActionEvent e) { System.out.println("User clicks register"); ClientRegisterControl clientRegisterControl = controlContainer.getClientRegisterControl(); try { + // Call the registration control to create the user clientRegisterControl.create(userName.getText(), email.getText(), String.valueOf(password1.getPassword()), String.valueOf(password2.getPassword()), stateAbb.getText(), postalCode.getText(), - (String)ethnicity.getSelectedItem(), Integer.parseInt(age.getText()), (String)gender.getSelectedItem(), - (String)maritalStatus.getSelectedItem(), Integer.parseInt(numberOfHousehold.getText()), + (String) ethnicity.getSelectedItem(), Integer.parseInt(age.getText()), (String) gender.getSelectedItem(), + (String) maritalStatus.getSelectedItem(), Integer.parseInt(numberOfHousehold.getText()), Float.parseFloat(annualIncome.getText())); - } - catch(Exception ex){ + } catch (Exception ex) { JOptionPane.showMessageDialog(this, ex.getMessage()); } } -} +} \ No newline at end of file diff --git a/src/main/java/driver/screen/ReplyQuestionUI.java b/src/main/java/driver/screen/ReplyQuestionUI.java index 5c1e5ba7..2645ad35 100644 --- a/src/main/java/driver/screen/ReplyQuestionUI.java +++ b/src/main/java/driver/screen/ReplyQuestionUI.java @@ -1,4 +1,8 @@ package driver.screen; +/** + * This class represents the user interface for replying to a question. + */ public class ReplyQuestionUI { -} + // Add class members, constructor, methods, etc. here +} \ No newline at end of file diff --git a/src/main/java/driver/screen/TheQuestionUI.java b/src/main/java/driver/screen/TheQuestionUI.java index 6a9336a2..e296dadc 100644 --- a/src/main/java/driver/screen/TheQuestionUI.java +++ b/src/main/java/driver/screen/TheQuestionUI.java @@ -17,6 +17,11 @@ import static driver.screen.UIDesign.*; +/** + * TheQuestionUI class represents the user interface for a specific question. + * It displays information about the question, posts, and provides interaction + * options such as posting replies, closing the question, and rating it. + */ public class TheQuestionUI extends JPanel implements ActionListener { ControlContainer controlContainer; CardLayout cardLayout; @@ -29,11 +34,24 @@ public class TheQuestionUI extends JPanel implements ActionListener { LocalDate deadline; Map postMap; - JTextArea inputPostArea = new JTextArea(); String[] rateList = {"Satisfied", "Not satisfied"}; JComboBox rate = new JComboBox<>(rateList); + /** + * Constructs a new instance of TheQuestionUI with provided data and components. + * + * @param controlContainer The container holding various controller instances. + * @param cardLayout The CardLayout used for managing screen transitions. + * @param screens The panel containing various screens. + * @param userId The ID of the user interacting with the UI. + * @param userName The name of the user. + * @param questionId The ID of the question being displayed. + * @param title The title of the question. + * @param type The type/category of the question. + * @param deadline The deadline associated with the question. + * @param postMap A map of post IDs to their display formatters. + */ public TheQuestionUI(ControlContainer controlContainer, CardLayout cardLayout, JPanel screens, int userId, String userName, int questionId, String title, String type, LocalDate deadline, Map postMap) { @@ -48,8 +66,6 @@ public TheQuestionUI(ControlContainer controlContainer, CardLayout cardLayout, this.deadline = deadline; this.postMap = postMap; - UIDesign.setBackgroundFrame(this); - setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); //UserName and UserId String helloMessageString = "Hello, " + userName + "(" + userId + ")"; @@ -165,7 +181,11 @@ public TheQuestionUI(ControlContainer controlContainer, CardLayout cardLayout, } - + /** + * Handles user actions performed within the UI. + * + * @param e The ActionEvent representing the user action. + */ @Override public void actionPerformed(ActionEvent e) { String actionCommand = e.getActionCommand(); diff --git a/src/main/java/driver/screen/UIDesign.java b/src/main/java/driver/screen/UIDesign.java index dc992378..e171891c 100644 --- a/src/main/java/driver/screen/UIDesign.java +++ b/src/main/java/driver/screen/UIDesign.java @@ -6,6 +6,9 @@ import java.awt.*; import java.util.concurrent.Flow; +/** + * This class represents a consistent design settings and helper methods for UI components. + */ public class UIDesign { //All colors used in the UI public static Color lightGreenColor = new Color(202,216,209); diff --git a/src/main/java/driver/screen/WelcomeUI.java b/src/main/java/driver/screen/WelcomeUI.java index 5cb02c1a..6097ca9c 100644 --- a/src/main/java/driver/screen/WelcomeUI.java +++ b/src/main/java/driver/screen/WelcomeUI.java @@ -7,16 +7,26 @@ import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; -import java.rmi.server.UID; import static driver.screen.UIDesign.*; +/** + * This class represents the initial screen of the application where users can choose to register or log in. + */ public class WelcomeUI extends JPanel implements ActionListener { ControlContainer controlContainer; CardLayout cardLayout; JPanel screens; - public WelcomeUI (ControlContainer controlContainer, CardLayout cardLayout, JPanel screens){ + /** + * Constructs a WelcomeUI instance with the provided control container, + * card layout, and screens panel. + * + * @param controlContainer The container holding various controller instances. + * @param cardLayout The CardLayout used for managing screen transitions. + * @param screens The panel containing various screens. + */ + public WelcomeUI(ControlContainer controlContainer, CardLayout cardLayout, JPanel screens) { this.cardLayout = cardLayout; this.screens = screens; this.controlContainer = controlContainer; @@ -24,10 +34,12 @@ public WelcomeUI (ControlContainer controlContainer, CardLayout cardLayout, JPan setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + // Create and stylize the title label JLabel title = new JLabel("Welcome"); title.setAlignmentX(Component.CENTER_ALIGNMENT); UIDesign.setTitleFont(title); + // Add margin around the title int topMargin = 50; int leftMargin = 0; int bottomMargin = 100; @@ -36,42 +48,53 @@ public WelcomeUI (ControlContainer controlContainer, CardLayout cardLayout, JPan add(title); + // Create buttons panel for Register and Login options JPanel buttonsPanel = new JPanel(); buttonsPanel.setBackground(lightGreenColor); - buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS)); // Use X_AXIS for horizontal alignment + buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS)); + // Create Register and Login buttons and apply styling JButton registerButton = new JButton("Register"); JButton loginButton = new JButton("Login"); UIDesign.setButton(registerButton); UIDesign.setButton(loginButton); - buttonsPanel.add(Box.createHorizontalGlue()); // Add glue to push buttons to the left + // Add buttons to the panel with horizontal glue for alignment + buttonsPanel.add(Box.createHorizontalGlue()); buttonsPanel.add(registerButton); - buttonsPanel.add(Box.createHorizontalGlue()); // Add glue to push buttons to the center + buttonsPanel.add(Box.createHorizontalGlue()); buttonsPanel.add(loginButton); - buttonsPanel.add(Box.createHorizontalGlue()); // Add glue to push buttons to the right + buttonsPanel.add(Box.createHorizontalGlue()); + // Add action listeners to the buttons registerButton.addActionListener(this); loginButton.addActionListener(this); add(buttonsPanel); } + /** + * Handles user actions performed within the UI, such as button clicks. + * + * @param e The ActionEvent representing the user action. + */ @Override public void actionPerformed(ActionEvent e) { String actionCommand = e.getActionCommand(); - if ("Register".equals(actionCommand)){ + if ("Register".equals(actionCommand)) { + // Handle the Register button click RegisterUI registerUI = new RegisterUI(controlContainer); JScrollPane registerScrollPane = new JScrollPane(registerUI); screens.add(registerScrollPane, "Register"); cardLayout.show(screens, "Register"); System.out.println("User chooses register\nRegister screen showed"); - } else if ("Login".equals(actionCommand)){ + } else if ("Login".equals(actionCommand)) { + // Handle the Login button click LoginUI loginUI = new LoginUI(controlContainer); screens.add(loginUI, "Login"); cardLayout.show(screens, "Login"); System.out.println("User chooses login\nLogin screen showed"); } } -} +} \ No newline at end of file diff --git a/src/main/java/entity/Client.java b/src/main/java/entity/Client.java index 013fe674..10ec61c4 100644 --- a/src/main/java/entity/Client.java +++ b/src/main/java/entity/Client.java @@ -11,12 +11,9 @@ import java.util.Objects; /** - * This is a class representing client user. - * - * A Client is a registered user who seeks legal advice and assistance by posting questions + * Represents a client user who seeks legal advice and assistance by posting questions * to be answered by attorneys. */ - @Entity public class Client implements User { @Id @@ -44,10 +41,29 @@ public class Client implements User { @JsonProperty(required = true) private List questionsList; + /** + * Default constructor initializes fields and the list of questions. + */ public Client() { questionsList = new ArrayList(); } + /** + * Constructs a Client instance with provided details. + * + * @param userId The unique identifier of the client. + * @param userName The name of the client. + * @param email The email of the client. + * @param password The password of the client. + * @param stateAbb The state abbreviation of the client. + * @param postalCode The postal code of the client. + * @param ethnicity The ethnicity of the client. + * @param age The age of the client. + * @param gender The gender of the client. + * @param maritalStatus The marital status of the client. + * @param numberOfHousehold The number of people in the household of the client. + * @param annualIncome The annual income of the client. + */ public Client(int userId, String userName, String email, String password, String stateAbb, String postalCode, String ethnicity, int age, String gender, String maritalStatus, int numberOfHousehold, float annualIncome) { @@ -65,112 +81,261 @@ public Client(int userId, String userName, String email, String password, String this.annualIncome = annualIncome; this.questionsList = new ArrayList(); } - + /** + * Gets the user's id. + * @return The user's id. + */ @Override public int getUserId() { return userId; } - + /** + * Gets the user's password. + * @return The user's password. + */ @Override public String getPassword() { return password; } - public String getUserName() {return name;} + /** + * Gets the user's name. + * @return The user's name. + */ + public String getUserName() { + return name; + } + /** + * {@inheritDoc} + */ @Override - public String getEmail() {return email;} + public String getEmail() { + return email; + } + /** + * Gets the state abbreviation. + * @return The state abbreviation. + */ public String getStateAbb() { return stateAbb; } + /** + * Gets the postal code. + * @return The postal code. + */ public String getPostalCode() { return postalCode; } + /** + * Gets the ethnicity. + * @return The ethnicity. + */ public String getEthnicity() { return ethnicity; } + /** + * Gets the age. + * @return The age. + */ public int getAge() { return age; } + /** + * Gets the gender. + * @return The gender. + */ public String getGender() { return gender; } + /** + * Gets the marital status. + * @return The marital status. + */ public String getMaritalStatus() { return maritalStatus; } + /** + * Gets the number of household members. + * @return The number of household members. + */ public int getNumberOfHousehold() { return numberOfHousehold; } + /** + * Gets the annual income. + * @return The annual income. + */ public float getAnnualIncome() { return annualIncome; } + /** + * {@inheritDoc} + */ @Override - public List getQuestionsList() {return questionsList;} + public List getQuestionsList() { + return questionsList; + } - public void setUserId(int userId) {this.userId = userId;} + /** + * Sets the user ID. + * @param userId The user ID to set. + */ + public void setUserId(int userId) { + this.userId = userId; + } - public void setUserName(String userName) {this.name = userName;} + /** + * Sets the user name. + * @param userName The user name to set. + */ + public void setUserName(String userName) { + this.name = userName; + } - public void setEmail(String email) {this.email = email;} + /** + * Sets the email. + * @param email The email to set. + */ + public void setEmail(String email) { + this.email = email; + } - public void setPassword(String password) {this.password = password;} + /** + * Sets the password. + * @param password The password to set. + */ + public void setPassword(String password) { + this.password = password; + } - public void setStateAbb(String stateAbb) {this.stateAbb = stateAbb;} + /** + * Sets the state abbreviation. + * @param stateAbb The state abbreviation to set. + */ + public void setStateAbb(String stateAbb) { + this.stateAbb = stateAbb; + } - public void setPostalCode(String postalCode) {this.postalCode = postalCode;} + /** + * Sets the postal code. + * @param postalCode The postal code to set. + */ + public void setPostalCode(String postalCode) { + this.postalCode = postalCode; + } - public void setEthnicity(String ethnicity) {this.ethnicity = ethnicity;} + /** + * Sets the ethnicity. + * @param ethnicity The ethnicity to set. + */ + public void setEthnicity(String ethnicity) { + this.ethnicity = ethnicity; + } - public void setAge(int age) {this.age = age;} + /** + * Sets the age. + * @param age The age to set. + */ + public void setAge(int age) { + this.age = age; + } - public void setGender(String gender) {this.gender = gender;} + /** + * Sets the gender. + * @param gender The gender to set. + */ + public void setGender(String gender) { + this.gender = gender; + } - public void setMaritalStatus(String maritalStatus) {this.maritalStatus = maritalStatus;} + /** + * Sets the marital status. + * @param maritalStatus The marital status to set. + */ + public void setMaritalStatus(String maritalStatus) { + this.maritalStatus = maritalStatus; + } - public void setNumberOfHousehold(int numberOfHousehold) {this.numberOfHousehold = numberOfHousehold;} + /** + * Sets the number of household members. + * @param numberOfHousehold The number of household members to set. + */ + public void setNumberOfHousehold(int numberOfHousehold) { + this.numberOfHousehold = numberOfHousehold; + } - public void setAnnualIncome(float annualIncome) {this.annualIncome = annualIncome;} + /** + * Sets the annual income. + * @param annualIncome The annual income to set. + */ + public void setAnnualIncome(float annualIncome) { + this.annualIncome = annualIncome; + } + /** + * {@inheritDoc} + */ @Override public void addQuestion(Question question) { - if (! questionsList.contains(question)) { + if (!questionsList.contains(question)) { questionsList.add(question); } } + /** + * {@inheritDoc} + */ @Override public boolean isClient() { return true; } + /** + * {@inheritDoc} + */ @Override public boolean isQuestionCloseable(Question question) { boolean isClose = question.isClose(); return !isClose; } + /** + * {@inheritDoc} + */ @Override public boolean isQuestionSelectable(Question question) { return true; } + /** + * {@inheritDoc} + */ @Override public boolean isQuestionReplyable(Question question) { return !question.isClose(); } + /** + * {@inheritDoc} + */ @Override - public int hashCode() {return Objects.hashCode(userId);} + public int hashCode() { + return Objects.hashCode(userId); + } + /** + * {@inheritDoc} + */ @Override public boolean equals(Object obj) { if (!(obj instanceof Client)) return false; @@ -178,15 +343,20 @@ public boolean equals(Object obj) { return userId == otherClient.userId; } + /** + * {@inheritDoc} + */ @Override public String toString() { return String.format("[Client]: %s", name); } + /** + * {@inheritDoc} + */ @Override public boolean isQuestionRateable(Question question) { return question.isClose(); } } - diff --git a/src/main/java/entity/Post.java b/src/main/java/entity/Post.java index 0b566941..f8b6f693 100644 --- a/src/main/java/entity/Post.java +++ b/src/main/java/entity/Post.java @@ -8,14 +8,13 @@ import java.util.Objects; /** - * This is a class representing a post in a question thread. + * This class represents a post in a question thread. * * A "Post" is a message or response posted in the context of a specific question thread. * Each post contains information such as the ID of the associated question, the post ID, * the creation date, the text of the post, and an identifier indicating which user the post * belongs to. */ - @Entity public class Post { @JsonProperty(required = true) @@ -33,6 +32,15 @@ public class Post { public Post() { } + /** + * Constructs a new Post instance. + * + * @param questionId The ID of the associated question. + * @param postId The ID of the post. + * @param createAt The creation date of the post. + * @param postText The text of the post. + * @param belongsTo The identifier of the user to whom the post belongs. + */ public Post(int questionId, int postId, LocalDate createAt, String postText, int belongsTo){ this.questionId = questionId; this.postId = postId; @@ -41,37 +49,93 @@ public Post(int questionId, int postId, LocalDate createAt, String postText, int this.belongsTo = belongsTo; } + /** + * Gets the ID of the associated question. + * + * @return The question ID. + */ public int getQuestionId() { return questionId; } + /** + * Gets the ID of the post. + * + * @return The post ID. + */ public int getPostId() { return postId; } + /** + * Gets the creation date of the post. + * + * @return The creation date. + */ public LocalDate getCreateAt() { return createAt; } + /** + * Gets the text of the post. + * + * @return The post text. + */ public String getPostText() { return postText; } + /** + * Gets the identifier of the user to whom the post belongs. + * + * @return The user identifier. + */ public int getBelongsTo() {return belongsTo;} + /** + * Sets the ID of the associated question. + * + * @param questionId The question ID to set. + */ public void setQuestionId(int questionId) {this.questionId = questionId;} + /** + * Sets the ID of the post. + * + * @param postId The post ID to set. + */ public void setPostId(int postId) {this.postId = postId;} + /** + * Sets the creation date of the post. + * + * @param createAt The creation date to set. + */ public void setCreateAt(LocalDate createAt) {this.createAt = createAt;} + /** + * Sets the text of the post. + * + * @param postText The post text to set. + */ public void setPostText(String postText) {this.postText = postText;} + /** + * Sets the identifier of the user to whom the post belongs. + * + * @param belongsTo The user identifier to set. + */ public void setBelongsTo(int belongsTo) {this.belongsTo = belongsTo;} + /** + * {@inheritDoc} + */ @Override public int hashCode() {return Objects.hashCode(postId);} + /** + * {@inheritDoc} + */ @Override public boolean equals(Object obj) { if (!(obj instanceof Post)) return false; @@ -79,8 +143,11 @@ public boolean equals(Object obj) { return postId == otherPost.postId; } + /** + * {@inheritDoc} + */ @Override public String toString() { return String.format("This is a post in %d belongs to %d", questionId, belongsTo); } -} +} \ No newline at end of file diff --git a/src/main/java/entity/Question.java b/src/main/java/entity/Question.java index 586aacf8..b532b49a 100644 --- a/src/main/java/entity/Question.java +++ b/src/main/java/entity/Question.java @@ -12,10 +12,10 @@ import java.util.Objects; /** - * This is a class representing a question thread. + * This class represents a question thread. * - * Each question thread contain information about the type of the question, the client who asked the question, - * whether the question has been taken and who took the question, and a list of post belongs to the question. + * Each question thread contains information about the type of the question, the client who asked the question, + * whether the question has been taken and by whom, and a list of posts belonging to the question. */ @Entity public class Question { @@ -46,12 +46,21 @@ public class Question { private List posts; public static final int MISSING_RATING = -1; - public Question() { rating = MISSING_RATING; posts = new ArrayList(); } + /** + * Constructs a new Question instance. + * + * @param questionId The ID of the question. + * @param type The type of the question. + * @param title The title of the question. + * @param createAt The creation date of the question. + * @param askedByClient The ID of the client who asked the question. + * @param legalDeadline The legal deadline for the question. + */ public Question(int questionId, String type, String title, LocalDate createAt, int askedByClient, LocalDate legalDeadline) { this.questionId = questionId; this.type = type; @@ -63,63 +72,197 @@ public Question(int questionId, String type, String title, LocalDate createAt, i this.posts = new ArrayList(); } + /** + * Gets the ID of the question. + * + * @return The question ID. + */ public int getQuestionId() {return questionId;} + /** + * Gets the type of the question. + * + * @return The question type. + */ public String getType() {return type;} + /** + * Gets the title of the question. + * + * @return The question title. + */ public String getTitle() { return title; } + /** + * Gets the creation date of the question. + * + * @return The creation date. + */ public LocalDate getCreateAt() {return createAt;} + /** + * Gets the ID of the client who asked the question. + * + * @return The client ID. + */ public int getAskedByClient() {return askedByClient;} + /** + * Gets the legal deadline for the question. + * + * @return The legal deadline. + */ public LocalDate getLegalDeadline() {return legalDeadline;} + /** + * Checks if the question has been taken. + * + * @return True if the question is taken, false otherwise. + */ public boolean isTaken() {return isTaken;} + /** + * Gets the ID of the attorney who took the question. + * + * @return The attorney ID. + */ public int getTakenByAttorney() {return takenByAttorney;} + /** + * Gets the date when the question was taken. + * + * @return The taken date. + */ public LocalDate getTakenAt() {return takenAt;} + /** + * Checks if the question is closed. + * + * @return True if the question is closed, false otherwise. + */ public boolean isClose() {return isClose;} + /** + * Gets the rating of the question. + * + * @return The question rating. + */ public int getRating() {return rating;} + /** + * Gets the list of posts belonging to the question. + * + * @return The list of posts. + */ public List getPosts() {return posts;} + /** + * Sets the ID of the question. + * + * @param questionId The question ID to set. + */ public void setQuestionId(int questionId) {this.questionId = questionId;} + /** + * Sets the type of the question. + * + * @param type The question type to set. + */ public void setType(String type) {this.type = type;} + /** + * Sets the title of the question. + * + * @param title The question title to set. + */ public void setTitle(String title) {this.title = title;} + /** + * Sets the creation date of the question. + * + * @param createAt The creation date to set. + */ public void setCreateAt(LocalDate createAt) {this.createAt = createAt;} + /** + * Sets the ID of the client who asked the question. + * + * @param askedByClient The client ID to set. + */ public void setAskedByClient(int askedByClient) {this.askedByClient = askedByClient;} + /** + * Sets the legal deadline for the question. + * + * @param legalDeadline The legal deadline to set. + */ public void setLegalDeadline(LocalDate legalDeadline) {this.legalDeadline = legalDeadline;} + /** + * Sets whether the question is taken or not. + * + * @param taken True if taken, false otherwise. + */ public void setTaken(boolean taken) {isTaken = taken;} + /** + * Sets the ID of the attorney who took the question. + * + * @param takenByAttorney The attorney ID to set. + */ public void setTakenByAttorney(int takenByAttorney) {this.takenByAttorney = takenByAttorney;} + /** + * Sets the date when the question was taken. + * + * @param takenAt The taken date to set. + */ public void setTakenAt(LocalDate takenAt) {this.takenAt = takenAt;} + /** + * Sets whether the question is closed or not. + * + * @param close True if closed, false otherwise. + */ public void setClose(boolean close) {isClose = close;} + /** + * Sets the rating of the question. + * + * @param rating The question rating to set. + */ public void setRating(int rating) {this.rating = rating;} + /** + * Adds a post to the list of posts belonging to the question. + * + * @param post The post to add. + */ public void addPosts(Post post) { - if (! posts.contains(post)) { + if (!posts.contains(post)) { posts.add(post); } } + + /** + * Generates a hash code for the Question object based on its questionId. + * + * @return The hash code value. + */ @Override - public int hashCode() {return Objects.hashCode(questionId);} + public int hashCode() { + return Objects.hashCode(questionId); + } + /** + * Compares this Question object with another object to determine equality. + * + * @param obj The object to compare with. + * @return True if the objects are equal, false otherwise. + */ @Override public boolean equals(Object obj) { if (!(obj instanceof Question)) return false; @@ -127,8 +270,12 @@ public boolean equals(Object obj) { return questionId == otherQuestion.questionId; } + /** + * Returns a string representation of the Question object. + * + * @return The formatted string. + */ @Override public String toString() { return String.format("This is a %s type question asked by %d", type, askedByClient); - } -} + } \ No newline at end of file diff --git a/src/main/java/entity/User.java b/src/main/java/entity/User.java index f5711285..6ae9f745 100644 --- a/src/main/java/entity/User.java +++ b/src/main/java/entity/User.java @@ -1,14 +1,12 @@ package entity; +import java.util.List; + +import javax.persistence.Entity; /** * The "User" interface represents a generic user in the system. * This interface defines common methods that are shared by different types of users in the application, */ - -import java.util.List; - -import javax.persistence.Entity; - public interface User { int getUserId(); String getUserName(); From 2b1c258ee46593d12d55a0571635af91365f8069 Mon Sep 17 00:00:00 2001 From: river3966 Date: Wed, 9 Aug 2023 01:26:34 -0400 Subject: [PATCH 06/24] documentation --- src/main/java/entity/Question.java | 99 ++++++++++++++++++++++-------- 1 file changed, 72 insertions(+), 27 deletions(-) diff --git a/src/main/java/entity/Question.java b/src/main/java/entity/Question.java index b532b49a..48dc3de1 100644 --- a/src/main/java/entity/Question.java +++ b/src/main/java/entity/Question.java @@ -54,10 +54,10 @@ public Question() { /** * Constructs a new Question instance. * - * @param questionId The ID of the question. - * @param type The type of the question. - * @param title The title of the question. - * @param createAt The creation date of the question. + * @param questionId The ID of the question. + * @param type The type of the question. + * @param title The title of the question. + * @param createAt The creation date of the question. * @param askedByClient The ID of the client who asked the question. * @param legalDeadline The legal deadline for the question. */ @@ -77,14 +77,18 @@ public Question(int questionId, String type, String title, LocalDate createAt, i * * @return The question ID. */ - public int getQuestionId() {return questionId;} + public int getQuestionId() { + return questionId; + } /** * Gets the type of the question. * * @return The question type. */ - public String getType() {return type;} + public String getType() { + return type; + } /** * Gets the title of the question. @@ -100,140 +104,180 @@ public String getTitle() { * * @return The creation date. */ - public LocalDate getCreateAt() {return createAt;} + public LocalDate getCreateAt() { + return createAt; + } /** * Gets the ID of the client who asked the question. * * @return The client ID. */ - public int getAskedByClient() {return askedByClient;} + public int getAskedByClient() { + return askedByClient; + } /** * Gets the legal deadline for the question. * * @return The legal deadline. */ - public LocalDate getLegalDeadline() {return legalDeadline;} + public LocalDate getLegalDeadline() { + return legalDeadline; + } /** * Checks if the question has been taken. * * @return True if the question is taken, false otherwise. */ - public boolean isTaken() {return isTaken;} + public boolean isTaken() { + return isTaken; + } /** * Gets the ID of the attorney who took the question. * * @return The attorney ID. */ - public int getTakenByAttorney() {return takenByAttorney;} + public int getTakenByAttorney() { + return takenByAttorney; + } /** * Gets the date when the question was taken. * * @return The taken date. */ - public LocalDate getTakenAt() {return takenAt;} + public LocalDate getTakenAt() { + return takenAt; + } /** * Checks if the question is closed. * * @return True if the question is closed, false otherwise. */ - public boolean isClose() {return isClose;} + public boolean isClose() { + return isClose; + } /** * Gets the rating of the question. * * @return The question rating. */ - public int getRating() {return rating;} + public int getRating() { + return rating; + } /** * Gets the list of posts belonging to the question. * * @return The list of posts. */ - public List getPosts() {return posts;} + public List getPosts() { + return posts; + } /** * Sets the ID of the question. * * @param questionId The question ID to set. */ - public void setQuestionId(int questionId) {this.questionId = questionId;} + public void setQuestionId(int questionId) { + this.questionId = questionId; + } /** * Sets the type of the question. * * @param type The question type to set. */ - public void setType(String type) {this.type = type;} + public void setType(String type) { + this.type = type; + } /** * Sets the title of the question. * * @param title The question title to set. */ - public void setTitle(String title) {this.title = title;} + public void setTitle(String title) { + this.title = title; + } /** * Sets the creation date of the question. * * @param createAt The creation date to set. */ - public void setCreateAt(LocalDate createAt) {this.createAt = createAt;} + public void setCreateAt(LocalDate createAt) { + this.createAt = createAt; + } /** * Sets the ID of the client who asked the question. * * @param askedByClient The client ID to set. */ - public void setAskedByClient(int askedByClient) {this.askedByClient = askedByClient;} + public void setAskedByClient(int askedByClient) { + this.askedByClient = askedByClient; + } /** * Sets the legal deadline for the question. * * @param legalDeadline The legal deadline to set. */ - public void setLegalDeadline(LocalDate legalDeadline) {this.legalDeadline = legalDeadline;} + public void setLegalDeadline(LocalDate legalDeadline) { + this.legalDeadline = legalDeadline; + } /** * Sets whether the question is taken or not. * * @param taken True if taken, false otherwise. */ - public void setTaken(boolean taken) {isTaken = taken;} + public void setTaken(boolean taken) { + isTaken = taken; + } /** * Sets the ID of the attorney who took the question. * * @param takenByAttorney The attorney ID to set. */ - public void setTakenByAttorney(int takenByAttorney) {this.takenByAttorney = takenByAttorney;} + public void setTakenByAttorney(int takenByAttorney) { + this.takenByAttorney = takenByAttorney; + } /** * Sets the date when the question was taken. * * @param takenAt The taken date to set. */ - public void setTakenAt(LocalDate takenAt) {this.takenAt = takenAt;} + public void setTakenAt(LocalDate takenAt) { + this.takenAt = takenAt; + } /** * Sets whether the question is closed or not. * * @param close True if closed, false otherwise. */ - public void setClose(boolean close) {isClose = close;} + public void setClose(boolean close) { + isClose = close; + } /** * Sets the rating of the question. * * @param rating The question rating to set. */ - public void setRating(int rating) {this.rating = rating;} + public void setRating(int rating) { + this.rating = rating; + } /** * Adds a post to the list of posts belonging to the question. @@ -278,4 +322,5 @@ public boolean equals(Object obj) { @Override public String toString() { return String.format("This is a %s type question asked by %d", type, askedByClient); - } \ No newline at end of file + } +} \ No newline at end of file From e6d3c84a950f50d917821bad75b2778d1448790e Mon Sep 17 00:00:00 2001 From: river3966 Date: Fri, 11 Aug 2023 10:07:56 -0400 Subject: [PATCH 07/24] small --- src/main/java/AttorneyRegister.java | 237 +++++++++++++++++++++++++++- 1 file changed, 235 insertions(+), 2 deletions(-) diff --git a/src/main/java/AttorneyRegister.java b/src/main/java/AttorneyRegister.java index f1f26fe1..176b00c0 100644 --- a/src/main/java/AttorneyRegister.java +++ b/src/main/java/AttorneyRegister.java @@ -1,10 +1,243 @@ import driver.database.AttorneyRepository; import entity.Attorney; + public class AttorneyRegister { public static void main(String[] args) { AttorneyRepository attorneyRepository = new AttorneyRepository(); - Attorney attorney1 = new Attorney(); - attorneyRepository.save(attorney1); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + +// ------------------------------------------------ + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + AttorneyRepository attorneyRepository = new AttorneyRepository(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); + Set professionals = new HashSet<>(); + professionals.add("Family and Children"); + professionals.add("Housing and Homelessness"); + professionals.add("Education"); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + registrationData.setUserId(12345678); + Attorney cathy = attorneyFactory.createUser(registrationData); + attorneyRepository.save(cathy); + + + } } From 85a20b6969358350f9c834b938e5187a14cd35be Mon Sep 17 00:00:00 2001 From: river3966 Date: Fri, 11 Aug 2023 10:51:13 -0400 Subject: [PATCH 08/24] small --- src/main/java/AttorneyRegister.java | 266 +++++----------------------- 1 file changed, 43 insertions(+), 223 deletions(-) diff --git a/src/main/java/AttorneyRegister.java b/src/main/java/AttorneyRegister.java index 176b00c0..3b83efbf 100644 --- a/src/main/java/AttorneyRegister.java +++ b/src/main/java/AttorneyRegister.java @@ -1,6 +1,6 @@ import driver.database.AttorneyRepository; import entity.Attorney; - +import AttorneyFactory public class AttorneyRegister { public static void main(String[] args) { @@ -10,233 +10,53 @@ public static void main(String[] args) { professionals.add("Family and Children"); professionals.add("Housing and Homelessness"); professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); + RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", + "12345678", "CA", "12345", professionals); registrationData.setUserId(12345678); Attorney cathy = attorneyFactory.createUser(registrationData); attorneyRepository.save(cathy); // ------------------------------------------------ - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - - - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - + AttorneyRepository attorneyRepository2 = new AttorneyRepository(); + AttorneyFactory attorneyFactory2 = new AttorneyFactory(); + Set professionals2 = new HashSet<>(); + professionals2.add("Family and Children"); + RegistrationData registrationData2 = new RegistrationData("a2", "zihan.yuan@mail.utoronto.ca", "12345678", + "12345678", "CA", "12345", professionals2); + registrationData2.setUserId(12345678); + Attorney a2 = attorneyFactory2.createUser(registrationData); + attorneyRepository2.save(a2); + + + AttorneyRepository attorneyRepository3 = new AttorneyRepository(); + AttorneyFactory attorneyFactory3 = new AttorneyFactory(); + Set professionals3 = new HashSet<>(); + professionals3.add("Housing and Homelessness"); + RegistrationData registrationData3 = new RegistrationData("a3", "zihan.yuan@mail.utoronto.ca", "12345678", + "12345678", "CA", "12345", professionals3); + registrationData3.setUserId(12345678); + Attorney a3 = attorneyFactory3.createUser(registrationData); + attorneyRepository3.save(a3); + + AttorneyRepository attorneyRepository4 = new AttorneyRepository(); + AttorneyFactory attorneyFactory4 = new AttorneyFactory(); + Set professionals4 = new HashSet<>(); + professionals4.add("Housing and Homelessness"); + RegistrationData registrationData4 = new RegistrationData("a4", "zihan.yuan@mail.utoronto.ca", + "12345678", "12345678", "CA", "12345", professionals4); + registrationData4.setUserId(12345678); + Attorney a4 = attorneyFactory4.createUser(registrationData); + attorneyRepository4.save(a4); + + AttorneyRepository attorneyRepository5 = new AttorneyRepository(); + AttorneyFactory attorneyFactory5 = new AttorneyFactory(); + Set professionals5 = new HashSet<>(); + professionals5.add("Housing and Homelessness"); + RegistrationData registrationData5 = new RegistrationData("a5", "zihan.yuan@mail.utoronto.ca", + "12345678", "12345678", "CA", "12345", professionals5); + registrationData5.setUserId(12345678); + Attorney a5 = attorneyFactory5.createUser(registrationData); + attorneyRepository5.save(a5); } From 3ef97bf980a01d3d69fc93cc86ee40e1670ce856 Mon Sep 17 00:00:00 2001 From: river3966 Date: Fri, 11 Aug 2023 11:20:30 -0400 Subject: [PATCH 09/24] create all attorney --- src/main/java/AttorneyRegister.java | 185 +++++++++++++++++++++++++--- 1 file changed, 170 insertions(+), 15 deletions(-) diff --git a/src/main/java/AttorneyRegister.java b/src/main/java/AttorneyRegister.java index 3b83efbf..70a184ba 100644 --- a/src/main/java/AttorneyRegister.java +++ b/src/main/java/AttorneyRegister.java @@ -1,6 +1,11 @@ +import businessrule.requestmodel.RegistrationData; import driver.database.AttorneyRepository; import entity.Attorney; -import AttorneyFactory +import entity.factory.AttorneyFactory; + +import java.util.HashSet; +import java.util.Set; + public class AttorneyRegister { public static void main(String[] args) { @@ -21,43 +26,193 @@ public static void main(String[] args) { AttorneyFactory attorneyFactory2 = new AttorneyFactory(); Set professionals2 = new HashSet<>(); professionals2.add("Family and Children"); - RegistrationData registrationData2 = new RegistrationData("a2", "zihan.yuan@mail.utoronto.ca", "12345678", + RegistrationData registrationData2 = new RegistrationData("a2", "ihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals2); - registrationData2.setUserId(12345678); - Attorney a2 = attorneyFactory2.createUser(registrationData); + registrationData2.setUserId(123456781); + Attorney a2 = attorneyFactory2.createUser(registrationData2); attorneyRepository2.save(a2); AttorneyRepository attorneyRepository3 = new AttorneyRepository(); AttorneyFactory attorneyFactory3 = new AttorneyFactory(); Set professionals3 = new HashSet<>(); - professionals3.add("Housing and Homelessness"); - RegistrationData registrationData3 = new RegistrationData("a3", "zihan.yuan@mail.utoronto.ca", "12345678", + professionals3.add("Consumer Financial Questions"); + RegistrationData registrationData3 = new RegistrationData("a3", "ihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals3); - registrationData3.setUserId(12345678); - Attorney a3 = attorneyFactory3.createUser(registrationData); + registrationData3.setUserId(123456782); + Attorney a3 = attorneyFactory3.createUser(registrationData3); attorneyRepository3.save(a3); AttorneyRepository attorneyRepository4 = new AttorneyRepository(); AttorneyFactory attorneyFactory4 = new AttorneyFactory(); Set professionals4 = new HashSet<>(); professionals4.add("Housing and Homelessness"); - RegistrationData registrationData4 = new RegistrationData("a4", "zihan.yuan@mail.utoronto.ca", + RegistrationData registrationData4 = new RegistrationData("a4", "ihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals4); - registrationData4.setUserId(12345678); - Attorney a4 = attorneyFactory4.createUser(registrationData); + registrationData4.setUserId(123456783); + Attorney a4 = attorneyFactory4.createUser(registrationData4); attorneyRepository4.save(a4); AttorneyRepository attorneyRepository5 = new AttorneyRepository(); AttorneyFactory attorneyFactory5 = new AttorneyFactory(); Set professionals5 = new HashSet<>(); - professionals5.add("Housing and Homelessness"); - RegistrationData registrationData5 = new RegistrationData("a5", "zihan.yuan@mail.utoronto.ca", + professionals5.add(" Individual Rights"); + RegistrationData registrationData5 = new RegistrationData("a5", "ihan.yuan@mail.utoronto.ca", "12345678", "12345678", "CA", "12345", professionals5); - registrationData5.setUserId(12345678); - Attorney a5 = attorneyFactory5.createUser(registrationData); + registrationData5.setUserId(123456784); + Attorney a5 = attorneyFactory5.createUser(registrationData5); attorneyRepository5.save(a5); + AttorneyRepository attorneyRepository6 = new AttorneyRepository(); + AttorneyFactory attorneyFactory6 = new AttorneyFactory(); + Set professionals6 = new HashSet<>(); + professionals6.add("Income Maintenance"); + RegistrationData registrationData6 = new RegistrationData("a6", "ihan.yuan@mail.utoronto.ca", + "12345678", "12345678", "CA", "12345", professionals6); + registrationData6.setUserId(123456785); + Attorney a6 = attorneyFactory6.createUser(registrationData6); + attorneyRepository6.save(a6); + + AttorneyRepository attorneyRepository7 = new AttorneyRepository(); + AttorneyFactory attorneyFactory7 = new AttorneyFactory(); + Set professionals7 = new HashSet<>(); + professionals7.add("Health and Disability"); + RegistrationData registrationData7 = new RegistrationData("a7", "ihan.yuan@mail.utoronto.ca", + "12345678", "12345678", "CA", "12345", professionals7); + registrationData7.setUserId(123456786); + Attorney a7 = attorneyFactory7.createUser(registrationData7); + attorneyRepository7.save(a7); + + AttorneyRepository attorneyRepository8 = new AttorneyRepository(); + AttorneyFactory attorneyFactory8 = new AttorneyFactory(); + Set professionals8 = new HashSet<>(); + professionals8.add("Work, Employment and Unemployment"); + RegistrationData registrationData8 = new RegistrationData("a8", "ihan.yuan@mail.utoronto.ca", + "12345678", "12345678", "CA", "12345", professionals8); + registrationData8.setUserId(123456787); + Attorney a8 = attorneyFactory8.createUser(registrationData8); + attorneyRepository8.save(a8); + + AttorneyRepository attorneyRepository9 = new AttorneyRepository(); + AttorneyFactory attorneyFactory9 = new AttorneyFactory(); + Set professionals9 = new HashSet<>(); + professionals9.add("Juvenile"); + RegistrationData registrationData9 = new RegistrationData("a9", "ihan.yuan@mail.utoronto.ca", + "12345678", "12345678", "CA", "12345", professionals9); + registrationData9.setUserId(123456788); + Attorney a9 = attorneyFactory9.createUser(registrationData9); + attorneyRepository9.save(a9); + + AttorneyRepository attorneyRepository10 = new AttorneyRepository(); + AttorneyFactory attorneyFactory10 = new AttorneyFactory(); + Set professionals10 = new HashSet<>(); + professionals10.add("Education"); + RegistrationData registrationData10 = new RegistrationData("a10", "ihan.yuan@mail.utoronto.ca", + "12345678", "12345678", "CA", "12345", professionals10); + registrationData10.setUserId(123456789); + Attorney a10 = attorneyFactory10.createUser(registrationData10); + attorneyRepository10.save(a10); + + AttorneyRepository attorneyRepository21 = new AttorneyRepository(); + AttorneyFactory attorneyFactory21 = new AttorneyFactory(); + Set professionals21 = new HashSet<>(); + professionals21.add("Family and Children"); + RegistrationData registrationData21 = new RegistrationData("a21", "zhan.yuan@mail.utoronto.ca", "12345678", + "12345678", "CA", "12345", professionals21); + registrationData21.setUserId(1234567810); + Attorney a21 = attorneyFactory21.createUser(registrationData21); + attorneyRepository21.save(a21); + + + AttorneyRepository attorneyRepository31 = new AttorneyRepository(); + AttorneyFactory attorneyFactory31 = new AttorneyFactory(); + Set professionals31 = new HashSet<>(); + professionals31.add("Consumer Financial Questions"); + RegistrationData registrationData31 = new RegistrationData("a31", "zhan.yuan@mail.utoronto.ca", "12345678", + "12345678", "CA", "12345", professionals31); + registrationData31.setUserId(1234567811); + Attorney a31 = attorneyFactory31.createUser(registrationData31); + attorneyRepository31.save(a31); + + AttorneyRepository attorneyRepository41 = new AttorneyRepository(); + AttorneyFactory attorneyFactory41 = new AttorneyFactory(); + Set professionals41 = new HashSet<>(); + professionals41.add("Housing and Homelessness"); + RegistrationData registrationData41 = new RegistrationData("a41", "ihan.yuan@mail.utoronto.ca", + "12345678", "12345678", "CA", "12345", professionals41); + registrationData41.setUserId(1234567812); + Attorney a41 = attorneyFactory41.createUser(registrationData41); + attorneyRepository41.save(a41); + + AttorneyRepository attorneyRepository51 = new AttorneyRepository(); + AttorneyFactory attorneyFactory51 = new AttorneyFactory(); + Set professionals51 = new HashSet<>(); + professionals51.add(" Individual Rights"); + RegistrationData registrationData51 = new RegistrationData("a51", "ihan.yuan@mail.utoronto.ca", + "12345678", "12345678", "CA", "12345", professionals51); + registrationData51.setUserId(1234567813); + Attorney a51 = attorneyFactory51.createUser(registrationData51); + attorneyRepository5.save(a51); + + AttorneyRepository attorneyRepository61 = new AttorneyRepository(); + AttorneyFactory attorneyFactory61 = new AttorneyFactory(); + Set professionals61 = new HashSet<>(); + professionals61.add("Income Maintenance"); + RegistrationData registrationData61 = new RegistrationData("a61", "zhan.yuan@mail.utoronto.ca", + "12345678", "12345678", "CA", "12345", professionals61); + registrationData61.setUserId(1234567814); + Attorney a61 = attorneyFactory61.createUser(registrationData61); + attorneyRepository61.save(a61); + + AttorneyRepository attorneyRepository71 = new AttorneyRepository(); + AttorneyFactory attorneyFactory71 = new AttorneyFactory(); + Set professionals71 = new HashSet<>(); + professionals71.add("Health and Disability"); + RegistrationData registrationData71 = new RegistrationData("a71", "ihan.yuan@mail.utoronto.ca", + "12345678", "12345678", "CA", "12345", professionals71); + registrationData71.setUserId(1234567815); + Attorney a71 = attorneyFactory7.createUser(registrationData71); + attorneyRepository71.save(a71); + + AttorneyRepository attorneyRepository81 = new AttorneyRepository(); + AttorneyFactory attorneyFactory81 = new AttorneyFactory(); + Set professionals81 = new HashSet<>(); + professionals81.add("Work, Employment and Unemployment"); + RegistrationData registrationData81 = new RegistrationData("a81", "ihan.yuan@mail.utoronto.ca", + "12345678", "12345678", "CA", "12345", professionals81); + registrationData81.setUserId(1234567816); + Attorney a81 = attorneyFactory81.createUser(registrationData81); + attorneyRepository81.save(a81); + + AttorneyRepository attorneyRepository91 = new AttorneyRepository(); + AttorneyFactory attorneyFactory91 = new AttorneyFactory(); + Set professionals91 = new HashSet<>(); + professionals91.add("Juvenile"); + RegistrationData registrationData91 = new RegistrationData("a91", "ihan.yuan@mail.utoronto.ca", + "12345678", "12345678", "CA", "12345", professionals91); + registrationData91.setUserId(1234567817); + Attorney a91 = attorneyFactory91.createUser(registrationData91); + attorneyRepository91.save(a91); + + AttorneyRepository attorneyRepository101 = new AttorneyRepository(); + AttorneyFactory attorneyFactory101 = new AttorneyFactory(); + Set professionals101 = new HashSet<>(); + professionals101.add("Education"); + RegistrationData registrationData101 = new RegistrationData("a101", "ihan.yuan@mail.utoronto.ca", + "12345678", "12345678", "CA", "12345", professionals101); + registrationData101.setUserId(1234567818); + Attorney a101 = attorneyFactory101.createUser(registrationData101); + attorneyRepository101.save(a101); + + AttorneyRepository attorneyRepository12 = new AttorneyRepository(); + AttorneyFactory attorneyFactory12 = new AttorneyFactory(); + Set professionals12 = new HashSet<>(); + professionals12.add("Education"); + RegistrationData registrationData12 = new RegistrationData("a12", "ihan.yuan@mail.utoronto.ca", + "12345678", "12345678", "CA", "12345", professionals12); + registrationData12.setUserId(1234567819); + Attorney a12 = attorneyFactory12.createUser(registrationData12); + attorneyRepository12.save(a12); } } From 6ebe86075af1f54e5c00ee8e2f976a5b6f7aae72 Mon Sep 17 00:00:00 2001 From: river3966 Date: Fri, 11 Aug 2023 11:30:47 -0400 Subject: [PATCH 10/24] ok --- src/main/java/AttorneyRegister.java | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/AttorneyRegister.java b/src/main/java/AttorneyRegister.java index 70a184ba..f4ab33e4 100644 --- a/src/main/java/AttorneyRegister.java +++ b/src/main/java/AttorneyRegister.java @@ -9,17 +9,17 @@ public class AttorneyRegister { public static void main(String[] args) { - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", - "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); +// AttorneyRepository attorneyRepository = new AttorneyRepository(); +// AttorneyFactory attorneyFactory = new AttorneyFactory(); +// Set professionals = new HashSet<>(); +// professionals.add("Family and Children"); +// professionals.add("Housing and Homelessness"); +// professionals.add("Education"); +// RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", +// "12345678", "CA", "12345", professionals); +// registrationData.setUserId(12345678); +// Attorney cathy = attorneyFactory.createUser(registrationData); +// attorneyRepository.save(cathy); // ------------------------------------------------ AttorneyRepository attorneyRepository2 = new AttorneyRepository(); From 7b60f36428530b3ca6a0b0aabf63c0260648697c Mon Sep 17 00:00:00 2001 From: river3966 Date: Sat, 12 Aug 2023 17:57:53 -0400 Subject: [PATCH 11/24] ok --- .../controller/ClientRegisterControl.java | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/main/java/adapter/controller/ClientRegisterControl.java b/src/main/java/adapter/controller/ClientRegisterControl.java index 670c7f46..60fa1d7a 100644 --- a/src/main/java/adapter/controller/ClientRegisterControl.java +++ b/src/main/java/adapter/controller/ClientRegisterControl.java @@ -4,19 +4,45 @@ import businessrule.requestmodel.RegistrationData; import businessrule.responsemodel.RegisterResponseModel; +/** + * This class represents responsible for handling user registration. + */ public class ClientRegisterControl { + private final UserRegisterInputBoundary inputBoundary; + /** + * Constructs a new instance of ClientRegisterControl. + * + * @param inputBoundary The input boundary for user registration. + */ public ClientRegisterControl(UserRegisterInputBoundary inputBoundary) { this.inputBoundary = inputBoundary; } - public RegisterResponseModel create(String userName, String email, String password1, String password2, - String StateAbb, String PostalCode, - String ethnicity, int age, String gender, String maritalStatus, - int numberOfHousehold, float annualIncome){ + /** + * Creates a new user registration based on the provided information. + * + * @param userName The username of the user. + * @param email The email address of the user. + * @param password1 The first password. + * @param password2 The confirmation password. + * @param StateAbb The state abbreviation. + * @param PostalCode The postal code. + * @param ethnicity The ethnicity of the user. + * @param age The age of the user. + * @param gender The gender of the user. + * @param maritalStatus The marital status of the user. + * @param numberOfHousehold The number of individuals in the household. + * @param annualIncome The annual income of the user. + * @return A RegisterResponseModel indicating the result of the registration attempt. + */ + public RegisterResponseModel create(String userName, String email, String password1, String password2, + String StateAbb, String PostalCode, + String ethnicity, int age, String gender, String maritalStatus, + int numberOfHousehold, float annualIncome) { RegistrationData requestModel = new RegistrationData(userName, email, password1, password2, StateAbb, PostalCode, ethnicity, age, gender, maritalStatus, numberOfHousehold, annualIncome); return inputBoundary.create(requestModel); } -} +} \ No newline at end of file From 0172bbc7fe267635dd0be1bb0df01b11fc40a6d1 Mon Sep 17 00:00:00 2001 From: Yifan Liu Date: Sun, 13 Aug 2023 00:03:45 -0400 Subject: [PATCH 12/24] delete attorney creation --- src/main/java/AttorneyRegister.java | 218 ---------------------------- 1 file changed, 218 deletions(-) delete mode 100644 src/main/java/AttorneyRegister.java diff --git a/src/main/java/AttorneyRegister.java b/src/main/java/AttorneyRegister.java deleted file mode 100644 index 70a184ba..00000000 --- a/src/main/java/AttorneyRegister.java +++ /dev/null @@ -1,218 +0,0 @@ -import businessrule.requestmodel.RegistrationData; -import driver.database.AttorneyRepository; -import entity.Attorney; -import entity.factory.AttorneyFactory; - -import java.util.HashSet; -import java.util.Set; - - -public class AttorneyRegister { - public static void main(String[] args) { - AttorneyRepository attorneyRepository = new AttorneyRepository(); - AttorneyFactory attorneyFactory = new AttorneyFactory(); - Set professionals = new HashSet<>(); - professionals.add("Family and Children"); - professionals.add("Housing and Homelessness"); - professionals.add("Education"); - RegistrationData registrationData = new RegistrationData("Cathy", "zihan.yuan@mail.utoronto.ca", "12345678", - "12345678", "CA", "12345", professionals); - registrationData.setUserId(12345678); - Attorney cathy = attorneyFactory.createUser(registrationData); - attorneyRepository.save(cathy); - -// ------------------------------------------------ - AttorneyRepository attorneyRepository2 = new AttorneyRepository(); - AttorneyFactory attorneyFactory2 = new AttorneyFactory(); - Set professionals2 = new HashSet<>(); - professionals2.add("Family and Children"); - RegistrationData registrationData2 = new RegistrationData("a2", "ihan.yuan@mail.utoronto.ca", "12345678", - "12345678", "CA", "12345", professionals2); - registrationData2.setUserId(123456781); - Attorney a2 = attorneyFactory2.createUser(registrationData2); - attorneyRepository2.save(a2); - - - AttorneyRepository attorneyRepository3 = new AttorneyRepository(); - AttorneyFactory attorneyFactory3 = new AttorneyFactory(); - Set professionals3 = new HashSet<>(); - professionals3.add("Consumer Financial Questions"); - RegistrationData registrationData3 = new RegistrationData("a3", "ihan.yuan@mail.utoronto.ca", "12345678", - "12345678", "CA", "12345", professionals3); - registrationData3.setUserId(123456782); - Attorney a3 = attorneyFactory3.createUser(registrationData3); - attorneyRepository3.save(a3); - - AttorneyRepository attorneyRepository4 = new AttorneyRepository(); - AttorneyFactory attorneyFactory4 = new AttorneyFactory(); - Set professionals4 = new HashSet<>(); - professionals4.add("Housing and Homelessness"); - RegistrationData registrationData4 = new RegistrationData("a4", "ihan.yuan@mail.utoronto.ca", - "12345678", "12345678", "CA", "12345", professionals4); - registrationData4.setUserId(123456783); - Attorney a4 = attorneyFactory4.createUser(registrationData4); - attorneyRepository4.save(a4); - - AttorneyRepository attorneyRepository5 = new AttorneyRepository(); - AttorneyFactory attorneyFactory5 = new AttorneyFactory(); - Set professionals5 = new HashSet<>(); - professionals5.add(" Individual Rights"); - RegistrationData registrationData5 = new RegistrationData("a5", "ihan.yuan@mail.utoronto.ca", - "12345678", "12345678", "CA", "12345", professionals5); - registrationData5.setUserId(123456784); - Attorney a5 = attorneyFactory5.createUser(registrationData5); - attorneyRepository5.save(a5); - - AttorneyRepository attorneyRepository6 = new AttorneyRepository(); - AttorneyFactory attorneyFactory6 = new AttorneyFactory(); - Set professionals6 = new HashSet<>(); - professionals6.add("Income Maintenance"); - RegistrationData registrationData6 = new RegistrationData("a6", "ihan.yuan@mail.utoronto.ca", - "12345678", "12345678", "CA", "12345", professionals6); - registrationData6.setUserId(123456785); - Attorney a6 = attorneyFactory6.createUser(registrationData6); - attorneyRepository6.save(a6); - - AttorneyRepository attorneyRepository7 = new AttorneyRepository(); - AttorneyFactory attorneyFactory7 = new AttorneyFactory(); - Set professionals7 = new HashSet<>(); - professionals7.add("Health and Disability"); - RegistrationData registrationData7 = new RegistrationData("a7", "ihan.yuan@mail.utoronto.ca", - "12345678", "12345678", "CA", "12345", professionals7); - registrationData7.setUserId(123456786); - Attorney a7 = attorneyFactory7.createUser(registrationData7); - attorneyRepository7.save(a7); - - AttorneyRepository attorneyRepository8 = new AttorneyRepository(); - AttorneyFactory attorneyFactory8 = new AttorneyFactory(); - Set professionals8 = new HashSet<>(); - professionals8.add("Work, Employment and Unemployment"); - RegistrationData registrationData8 = new RegistrationData("a8", "ihan.yuan@mail.utoronto.ca", - "12345678", "12345678", "CA", "12345", professionals8); - registrationData8.setUserId(123456787); - Attorney a8 = attorneyFactory8.createUser(registrationData8); - attorneyRepository8.save(a8); - - AttorneyRepository attorneyRepository9 = new AttorneyRepository(); - AttorneyFactory attorneyFactory9 = new AttorneyFactory(); - Set professionals9 = new HashSet<>(); - professionals9.add("Juvenile"); - RegistrationData registrationData9 = new RegistrationData("a9", "ihan.yuan@mail.utoronto.ca", - "12345678", "12345678", "CA", "12345", professionals9); - registrationData9.setUserId(123456788); - Attorney a9 = attorneyFactory9.createUser(registrationData9); - attorneyRepository9.save(a9); - - AttorneyRepository attorneyRepository10 = new AttorneyRepository(); - AttorneyFactory attorneyFactory10 = new AttorneyFactory(); - Set professionals10 = new HashSet<>(); - professionals10.add("Education"); - RegistrationData registrationData10 = new RegistrationData("a10", "ihan.yuan@mail.utoronto.ca", - "12345678", "12345678", "CA", "12345", professionals10); - registrationData10.setUserId(123456789); - Attorney a10 = attorneyFactory10.createUser(registrationData10); - attorneyRepository10.save(a10); - - AttorneyRepository attorneyRepository21 = new AttorneyRepository(); - AttorneyFactory attorneyFactory21 = new AttorneyFactory(); - Set professionals21 = new HashSet<>(); - professionals21.add("Family and Children"); - RegistrationData registrationData21 = new RegistrationData("a21", "zhan.yuan@mail.utoronto.ca", "12345678", - "12345678", "CA", "12345", professionals21); - registrationData21.setUserId(1234567810); - Attorney a21 = attorneyFactory21.createUser(registrationData21); - attorneyRepository21.save(a21); - - - AttorneyRepository attorneyRepository31 = new AttorneyRepository(); - AttorneyFactory attorneyFactory31 = new AttorneyFactory(); - Set professionals31 = new HashSet<>(); - professionals31.add("Consumer Financial Questions"); - RegistrationData registrationData31 = new RegistrationData("a31", "zhan.yuan@mail.utoronto.ca", "12345678", - "12345678", "CA", "12345", professionals31); - registrationData31.setUserId(1234567811); - Attorney a31 = attorneyFactory31.createUser(registrationData31); - attorneyRepository31.save(a31); - - AttorneyRepository attorneyRepository41 = new AttorneyRepository(); - AttorneyFactory attorneyFactory41 = new AttorneyFactory(); - Set professionals41 = new HashSet<>(); - professionals41.add("Housing and Homelessness"); - RegistrationData registrationData41 = new RegistrationData("a41", "ihan.yuan@mail.utoronto.ca", - "12345678", "12345678", "CA", "12345", professionals41); - registrationData41.setUserId(1234567812); - Attorney a41 = attorneyFactory41.createUser(registrationData41); - attorneyRepository41.save(a41); - - AttorneyRepository attorneyRepository51 = new AttorneyRepository(); - AttorneyFactory attorneyFactory51 = new AttorneyFactory(); - Set professionals51 = new HashSet<>(); - professionals51.add(" Individual Rights"); - RegistrationData registrationData51 = new RegistrationData("a51", "ihan.yuan@mail.utoronto.ca", - "12345678", "12345678", "CA", "12345", professionals51); - registrationData51.setUserId(1234567813); - Attorney a51 = attorneyFactory51.createUser(registrationData51); - attorneyRepository5.save(a51); - - AttorneyRepository attorneyRepository61 = new AttorneyRepository(); - AttorneyFactory attorneyFactory61 = new AttorneyFactory(); - Set professionals61 = new HashSet<>(); - professionals61.add("Income Maintenance"); - RegistrationData registrationData61 = new RegistrationData("a61", "zhan.yuan@mail.utoronto.ca", - "12345678", "12345678", "CA", "12345", professionals61); - registrationData61.setUserId(1234567814); - Attorney a61 = attorneyFactory61.createUser(registrationData61); - attorneyRepository61.save(a61); - - AttorneyRepository attorneyRepository71 = new AttorneyRepository(); - AttorneyFactory attorneyFactory71 = new AttorneyFactory(); - Set professionals71 = new HashSet<>(); - professionals71.add("Health and Disability"); - RegistrationData registrationData71 = new RegistrationData("a71", "ihan.yuan@mail.utoronto.ca", - "12345678", "12345678", "CA", "12345", professionals71); - registrationData71.setUserId(1234567815); - Attorney a71 = attorneyFactory7.createUser(registrationData71); - attorneyRepository71.save(a71); - - AttorneyRepository attorneyRepository81 = new AttorneyRepository(); - AttorneyFactory attorneyFactory81 = new AttorneyFactory(); - Set professionals81 = new HashSet<>(); - professionals81.add("Work, Employment and Unemployment"); - RegistrationData registrationData81 = new RegistrationData("a81", "ihan.yuan@mail.utoronto.ca", - "12345678", "12345678", "CA", "12345", professionals81); - registrationData81.setUserId(1234567816); - Attorney a81 = attorneyFactory81.createUser(registrationData81); - attorneyRepository81.save(a81); - - AttorneyRepository attorneyRepository91 = new AttorneyRepository(); - AttorneyFactory attorneyFactory91 = new AttorneyFactory(); - Set professionals91 = new HashSet<>(); - professionals91.add("Juvenile"); - RegistrationData registrationData91 = new RegistrationData("a91", "ihan.yuan@mail.utoronto.ca", - "12345678", "12345678", "CA", "12345", professionals91); - registrationData91.setUserId(1234567817); - Attorney a91 = attorneyFactory91.createUser(registrationData91); - attorneyRepository91.save(a91); - - AttorneyRepository attorneyRepository101 = new AttorneyRepository(); - AttorneyFactory attorneyFactory101 = new AttorneyFactory(); - Set professionals101 = new HashSet<>(); - professionals101.add("Education"); - RegistrationData registrationData101 = new RegistrationData("a101", "ihan.yuan@mail.utoronto.ca", - "12345678", "12345678", "CA", "12345", professionals101); - registrationData101.setUserId(1234567818); - Attorney a101 = attorneyFactory101.createUser(registrationData101); - attorneyRepository101.save(a101); - - AttorneyRepository attorneyRepository12 = new AttorneyRepository(); - AttorneyFactory attorneyFactory12 = new AttorneyFactory(); - Set professionals12 = new HashSet<>(); - professionals12.add("Education"); - RegistrationData registrationData12 = new RegistrationData("a12", "ihan.yuan@mail.utoronto.ca", - "12345678", "12345678", "CA", "12345", professionals12); - registrationData12.setUserId(1234567819); - Attorney a12 = attorneyFactory12.createUser(registrationData12); - attorneyRepository12.save(a12); - - } -} From 6a7f933f570174734cee7a2ef3916714f805bf64 Mon Sep 17 00:00:00 2001 From: Yifan Liu Date: Sun, 13 Aug 2023 00:15:25 -0400 Subject: [PATCH 13/24] merge with main --- src/main/java/businessrule/usecase/RateInteractor.java | 4 ++-- src/main/java/driver/database/DatabaseConnection.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/businessrule/usecase/RateInteractor.java b/src/main/java/businessrule/usecase/RateInteractor.java index 50becc2d..f9f22c24 100644 --- a/src/main/java/businessrule/usecase/RateInteractor.java +++ b/src/main/java/businessrule/usecase/RateInteractor.java @@ -22,15 +22,15 @@ public class RateInteractor implements RateInputBoundary { private final ClientGateway clientGateway; private final AttorneyGateway attorneyGateway; - public RateInteractor(QuestionGateway questionGateway, HomePageOutputBoundary homePageOutputBoundary, ClientGateway clientGateway, AttorneyGateway attorneyGateway) { /** * Constructor for RateInteractor. * * @param questionGateway The gateway for managing question entities. * @param homePageOutputBoundary The output boundary for preparing home page response models. * @param clientGateway The gateway for managing client entities. + * @param attorneyGateway The gateway for managing attorney entities */ - public RateInteractor(QuestionGateway questionGateway, HomePageOutputBoundary homePageOutputBoundary, ClientGateway clientGateway) { + public RateInteractor(QuestionGateway questionGateway, HomePageOutputBoundary homePageOutputBoundary, ClientGateway clientGateway, AttorneyGateway attorneyGateway) { this.questionGateway = questionGateway; this.homePageOutputBoundary = homePageOutputBoundary; this.clientGateway = clientGateway; diff --git a/src/main/java/driver/database/DatabaseConnection.java b/src/main/java/driver/database/DatabaseConnection.java index 037fa420..1cb9bab9 100644 --- a/src/main/java/driver/database/DatabaseConnection.java +++ b/src/main/java/driver/database/DatabaseConnection.java @@ -9,7 +9,7 @@ */ public class DatabaseConnection { - private static final String URL = "objectdb://175.24.206.37:39136/myapp.odb;admin"; + private static final String URL = "objectdb:myapp.odb;admin"; private static EntityManagerFactory entityManagerFactory; /** From 32a2c2cd5315f47cffab0f705ed0702dd01a09fe Mon Sep 17 00:00:00 2001 From: river3966 Date: Sun, 13 Aug 2023 03:43:57 -0400 Subject: [PATCH 14/24] doc --- .../ClientRegisterControlTest.java | 12 ++++ .../CloseQuestionControlTest.java | 13 ++++ .../ControlContainerTest.java | 29 +++++++- .../controllertesting/PostControlTest.java | 12 ++++ .../QuestionControlTest.java | 17 ++++- .../controllertesting/RateControlTest.java | 14 +++- .../SelectQuestionControlTest.java | 14 +++- .../UserLoginControlTest.java | 14 +++- .../ViewQuestionControlTest.java | 12 ++++ src/test/java/entitytesting/AttorneyTest.java | 71 ++++++++++++++++++- src/test/java/entitytesting/ClientTest.java | 55 +++++++++++++- src/test/java/entitytesting/PostTest.java | 24 +++++++ src/test/java/entitytesting/QuestionTest.java | 32 ++++++++- 13 files changed, 309 insertions(+), 10 deletions(-) diff --git a/src/test/java/controllertesting/ClientRegisterControlTest.java b/src/test/java/controllertesting/ClientRegisterControlTest.java index 6d2473fd..e2237ce9 100644 --- a/src/test/java/controllertesting/ClientRegisterControlTest.java +++ b/src/test/java/controllertesting/ClientRegisterControlTest.java @@ -10,7 +10,11 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.*; +/** + * This class contains unit tests for the ClientRegisterControl class. + */ public class ClientRegisterControlTest { + private static String USER_NAME = "SampleUser"; private static String EMAIL = "sample@example.com"; private static String PASSWORD1 = "test password"; @@ -26,18 +30,26 @@ public class ClientRegisterControlTest { private static RegisterResponseModel expectedResponse; + /** + * Sets up the needed resources for testing ClientRegisterControl. + */ public void setUpClientRegisterControl() { // Arrange expectedResponse = new RegisterResponseModel(); } + /** + * Tests the create method of ClientRegisterControl. + */ @Test public void testCreateClientRegistration() { setUpClientRegisterControl(); + // Create a mock for UserRegisterInputBoundary UserRegisterInputBoundary mockInputBoundary = mock(UserRegisterInputBoundary.class); when(mockInputBoundary.create(any(RegistrationData.class))).thenReturn(expectedResponse); + // Create an instance of ClientRegisterControl ClientRegisterControl control = new ClientRegisterControl(mockInputBoundary); // Act diff --git a/src/test/java/controllertesting/CloseQuestionControlTest.java b/src/test/java/controllertesting/CloseQuestionControlTest.java index 1e8bad62..1ee9bbef 100644 --- a/src/test/java/controllertesting/CloseQuestionControlTest.java +++ b/src/test/java/controllertesting/CloseQuestionControlTest.java @@ -10,23 +10,35 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; +/** + * This class contains unit tests for the CloseQuestionControl class. + */ public class CloseQuestionControlTest { + private static int QUESTION_ID = 333333333; private static int USER_ID = 11234567; private static HomePageResponseModel expectedResponse; + /** + * Sets up the necessary resources for testing CloseQuestionControl. + */ public void setUpCloseQuestionControl() { // Arrange expectedResponse = new HomePageResponseModel(USER_ID, "SampleUser", "SampleType"); // Assuming suitable constructor } + /** + * Tests the closeQuestion method of CloseQuestionControl. + */ @Test public void testCloseQuestion() { setUpCloseQuestionControl(); + // Create a mock for CloseInputBoundary CloseInputBoundary mockInputBoundary = mock(CloseInputBoundary.class); when(mockInputBoundary.closeQuestion(any(CloseRequestModel.class))).thenReturn(expectedResponse); + // Create an instance of CloseQuestionControl CloseQuestionControl control = new CloseQuestionControl(mockInputBoundary); // Act @@ -39,3 +51,4 @@ public void testCloseQuestion() { verify(mockInputBoundary, times(1)).closeQuestion(any(CloseRequestModel.class)); } } + diff --git a/src/test/java/controllertesting/ControlContainerTest.java b/src/test/java/controllertesting/ControlContainerTest.java index 563ed955..625de4ec 100644 --- a/src/test/java/controllertesting/ControlContainerTest.java +++ b/src/test/java/controllertesting/ControlContainerTest.java @@ -6,8 +6,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; +/** + * This class contains unit tests for the ControlContainer class. + */ public class ControlContainerTest { + /** + * Tests the getClientRegisterControl method of ControlContainer. + */ @Test public void testGetClientRegisterControl() { ClientRegisterControl mockClientRegisterControl = mock(ClientRegisterControl.class); @@ -15,6 +21,9 @@ public void testGetClientRegisterControl() { assertEquals(mockClientRegisterControl, controlContainer.getClientRegisterControl()); } + /** + * Tests the getCloseQuestionControl method of ControlContainer. + */ @Test public void testGetCloseQuestionControl() { CloseQuestionControl mockCloseQuestionControl = mock(CloseQuestionControl.class); @@ -22,6 +31,9 @@ public void testGetCloseQuestionControl() { assertEquals(mockCloseQuestionControl, controlContainer.getCloseQuestionControl()); } + /** + * Tests the getPostControl method of ControlContainer. + */ @Test public void testGetPostControl() { PostControl mockPostControl = mock(PostControl.class); @@ -29,6 +41,9 @@ public void testGetPostControl() { assertEquals(mockPostControl, controlContainer.getPostControl()); } + /** + * Tests the getQuestionControl method of ControlContainer. + */ @Test public void testGetQuestionControl() { QuestionControl mockQuestionControl = mock(QuestionControl.class); @@ -36,6 +51,9 @@ public void testGetQuestionControl() { assertEquals(mockQuestionControl, controlContainer.getQuestionControl()); } + /** + * Tests the getRateControl method of ControlContainer. + */ @Test public void testGetRateControl() { RateControl mockRateControl = mock(RateControl.class); @@ -43,6 +61,9 @@ public void testGetRateControl() { assertEquals(mockRateControl, controlContainer.getRateControl()); } + /** + * Tests the getSelectQuestionControl method of ControlContainer. + */ @Test public void testGetSelectQuestionControl() { SelectQuestionControl mockSelectQuestionControl = mock(SelectQuestionControl.class); @@ -50,6 +71,9 @@ public void testGetSelectQuestionControl() { assertEquals(mockSelectQuestionControl, controlContainer.getSelectQuestionControl()); } + /** + * Tests the getUserLoginControl method of ControlContainer. + */ @Test public void testGetUserLoginControl() { UserLoginControl mockUserLoginControl = mock(UserLoginControl.class); @@ -57,10 +81,13 @@ public void testGetUserLoginControl() { assertEquals(mockUserLoginControl, controlContainer.getUserLoginControl()); } + /** + * Tests the getViewQuestionControl method of ControlContainer. + */ @Test public void testGetViewQuestionControl() { ViewQuestionControl mockViewQuestionControl = mock(ViewQuestionControl.class); ControlContainer controlContainer = new ControlContainer(null, null, null, null, null, null, null, mockViewQuestionControl); assertEquals(mockViewQuestionControl, controlContainer.getViewQuestionControl()); } -} +} \ No newline at end of file diff --git a/src/test/java/controllertesting/PostControlTest.java b/src/test/java/controllertesting/PostControlTest.java index 58650977..defe3dd6 100644 --- a/src/test/java/controllertesting/PostControlTest.java +++ b/src/test/java/controllertesting/PostControlTest.java @@ -10,7 +10,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; +/** + * This class contains unit tests for the PostControl class. + */ public class PostControlTest { + private static int USER_ID = 11234567; private static String USER_NAME = "SampleUser"; private static String USER_TYPE = "SampleType"; @@ -19,18 +23,26 @@ public class PostControlTest { private static HomePageResponseModel expectedResponse; + /** + * Sets up the necessary resources for testing PostControl. + */ public void setUpPostControl() { // Arrange expectedResponse = new HomePageResponseModel(USER_ID, USER_NAME, USER_TYPE); } + /** + * Tests the createPost method of PostControl. + */ @Test public void testCreatePost() { setUpPostControl(); + // Create a mock for PostInputBoundary PostInputBoundary mockInputBoundary = mock(PostInputBoundary.class); when(mockInputBoundary.createPost(any(PostRequestModel.class))).thenReturn(expectedResponse); + // Create an instance of PostControl PostControl control = new PostControl(mockInputBoundary); // Act diff --git a/src/test/java/controllertesting/QuestionControlTest.java b/src/test/java/controllertesting/QuestionControlTest.java index 0c1f57d1..da19a030 100644 --- a/src/test/java/controllertesting/QuestionControlTest.java +++ b/src/test/java/controllertesting/QuestionControlTest.java @@ -15,7 +15,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; +/** + * This class contains unit tests for the QuestionControl class. + */ public class QuestionControlTest { + private static int USER_ID = 11234567; private static int QUESTION_ID = 333333333; private static String USER_NAME = "SampleUser"; @@ -24,21 +28,30 @@ public class QuestionControlTest { private static TheQuestionResponseModel expectedResponse; - public void setUpQuestionControl(){ + /** + * Sets up the necessary resources for testing QuestionControl. + */ + public void setUpQuestionControl() { // Arrange LocalDate deadline = LocalDate.now().plusDays(5); boolean isClose = false; Map postMap = new HashMap<>(); // Assuming suitable values or empty - expectedResponse = new TheQuestionResponseModel(USER_ID, QUESTION_ID, USER_NAME, TITLE, TYPE, deadline, isClose, postMap); + expectedResponse = new TheQuestionResponseModel(USER_ID, QUESTION_ID, USER_NAME, TITLE, TYPE, deadline, isClose, postMap); } + /** + * Tests the createQuestion method of QuestionControl. + */ @Test public void testCreateQuestion() { setUpQuestionControl(); + + // Create a mock for QuestionInputBoundary QuestionInputBoundary mockInputBoundary = mock(QuestionInputBoundary.class); when(mockInputBoundary.createQuestion(any(QuestionRequestModel.class))).thenReturn(expectedResponse); + // Create an instance of QuestionControl QuestionControl control = new QuestionControl(mockInputBoundary); // Sample input parameters diff --git a/src/test/java/controllertesting/RateControlTest.java b/src/test/java/controllertesting/RateControlTest.java index 8032402b..ce6f648c 100644 --- a/src/test/java/controllertesting/RateControlTest.java +++ b/src/test/java/controllertesting/RateControlTest.java @@ -10,24 +10,36 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; +/** + * This class contains unit tests for the RateControl class. + */ public class RateControlTest { + private static int RATE = 5; private static int QUESTION_ID = 333333333; private static int USER_ID = 11234567; private static HomePageResponseModel expectedResponse; + /** + * Sets up the necessary resources for testing RateControl. + */ public void setUpRateControl() { // Arrange expectedResponse = new HomePageResponseModel(USER_ID, "SampleUser", "SampleType"); // Assuming suitable constructor } + /** + * Tests the rateAnswer method of RateControl. + */ @Test public void testRateAnswer() { setUpRateControl(); + // Create a mock for RateInputBoundary RateInputBoundary mockInputBoundary = mock(RateInputBoundary.class); when(mockInputBoundary.rateAnswer(any(RateRequestModel.class))).thenReturn(expectedResponse); + // Create an instance of RateControl RateControl control = new RateControl(mockInputBoundary); // Act @@ -39,4 +51,4 @@ public void testRateAnswer() { // Verify interactions verify(mockInputBoundary, times(1)).rateAnswer(any(RateRequestModel.class)); } -} +} \ No newline at end of file diff --git a/src/test/java/controllertesting/SelectQuestionControlTest.java b/src/test/java/controllertesting/SelectQuestionControlTest.java index 30d2e227..d0484ba9 100644 --- a/src/test/java/controllertesting/SelectQuestionControlTest.java +++ b/src/test/java/controllertesting/SelectQuestionControlTest.java @@ -10,24 +10,36 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; +/** + * This class contains unit tests for the SelectQuestionControl class. + */ public class SelectQuestionControlTest { + private static int QUESTION_ID = 333333333; private static int USER_ID = 11234567; private static TheQuestionResponseModel expectedResponse; + /** + * Sets up the necessary resources for testing SelectQuestionControl. + */ public void setUpSelectQuestionControl() { // Arrange expectedResponse = new TheQuestionResponseModel(USER_ID, QUESTION_ID, "SampleUser", "SampleTitle", "SampleType", null, false, null); // Assuming suitable constructor or setters } + /** + * Tests the selectQuestion method of SelectQuestionControl. + */ @Test public void testSelectQuestion() { setUpSelectQuestionControl(); + // Create a mock for SelectInputBoundary SelectInputBoundary mockInputBoundary = mock(SelectInputBoundary.class); when(mockInputBoundary.selectQuestion(any(SelectRequestModel.class))).thenReturn(expectedResponse); + // Create an instance of SelectQuestionControl SelectQuestionControl control = new SelectQuestionControl(mockInputBoundary); // Act @@ -39,4 +51,4 @@ public void testSelectQuestion() { // Verify interactions verify(mockInputBoundary, times(1)).selectQuestion(any(SelectRequestModel.class)); } -} +} \ No newline at end of file diff --git a/src/test/java/controllertesting/UserLoginControlTest.java b/src/test/java/controllertesting/UserLoginControlTest.java index 8fc5f994..4e1b0b16 100644 --- a/src/test/java/controllertesting/UserLoginControlTest.java +++ b/src/test/java/controllertesting/UserLoginControlTest.java @@ -10,23 +10,35 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; +/** + * This class contains unit tests for the UserLoginControl class. + */ public class UserLoginControlTest { + private static int USER_ID = 11234567; private static String PASSWORD = "test password"; private static HomePageResponseModel expectedResponse; + /** + * Sets up the necessary resources for testing UserLoginControl. + */ public void setUpUserLoginControl() { // Arrange expectedResponse = new HomePageResponseModel(USER_ID, "SampleUser", "SampleType"); // Assuming suitable constructor } + /** + * Tests the login method of UserLoginControl. + */ @Test public void testLogin() { setUpUserLoginControl(); + // Create a mock for UserLoginInputBoundary UserLoginInputBoundary mockInputBoundary = mock(UserLoginInputBoundary.class); when(mockInputBoundary.login(any(UserLoginRequestModel.class))).thenReturn(expectedResponse); + // Create an instance of UserLoginControl UserLoginControl control = new UserLoginControl(mockInputBoundary); // Act @@ -38,4 +50,4 @@ public void testLogin() { // Verify interactions verify(mockInputBoundary, times(1)).login(any(UserLoginRequestModel.class)); } -} +} \ No newline at end of file diff --git a/src/test/java/controllertesting/ViewQuestionControlTest.java b/src/test/java/controllertesting/ViewQuestionControlTest.java index 96010881..8bed8dd4 100644 --- a/src/test/java/controllertesting/ViewQuestionControlTest.java +++ b/src/test/java/controllertesting/ViewQuestionControlTest.java @@ -14,24 +14,36 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; +/** + * This class contains unit tests for the ViewQuestionControl class. + */ public class ViewQuestionControlTest { + private static int USER_ID = 11234567; private static String USER_NAME = "SampleUser"; private static ViewResponseModel expectedResponse; + /** + * Sets up the necessary resources for testing ViewQuestionControl. + */ public void setUpViewQuestionControl() { // Arrange Map questionMap = Collections.emptyMap(); // Sample empty map expectedResponse = new ViewResponseModel(USER_ID, USER_NAME, questionMap); // Initializing with suitable values } + /** + * Tests the viewQuestion method of ViewQuestionControl. + */ @Test public void testViewQuestion() { setUpViewQuestionControl(); + // Create a mock for ViewInputBoundary ViewInputBoundary mockInputBoundary = mock(ViewInputBoundary.class); when(mockInputBoundary.viewQuestion(any(ViewRequestModel.class))).thenReturn(expectedResponse); + // Create an instance of ViewQuestionControl ViewQuestionControl control = new ViewQuestionControl(mockInputBoundary); // Act diff --git a/src/test/java/entitytesting/AttorneyTest.java b/src/test/java/entitytesting/AttorneyTest.java index 004c68ad..174a18d8 100644 --- a/src/test/java/entitytesting/AttorneyTest.java +++ b/src/test/java/entitytesting/AttorneyTest.java @@ -7,6 +7,10 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.*; +/** + * This class contains unit tests for the Attorney class. + */ + class AttorneyTest { int expectedUserId = 1000000; String expectedName = "Xingfu Wu"; @@ -16,6 +20,9 @@ class AttorneyTest { String expectedStateAbb = "CA"; String expectedPostalCode = "12345"; + /** + * Test the constructor and getter methods of the Attorney class. + */ @Test void testConstructorAndGetter() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -32,6 +39,9 @@ void testConstructorAndGetter() { assertEquals(expectedPostalCode, attorney.getPostalCode(), "Postal code is not set correctly in the constructor."); } + /** + * Test the setter methods of the Attorney class. + */ @Test void testSetters() { @@ -58,6 +68,10 @@ void testSetters() { assertEquals(expectedStateAbb, attorney.getStateAbb(), "The state abbreviation should be updated."); assertEquals(expectedPostalCode, attorney.getPostalCode(), "The postal code should be updated."); } + + /** + * Test adding questions to the Attorney's question list. + */ @Test void testAddQuestion() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -79,6 +93,10 @@ void testAddQuestion() { attorney.addQuestion(question1); assertEquals(2, questions.size(), "After adding a duplicate question, the number of questions in the list should remain at 2."); } + + /** + * Test if a question is closeable when it's not taken. + */ @Test void testCloseableIfNotTaken() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -94,6 +112,10 @@ void testCloseableIfNotTaken() { boolean actual = attorney.isQuestionCloseable(question); assertEquals(expected, actual, "The question should not be closeable when it is not taken."); } + + /** + * Test if a question is not closeable when taken by another attorney. + */ @Test void testCloseableIfTakenByOthers() { RegistrationData registrationData1 = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -115,6 +137,9 @@ void testCloseableIfTakenByOthers() { assertEquals(expected, actual, "The question should not be closeable when it is taken by a different attorney."); } + /** + * Test the isClient() method of the Attorney class. + */ @Test void testIsClient() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -125,6 +150,10 @@ void testIsClient() { boolean actual = attorney.isClient(); assertEquals(expected, actual, "The isClient method of an Attorney should always return false."); } + + /** + * Test if a question is not selectable when it's closed. + */ @Test void testSelectableIfClosed() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -139,6 +168,10 @@ void testSelectableIfClosed() { boolean actual = attorney.isQuestionSelectable(question); assertEquals(expected, actual, "The question should not be selectable when it is closed."); } + + /** + * Test if a question is selectable when it's not taken. + */ @Test void testSelectableIfNotTaken() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -153,6 +186,10 @@ void testSelectableIfNotTaken() { boolean actual = attorney.isQuestionSelectable(question); assertEquals(expected, actual, "The question should be selectable when it is not taken."); } + + /** + * Test if a question is not selectable when taken by another attorney. + */ @Test void testSelectableIfTakenByOthers() { RegistrationData registrationData1 = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -175,6 +212,9 @@ void testSelectableIfTakenByOthers() { assertEquals(expected, actual, "The question should not be selectable when it is taken by a different attorney."); } + /** + * Test if a question is selectable when taken by the current attorney. + */ @Test void testSelectableIfTakenBySelf() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -191,6 +231,9 @@ void testSelectableIfTakenBySelf() { assertEquals(expected, actual, "The question should be selectable when it is taken by the current attorney."); } + /** + * Test if a question is not replyable when it is closed. + */ @Test void testReplyableIfClosed() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -205,6 +248,10 @@ void testReplyableIfClosed() { boolean actual = attorney.isQuestionReplyable(question); assertEquals(expected, actual, "The question should not be replyable when it is closed."); } + + /** + * Test if a question is not replyable when it is taken by a different attorney.". + */ @Test void testReplyableIfTakenByOthers() { RegistrationData registrationData1 = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -226,6 +273,9 @@ void testReplyableIfTakenByOthers() { assertEquals(expected, actual, "The question should not be replyable when it is taken by a different attorney."); } + /** + * Test if a question is replyable when it is taken by the current attorney. + */ @Test void testReplyableIfTakenBySelf() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -242,6 +292,9 @@ void testReplyableIfTakenBySelf() { assertEquals(expected, actual, "The question should be replyable when it is taken by the current attorney."); } + /** + * Test if a question is replyable when it is not taken by any user. + */ @Test void testReplyableIfNotTaken() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -259,6 +312,9 @@ void testReplyableIfNotTaken() { assertEquals(attorney.getUserId(), question.getTakenByAttorney(), "The attorney who took the question should be set to the current attorney after isQuestionReplyable is called."); } + /** + * Test the equals method for a successful comparison between two identical Attorneys. + */ @Test void testEqualsSucceed(){ RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -267,6 +323,10 @@ void testEqualsSucceed(){ Attorney attorney = attorneyFactory.createUser(registrationData); assertEquals(true,attorney.equals(attorney),"The equal method is wrong"); } + + /** + * Test the equals method where the comparison fails due to one object being an Attorney and the other a Question. + */ @Test void testEqualFailByNotClient(){ RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -276,7 +336,12 @@ void testEqualFailByNotClient(){ Question question = new Question(); assertEquals(false,attorney.equals(question),"The equal method is wrong"); - }@Test + } + + /** + * Test the equals method where the comparison fails due to two different Attorneys. + */ + @Test void testEqualsFailByNotEqual(){ RegistrationData registrationData1 = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, expectedPostalCode); @@ -288,7 +353,9 @@ void testEqualsFailByNotEqual(){ assertEquals(true, attorney1.equals(attorney2),"The equal method is wrong"); } - + /** + * Test if a question is not rateable by an Attorney. + */ @Test void testIsQuestionRateable() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, diff --git a/src/test/java/entitytesting/ClientTest.java b/src/test/java/entitytesting/ClientTest.java index 52933af8..03d49f0a 100644 --- a/src/test/java/entitytesting/ClientTest.java +++ b/src/test/java/entitytesting/ClientTest.java @@ -10,7 +10,9 @@ import java.util.Objects; import static org.junit.jupiter.api.Assertions.*; - +/** + * This class contains unit tests for the Client class. + */ class ClientTest { int expectedUserId = 1000000; @@ -27,6 +29,9 @@ class ClientTest { int expectedNumberOfHousehold = 1; float expectedAnnualIncome = 60000.0f; + /** + * Tests the constructor and getter methods of the Client class. + */ @Test void testConstructorAndGetter() { // constructor @@ -54,6 +59,9 @@ void testConstructorAndGetter() { assertTrue(client.isClient(), "isClient should be true for Client."); } + /** + * Tests the setter methods of the Client class. + */ @Test void testSetters() { // no-arg constructor @@ -88,6 +96,9 @@ void testSetters() { assertEquals(expectedAnnualIncome, client.getAnnualIncome(), "Annual income is incorrect."); } + /** + * Tests whether a question can be closed successfully for a client. + */ @Test void testClientIsQuestionCloseableSucceed() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -101,6 +112,9 @@ void testClientIsQuestionCloseableSucceed() { assertTrue(client.isQuestionCloseable(question)); } + /** + * Tests whether a closed question is not closeable for a client. + */ @Test void testClientIsQuestionCloseableFail() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -115,6 +129,9 @@ void testClientIsQuestionCloseableFail() { assertFalse(client.isQuestionCloseable(question)); } + /** + * Tests whether a question is selectable for a client. + */ @Test void testClientIsQuestionSelectable() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -128,6 +145,9 @@ void testClientIsQuestionSelectable() { } + /** + * Tests whether a question can be replied to successfully for a client. + */ @Test void testClientIsQuestionReplyableSucceed() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -143,6 +163,9 @@ void testClientIsQuestionReplyableSucceed() { } + /** + * Tests whether a closed question is not replyable for a client. + */ @Test void testClientIsQuestionReplyableFail() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -157,6 +180,9 @@ void testClientIsQuestionReplyableFail() { } + /** + * Tests the addition of a question to the client's question list. + */ @Test void testAddQuestion() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -172,6 +198,9 @@ void testAddQuestion() { assertTrue(client.getQuestionsList().contains(question), "The question is not added in the list."); } + /** + * Tests the hash code generation of the Client class. + */ @Test void testHashCodeSucceed() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -184,6 +213,9 @@ void testHashCodeSucceed() { assertEquals(client.hashCode(), Objects.hashCode(1000000), "The hashcode is wrong"); } + /** + * Tests whether the generated hash code differs when expected and actual user IDs do not match. + */ @Test void testHashCodeFail() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -195,6 +227,9 @@ void testHashCodeFail() { assertNotEquals(client.hashCode(), Objects.hashCode(100000), "The hashcode is wrong"); } + /** + * Tests the equality of two Client objects. + */ @Test void testEqualsSucceed() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -206,6 +241,9 @@ void testEqualsSucceed() { assertEquals(client, client, "The equal method is wrong"); } + /** + * Tests inequality between a Client and a non-Client object. + */ @Test void testEqualsFailByNotClient() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -218,6 +256,9 @@ void testEqualsFailByNotClient() { assertEquals(false, client.equals(question), "The equal method is wrong"); } + /** + * Tests inequality between two Client objects with non-matching data. + */ @Test void testEqualsFailByNotEqual() { RegistrationData registrationData1 = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -235,6 +276,9 @@ void testEqualsFailByNotEqual() { assertNotEquals(client1, client2, "The equal method is wrong"); } + /** + * Test the toString method of the Client class when it succeeds. + */ @Test void testToStringSucceed() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -247,6 +291,9 @@ void testToStringSucceed() { assertEquals(expectedToString, client.toString(), "The toString method is wrong"); } + /** + * Test the toString method of the Client class when it fails. + */ @Test void testToStringFail() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -259,6 +306,9 @@ void testToStringFail() { assertNotSame(expectedToString, client.toString(), "The toString method is wrong"); } + /** + * Tests whether a closed question is rateable for a client. + */ @Test void testIsQuestionRateableSucceed() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, @@ -271,6 +321,9 @@ void testIsQuestionRateableSucceed() { assertTrue(client.isQuestionRateable(question), "IsQuestionRateable is wrong."); } + /** + * Tests whether a non-closed question is not rateable for a client. + */ @Test void testIsQuestionRateableFail() { RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, diff --git a/src/test/java/entitytesting/PostTest.java b/src/test/java/entitytesting/PostTest.java index 05b6b9dd..d516087f 100644 --- a/src/test/java/entitytesting/PostTest.java +++ b/src/test/java/entitytesting/PostTest.java @@ -7,9 +7,15 @@ import java.time.LocalDate; import static org.junit.jupiter.api.Assertions.*; +/** + * This class contains unit tests for the Post class. + */ class PostTest { + /** + * Test the constructor and getter methods of the Post class. + */ @Test void testConstructorAndGetter() { // expected values @@ -30,6 +36,9 @@ void testConstructorAndGetter() { assertEquals(expectedBelongsTo, post.getBelongsTo(), "BelongsTo is wrong."); } + /** + * Test the setter methods of the Post class. + */ @Test void testSetters() { // expected values @@ -57,12 +66,18 @@ void testSetters() { assertEquals(expectedBelongsTo, post.getBelongsTo(), "BelongsTo is wrong."); } + /** + * Test the equals method of the Post class when objects are the same. + */ @Test void testEqualsSucceed() { Post post1 = new Post(1000000, 2000000, LocalDate.now(), "This is a post.", 3000000); assertEquals(true, post1.equals(post1), "The equal method is wrong"); } + /** + * Test the equals method of the Post class with objects of different classes. + */ @Test void testEqualsFailByDifferentClass() { Post post1 = new Post(1000000, 2000000, LocalDate.now(), "This is a post.", 3000000); @@ -70,6 +85,9 @@ void testEqualsFailByDifferentClass() { assertEquals(false, post1.equals(question), "The equal method is wrong"); } + /** + * Test the equals method of the Post class with objects having different post IDs. + */ @Test void testEqualsFailByDifferentPostId() { Post post1 = new Post(1000000, 2000000, LocalDate.now(), "This is a post.", 3000000); @@ -77,6 +95,9 @@ void testEqualsFailByDifferentPostId() { assertEquals(false, post1.equals(post2), "The equal method is wrong"); } + /** + * Test the toString method of the Post class when it succeeds. + */ @Test void testToStringSucceed() { int expectedQuestionId = 1000000; @@ -86,6 +107,9 @@ void testToStringSucceed() { assertEquals(expectedToString, post.toString(), "The toString method is wrong"); } + /** + * Test the toString method of the Post class when it fails. + */ @Test void testToStringFail() { int expectedQuestionId = 1000000; diff --git a/src/test/java/entitytesting/QuestionTest.java b/src/test/java/entitytesting/QuestionTest.java index 86245978..af15ad97 100644 --- a/src/test/java/entitytesting/QuestionTest.java +++ b/src/test/java/entitytesting/QuestionTest.java @@ -9,9 +9,14 @@ import java.util.Objects; import static org.junit.jupiter.api.Assertions.*; - +/** + * This class contains unit tests for the Question class. + */ class QuestionTest { + /** + * Test the constructor and getter methods of the Question class. + */ @Test void testConstructorAndGetter() { int expectedQuestionId = 1000000; @@ -37,6 +42,9 @@ void testConstructorAndGetter() { assertTrue(question.getPosts().isEmpty(), "Posts should be empty initially."); } + /** + * Test the setter methods of the Question class. + */ @Test void testSetters() { int expectedQuestionId = 1000000; @@ -63,12 +71,19 @@ void testSetters() { assertEquals(expectedAskedByClient, question.getAskedByClient(), "AskedByClient is wrong."); assertEquals(expectedLegalDeadline, question.getLegalDeadline(), "LegalDeadline is wrong."); } + + /** + * Test the equals method of the Question class when objects are the same. + */ @Test void testEqualsSucceed() { Question question1 = new Question(1, "fraud", "Question Title", LocalDate.now(), 2000000, LocalDate.now()); assertEquals(true, question1.equals(question1), "The equal method is wrong"); } + /** + * Test the equals method of the Question class with objects of different classes. + */ @Test void testEqualsFailByNotQuestion() { Question question1 = new Question(1, "fraud", "Question Title", LocalDate.now(), 2000000, LocalDate.now()); @@ -77,6 +92,9 @@ void testEqualsFailByNotQuestion() { assertEquals(false, question1.equals(attorney), "The equal method is wrong"); } + /** + * Test the equals method of the Question class with objects that are not equal. + */ @Test void testEqualsFailByNotEqual() { Question question1 = new Question(1, "fraud", "Question Title", LocalDate.now(), 2000000, LocalDate.now()); @@ -84,18 +102,27 @@ void testEqualsFailByNotEqual() { assertEquals(false, question1.equals(question2), "The equal method is wrong"); } + /** + * Test the hashCode method of the Question class when it fails. + */ @Test void testHashCodeFail() { Question question1 = new Question(1, "fraud", "Question Title", LocalDate.now(), 2000000, LocalDate.now()); assertEquals(false, question1.hashCode() == Objects.hashCode(2), "The hashCode is wrong"); } + /** + * Test the hashCode method of the Question class when it succeeds. + */ @Test void testHashCodeSucceed() { Question question1 = new Question(1, "fraud", "Question Title", LocalDate.now(), 2000000, LocalDate.now()); assertEquals(question1.hashCode(), Objects.hashCode(1), "The hashCode is wrong"); } + /** + * Test the toString method of the Question class when it succeeds. + */ @Test void testToStringSucceed() { String expectedType = "fraud"; @@ -105,6 +132,9 @@ void testToStringSucceed() { assertEquals(expectedToString, question1.toString(), "The toString method is wrong"); } + /** + * Test the toString method of the Question class when it fails. + */ @Test void testToStringFail() { String unexpectedType = "criminal"; From be8f48129ca01b15ff57625d09e9f43f2de0c1de Mon Sep 17 00:00:00 2001 From: river3966 Date: Sun, 13 Aug 2023 04:25:53 -0400 Subject: [PATCH 15/24] doc --- .../factorytesting/ClientFactoryTest.java | 6 +++ .../factorytesting/CredentialCheckerTest.java | 17 +++++- .../java/factorytesting/PostFactoryTest.java | 9 ++++ .../factorytesting/QuestionFactoryTest.java | 9 ++++ .../RandomNumberGeneratorTest.java | 20 ++++++- .../AttorneyRepositoryTest.java | 30 +++++++++++ .../gatewaytesting/ClientRepositoryTest.java | 30 +++++++++++ .../java/gatewaytesting/PostRepoTest.java | 24 ++++++++- .../java/gatewaytesting/QuestionRepoTest.java | 54 +++++++++++++++++++ 9 files changed, 194 insertions(+), 5 deletions(-) diff --git a/src/test/java/factorytesting/ClientFactoryTest.java b/src/test/java/factorytesting/ClientFactoryTest.java index 9a39f811..d62929aa 100644 --- a/src/test/java/factorytesting/ClientFactoryTest.java +++ b/src/test/java/factorytesting/ClientFactoryTest.java @@ -6,8 +6,14 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; +/** + * This class contains unit tests for the ClientFactory class. + */ public class ClientFactoryTest { + /** + * Test the create method of ClientFactory. + */ @Test public void testCreate() { ClientFactory factory = new ClientFactory(); diff --git a/src/test/java/factorytesting/CredentialCheckerTest.java b/src/test/java/factorytesting/CredentialCheckerTest.java index 4b67f44b..84666103 100644 --- a/src/test/java/factorytesting/CredentialCheckerTest.java +++ b/src/test/java/factorytesting/CredentialCheckerTest.java @@ -6,15 +6,24 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +/** + * This class contains unit tests for CredentialChecker class. + */ class CredentialCheckerTest { private CredentialChecker checker; + /** + * Set up the CredentialChecker instance before each test. + */ @BeforeEach void setUpCredentialChecker() { checker = new CredentialChecker(); } + /** + * Test the checkPostalCode method of CredentialChecker. + */ @Test void testCheckPostalCode() { assertEquals(true, checker.checkPostalCode("12345"), "Postal code validation failed."); @@ -23,7 +32,9 @@ void testCheckPostalCode() { assertEquals(false, checker.checkPostalCode(""), "Empty postal code passed validation."); } - + /** + * Test the checkEmail method of CredentialChecker. + */ @Test void testCheckEmail() { assertTrue(checker.checkEmail("test@example.com"), "Expected valid email to pass validation."); @@ -33,7 +44,9 @@ void testCheckEmail() { assertFalse(checker.checkEmail(" "), "Expected email with only spaces to fail validation."); } - + /** + * Test the checkAge method of CredentialChecker. + */ @Test void testCheckAge() { assertEquals(true, checker.checkAge(50), "Age validation failed."); diff --git a/src/test/java/factorytesting/PostFactoryTest.java b/src/test/java/factorytesting/PostFactoryTest.java index 808bb69d..6dee409f 100644 --- a/src/test/java/factorytesting/PostFactoryTest.java +++ b/src/test/java/factorytesting/PostFactoryTest.java @@ -9,6 +9,9 @@ import java.time.LocalDate; +/** + * This class contains unit tests for PostFactory class. + */ class PostFactoryTest { private PostFactory postFactory; @@ -18,6 +21,9 @@ class PostFactoryTest { private String postText; private int belongsTo; + /** + * Set up the PostFactory instance before each test. + */ @BeforeEach void setUpPostFactory() { postFactory = new PostFactory(); @@ -28,6 +34,9 @@ void setUpPostFactory() { belongsTo = 3; } + /** + * Test the create method of PostFactory. + */ @Test void testCreate() { Post post = postFactory.create(postId, questionId, createAt, postText, belongsTo); diff --git a/src/test/java/factorytesting/QuestionFactoryTest.java b/src/test/java/factorytesting/QuestionFactoryTest.java index 4bf3116f..d195d36b 100644 --- a/src/test/java/factorytesting/QuestionFactoryTest.java +++ b/src/test/java/factorytesting/QuestionFactoryTest.java @@ -9,6 +9,9 @@ import java.time.LocalDate; +/** + * This class contains unit tests for the QuestionFactory class. + */ class QuestionFactoryTest { private QuestionFactory questionFactory; @@ -19,6 +22,9 @@ class QuestionFactoryTest { private int askedByClient; private LocalDate legalDeadline; + /** + * Set up the QuestionFactory instance and test data before tests. + */ @BeforeEach void setUpQuestionFactory() { questionFactory = new QuestionFactory(); @@ -30,6 +36,9 @@ void setUpQuestionFactory() { legalDeadline = LocalDate.now(); } + /** + * Test the create method of QuestionFactory. + */ @Test void testCreate() { Question question = questionFactory.create(questionId, type, title, createAt, askedByClient, legalDeadline); diff --git a/src/test/java/factorytesting/RandomNumberGeneratorTest.java b/src/test/java/factorytesting/RandomNumberGeneratorTest.java index 5bd0115f..f4270ab0 100644 --- a/src/test/java/factorytesting/RandomNumberGeneratorTest.java +++ b/src/test/java/factorytesting/RandomNumberGeneratorTest.java @@ -6,38 +6,56 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +/** + * This class contains unit tests for the RandomNumberGenerator class. + */ public class RandomNumberGeneratorTest { private static final int PASSWORD_LENGTH = 8; private RandomNumberGenerator generator; + /** + * Set up the test environment by initializing the RandomNumberGenerator instance. + */ @BeforeEach void setUp() { generator = new RandomNumberGenerator(); } + /** + * Test the generation of a client ID and check if it starts with "2". + */ @Test void testGenerateClientId() { int clientId = generator.generateClientId(PASSWORD_LENGTH); assertTrue(String.valueOf(clientId).startsWith("2"), "ClientId should start with 2."); } + /** + * Test the generation of an attorney ID and check if it starts with "1". + */ @Test void testGenerateAttorneyId() { int attorneyId = generator.generateAttorneyId(PASSWORD_LENGTH); assertTrue(String.valueOf(attorneyId).startsWith("1"), "AttorneyId should start with 1."); } + /** + * Test the generation of a question ID and check if it starts with "3". + */ @Test void testGenerateQuestionId() { int questionId = generator.generateQuestionId(PASSWORD_LENGTH); assertTrue(String.valueOf(questionId).startsWith("3"), "QuestionId should start with 3."); } + /** + * Test the generation of a post ID and check if it starts with "4". + */ @Test void testGeneratePostId() { int postId = generator.generatePostId(PASSWORD_LENGTH); assertTrue(String.valueOf(postId).startsWith("4"), "PostId should start with 4."); } -} +} \ No newline at end of file diff --git a/src/test/java/gatewaytesting/AttorneyRepositoryTest.java b/src/test/java/gatewaytesting/AttorneyRepositoryTest.java index e9706eb8..ef3758f1 100644 --- a/src/test/java/gatewaytesting/AttorneyRepositoryTest.java +++ b/src/test/java/gatewaytesting/AttorneyRepositoryTest.java @@ -18,6 +18,9 @@ import static org.junit.jupiter.api.Assertions.*; +/** + * This class contains unit tests for the AttorneyRepository class. + */ public class AttorneyRepositoryTest { //Attorney @@ -32,6 +35,9 @@ public class AttorneyRepositoryTest { final static int ASKED_BY_CLIENT1 = 20; final static int ASKED_BY_CLIENT2 = 30; + /** + * Set up the test environment by initializing the AttorneyRepository instance. + */ @BeforeAll public static void setUp() { //Attorney @@ -94,6 +100,9 @@ public static void setUp() { qRepo.save(q2); } + /** + * Test whether an attorney ID exists in the repository. + */ @Test public void testExistsById(){ AttorneyRepository repo = new AttorneyRepository(); @@ -103,6 +112,9 @@ public void testExistsById(){ assertFalse(repo.existsById(75), "The id exists!"); } + /** + * Test whether an attorney with a given username exists in the repository. + */ @Test public void testExistsByName() { AttorneyRepository repo = new AttorneyRepository(); @@ -112,6 +124,9 @@ public void testExistsByName() { assertFalse(repo.existsByName("John"), "The username exists!"); } + /** + * Test updating an attorney's question list. + */ @Test public void testUpdateQuestionList() { AttorneyRepository repo = new AttorneyRepository(); @@ -124,6 +139,9 @@ public void testUpdateQuestionList() { assert expectedList1.equals(repo.get(ATTORNEY_ID).getQuestionsList()); } + /** + * Delete all data in AttorneyRepository, ClientRepository and QuestionRepo. + */ @AfterAll public static void tearDown() { AttorneyRepository repo = new AttorneyRepository(); @@ -134,6 +152,9 @@ public static void tearDown() { qRepo.deleteAll(); } + /** + * Test getting an attorney from the repository. + */ @Test public void testGetUser() { String attorneyUsername = "yao"; @@ -158,6 +179,9 @@ public void testGetUser() { assertEquals(a, repo.get(ATTORNEY_ID), "That is not the correct client!"); } + /** + * Test adding an attorney to the repository. + */ @Test public void testAddUser() { int attorneyId = 50; @@ -183,6 +207,9 @@ public void testAddUser() { assertTrue(repo.existsById(attorneyId), "The attorney is not added!"); } + /** + * Test deleting an attorney in the repository. + */ @Test public void testDeleteUser() { int attorneyId = 50; @@ -213,6 +240,9 @@ public void testDeleteUser() { repo.save(a); } + /** + * Test deleting all attorneys in the repository. + */ @Test public void testDeleteAllUser() { int attorneyId = 50; diff --git a/src/test/java/gatewaytesting/ClientRepositoryTest.java b/src/test/java/gatewaytesting/ClientRepositoryTest.java index 7b2c98b8..525df0ff 100644 --- a/src/test/java/gatewaytesting/ClientRepositoryTest.java +++ b/src/test/java/gatewaytesting/ClientRepositoryTest.java @@ -21,6 +21,9 @@ import static org.junit.jupiter.api.Assertions.*; +/** + * This class contains unit tests for the ClientRepository class. + */ public class ClientRepositoryTest { //Client @@ -32,6 +35,9 @@ public class ClientRepositoryTest { final static int QUESTION_ID1 = 25; final static int QUESTION_ID2 = 35; + /** + * Set up the test environment by initializing the ClientRepository instance. + */ @BeforeAll public static void setUp() { //Client @@ -91,6 +97,9 @@ public static void setUp() { qRepo.save(q2); } + /** + * Test whether a client ID exists in the repository. + */ @Test public void testExistsById(){ ClientRepository repo = new ClientRepository(); @@ -100,6 +109,9 @@ public void testExistsById(){ assertFalse(repo.existsById(200), "The id exists!"); } + /** + * Test whether a client with a given username exists in the repository. + */ @Test public void testExistsByName() { ClientRepository repo = new ClientRepository(); @@ -109,6 +121,9 @@ public void testExistsByName() { assertFalse(repo.existsByName("John"), "The username exists!"); } + /** + * Test updating a client's question list. + */ @Test public void testUpdateQuestionList() { ClientRepository repo = new ClientRepository(); @@ -120,6 +135,9 @@ public void testUpdateQuestionList() { assert expectedList.equals(repo.get(CLIENT_ID).getQuestionsList()); } + /** + * Delete all data in AttorneyRepository, ClientRepository and QuestionRepo. + */ @AfterAll public static void tearDown() { ClientRepository repo = new ClientRepository(); @@ -130,6 +148,9 @@ public static void tearDown() { qRepo.deleteAll(); } + /** + * Test getting a client from the repository. + */ @Test public void testGetUser() { String clientUsername = "bob"; @@ -160,6 +181,9 @@ public void testGetUser() { assertEquals(c, repo.get(100), "That is not the correct client!"); } + /** + * Test adding a client to the repository. + */ @Test public void testAddUser() { String clientUsername = "bob"; @@ -190,6 +214,9 @@ public void testAddUser() { assertTrue(repo.existsById(100), "The client is not added!"); } + /** + * Test deleting a client in the repository. + */ @Test public void testDeleteUser() { int clientId = 100; @@ -226,6 +253,9 @@ public void testDeleteUser() { repo.save(c); } + /** + * Test deleting all client in the repository. + */ @Test public void testDeleteAllUser() { int clientId = 100; diff --git a/src/test/java/gatewaytesting/PostRepoTest.java b/src/test/java/gatewaytesting/PostRepoTest.java index cf13ed97..f8e435f6 100644 --- a/src/test/java/gatewaytesting/PostRepoTest.java +++ b/src/test/java/gatewaytesting/PostRepoTest.java @@ -10,6 +10,9 @@ import static org.junit.jupiter.api.Assertions.*; +/** + * This class contains unit tests for the PostRepo class. + */ public class PostRepoTest { //Post @@ -18,6 +21,9 @@ public class PostRepoTest { //Question final static int QUESTION_ID = 10; + /** + * Set up the test environment by initializing the PostRepo instance. + */ @BeforeEach public void setUp() { LocalDate createdAt = LocalDate.now(); @@ -33,6 +39,9 @@ public void setUp() { repo.save(p); } + /** + * Test whether a post ID exists in the repository. + */ @Test public void testCheckExistsById() { PostRepo repo = new PostRepo(); @@ -42,7 +51,9 @@ public void testCheckExistsById() { assertFalse(repo.existsById(15), "The id exists!"); } - + /** + * Test saving a post into the repository. + */ @Test public void testSavePost() { int questionId = 15; @@ -63,6 +74,9 @@ public void testSavePost() { assertTrue(repo.existsById(postId), "Post is not saved into the database!"); } + /** + * Test retrieving a post from the repository. + */ @Test public void testGetPost() { int questionId = 15; @@ -83,6 +97,9 @@ public void testGetPost() { assertEquals(p, repo.get(postId), "That is not the correct post!"); } + /** + * Test deleting a post from the repository. + */ @Test public void testDeletePost() { int questionId = 15; @@ -99,12 +116,15 @@ public void testDeletePost() { repo.deleteAll(); repo.save(p); - //test deleting an existing client from the database + //test deleting an existing post from the database assertTrue(repo.existsById(postId), "The post was not added!"); repo.delete(postId); assertFalse(repo.existsById(postId), "the post was not deleted!"); } + /** + * Test deleting all posts from the repository. + */ @Test public void testDeleteAllPost() { int questionId = 15; diff --git a/src/test/java/gatewaytesting/QuestionRepoTest.java b/src/test/java/gatewaytesting/QuestionRepoTest.java index 431489e0..0f6ac4ee 100644 --- a/src/test/java/gatewaytesting/QuestionRepoTest.java +++ b/src/test/java/gatewaytesting/QuestionRepoTest.java @@ -17,6 +17,9 @@ import static org.junit.jupiter.api.Assertions.*; +/** + * This class contains unit tests for the QuestionRepo class. + */ public class QuestionRepoTest { //Question @@ -33,6 +36,9 @@ public class QuestionRepoTest { final static int ATTORNEY_ID = 150; final static int ATTORNEY_ID1 = 151; + /** + * Set up the test environment by initializing the QuestionRepo instance. + */ @BeforeAll public static void setUp() { //Question @@ -90,6 +96,9 @@ public static void setUp() { aRepo.save(a1); } + /** + * Tests the existsById method of the QuestionRepo class. + */ @Test public void testExistsById() { QuestionRepo repo = new QuestionRepo(); @@ -99,6 +108,9 @@ public void testExistsById() { assertFalse(repo.existsById(7), "The question exists!"); } + /** + * Test for the getAll method of QuestionRepo. + */ @Test public void testGetAllQuestion() { QuestionRepo repo = new QuestionRepo(); @@ -120,6 +132,9 @@ public void testGetAllQuestion() { repo.save(q1); } + /** + * Test for the getNotTakenQuestion method of QuestionRepo. + */ @Test public void testGetNotTakenQuestion() { QuestionRepo repo = new QuestionRepo(); @@ -129,6 +144,9 @@ public void testGetNotTakenQuestion() { assert expectedList.equals(repo.getNotTakenQuestion()); } + /** + * Test for the getNotClosedQuestion method of QuestionRepo. + */ @Test public void testGetNotClosedQuestion() { QuestionRepo repo = new QuestionRepo(); @@ -138,6 +156,9 @@ public void testGetNotClosedQuestion() { assert expectedList.equals(repo.getNotClosedQuestion()); } + /** + * Test for the getAllPostOfQuestion method of QuestionRepo. + */ @Test public void testGetAllPostByQuestion() { QuestionRepo repo = new QuestionRepo(); @@ -149,6 +170,9 @@ public void testGetAllPostByQuestion() { assert expectedList.equals(repo.getAllPostOfQuestion(QUESTION_ID)); } + /** + * Test for the updateIsTaken method of QuestionRepo. + */ @Test public void testUpdateIsTaken() { QuestionRepo repo = new QuestionRepo(); @@ -167,6 +191,9 @@ public void testUpdateIsTaken() { repo.updateIsTaken(QUESTION_ID1, false); } + /** + * Tests the updateTakenByAttorney method of the QuestionRepo class. + */ @Test public void testUpdateTakenByAttorney() { QuestionRepo repo = new QuestionRepo(); @@ -179,6 +206,9 @@ public void testUpdateTakenByAttorney() { assertNotEquals(ATTORNEY_ID, repo.get(QUESTION_ID).getTakenByAttorney(), "q is taken by a!"); } + /** + * Tests the updateIsClose method of the QuestionRepo class. + */ @Test public void testUpdateIsClose() { QuestionRepo repo = new QuestionRepo(); @@ -193,6 +223,9 @@ public void testUpdateIsClose() { assertFalse(repo.get(QUESTION_ID).isClose(), "This question was updated!"); } + /** + * Tests the updateRating method of the QuestionRepo class. + */ @Test public void testUpdateRating() { QuestionRepo repo = new QuestionRepo(); @@ -207,6 +240,9 @@ public void testUpdateRating() { assertEquals(0, repo.get(QUESTION_ID).getRating(), "This question was updated!"); } + /** + * Tests the updateTakenAt method of the QuestionRepo class. + */ @Test public void testUpdateTakenAt() { LocalDate changeDate = LocalDate.now().minusDays(1); @@ -222,6 +258,9 @@ public void testUpdateTakenAt() { assertEquals(CREATE_AT, repo.get(QUESTION_ID).getTakenAt(), "This question was updated!"); } + /** + * Tests the updatePosts method of the QuestionRepo class. + */ @Test public void testUpdatePosts() { QuestionRepo repo = new QuestionRepo(); @@ -233,6 +272,9 @@ public void testUpdatePosts() { assert expectedList.equals(repo.get(QUESTION_ID).getPosts()); } + /** + * Delete all data in AttorneyRepository, ClientRepository and QuestionRepo. + */ @AfterAll public static void tearDown() { QuestionRepo repo = new QuestionRepo(); @@ -243,6 +285,9 @@ public static void tearDown() { aRepo.deleteAll(); } + /** + * Tests saving a question using the save method of the QuestionRepo class. + */ @Test public void testSaveQuestion() { int questionId = 6; @@ -265,6 +310,9 @@ public void testSaveQuestion() { assertTrue(repo.existsById(questionId), "Question is not saved into the database!"); } + /** + * Tests retrieving a question using the get method of the QuestionRepo class. + */ @Test public void testGetQuestion() { int questionId = 6; @@ -287,6 +335,9 @@ public void testGetQuestion() { assertEquals(q, repo.get(questionId), "That is not the correct question!"); } + /** + * Tests deleting a question in the QuestionRepo. + */ @Test public void testDeleteQuestion() { int questionId = 6; @@ -318,6 +369,9 @@ public void testDeleteQuestion() { repo.save(q1); } + /** + * Tests deleting all question in QuestionRepo. + */ @Test public void testDeleteAllQuestion() { int questionId = 6; From 8fddfcf404c07726a2cc9eaaecd107b5c32108a2 Mon Sep 17 00:00:00 2001 From: river3966 Date: Sun, 13 Aug 2023 05:13:00 -0400 Subject: [PATCH 16/24] doc --- .../AskQuestionUseCaseTest.java | 27 +++++++--- .../BrowseQuestionUseCaseTest.java | 13 ++++- .../ClientRegisterUseCaseTest.java | 34 +++++++++++- .../java/usecasetesting/CloseUseCaseTest.java | 54 ++++++++++++++----- .../usecasetesting/RateAnswerUseCaseTest.java | 45 +++++++++++----- .../java/usecasetesting/ReplyUseCaseTest.java | 22 ++++++++ .../SelectQuestionUseCaseTest.java | 22 +++++++- .../usecasetesting/UserLoginUseCaseTest.java | 18 +++++++ .../UserViewHistoryUseCaseTest.java | 15 ++++++ 9 files changed, 215 insertions(+), 35 deletions(-) diff --git a/src/test/java/usecasetesting/AskQuestionUseCaseTest.java b/src/test/java/usecasetesting/AskQuestionUseCaseTest.java index f82d8d70..8225cd41 100644 --- a/src/test/java/usecasetesting/AskQuestionUseCaseTest.java +++ b/src/test/java/usecasetesting/AskQuestionUseCaseTest.java @@ -19,6 +19,9 @@ import static org.junit.jupiter.api.Assertions.*; ; +/** + * This class contains unit tests for the AskQuestionUseCase class. + */ public class AskQuestionUseCaseTest { final static int CLIENT_ID = 21345678; @@ -31,6 +34,9 @@ public class AskQuestionUseCaseTest { private TheQuestionOutputBoundary theQuestionOutputBoundary; private QuestionInputBoundary questionInputBoundary; + /** + * Set up the test environment by initializing the AskQuestionUseCase instance. + */ public void setUpAskQuestionUseCase(){ questionGateway = new QuestionRepo(); questionFactory = new QuestionFactory(); @@ -70,8 +76,11 @@ public TheQuestionResponseModel prepareSuccess(TheQuestionResponseModel response attorneyGateway.save(secondAttorney); } + /** + * Test the AskQuestionUseCase when the question is created successfully. + */ @Test - public void TestAskQuestionPassed(){ + public void testAskQuestionPassed(){ setUpAskQuestionUseCase(); QuestionRequestModel inputData = new QuestionRequestModel("fraud", "Test title", LocalDate.now(), CLIENT_ID, LocalDate.now()); @@ -80,11 +89,14 @@ public void TestAskQuestionPassed(){ User user = clientGateway.get(CLIENT_ID); assertEquals(1, user.getQuestionsList().size(), "The ask question use case failed."); - ClearAllRepository(); + clearAllRepository(); } + /** + * Test the AskQuestionUseCase when the question creation fails due to an empty category. + */ @Test - public void TestAskQuestionFailByEmptyCategory(){ + public void testAskQuestionFailByEmptyCategory(){ setUpAskQuestionUseCase(); QuestionRequestModel inputData = new QuestionRequestModel(null, "Test title", LocalDate.now(), CLIENT_ID, LocalDate.now()); @@ -93,10 +105,13 @@ public void TestAskQuestionFailByEmptyCategory(){ User user = clientGateway.get(CLIENT_ID); assertEquals(0, user.getQuestionsList().size(), "The ask question use case failed."); - ClearAllRepository(); + clearAllRepository(); } - public void ClearAllRepository(){ + /** + * Delete all data in questionGateway, clientGateway and attorneyGateway. + */ + public void clearAllRepository(){ questionGateway = new QuestionRepo(); clientGateway = new ClientRepository(); attorneyGateway = new AttorneyRepository(); @@ -104,4 +119,4 @@ public void ClearAllRepository(){ questionGateway.deleteAll(); attorneyGateway.deleteAll(); } -} +} \ No newline at end of file diff --git a/src/test/java/usecasetesting/BrowseQuestionUseCaseTest.java b/src/test/java/usecasetesting/BrowseQuestionUseCaseTest.java index a338e25b..44d6f87a 100644 --- a/src/test/java/usecasetesting/BrowseQuestionUseCaseTest.java +++ b/src/test/java/usecasetesting/BrowseQuestionUseCaseTest.java @@ -17,7 +17,9 @@ import static org.junit.jupiter.api.Assertions.*; ; - +/** + * This class contains unit tests for the BrowseQuestionUseCase class. + */ public class BrowseQuestionUseCaseTest { final static int CLIENT_ID = 21345678; final static int ATTORNEY_ID = 11345678; @@ -48,6 +50,9 @@ public ViewResponseModel prepareSuccess(ViewResponseModel response) { }; private ViewInputBoundary viewInputBoundary; + /** + * Set up the test environment by initializing the BrowseQuestionUseCase instance. + */ public void setUpBrowseUseCase(){ questionGateway = new QuestionRepo(); clientGateway = new ClientRepository(); @@ -80,6 +85,9 @@ public void setUpBrowseUseCase(){ } + /** + * Test the AttorneyBrowseQuestionUseCase when the question is created successfully. + */ @Test public void TestAttorneyBrowseQuestionUseCase(){ setUpBrowseUseCase(); @@ -89,6 +97,9 @@ public void TestAttorneyBrowseQuestionUseCase(){ ClearAllRepository(); } + /** + * Delete all data in questionGateway, clientGateway and attorneyGateway. + */ public void ClearAllRepository(){ questionGateway = new QuestionRepo(); clientGateway = new ClientRepository(); diff --git a/src/test/java/usecasetesting/ClientRegisterUseCaseTest.java b/src/test/java/usecasetesting/ClientRegisterUseCaseTest.java index ab04a7d9..0c0e2a3f 100644 --- a/src/test/java/usecasetesting/ClientRegisterUseCaseTest.java +++ b/src/test/java/usecasetesting/ClientRegisterUseCaseTest.java @@ -13,7 +13,9 @@ import static org.junit.Assert.fail; ; - +/** + * This class contains unit tests for the ClientRegisterUseCase class. + */ public class ClientRegisterUseCaseTest { final static String PASSWORD = "abcdefghi"; final static int USER_ID = 11234567; @@ -33,6 +35,10 @@ public class ClientRegisterUseCaseTest { private ClientGateway clientGateway; private RegisterOutputBoundary registerOutputBoundary; private UserRegisterInputBoundary clientRegisterInputBoundary; + + /** + * Set up the test environment by initializing the ClientRegisterUseCase instance. + */ public void setUpClientRegisterUseCase(){ clientGateway = new ClientRepository(); clientFactory = new ClientFactory(); @@ -59,6 +65,10 @@ public RegisterResponseModel prepareFail(String msg) { clientRegisterInputBoundary = new ClientRegisterInteractor(clientGateway, clientFactory, registerOutputBoundary); } + + /** + * Test the successful registration scenario. + */ @Test public void TestSuccessfulRegistration(){ setUpClientRegisterUseCase(); @@ -69,6 +79,9 @@ public void TestSuccessfulRegistration(){ ClearAllRepository(); } + /** + * Test the registration failure scenario due to an existing user. + */ @Test public void TestRegistrationFailByAlreadyExists(){ setUpClientRegisterUseCase(); @@ -80,6 +93,9 @@ public void TestRegistrationFailByAlreadyExists(){ ClearAllRepository(); } + /** + * Test registration failure due to password not matching. + */ @Test public void TestRegistrationFailByPasswordDoesNotMatch(){ setUpClientRegisterUseCase(); @@ -88,6 +104,10 @@ public void TestRegistrationFailByPasswordDoesNotMatch(){ clientRegisterInputBoundary.create(inputData); ClearAllRepository(); } + + /** + * Test registration failure due to password length being too small. + */ @Test public void TestRegistrationFailByPasswordLengthTooSmall(){ setUpClientRegisterUseCase(); @@ -98,6 +118,9 @@ public void TestRegistrationFailByPasswordLengthTooSmall(){ ClearAllRepository(); } + /** + * Test registration failure due to invalid email format. + */ @Test public void TestRegistrationFailByInvalidEmail(){ setUpClientRegisterUseCase(); @@ -108,6 +131,9 @@ public void TestRegistrationFailByInvalidEmail(){ ClearAllRepository(); } + /** + * Test registration failure due to invalid age. + */ @Test public void TestRegistrationFailByInvalidAge(){ setUpClientRegisterUseCase(); @@ -118,6 +144,9 @@ public void TestRegistrationFailByInvalidAge(){ ClearAllRepository(); } + /** + * Test registration failure due to invalid postal code. + */ @Test public void TestRegistrationFailByInvalidPostalCode(){ setUpClientRegisterUseCase(); @@ -128,6 +157,9 @@ public void TestRegistrationFailByInvalidPostalCode(){ ClearAllRepository(); } + /** + * Delete all data in clientGateway. + */ public void ClearAllRepository(){ clientGateway = new ClientRepository(); clientGateway.deleteAll();; diff --git a/src/test/java/usecasetesting/CloseUseCaseTest.java b/src/test/java/usecasetesting/CloseUseCaseTest.java index 5f77724a..64f64860 100644 --- a/src/test/java/usecasetesting/CloseUseCaseTest.java +++ b/src/test/java/usecasetesting/CloseUseCaseTest.java @@ -1,6 +1,5 @@ package usecasetesting; - import adapter.controller.ControlContainer; import businessrule.gateway.*; import businessrule.inputboundary.CloseInputBoundary; @@ -16,14 +15,20 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; -; +/** + * This class contains test cases for the CloseUseCase class. + */ public class CloseUseCaseTest { + + // IDs for testing purposes final static int CLIENT_ID = 21345678; final static int ATTORNEY_ID = 11345678; final static int SECOND_ATTORNEY_ID = 12222222; final static int QUESTION_ID = 323456789; final static int CLOSED_QUESTION_ID = 333333333; + + // Gateways and use case components private QuestionGateway questionGateway; private PostGateway postGateway; private PostFactory postFactory; @@ -33,18 +38,23 @@ public class CloseUseCaseTest { private HomePageOutputBoundary homePageOutputBoundary; private CloseInputBoundary closeInputBoundary; - public void setUpCloseUseCase(){ - + /** + * Set up the test environment by initializing the CloseUseUseCase instance. + */ + public void setUpCloseUseCase() { + // Initialize gateways and use case components questionGateway = new QuestionRepo(); postGateway = new PostRepo(); postFactory = new PostFactory(); userGatewayFactory = new UserGatewayFactory(); clientGateway = new ClientRepository(); attorneyGateway = new AttorneyRepository(); + + // Mocking homePageOutputBoundary homePageOutputBoundary = new HomePageOutputBoundary() { @Override public void setControlContainer(ControlContainer controlContainer) { - + // No implementation needed for testing } @Override @@ -55,15 +65,18 @@ public HomePageResponseModel prepareFail(String msg) { @Override public HomePageResponseModel prepareSuccess(HomePageResponseModel homePageResponseModel) { + // No implementation needed for testing return null; } }; + + // Initialize closeInputBoundary closeInputBoundary = new CloseQuestionInteractor(questionGateway, homePageOutputBoundary, userGatewayFactory); + // Setting up test data Question question = new Question(); question.setQuestionId(QUESTION_ID); - Question closedQuestion = new Question(); closedQuestion.setQuestionId(CLOSED_QUESTION_ID); questionGateway.save(closedQuestion); @@ -85,8 +98,12 @@ public HomePageResponseModel prepareSuccess(HomePageResponseModel homePageRespon question.setTaken(true); questionGateway.save(question); } + + /** + * Test case for closing a question by a client. + */ @Test - public void TestClientCloseableQuestion(){ + public void TestClientCloseableQuestion() { setUpCloseUseCase(); CloseRequestModel inputData = new CloseRequestModel(QUESTION_ID, CLIENT_ID); @@ -96,8 +113,12 @@ public void TestClientCloseableQuestion(){ assertEquals(question.isClose(), true); ClearAllRepository(); } + + /** + * Test case for attempting to close an already closed question by a client. + */ @Test - public void TestClientUnclosableQuestion(){ + public void TestClientUnclosableQuestion() { setUpCloseUseCase(); CloseRequestModel inputData = new CloseRequestModel(CLOSED_QUESTION_ID, CLIENT_ID); @@ -105,8 +126,11 @@ public void TestClientUnclosableQuestion(){ ClearAllRepository(); } + /** + * Test case for attempting to close a question by an attorney when it's already closed. + */ @Test - public void TestAttorneyClosedQuestion(){ + public void TestAttorneyClosedQuestion() { setUpCloseUseCase(); CloseRequestModel inputData = new CloseRequestModel(CLOSED_QUESTION_ID, CLIENT_ID); @@ -114,8 +138,11 @@ public void TestAttorneyClosedQuestion(){ ClearAllRepository(); } + /** + * Test case for attempting to close a question by an attorney when the question is not taken by them. + */ @Test - public void TestAttorneyNonTakenQuestion(){ + public void TestAttorneyNonTakenQuestion() { setUpCloseUseCase(); CloseRequestModel inputData = new CloseRequestModel(CLOSED_QUESTION_ID, CLIENT_ID); @@ -123,7 +150,10 @@ public void TestAttorneyNonTakenQuestion(){ ClearAllRepository(); } - public void ClearAllRepository(){ + /** + * Delete all data in clientGateway. + */ + public void ClearAllRepository() { questionGateway = new QuestionRepo(); clientGateway = new ClientRepository(); attorneyGateway = new AttorneyRepository(); @@ -133,4 +163,4 @@ public void ClearAllRepository(){ attorneyGateway.deleteAll(); postGateway.deleteAll(); } -} +} \ No newline at end of file diff --git a/src/test/java/usecasetesting/RateAnswerUseCaseTest.java b/src/test/java/usecasetesting/RateAnswerUseCaseTest.java index 58c5740c..977c4b2d 100644 --- a/src/test/java/usecasetesting/RateAnswerUseCaseTest.java +++ b/src/test/java/usecasetesting/RateAnswerUseCaseTest.java @@ -1,26 +1,23 @@ package usecasetesting; - import adapter.controller.ControlContainer; import businessrule.gateway.*; - import businessrule.inputboundary.RateInputBoundary; import businessrule.outputboundary.HomePageOutputBoundary; import businessrule.requestmodel.RateRequestModel; import businessrule.responsemodel.HomePageResponseModel; import businessrule.usecase.RateInteractor; - import driver.database.*; import entity.Attorney; import entity.Client; import entity.factory.PostFactory; import entity.Question; import org.junit.jupiter.api.Test; - - import static org.junit.jupiter.api.Assertions.*; -; +/** + * This class contains unit tests for the RateAnswerUseCase class. + */ public class RateAnswerUseCaseTest { final static int CLIENT_ID = 21345678; @@ -37,22 +34,28 @@ public class RateAnswerUseCaseTest { private HomePageOutputBoundary homePageOutputBoundary; private RateInputBoundary rateInputBoundary; - public void setUpRateAnswerUseCase(){ - + /** + * Set up the test environment by initializing the RateAnswerUseCase instance. + */ + public void setUpRateAnswerUseCase() { + // Initialize gateways and other components questionGateway = new QuestionRepo(); postGateway = new PostRepo(); postFactory = new PostFactory(); userGatewayFactory = new UserGatewayFactory(); clientGateway = new ClientRepository(); attorneyGateway = new AttorneyRepository(); + + // Clear repositories clientGateway.deleteAll(); questionGateway.deleteAll(); attorneyGateway.deleteAll(); postGateway.deleteAll(); + + // Initialize homePageOutputBoundary homePageOutputBoundary = new HomePageOutputBoundary() { @Override public void setControlContainer(ControlContainer controlContainer) { - } @Override @@ -66,12 +69,14 @@ public HomePageResponseModel prepareSuccess(HomePageResponseModel homePageRespon return null; } }; - rateInputBoundary = new RateInteractor(questionGateway, homePageOutputBoundary, clientGateway, attorneyGateway); + // Initialize rateInputBoundary + rateInputBoundary = new RateInteractor(questionGateway, homePageOutputBoundary, clientGateway, attorneyGateway); + + // Create and set up test data Question question = new Question(); question.setQuestionId(QUESTION_ID); - Question closedQuestion = new Question(); closedQuestion.setQuestionId(CLOSED_QUESTION_ID); closedQuestion.setClose(true); @@ -94,22 +99,34 @@ public HomePageResponseModel prepareSuccess(HomePageResponseModel homePageRespon question.setTaken(true); questionGateway.save(question); } + + /** + * Test for the scenario when a client rates a closed question. + */ @Test - public void TestClientRateClosedQuestion(){ + public void TestClientRateClosedQuestion() { setUpRateAnswerUseCase(); RateRequestModel inputData = new RateRequestModel(10, CLOSED_QUESTION_ID, CLIENT_ID); rateInputBoundary.rateAnswer(inputData); assertEquals(10, questionGateway.get(CLOSED_QUESTION_ID).getRating()); ClearAllRepository(); } + + /** + * Test for the scenario when a client rates an unclosed question. + */ @Test - public void TestClientRateUnClosedQuestion(){ + public void TestClientRateUnClosedQuestion() { setUpRateAnswerUseCase(); RateRequestModel inputData = new RateRequestModel(10, QUESTION_ID, CLIENT_ID); rateInputBoundary.rateAnswer(inputData); ClearAllRepository(); } - public void ClearAllRepository(){ + + /** + * Delete all data in clientGateway, questionGateway, attorneyGateway, postGateway. + */ + public void ClearAllRepository() { questionGateway = new QuestionRepo(); clientGateway = new ClientRepository(); attorneyGateway = new AttorneyRepository(); diff --git a/src/test/java/usecasetesting/ReplyUseCaseTest.java b/src/test/java/usecasetesting/ReplyUseCaseTest.java index 9bd39d3c..47b27d79 100644 --- a/src/test/java/usecasetesting/ReplyUseCaseTest.java +++ b/src/test/java/usecasetesting/ReplyUseCaseTest.java @@ -16,6 +16,9 @@ import static org.junit.jupiter.api.Assertions.*; ; +/** + * This class contains test cases for the ReplyUseCase. + */ public class ReplyUseCaseTest { final static int CLIENT_ID = 21345678; @@ -31,6 +34,10 @@ public class ReplyUseCaseTest { private AttorneyGateway attorneyGateway; private HomePageOutputBoundary homePageOutputBoundary; private PostInputBoundary postInputBoundary; + + /** + * Set up the test environment by initializing the ReplyUseCase instance. + */ public void setUpReplyUseCase(){ questionGateway = new QuestionRepo(); @@ -82,6 +89,9 @@ public HomePageResponseModel prepareSuccess(HomePageResponseModel homePageRespon attorneyGateway.save(secondAttorney); } + /** + * Test client's reply to a question. + */ @Test public void testClientReply(){ setUpReplyUseCase(); @@ -94,6 +104,9 @@ public void testClientReply(){ ClearAllRepository(); } + /** + * Test attorney's first reply to a question. + */ @Test public void testAttorneyFirstReply(){ setUpReplyUseCase(); @@ -111,6 +124,9 @@ public void testAttorneyFirstReply(){ assertEquals(attorneyQuestion.isTaken(), true); ClearAllRepository(); } + /** + * Test attorney's follow-up reply to a question. + */ @Test public void testAttorneyFollowUp(){ setUpReplyUseCase(); @@ -143,6 +159,9 @@ public void testFailToReplyQuestionClosed(){ ClearAllRepository(); } + /** + * Test failure to reply to a closed question. + */ @Test public void testAttorneyFailToReplyQuestionTakenByOther(){ setUpReplyUseCase(); @@ -160,6 +179,9 @@ public void testAttorneyFailToReplyQuestionTakenByOther(){ ClearAllRepository(); } + /** + * Delete all data in clientGateway, questionGateway, attorneyGateway, postGateway. + */ public void ClearAllRepository(){ questionGateway = new QuestionRepo(); clientGateway = new ClientRepository(); diff --git a/src/test/java/usecasetesting/SelectQuestionUseCaseTest.java b/src/test/java/usecasetesting/SelectQuestionUseCaseTest.java index d5e78d9e..6c3b352f 100644 --- a/src/test/java/usecasetesting/SelectQuestionUseCaseTest.java +++ b/src/test/java/usecasetesting/SelectQuestionUseCaseTest.java @@ -20,7 +20,9 @@ import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.*; ; - +/** + * This class contains test cases for the SelectQuestionUseCase. + */ public class SelectQuestionUseCaseTest { final static int CLIENT_ID = 21345678; final static int ATTORNEY_ID = 11345678; @@ -38,6 +40,9 @@ public class SelectQuestionUseCaseTest { private TheQuestionOutputBoundary theQuestionOutputBoundary; private SelectInputBoundary selectInputBoundary; + /** + * Set up the test environment by initializing the SelectQuestionUseCase instance. + */ public void setUpSelectUseCase(){ questionGateway = new QuestionRepo(); userGatewayFactory = new UserGatewayFactory(); @@ -120,6 +125,9 @@ public void TestClientSelectQuestionUseCase(){ ClearAllRepository(); } + /** + * Test the scenario where an attorney selects a non-taken question. + */ @Test public void TestAttorneySelectNonTakenQuestionUseCase(){ setUpSelectUseCase(); @@ -129,6 +137,9 @@ public void TestAttorneySelectNonTakenQuestionUseCase(){ ClearAllRepository(); } + /** + * Test the scenario where an attorney selects a question taken by himself. + */ @Test public void TestAttorneySelectQuestionTakenByHimselfUseCase(){ setUpSelectUseCase(); @@ -138,6 +149,9 @@ public void TestAttorneySelectQuestionTakenByHimselfUseCase(){ ClearAllRepository(); } + /** + * Test the scenario where an attorney's attempt to select a closed question fails. + */ @Test public void TestAttorneySelectQuestionFailByClosedQuestion(){ setUpSelectUseCase(); @@ -147,6 +161,9 @@ public void TestAttorneySelectQuestionFailByClosedQuestion(){ ClearAllRepository(); } + /** + * Test the scenario where an attorney's attempt to select a question taken by another attorney fails. + */ @Test public void TestAttorneySelectQuestionFailByTakenByOther(){ setUpSelectUseCase(); @@ -156,6 +173,9 @@ public void TestAttorneySelectQuestionFailByTakenByOther(){ ClearAllRepository(); } + /** + * Delete all data in clientGateway, questionGateway, attorneyGateway, postGateway. + */ public void ClearAllRepository(){ questionGateway = new QuestionRepo(); clientGateway = new ClientRepository(); diff --git a/src/test/java/usecasetesting/UserLoginUseCaseTest.java b/src/test/java/usecasetesting/UserLoginUseCaseTest.java index 30258d20..29172256 100644 --- a/src/test/java/usecasetesting/UserLoginUseCaseTest.java +++ b/src/test/java/usecasetesting/UserLoginUseCaseTest.java @@ -15,6 +15,9 @@ import static org.junit.jupiter.api.Assertions.*; +/** + * This class contains test cases for the UserLoginUseCase. + */ public class UserLoginUseCaseTest { final static int CLIENT_ID = 21345678; @@ -24,6 +27,9 @@ public class UserLoginUseCaseTest { private HomePageOutputBoundary homePageOutputBoundary; private UserLoginInputBoundary userLoginInputBoundary; + /** + * Set up the test environment by initializing the UserLoginUseCase instance. + */ public void setUpUserLoginUseCase(){ userGatewayFactory = new UserGatewayFactory(); clientGateway = new ClientRepository(); @@ -52,6 +58,9 @@ public HomePageResponseModel prepareSuccess(HomePageResponseModel homePageRespon client.setPassword(PASSWORD); clientGateway.save(client); } + /** + * Test a successful user login scenario. + */ @Test public void TestLoginPass(){ setUpUserLoginUseCase(); @@ -59,6 +68,9 @@ public void TestLoginPass(){ userLoginInputBoundary.login(inputData); ClearAllRepository(); } + /** + * Test user login fails because the provided ID does not exist. + */ @Test public void TestLoginFailIdDNE(){ setUpUserLoginUseCase(); @@ -66,6 +78,9 @@ public void TestLoginFailIdDNE(){ userLoginInputBoundary.login(inputData); ClearAllRepository(); } + /** + * Test the scenario where user login fails because the provided password is incorrect. + */ @Test public void TestLoginFailWrongPassword(){ setUpUserLoginUseCase(); @@ -74,6 +89,9 @@ public void TestLoginFailWrongPassword(){ ClearAllRepository(); } + /** + * Delete all data in clientGateway. + */ public void ClearAllRepository(){ clientGateway = new ClientRepository(); clientGateway.deleteAll(); diff --git a/src/test/java/usecasetesting/UserViewHistoryUseCaseTest.java b/src/test/java/usecasetesting/UserViewHistoryUseCaseTest.java index a09d4152..7eee2cc8 100644 --- a/src/test/java/usecasetesting/UserViewHistoryUseCaseTest.java +++ b/src/test/java/usecasetesting/UserViewHistoryUseCaseTest.java @@ -24,6 +24,9 @@ import static org.junit.jupiter.api.Assertions.*; +/** + * This class contains test cases for the ViewHistoryUseCase. + */ public class UserViewHistoryUseCaseTest { final static int CLIENT_ID = 21345678; final static int ATTORNEY_ID = 11345678; @@ -35,6 +38,9 @@ public class UserViewHistoryUseCaseTest { private ViewOutputBoundary viewOutputBoundary; private ViewInputBoundary viewInputBoundary; + /** + * Set up the test environment by initializing the ViewQuestionUseCase instance. + */ public void setUpViewQuestionUseCase(){ userGatewayFactory = new UserGatewayFactory(); questionGateway = new QuestionRepo(); @@ -80,6 +86,9 @@ public ViewResponseModel prepareSuccess(ViewResponseModel response) { attorneyGateway.save(attorney); } + /** + * Test the client's view question use case. + */ @Test public void TestClientViewUseCase(){ setUpViewQuestionUseCase(); @@ -89,6 +98,9 @@ public void TestClientViewUseCase(){ ClearAllRepository(); } + /** + * Test the attorney's view question use case. + */ @Test public void TestAttorneyViewUseCase(){ setUpViewQuestionUseCase(); @@ -98,6 +110,9 @@ public void TestAttorneyViewUseCase(){ ClearAllRepository(); } + /** + * Delete all data in clientGateway, questionGateway, attorneyGateway. + */ public void ClearAllRepository(){ questionGateway = new QuestionRepo(); clientGateway = new ClientRepository(); From 1a200b432c8a291bad999c5434805228b9529347 Mon Sep 17 00:00:00 2001 From: river3966 Date: Sun, 13 Aug 2023 06:20:25 -0400 Subject: [PATCH 17/24] doc --- .../gateway/UserGatewayFactory.java | 22 +- .../UserRegisterInputBoundary.java | 12 +- .../requestmodel/RegistrationData.java | 17 +- .../usecase/ClientRegisterInteractor.java | 22 ++ .../usecase/UserRegisterInteractor.java | 30 ++- .../java/driver/screen/AskQuestionUI.java | 5 +- .../java/driver/screen/TheQuestionUI.java | 4 +- src/main/java/entity/Attorney.java | 25 +++ src/main/java/entity/Client.java | 197 +++++++++++++++++- src/main/java/entity/UserImp.java | 186 +++++++++++++++-- .../java/entity/factory/AttorneyFactory.java | 12 +- .../java/entity/factory/ClientFactory.java | 13 +- .../java/entity/factory/QuestionFactory.java | 6 +- src/main/java/entity/factory/UserFactory.java | 16 +- 14 files changed, 513 insertions(+), 54 deletions(-) diff --git a/src/main/java/businessrule/gateway/UserGatewayFactory.java b/src/main/java/businessrule/gateway/UserGatewayFactory.java index adf0ff29..899feded 100644 --- a/src/main/java/businessrule/gateway/UserGatewayFactory.java +++ b/src/main/java/businessrule/gateway/UserGatewayFactory.java @@ -4,9 +4,19 @@ import driver.database.ClientRepository; import entity.ApplicationException; +/** + * This class represents for creating instances of UserGateway based on the user's role. + */ public class UserGatewayFactory { - public UserGateway createUserGateway(int userId) { + /** + * Creates a UserGateway based on the user's role. + * + * @param userId The ID of the user for whom the gateway is to be created. + * @return An instance of UserGateway for the specified user. + * @throws ApplicationException If there is an issue creating the gateway or if the user ID does not exist. + */ + public UserGateway createUserGateway(int userId) throws ApplicationException { try { UserGateway userGateway; if (isClient(userId)) { @@ -19,6 +29,14 @@ public UserGateway createUserGateway(int userId) { throw new ApplicationException("UserId does not exist"); } } + + /** + * Checks if the given user ID belongs to a client. + * + * @param userId The ID of the user to check. + * @return True if the user is a client, false if the user is an attorney. + * @throws ApplicationException If the user ID format is invalid or if it doesn't exist. + */ private static boolean isClient(int userId) throws ApplicationException { if (Integer.toString(userId).startsWith("1")) { return false; @@ -28,4 +46,4 @@ private static boolean isClient(int userId) throws ApplicationException { throw new ApplicationException("UserId does not exist"); } } -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/inputboundary/UserRegisterInputBoundary.java b/src/main/java/businessrule/inputboundary/UserRegisterInputBoundary.java index bd0dd94f..1e824c9c 100644 --- a/src/main/java/businessrule/inputboundary/UserRegisterInputBoundary.java +++ b/src/main/java/businessrule/inputboundary/UserRegisterInputBoundary.java @@ -3,6 +3,16 @@ import businessrule.responsemodel.RegisterResponseModel; import businessrule.requestmodel.RegistrationData; +/** + * This interface represents the input boundary for user registration use case. + */ public interface UserRegisterInputBoundary { + + /** + * Creates a user registration using the provided registration data. + * + * @param requestModel The registration data for the user. + * @return The response model indicating the result of the registration process. + */ RegisterResponseModel create(RegistrationData requestModel); -} +} \ No newline at end of file diff --git a/src/main/java/businessrule/requestmodel/RegistrationData.java b/src/main/java/businessrule/requestmodel/RegistrationData.java index f32a6aab..02b77dbf 100644 --- a/src/main/java/businessrule/requestmodel/RegistrationData.java +++ b/src/main/java/businessrule/requestmodel/RegistrationData.java @@ -2,6 +2,9 @@ import java.util.Set; +/** + * This class represents registration data for a user, client, or attorney. + */ public class RegistrationData { // common fields for user registration public int userId; @@ -22,8 +25,10 @@ public class RegistrationData { // fields for attorney registration public Set professionals; - // for user + /** + * Constructor for user registration. + */ public RegistrationData(String userName, String email, String password, String password2, String stateAbb, String postalCode) { this.userName = userName; this.email = email; @@ -33,6 +38,9 @@ public RegistrationData(String userName, String email, String password, String p this.postalCode = postalCode; } + /** + * Constructor for client registration. + */ // for client registration public RegistrationData(String userName, String email, String password, String password2, String stateAbb, String postalCode, String ethnicity, int age, String gender, String maritalStatus, int numberOfHousehold, float annualIncome) { this.userName = userName; @@ -49,6 +57,9 @@ public RegistrationData(String userName, String email, String password, String p this.annualIncome = annualIncome; } + /** + * Constructor for attorney registration. + */ public RegistrationData(String userName, String email, String password, String password2, String stateAbb, String postalCode, Set professionals) { this.userName = userName; this.email = email; @@ -59,6 +70,8 @@ public RegistrationData(String userName, String email, String password, String p this.professionals = professionals; } - + /** + * Sets the user ID. + */ public void setUserId(int userId) {this.userId = userId;} } diff --git a/src/main/java/businessrule/usecase/ClientRegisterInteractor.java b/src/main/java/businessrule/usecase/ClientRegisterInteractor.java index 6559576c..191d9b7f 100644 --- a/src/main/java/businessrule/usecase/ClientRegisterInteractor.java +++ b/src/main/java/businessrule/usecase/ClientRegisterInteractor.java @@ -10,12 +10,28 @@ import businessrule.usecase.util.CredentialChecker; import businessrule.requestmodel.RegistrationData; +/** + * This class represents interactor responsible for client registration use case. + */ public class ClientRegisterInteractor extends UserRegisterInteractor { + /** + * Constructs a ClientRegisterInteractor. + * + * @param clientGateway The gateway for client-related operations. + * @param clientFactory The factory for creating client entities. + * @param outputBoundary The output boundary for the registration process. + */ public ClientRegisterInteractor(ClientGateway clientGateway, ClientFactory clientFactory, RegisterOutputBoundary outputBoundary) { super(clientGateway, clientFactory, outputBoundary); } + /** + * Create a new client registration based on the provided registration data. + * + * @param requestModel The registration data for the client. + * @return The response model indicating the result of the registration process. + */ @Override public RegisterResponseModel create(RegistrationData requestModel) { try {checkCredential(requestModel);} @@ -27,6 +43,12 @@ public RegisterResponseModel create(RegistrationData requestModel) { return outputBoundary.prepareSuccess(message); } + /** + * Check the credentials and validate the input data for client registration. + * + * @param requestModel The registration data for the client. + * @throws ApplicationException If there are issues with the provided credentials or input data. + */ private void checkCredential(RegistrationData requestModel) throws ApplicationException{ // prepare input data String inputUserName = requestModel.userName; diff --git a/src/main/java/businessrule/usecase/UserRegisterInteractor.java b/src/main/java/businessrule/usecase/UserRegisterInteractor.java index dbda4416..1dbde9c8 100644 --- a/src/main/java/businessrule/usecase/UserRegisterInteractor.java +++ b/src/main/java/businessrule/usecase/UserRegisterInteractor.java @@ -9,11 +9,25 @@ import businessrule.requestmodel.RegistrationData; import entity.factory.UserFactory; +/** + * This class represents the user registration interactors. + * + * @param The type of UserGateway used for interacting with users. + * @param The type of UserFactory used for creating user instances. + * @param The type of User entity. + */ public abstract class UserRegisterInteractor, F extends UserFactory, U extends User> implements UserRegisterInputBoundary { protected final T userGateway; protected final F userFactory; protected final RegisterOutputBoundary outputBoundary; + /** + * Constructor for UserRegisterInteractor. + * + * @param userGateway The gateway for user-related operations. + * @param userFactory The factory for creating user instances. + * @param outputBoundary The output boundary for registration results. + */ public UserRegisterInteractor(T userGateway, F userFactory, RegisterOutputBoundary outputBoundary) { this.userGateway = userGateway; this.userFactory = userFactory; @@ -23,6 +37,11 @@ public UserRegisterInteractor(T userGateway, F userFactory, RegisterOutputBounda @Override public abstract RegisterResponseModel create(RegistrationData requestModel); + /** + * Generates a unique user ID. + * + * @return A unique user ID. + */ protected int generateId() { RandomNumberGenerator generator = new RandomNumberGenerator(); int randomUserId = generator.generateClientId(8); @@ -30,11 +49,18 @@ protected int generateId() { while (exists) { randomUserId = generator.generateClientId(8); exists = userGateway.existsById(randomUserId); - } return randomUserId; + } + return randomUserId; } + /** + * Saves a user entity and returns the user's ID. + * + * @param user The user entity to be saved. + * @return The user's ID after saving. + */ protected int saveUser(U user) { userGateway.save(user); return user.getUserId(); } -} +} \ No newline at end of file diff --git a/src/main/java/driver/screen/AskQuestionUI.java b/src/main/java/driver/screen/AskQuestionUI.java index 52f22560..99a9cf61 100644 --- a/src/main/java/driver/screen/AskQuestionUI.java +++ b/src/main/java/driver/screen/AskQuestionUI.java @@ -19,11 +19,10 @@ import static driver.screen.UIDesign.buttonSize; import static javax.swing.BoxLayout.Y_AXIS; - /** - * - * @author joseph + * This class represents the user interface for asking a new question. */ + public class AskQuestionUI extends JPanel implements ActionListener{ ControlContainer controlContainer; CardLayout cardLayout; diff --git a/src/main/java/driver/screen/TheQuestionUI.java b/src/main/java/driver/screen/TheQuestionUI.java index e296dadc..2fb1f580 100644 --- a/src/main/java/driver/screen/TheQuestionUI.java +++ b/src/main/java/driver/screen/TheQuestionUI.java @@ -18,9 +18,7 @@ import static driver.screen.UIDesign.*; /** - * TheQuestionUI class represents the user interface for a specific question. - * It displays information about the question, posts, and provides interaction - * options such as posting replies, closing the question, and rating it. + * This class represents the user interface for a specific question. */ public class TheQuestionUI extends JPanel implements ActionListener { ControlContainer controlContainer; diff --git a/src/main/java/entity/Attorney.java b/src/main/java/entity/Attorney.java index 277add68..5e8fa5b1 100644 --- a/src/main/java/entity/Attorney.java +++ b/src/main/java/entity/Attorney.java @@ -29,24 +29,49 @@ public class Attorney extends UserImp { @ElementCollection(fetch = FetchType.EAGER) private Set professionals; + /** + * Default constructor for creating an Attorney instance. + */ public Attorney() { super(); recommendations = new ArrayList<>(); professionals = new HashSet<>(); } + /** + * Constructor for creating an Attorney instance using a builder. + * + * @param builder The builder instance used for constructing the Attorney. + */ public Attorney(Builder builder) { super(builder); } + + /** + * Builder class for constructing Attorney instances. + */ public static class Builder extends UserImp.Builder { + + /** + * Constructor for the Attorney builder. + * + * @param data The registration data for creating the Attorney. + */ public Builder(RegistrationData data) { super(data); } + /** + * Set the list of professional specialties for the Attorney. + * + * @param professionals The set of professional specialties. + * @return The builder instance. + */ public Attorney.Builder professionals(Set professionals) { this.data.professionals = professionals; return this; } + @Override protected Attorney.Builder self() { return this; diff --git a/src/main/java/entity/Client.java b/src/main/java/entity/Client.java index 0b9fdf8a..acf0bcaf 100644 --- a/src/main/java/entity/Client.java +++ b/src/main/java/entity/Client.java @@ -6,6 +6,7 @@ import javax.persistence.*; import java.util.ArrayList; + @Entity public class Client extends UserImp { @JsonProperty(required = true) @@ -21,8 +22,18 @@ public class Client extends UserImp { @JsonProperty(required = true) private float annualIncome; - public Client() {super();} + /** + * Default constructor for the Client class. + */ + public Client() { + super(); + } + /** + * Constructor to create a Client instance using the provided Builder. + * + * @param builder The Builder instance containing client data. + */ private Client(Builder builder) { super(builder); this.ethnicity = builder.data.ethnicity; @@ -34,108 +45,265 @@ private Client(Builder builder) { this.questionsList = new ArrayList(); } + /** + * Builder class for creating instances of the Client class. + */ public static class Builder extends UserImp.Builder { + /** + * Constructor for the Builder class. + * + * @param data The registration data for the client. + */ public Builder(RegistrationData data) { super(data); } + /** + * Set the ethnicity for the client. + * + * @param ethnicity The ethnicity of the client. + * @return The Builder instance. + */ public Builder ethnicity(String ethnicity) { this.data.ethnicity = ethnicity; return this; } + /** + * Set the age for the client. + * + * @param age The age of the client. + * @return The Builder instance. + */ public Builder age(int age) { this.data.age = age; return this; } + /** + * Set the gender for the client. + * + * @param gender The gender of the client. + * @return The Builder instance. + */ public Builder gender(String gender) { this.data.gender = gender; return this; } + /** + * Set the marital status for the client. + * + * @param maritalStatus The marital status of the client. + * @return The Builder instance. + */ public Builder maritalStatus(String maritalStatus) { this.data.maritalStatus = maritalStatus; return this; } + /** + * Set the number of household members for the client. + * + * @param numberOfHousehold The number of household members of the client. + * @return The Builder instance. + */ public Builder numberOfHousehold(int numberOfHousehold) { this.data.numberOfHousehold = numberOfHousehold; return this; } + /** + * Set the annual income for the client. + * + * @param annualIncome The annual income of the client. + * @return The Builder instance. + */ public Builder annualIncome(float annualIncome) { this.data.annualIncome = annualIncome; return this; } + /** + * {@inheritDoc} + */ @Override protected Builder self() { return this; } + /** + * Build and return a Client instance based on the Builder configuration. + * + * @return A new Client instance. + */ @Override public Client build() { return new Client(this); } } + /** + * Get the ethnicity of the client. + * + * @return The ethnicity of the client. + */ public String getEthnicity() { return ethnicity; } + /** + * Get the age of the client. + * + * @return The age of the client. + */ public int getAge() { return age; } + /** + * Get the gender of the client. + * + * @return The gender of the client. + */ public String getGender() { return gender; } + /** + * Get the marital status of the client. + * + * @return The marital status of the client. + */ public String getMaritalStatus() { return maritalStatus; } + /** + * Get the number of household members of the client. + * + * @return The number of household members of the client. + */ public int getNumberOfHousehold() { return numberOfHousehold; } + /** + * Get the annual income of the client. + * + * @return The annual income of the client. + */ public float getAnnualIncome() { return annualIncome; } - public void setEthnicity(String ethnicity) {this.ethnicity = ethnicity;} +// Setter methods - public void setAge(int age) {this.age = age;} + /** + * Set the ethnicity of the client. + * + * @param ethnicity The new ethnicity of the client. + */ + public void setEthnicity(String ethnicity) { + this.ethnicity = ethnicity; + } - public void setGender(String gender) {this.gender = gender;} + /** + * Set the age of the client. + * + * @param age The new age of the client. + */ + public void setAge(int age) { + this.age = age; + } - public void setMaritalStatus(String maritalStatus) {this.maritalStatus = maritalStatus;} + /** + * Set the gender of the client. + * + * @param gender The new gender of the client. + */ + public void setGender(String gender) { + this.gender = gender; + } - public void setNumberOfHousehold(int numberOfHousehold) {this.numberOfHousehold = numberOfHousehold;} + /** + * Set the marital status of the client. + * + * @param maritalStatus The new marital status of the client. + */ + public void setMaritalStatus(String maritalStatus) { + this.maritalStatus = maritalStatus; + } - public void setAnnualIncome(float annualIncome) {this.annualIncome = annualIncome;} + /** + * Set the number of household members of the client. + * + * @param numberOfHousehold The new number of household members of the client. + */ + public void setNumberOfHousehold(int numberOfHousehold) { + this.numberOfHousehold = numberOfHousehold; + } + /** + * Set the annual income of the client. + * + * @param annualIncome The new annual income of the client. + */ + public void setAnnualIncome(float annualIncome) { + this.annualIncome = annualIncome; + } + + /** + * Check if the user is a client. + * + * @return True indicating the user is a client. + */ @Transient @Override - public boolean isClient() {return true;} + public boolean isClient() { + return true; + } + /** + * Check if a question can be closed for the client. + * + * @param question The question to be checked. + * @return True if the question can be closed, otherwise false. + */ @Override public boolean isQuestionCloseable(Question question) { boolean isClose = question.isClose(); return !isClose; } + /** + * Check if a question is selectable for the client. + * + * @param question The question to be checked. + * @return Always returns true, indicating that the question is selectable. + */ @Override public boolean isQuestionSelectable(Question question) { return true; } + /** + * Check if a question can be replied to by the client. + * + * @param question The question to be checked. + * @return True if the question can be replied to, otherwise false. + */ @Override public boolean isQuestionReplyable(Question question) { return !question.isClose(); } + /** + * Check if this client instance is equal to another object. + * + * @param obj The object to compare with this client instance. + * @return True if the objects are equal, otherwise false. + */ @Override public boolean equals(Object obj) { if (!(obj instanceof Client)) return false; @@ -143,15 +311,24 @@ public boolean equals(Object obj) { return userId == otherClient.userId; } + /** + * Get a string representation of the client. + * + * @return A formatted string representing the client. + */ @Override public String toString() { return String.format("[Client]: %s", name); } + /** + * Check if a question is rateable for the client. + * + * @param question The question to be checked. + * @return True if the question is rateable, otherwise false. + */ @Override public boolean isQuestionRateable(Question question) { return question.isClose(); } } - - diff --git a/src/main/java/entity/UserImp.java b/src/main/java/entity/UserImp.java index afe41a99..63cb3656 100644 --- a/src/main/java/entity/UserImp.java +++ b/src/main/java/entity/UserImp.java @@ -11,6 +11,9 @@ import java.util.List; import java.util.Objects; +/** + * This class respresents a user entity with common properties and behaviors. + */ @Entity public abstract class UserImp implements User{ @Id @@ -26,8 +29,12 @@ public abstract class UserImp implements User{ @JsonProperty(required = true) protected List questionsList; + /** + * Default constructor for the UserImp class. Initializes the questions list. + */ public UserImp() {questionsList = new ArrayList();} + protected UserImp(Builder builder) { this.userId = builder.data.userId; this.name = builder.data.userName; @@ -38,99 +45,234 @@ protected UserImp(Builder builder) { this.questionsList = new ArrayList<>(); } + /** + * Abstract builder class for creating instances of the UserImp class. + */ public static abstract class Builder> { protected RegistrationData data; + /** + * Constructor for the Builder class. + * + * @param data The registration data for the user. + */ public Builder(RegistrationData data) { this.data = data; } + /** + * Set the user ID for the user being built. + * + * @param userId The user ID. + * @return The Builder instance. + */ public T userId(int userId) { this.data.userId = userId; return self(); } + /** + * Set the user name for the user being built. + * + * @param userName The user name. + * @return The Builder instance. + */ public T userName(String userName) { this.data.userName = userName; return self(); } - + /** + * Set the password for the user being built. + * + * @param password The password. + * @return The Builder instance. + */ public T password(String password) { this.data.password = password; return self(); } - + /** + * Set the email for the user being built. + * + * @param email The email. + * @return The Builder instance. + */ public T email(String email) { this.data.email = email; return self(); } - + /** + * Set the state abbreviation for the user being built. + * + * @param stateAbb The state abbreviation. + * @return The Builder instance. + */ public T stateAbb(String stateAbb) { this.data.stateAbb = stateAbb; return self(); } - + /** + * Set the postal code for the user being built. + * + * @param postalCode The postal code. + * @return The Builder instance. + */ public T postalCode(String postalCode) { this.data.postalCode = postalCode; return self(); } protected abstract T self(); + /** + * Build and return a UserImp instance based on the Builder configuration. + * + * @return A new UserImp instance. + */ public abstract UserImp build(); } + /** + * Retrieves the user ID of this user. + * + * @return The user ID of this user. + */ @Override - public int getUserId() {return userId;} + public int getUserId() { + return userId; + } + /** + * Retrieves the user name of this user. + * + * @return The user name of this user. + */ @Override - public String getUserName() {return name;} + public String getUserName() { + return name; + } + /** + * Retrieves the email address of this user. + * + * @return The email address of this user. + */ @Override - public String getEmail() {return email;} + public String getEmail() { + return email; + } @Override public String getPassword() {return password;} - + /** + * Get the state abbreviation of the user. + * + * @return The state abbreviation. + */ public String getStateAbb() {return stateAbb;} - + /** + * Get the postal code of the user. + * + * @return The postal code. + */ public String getPostalCode() {return postalCode;} - + /** + * Retrieves the list of questions associated with this user. + * + * @return The list of questions associated with this user. + */ @Override public List getQuestionsList() {return questionsList;} - + /** + * Add a question to the user's questions list. + * + * @param question The question to be added. + */ @Override public void addQuestion(Question question) { if (!questionsList.contains(question)) { questionsList.add(question); } } + /** + * Set the user ID for the user. + * + * @param value The user ID value to set. + */ @Override public void setUserId(int value) {this.userId = value;} - + /** + * Set the user name for the user. + * + * @param name The user name to set. + */ @Override public void setUserName(String name) {this.name = name;} - + /** + * Set the email for the user. + * + * @param value The email value to set. + */ @Override public void setEmail(String value) {this.email = value;} - + /** + * Set the state abbreviation for the user. + * + * @param value The state abbreviation to set. + */ @Override public void setStateAbb(String value) {this.stateAbb = value;} - + /** + * Set the postal code for the user. + * + * @param value The postal code to set. + */ @Override public void setPostalCode(String value) {this.postalCode = value;} - + /** + * Set the password for the user. + * + * @param value The password value to set. + */ @Override public void setPassword(String value) {this.password = value;} - + /** + * Returns the hash code value for this UserImp object. The hash code is generated based on the user ID. + * + * @return The hash code value for this object. + */ @Override public int hashCode() {return Objects.hashCode(userId);} - + /** + * Check if the user is a client. + * + * @return True if the user is a client, otherwise false. + */ public abstract boolean isClient(); - + /** + * Check if a question can be closed for the user. + * + * @param question The question to be checked. + * @return True if the question can be closed, otherwise false. + */ public abstract boolean isQuestionCloseable(Question question); - + /** + * Check if a question is selectable for the user. + * + * @param question The question to be checked. + * @return True if the question is selectable, otherwise false. + */ public abstract boolean isQuestionSelectable(Question question); - + /** + * Check if a question can be replied to by the user. + * + * @param question The question to be checked. + * @return True if the question can be replied to, otherwise false. + */ public abstract boolean isQuestionReplyable(Question question); - + /** + * Check if a question is rateable by the user. + * + * @param question The question to be checked. + * @return True if the question is rateable, otherwise false. + */ public abstract boolean isQuestionRateable(Question question); } diff --git a/src/main/java/entity/factory/AttorneyFactory.java b/src/main/java/entity/factory/AttorneyFactory.java index d121c3ca..f7bb6518 100644 --- a/src/main/java/entity/factory/AttorneyFactory.java +++ b/src/main/java/entity/factory/AttorneyFactory.java @@ -3,9 +3,19 @@ import businessrule.requestmodel.RegistrationData; import entity.Attorney; +/** + * This class represents creating Attorney instances. + */ public class AttorneyFactory implements UserFactory { + + /** + * Creates an Attorney instance based on the provided registration data. + * + * @param data The registration data for creating the Attorney. + * @return A new Attorney instance. + */ @Override public Attorney createUser(RegistrationData data) { return new Attorney.Builder(data).build(); } -} +} \ No newline at end of file diff --git a/src/main/java/entity/factory/ClientFactory.java b/src/main/java/entity/factory/ClientFactory.java index 39fac52d..98b8ae95 100644 --- a/src/main/java/entity/factory/ClientFactory.java +++ b/src/main/java/entity/factory/ClientFactory.java @@ -1,10 +1,21 @@ package entity.factory; + import businessrule.requestmodel.RegistrationData; import entity.Client; +/** + * This class represents creating Client instances. + */ public class ClientFactory implements UserFactory { + + /** + * Creates a Client instance based on the provided registration data. + * + * @param data The registration data for creating the Client. + * @return A new Client instance. + */ @Override public Client createUser(RegistrationData data) { return new Client.Builder(data).build(); } -} +} \ No newline at end of file diff --git a/src/main/java/entity/factory/QuestionFactory.java b/src/main/java/entity/factory/QuestionFactory.java index 945846ed..619a855b 100644 --- a/src/main/java/entity/factory/QuestionFactory.java +++ b/src/main/java/entity/factory/QuestionFactory.java @@ -5,11 +5,7 @@ import java.time.LocalDate; /** - * This is a factory class for creating instances of the "Question" class. - * - * The QuestionFactory class provides a simple and convenient way to create new "Question" objects with - * the specified attributes. It encapsulates the instantiation process and centralizes it in a single - * location, promoting code reusability and maintainability. + * This is class represnts for creating instances of the "Question" class. */ public class QuestionFactory { public Question create(int questionId, String type, String title, LocalDate createAt, int askedByClient, LocalDate legalDeadline){ diff --git a/src/main/java/entity/factory/UserFactory.java b/src/main/java/entity/factory/UserFactory.java index fea07144..a087dc9c 100644 --- a/src/main/java/entity/factory/UserFactory.java +++ b/src/main/java/entity/factory/UserFactory.java @@ -3,6 +3,18 @@ import businessrule.requestmodel.RegistrationData; import entity.UserImp; -public interface UserFactory { +/** + * This is a interface represents creating user instances. + * + * @param The type of user to create, extending UserImp. + */ +public interface UserFactory { + + /** + * Creates a user instance based on the provided registration data. + * + * @param data The registration data for creating the user. + * @return A new user instance. + */ T createUser(RegistrationData data); -} +} \ No newline at end of file From 164ac3743550e57837c26dcdae83eed52e600e64 Mon Sep 17 00:00:00 2001 From: josephpcsywm Date: Mon, 14 Aug 2023 20:34:59 -0400 Subject: [PATCH 18/24] commit for UIFactory test first attempt --- .../java/factorytesting/UIFactoryTest.java | 108 ++++++++++++++++++ .../java/usecasetesting/ReplyUseCaseTest.java | 4 +- 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/test/java/factorytesting/UIFactoryTest.java diff --git a/src/test/java/factorytesting/UIFactoryTest.java b/src/test/java/factorytesting/UIFactoryTest.java new file mode 100644 index 00000000..2b721504 --- /dev/null +++ b/src/test/java/factorytesting/UIFactoryTest.java @@ -0,0 +1,108 @@ +package factorytesting; + +import businessrule.UIFactory; +import businessrule.gateway.UserGatewayFactory; +import businessrule.responsemodel.BaseResponseModel; +import businessrule.responsemodel.TheQuestionResponseModel; +import businessrule.responsemodel.UserResponseModel; +import businessrule.responsemodel.ViewResponseModel; +import businessrule.usecase.util.BuilderService; +import businessrule.usecase.util.PostDisplayFormatter; +import businessrule.usecase.util.PostMapConstructor; +import businessrule.usecase.util.QuestionDisplayFormatter; +import driver.screen.*; +import driver.screen.UIManager; +import entity.Question; +import entity.factory.QuestionFactory; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import javax.swing.*; +import java.awt.*; +import java.time.LocalDate; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class UIFactoryTest { + + private UIFactory uiFactory; + private final int USER_ID = 24567893; + private final int QUESTION_ID = 324724768; + private final String USER_NAME = "test client"; + private final String USER_TYPE = "Client"; + private final String TITLE = "test title"; + private final String QUESTION_TYPE = "test type"; + private UserResponseModel userResponseModel; + private BaseResponseModel baseResponseModel; + private TheQuestionResponseModel theQuestionResponseModel; + private ViewResponseModel viewResponseModel; + private UIManager uiManager; + private Map postMap; + private Map questionMap; + + @BeforeEach + void setUpUIFactory() { + uiFactory = new UIFactory(); + baseResponseModel = new BaseResponseModel(); + userResponseModel = new UserResponseModel(USER_ID, USER_NAME, USER_TYPE); + JPanel testScreen = new JPanel(); + CardLayout testCardLayout = new CardLayout(); + uiManager = new UIManager(testScreen, testCardLayout); + Question question = new Question(); + postMap = new HashMap<>(); + questionMap = new HashMap<>(); + theQuestionResponseModel = BuilderService.getInstance().constructTheQuestionResponse(question, userResponseModel, postMap); + viewResponseModel = BuilderService.getInstance().constructViewResponse(userResponseModel, questionMap); + + + } + + @Test + void testGetWelcomeUI() { + setUpUIFactory(); + WelcomeUI expectedUI = new WelcomeUI(uiManager); + assertEquals(expectedUI.getClass(), UIFactory.getUI(UIFactory.UIType.WELCOME_UI, uiManager, baseResponseModel).getClass()); + } + @Test + void testGetRegisterUI() { + setUpUIFactory(); + RegisterUI expectedUI = new RegisterUI(uiManager); + assertEquals(expectedUI.getClass(), UIFactory.getUI(UIFactory.UIType.REGISTER_UI, uiManager, baseResponseModel).getClass()); + } + @Test + void testGetLoginUI() { + setUpUIFactory(); + LoginUI expectedUI = new LoginUI(uiManager); + assertEquals(expectedUI.getClass(), UIFactory.getUI(UIFactory.UIType.LOGIN_UI, uiManager, baseResponseModel).getClass()); + } + + @Test + void testGetHomePageUI() { + setUpUIFactory(); + HomePageUI expectedUI = new ClientHomePageUI(USER_NAME, USER_ID, uiManager); + assertEquals(expectedUI.getClass(), UIFactory.getUI(UIFactory.UIType.HOME_PAGE, uiManager, userResponseModel).getClass()); + } + + @Test + void testAskQuestionUI() { + setUpUIFactory(); + AskQuestionUI expectedUI = new AskQuestionUI(USER_NAME, USER_ID, uiManager); + assertEquals(expectedUI.getClass(), UIFactory.getUI(UIFactory.UIType.ASK_QUESTION_UI, uiManager, theQuestionResponseModel).getClass()); + } + + @Test + void testQuestionListUI() { + setUpUIFactory(); + QuestionListUI expectedUI = new QuestionListUI(USER_NAME, USER_ID, uiManager, questionMap); + assertEquals(expectedUI.getClass(), UIFactory.getUI(UIFactory.UIType.QUESTION_LIST_UI, uiManager, viewResponseModel).getClass()); + } + + @Test + void testQuestionUI() { + setUpUIFactory(); + QuestionUI expectedUI = new QuestionNewUI(USER_NAME, USER_ID, uiManager, QUESTION_ID, TITLE, QUESTION_TYPE, LocalDate.now(), postMap); + assertEquals(expectedUI.getClass(), UIFactory.getUI(UIFactory.UIType.QUESTION_UI, uiManager, theQuestionResponseModel).getClass()); + } +} \ No newline at end of file diff --git a/src/test/java/usecasetesting/ReplyUseCaseTest.java b/src/test/java/usecasetesting/ReplyUseCaseTest.java index cc71106d..453c30b1 100644 --- a/src/test/java/usecasetesting/ReplyUseCaseTest.java +++ b/src/test/java/usecasetesting/ReplyUseCaseTest.java @@ -58,15 +58,17 @@ public TheQuestionResponseModel prepareSuccess(TheQuestionResponseModel response Question question = new Question(); question.setQuestionId(QUESTION_ID); + question.setAskedByClient(CLIENT_ID); questionGateway.save(question); Question closedQuestion = new Question(); closedQuestion.setQuestionId(CLOSED_QUESTION_ID); + closedQuestion.setAskedByClient(CLIENT_ID); questionGateway.save(closedQuestion); Client client = new Client(); client.setUserId(CLIENT_ID); - client.setEmail("josephpc061@gmail.com"); + client.setEmail("josephpc0612@gmail.com"); client.addQuestion(question); clientGateway.save(client); From 950aa365c7f68b948601c08632d058f688595941 Mon Sep 17 00:00:00 2001 From: josephpcsywm Date: Mon, 14 Aug 2023 20:43:24 -0400 Subject: [PATCH 19/24] commit for UIFactory test first attempt --- src/test/java/factorytesting/UIFactoryTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/java/factorytesting/UIFactoryTest.java b/src/test/java/factorytesting/UIFactoryTest.java index 2b721504..3b0282e4 100644 --- a/src/test/java/factorytesting/UIFactoryTest.java +++ b/src/test/java/factorytesting/UIFactoryTest.java @@ -12,6 +12,7 @@ import businessrule.usecase.util.QuestionDisplayFormatter; import driver.screen.*; import driver.screen.UIManager; +import entity.Post; import entity.Question; import entity.factory.QuestionFactory; import org.junit.jupiter.api.BeforeEach; @@ -34,6 +35,7 @@ class UIFactoryTest { private final String USER_TYPE = "Client"; private final String TITLE = "test title"; private final String QUESTION_TYPE = "test type"; + private final String POST_TEXT = "test text"; private UserResponseModel userResponseModel; private BaseResponseModel baseResponseModel; private TheQuestionResponseModel theQuestionResponseModel; @@ -51,7 +53,10 @@ void setUpUIFactory() { CardLayout testCardLayout = new CardLayout(); uiManager = new UIManager(testScreen, testCardLayout); Question question = new Question(); + PostDisplayFormatter post = new PostDisplayFormatter(POST_TEXT, USER_TYPE, USER_NAME, LocalDate.now()); + postMap = new HashMap<>(); + postMap.put(1, post); questionMap = new HashMap<>(); theQuestionResponseModel = BuilderService.getInstance().constructTheQuestionResponse(question, userResponseModel, postMap); viewResponseModel = BuilderService.getInstance().constructViewResponse(userResponseModel, questionMap); From fe16717f5ce5d0d3f5752cc249b04319690c9e08 Mon Sep 17 00:00:00 2001 From: Yifan Liu Date: Mon, 14 Aug 2023 23:11:07 -0400 Subject: [PATCH 20/24] finish ui factory test --- src/test/java/factorytesting/UIFactoryTest.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/test/java/factorytesting/UIFactoryTest.java b/src/test/java/factorytesting/UIFactoryTest.java index 3b0282e4..0e088912 100644 --- a/src/test/java/factorytesting/UIFactoryTest.java +++ b/src/test/java/factorytesting/UIFactoryTest.java @@ -1,41 +1,32 @@ package factorytesting; import businessrule.UIFactory; -import businessrule.gateway.UserGatewayFactory; import businessrule.responsemodel.BaseResponseModel; import businessrule.responsemodel.TheQuestionResponseModel; import businessrule.responsemodel.UserResponseModel; import businessrule.responsemodel.ViewResponseModel; import businessrule.usecase.util.BuilderService; import businessrule.usecase.util.PostDisplayFormatter; -import businessrule.usecase.util.PostMapConstructor; import businessrule.usecase.util.QuestionDisplayFormatter; import driver.screen.*; import driver.screen.UIManager; -import entity.Post; import entity.Question; -import entity.factory.QuestionFactory; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - import javax.swing.*; import java.awt.*; import java.time.LocalDate; import java.util.HashMap; import java.util.Map; - import static org.junit.jupiter.api.Assertions.assertEquals; class UIFactoryTest { - private UIFactory uiFactory; private final int USER_ID = 24567893; private final int QUESTION_ID = 324724768; private final String USER_NAME = "test client"; - private final String USER_TYPE = "Client"; private final String TITLE = "test title"; private final String QUESTION_TYPE = "test type"; - private final String POST_TEXT = "test text"; private UserResponseModel userResponseModel; private BaseResponseModel baseResponseModel; private TheQuestionResponseModel theQuestionResponseModel; @@ -46,13 +37,14 @@ class UIFactoryTest { @BeforeEach void setUpUIFactory() { - uiFactory = new UIFactory(); baseResponseModel = new BaseResponseModel(); + String USER_TYPE = "Client"; userResponseModel = new UserResponseModel(USER_ID, USER_NAME, USER_TYPE); JPanel testScreen = new JPanel(); CardLayout testCardLayout = new CardLayout(); uiManager = new UIManager(testScreen, testCardLayout); - Question question = new Question(); + Question question = new Question(QUESTION_ID, QUESTION_TYPE, TITLE, LocalDate.now(), USER_ID, LocalDate.now()); + String POST_TEXT = "test text"; PostDisplayFormatter post = new PostDisplayFormatter(POST_TEXT, USER_TYPE, USER_NAME, LocalDate.now()); postMap = new HashMap<>(); @@ -107,7 +99,7 @@ void testQuestionListUI() { @Test void testQuestionUI() { setUpUIFactory(); - QuestionUI expectedUI = new QuestionNewUI(USER_NAME, USER_ID, uiManager, QUESTION_ID, TITLE, QUESTION_TYPE, LocalDate.now(), postMap); + QuestionOpenClientUI expectedUI = new QuestionOpenClientUI(USER_NAME, USER_ID, uiManager, QUESTION_ID, TITLE, QUESTION_TYPE, LocalDate.now(), postMap); assertEquals(expectedUI.getClass(), UIFactory.getUI(UIFactory.UIType.QUESTION_UI, uiManager, theQuestionResponseModel).getClass()); } } \ No newline at end of file From bd8720db83b9ad470c7e94efeed23fd69bfb787e Mon Sep 17 00:00:00 2001 From: Yifan Liu Date: Tue, 15 Aug 2023 01:21:25 -0400 Subject: [PATCH 21/24] merge with main and add documentation --- src/test/java/usecasetesting/AskQuestionUseCaseTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/usecasetesting/AskQuestionUseCaseTest.java b/src/test/java/usecasetesting/AskQuestionUseCaseTest.java index 6182f3b8..6dd60533 100644 --- a/src/test/java/usecasetesting/AskQuestionUseCaseTest.java +++ b/src/test/java/usecasetesting/AskQuestionUseCaseTest.java @@ -89,7 +89,7 @@ public void TestAskQuestionPassed(){ User user = clientGateway.get(CLIENT_ID); assertEquals(1, user.getQuestionsList().size(), "The ask question use case failed."); - ClearAllRepository(); + clearAllRepository(); } /** @@ -105,7 +105,7 @@ public void TestAskQuestionFailByEmptyCategory(){ User user = clientGateway.get(CLIENT_ID); assertEquals(0, user.getQuestionsList().size(), "The ask question use case failed."); - ClearAllRepository(); + clearAllRepository(); } /** From a6b069a4ce9caad9fb3af6be708baca8cd305068 Mon Sep 17 00:00:00 2001 From: Yifan Liu Date: Tue, 15 Aug 2023 01:22:45 -0400 Subject: [PATCH 22/24] small changes --- src/main/java/driver/screen/DateChooserPanel.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/main/java/driver/screen/DateChooserPanel.java diff --git a/src/main/java/driver/screen/DateChooserPanel.java b/src/main/java/driver/screen/DateChooserPanel.java deleted file mode 100644 index e69de29b..00000000 From 7176ecda3ca46f2ff8f9f7bd51812fd5117c157d Mon Sep 17 00:00:00 2001 From: Yifan Liu Date: Tue, 15 Aug 2023 02:47:34 -0400 Subject: [PATCH 23/24] solve all warnings --- build.gradle | 4 +- src/main/java/Main.java | 49 +++++++++---------- .../controllers}/ClientRegisterControl.java | 8 +-- .../controllers}/CloseQuestionControl.java | 8 +-- .../controllers}/ControlContainer.java | 3 +- .../controllers}/PostControl.java | 9 ++-- .../controllers}/QuestionControl.java | 9 ++-- .../controllers}/RateControl.java | 8 +-- .../controllers}/SelectQuestionControl.java | 9 ++-- .../controllers}/UserLoginControl.java | 8 +-- .../controllers}/ViewQuestionControl.java | 10 ++-- .../HomePageResponseFormatter.java | 13 +++-- .../RegisterResponseFormatter.java | 17 +++---- .../TheQuestionResponseFormatter.java | 19 ++++--- .../presenters}/ViewResponseFormatter.java | 15 +++--- .../java/driver/screen/ReplyQuestionUI.java | 8 --- .../ApplicationException.java | 2 +- src/main/java/{entity => entities}/Post.java | 3 +- .../java/{entity => entities}/Question.java | 3 +- .../factories}/AttorneyFactory.java | 6 +-- .../factories}/ClientFactory.java | 6 +-- .../factories}/PostFactory.java | 5 +- .../factories}/QuestionFactory.java | 4 +- .../factories}/UserFactory.java | 6 +-- .../{entity => entities/user}/Attorney.java | 7 ++- .../{entity => entities/user}/Client.java | 7 +-- .../java/{entity => entities/user}/User.java | 5 +- .../{entity => entities/user}/UserImp.java | 9 ++-- .../database/AttorneyRepository.java | 7 +-- .../database/ClientRepository.java | 6 +-- .../database/DatabaseConnection.java | 2 +- .../database/GenericRepository.java | 4 +- .../database/PostRepo.java | 6 +-- .../database/QuestionRepo.java | 8 +-- .../database}/UserGatewayFactory.java | 9 ++-- .../database/UserRepository.java | 8 +-- .../screens}/AskQuestionUI.java | 12 +++-- .../screens}/AttorneyHomePageUI.java | 17 +++---- .../screens}/BaseUI.java | 11 +++-- .../screens}/ClientHomePageUI.java | 15 +++--- .../screens}/HomePageUI.java | 9 +++- .../screens}/LoginUI.java | 11 +++-- .../screens}/QuestionCloseUI.java | 15 +++--- .../screens}/QuestionListUI.java | 33 ++++++------- .../screens}/QuestionNewUI.java | 18 ++++--- .../screens}/QuestionOpenAttorneyUI.java | 16 +++--- .../screens}/QuestionOpenClientUI.java | 18 ++++--- .../screens}/QuestionUI.java | 18 ++++--- .../screens}/RatePanel.java | 14 +++--- .../screens}/RegisterUI.java | 11 +++-- .../screens}/UIFactory.java | 31 ++++++++---- .../screens}/UserUI.java | 11 +++-- .../screens}/WelcomeUI.java | 8 +-- .../screens/utils}/UIDesign.java | 5 +- .../screens/utils}/UIDrawer.java | 6 +-- .../screens/utils}/UIManager.java | 4 +- src/main/java/tutorial/MainFrame.java | 0 .../util => usecases/dto}/Matching.java | 2 +- .../util => usecases/dto}/MatchingResult.java | 2 +- .../dto/PostDisplay.java} | 8 ++- .../dto/QuestionDisplay.java} | 6 +-- .../gateway/AttorneyGateway.java | 6 +-- .../gateway/ClientGateway.java | 4 +- .../gateway/GenericGateway.java | 2 +- .../gateway/PostGateway.java | 4 +- .../gateway/QuestionGateway.java | 6 +-- .../gateway/UserGateway.java | 6 +-- .../inputboundary/CloseInputBoundary.java | 6 +-- .../inputboundary/PostInputBoundary.java | 7 ++- .../inputboundary/QuestionInputBoundary.java | 7 ++- .../inputboundary/RateInputBoundary.java | 6 +-- .../inputboundary/SelectInputBoundary.java | 7 ++- .../inputboundary/UserLoginInputBoundary.java | 6 +-- .../UserRegisterInputBoundary.java | 7 ++- .../inputboundary/ViewInputBoundary.java | 5 +- .../interactors}/AskQuestionInteractor.java | 36 +++++++------- .../AttorneyRecommendInteractor.java | 21 +++----- .../BrowseQuestionInteractor.java | 18 +++---- .../ClientRegisterInteractor.java | 22 ++++----- .../interactors}/CloseQuestionInteractor.java | 27 +++++----- .../interactors}/RateInteractor.java | 33 +++++-------- .../interactors}/ReplyInteractor.java | 38 +++++++------- .../SelectQuestionInteractor.java | 35 +++++++------ .../interactors}/UserLoginInteractor.java | 34 ++++++------- .../interactors}/UserRegisterInteractor.java | 18 +++---- .../interactors}/ViewQuestionInteractor.java | 18 +++---- .../ViewQuestionInteractorBase.java | 36 ++++++-------- .../outputboundary/BaseOutputBoundary.java | 5 +- .../TheQuestionOutputBoundary.java | 6 +-- .../outputboundary/UserOutputBoundary.java | 5 +- .../outputboundary/ViewOutputBoundary.java | 7 +-- .../requests}/CloseRequestModel.java | 2 +- .../requests}/PostRequestModel.java | 2 +- .../requests}/QuestionRequestModel.java | 2 +- .../requests}/RateRequestModel.java | 2 +- .../requests}/RegistrationData.java | 2 +- .../requests}/SelectRequestModel.java | 2 +- .../requests}/UserLoginRequestModel.java | 2 +- .../responses}/BaseResponseModel.java | 4 +- .../responses}/TheQuestionResponseModel.java | 22 ++++----- .../responses}/UserResponseModel.java | 4 +- .../responses}/ViewResponseModel.java | 22 ++++----- .../session}/SessionManager.java | 5 +- .../session}/UserSession.java | 10 ++-- .../utils}/BuilderService.java | 20 +++++--- .../utils}/CredentialChecker.java | 4 +- .../utils}/EmailNotificationSender.java | 14 ++++-- .../utils}/MatchingHandler.java | 23 ++++----- .../utils}/PostMapConstructor.java | 22 ++++----- .../util => usecases/utils}/PythonReader.java | 2 +- .../utils}/QuestionMapConstructor.java | 12 ++--- .../utils}/RandomNumberGenerator.java | 2 +- .../ClientRegisterControlTest.java | 8 +-- .../CloseQuestionControlTest.java | 8 +-- .../ControlContainerTest.java | 2 +- .../controllertesting/PostControlTest.java | 14 +++--- .../QuestionControlTest.java | 14 +++--- .../controllertesting/RateControlTest.java | 12 ++--- .../SelectQuestionControlTest.java | 16 +++--- .../UserLoginControlTest.java | 8 +-- .../ViewQuestionControlTest.java | 6 +-- src/test/java/entitytesting/AttorneyTest.java | 8 +-- src/test/java/entitytesting/ClientTest.java | 8 +-- src/test/java/entitytesting/PostTest.java | 2 +- src/test/java/entitytesting/QuestionTest.java | 2 +- .../factorytesting/ClientFactoryTest.java | 6 +-- .../factorytesting/CredentialCheckerTest.java | 2 +- .../java/factorytesting/PostFactoryTest.java | 4 +- .../factorytesting/QuestionFactoryTest.java | 4 +- .../RandomNumberGeneratorTest.java | 2 +- .../java/factorytesting/UIFactoryTest.java | 28 +++++------ .../AttorneyRepositoryTest.java | 14 +++--- .../gatewaytesting/ClientRepositoryTest.java | 20 ++++---- .../java/gatewaytesting/PostRepoTest.java | 6 +-- .../java/gatewaytesting/QuestionRepoTest.java | 12 ++--- .../AskQuestionUseCaseTest.java | 30 ++++++------ .../BrowseQuestionUseCaseTest.java | 26 +++++----- .../ClientRegisterUseCaseTest.java | 16 +++--- .../java/usecasetesting/CloseUseCaseTest.java | 24 ++++----- .../usecasetesting/RateAnswerUseCaseTest.java | 26 +++++----- .../java/usecasetesting/ReplyUseCaseTest.java | 29 ++++++----- .../SelectQuestionUseCaseTest.java | 28 ++++++----- .../usecasetesting/UserLoginUseCaseTest.java | 20 ++++---- .../UserViewHistoryUseCaseTest.java | 38 +++++++------- .../ViewRecommendationUseCaseTest.java | 26 +++++----- 145 files changed, 845 insertions(+), 853 deletions(-) rename src/main/java/{adapter/controller => adapters/controllers}/ClientRegisterControl.java (90%) rename src/main/java/{adapter/controller => adapters/controllers}/CloseQuestionControl.java (84%) rename src/main/java/{adapter/controller => adapters/controllers}/ControlContainer.java (99%) rename src/main/java/{adapter/controller => adapters/controllers}/PostControl.java (79%) rename src/main/java/{adapter/controller => adapters/controllers}/QuestionControl.java (83%) rename src/main/java/{adapter/controller => adapters/controllers}/RateControl.java (85%) rename src/main/java/{adapter/controller => adapters/controllers}/SelectQuestionControl.java (81%) rename src/main/java/{adapter/controller => adapters/controllers}/UserLoginControl.java (85%) rename src/main/java/{adapter/controller => adapters/controllers}/ViewQuestionControl.java (82%) rename src/main/java/{adapter/presenter => adapters/presenters}/HomePageResponseFormatter.java (85%) rename src/main/java/{adapter/presenter => adapters/presenters}/RegisterResponseFormatter.java (83%) rename src/main/java/{adapter/presenter => adapters/presenters}/TheQuestionResponseFormatter.java (79%) rename src/main/java/{adapter/presenter => adapters/presenters}/ViewResponseFormatter.java (82%) delete mode 100644 src/main/java/driver/screen/ReplyQuestionUI.java rename src/main/java/{entity => entities}/ApplicationException.java (95%) rename src/main/java/{entity => entities}/Post.java (99%) rename src/main/java/{entity => entities}/Question.java (99%) rename src/main/java/{entity/factory => entities/factories}/AttorneyFactory.java (82%) rename src/main/java/{entity/factory => entities/factories}/ClientFactory.java (81%) rename src/main/java/{entity/factory => entities/factories}/PostFactory.java (91%) rename src/main/java/{entity/factory => entities/factories}/QuestionFactory.java (87%) rename src/main/java/{entity/factory => entities/factories}/UserFactory.java (80%) rename src/main/java/{entity => entities/user}/Attorney.java (97%) rename src/main/java/{entity => entities/user}/Client.java (98%) rename src/main/java/{entity => entities/user}/User.java (94%) rename src/main/java/{entity => entities/user}/UserImp.java (95%) rename src/main/java/{driver => infrastructure}/database/AttorneyRepository.java (95%) rename src/main/java/{driver => infrastructure}/database/ClientRepository.java (87%) rename src/main/java/{driver => infrastructure}/database/DatabaseConnection.java (96%) rename src/main/java/{driver => infrastructure}/database/GenericRepository.java (97%) rename src/main/java/{driver => infrastructure}/database/PostRepo.java (87%) rename src/main/java/{driver => infrastructure}/database/QuestionRepo.java (97%) rename src/main/java/{businessrule/gateway => infrastructure/database}/UserGatewayFactory.java (89%) rename src/main/java/{driver => infrastructure}/database/UserRepository.java (91%) rename src/main/java/{driver/screen => infrastructure/screens}/AskQuestionUI.java (93%) rename src/main/java/{driver/screen => infrastructure/screens}/AttorneyHomePageUI.java (85%) rename src/main/java/{driver/screen => infrastructure/screens}/BaseUI.java (59%) rename src/main/java/{driver/screen => infrastructure/screens}/ClientHomePageUI.java (86%) rename src/main/java/{driver/screen => infrastructure/screens}/HomePageUI.java (71%) rename src/main/java/{driver/screen => infrastructure/screens}/LoginUI.java (90%) rename src/main/java/{driver/screen => infrastructure/screens}/QuestionCloseUI.java (73%) rename src/main/java/{driver/screen => infrastructure/screens}/QuestionListUI.java (77%) rename src/main/java/{driver/screen => infrastructure/screens}/QuestionNewUI.java (70%) rename src/main/java/{driver/screen => infrastructure/screens}/QuestionOpenAttorneyUI.java (67%) rename src/main/java/{driver/screen => infrastructure/screens}/QuestionOpenClientUI.java (78%) rename src/main/java/{driver/screen => infrastructure/screens}/QuestionUI.java (93%) rename src/main/java/{driver/screen => infrastructure/screens}/RatePanel.java (90%) rename src/main/java/{driver/screen => infrastructure/screens}/RegisterUI.java (96%) rename src/main/java/{businessrule => infrastructure/screens}/UIFactory.java (84%) rename src/main/java/{driver/screen => infrastructure/screens}/UserUI.java (65%) rename src/main/java/{driver/screen => infrastructure/screens}/WelcomeUI.java (92%) rename src/main/java/{driver/screen => infrastructure/screens/utils}/UIDesign.java (94%) rename src/main/java/{driver/screen => infrastructure/screens/utils}/UIDrawer.java (98%) rename src/main/java/{driver/screen => infrastructure/screens/utils}/UIManager.java (88%) delete mode 100644 src/main/java/tutorial/MainFrame.java rename src/main/java/{businessrule/usecase/util => usecases/dto}/Matching.java (95%) rename src/main/java/{businessrule/usecase/util => usecases/dto}/MatchingResult.java (92%) rename src/main/java/{businessrule/usecase/util/PostDisplayFormatter.java => usecases/dto/PostDisplay.java} (88%) rename src/main/java/{businessrule/usecase/util/QuestionDisplayFormatter.java => usecases/dto/QuestionDisplay.java} (89%) rename src/main/java/{businessrule => usecases}/gateway/AttorneyGateway.java (90%) rename src/main/java/{businessrule => usecases}/gateway/ClientGateway.java (86%) rename src/main/java/{businessrule => usecases}/gateway/GenericGateway.java (97%) rename src/main/java/{businessrule => usecases}/gateway/PostGateway.java (87%) rename src/main/java/{businessrule => usecases}/gateway/QuestionGateway.java (97%) rename src/main/java/{businessrule => usecases}/gateway/UserGateway.java (92%) rename src/main/java/{businessrule => usecases}/inputboundary/CloseInputBoundary.java (79%) rename src/main/java/{businessrule => usecases}/inputboundary/PostInputBoundary.java (72%) rename src/main/java/{businessrule => usecases}/inputboundary/QuestionInputBoundary.java (72%) rename src/main/java/{businessrule => usecases}/inputboundary/RateInputBoundary.java (79%) rename src/main/java/{businessrule => usecases}/inputboundary/SelectInputBoundary.java (72%) rename src/main/java/{businessrule => usecases}/inputboundary/UserLoginInputBoundary.java (78%) rename src/main/java/{businessrule => usecases}/inputboundary/UserRegisterInputBoundary.java (69%) rename src/main/java/{businessrule => usecases}/inputboundary/ViewInputBoundary.java (71%) rename src/main/java/{businessrule/usecase => usecases/interactors}/AskQuestionInteractor.java (81%) rename src/main/java/{businessrule/usecase => usecases/interactors}/AttorneyRecommendInteractor.java (68%) rename src/main/java/{businessrule/usecase => usecases/interactors}/BrowseQuestionInteractor.java (80%) rename src/main/java/{businessrule/usecase => usecases/interactors}/ClientRegisterInteractor.java (84%) rename src/main/java/{businessrule/usecase => usecases/interactors}/CloseQuestionInteractor.java (73%) rename src/main/java/{businessrule/usecase => usecases/interactors}/RateInteractor.java (80%) rename src/main/java/{businessrule/usecase => usecases/interactors}/ReplyInteractor.java (90%) rename src/main/java/{businessrule/usecase => usecases/interactors}/SelectQuestionInteractor.java (75%) rename src/main/java/{businessrule/usecase => usecases/interactors}/UserLoginInteractor.java (75%) rename src/main/java/{businessrule/usecase => usecases/interactors}/UserRegisterInteractor.java (80%) rename src/main/java/{businessrule/usecase => usecases/interactors}/ViewQuestionInteractor.java (76%) rename src/main/java/{businessrule/usecase => usecases/interactors}/ViewQuestionInteractorBase.java (63%) rename src/main/java/{businessrule => usecases}/outputboundary/BaseOutputBoundary.java (50%) rename src/main/java/{businessrule => usecases}/outputboundary/TheQuestionOutputBoundary.java (79%) rename src/main/java/{businessrule => usecases}/outputboundary/UserOutputBoundary.java (53%) rename src/main/java/{businessrule => usecases}/outputboundary/ViewOutputBoundary.java (77%) rename src/main/java/{businessrule/requestmodel => usecases/requests}/CloseRequestModel.java (94%) rename src/main/java/{businessrule/requestmodel => usecases/requests}/PostRequestModel.java (96%) rename src/main/java/{businessrule/requestmodel => usecases/requests}/QuestionRequestModel.java (97%) rename src/main/java/{businessrule/requestmodel => usecases/requests}/RateRequestModel.java (95%) rename src/main/java/{businessrule/requestmodel => usecases/requests}/RegistrationData.java (98%) rename src/main/java/{businessrule/requestmodel => usecases/requests}/SelectRequestModel.java (95%) rename src/main/java/{businessrule/requestmodel => usecases/requests}/UserLoginRequestModel.java (96%) rename src/main/java/{businessrule/responsemodel => usecases/responses}/BaseResponseModel.java (66%) rename src/main/java/{businessrule/responsemodel => usecases/responses}/TheQuestionResponseModel.java (82%) rename src/main/java/{businessrule/responsemodel => usecases/responses}/UserResponseModel.java (88%) rename src/main/java/{businessrule/responsemodel => usecases/responses}/ViewResponseModel.java (60%) rename src/main/java/{businessrule => usecases/session}/SessionManager.java (80%) rename src/main/java/{businessrule => usecases/session}/UserSession.java (58%) rename src/main/java/{businessrule/usecase/util => usecases/utils}/BuilderService.java (66%) rename src/main/java/{businessrule/usecase/util => usecases/utils}/CredentialChecker.java (91%) rename src/main/java/{businessrule/usecase/util => usecases/utils}/EmailNotificationSender.java (82%) rename src/main/java/{businessrule/usecase/util => usecases/utils}/MatchingHandler.java (93%) rename src/main/java/{businessrule/usecase/util => usecases/utils}/PostMapConstructor.java (73%) rename src/main/java/{businessrule/usecase/util => usecases/utils}/PythonReader.java (97%) rename src/main/java/{businessrule/usecase/util => usecases/utils}/QuestionMapConstructor.java (72%) rename src/main/java/{businessrule/usecase/util => usecases/utils}/RandomNumberGenerator.java (98%) diff --git a/build.gradle b/build.gradle index 074c8187..e879019c 100644 --- a/build.gradle +++ b/build.gradle @@ -18,9 +18,9 @@ dependencies { implementation 'commons-validator:commons-validator:1.7' implementation 'com.toedter:jcalendar:1.4' implementation 'com.fasterxml.jackson.core:jackson-core:2.12.3' - implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3' + implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.7.1' implementation 'commons-io:commons-io:2.8.0' - implementation 'cn.hutool:hutool-core:5.7.16' + implementation 'cn.hutool:hutool-core:5.8.11' implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.5' } diff --git a/src/main/java/Main.java b/src/main/java/Main.java index fbd04236..f4333c1c 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,19 +1,18 @@ -import adapter.controller.*; -import adapter.presenter.*; -import businessrule.UIFactory; -import businessrule.gateway.*; -import businessrule.inputboundary.*; -import businessrule.outputboundary.*; -import businessrule.responsemodel.BaseResponseModel; -import businessrule.usecase.*; -import driver.database.*; -import driver.screen.UIDesign; -import driver.screen.UIManager; -import driver.screen.WelcomeUI; -import entity.Attorney; -import entity.factory.ClientFactory; -import entity.factory.PostFactory; -import entity.factory.QuestionFactory; +import adapters.controllers.*; +import adapters.presenters.*; +import infrastructure.screens.UIFactory; +import usecases.gateway.*; +import usecases.inputboundary.*; +import usecases.outputboundary.*; +import usecases.responses.BaseResponseModel; +import usecases.interactors.*; +import infrastructure.database.*; +import infrastructure.screens.utils.UIDesign; +import infrastructure.screens.utils.UIManager; +import entities.user.Attorney; +import entities.factories.ClientFactory; +import entities.factories.PostFactory; +import entities.factories.QuestionFactory; import javax.swing.*; import java.awt.*; @@ -33,14 +32,14 @@ public static void main(String[] args) { System.out.println("System - finished set up repo"); - AttorneyRepository attorneyRepo = new AttorneyRepository(); - attorneyRepo.delete(12345678); - Attorney attorney = new Attorney(); - attorney.setUserName("Kaxi"); - attorney.setPassword("12345678"); - attorney.setUserId(12345678); - attorney.setEmail("123455@gmail.com"); - attorneyRepo.save(attorney); +// AttorneyRepository attorneyRepo = new AttorneyRepository(); +// attorneyRepo.delete(12345678); +// Attorney attorney = new Attorney(); +// attorney.setUserName("Kaxi"); +// attorney.setPassword("12345678"); +// attorney.setUserId(12345678); +// attorney.setEmail("123455@gmail.com"); +// attorneyRepo.save(attorney); //set up Jframe JFrame application = new JFrame("Legal Consultation Platform"); @@ -93,7 +92,7 @@ public static void main(String[] args) { postFactory, gatewayFactory); PostControl postControl = new PostControl(replyInteractor); - RateInputBoundary rateInteractor = new RateInteractor(questionGateway, homePageOutputBoundary, clientGateway, + RateInputBoundary rateInteractor = new RateInteractor(questionGateway, homePageOutputBoundary, attorneyGateway); RateControl rateControl = new RateControl(rateInteractor); System.out.println("System - finished set up use case"); diff --git a/src/main/java/adapter/controller/ClientRegisterControl.java b/src/main/java/adapters/controllers/ClientRegisterControl.java similarity index 90% rename from src/main/java/adapter/controller/ClientRegisterControl.java rename to src/main/java/adapters/controllers/ClientRegisterControl.java index 6a29a53c..ca68c58c 100644 --- a/src/main/java/adapter/controller/ClientRegisterControl.java +++ b/src/main/java/adapters/controllers/ClientRegisterControl.java @@ -1,8 +1,8 @@ -package adapter.controller; +package adapters.controllers; -import businessrule.inputboundary.UserRegisterInputBoundary; -import businessrule.requestmodel.RegistrationData; -import businessrule.responsemodel.BaseResponseModel; +import usecases.inputboundary.UserRegisterInputBoundary; +import usecases.requests.RegistrationData; +import usecases.responses.BaseResponseModel; /** * This class represents responsible for handling user registration. diff --git a/src/main/java/adapter/controller/CloseQuestionControl.java b/src/main/java/adapters/controllers/CloseQuestionControl.java similarity index 84% rename from src/main/java/adapter/controller/CloseQuestionControl.java rename to src/main/java/adapters/controllers/CloseQuestionControl.java index 116c27af..b1b5a443 100644 --- a/src/main/java/adapter/controller/CloseQuestionControl.java +++ b/src/main/java/adapters/controllers/CloseQuestionControl.java @@ -1,8 +1,8 @@ -package adapter.controller; +package adapters.controllers; -import businessrule.inputboundary.CloseInputBoundary; -import businessrule.requestmodel.CloseRequestModel; -import businessrule.responsemodel.UserResponseModel; +import usecases.inputboundary.CloseInputBoundary; +import usecases.requests.CloseRequestModel; +import usecases.responses.UserResponseModel; /** * This class represents a controller responsible for closing a question. It utilizes the CloseInputBoundary diff --git a/src/main/java/adapter/controller/ControlContainer.java b/src/main/java/adapters/controllers/ControlContainer.java similarity index 99% rename from src/main/java/adapter/controller/ControlContainer.java rename to src/main/java/adapters/controllers/ControlContainer.java index 47e03e43..6d1295d5 100644 --- a/src/main/java/adapter/controller/ControlContainer.java +++ b/src/main/java/adapters/controllers/ControlContainer.java @@ -1,8 +1,7 @@ -package adapter.controller; +package adapters.controllers; /** * This class represents that holds instances of various control classes. - * * It is responsible for managing different aspects of the application. */ public class ControlContainer { diff --git a/src/main/java/adapter/controller/PostControl.java b/src/main/java/adapters/controllers/PostControl.java similarity index 79% rename from src/main/java/adapter/controller/PostControl.java rename to src/main/java/adapters/controllers/PostControl.java index c521570f..91585d37 100644 --- a/src/main/java/adapter/controller/PostControl.java +++ b/src/main/java/adapters/controllers/PostControl.java @@ -1,9 +1,8 @@ -package adapter.controller; +package adapters.controllers; -import businessrule.inputboundary.PostInputBoundary; -import businessrule.requestmodel.PostRequestModel; -import businessrule.responsemodel.TheQuestionResponseModel; -import businessrule.responsemodel.UserResponseModel; +import usecases.inputboundary.PostInputBoundary; +import usecases.requests.PostRequestModel; +import usecases.responses.TheQuestionResponseModel; /** * This class represents the controller responsible for handling interactions related to creating posts. diff --git a/src/main/java/adapter/controller/QuestionControl.java b/src/main/java/adapters/controllers/QuestionControl.java similarity index 83% rename from src/main/java/adapter/controller/QuestionControl.java rename to src/main/java/adapters/controllers/QuestionControl.java index ce58551e..3b88059f 100644 --- a/src/main/java/adapter/controller/QuestionControl.java +++ b/src/main/java/adapters/controllers/QuestionControl.java @@ -1,9 +1,8 @@ -package adapter.controller; +package adapters.controllers; -import businessrule.responsemodel.TheQuestionResponseModel; -import businessrule.inputboundary.QuestionInputBoundary; -import businessrule.requestmodel.QuestionRequestModel; -import businessrule.responsemodel.UserResponseModel; +import usecases.responses.TheQuestionResponseModel; +import usecases.inputboundary.QuestionInputBoundary; +import usecases.requests.QuestionRequestModel; import java.time.LocalDate; diff --git a/src/main/java/adapter/controller/RateControl.java b/src/main/java/adapters/controllers/RateControl.java similarity index 85% rename from src/main/java/adapter/controller/RateControl.java rename to src/main/java/adapters/controllers/RateControl.java index 9ae67d7b..d52d887f 100644 --- a/src/main/java/adapter/controller/RateControl.java +++ b/src/main/java/adapters/controllers/RateControl.java @@ -1,8 +1,8 @@ -package adapter.controller; +package adapters.controllers; -import businessrule.inputboundary.RateInputBoundary; -import businessrule.requestmodel.RateRequestModel; -import businessrule.responsemodel.UserResponseModel; +import usecases.inputboundary.RateInputBoundary; +import usecases.requests.RateRequestModel; +import usecases.responses.UserResponseModel; /** * This class represents a controller responsible for handling rating-related actions. diff --git a/src/main/java/adapter/controller/SelectQuestionControl.java b/src/main/java/adapters/controllers/SelectQuestionControl.java similarity index 81% rename from src/main/java/adapter/controller/SelectQuestionControl.java rename to src/main/java/adapters/controllers/SelectQuestionControl.java index 282f27e7..9bf1f5e9 100644 --- a/src/main/java/adapter/controller/SelectQuestionControl.java +++ b/src/main/java/adapters/controllers/SelectQuestionControl.java @@ -1,9 +1,8 @@ -package adapter.controller; +package adapters.controllers; -import businessrule.inputboundary.SelectInputBoundary; -import businessrule.requestmodel.SelectRequestModel; -import businessrule.responsemodel.TheQuestionResponseModel; -import businessrule.responsemodel.UserResponseModel; +import usecases.inputboundary.SelectInputBoundary; +import usecases.requests.SelectRequestModel; +import usecases.responses.TheQuestionResponseModel; /** * This class represents a controller responsible for selecting a question. diff --git a/src/main/java/adapter/controller/UserLoginControl.java b/src/main/java/adapters/controllers/UserLoginControl.java similarity index 85% rename from src/main/java/adapter/controller/UserLoginControl.java rename to src/main/java/adapters/controllers/UserLoginControl.java index a21d0a5d..fbb39b93 100644 --- a/src/main/java/adapter/controller/UserLoginControl.java +++ b/src/main/java/adapters/controllers/UserLoginControl.java @@ -1,8 +1,8 @@ -package adapter.controller; +package adapters.controllers; -import businessrule.inputboundary.UserLoginInputBoundary; -import businessrule.requestmodel.UserLoginRequestModel; -import businessrule.responsemodel.UserResponseModel; +import usecases.inputboundary.UserLoginInputBoundary; +import usecases.requests.UserLoginRequestModel; +import usecases.responses.UserResponseModel; /** * This class represents the controller responsible for handling user login functionality. diff --git a/src/main/java/adapter/controller/ViewQuestionControl.java b/src/main/java/adapters/controllers/ViewQuestionControl.java similarity index 82% rename from src/main/java/adapter/controller/ViewQuestionControl.java rename to src/main/java/adapters/controllers/ViewQuestionControl.java index 92041012..020622e4 100644 --- a/src/main/java/adapter/controller/ViewQuestionControl.java +++ b/src/main/java/adapters/controllers/ViewQuestionControl.java @@ -1,14 +1,10 @@ -package adapter.controller; +package adapters.controllers; -import businessrule.responsemodel.UserResponseModel; -import businessrule.inputboundary.ViewInputBoundary; -import businessrule.responsemodel.ViewResponseModel; - -import javax.swing.text.View; +import usecases.inputboundary.ViewInputBoundary; +import usecases.responses.ViewResponseModel; /** * Controller class responsible for viewing questions. - * * This class acts as an interface between the presentation layer and the business logic for viewing questions. * It takes a user's ID as input, creates a request model, and delegates the request to the corresponding input boundary. * The response model from the input boundary is returned to the caller. diff --git a/src/main/java/adapter/presenter/HomePageResponseFormatter.java b/src/main/java/adapters/presenters/HomePageResponseFormatter.java similarity index 85% rename from src/main/java/adapter/presenter/HomePageResponseFormatter.java rename to src/main/java/adapters/presenters/HomePageResponseFormatter.java index 5410983c..faf43e8d 100644 --- a/src/main/java/adapter/presenter/HomePageResponseFormatter.java +++ b/src/main/java/adapters/presenters/HomePageResponseFormatter.java @@ -1,10 +1,9 @@ -package adapter.presenter; -import businessrule.UIFactory; -import businessrule.outputboundary.UserOutputBoundary; -import businessrule.responsemodel.UserResponseModel; -import driver.screen.HomePageUI; -import driver.screen.UIManager; -import entity.ApplicationException; +package adapters.presenters; +import infrastructure.screens.UIFactory; +import usecases.outputboundary.UserOutputBoundary; +import usecases.responses.UserResponseModel; +import infrastructure.screens.utils.UIManager; +import entities.ApplicationException; import javax.swing.*; import java.awt.*; diff --git a/src/main/java/adapter/presenter/RegisterResponseFormatter.java b/src/main/java/adapters/presenters/RegisterResponseFormatter.java similarity index 83% rename from src/main/java/adapter/presenter/RegisterResponseFormatter.java rename to src/main/java/adapters/presenters/RegisterResponseFormatter.java index 78c9f88e..6bf51989 100644 --- a/src/main/java/adapter/presenter/RegisterResponseFormatter.java +++ b/src/main/java/adapters/presenters/RegisterResponseFormatter.java @@ -1,11 +1,10 @@ -package adapter.presenter; +package adapters.presenters; -import adapter.controller.ControlContainer; -import businessrule.UIFactory; -import businessrule.outputboundary.BaseOutputBoundary; -import businessrule.responsemodel.BaseResponseModel; -import driver.screen.UIManager; -import entity.ApplicationException; +import infrastructure.screens.UIFactory; +import usecases.outputboundary.BaseOutputBoundary; +import usecases.responses.BaseResponseModel; +import infrastructure.screens.utils.UIManager; +import entities.ApplicationException; import javax.swing.*; import java.awt.*; import java.awt.datatransfer.Clipboard; @@ -54,10 +53,10 @@ public BaseResponseModel prepareSuccess(String msg) { screens.add(welcomeUI, "Welcome"); cardLayout.show(screens, "Welcome"); Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); - Transferable tText = new StringSelection(msg+""); + Transferable tText = new StringSelection(msg); clip.setContents(tText, null); String message = "Important: Your unique User ID: " + msg + " has been generated and copied to your clipboard. \nPlease save it securely, as it will not be shown again."; - JOptionPane.showMessageDialog(null, message,"Notice",JOptionPane.YES_OPTION); + JOptionPane.showMessageDialog(null, message, "Notice", JOptionPane.INFORMATION_MESSAGE); return new BaseResponseModel(); } } diff --git a/src/main/java/adapter/presenter/TheQuestionResponseFormatter.java b/src/main/java/adapters/presenters/TheQuestionResponseFormatter.java similarity index 79% rename from src/main/java/adapter/presenter/TheQuestionResponseFormatter.java rename to src/main/java/adapters/presenters/TheQuestionResponseFormatter.java index fb630bdb..a9c6522e 100644 --- a/src/main/java/adapter/presenter/TheQuestionResponseFormatter.java +++ b/src/main/java/adapters/presenters/TheQuestionResponseFormatter.java @@ -1,13 +1,12 @@ -package adapter.presenter; +package adapters.presenters; -import businessrule.UIFactory; -import businessrule.outputboundary.TheQuestionOutputBoundary; -import businessrule.responsemodel.TheQuestionResponseModel; -import businessrule.responsemodel.UserResponseModel; -import businessrule.usecase.util.PostDisplayFormatter; -import driver.screen.UIManager; -import entity.ApplicationException; +import infrastructure.screens.UIFactory; +import usecases.outputboundary.TheQuestionOutputBoundary; +import usecases.responses.TheQuestionResponseModel; +import usecases.dto.PostDisplay; +import infrastructure.screens.utils.UIManager; +import entities.ApplicationException; import javax.swing.*; import java.awt.*; @@ -19,7 +18,7 @@ */ public class TheQuestionResponseFormatter implements TheQuestionOutputBoundary { - driver.screen.UIManager UIManager; + infrastructure.screens.utils.UIManager UIManager; /** * Constructs a TheQuestionResponseFormatter with the specified CardLayout and JPanel. @@ -52,7 +51,7 @@ public TheQuestionResponseModel prepareFail(String msg) { public TheQuestionResponseModel prepareSuccess(TheQuestionResponseModel response) { JPanel screens = UIManager.getScreens(); CardLayout cardLayout = UIManager.getCardLayout(); - Map postMap= response.getPostMap(); + Map postMap= response.getPostMap(); if (postMap.size() == 1){ cardLayout.show(screens, "Home Page"); } else { diff --git a/src/main/java/adapter/presenter/ViewResponseFormatter.java b/src/main/java/adapters/presenters/ViewResponseFormatter.java similarity index 82% rename from src/main/java/adapter/presenter/ViewResponseFormatter.java rename to src/main/java/adapters/presenters/ViewResponseFormatter.java index ce812b69..ae965207 100644 --- a/src/main/java/adapter/presenter/ViewResponseFormatter.java +++ b/src/main/java/adapters/presenters/ViewResponseFormatter.java @@ -1,11 +1,10 @@ -package adapter.presenter; +package adapters.presenters; -import businessrule.UIFactory; -import businessrule.outputboundary.ViewOutputBoundary; -import businessrule.responsemodel.UserResponseModel; -import businessrule.responsemodel.ViewResponseModel; -import driver.screen.UIManager; -import entity.ApplicationException; +import infrastructure.screens.UIFactory; +import usecases.outputboundary.ViewOutputBoundary; +import usecases.responses.ViewResponseModel; +import infrastructure.screens.utils.UIManager; +import entities.ApplicationException; import javax.swing.*; import java.awt.*; @@ -21,7 +20,7 @@ public class ViewResponseFormatter implements ViewOutputBoundary { * * @param UIManager UIManager class contains screens, cardlayouts, and control container. */ - public ViewResponseFormatter(driver.screen.UIManager UIManager) { + public ViewResponseFormatter(infrastructure.screens.utils.UIManager UIManager) { this.UIManager = UIManager; } diff --git a/src/main/java/driver/screen/ReplyQuestionUI.java b/src/main/java/driver/screen/ReplyQuestionUI.java deleted file mode 100644 index 2645ad35..00000000 --- a/src/main/java/driver/screen/ReplyQuestionUI.java +++ /dev/null @@ -1,8 +0,0 @@ -package driver.screen; - -/** - * This class represents the user interface for replying to a question. - */ -public class ReplyQuestionUI { - // Add class members, constructor, methods, etc. here -} \ No newline at end of file diff --git a/src/main/java/entity/ApplicationException.java b/src/main/java/entities/ApplicationException.java similarity index 95% rename from src/main/java/entity/ApplicationException.java rename to src/main/java/entities/ApplicationException.java index ef8c0e55..7f713644 100644 --- a/src/main/java/entity/ApplicationException.java +++ b/src/main/java/entities/ApplicationException.java @@ -1,4 +1,4 @@ -package entity; +package entities; /** * This class represents a custom runtime exception that can be thrown during application execution. diff --git a/src/main/java/entity/Post.java b/src/main/java/entities/Post.java similarity index 99% rename from src/main/java/entity/Post.java rename to src/main/java/entities/Post.java index f8b6f693..892c4ebc 100644 --- a/src/main/java/entity/Post.java +++ b/src/main/java/entities/Post.java @@ -1,4 +1,4 @@ -package entity; +package entities; import com.fasterxml.jackson.annotation.JsonProperty; @@ -9,7 +9,6 @@ /** * This class represents a post in a question thread. - * * A "Post" is a message or response posted in the context of a specific question thread. * Each post contains information such as the ID of the associated question, the post ID, * the creation date, the text of the post, and an identifier indicating which user the post diff --git a/src/main/java/entity/Question.java b/src/main/java/entities/Question.java similarity index 99% rename from src/main/java/entity/Question.java rename to src/main/java/entities/Question.java index 48dc3de1..21ec1ab3 100644 --- a/src/main/java/entity/Question.java +++ b/src/main/java/entities/Question.java @@ -1,4 +1,4 @@ -package entity; +package entities; import com.fasterxml.jackson.annotation.JsonProperty; @@ -13,7 +13,6 @@ /** * This class represents a question thread. - * * Each question thread contains information about the type of the question, the client who asked the question, * whether the question has been taken and by whom, and a list of posts belonging to the question. */ diff --git a/src/main/java/entity/factory/AttorneyFactory.java b/src/main/java/entities/factories/AttorneyFactory.java similarity index 82% rename from src/main/java/entity/factory/AttorneyFactory.java rename to src/main/java/entities/factories/AttorneyFactory.java index f7bb6518..ec49b84b 100644 --- a/src/main/java/entity/factory/AttorneyFactory.java +++ b/src/main/java/entities/factories/AttorneyFactory.java @@ -1,7 +1,7 @@ -package entity.factory; +package entities.factories; -import businessrule.requestmodel.RegistrationData; -import entity.Attorney; +import usecases.requests.RegistrationData; +import entities.user.Attorney; /** * This class represents creating Attorney instances. diff --git a/src/main/java/entity/factory/ClientFactory.java b/src/main/java/entities/factories/ClientFactory.java similarity index 81% rename from src/main/java/entity/factory/ClientFactory.java rename to src/main/java/entities/factories/ClientFactory.java index 98b8ae95..283c37de 100644 --- a/src/main/java/entity/factory/ClientFactory.java +++ b/src/main/java/entities/factories/ClientFactory.java @@ -1,7 +1,7 @@ -package entity.factory; +package entities.factories; -import businessrule.requestmodel.RegistrationData; -import entity.Client; +import usecases.requests.RegistrationData; +import entities.user.Client; /** * This class represents creating Client instances. diff --git a/src/main/java/entity/factory/PostFactory.java b/src/main/java/entities/factories/PostFactory.java similarity index 91% rename from src/main/java/entity/factory/PostFactory.java rename to src/main/java/entities/factories/PostFactory.java index eed840e1..01f2a076 100644 --- a/src/main/java/entity/factory/PostFactory.java +++ b/src/main/java/entities/factories/PostFactory.java @@ -1,12 +1,11 @@ -package entity.factory; +package entities.factories; -import entity.Post; +import entities.Post; import java.time.LocalDate; /** * This is a factory class for creating Post objects. - * * The "PostFactory" class provides a convenient way to create instances of the "Post" class by encapsulating * the construction logic. It serves as a central point for creating posts associated with questions in the application. */ diff --git a/src/main/java/entity/factory/QuestionFactory.java b/src/main/java/entities/factories/QuestionFactory.java similarity index 87% rename from src/main/java/entity/factory/QuestionFactory.java rename to src/main/java/entities/factories/QuestionFactory.java index 619a855b..2b1cca82 100644 --- a/src/main/java/entity/factory/QuestionFactory.java +++ b/src/main/java/entities/factories/QuestionFactory.java @@ -1,6 +1,6 @@ -package entity.factory; +package entities.factories; -import entity.Question; +import entities.Question; import java.time.LocalDate; diff --git a/src/main/java/entity/factory/UserFactory.java b/src/main/java/entities/factories/UserFactory.java similarity index 80% rename from src/main/java/entity/factory/UserFactory.java rename to src/main/java/entities/factories/UserFactory.java index a087dc9c..3f5f466b 100644 --- a/src/main/java/entity/factory/UserFactory.java +++ b/src/main/java/entities/factories/UserFactory.java @@ -1,7 +1,7 @@ -package entity.factory; +package entities.factories; -import businessrule.requestmodel.RegistrationData; -import entity.UserImp; +import usecases.requests.RegistrationData; +import entities.user.UserImp; /** * This is a interface represents creating user instances. diff --git a/src/main/java/entity/Attorney.java b/src/main/java/entities/user/Attorney.java similarity index 97% rename from src/main/java/entity/Attorney.java rename to src/main/java/entities/user/Attorney.java index 6deafff8..58938367 100644 --- a/src/main/java/entity/Attorney.java +++ b/src/main/java/entities/user/Attorney.java @@ -1,8 +1,8 @@ -package entity; +package entities.user; import com.fasterxml.jackson.annotation.JsonProperty; -import businessrule.requestmodel.RegistrationData; -import driver.database.AttorneyRepository; +import entities.Question; +import usecases.requests.RegistrationData; import javax.persistence.*; import java.time.LocalDate; @@ -13,7 +13,6 @@ /** * This is a class representing attorney user. - * * An Attorney is a registered user who is a legal professional, capable of answering legal questions * posted by clients. The Attorney has attributes such as user ID, name, email, password, state abbreviation, * postal code, and a list of questions associated with them. diff --git a/src/main/java/entity/Client.java b/src/main/java/entities/user/Client.java similarity index 98% rename from src/main/java/entity/Client.java rename to src/main/java/entities/user/Client.java index 5cdf6781..6ae9f83d 100644 --- a/src/main/java/entity/Client.java +++ b/src/main/java/entities/user/Client.java @@ -1,7 +1,8 @@ -package entity; +package entities.user; import com.fasterxml.jackson.annotation.JsonProperty; -import businessrule.requestmodel.RegistrationData; +import entities.Question; +import usecases.requests.RegistrationData; import javax.persistence.*; import java.util.ArrayList; @@ -39,7 +40,7 @@ private Client(Builder builder) { this.maritalStatus = builder.data.maritalStatus; this.numberOfHousehold = builder.data.numberOfHousehold; this.annualIncome = builder.data.annualIncome; - this.questionsList = new ArrayList(); + this.questionsList = new ArrayList<>(); } /** diff --git a/src/main/java/entity/User.java b/src/main/java/entities/user/User.java similarity index 94% rename from src/main/java/entity/User.java rename to src/main/java/entities/user/User.java index ae56bfda..d2631646 100644 --- a/src/main/java/entity/User.java +++ b/src/main/java/entities/user/User.java @@ -1,8 +1,9 @@ -package entity; +package entities.user; + +import entities.Question; import java.util.List; -import javax.persistence.Entity; /** * The "User" interface represents a generic user in the system. * This interface defines common methods that are shared by different types of users in the application, diff --git a/src/main/java/entity/UserImp.java b/src/main/java/entities/user/UserImp.java similarity index 95% rename from src/main/java/entity/UserImp.java rename to src/main/java/entities/user/UserImp.java index 3dca3c2a..aa741b94 100644 --- a/src/main/java/entity/UserImp.java +++ b/src/main/java/entities/user/UserImp.java @@ -1,7 +1,8 @@ -package entity; +package entities.user; import com.fasterxml.jackson.annotation.JsonProperty; -import businessrule.requestmodel.RegistrationData; +import entities.Question; +import usecases.requests.RegistrationData; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -15,7 +16,7 @@ * This class respresents a user entity with common properties and behaviors. */ @Entity -public abstract class UserImp implements User{ +public abstract class UserImp implements User { @Id @JsonProperty(required = true) protected int userId; @@ -29,7 +30,7 @@ public abstract class UserImp implements User{ @JsonProperty(required = true) protected List questionsList; - public UserImp() {questionsList = new ArrayList();} + public UserImp() {questionsList = new ArrayList<>();} protected UserImp(Builder builder) { this.userId = builder.data.userId; diff --git a/src/main/java/driver/database/AttorneyRepository.java b/src/main/java/infrastructure/database/AttorneyRepository.java similarity index 95% rename from src/main/java/driver/database/AttorneyRepository.java rename to src/main/java/infrastructure/database/AttorneyRepository.java index 55008aea..93d39297 100644 --- a/src/main/java/driver/database/AttorneyRepository.java +++ b/src/main/java/infrastructure/database/AttorneyRepository.java @@ -1,7 +1,8 @@ -package driver.database; +package infrastructure.database; -import businessrule.gateway.AttorneyGateway; -import entity.*; +import entities.user.Attorney; +import usecases.gateway.AttorneyGateway; +import entities.*; import javax.jdo.JDOHelper; import javax.persistence.EntityManager; diff --git a/src/main/java/driver/database/ClientRepository.java b/src/main/java/infrastructure/database/ClientRepository.java similarity index 87% rename from src/main/java/driver/database/ClientRepository.java rename to src/main/java/infrastructure/database/ClientRepository.java index 6e7cc451..d6230541 100644 --- a/src/main/java/driver/database/ClientRepository.java +++ b/src/main/java/infrastructure/database/ClientRepository.java @@ -1,7 +1,7 @@ -package driver.database; +package infrastructure.database; -import businessrule.gateway.ClientGateway; -import entity.Client; +import usecases.gateway.ClientGateway; +import entities.user.Client; /** * This class represents managing Client entities in the database. diff --git a/src/main/java/driver/database/DatabaseConnection.java b/src/main/java/infrastructure/database/DatabaseConnection.java similarity index 96% rename from src/main/java/driver/database/DatabaseConnection.java rename to src/main/java/infrastructure/database/DatabaseConnection.java index 1cb9bab9..229e47d1 100644 --- a/src/main/java/driver/database/DatabaseConnection.java +++ b/src/main/java/infrastructure/database/DatabaseConnection.java @@ -1,4 +1,4 @@ -package driver.database; +package infrastructure.database; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManager; diff --git a/src/main/java/driver/database/GenericRepository.java b/src/main/java/infrastructure/database/GenericRepository.java similarity index 97% rename from src/main/java/driver/database/GenericRepository.java rename to src/main/java/infrastructure/database/GenericRepository.java index 64969144..feda2e95 100644 --- a/src/main/java/driver/database/GenericRepository.java +++ b/src/main/java/infrastructure/database/GenericRepository.java @@ -1,6 +1,6 @@ -package driver.database; +package infrastructure.database; -import businessrule.gateway.GenericGateway; +import usecases.gateway.GenericGateway; import javax.persistence.EntityManager; import javax.persistence.EntityTransaction; import java.util.List; diff --git a/src/main/java/driver/database/PostRepo.java b/src/main/java/infrastructure/database/PostRepo.java similarity index 87% rename from src/main/java/driver/database/PostRepo.java rename to src/main/java/infrastructure/database/PostRepo.java index ddc780ae..b8ff3d6e 100644 --- a/src/main/java/driver/database/PostRepo.java +++ b/src/main/java/infrastructure/database/PostRepo.java @@ -1,7 +1,7 @@ -package driver.database; +package infrastructure.database; -import businessrule.gateway.PostGateway; -import entity.Post; +import usecases.gateway.PostGateway; +import entities.Post; /** * This class representsmanaging Post entities in the database. diff --git a/src/main/java/driver/database/QuestionRepo.java b/src/main/java/infrastructure/database/QuestionRepo.java similarity index 97% rename from src/main/java/driver/database/QuestionRepo.java rename to src/main/java/infrastructure/database/QuestionRepo.java index a97204c3..82b1be82 100644 --- a/src/main/java/driver/database/QuestionRepo.java +++ b/src/main/java/infrastructure/database/QuestionRepo.java @@ -1,8 +1,8 @@ -package driver.database; +package infrastructure.database; -import businessrule.gateway.QuestionGateway; -import entity.Post; -import entity.Question; +import usecases.gateway.QuestionGateway; +import entities.Post; +import entities.Question; import javax.jdo.JDOHelper; import javax.persistence.EntityManager; import javax.persistence.EntityTransaction; diff --git a/src/main/java/businessrule/gateway/UserGatewayFactory.java b/src/main/java/infrastructure/database/UserGatewayFactory.java similarity index 89% rename from src/main/java/businessrule/gateway/UserGatewayFactory.java rename to src/main/java/infrastructure/database/UserGatewayFactory.java index 96681194..2bab0680 100644 --- a/src/main/java/businessrule/gateway/UserGatewayFactory.java +++ b/src/main/java/infrastructure/database/UserGatewayFactory.java @@ -1,9 +1,8 @@ -package businessrule.gateway; +package infrastructure.database; -import driver.database.AttorneyRepository; -import driver.database.ClientRepository; -import entity.ApplicationException; -import entity.User; +import entities.ApplicationException; +import entities.user.User; +import usecases.gateway.UserGateway; /** * This class represents for creating instances of UserGateway based on the user's role. diff --git a/src/main/java/driver/database/UserRepository.java b/src/main/java/infrastructure/database/UserRepository.java similarity index 91% rename from src/main/java/driver/database/UserRepository.java rename to src/main/java/infrastructure/database/UserRepository.java index 8e008f0a..66edba61 100644 --- a/src/main/java/driver/database/UserRepository.java +++ b/src/main/java/infrastructure/database/UserRepository.java @@ -1,8 +1,8 @@ -package driver.database; +package infrastructure.database; -import businessrule.gateway.UserGateway; -import entity.Question; -import entity.User; +import usecases.gateway.UserGateway; +import entities.Question; +import entities.user.User; import javax.jdo.JDOHelper; import java.util.List; diff --git a/src/main/java/driver/screen/AskQuestionUI.java b/src/main/java/infrastructure/screens/AskQuestionUI.java similarity index 93% rename from src/main/java/driver/screen/AskQuestionUI.java rename to src/main/java/infrastructure/screens/AskQuestionUI.java index 768755fd..ed0fa517 100644 --- a/src/main/java/driver/screen/AskQuestionUI.java +++ b/src/main/java/infrastructure/screens/AskQuestionUI.java @@ -1,7 +1,7 @@ -package driver.screen; +package infrastructure.screens; -import adapter.controller.ControlContainer; -import adapter.controller.QuestionControl; +import adapters.controllers.ControlContainer; +import adapters.controllers.QuestionControl; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; @@ -16,9 +16,11 @@ import javax.swing.JPanel; import com.toedter.calendar.JDateChooser; +import infrastructure.screens.utils.UIDesign; +import infrastructure.screens.utils.UIManager; -import static driver.screen.UIDesign.*; -import static driver.screen.UIDrawer.*; +import static infrastructure.screens.utils.UIDesign.*; +import static infrastructure.screens.utils.UIDrawer.*; /** diff --git a/src/main/java/driver/screen/AttorneyHomePageUI.java b/src/main/java/infrastructure/screens/AttorneyHomePageUI.java similarity index 85% rename from src/main/java/driver/screen/AttorneyHomePageUI.java rename to src/main/java/infrastructure/screens/AttorneyHomePageUI.java index 8b0afa38..ac3342a8 100644 --- a/src/main/java/driver/screen/AttorneyHomePageUI.java +++ b/src/main/java/infrastructure/screens/AttorneyHomePageUI.java @@ -1,10 +1,9 @@ -package driver.screen; +package infrastructure.screens; -import adapter.controller.ControlContainer; -import adapter.controller.ViewQuestionControl; -import businessrule.SessionManager; -import businessrule.UIFactory; -import cn.hutool.core.net.LocalPortGenerater; +import adapters.controllers.ControlContainer; +import adapters.controllers.ViewQuestionControl; +import infrastructure.screens.utils.UIManager; +import usecases.session.SessionManager; import javax.swing.*; import java.awt.*; @@ -13,7 +12,7 @@ import java.util.ArrayList; import java.util.List; -import static driver.screen.UIDrawer.*; +import static infrastructure.screens.utils.UIDrawer.*; /** @@ -27,9 +26,7 @@ public class AttorneyHomePageUI extends HomePageUI implements ActionListener { /** * Constructs an AttorneyHomePageUI instance. * - * @param controlContainer The container for controllers. - * @param cardLayout The CardLayout for managing screens. - * @param screens The parent panel containing multiple screens. + * @param UIManager UIManager contains screens, cardlayouts, and control containers. * @param userId The ID of the logged-in attorney user. * @param userName The name of the logged-in attorney user. */ diff --git a/src/main/java/driver/screen/BaseUI.java b/src/main/java/infrastructure/screens/BaseUI.java similarity index 59% rename from src/main/java/driver/screen/BaseUI.java rename to src/main/java/infrastructure/screens/BaseUI.java index 875e2ed6..6a2a5428 100644 --- a/src/main/java/driver/screen/BaseUI.java +++ b/src/main/java/infrastructure/screens/BaseUI.java @@ -1,11 +1,16 @@ -package driver.screen; +package infrastructure.screens; + +import infrastructure.screens.utils.UIManager; import javax.swing.*; import java.awt.event.ActionListener; -import static driver.screen.UIDesign.*; +import static infrastructure.screens.utils.UIDesign.*; +/** + * This absr=tract class represents the base for all other user interface. + */ public abstract class BaseUI extends JPanel implements ActionListener { - UIManager uiManager; + infrastructure.screens.utils.UIManager uiManager; public BaseUI(UIManager UIManager) { setBackgroundFrame(this); setBackground(lightGreenColor); diff --git a/src/main/java/driver/screen/ClientHomePageUI.java b/src/main/java/infrastructure/screens/ClientHomePageUI.java similarity index 86% rename from src/main/java/driver/screen/ClientHomePageUI.java rename to src/main/java/infrastructure/screens/ClientHomePageUI.java index c23b4441..4028acaf 100644 --- a/src/main/java/driver/screen/ClientHomePageUI.java +++ b/src/main/java/infrastructure/screens/ClientHomePageUI.java @@ -1,9 +1,8 @@ -package driver.screen; +package infrastructure.screens; -import adapter.controller.*; -import businessrule.SessionManager; -import businessrule.UIFactory; -import businessrule.UserSession; +import adapters.controllers.*; +import infrastructure.screens.utils.UIManager; +import usecases.session.SessionManager; import javax.swing.*; import java.awt.*; @@ -12,7 +11,7 @@ import java.util.ArrayList; import java.util.List; -import static driver.screen.UIDrawer.*; +import static infrastructure.screens.utils.UIDrawer.*; /** * This class represents a JPanel for the Client's home page user interface. @@ -23,9 +22,7 @@ public class ClientHomePageUI extends HomePageUI implements ActionListener { /** * Constructs a new ClientHomePageUI instance. * - * @param controlContainer The container for controllers. - * @param cardLayout The CardLayout for managing screens. - * @param screens The parent panel containing multiple screens. + * @param UIManager UIManager contains screens, cardlayouts, and control containers. * @param userId The ID of the logged-in client user. * @param userName The name of the logged-in client user. */ diff --git a/src/main/java/driver/screen/HomePageUI.java b/src/main/java/infrastructure/screens/HomePageUI.java similarity index 71% rename from src/main/java/driver/screen/HomePageUI.java rename to src/main/java/infrastructure/screens/HomePageUI.java index 1c1e68c5..405e503a 100644 --- a/src/main/java/driver/screen/HomePageUI.java +++ b/src/main/java/infrastructure/screens/HomePageUI.java @@ -1,10 +1,15 @@ -package driver.screen; +package infrastructure.screens; + +import infrastructure.screens.utils.UIManager; import javax.swing.*; import java.awt.*; -import static driver.screen.UIDesign.setTitleFont; +import static infrastructure.screens.utils.UIDesign.setTitleFont; +/** + * This abstract class represents a base for all home page user interface. + */ public abstract class HomePageUI extends UserUI { protected JLabel title; static final String TITLE_NAME = "Home"; diff --git a/src/main/java/driver/screen/LoginUI.java b/src/main/java/infrastructure/screens/LoginUI.java similarity index 90% rename from src/main/java/driver/screen/LoginUI.java rename to src/main/java/infrastructure/screens/LoginUI.java index 1a89b7b9..1494c0e7 100644 --- a/src/main/java/driver/screen/LoginUI.java +++ b/src/main/java/infrastructure/screens/LoginUI.java @@ -1,7 +1,8 @@ -package driver.screen; +package infrastructure.screens; -import adapter.controller.ControlContainer; -import adapter.controller.UserLoginControl; +import adapters.controllers.ControlContainer; +import adapters.controllers.UserLoginControl; +import infrastructure.screens.utils.UIManager; import javax.swing.*; import java.awt.*; @@ -10,8 +11,8 @@ import java.util.ArrayList; import java.util.List; -import static driver.screen.UIDesign.*; -import static driver.screen.UIDrawer.*; +import static infrastructure.screens.utils.UIDesign.*; +import static infrastructure.screens.utils.UIDrawer.*; /** diff --git a/src/main/java/driver/screen/QuestionCloseUI.java b/src/main/java/infrastructure/screens/QuestionCloseUI.java similarity index 73% rename from src/main/java/driver/screen/QuestionCloseUI.java rename to src/main/java/infrastructure/screens/QuestionCloseUI.java index b4e6aa13..8b6590ec 100644 --- a/src/main/java/driver/screen/QuestionCloseUI.java +++ b/src/main/java/infrastructure/screens/QuestionCloseUI.java @@ -1,18 +1,21 @@ -package driver.screen; -import adapter.controller.ControlContainer; -import businessrule.usecase.util.PostDisplayFormatter; +package infrastructure.screens; +import adapters.controllers.ControlContainer; +import infrastructure.screens.utils.UIManager; +import usecases.dto.PostDisplay; import javax.swing.*; import java.awt.*; import java.time.LocalDate; import java.util.Map; -import static driver.screen.UIDrawer.*; - +import static infrastructure.screens.utils.UIDrawer.*; +/** + * This class provides a UI for client to view the question that was closed. + */ public class QuestionCloseUI extends QuestionUI{ public QuestionCloseUI(String userName, int userId, UIManager UIManager, int questionId, String title, - String questionType, LocalDate deadline, Map postMap) { + String questionType, LocalDate deadline, Map postMap) { super(userName, userId, UIManager, questionId, title, questionType, deadline, postMap); //Spacers diff --git a/src/main/java/driver/screen/QuestionListUI.java b/src/main/java/infrastructure/screens/QuestionListUI.java similarity index 77% rename from src/main/java/driver/screen/QuestionListUI.java rename to src/main/java/infrastructure/screens/QuestionListUI.java index df1acfbc..cfe32f6e 100644 --- a/src/main/java/driver/screen/QuestionListUI.java +++ b/src/main/java/infrastructure/screens/QuestionListUI.java @@ -1,7 +1,9 @@ -package driver.screen; -import adapter.controller.ControlContainer; -import adapter.controller.SelectQuestionControl; -import businessrule.usecase.util.QuestionDisplayFormatter; +package infrastructure.screens; +import adapters.controllers.ControlContainer; +import adapters.controllers.SelectQuestionControl; +import infrastructure.screens.utils.UIDesign; +import infrastructure.screens.utils.UIManager; +import usecases.dto.QuestionDisplay; import javax.swing.*; import java.awt.*; @@ -10,14 +12,14 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.Map; -import static driver.screen.UIDesign.*; -import static driver.screen.UIDrawer.*; +import static infrastructure.screens.utils.UIDesign.*; +import static infrastructure.screens.utils.UIDrawer.*; /** * This class represents a JPanel for a list of questions displayed in the user interface. */ public class QuestionListUI extends UserUI implements ActionListener { - Map questionMap; + Map questionMap; static final String HOME_PAGE_BUTTON_NAME = "Home Page"; /** @@ -29,7 +31,7 @@ public class QuestionListUI extends UserUI implements ActionListener { * @param questionMap A map of question IDs to their display formatters. */ public QuestionListUI(String userName, int userId, UIManager UIManager, - Map questionMap) { + Map questionMap) { super(userName, userId, UIManager); this.questionMap = questionMap; @@ -44,7 +46,7 @@ public QuestionListUI(String userName, int userId, UIManager UIManager, questionScrollPanel.setLayout(new BoxLayout(questionScrollPanel, BoxLayout.Y_AXIS)); for (Integer questionId : questionMap.keySet()) { //read all variables from displayFormatter - QuestionDisplayFormatter question = questionMap.get(questionId); + QuestionDisplay question = questionMap.get(questionId); String title = question.getTitle(); String type = question.getType(); @@ -58,14 +60,11 @@ public QuestionListUI(String userName, int userId, UIManager UIManager, JButton questionButton = new JButton(); UIDesign.setSizeInLayout(questionButton, new Dimension(340, 60)); questionButton.add(questionPanel); - questionButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - System.out.println("Question selected"); - ControlContainer controlContainer = UIManager.getControlContainer(); - SelectQuestionControl selectQuestionControl = controlContainer.getSelectQuestionControl(); - selectQuestionControl.selectQuestion(questionId); - } + questionButton.addActionListener(e -> { + System.out.println("Question selected"); + ControlContainer controlContainer = UIManager.getControlContainer(); + SelectQuestionControl selectQuestionControl = controlContainer.getSelectQuestionControl(); + selectQuestionControl.selectQuestion(questionId); }); questionScrollPanel.add(questionButton); } diff --git a/src/main/java/driver/screen/QuestionNewUI.java b/src/main/java/infrastructure/screens/QuestionNewUI.java similarity index 70% rename from src/main/java/driver/screen/QuestionNewUI.java rename to src/main/java/infrastructure/screens/QuestionNewUI.java index 4ace4157..3dd1cd85 100644 --- a/src/main/java/driver/screen/QuestionNewUI.java +++ b/src/main/java/infrastructure/screens/QuestionNewUI.java @@ -1,19 +1,23 @@ -package driver.screen; +package infrastructure.screens; -import adapter.controller.ControlContainer; -import adapter.controller.PostControl; -import businessrule.usecase.util.PostDisplayFormatter; -import entity.ApplicationException; +import adapters.controllers.ControlContainer; +import adapters.controllers.PostControl; +import infrastructure.screens.utils.UIManager; +import usecases.dto.PostDisplay; +import entities.ApplicationException; import javax.swing.*; import java.awt.*; import java.time.LocalDate; import java.util.Map; -import static driver.screen.UIDrawer.addSpacer; +import static infrastructure.screens.utils.UIDrawer.addSpacer; +/** + * This class provides a UI for users to compose the initial content of a newly initiated question. + */ public class QuestionNewUI extends QuestionUI{ - public QuestionNewUI(String userName, int userId, UIManager UIManager, int questionId, String title, String questionType, LocalDate deadline, Map postMap) { + public QuestionNewUI(String userName, int userId, UIManager UIManager, int questionId, String title, String questionType, LocalDate deadline, Map postMap) { super(userName, userId, UIManager, questionId, title, questionType, deadline, postMap); JPanel spacer = addSpacer(20); diff --git a/src/main/java/driver/screen/QuestionOpenAttorneyUI.java b/src/main/java/infrastructure/screens/QuestionOpenAttorneyUI.java similarity index 67% rename from src/main/java/driver/screen/QuestionOpenAttorneyUI.java rename to src/main/java/infrastructure/screens/QuestionOpenAttorneyUI.java index b7d9eb87..d30c1aed 100644 --- a/src/main/java/driver/screen/QuestionOpenAttorneyUI.java +++ b/src/main/java/infrastructure/screens/QuestionOpenAttorneyUI.java @@ -1,21 +1,21 @@ -package driver.screen; +package infrastructure.screens; -import adapter.controller.ControlContainer; -import adapter.controller.PostControl; -import businessrule.usecase.util.PostDisplayFormatter; -import entity.ApplicationException; +import infrastructure.screens.utils.UIManager; +import usecases.dto.PostDisplay; import javax.swing.*; -import java.awt.*; import java.time.LocalDate; import java.util.Map; -import static driver.screen.UIDrawer.*; +import static infrastructure.screens.utils.UIDrawer.*; +/** + * This class provides a UI for attorney to post their answer for a specific question. + */ public class QuestionOpenAttorneyUI extends QuestionNewUI { public QuestionOpenAttorneyUI(String userName, int userId, UIManager UIManager, int questionId, String title, - String questionType, LocalDate deadline, Map postMap) { + String questionType, LocalDate deadline, Map postMap) { super(userName, userId, UIManager, questionId, title, questionType, deadline, postMap); //spacers diff --git a/src/main/java/driver/screen/QuestionOpenClientUI.java b/src/main/java/infrastructure/screens/QuestionOpenClientUI.java similarity index 78% rename from src/main/java/driver/screen/QuestionOpenClientUI.java rename to src/main/java/infrastructure/screens/QuestionOpenClientUI.java index 9e53d306..b12b050d 100644 --- a/src/main/java/driver/screen/QuestionOpenClientUI.java +++ b/src/main/java/infrastructure/screens/QuestionOpenClientUI.java @@ -1,21 +1,25 @@ -package driver.screen; +package infrastructure.screens; -import adapter.controller.CloseQuestionControl; -import adapter.controller.ControlContainer; -import businessrule.usecase.util.PostDisplayFormatter; -import entity.ApplicationException; +import adapters.controllers.CloseQuestionControl; +import adapters.controllers.ControlContainer; +import infrastructure.screens.utils.UIManager; +import usecases.dto.PostDisplay; +import entities.ApplicationException; import javax.swing.*; import java.awt.*; import java.time.LocalDate; import java.util.Map; -import static driver.screen.UIDrawer.*; +import static infrastructure.screens.utils.UIDrawer.*; +/** + * This class provides a UI for client to their follow-up. + */ public class QuestionOpenClientUI extends QuestionOpenAttorneyUI{ public QuestionOpenClientUI(String userName, int userId, UIManager UIManager, int questionId, String title, - String questionType, LocalDate deadline, Map postMap) { + String questionType, LocalDate deadline, Map postMap) { super(userName, userId ,UIManager,questionId, title, questionType, deadline, postMap); //The spacer diff --git a/src/main/java/driver/screen/QuestionUI.java b/src/main/java/infrastructure/screens/QuestionUI.java similarity index 93% rename from src/main/java/driver/screen/QuestionUI.java rename to src/main/java/infrastructure/screens/QuestionUI.java index 00f42d19..d0485698 100644 --- a/src/main/java/driver/screen/QuestionUI.java +++ b/src/main/java/infrastructure/screens/QuestionUI.java @@ -1,6 +1,7 @@ -package driver.screen; -import adapter.controller.ControlContainer; -import businessrule.usecase.util.PostDisplayFormatter; +package infrastructure.screens; +import adapters.controllers.ControlContainer; +import infrastructure.screens.utils.UIManager; +import usecases.dto.PostDisplay; import javax.swing.*; import javax.swing.event.DocumentEvent; @@ -15,9 +16,12 @@ import java.util.List; import java.util.Map; -import static driver.screen.UIDesign.*; -import static driver.screen.UIDrawer.*; +import static infrastructure.screens.utils.UIDesign.*; +import static infrastructure.screens.utils.UIDrawer.*; +/** + * This abstract class represents a base for all question-specific user interface. + */ public abstract class QuestionUI extends UserUI { int questionId; JPanel questionTitle = new JPanel(); @@ -35,7 +39,7 @@ public abstract class QuestionUI extends UserUI { static final String CLOSE_BUTTON_NAME = "Close Question"; public QuestionUI(String userName, int userId, UIManager UIManager, int questionId, String title, - String questionType, LocalDate deadline, Map postMap) { + String questionType, LocalDate deadline, Map postMap) { super(userName, userId, UIManager); this.questionId = questionId; @@ -66,7 +70,7 @@ public QuestionUI(String userName, int userId, UIManager UIManager, int question //Set post scroll pane JPanel postScrollPanel = new JPanel(); postScrollPanel.setLayout(new BoxLayout(postScrollPanel, BoxLayout.Y_AXIS)); - for (PostDisplayFormatter post : postMap.values()) { + for (PostDisplay post : postMap.values()) { //read all variables from displayFormatter String name = post.getName(); String postText = post.getPostText(); diff --git a/src/main/java/driver/screen/RatePanel.java b/src/main/java/infrastructure/screens/RatePanel.java similarity index 90% rename from src/main/java/driver/screen/RatePanel.java rename to src/main/java/infrastructure/screens/RatePanel.java index 438941fd..d6e2555b 100644 --- a/src/main/java/driver/screen/RatePanel.java +++ b/src/main/java/infrastructure/screens/RatePanel.java @@ -1,7 +1,8 @@ -package driver.screen; +package infrastructure.screens; -import adapter.controller.ControlContainer; -import adapter.controller.RateControl; +import adapters.controllers.ControlContainer; +import adapters.controllers.RateControl; +import infrastructure.screens.utils.UIDesign; import javax.swing.*; import java.awt.*; @@ -9,8 +10,11 @@ import java.awt.event.ActionListener; import java.util.Objects; -import static driver.screen.UIDesign.*; +import static infrastructure.screens.utils.UIDesign.*; +/** + * This class provides a UI for client to rate their experience. + */ public class RatePanel extends JPanel implements ActionListener { ControlContainer controlContainer; JFrame rateFrame; @@ -29,8 +33,6 @@ public RatePanel(ControlContainer controlContainer, JFrame rateFrame, int userId dropdownContainer.setBackground(UIDesign.whiteColor); UIDesign.setSizeInLayout(dropdownContainer, new Dimension(350, 50)); - String[] rateList = {"Satisfied", "Not satisfied"}; - UIDesign.setSizeInLayout(rate, new Dimension(250, 40)); rate.setRenderer(new MyComboBoxRenderer()); diff --git a/src/main/java/driver/screen/RegisterUI.java b/src/main/java/infrastructure/screens/RegisterUI.java similarity index 96% rename from src/main/java/driver/screen/RegisterUI.java rename to src/main/java/infrastructure/screens/RegisterUI.java index b2e7978c..0d513a46 100644 --- a/src/main/java/driver/screen/RegisterUI.java +++ b/src/main/java/infrastructure/screens/RegisterUI.java @@ -1,7 +1,8 @@ -package driver.screen; +package infrastructure.screens; -import adapter.controller.ClientRegisterControl; -import adapter.controller.ControlContainer; +import adapters.controllers.ClientRegisterControl; +import adapters.controllers.ControlContainer; +import infrastructure.screens.utils.UIManager; import javax.swing.*; import java.awt.*; @@ -9,8 +10,8 @@ import java.util.ArrayList; import java.util.List; -import static driver.screen.UIDrawer.*; -import static driver.screen.UIDesign.*; +import static infrastructure.screens.utils.UIDrawer.*; +import static infrastructure.screens.utils.UIDesign.*; /** * This class represents a JPanel for the user registration interface. diff --git a/src/main/java/businessrule/UIFactory.java b/src/main/java/infrastructure/screens/UIFactory.java similarity index 84% rename from src/main/java/businessrule/UIFactory.java rename to src/main/java/infrastructure/screens/UIFactory.java index 42dc834c..26a0e8c2 100644 --- a/src/main/java/businessrule/UIFactory.java +++ b/src/main/java/infrastructure/screens/UIFactory.java @@ -1,14 +1,17 @@ -package businessrule; - -import businessrule.responsemodel.BaseResponseModel; -import businessrule.responsemodel.TheQuestionResponseModel; -import businessrule.responsemodel.UserResponseModel; -import businessrule.responsemodel.ViewResponseModel; -import businessrule.usecase.util.PostDisplayFormatter; -import driver.screen.*; +package infrastructure.screens; + +import infrastructure.screens.utils.UIManager; +import usecases.responses.BaseResponseModel; +import usecases.responses.TheQuestionResponseModel; +import usecases.responses.UserResponseModel; +import usecases.responses.ViewResponseModel; +import usecases.dto.PostDisplay; import java.util.HashMap; import java.util.Map; +/** + * This class represents a factory that create UI based on specific needs and situations. + */ public class UIFactory { private static final String CLIENT_TYPE = "Client"; private static final String ATTORNEY_TYPE = "Attorney"; @@ -24,6 +27,14 @@ public enum UIType { QUESTION_UI } + /** + * + * @param uiType type of the target UI. + * @param uiManager UIManager that contains screens, cardlayouts, and control containers. + * @param userResponseModel a response model contains basic user information. + * @return the specific UI needed. + * @throws IllegalArgumentException when the UI type is invalid. + */ private static UserUI getUserUI(UIType uiType, UIManager uiManager, UserResponseModel userResponseModel) throws IllegalArgumentException { int userId = userResponseModel.getUserId(); String userName = userResponseModel.getUserName(); @@ -52,8 +63,8 @@ private static QuestionListUI getQuestionListUI(UIManager uiManager, ViewRespons private static QuestionUI getQuestionUI(UIManager uiManager, TheQuestionResponseModel questionResponseModel) { String userType = questionResponseModel.getUserType(); - Boolean isClose = questionResponseModel.isClose(); - Map postMap = questionResponseModel.getPostMap(); + boolean isClose = questionResponseModel.isClose(); + Map postMap = questionResponseModel.getPostMap(); if (isClose) { return new QuestionCloseUI(questionResponseModel.getUserName(), questionResponseModel.getUserId(), uiManager, questionResponseModel.getQuestionId(), questionResponseModel.getTitle(), questionResponseModel.getType(), diff --git a/src/main/java/driver/screen/UserUI.java b/src/main/java/infrastructure/screens/UserUI.java similarity index 65% rename from src/main/java/driver/screen/UserUI.java rename to src/main/java/infrastructure/screens/UserUI.java index c6f8af63..57892e69 100644 --- a/src/main/java/driver/screen/UserUI.java +++ b/src/main/java/infrastructure/screens/UserUI.java @@ -1,9 +1,14 @@ -package driver.screen; +package infrastructure.screens; + +import infrastructure.screens.utils.UIManager; import javax.swing.*; -import static driver.screen.UIDesign.*; -import static driver.screen.UIDrawer.*; +import static infrastructure.screens.utils.UIDrawer.*; + +/** + * This abstract class serve as the base for all user-specific UI. + */ public abstract class UserUI extends BaseUI{ protected String userName; protected int userId; diff --git a/src/main/java/driver/screen/WelcomeUI.java b/src/main/java/infrastructure/screens/WelcomeUI.java similarity index 92% rename from src/main/java/driver/screen/WelcomeUI.java rename to src/main/java/infrastructure/screens/WelcomeUI.java index 1b15d93d..cf18ab7d 100644 --- a/src/main/java/driver/screen/WelcomeUI.java +++ b/src/main/java/infrastructure/screens/WelcomeUI.java @@ -1,6 +1,6 @@ -package driver.screen; +package infrastructure.screens; -import adapter.controller.ControlContainer; +import infrastructure.screens.utils.UIManager; import javax.swing.*; import java.awt.*; @@ -9,8 +9,8 @@ import java.util.ArrayList; import java.util.List; -import static driver.screen.UIDesign.*; -import static driver.screen.UIDrawer.*; +import static infrastructure.screens.utils.UIDesign.*; +import static infrastructure.screens.utils.UIDrawer.*; /** * This class represents the initial screen of the application where users can choose to register or log in. diff --git a/src/main/java/driver/screen/UIDesign.java b/src/main/java/infrastructure/screens/utils/UIDesign.java similarity index 94% rename from src/main/java/driver/screen/UIDesign.java rename to src/main/java/infrastructure/screens/utils/UIDesign.java index ceb3bdb7..fbaa5fd2 100644 --- a/src/main/java/driver/screen/UIDesign.java +++ b/src/main/java/infrastructure/screens/utils/UIDesign.java @@ -1,10 +1,7 @@ -package driver.screen; +package infrastructure.screens.utils; import javax.swing.*; -import javax.swing.border.EmptyBorder; -import javax.swing.border.LineBorder; import java.awt.*; -import java.util.concurrent.Flow; /** * This class represents a consistent design settings and helper methods for UI components. diff --git a/src/main/java/driver/screen/UIDrawer.java b/src/main/java/infrastructure/screens/utils/UIDrawer.java similarity index 98% rename from src/main/java/driver/screen/UIDrawer.java rename to src/main/java/infrastructure/screens/utils/UIDrawer.java index 700187f2..d08393a9 100644 --- a/src/main/java/driver/screen/UIDrawer.java +++ b/src/main/java/infrastructure/screens/utils/UIDrawer.java @@ -1,11 +1,11 @@ -package driver.screen; +package infrastructure.screens.utils; import com.toedter.calendar.JDateChooser; import javax.swing.*; import javax.swing.border.LineBorder; import java.awt.*; -import static driver.screen.UIDesign.*; +import static infrastructure.screens.utils.UIDesign.*; import java.awt.event.ActionListener; import java.util.List; @@ -250,7 +250,7 @@ public static JPanel questionTitleDrawer(String questionType, String title){ return titlePanel; } - protected static JPanel replyAreaDrawer(JTextArea inputPostArea, String buttonName, ActionListener parent) { + public static JPanel replyAreaDrawer(JTextArea inputPostArea, String buttonName, ActionListener parent) { inputPostArea.setLineWrap(true); inputPostArea.setWrapStyleWord(true); diff --git a/src/main/java/driver/screen/UIManager.java b/src/main/java/infrastructure/screens/utils/UIManager.java similarity index 88% rename from src/main/java/driver/screen/UIManager.java rename to src/main/java/infrastructure/screens/utils/UIManager.java index f55a54a6..002ff566 100644 --- a/src/main/java/driver/screen/UIManager.java +++ b/src/main/java/infrastructure/screens/utils/UIManager.java @@ -1,6 +1,6 @@ -package driver.screen; +package infrastructure.screens.utils; -import adapter.controller.ControlContainer; +import adapters.controllers.ControlContainer; import javax.swing.*; import java.awt.*; diff --git a/src/main/java/tutorial/MainFrame.java b/src/main/java/tutorial/MainFrame.java deleted file mode 100644 index e69de29b..00000000 diff --git a/src/main/java/businessrule/usecase/util/Matching.java b/src/main/java/usecases/dto/Matching.java similarity index 95% rename from src/main/java/businessrule/usecase/util/Matching.java rename to src/main/java/usecases/dto/Matching.java index da252656..553f651c 100644 --- a/src/main/java/businessrule/usecase/util/Matching.java +++ b/src/main/java/usecases/dto/Matching.java @@ -1,4 +1,4 @@ -package businessrule.usecase.util; +package usecases.dto; /** * This class represents a matching between a question and an attorney. diff --git a/src/main/java/businessrule/usecase/util/MatchingResult.java b/src/main/java/usecases/dto/MatchingResult.java similarity index 92% rename from src/main/java/businessrule/usecase/util/MatchingResult.java rename to src/main/java/usecases/dto/MatchingResult.java index 51c1f220..b66d12a5 100644 --- a/src/main/java/businessrule/usecase/util/MatchingResult.java +++ b/src/main/java/usecases/dto/MatchingResult.java @@ -1,4 +1,4 @@ -package businessrule.usecase.util; +package usecases.dto; import java.util.List; diff --git a/src/main/java/businessrule/usecase/util/PostDisplayFormatter.java b/src/main/java/usecases/dto/PostDisplay.java similarity index 88% rename from src/main/java/businessrule/usecase/util/PostDisplayFormatter.java rename to src/main/java/usecases/dto/PostDisplay.java index e61b4dbe..95c90119 100644 --- a/src/main/java/businessrule/usecase/util/PostDisplayFormatter.java +++ b/src/main/java/usecases/dto/PostDisplay.java @@ -1,6 +1,4 @@ -package businessrule.usecase.util; - -import entity.Post; +package usecases.dto; import java.time.LocalDate; @@ -9,7 +7,7 @@ * It contains attributes such as the post text, whether it's from a client, the name of the poster, * and the creation date. */ -public class PostDisplayFormatter { +public class PostDisplay { private final String postText; private final String userType; private final String name; @@ -23,7 +21,7 @@ public class PostDisplayFormatter { * @param name The name of the poster. * @param createAt The creation date of the post. */ - public PostDisplayFormatter(String postText,String userType, String name, LocalDate createAt) { + public PostDisplay(String postText, String userType, String name, LocalDate createAt) { this.postText = postText; this.userType = userType; this.name = name; diff --git a/src/main/java/businessrule/usecase/util/QuestionDisplayFormatter.java b/src/main/java/usecases/dto/QuestionDisplay.java similarity index 89% rename from src/main/java/businessrule/usecase/util/QuestionDisplayFormatter.java rename to src/main/java/usecases/dto/QuestionDisplay.java index c8af2055..d48ba6fc 100644 --- a/src/main/java/businessrule/usecase/util/QuestionDisplayFormatter.java +++ b/src/main/java/usecases/dto/QuestionDisplay.java @@ -1,4 +1,4 @@ -package businessrule.usecase.util; +package usecases.dto; import java.time.LocalDate; @@ -6,7 +6,7 @@ * This class represents the formatted display information for a question. * It encapsulates attributes such as the question title, type, legal deadline, and whether the question is closed. */ -public class QuestionDisplayFormatter { +public class QuestionDisplay { private final String title; private final String type; private final LocalDate legalDeadline; @@ -20,7 +20,7 @@ public class QuestionDisplayFormatter { * @param legalDeadline The legal deadline for the question. * @param isClose Indicates if the question is closed. */ - public QuestionDisplayFormatter(String title, String type, LocalDate legalDeadline, boolean isClose) { + public QuestionDisplay(String title, String type, LocalDate legalDeadline, boolean isClose) { this.title = title; this.type = type; this.legalDeadline = legalDeadline; diff --git a/src/main/java/businessrule/gateway/AttorneyGateway.java b/src/main/java/usecases/gateway/AttorneyGateway.java similarity index 90% rename from src/main/java/businessrule/gateway/AttorneyGateway.java rename to src/main/java/usecases/gateway/AttorneyGateway.java index 9a3ba9e5..d8768096 100644 --- a/src/main/java/businessrule/gateway/AttorneyGateway.java +++ b/src/main/java/usecases/gateway/AttorneyGateway.java @@ -1,7 +1,7 @@ -package businessrule.gateway; +package usecases.gateway; -import entity.Attorney; -import entity.Question; +import entities.user.Attorney; +import entities.Question; /** * This interface provides methods for retrieving an attorney, clearing recommendations, and diff --git a/src/main/java/businessrule/gateway/ClientGateway.java b/src/main/java/usecases/gateway/ClientGateway.java similarity index 86% rename from src/main/java/businessrule/gateway/ClientGateway.java rename to src/main/java/usecases/gateway/ClientGateway.java index d5769efb..3376c74b 100644 --- a/src/main/java/businessrule/gateway/ClientGateway.java +++ b/src/main/java/usecases/gateway/ClientGateway.java @@ -1,6 +1,6 @@ -package businessrule.gateway; +package usecases.gateway; -import entity.Client; +import entities.user.Client; /** * This interface provides a method for retrieving a client by their ID. diff --git a/src/main/java/businessrule/gateway/GenericGateway.java b/src/main/java/usecases/gateway/GenericGateway.java similarity index 97% rename from src/main/java/businessrule/gateway/GenericGateway.java rename to src/main/java/usecases/gateway/GenericGateway.java index 75ac68df..141776c6 100644 --- a/src/main/java/businessrule/gateway/GenericGateway.java +++ b/src/main/java/usecases/gateway/GenericGateway.java @@ -1,4 +1,4 @@ -package businessrule.gateway; +package usecases.gateway; import java.util.List; diff --git a/src/main/java/businessrule/gateway/PostGateway.java b/src/main/java/usecases/gateway/PostGateway.java similarity index 87% rename from src/main/java/businessrule/gateway/PostGateway.java rename to src/main/java/usecases/gateway/PostGateway.java index acdca2d6..4a519b8a 100644 --- a/src/main/java/businessrule/gateway/PostGateway.java +++ b/src/main/java/usecases/gateway/PostGateway.java @@ -1,6 +1,6 @@ -package businessrule.gateway; +package usecases.gateway; -import entity.Post; +import entities.Post; /** * This interface provides a method for retrieving a post by its ID. diff --git a/src/main/java/businessrule/gateway/QuestionGateway.java b/src/main/java/usecases/gateway/QuestionGateway.java similarity index 97% rename from src/main/java/businessrule/gateway/QuestionGateway.java rename to src/main/java/usecases/gateway/QuestionGateway.java index 695ad162..b084866a 100644 --- a/src/main/java/businessrule/gateway/QuestionGateway.java +++ b/src/main/java/usecases/gateway/QuestionGateway.java @@ -1,7 +1,7 @@ -package businessrule.gateway; +package usecases.gateway; -import entity.Post; -import entity.Question; +import entities.Post; +import entities.Question; import java.time.LocalDate; import java.util.List; diff --git a/src/main/java/businessrule/gateway/UserGateway.java b/src/main/java/usecases/gateway/UserGateway.java similarity index 92% rename from src/main/java/businessrule/gateway/UserGateway.java rename to src/main/java/usecases/gateway/UserGateway.java index 655aa2dc..84b57da9 100644 --- a/src/main/java/businessrule/gateway/UserGateway.java +++ b/src/main/java/usecases/gateway/UserGateway.java @@ -1,7 +1,7 @@ -package businessrule.gateway; +package usecases.gateway; -import entity.Question; -import entity.User; +import entities.Question; +import entities.user.User; /** * This interface provides methods for checking if a user exists by name, updating a user's question list, diff --git a/src/main/java/businessrule/inputboundary/CloseInputBoundary.java b/src/main/java/usecases/inputboundary/CloseInputBoundary.java similarity index 79% rename from src/main/java/businessrule/inputboundary/CloseInputBoundary.java rename to src/main/java/usecases/inputboundary/CloseInputBoundary.java index 6f088ab7..ee98d492 100644 --- a/src/main/java/businessrule/inputboundary/CloseInputBoundary.java +++ b/src/main/java/usecases/inputboundary/CloseInputBoundary.java @@ -1,7 +1,7 @@ -package businessrule.inputboundary; +package usecases.inputboundary; -import businessrule.requestmodel.CloseRequestModel; -import businessrule.responsemodel.UserResponseModel; +import usecases.requests.CloseRequestModel; +import usecases.responses.UserResponseModel; /** * This interface provides a method for closing a question based on the provided close request model. diff --git a/src/main/java/businessrule/inputboundary/PostInputBoundary.java b/src/main/java/usecases/inputboundary/PostInputBoundary.java similarity index 72% rename from src/main/java/businessrule/inputboundary/PostInputBoundary.java rename to src/main/java/usecases/inputboundary/PostInputBoundary.java index e361a129..1fc4d80b 100644 --- a/src/main/java/businessrule/inputboundary/PostInputBoundary.java +++ b/src/main/java/usecases/inputboundary/PostInputBoundary.java @@ -1,8 +1,7 @@ -package businessrule.inputboundary; +package usecases.inputboundary; -import businessrule.requestmodel.PostRequestModel; -import businessrule.responsemodel.TheQuestionResponseModel; -import businessrule.responsemodel.UserResponseModel; +import usecases.requests.PostRequestModel; +import usecases.responses.TheQuestionResponseModel; /** * This interface provides a method for creating a post based on the provided post request model. diff --git a/src/main/java/businessrule/inputboundary/QuestionInputBoundary.java b/src/main/java/usecases/inputboundary/QuestionInputBoundary.java similarity index 72% rename from src/main/java/businessrule/inputboundary/QuestionInputBoundary.java rename to src/main/java/usecases/inputboundary/QuestionInputBoundary.java index 71c986c0..f7ff794c 100644 --- a/src/main/java/businessrule/inputboundary/QuestionInputBoundary.java +++ b/src/main/java/usecases/inputboundary/QuestionInputBoundary.java @@ -1,8 +1,7 @@ -package businessrule.inputboundary; +package usecases.inputboundary; -import businessrule.responsemodel.TheQuestionResponseModel; -import businessrule.requestmodel.QuestionRequestModel; -import businessrule.responsemodel.UserResponseModel; +import usecases.responses.TheQuestionResponseModel; +import usecases.requests.QuestionRequestModel; /** * This interface provides a method for creating a question based on the provided question request model. diff --git a/src/main/java/businessrule/inputboundary/RateInputBoundary.java b/src/main/java/usecases/inputboundary/RateInputBoundary.java similarity index 79% rename from src/main/java/businessrule/inputboundary/RateInputBoundary.java rename to src/main/java/usecases/inputboundary/RateInputBoundary.java index 649a645e..1b6ee217 100644 --- a/src/main/java/businessrule/inputboundary/RateInputBoundary.java +++ b/src/main/java/usecases/inputboundary/RateInputBoundary.java @@ -1,7 +1,7 @@ -package businessrule.inputboundary; +package usecases.inputboundary; -import businessrule.requestmodel.RateRequestModel; -import businessrule.responsemodel.UserResponseModel; +import usecases.requests.RateRequestModel; +import usecases.responses.UserResponseModel; /** * This interface provides a method for rating an answer based on the provided rate request model. diff --git a/src/main/java/businessrule/inputboundary/SelectInputBoundary.java b/src/main/java/usecases/inputboundary/SelectInputBoundary.java similarity index 72% rename from src/main/java/businessrule/inputboundary/SelectInputBoundary.java rename to src/main/java/usecases/inputboundary/SelectInputBoundary.java index 018e6fea..88ef32d6 100644 --- a/src/main/java/businessrule/inputboundary/SelectInputBoundary.java +++ b/src/main/java/usecases/inputboundary/SelectInputBoundary.java @@ -1,8 +1,7 @@ -package businessrule.inputboundary; +package usecases.inputboundary; -import businessrule.responsemodel.TheQuestionResponseModel; -import businessrule.requestmodel.SelectRequestModel; -import businessrule.responsemodel.UserResponseModel; +import usecases.responses.TheQuestionResponseModel; +import usecases.requests.SelectRequestModel; /** * This interface provides a method for selecting a question based on the provided select request model. diff --git a/src/main/java/businessrule/inputboundary/UserLoginInputBoundary.java b/src/main/java/usecases/inputboundary/UserLoginInputBoundary.java similarity index 78% rename from src/main/java/businessrule/inputboundary/UserLoginInputBoundary.java rename to src/main/java/usecases/inputboundary/UserLoginInputBoundary.java index 8f8b0a9c..533480cb 100644 --- a/src/main/java/businessrule/inputboundary/UserLoginInputBoundary.java +++ b/src/main/java/usecases/inputboundary/UserLoginInputBoundary.java @@ -1,7 +1,7 @@ -package businessrule.inputboundary; +package usecases.inputboundary; -import businessrule.requestmodel.UserLoginRequestModel; -import businessrule.responsemodel.UserResponseModel; +import usecases.requests.UserLoginRequestModel; +import usecases.responses.UserResponseModel; /** * This interface provides a method for authenticating user credentials based on the provided login request model. diff --git a/src/main/java/businessrule/inputboundary/UserRegisterInputBoundary.java b/src/main/java/usecases/inputboundary/UserRegisterInputBoundary.java similarity index 69% rename from src/main/java/businessrule/inputboundary/UserRegisterInputBoundary.java rename to src/main/java/usecases/inputboundary/UserRegisterInputBoundary.java index 466158d0..9b94cb8c 100644 --- a/src/main/java/businessrule/inputboundary/UserRegisterInputBoundary.java +++ b/src/main/java/usecases/inputboundary/UserRegisterInputBoundary.java @@ -1,8 +1,7 @@ -package businessrule.inputboundary; +package usecases.inputboundary; -import businessrule.requestmodel.RegistrationData; -import businessrule.responsemodel.BaseResponseModel; -import businessrule.responsemodel.UserResponseModel; +import usecases.requests.RegistrationData; +import usecases.responses.BaseResponseModel; /** * This interface represents the input boundary for user registration use case. diff --git a/src/main/java/businessrule/inputboundary/ViewInputBoundary.java b/src/main/java/usecases/inputboundary/ViewInputBoundary.java similarity index 71% rename from src/main/java/businessrule/inputboundary/ViewInputBoundary.java rename to src/main/java/usecases/inputboundary/ViewInputBoundary.java index 8c30fcb4..2515aa0f 100644 --- a/src/main/java/businessrule/inputboundary/ViewInputBoundary.java +++ b/src/main/java/usecases/inputboundary/ViewInputBoundary.java @@ -1,7 +1,6 @@ -package businessrule.inputboundary; +package usecases.inputboundary; -import businessrule.responsemodel.UserResponseModel; -import businessrule.responsemodel.ViewResponseModel; +import usecases.responses.ViewResponseModel; /** * This interface provides a method for viewing a question based on the provided view request model. diff --git a/src/main/java/businessrule/usecase/AskQuestionInteractor.java b/src/main/java/usecases/interactors/AskQuestionInteractor.java similarity index 81% rename from src/main/java/businessrule/usecase/AskQuestionInteractor.java rename to src/main/java/usecases/interactors/AskQuestionInteractor.java index e8481994..911943aa 100644 --- a/src/main/java/businessrule/usecase/AskQuestionInteractor.java +++ b/src/main/java/usecases/interactors/AskQuestionInteractor.java @@ -1,20 +1,19 @@ -package businessrule.usecase; +package usecases.interactors; -import businessrule.SessionManager; -import businessrule.UserSession; -import businessrule.outputboundary.TheQuestionOutputBoundary; -import businessrule.outputboundary.UserOutputBoundary; -import businessrule.responsemodel.TheQuestionResponseModel; -import businessrule.responsemodel.UserResponseModel; -import businessrule.usecase.util.BuilderService; -import businessrule.usecase.util.PostDisplayFormatter; -import businessrule.usecase.util.RandomNumberGenerator; -import entity.*; -import businessrule.inputboundary.QuestionInputBoundary; -import businessrule.requestmodel.QuestionRequestModel; -import businessrule.gateway.ClientGateway; -import businessrule.gateway.QuestionGateway; -import entity.factory.QuestionFactory; +import usecases.session.SessionManager; +import usecases.session.UserSession; +import usecases.outputboundary.TheQuestionOutputBoundary; +import usecases.responses.TheQuestionResponseModel; +import usecases.responses.UserResponseModel; +import usecases.utils.BuilderService; +import usecases.dto.PostDisplay; +import usecases.utils.RandomNumberGenerator; +import entities.*; +import usecases.inputboundary.QuestionInputBoundary; +import usecases.requests.QuestionRequestModel; +import usecases.gateway.ClientGateway; +import usecases.gateway.QuestionGateway; +import entities.factories.QuestionFactory; import java.time.LocalDate; import java.util.HashMap; import java.util.Map; @@ -22,7 +21,6 @@ /** * This class represents the interactor responsible for asking a new question. - * * This interactor validates input, generates a unique question ID, creates a question entity, * updates relevant gateways, and constructs the response model. */ @@ -37,7 +35,7 @@ public class AskQuestionInteractor implements QuestionInputBoundary { * Constructor for AskQuestionInteractor. * * @param questionGateway The gateway for managing question entities. - * @param theQuestionOutputBoundary The output boundary for preparing question response models. + * @param outputBoundary The output boundary for preparing question response models. * @param questionFactory The factory for creating question entities. * @param clientGateway The gateway for managing client entities. */ @@ -69,7 +67,7 @@ public TheQuestionResponseModel createQuestion(QuestionRequestModel questionRequ Question question = createQuestionEntity(questionRequestModel, askedByClient); // construct response model - Map postMap = new HashMap<>(); + Map postMap = new HashMap<>(); return outputBoundary.prepareSuccess(BuilderService.getInstance().constructTheQuestionResponse(question, response, postMap)); } diff --git a/src/main/java/businessrule/usecase/AttorneyRecommendInteractor.java b/src/main/java/usecases/interactors/AttorneyRecommendInteractor.java similarity index 68% rename from src/main/java/businessrule/usecase/AttorneyRecommendInteractor.java rename to src/main/java/usecases/interactors/AttorneyRecommendInteractor.java index d61c8e08..1d6692bb 100644 --- a/src/main/java/businessrule/usecase/AttorneyRecommendInteractor.java +++ b/src/main/java/usecases/interactors/AttorneyRecommendInteractor.java @@ -1,18 +1,15 @@ -package businessrule.usecase; +package usecases.interactors; -import businessrule.gateway.AttorneyGateway; -import businessrule.gateway.QuestionGateway; -import businessrule.outputboundary.TheQuestionOutputBoundary; -import businessrule.outputboundary.UserOutputBoundary; -import businessrule.outputboundary.ViewOutputBoundary; -import entity.Attorney; -import entity.Question; -import entity.User; +import usecases.gateway.AttorneyGateway; +import usecases.gateway.QuestionGateway; +import usecases.outputboundary.ViewOutputBoundary; +import entities.user.Attorney; +import entities.Question; +import entities.user.User; import java.util.List; /** * This class represents the interactor responsible for recommending questions to an attorney. - * * This interactor fetches recommended questions for an attorney based on their profile and preferences. */ public class AttorneyRecommendInteractor extends ViewQuestionInteractorBase { @@ -21,7 +18,7 @@ public class AttorneyRecommendInteractor extends ViewQuestionInteractorBase { /** * Constructor for AttorneyRecommendInteractor. * - * @param viewOutputBoundary The output boundary for preparing view response models. + * @param outputBoundary The output boundary for preparing view response models. * @param questionGateway The gateway for managing question entities. * @param attorneyGateway The gateway for managing attorney entities. */ @@ -33,7 +30,6 @@ public AttorneyRecommendInteractor(ViewOutputBoundary outputBoundary, QuestionGa /** * Fetch recommended questions for an attorney. * - * @param viewRequestModel The request model containing the attorney's user ID. * @return The list of recommended questions. */ @Override @@ -45,7 +41,6 @@ protected List fetchQuestions(int userId) { /** * Fetch the attorney based on the provided user ID. * - * @param viewRequestModel The request model containing the attorney's user ID. * @return The fetched attorney entity. */ @Override diff --git a/src/main/java/businessrule/usecase/BrowseQuestionInteractor.java b/src/main/java/usecases/interactors/BrowseQuestionInteractor.java similarity index 80% rename from src/main/java/businessrule/usecase/BrowseQuestionInteractor.java rename to src/main/java/usecases/interactors/BrowseQuestionInteractor.java index f377a924..0e042024 100644 --- a/src/main/java/businessrule/usecase/BrowseQuestionInteractor.java +++ b/src/main/java/usecases/interactors/BrowseQuestionInteractor.java @@ -1,11 +1,10 @@ -package businessrule.usecase; +package usecases.interactors; -import businessrule.gateway.AttorneyGateway; -import businessrule.outputboundary.TheQuestionOutputBoundary; -import businessrule.gateway.QuestionGateway; -import businessrule.outputboundary.ViewOutputBoundary; -import entity.Question; -import entity.User; +import usecases.gateway.AttorneyGateway; +import usecases.gateway.QuestionGateway; +import usecases.outputboundary.ViewOutputBoundary; +import entities.Question; +import entities.user.User; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -13,7 +12,6 @@ /** * This class represents the interactor responsible for browsing available questions. - * * This interactor fetches a list of available questions that have not been taken and are not closed. */ public class BrowseQuestionInteractor extends ViewQuestionInteractorBase { @@ -22,7 +20,7 @@ public class BrowseQuestionInteractor extends ViewQuestionInteractorBase { /** * Constructor for BrowseQuestionInteractor. * - * @param viewOutputBoundary The output boundary for preparing view response models. + * @param outputBoundary The output boundary for preparing view response models. * @param questionGateway The gateway for managing question entities. * @param attorneyGateway The gateway for managing attorney entities. */ @@ -34,7 +32,6 @@ public BrowseQuestionInteractor(ViewOutputBoundary outputBoundary, QuestionGatew /** * Fetch available questions that have not been taken and are not closed. * - * @param userId * @return The list of available questions. */ @Override @@ -50,7 +47,6 @@ protected List fetchQuestions(int userId) { /** * Fetch the user based on the provided user ID. * - * @param userId * @return The fetched user entity. */ @Override diff --git a/src/main/java/businessrule/usecase/ClientRegisterInteractor.java b/src/main/java/usecases/interactors/ClientRegisterInteractor.java similarity index 84% rename from src/main/java/businessrule/usecase/ClientRegisterInteractor.java rename to src/main/java/usecases/interactors/ClientRegisterInteractor.java index b9a47b95..12775cbf 100644 --- a/src/main/java/businessrule/usecase/ClientRegisterInteractor.java +++ b/src/main/java/usecases/interactors/ClientRegisterInteractor.java @@ -1,14 +1,14 @@ -package businessrule.usecase; +package usecases.interactors; -import businessrule.gateway.ClientGateway; -import businessrule.outputboundary.BaseOutputBoundary; -import businessrule.responsemodel.BaseResponseModel; -import entity.ApplicationException; -import entity.Client; -import entity.factory.ClientFactory; -import businessrule.usecase.util.CredentialChecker; -import businessrule.requestmodel.RegistrationData; +import usecases.gateway.ClientGateway; +import usecases.outputboundary.BaseOutputBoundary; +import usecases.responses.BaseResponseModel; +import entities.ApplicationException; +import entities.user.Client; +import entities.factories.ClientFactory; +import usecases.utils.CredentialChecker; +import usecases.requests.RegistrationData; /** * This class represents interactor responsible for client registration use case. @@ -18,8 +18,8 @@ public class ClientRegisterInteractor extends UserRegisterInteractor postMap = postMapConstructor.constructPostMap(question); + Map postMap = postMapConstructor.constructPostMap(question); TheQuestionResponseModel theQuestionResponseModel = BuilderService.getInstance().constructTheQuestionResponse(question, response, postMap); return outputBoundary.prepareSuccess(theQuestionResponseModel); } diff --git a/src/main/java/businessrule/usecase/SelectQuestionInteractor.java b/src/main/java/usecases/interactors/SelectQuestionInteractor.java similarity index 75% rename from src/main/java/businessrule/usecase/SelectQuestionInteractor.java rename to src/main/java/usecases/interactors/SelectQuestionInteractor.java index 58286992..c81a3728 100644 --- a/src/main/java/businessrule/usecase/SelectQuestionInteractor.java +++ b/src/main/java/usecases/interactors/SelectQuestionInteractor.java @@ -1,25 +1,24 @@ -package businessrule.usecase; +package usecases.interactors; -import businessrule.SessionManager; -import businessrule.UserSession; -import businessrule.inputboundary.SelectInputBoundary; -import businessrule.outputboundary.TheQuestionOutputBoundary; -import businessrule.requestmodel.SelectRequestModel; -import businessrule.responsemodel.UserResponseModel; -import businessrule.usecase.util.BuilderService; -import businessrule.usecase.util.PostDisplayFormatter; -import businessrule.usecase.util.PostMapConstructor; -import entity.Question; -import businessrule.gateway.QuestionGateway; -import businessrule.responsemodel.TheQuestionResponseModel; -import entity.User; -import businessrule.gateway.UserGateway; -import businessrule.gateway.UserGatewayFactory; +import usecases.session.SessionManager; +import usecases.session.UserSession; +import usecases.inputboundary.SelectInputBoundary; +import usecases.outputboundary.TheQuestionOutputBoundary; +import usecases.requests.SelectRequestModel; +import usecases.responses.UserResponseModel; +import usecases.utils.BuilderService; +import usecases.dto.PostDisplay; +import usecases.utils.PostMapConstructor; +import entities.Question; +import usecases.gateway.QuestionGateway; +import usecases.responses.TheQuestionResponseModel; +import entities.user.User; +import usecases.gateway.UserGateway; +import infrastructure.database.UserGatewayFactory; import java.util.Map; /** * This class represents the interactor responsible for selecting a question. - * * This interactor handles the process of selecting a question based on user input and * preparing and formatting the response model. */ @@ -65,7 +64,7 @@ public TheQuestionResponseModel selectQuestion(SelectRequestModel selectRequestM boolean isQuestionSelectable = user.isQuestionSelectable(question); if (isQuestionSelectable) { PostMapConstructor postMapConstructor = new PostMapConstructor(userGatewayFactory); - Map postMap = postMapConstructor.constructPostMap(question); + Map postMap = postMapConstructor.constructPostMap(question); TheQuestionResponseModel theQuestionResponseModel = BuilderService.getInstance().constructTheQuestionResponse(question, response, postMap); return outputBoundary.prepareSuccess(theQuestionResponseModel); } else { diff --git a/src/main/java/businessrule/usecase/UserLoginInteractor.java b/src/main/java/usecases/interactors/UserLoginInteractor.java similarity index 75% rename from src/main/java/businessrule/usecase/UserLoginInteractor.java rename to src/main/java/usecases/interactors/UserLoginInteractor.java index eaab85cd..ebb4e337 100644 --- a/src/main/java/businessrule/usecase/UserLoginInteractor.java +++ b/src/main/java/usecases/interactors/UserLoginInteractor.java @@ -1,25 +1,23 @@ -package businessrule.usecase; +package usecases.interactors; + +import usecases.session.SessionManager; +import usecases.session.UserSession; +import infrastructure.database.UserGatewayFactory; +import usecases.inputboundary.UserLoginInputBoundary; +import usecases.outputboundary.UserOutputBoundary; +import usecases.requests.UserLoginRequestModel; +import usecases.gateway.UserGateway; +import usecases.responses.UserResponseModel; +import usecases.utils.BuilderService; +import usecases.dto.QuestionDisplay; +import usecases.utils.QuestionMapConstructor; +import entities.user.User; +import entities.ApplicationException; -import businessrule.SessionManager; -import businessrule.UserSession; -import businessrule.gateway.UserGatewayFactory; -import businessrule.inputboundary.UserLoginInputBoundary; -import businessrule.outputboundary.UserOutputBoundary; -import businessrule.requestmodel.UserLoginRequestModel; -import businessrule.gateway.UserGateway; -import businessrule.responsemodel.UserResponseModel; -import businessrule.responsemodel.ViewResponseModel; -import businessrule.usecase.util.BuilderService; -import businessrule.usecase.util.QuestionDisplayFormatter; -import businessrule.usecase.util.QuestionMapConstructor; -import entity.User; -import entity.ApplicationException; -import javax.swing.text.View; import java.util.Map; /** * This class represents the interactor responsible for handling user login. - * * This interactor handles the process of authenticating user login credentials,retrieving user information, * and preparing the appropriate response model. */ @@ -59,7 +57,7 @@ public UserResponseModel login(UserLoginRequestModel requestModel) { setUserSession(responseModel); - Map questionMap = new QuestionMapConstructor().constructQuestionMap(user.getQuestionsList()); + Map questionMap = new QuestionMapConstructor().constructQuestionMap(user.getQuestionsList()); BuilderService.getInstance().constructViewResponse(responseModel, questionMap); return outputBoundary.prepareSuccess(responseModel); } diff --git a/src/main/java/businessrule/usecase/UserRegisterInteractor.java b/src/main/java/usecases/interactors/UserRegisterInteractor.java similarity index 80% rename from src/main/java/businessrule/usecase/UserRegisterInteractor.java rename to src/main/java/usecases/interactors/UserRegisterInteractor.java index 8720c402..c7792c69 100644 --- a/src/main/java/businessrule/usecase/UserRegisterInteractor.java +++ b/src/main/java/usecases/interactors/UserRegisterInteractor.java @@ -1,13 +1,13 @@ -package businessrule.usecase; +package usecases.interactors; -import businessrule.gateway.UserGateway; -import businessrule.inputboundary.UserRegisterInputBoundary; -import businessrule.outputboundary.BaseOutputBoundary; -import businessrule.responsemodel.BaseResponseModel; -import businessrule.usecase.util.RandomNumberGenerator; -import entity.User; -import businessrule.requestmodel.RegistrationData; -import entity.factory.UserFactory; +import usecases.gateway.UserGateway; +import usecases.inputboundary.UserRegisterInputBoundary; +import usecases.outputboundary.BaseOutputBoundary; +import usecases.responses.BaseResponseModel; +import usecases.utils.RandomNumberGenerator; +import entities.user.User; +import usecases.requests.RegistrationData; +import entities.factories.UserFactory; /** * This class represents the user registration interactors. diff --git a/src/main/java/businessrule/usecase/ViewQuestionInteractor.java b/src/main/java/usecases/interactors/ViewQuestionInteractor.java similarity index 76% rename from src/main/java/businessrule/usecase/ViewQuestionInteractor.java rename to src/main/java/usecases/interactors/ViewQuestionInteractor.java index 164cff22..c905a779 100644 --- a/src/main/java/businessrule/usecase/ViewQuestionInteractor.java +++ b/src/main/java/usecases/interactors/ViewQuestionInteractor.java @@ -1,18 +1,16 @@ -package businessrule.usecase; +package usecases.interactors; -import businessrule.gateway.QuestionGateway; -import businessrule.gateway.UserGateway; -import businessrule.gateway.UserGatewayFactory; -import businessrule.outputboundary.TheQuestionOutputBoundary; -import businessrule.outputboundary.ViewOutputBoundary; -import entity.Question; -import entity.User; +import usecases.gateway.QuestionGateway; +import usecases.gateway.UserGateway; +import infrastructure.database.UserGatewayFactory; +import usecases.outputboundary.ViewOutputBoundary; +import entities.Question; +import entities.user.User; import java.util.List; /** * This class represents the interactor responsible for viewing questions. - * * This interactor handles the process of fetching and displaying questions based on user input * and preparing the appropriate response model. */ @@ -34,7 +32,6 @@ public ViewQuestionInteractor(ViewOutputBoundary outputBoundary, QuestionGateway /** * Fetch questions for the user. * - * @param viewRequestModel The request model containing user details. * @return The list of questions for the user. */ @Override @@ -46,7 +43,6 @@ protected List fetchQuestions(int userId) { /** * Fetch the user based on the request model. * - * @param viewRequestModel The request model containing user details. * @return The user corresponding to the request. */ @Override diff --git a/src/main/java/businessrule/usecase/ViewQuestionInteractorBase.java b/src/main/java/usecases/interactors/ViewQuestionInteractorBase.java similarity index 63% rename from src/main/java/businessrule/usecase/ViewQuestionInteractorBase.java rename to src/main/java/usecases/interactors/ViewQuestionInteractorBase.java index e590783a..5a838af8 100644 --- a/src/main/java/businessrule/usecase/ViewQuestionInteractorBase.java +++ b/src/main/java/usecases/interactors/ViewQuestionInteractorBase.java @@ -1,21 +1,18 @@ -package businessrule.usecase; +package usecases.interactors; -import businessrule.SessionManager; -import businessrule.UserSession; -import businessrule.gateway.QuestionGateway; -import businessrule.inputboundary.ViewInputBoundary; -import businessrule.outputboundary.TheQuestionOutputBoundary; -import businessrule.outputboundary.UserOutputBoundary; -import businessrule.outputboundary.ViewOutputBoundary; -import businessrule.responsemodel.UserResponseModel; -import businessrule.responsemodel.ViewResponseModel; -import businessrule.usecase.util.BuilderService; -import businessrule.usecase.util.QuestionDisplayFormatter; -import businessrule.usecase.util.QuestionMapConstructor; -import entity.Question; -import entity.User; +import usecases.session.SessionManager; +import usecases.session.UserSession; +import usecases.gateway.QuestionGateway; +import usecases.inputboundary.ViewInputBoundary; +import usecases.outputboundary.ViewOutputBoundary; +import usecases.responses.UserResponseModel; +import usecases.responses.ViewResponseModel; +import usecases.utils.BuilderService; +import usecases.dto.QuestionDisplay; +import usecases.utils.QuestionMapConstructor; +import entities.Question; +import entities.user.User; -import javax.swing.text.View; import java.util.List; import java.util.Map; @@ -29,7 +26,7 @@ public abstract class ViewQuestionInteractorBase implements ViewInputBoundary { /** * Constructs a ViewQuestionInteractorBase instance. * - * @param putputBoundary The output boundary for communicating results. + * @param outputBoundary The output boundary for communicating results. * @param questionGateway The gateway for accessing question data. */ public ViewQuestionInteractorBase(ViewOutputBoundary outputBoundary, QuestionGateway questionGateway) { @@ -46,17 +43,15 @@ public ViewResponseModel viewQuestion() { // strategy List questionList = fetchQuestions(userId); - User user = fetchUser(userId); QuestionMapConstructor questionMapConstructor = new QuestionMapConstructor(); - Map questionMap = questionMapConstructor.constructQuestionMap(questionList); + Map questionMap = questionMapConstructor.constructQuestionMap(questionList); return outputBoundary.prepareSuccess(BuilderService.getInstance().constructViewResponse(response, questionMap)); } /** * Fetches a list of questions based on the provided view request model. * - * @param userId * @return A list of questions based on the provided criteria. */ protected abstract List fetchQuestions(int userId); @@ -64,7 +59,6 @@ public ViewResponseModel viewQuestion() { /** * Fetches user information based on the provided view request model. * - * @param userId * @return The user associated with the provided criteria. */ protected abstract User fetchUser(int userId); diff --git a/src/main/java/businessrule/outputboundary/BaseOutputBoundary.java b/src/main/java/usecases/outputboundary/BaseOutputBoundary.java similarity index 50% rename from src/main/java/businessrule/outputboundary/BaseOutputBoundary.java rename to src/main/java/usecases/outputboundary/BaseOutputBoundary.java index 5ed70001..e510601a 100644 --- a/src/main/java/businessrule/outputboundary/BaseOutputBoundary.java +++ b/src/main/java/usecases/outputboundary/BaseOutputBoundary.java @@ -1,7 +1,6 @@ -package businessrule.outputboundary; +package usecases.outputboundary; -import adapter.controller.ControlContainer; -import businessrule.responsemodel.BaseResponseModel; +import usecases.responses.BaseResponseModel; public interface BaseOutputBoundary { BaseResponseModel prepareSuccess(String msg); diff --git a/src/main/java/businessrule/outputboundary/TheQuestionOutputBoundary.java b/src/main/java/usecases/outputboundary/TheQuestionOutputBoundary.java similarity index 79% rename from src/main/java/businessrule/outputboundary/TheQuestionOutputBoundary.java rename to src/main/java/usecases/outputboundary/TheQuestionOutputBoundary.java index e973602c..832df65e 100644 --- a/src/main/java/businessrule/outputboundary/TheQuestionOutputBoundary.java +++ b/src/main/java/usecases/outputboundary/TheQuestionOutputBoundary.java @@ -1,8 +1,6 @@ -package businessrule.outputboundary; +package usecases.outputboundary; -import adapter.controller.ControlContainer; -import businessrule.responsemodel.TheQuestionResponseModel; -import businessrule.responsemodel.UserResponseModel; +import usecases.responses.TheQuestionResponseModel; /** * This interface provides methods for setting the control container, preparing failure responses, diff --git a/src/main/java/businessrule/outputboundary/UserOutputBoundary.java b/src/main/java/usecases/outputboundary/UserOutputBoundary.java similarity index 53% rename from src/main/java/businessrule/outputboundary/UserOutputBoundary.java rename to src/main/java/usecases/outputboundary/UserOutputBoundary.java index d667397e..d28ed449 100644 --- a/src/main/java/businessrule/outputboundary/UserOutputBoundary.java +++ b/src/main/java/usecases/outputboundary/UserOutputBoundary.java @@ -1,7 +1,6 @@ -package businessrule.outputboundary; +package usecases.outputboundary; -import adapter.controller.ControlContainer; -import businessrule.responsemodel.UserResponseModel; +import usecases.responses.UserResponseModel; public interface UserOutputBoundary { UserResponseModel prepareFail(String msg); diff --git a/src/main/java/businessrule/outputboundary/ViewOutputBoundary.java b/src/main/java/usecases/outputboundary/ViewOutputBoundary.java similarity index 77% rename from src/main/java/businessrule/outputboundary/ViewOutputBoundary.java rename to src/main/java/usecases/outputboundary/ViewOutputBoundary.java index 02829e18..3b099a46 100644 --- a/src/main/java/businessrule/outputboundary/ViewOutputBoundary.java +++ b/src/main/java/usecases/outputboundary/ViewOutputBoundary.java @@ -1,9 +1,6 @@ -package businessrule.outputboundary; +package usecases.outputboundary; -import adapter.controller.ControlContainer; -import businessrule.responsemodel.UserResponseModel; -import businessrule.responsemodel.ViewResponseModel; -import entity.User; +import usecases.responses.ViewResponseModel; /** * This interface provides methods for setting the control container, preparing failure responses, diff --git a/src/main/java/businessrule/requestmodel/CloseRequestModel.java b/src/main/java/usecases/requests/CloseRequestModel.java similarity index 94% rename from src/main/java/businessrule/requestmodel/CloseRequestModel.java rename to src/main/java/usecases/requests/CloseRequestModel.java index c6ef3395..29d67d89 100644 --- a/src/main/java/businessrule/requestmodel/CloseRequestModel.java +++ b/src/main/java/usecases/requests/CloseRequestModel.java @@ -1,4 +1,4 @@ -package businessrule.requestmodel; +package usecases.requests; /** * This class represents a request model to close a question made by a client. diff --git a/src/main/java/businessrule/requestmodel/PostRequestModel.java b/src/main/java/usecases/requests/PostRequestModel.java similarity index 96% rename from src/main/java/businessrule/requestmodel/PostRequestModel.java rename to src/main/java/usecases/requests/PostRequestModel.java index 0698cb0c..43793b26 100644 --- a/src/main/java/businessrule/requestmodel/PostRequestModel.java +++ b/src/main/java/usecases/requests/PostRequestModel.java @@ -1,4 +1,4 @@ -package businessrule.requestmodel; +package usecases.requests; /** * This class represents a post request model for creating a new post. diff --git a/src/main/java/businessrule/requestmodel/QuestionRequestModel.java b/src/main/java/usecases/requests/QuestionRequestModel.java similarity index 97% rename from src/main/java/businessrule/requestmodel/QuestionRequestModel.java rename to src/main/java/usecases/requests/QuestionRequestModel.java index 71195e3c..561bf9ca 100644 --- a/src/main/java/businessrule/requestmodel/QuestionRequestModel.java +++ b/src/main/java/usecases/requests/QuestionRequestModel.java @@ -1,4 +1,4 @@ -package businessrule.requestmodel; +package usecases.requests; import java.time.LocalDate; diff --git a/src/main/java/businessrule/requestmodel/RateRequestModel.java b/src/main/java/usecases/requests/RateRequestModel.java similarity index 95% rename from src/main/java/businessrule/requestmodel/RateRequestModel.java rename to src/main/java/usecases/requests/RateRequestModel.java index b66f9b18..649118a6 100644 --- a/src/main/java/businessrule/requestmodel/RateRequestModel.java +++ b/src/main/java/usecases/requests/RateRequestModel.java @@ -1,4 +1,4 @@ -package businessrule.requestmodel; +package usecases.requests; /** * This class represents a request model for rating an answer. diff --git a/src/main/java/businessrule/requestmodel/RegistrationData.java b/src/main/java/usecases/requests/RegistrationData.java similarity index 98% rename from src/main/java/businessrule/requestmodel/RegistrationData.java rename to src/main/java/usecases/requests/RegistrationData.java index 02b77dbf..1bbec0c5 100644 --- a/src/main/java/businessrule/requestmodel/RegistrationData.java +++ b/src/main/java/usecases/requests/RegistrationData.java @@ -1,4 +1,4 @@ -package businessrule.requestmodel; +package usecases.requests; import java.util.Set; diff --git a/src/main/java/businessrule/requestmodel/SelectRequestModel.java b/src/main/java/usecases/requests/SelectRequestModel.java similarity index 95% rename from src/main/java/businessrule/requestmodel/SelectRequestModel.java rename to src/main/java/usecases/requests/SelectRequestModel.java index 75382da8..c88027b7 100644 --- a/src/main/java/businessrule/requestmodel/SelectRequestModel.java +++ b/src/main/java/usecases/requests/SelectRequestModel.java @@ -1,4 +1,4 @@ -package businessrule.requestmodel; +package usecases.requests; /** * This class represents a request model for selecting a question. diff --git a/src/main/java/businessrule/requestmodel/UserLoginRequestModel.java b/src/main/java/usecases/requests/UserLoginRequestModel.java similarity index 96% rename from src/main/java/businessrule/requestmodel/UserLoginRequestModel.java rename to src/main/java/usecases/requests/UserLoginRequestModel.java index 3f2b2102..cfad5a60 100644 --- a/src/main/java/businessrule/requestmodel/UserLoginRequestModel.java +++ b/src/main/java/usecases/requests/UserLoginRequestModel.java @@ -1,4 +1,4 @@ -package businessrule.requestmodel; +package usecases.requests; /** * This class represents a user login request model. diff --git a/src/main/java/businessrule/responsemodel/BaseResponseModel.java b/src/main/java/usecases/responses/BaseResponseModel.java similarity index 66% rename from src/main/java/businessrule/responsemodel/BaseResponseModel.java rename to src/main/java/usecases/responses/BaseResponseModel.java index 420ed2d8..80934674 100644 --- a/src/main/java/businessrule/responsemodel/BaseResponseModel.java +++ b/src/main/java/usecases/responses/BaseResponseModel.java @@ -1,7 +1,7 @@ -package businessrule.responsemodel; +package usecases.responses; /** - * This class represents a simple and convenient an empty response to the client. + * This class represents a simple and convenient an empty response. */ public class BaseResponseModel { diff --git a/src/main/java/businessrule/responsemodel/TheQuestionResponseModel.java b/src/main/java/usecases/responses/TheQuestionResponseModel.java similarity index 82% rename from src/main/java/businessrule/responsemodel/TheQuestionResponseModel.java rename to src/main/java/usecases/responses/TheQuestionResponseModel.java index 8ee8c83d..fa06fcdb 100644 --- a/src/main/java/businessrule/responsemodel/TheQuestionResponseModel.java +++ b/src/main/java/usecases/responses/TheQuestionResponseModel.java @@ -1,11 +1,11 @@ -package businessrule.responsemodel; +package usecases.responses; -import businessrule.usecase.util.PostDisplayFormatter; +import usecases.dto.PostDisplay; import java.time.LocalDate; import java.util.Map; /** - * This class represents a question with detailed informatio. + * This class represents a question with detailed information. * It is including its user, title, type, deadline, closure status, and associated posts. */ public class TheQuestionResponseModel extends UserResponseModel{ @@ -14,7 +14,7 @@ public class TheQuestionResponseModel extends UserResponseModel{ private final String type; private final LocalDate deadline; private final boolean isClose; - private final Map postMap; + private final Map postMap; private TheQuestionResponseModel(Builder builder) { super(builder.userId, builder.userName, builder.userType); @@ -26,7 +26,7 @@ private TheQuestionResponseModel(Builder builder) { this.postMap = builder.postMap; } - public TheQuestionResponseModel(int userId, String userName, String userType, int questionId, String title, String type, LocalDate deadline, boolean isClose, Map postMap) { + public TheQuestionResponseModel(int userId, String userName, String userType, int questionId, String title, String type, LocalDate deadline, boolean isClose, Map postMap) { super(userId, userName, userType); this.questionId = questionId; this.title = title; @@ -37,15 +37,15 @@ public TheQuestionResponseModel(int userId, String userName, String userType, in } public static class Builder { - private int userId; - private String userName; - private String userType; + private final int userId; + private final String userName; + private final String userType; private int questionId; private String questionTitle; private String questionType; private LocalDate deadline; private boolean isClose; - private Map postMap; + private Map postMap; public Builder(UserResponseModel userModel) { this.userId = userModel.getUserId(); @@ -78,7 +78,7 @@ public Builder isClose(boolean isClose) { return this; } - public Builder postMap(Map postMap) { + public Builder postMap(Map postMap) { this.postMap = postMap; return this; } @@ -104,7 +104,7 @@ public LocalDate getDeadline() { public boolean isClose() {return isClose;} - public Map getPostMap() { + public Map getPostMap() { return postMap; } } diff --git a/src/main/java/businessrule/responsemodel/UserResponseModel.java b/src/main/java/usecases/responses/UserResponseModel.java similarity index 88% rename from src/main/java/businessrule/responsemodel/UserResponseModel.java rename to src/main/java/usecases/responses/UserResponseModel.java index 64304a0d..a715f651 100644 --- a/src/main/java/businessrule/responsemodel/UserResponseModel.java +++ b/src/main/java/usecases/responses/UserResponseModel.java @@ -1,7 +1,7 @@ -package businessrule.responsemodel; +package usecases.responses; /** - * This class represents a response model to store the basic information for the user specific output. + * This class represents a response model to store the user specific output. */ public class UserResponseModel extends BaseResponseModel{ private final int userId; diff --git a/src/main/java/businessrule/responsemodel/ViewResponseModel.java b/src/main/java/usecases/responses/ViewResponseModel.java similarity index 60% rename from src/main/java/businessrule/responsemodel/ViewResponseModel.java rename to src/main/java/usecases/responses/ViewResponseModel.java index 2786f39e..e74550c7 100644 --- a/src/main/java/businessrule/responsemodel/ViewResponseModel.java +++ b/src/main/java/usecases/responses/ViewResponseModel.java @@ -1,38 +1,38 @@ -package businessrule.responsemodel; +package usecases.responses; -import businessrule.usecase.util.QuestionDisplayFormatter; +import usecases.dto.QuestionDisplay; import java.util.Map; /** - * This class represents a response model that provides a simple and convenient way to transfer view data as a response to the client. + * This class represents response data related to the question list shown to the user. */ public class ViewResponseModel extends UserResponseModel{ - private final Map questionMap; + private final Map questionMap; public ViewResponseModel(Builder builder) { super(builder.userId, builder.userName, builder.userType); this.questionMap = builder.questionMap; } - public ViewResponseModel(int userId, String userName, String userType, Map questionMap) { + public ViewResponseModel(int userId, String userName, String userType, Map questionMap) { super(userId, userName, userType); this.questionMap = questionMap; } public static class Builder { - private int userId; - private String userName; - private String userType; - private Map questionMap; + private final int userId; + private final String userName; + private final String userType; + private Map questionMap; public Builder(UserResponseModel userModel) { this.userId = userModel.getUserId(); this.userName = userModel.getUserName(); this.userType = userModel.getUserType(); } - public Builder questionMap(Map questionMap) { + public Builder questionMap(Map questionMap) { this.questionMap = questionMap; return this; } @@ -42,7 +42,7 @@ public ViewResponseModel build() { } } - public Map getQuestionMap() { + public Map getQuestionMap() { return questionMap; } } diff --git a/src/main/java/businessrule/SessionManager.java b/src/main/java/usecases/session/SessionManager.java similarity index 80% rename from src/main/java/businessrule/SessionManager.java rename to src/main/java/usecases/session/SessionManager.java index 59077327..90d87e32 100644 --- a/src/main/java/businessrule/SessionManager.java +++ b/src/main/java/usecases/session/SessionManager.java @@ -1,5 +1,8 @@ -package businessrule; +package usecases.session; +/** + * This class manages the life-cycle of the user session. + */ public class SessionManager { // The current active user session. diff --git a/src/main/java/businessrule/UserSession.java b/src/main/java/usecases/session/UserSession.java similarity index 58% rename from src/main/java/businessrule/UserSession.java rename to src/main/java/usecases/session/UserSession.java index 5f76dd81..30576c5b 100644 --- a/src/main/java/businessrule/UserSession.java +++ b/src/main/java/usecases/session/UserSession.java @@ -1,9 +1,11 @@ -package businessrule; +package usecases.session; -import businessrule.responsemodel.UserResponseModel; -import driver.screen.UIManager; -import driver.screen.UserUI; +import usecases.responses.UserResponseModel; +/** + * This class represents a session for a specific user. + * It stores key user information and carries over it once the user login. + */ public class UserSession { private final UserResponseModel userResponseModel; diff --git a/src/main/java/businessrule/usecase/util/BuilderService.java b/src/main/java/usecases/utils/BuilderService.java similarity index 66% rename from src/main/java/businessrule/usecase/util/BuilderService.java rename to src/main/java/usecases/utils/BuilderService.java index ab59f0c3..92b6c95f 100644 --- a/src/main/java/businessrule/usecase/util/BuilderService.java +++ b/src/main/java/usecases/utils/BuilderService.java @@ -1,13 +1,17 @@ -package businessrule.usecase.util; +package usecases.utils; -import businessrule.responsemodel.TheQuestionResponseModel; -import businessrule.responsemodel.UserResponseModel; -import businessrule.responsemodel.ViewResponseModel; -import entity.Question; +import usecases.dto.PostDisplay; +import usecases.dto.QuestionDisplay; +import usecases.responses.TheQuestionResponseModel; +import usecases.responses.UserResponseModel; +import usecases.responses.ViewResponseModel; +import entities.Question; -import java.util.HashMap; import java.util.Map; +/** + * This class provides builder service to construct the question response model and the view response model from base. + */ public class BuilderService { public static final BuilderService INSTANCE = new BuilderService(); @@ -17,7 +21,7 @@ public BuilderService() { public static BuilderService getInstance() { return INSTANCE; } - public TheQuestionResponseModel constructTheQuestionResponse(Question question, UserResponseModel response, Map postMap) { + public TheQuestionResponseModel constructTheQuestionResponse(Question question, UserResponseModel response, Map postMap) { return response.toQuestionResponseBuilder() .questionId(question.getQuestionId()) .questionTitle(question.getTitle()) @@ -28,7 +32,7 @@ public TheQuestionResponseModel constructTheQuestionResponse(Question question, .build(); } - public ViewResponseModel constructViewResponse(UserResponseModel response, Map questionMap) { + public ViewResponseModel constructViewResponse(UserResponseModel response, Map questionMap) { return response.toViewResponseBuilder() .questionMap(questionMap) .build(); diff --git a/src/main/java/businessrule/usecase/util/CredentialChecker.java b/src/main/java/usecases/utils/CredentialChecker.java similarity index 91% rename from src/main/java/businessrule/usecase/util/CredentialChecker.java rename to src/main/java/usecases/utils/CredentialChecker.java index 69c784bf..a062d8ae 100644 --- a/src/main/java/businessrule/usecase/util/CredentialChecker.java +++ b/src/main/java/usecases/utils/CredentialChecker.java @@ -1,10 +1,8 @@ -package businessrule.usecase.util; +package usecases.utils; import org.apache.commons.validator.routines.EmailValidator; -import java.util.regex.*; /** * This is a utility class for checking various credentials and data formats. - * * The "CredentialChecker" class provides methods to validate different types of credentials, * ensuring that they meet specific criteria or follow certain patterns. */ diff --git a/src/main/java/businessrule/usecase/util/EmailNotificationSender.java b/src/main/java/usecases/utils/EmailNotificationSender.java similarity index 82% rename from src/main/java/businessrule/usecase/util/EmailNotificationSender.java rename to src/main/java/usecases/utils/EmailNotificationSender.java index 40990af2..66648ee9 100644 --- a/src/main/java/businessrule/usecase/util/EmailNotificationSender.java +++ b/src/main/java/usecases/utils/EmailNotificationSender.java @@ -1,4 +1,4 @@ -package businessrule.usecase.util; +package usecases.utils; import javax.mail.Message; import javax.mail.Session; @@ -7,6 +7,9 @@ import javax.mail.internet.MimeMessage; import java.util.Properties; +/** + * This class provides emailing service for other usecase. + */ public class EmailNotificationSender{ private static final String address ="2066465318@qq.com"; @@ -17,7 +20,13 @@ public static void main(String[] args) throws Exception { sendEmail("josephpc0612@gmail.com","test title", "test content"); } - public static void sendEmail(String email, String title, String content) throws Exception{ + /** + * + * @param email The email address of the user, should be in valid format. + * @param title The tile of the email. + * @param content The specific content of the email. + */ + public static void sendEmail(String email, String title, String content) throws Exception { Properties properties = new Properties(); properties.put("mail.transport.protocol", "smtp"); properties.put("mail.smtp.host", "smtp.qq.com"); @@ -33,7 +42,6 @@ public static void sendEmail(String email, String title, String content) throws message.setFrom(new InternetAddress(address)); message.setRecipients(Message.RecipientType.TO, new InternetAddress[]{new InternetAddress(email)}); - //message.setRecipient(Message.RecipientType.TO, new InternetAddress("xxx@qq.com")); message.setSubject(title); diff --git a/src/main/java/businessrule/usecase/util/MatchingHandler.java b/src/main/java/usecases/utils/MatchingHandler.java similarity index 93% rename from src/main/java/businessrule/usecase/util/MatchingHandler.java rename to src/main/java/usecases/utils/MatchingHandler.java index b5fd50dc..762a3616 100644 --- a/src/main/java/businessrule/usecase/util/MatchingHandler.java +++ b/src/main/java/usecases/utils/MatchingHandler.java @@ -1,25 +1,22 @@ -package businessrule.usecase.util; +package usecases.utils; -import businessrule.gateway.AttorneyGateway; -import businessrule.gateway.ClientGateway; -import businessrule.gateway.QuestionGateway; -import businessrule.requestmodel.RegistrationData; +import usecases.dto.Matching; +import usecases.dto.MatchingResult; +import usecases.gateway.AttorneyGateway; +import usecases.gateway.ClientGateway; +import usecases.gateway.QuestionGateway; import com.fasterxml.jackson.core.JsonProcessingException; import java.io.*; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import driver.database.AttorneyRepository; -import driver.database.ClientRepository; -import driver.database.QuestionRepo; -import entity.Post; -import entity.Question; -import entity.Attorney; -import entity.Client; +import entities.Question; +import entities.user.Attorney; +import entities.user.Client; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; import com.fasterxml.jackson.databind.ObjectMapper; -import entity.factory.ClientFactory; + import java.nio.charset.StandardCharsets; /** diff --git a/src/main/java/businessrule/usecase/util/PostMapConstructor.java b/src/main/java/usecases/utils/PostMapConstructor.java similarity index 73% rename from src/main/java/businessrule/usecase/util/PostMapConstructor.java rename to src/main/java/usecases/utils/PostMapConstructor.java index 2b717186..884c279e 100644 --- a/src/main/java/businessrule/usecase/util/PostMapConstructor.java +++ b/src/main/java/usecases/utils/PostMapConstructor.java @@ -1,13 +1,13 @@ -package businessrule.usecase.util; +package usecases.utils; -import businessrule.gateway.UserGateway; -import businessrule.gateway.UserGatewayFactory; -import entity.Post; -import entity.Question; -import entity.User; +import usecases.dto.PostDisplay; +import usecases.gateway.UserGateway; +import infrastructure.database.UserGatewayFactory; +import entities.Post; +import entities.Question; +import entities.user.User; import java.time.LocalDate; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -32,11 +32,11 @@ public class PostMapConstructor { * @param question The question containing posts to be mapped. * @return A map of post IDs to formatted post display information. */ - public Map constructPostMap(Question question) { + public Map constructPostMap(Question question) { List postList = question.getPosts(); // initialize post map - Map postMap = new LinkedHashMap<>(); + Map postMap = new LinkedHashMap<>(); // handle the empty post list if (postList.isEmpty()) {return postMap;} @@ -44,13 +44,13 @@ public Map constructPostMap(Question question) { // for each post list, find the data needed for (Post post: postList) { int postId = post.getPostId(); - UserGateway userGateway = userGatewayFactory.createUserGateway(post.getBelongsTo()); + UserGateway userGateway = userGatewayFactory.createUserGateway(post.getBelongsTo()); User user = userGateway.get(post.getBelongsTo()); String userType = user.getUserType(); String name = user.getUserName(); String postText = post.getPostText(); LocalDate createAt = post.getCreateAt(); - PostDisplayFormatter postDisplayFormatter = new PostDisplayFormatter(postText, userType, name, createAt); + PostDisplay postDisplayFormatter = new PostDisplay(postText, userType, name, createAt); // put every data needed to the post map postMap.put(postId, postDisplayFormatter); } diff --git a/src/main/java/businessrule/usecase/util/PythonReader.java b/src/main/java/usecases/utils/PythonReader.java similarity index 97% rename from src/main/java/businessrule/usecase/util/PythonReader.java rename to src/main/java/usecases/utils/PythonReader.java index fb8e160e..df0ae22e 100644 --- a/src/main/java/businessrule/usecase/util/PythonReader.java +++ b/src/main/java/usecases/utils/PythonReader.java @@ -1,4 +1,4 @@ -package businessrule.usecase.util; +package usecases.utils; import org.apache.commons.io.IOUtils; diff --git a/src/main/java/businessrule/usecase/util/QuestionMapConstructor.java b/src/main/java/usecases/utils/QuestionMapConstructor.java similarity index 72% rename from src/main/java/businessrule/usecase/util/QuestionMapConstructor.java rename to src/main/java/usecases/utils/QuestionMapConstructor.java index 4c7f84a2..2be4996c 100644 --- a/src/main/java/businessrule/usecase/util/QuestionMapConstructor.java +++ b/src/main/java/usecases/utils/QuestionMapConstructor.java @@ -1,9 +1,9 @@ -package businessrule.usecase.util; +package usecases.utils; -import entity.Question; +import entities.Question; +import usecases.dto.QuestionDisplay; import java.time.LocalDate; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -19,8 +19,8 @@ public class QuestionMapConstructor { * @param questionList The list of questions to be processed. * @return A map where each question's ID is associated with a corresponding formatted display object. */ - public Map constructQuestionMap(List questionList) { - Map questionMap = new LinkedHashMap<>(); + public Map constructQuestionMap(List questionList) { + Map questionMap = new LinkedHashMap<>(); if (questionList.isEmpty()) { return questionMap; } @@ -30,7 +30,7 @@ public Map constructQuestionMap(List postMap; - private Map questionMap; + private Map postMap; + private Map questionMap; @BeforeEach void setUpUIFactory() { @@ -45,7 +45,7 @@ void setUpUIFactory() { uiManager = new UIManager(testScreen, testCardLayout); Question question = new Question(QUESTION_ID, QUESTION_TYPE, TITLE, LocalDate.now(), USER_ID, LocalDate.now()); String POST_TEXT = "test text"; - PostDisplayFormatter post = new PostDisplayFormatter(POST_TEXT, USER_TYPE, USER_NAME, LocalDate.now()); + PostDisplay post = new PostDisplay(POST_TEXT, USER_TYPE, USER_NAME, LocalDate.now()); postMap = new HashMap<>(); postMap.put(1, post); diff --git a/src/test/java/gatewaytesting/AttorneyRepositoryTest.java b/src/test/java/gatewaytesting/AttorneyRepositoryTest.java index ef3758f1..7114c675 100644 --- a/src/test/java/gatewaytesting/AttorneyRepositoryTest.java +++ b/src/test/java/gatewaytesting/AttorneyRepositoryTest.java @@ -1,15 +1,15 @@ package gatewaytesting; -import businessrule.requestmodel.RegistrationData; -import driver.database.*; -import entity.Question; -import entity.factory.AttorneyFactory; -import entity.factory.ClientFactory; +import usecases.requests.RegistrationData; +import infrastructure.database.*; +import entities.Question; +import entities.factories.AttorneyFactory; +import entities.factories.ClientFactory; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import entity.Attorney; -import entity.Client; +import entities.user.Attorney; +import entities.user.Client; import javax.persistence.EntityManager; diff --git a/src/test/java/gatewaytesting/ClientRepositoryTest.java b/src/test/java/gatewaytesting/ClientRepositoryTest.java index 525df0ff..bb383d55 100644 --- a/src/test/java/gatewaytesting/ClientRepositoryTest.java +++ b/src/test/java/gatewaytesting/ClientRepositoryTest.java @@ -1,18 +1,18 @@ package gatewaytesting; -import businessrule.requestmodel.RegistrationData; -import driver.database.AttorneyRepository; -import driver.database.ClientRepository; -import driver.database.DatabaseConnection; -import driver.database.QuestionRepo; -import entity.Question; -import entity.factory.AttorneyFactory; -import entity.factory.ClientFactory; +import usecases.requests.RegistrationData; +import infrastructure.database.AttorneyRepository; +import infrastructure.database.ClientRepository; +import infrastructure.database.DatabaseConnection; +import infrastructure.database.QuestionRepo; +import entities.Question; +import entities.factories.AttorneyFactory; +import entities.factories.ClientFactory; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import entity.Attorney; -import entity.Client; +import entities.user.Attorney; +import entities.user.Client; import javax.persistence.EntityManager; diff --git a/src/test/java/gatewaytesting/PostRepoTest.java b/src/test/java/gatewaytesting/PostRepoTest.java index f8e435f6..1c0c62c5 100644 --- a/src/test/java/gatewaytesting/PostRepoTest.java +++ b/src/test/java/gatewaytesting/PostRepoTest.java @@ -1,9 +1,9 @@ package gatewaytesting; -import driver.database.DatabaseConnection; -import driver.database.PostRepo; +import infrastructure.database.DatabaseConnection; +import infrastructure.database.PostRepo; import org.junit.jupiter.api.*; -import entity.Post; +import entities.Post; import javax.persistence.EntityManager; import java.time.LocalDate; diff --git a/src/test/java/gatewaytesting/QuestionRepoTest.java b/src/test/java/gatewaytesting/QuestionRepoTest.java index 0f6ac4ee..75d6b253 100644 --- a/src/test/java/gatewaytesting/QuestionRepoTest.java +++ b/src/test/java/gatewaytesting/QuestionRepoTest.java @@ -1,14 +1,14 @@ package gatewaytesting; -import businessrule.requestmodel.RegistrationData; -import driver.database.*; -import entity.Post; -import entity.factory.AttorneyFactory; +import usecases.requests.RegistrationData; +import infrastructure.database.*; +import entities.Post; +import entities.factories.AttorneyFactory; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import entity.Question; -import entity.Attorney; +import entities.Question; +import entities.user.Attorney; import javax.persistence.EntityManager; import java.time.LocalDate; diff --git a/src/test/java/usecasetesting/AskQuestionUseCaseTest.java b/src/test/java/usecasetesting/AskQuestionUseCaseTest.java index 6dd60533..3d205d2c 100644 --- a/src/test/java/usecasetesting/AskQuestionUseCaseTest.java +++ b/src/test/java/usecasetesting/AskQuestionUseCaseTest.java @@ -1,19 +1,21 @@ package usecasetesting; -import businessrule.SessionManager; -import businessrule.UserSession; -import businessrule.gateway.AttorneyGateway; -import businessrule.gateway.ClientGateway; -import businessrule.gateway.QuestionGateway; -import businessrule.inputboundary.QuestionInputBoundary; -import businessrule.outputboundary.TheQuestionOutputBoundary; -import businessrule.requestmodel.QuestionRequestModel; -import businessrule.responsemodel.TheQuestionResponseModel; -import businessrule.responsemodel.UserResponseModel; -import businessrule.usecase.AskQuestionInteractor; -import driver.database.*; -import entity.*; -import entity.factory.QuestionFactory; +import entities.user.Attorney; +import entities.user.Client; +import entities.user.User; +import usecases.session.SessionManager; +import usecases.session.UserSession; +import usecases.gateway.AttorneyGateway; +import usecases.gateway.ClientGateway; +import usecases.gateway.QuestionGateway; +import usecases.inputboundary.QuestionInputBoundary; +import usecases.outputboundary.TheQuestionOutputBoundary; +import usecases.requests.QuestionRequestModel; +import usecases.responses.TheQuestionResponseModel; +import usecases.responses.UserResponseModel; +import usecases.interactors.AskQuestionInteractor; +import infrastructure.database.*; +import entities.factories.QuestionFactory; import org.junit.jupiter.api.Test; import java.time.LocalDate; import static org.junit.jupiter.api.Assertions.*; diff --git a/src/test/java/usecasetesting/BrowseQuestionUseCaseTest.java b/src/test/java/usecasetesting/BrowseQuestionUseCaseTest.java index 8aefc938..27e3e237 100644 --- a/src/test/java/usecasetesting/BrowseQuestionUseCaseTest.java +++ b/src/test/java/usecasetesting/BrowseQuestionUseCaseTest.java @@ -1,17 +1,19 @@ package usecasetesting; -import businessrule.SessionManager; -import businessrule.UserSession; -import businessrule.gateway.AttorneyGateway; -import businessrule.gateway.ClientGateway; -import businessrule.gateway.QuestionGateway; -import businessrule.inputboundary.ViewInputBoundary; -import businessrule.outputboundary.ViewOutputBoundary; -import businessrule.responsemodel.UserResponseModel; -import businessrule.responsemodel.ViewResponseModel; -import businessrule.usecase.BrowseQuestionInteractor; -import driver.database.*; -import entity.*; +import entities.user.Attorney; +import entities.user.Client; +import usecases.session.SessionManager; +import usecases.session.UserSession; +import usecases.gateway.AttorneyGateway; +import usecases.gateway.ClientGateway; +import usecases.gateway.QuestionGateway; +import usecases.inputboundary.ViewInputBoundary; +import usecases.outputboundary.ViewOutputBoundary; +import usecases.responses.UserResponseModel; +import usecases.responses.ViewResponseModel; +import usecases.interactors.BrowseQuestionInteractor; +import infrastructure.database.*; +import entities.*; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; diff --git a/src/test/java/usecasetesting/ClientRegisterUseCaseTest.java b/src/test/java/usecasetesting/ClientRegisterUseCaseTest.java index daa70ba7..390c9672 100644 --- a/src/test/java/usecasetesting/ClientRegisterUseCaseTest.java +++ b/src/test/java/usecasetesting/ClientRegisterUseCaseTest.java @@ -1,13 +1,13 @@ package usecasetesting; -import businessrule.gateway.ClientGateway; -import businessrule.inputboundary.UserRegisterInputBoundary; -import businessrule.outputboundary.BaseOutputBoundary; -import businessrule.requestmodel.RegistrationData; -import businessrule.responsemodel.BaseResponseModel; -import businessrule.usecase.ClientRegisterInteractor; -import driver.database.ClientRepository; -import entity.factory.ClientFactory; +import usecases.gateway.ClientGateway; +import usecases.inputboundary.UserRegisterInputBoundary; +import usecases.outputboundary.BaseOutputBoundary; +import usecases.requests.RegistrationData; +import usecases.responses.BaseResponseModel; +import usecases.interactors.ClientRegisterInteractor; +import infrastructure.database.ClientRepository; +import entities.factories.ClientFactory; import org.junit.jupiter.api.Test; /** diff --git a/src/test/java/usecasetesting/CloseUseCaseTest.java b/src/test/java/usecasetesting/CloseUseCaseTest.java index ad0a439c..2bcd4105 100644 --- a/src/test/java/usecasetesting/CloseUseCaseTest.java +++ b/src/test/java/usecasetesting/CloseUseCaseTest.java @@ -1,18 +1,18 @@ package usecasetesting; -import businessrule.SessionManager; -import businessrule.UserSession; -import businessrule.gateway.*; -import businessrule.inputboundary.CloseInputBoundary; -import businessrule.outputboundary.UserOutputBoundary; -import businessrule.requestmodel.CloseRequestModel; -import businessrule.responsemodel.UserResponseModel; -import businessrule.usecase.CloseQuestionInteractor; -import driver.database.*; -import entity.Attorney; -import entity.Client; -import entity.Question; +import usecases.session.SessionManager; +import usecases.session.UserSession; +import usecases.gateway.*; +import usecases.inputboundary.CloseInputBoundary; +import usecases.outputboundary.UserOutputBoundary; +import usecases.requests.CloseRequestModel; +import usecases.responses.UserResponseModel; +import usecases.interactors.CloseQuestionInteractor; +import infrastructure.database.*; +import entities.user.Attorney; +import entities.user.Client; +import entities.Question; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; diff --git a/src/test/java/usecasetesting/RateAnswerUseCaseTest.java b/src/test/java/usecasetesting/RateAnswerUseCaseTest.java index 528a8afc..32b9546a 100644 --- a/src/test/java/usecasetesting/RateAnswerUseCaseTest.java +++ b/src/test/java/usecasetesting/RateAnswerUseCaseTest.java @@ -1,18 +1,18 @@ package usecasetesting; -import businessrule.SessionManager; -import businessrule.UserSession; -import businessrule.gateway.*; -import businessrule.inputboundary.RateInputBoundary; -import businessrule.outputboundary.UserOutputBoundary; -import businessrule.requestmodel.RateRequestModel; -import businessrule.responsemodel.UserResponseModel; -import businessrule.usecase.RateInteractor; -import driver.database.*; -import entity.Attorney; -import entity.Client; -import entity.Question; +import usecases.session.SessionManager; +import usecases.session.UserSession; +import usecases.gateway.*; +import usecases.inputboundary.RateInputBoundary; +import usecases.outputboundary.UserOutputBoundary; +import usecases.requests.RateRequestModel; +import usecases.responses.UserResponseModel; +import usecases.interactors.RateInteractor; +import infrastructure.database.*; +import entities.user.Attorney; +import entities.user.Client; +import entities.Question; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -59,7 +59,7 @@ public UserResponseModel prepareSuccess(UserResponseModel userResponseModel) { return null; } }; - rateInputBoundary = new RateInteractor(questionGateway, userOutputBoundary, clientGateway, attorneyGateway); + rateInputBoundary = new RateInteractor(questionGateway, userOutputBoundary, attorneyGateway); Question question = new Question(); question.setQuestionId(QUESTION_ID); diff --git a/src/test/java/usecasetesting/ReplyUseCaseTest.java b/src/test/java/usecasetesting/ReplyUseCaseTest.java index e0fde3d9..5c3a95d8 100644 --- a/src/test/java/usecasetesting/ReplyUseCaseTest.java +++ b/src/test/java/usecasetesting/ReplyUseCaseTest.java @@ -1,18 +1,21 @@ package usecasetesting; -import businessrule.SessionManager; -import businessrule.UserSession; -import businessrule.gateway.*; -import businessrule.inputboundary.PostInputBoundary; -import businessrule.outputboundary.TheQuestionOutputBoundary; -import businessrule.requestmodel.PostRequestModel; -import businessrule.responsemodel.TheQuestionResponseModel; -import businessrule.responsemodel.UserResponseModel; -import businessrule.usecase.ReplyInteractor; -import driver.database.*; -import entity.*; -import entity.factory.PostFactory; +import entities.user.Attorney; +import entities.user.Client; +import entities.user.User; +import usecases.session.SessionManager; +import usecases.session.UserSession; +import usecases.gateway.*; +import usecases.inputboundary.PostInputBoundary; +import usecases.outputboundary.TheQuestionOutputBoundary; +import usecases.requests.PostRequestModel; +import usecases.responses.TheQuestionResponseModel; +import usecases.responses.UserResponseModel; +import usecases.interactors.ReplyInteractor; +import infrastructure.database.*; +import entities.*; +import entities.factories.PostFactory; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -74,7 +77,7 @@ public TheQuestionResponseModel prepareSuccess(TheQuestionResponseModel response Client client = new Client(); client.setUserId(CLIENT_ID); - client.setEmail("josephpc0612@gmail.com"); + client.setEmail("josephpc061@gmail.com"); client.addQuestion(question); clientGateway.save(client); diff --git a/src/test/java/usecasetesting/SelectQuestionUseCaseTest.java b/src/test/java/usecasetesting/SelectQuestionUseCaseTest.java index e6b590c8..19b368ab 100644 --- a/src/test/java/usecasetesting/SelectQuestionUseCaseTest.java +++ b/src/test/java/usecasetesting/SelectQuestionUseCaseTest.java @@ -1,18 +1,20 @@ package usecasetesting; -import businessrule.SessionManager; -import businessrule.UserSession; -import businessrule.gateway.*; -import businessrule.inputboundary.SelectInputBoundary; -import businessrule.outputboundary.TheQuestionOutputBoundary; -import businessrule.requestmodel.SelectRequestModel; -import businessrule.responsemodel.TheQuestionResponseModel; -import businessrule.responsemodel.UserResponseModel; -import businessrule.usecase.util.PostDisplayFormatter; -import businessrule.usecase.SelectQuestionInteractor; -import driver.database.*; -import entity.*; +import entities.user.Attorney; +import entities.user.Client; +import usecases.session.SessionManager; +import usecases.session.UserSession; +import usecases.gateway.*; +import usecases.inputboundary.SelectInputBoundary; +import usecases.outputboundary.TheQuestionOutputBoundary; +import usecases.requests.SelectRequestModel; +import usecases.responses.TheQuestionResponseModel; +import usecases.responses.UserResponseModel; +import usecases.dto.PostDisplay; +import usecases.interactors.SelectQuestionInteractor; +import infrastructure.database.*; +import entities.*; import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; @@ -61,7 +63,7 @@ public TheQuestionResponseModel prepareFail(String msg) { @Override public TheQuestionResponseModel prepareSuccess(TheQuestionResponseModel response) { assertEquals(2, response.getPostMap().size(), "The post map is not correct."); - List arrayList; + List arrayList; arrayList = new ArrayList<>(response.getPostMap().values()); assertEquals("test text", arrayList.get(0).getPostText()); return null; diff --git a/src/test/java/usecasetesting/UserLoginUseCaseTest.java b/src/test/java/usecasetesting/UserLoginUseCaseTest.java index 7d80336f..4de29f3f 100644 --- a/src/test/java/usecasetesting/UserLoginUseCaseTest.java +++ b/src/test/java/usecasetesting/UserLoginUseCaseTest.java @@ -1,15 +1,15 @@ package usecasetesting; -import businessrule.SessionManager; -import businessrule.gateway.ClientGateway; -import businessrule.gateway.UserGatewayFactory; -import businessrule.inputboundary.UserLoginInputBoundary; -import businessrule.outputboundary.UserOutputBoundary; -import businessrule.requestmodel.UserLoginRequestModel; -import businessrule.responsemodel.UserResponseModel; -import businessrule.usecase.UserLoginInteractor; -import driver.database.*; -import entity.Client; +import usecases.session.SessionManager; +import usecases.gateway.ClientGateway; +import infrastructure.database.UserGatewayFactory; +import usecases.inputboundary.UserLoginInputBoundary; +import usecases.outputboundary.UserOutputBoundary; +import usecases.requests.UserLoginRequestModel; +import usecases.responses.UserResponseModel; +import usecases.interactors.UserLoginInteractor; +import infrastructure.database.*; +import entities.user.Client; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; diff --git a/src/test/java/usecasetesting/UserViewHistoryUseCaseTest.java b/src/test/java/usecasetesting/UserViewHistoryUseCaseTest.java index da341b47..ae7b314c 100644 --- a/src/test/java/usecasetesting/UserViewHistoryUseCaseTest.java +++ b/src/test/java/usecasetesting/UserViewHistoryUseCaseTest.java @@ -1,23 +1,23 @@ package usecasetesting; -import businessrule.SessionManager; -import businessrule.UserSession; -import businessrule.gateway.AttorneyGateway; -import businessrule.gateway.ClientGateway; -import businessrule.gateway.QuestionGateway; -import businessrule.gateway.UserGatewayFactory; -import businessrule.inputboundary.ViewInputBoundary; -import businessrule.outputboundary.ViewOutputBoundary; -import businessrule.responsemodel.UserResponseModel; -import businessrule.responsemodel.ViewResponseModel; -import businessrule.usecase.util.QuestionDisplayFormatter; -import businessrule.usecase.ViewQuestionInteractor; -import driver.database.AttorneyRepository; -import driver.database.ClientRepository; -import driver.database.QuestionRepo; -import entity.Attorney; -import entity.Client; -import entity.Question; +import usecases.session.SessionManager; +import usecases.session.UserSession; +import usecases.gateway.AttorneyGateway; +import usecases.gateway.ClientGateway; +import usecases.gateway.QuestionGateway; +import infrastructure.database.UserGatewayFactory; +import usecases.inputboundary.ViewInputBoundary; +import usecases.outputboundary.ViewOutputBoundary; +import usecases.responses.UserResponseModel; +import usecases.responses.ViewResponseModel; +import usecases.dto.QuestionDisplay; +import usecases.interactors.ViewQuestionInteractor; +import infrastructure.database.AttorneyRepository; +import infrastructure.database.ClientRepository; +import infrastructure.database.QuestionRepo; +import entities.user.Attorney; +import entities.user.Client; +import entities.Question; import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; @@ -59,7 +59,7 @@ public ViewResponseModel prepareFail(String msg) { @Override public ViewResponseModel prepareSuccess(ViewResponseModel response) { assertEquals(1, response.getQuestionMap().size(), "The Question Map is not correct."); - List arrayList; + List arrayList; arrayList = new ArrayList<>(response.getQuestionMap().values()); assertEquals("test title", arrayList.get(0).getTitle()); return null; diff --git a/src/test/java/usecasetesting/ViewRecommendationUseCaseTest.java b/src/test/java/usecasetesting/ViewRecommendationUseCaseTest.java index 66bd644d..3a87ebd3 100644 --- a/src/test/java/usecasetesting/ViewRecommendationUseCaseTest.java +++ b/src/test/java/usecasetesting/ViewRecommendationUseCaseTest.java @@ -1,17 +1,19 @@ package usecasetesting; -import businessrule.SessionManager; -import businessrule.UserSession; -import businessrule.gateway.AttorneyGateway; -import businessrule.gateway.ClientGateway; -import businessrule.gateway.QuestionGateway; -import businessrule.inputboundary.ViewInputBoundary; -import businessrule.outputboundary.ViewOutputBoundary; -import businessrule.responsemodel.UserResponseModel; -import businessrule.responsemodel.ViewResponseModel; -import businessrule.usecase.AttorneyRecommendInteractor; -import driver.database.*; -import entity.*; +import entities.user.Attorney; +import entities.user.Client; +import usecases.session.SessionManager; +import usecases.session.UserSession; +import usecases.gateway.AttorneyGateway; +import usecases.gateway.ClientGateway; +import usecases.gateway.QuestionGateway; +import usecases.inputboundary.ViewInputBoundary; +import usecases.outputboundary.ViewOutputBoundary; +import usecases.responses.UserResponseModel; +import usecases.responses.ViewResponseModel; +import usecases.interactors.AttorneyRecommendInteractor; +import infrastructure.database.*; +import entities.*; import org.junit.jupiter.api.Test; import java.time.LocalDate; import static org.junit.jupiter.api.Assertions.*; From 179f38d71652d06b0b5bb919c67e045e821dedc7 Mon Sep 17 00:00:00 2001 From: Yifan Liu Date: Tue, 15 Aug 2023 19:09:59 -0400 Subject: [PATCH 24/24] add attorney registration --- src/main/java/Main.java | 11 +- .../controllers/ClientRegisterControl.java | 47 ----- .../controllers/ControlContainer.java | 77 ++----- .../adapters/controllers/RegisterControl.java | 30 +++ .../entities/factories/AttorneyFactory.java | 1 + .../entities/factories/ClientFactory.java | 1 + .../java/entities/factories/UserFactory.java | 3 +- .../infrastructure/screens/RegisterUI.java | 21 +- .../AttorneyRegisterInteractor.java | 14 ++ .../interactors/ClientRegisterInteractor.java | 63 +----- .../interactors/UserRegisterInteractor.java | 57 +++-- .../requests/AttorneyRegistrationData.java | 38 ++++ .../requests/ClientRegistrationData.java | 69 ++++++ .../usecases/requests/RegistrationData.java | 87 ++++---- .../java/usecases/utils/BuilderService.java | 1 - .../ControlContainerTest.java | 24 +-- ...trolTest.java => RegisterControlTest.java} | 20 +- src/test/java/entitytesting/ClientTest.java | 198 ++++++++++++++---- .../factorytesting/ClientFactoryTest.java | 12 +- .../AttorneyRepositoryTest.java | 22 +- .../gatewaytesting/ClientRepositoryTest.java | 62 +++++- .../ClientRegisterUseCaseTest.java | 74 ++++++- 22 files changed, 629 insertions(+), 303 deletions(-) delete mode 100644 src/main/java/adapters/controllers/ClientRegisterControl.java create mode 100644 src/main/java/adapters/controllers/RegisterControl.java create mode 100644 src/main/java/usecases/interactors/AttorneyRegisterInteractor.java create mode 100644 src/main/java/usecases/requests/AttorneyRegistrationData.java create mode 100644 src/main/java/usecases/requests/ClientRegistrationData.java rename src/test/java/controllertesting/{ClientRegisterControlTest.java => RegisterControlTest.java} (71%) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index f4333c1c..885f07ac 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,5 +1,6 @@ import adapters.controllers.*; import adapters.presenters.*; +import entities.factories.AttorneyFactory; import infrastructure.screens.UIFactory; import usecases.gateway.*; import usecases.inputboundary.*; @@ -9,7 +10,6 @@ import infrastructure.database.*; import infrastructure.screens.utils.UIDesign; import infrastructure.screens.utils.UIManager; -import entities.user.Attorney; import entities.factories.ClientFactory; import entities.factories.PostFactory; import entities.factories.QuestionFactory; @@ -24,6 +24,7 @@ public static void main(String[] args) { ClientGateway clientGateway = new ClientRepository(); AttorneyGateway attorneyGateway = new AttorneyRepository(); ClientFactory clientFactory = new ClientFactory(); + AttorneyFactory attorneyFactory = new AttorneyFactory(); QuestionFactory questionFactory = new QuestionFactory(); QuestionGateway questionGateway = new QuestionRepo(); @@ -63,8 +64,10 @@ public static void main(String[] args) { UserLoginInputBoundary userLoginInteractor = new UserLoginInteractor(gatewayFactory, homePageOutputBoundary); UserLoginControl loginControl = new UserLoginControl(userLoginInteractor); - UserRegisterInputBoundary clientRegisterInteractor = new ClientRegisterInteractor(clientGateway, clientFactory, registerOutputBoundary); - ClientRegisterControl registerControl = new ClientRegisterControl(clientRegisterInteractor); + UserRegisterInputBoundary clientRegisterInteractor = new ClientRegisterInteractor(clientGateway, registerOutputBoundary, clientFactory); + UserRegisterInputBoundary attorneyRegisterInteractor = new AttorneyRegisterInteractor(attorneyGateway, registerOutputBoundary, attorneyFactory); + RegisterControl registerControl = new RegisterControl(clientRegisterInteractor); + RegisterControl attorneyRegisterControl = new RegisterControl(attorneyRegisterInteractor); QuestionInputBoundary questionInteractor = new AskQuestionInteractor(questionGateway, theQuestionOutputBoundary, questionFactory, clientGateway); @@ -100,7 +103,7 @@ public static void main(String[] args) { //control container ControlContainer controlContainer = new ControlContainer(registerControl, closeQuestionControl, postControl, questionControl, rateControl, selectQuestionControl, loginControl, viewQuestionControl, - browseQuestionControl, recommendationControl); + browseQuestionControl, recommendationControl, attorneyRegisterControl); //feed control container into the response formatter UIManager.setControlContainer(controlContainer); diff --git a/src/main/java/adapters/controllers/ClientRegisterControl.java b/src/main/java/adapters/controllers/ClientRegisterControl.java deleted file mode 100644 index ca68c58c..00000000 --- a/src/main/java/adapters/controllers/ClientRegisterControl.java +++ /dev/null @@ -1,47 +0,0 @@ -package adapters.controllers; - -import usecases.inputboundary.UserRegisterInputBoundary; -import usecases.requests.RegistrationData; -import usecases.responses.BaseResponseModel; - -/** - * This class represents responsible for handling user registration. - */ -public class ClientRegisterControl { - private final UserRegisterInputBoundary inputBoundary; - - /** - * Constructs a new instance of ClientRegisterControl. - * - * @param inputBoundary The input boundary for user registration. - */ - public ClientRegisterControl(UserRegisterInputBoundary inputBoundary) { - this.inputBoundary = inputBoundary; - } - - /** - * Creates a new user registration based on the provided information. - * - * @param userName The username of the user. - * @param email The email address of the user. - * @param password1 The first password. - * @param password2 The confirmation password. - * @param StateAbb The state abbreviation. - * @param PostalCode The postal code. - * @param ethnicity The ethnicity of the user. - * @param age The age of the user. - * @param gender The gender of the user. - * @param maritalStatus The marital status of the user. - * @param numberOfHousehold The number of individuals in the household. - * @param annualIncome The annual income of the user. - * @return A RegisterResponseModel indicating the result of the registration attempt. - */ - public BaseResponseModel create(String userName, String email, String password1, String password2, - String StateAbb, String PostalCode, - String ethnicity, int age, String gender, String maritalStatus, - int numberOfHousehold, float annualIncome){ - RegistrationData requestModel = new RegistrationData(userName, email, password1, password2, StateAbb, - PostalCode, ethnicity, age, gender, maritalStatus, numberOfHousehold, annualIncome); - return inputBoundary.create(requestModel); - } -} diff --git a/src/main/java/adapters/controllers/ControlContainer.java b/src/main/java/adapters/controllers/ControlContainer.java index 6d1295d5..f20186e5 100644 --- a/src/main/java/adapters/controllers/ControlContainer.java +++ b/src/main/java/adapters/controllers/ControlContainer.java @@ -5,7 +5,8 @@ * It is responsible for managing different aspects of the application. */ public class ControlContainer { - ClientRegisterControl clientRegisterControl; + RegisterControl clientRegisterControl; + RegisterControl attorneyRegisterControl; CloseQuestionControl closeQuestionControl; PostControl postControl; QuestionControl questionControl; @@ -19,23 +20,25 @@ public class ControlContainer { /** * Constructor to initialize the ControlContainer with instances of various control classes. * - * @param clientRegisterControl The control class for client registration. - * @param closeQuestionControl The control class for closing questions. - * @param postControl The control class for handling posts. - * @param questionControl The control class for question management. - * @param rateControl The control class for rating questions. - * @param selectQuestionControl The control class for selecting questions. - * @param userLoginControl The control class for user login. - * @param viewQuestionControl The control class for viewing questions. - * @param browseQuestionControl The control class for browsing questions. - * @param recommendationControl The control class for viewing recommended questions. + * @param clientRegisterControl The control class for client registration. + * @param closeQuestionControl The control class for closing questions. + * @param postControl The control class for handling posts. + * @param questionControl The control class for question management. + * @param rateControl The control class for rating questions. + * @param selectQuestionControl The control class for selecting questions. + * @param userLoginControl The control class for user login. + * @param viewQuestionControl The control class for viewing questions. + * @param browseQuestionControl The control class for browsing questions. + * @param recommendationControl The control class for viewing recommended questions. + * @param attorneyRegisterControl The control class for attorney registration */ - public ControlContainer(ClientRegisterControl clientRegisterControl, CloseQuestionControl closeQuestionControl, + public ControlContainer(RegisterControl clientRegisterControl, CloseQuestionControl closeQuestionControl, PostControl postControl, QuestionControl questionControl, RateControl rateControl, SelectQuestionControl selectQuestionControl, UserLoginControl userLoginControl, ViewQuestionControl viewQuestionControl, ViewQuestionControl browseQuestionControl, - ViewQuestionControl recommendationControl) { + ViewQuestionControl recommendationControl, RegisterControl attorneyRegisterControl) { this.clientRegisterControl = clientRegisterControl; + this.attorneyRegisterControl = attorneyRegisterControl; this.closeQuestionControl = closeQuestionControl; this.postControl = postControl; this.questionControl = questionControl; @@ -47,74 +50,38 @@ public ControlContainer(ClientRegisterControl clientRegisterControl, CloseQuesti this.recommendationControl = recommendationControl; } - /** - * Get the control class for client registration. - * - * @return The client registration control class. - */ - public ClientRegisterControl getClientRegisterControl() { + + public RegisterControl getClientRegisterControl() { return clientRegisterControl; } - /** - * Get the control class for closing questions. - * - * @return The close question control class. - */ + public CloseQuestionControl getCloseQuestionControl() { return closeQuestionControl; } - /** - * Get the control class for handling posts. - * - * @return The post control class. - */ + public PostControl getPostControl() { return postControl; } - /** - * Get the control class for question management. - * - * @return The question control class. - */ + public QuestionControl getQuestionControl() { return questionControl; } - /** - * Get the control class for rating questions. - * - * @return The rate control class. - */ public RateControl getRateControl() { return rateControl; } - /** - * Get the control class for selecting questions. - * - * @return The select question control class. - */ public SelectQuestionControl getSelectQuestionControl() { return selectQuestionControl; } - /** - * Get the control class for user login. - * - * @return The user login control class. - */ public UserLoginControl getUserLoginControl() { return userLoginControl; } - /** - * Get the control class for viewing questions. - * - * @return The view question control class. - */ public ViewQuestionControl getViewQuestionControl() { return viewQuestionControl; } @@ -122,4 +89,6 @@ public ViewQuestionControl getViewQuestionControl() { public ViewQuestionControl getBrowseQuestionControl() {return browseQuestionControl;} public ViewQuestionControl getRecommendationControl() {return recommendationControl;} + + public RegisterControl getAttorneyRegisterControl() {return attorneyRegisterControl;} } diff --git a/src/main/java/adapters/controllers/RegisterControl.java b/src/main/java/adapters/controllers/RegisterControl.java new file mode 100644 index 00000000..94625c3d --- /dev/null +++ b/src/main/java/adapters/controllers/RegisterControl.java @@ -0,0 +1,30 @@ +package adapters.controllers; + +import usecases.inputboundary.UserRegisterInputBoundary; +import usecases.requests.RegistrationData; +import usecases.responses.BaseResponseModel; + +/** + * This class represents responsible for handling user registration. + */ +public class RegisterControl { + private final UserRegisterInputBoundary inputBoundary; + + /** + * Constructs a new instance of ClientRegisterControl. + * + * @param inputBoundary The input boundary for user registration. + */ + public RegisterControl(UserRegisterInputBoundary inputBoundary) { + this.inputBoundary = inputBoundary; + } + + /** + * Creates a new user registration based on the provided information. + * + * @param requestModel @return A RegisterResponseModel indicating the result of the registration attempt. + */ + public BaseResponseModel create(RegistrationData requestModel){ + return inputBoundary.create(requestModel); + } +} diff --git a/src/main/java/entities/factories/AttorneyFactory.java b/src/main/java/entities/factories/AttorneyFactory.java index ec49b84b..3a7ceef0 100644 --- a/src/main/java/entities/factories/AttorneyFactory.java +++ b/src/main/java/entities/factories/AttorneyFactory.java @@ -1,5 +1,6 @@ package entities.factories; +import usecases.requests.AttorneyRegistrationData; import usecases.requests.RegistrationData; import entities.user.Attorney; diff --git a/src/main/java/entities/factories/ClientFactory.java b/src/main/java/entities/factories/ClientFactory.java index 283c37de..b904fcf7 100644 --- a/src/main/java/entities/factories/ClientFactory.java +++ b/src/main/java/entities/factories/ClientFactory.java @@ -1,5 +1,6 @@ package entities.factories; +import usecases.requests.ClientRegistrationData; import usecases.requests.RegistrationData; import entities.user.Client; diff --git a/src/main/java/entities/factories/UserFactory.java b/src/main/java/entities/factories/UserFactory.java index 3f5f466b..0061135f 100644 --- a/src/main/java/entities/factories/UserFactory.java +++ b/src/main/java/entities/factories/UserFactory.java @@ -1,5 +1,6 @@ package entities.factories; +import entities.user.User; import usecases.requests.RegistrationData; import entities.user.UserImp; @@ -8,7 +9,7 @@ * * @param The type of user to create, extending UserImp. */ -public interface UserFactory { +public interface UserFactory { /** * Creates a user instance based on the provided registration data. diff --git a/src/main/java/infrastructure/screens/RegisterUI.java b/src/main/java/infrastructure/screens/RegisterUI.java index 0d513a46..b2c08e42 100644 --- a/src/main/java/infrastructure/screens/RegisterUI.java +++ b/src/main/java/infrastructure/screens/RegisterUI.java @@ -1,8 +1,10 @@ package infrastructure.screens; -import adapters.controllers.ClientRegisterControl; +import adapters.controllers.RegisterControl; import adapters.controllers.ControlContainer; import infrastructure.screens.utils.UIManager; +import usecases.requests.ClientRegistrationData; +import usecases.requests.RegistrationData; import javax.swing.*; import java.awt.*; @@ -147,15 +149,20 @@ public void actionPerformed(ActionEvent e) { ControlContainer controlContainer = uiManager.getControlContainer(); JPanel screens = uiManager.getScreens(); CardLayout cardLayout = uiManager.getCardLayout(); - ClientRegisterControl clientRegisterControl = controlContainer.getClientRegisterControl(); + RegisterControl registerControl = controlContainer.getClientRegisterControl(); switch (actionCommand) { case REGISTER_BUTTON_NAME: try { - clientRegisterControl.create(userName.getText(), email.getText(), String.valueOf(password1.getPassword()), - String.valueOf(password2.getPassword()), stateAbb.getText(), postalCode.getText(), - (String) ethnicity.getSelectedItem(), Integer.parseInt(age.getText()), (String) gender.getSelectedItem(), - (String) maritalStatus.getSelectedItem(), Integer.parseInt(numberOfHousehold.getText()), - Float.parseFloat(annualIncome.getText())); + RegistrationData registrationData = new RegistrationData(userName.getText(), email.getText(), String.valueOf(password1.getPassword()), String.valueOf(password2.getPassword()), stateAbb.getText(), postalCode.getText()); + ClientRegistrationData clientRegistrationData = new ClientRegistrationData.Builder(registrationData) + .ethnicity((String) ethnicity.getSelectedItem()) + .age(Integer.parseInt(age.getText())) + .gender((String) gender.getSelectedItem()) + .maritalStatus((String) maritalStatus.getSelectedItem()) + .numberOfHousehold(Integer.parseInt(numberOfHousehold.getText())) + .annualIncome(Float.parseFloat(annualIncome.getText())) + .build(); + registerControl.create(clientRegistrationData); } catch (Exception ex) { JOptionPane.showMessageDialog(this, ex.getMessage()); } diff --git a/src/main/java/usecases/interactors/AttorneyRegisterInteractor.java b/src/main/java/usecases/interactors/AttorneyRegisterInteractor.java new file mode 100644 index 00000000..610afcb1 --- /dev/null +++ b/src/main/java/usecases/interactors/AttorneyRegisterInteractor.java @@ -0,0 +1,14 @@ +package usecases.interactors; + +import entities.factories.AttorneyFactory; +import entities.factories.UserFactory; +import entities.user.Attorney; +import usecases.gateway.AttorneyGateway; +import usecases.gateway.UserGateway; +import usecases.outputboundary.BaseOutputBoundary; + +public class AttorneyRegisterInteractor extends UserRegisterInteractor { + public AttorneyRegisterInteractor(AttorneyGateway userGateway, BaseOutputBoundary outputBoundary, AttorneyFactory userFactory) { + super(userGateway, outputBoundary, userFactory); + } +} diff --git a/src/main/java/usecases/interactors/ClientRegisterInteractor.java b/src/main/java/usecases/interactors/ClientRegisterInteractor.java index 12775cbf..09a806a5 100644 --- a/src/main/java/usecases/interactors/ClientRegisterInteractor.java +++ b/src/main/java/usecases/interactors/ClientRegisterInteractor.java @@ -3,12 +3,8 @@ import usecases.gateway.ClientGateway; import usecases.outputboundary.BaseOutputBoundary; -import usecases.responses.BaseResponseModel; -import entities.ApplicationException; import entities.user.Client; import entities.factories.ClientFactory; -import usecases.utils.CredentialChecker; -import usecases.requests.RegistrationData; /** * This class represents interactor responsible for client registration use case. @@ -18,62 +14,11 @@ public class ClientRegisterInteractor extends UserRegisterInteractor The type of UserFactory used for creating user instances. * @param The type of User entity. */ -public abstract class UserRegisterInteractor, F extends UserFactory, U extends User> implements UserRegisterInputBoundary { +public abstract class UserRegisterInteractor, F extends UserFactory, U extends User> implements UserRegisterInputBoundary { protected final T userGateway; protected final F userFactory; + protected final BaseOutputBoundary outputBoundary; /** * Constructor for UserRegisterInteractor. * - * @param userGateway The gateway for user-related operations. - * @param userFactory The factory for creating user instances. + * @param userGateway The gateway for user-related operations. * @param outputBoundary The output boundary for registration results. + * @param userFactory The user factory to create corresponding user entity. */ - public UserRegisterInteractor(T userGateway, F userFactory, BaseOutputBoundary outputBoundary) { + public UserRegisterInteractor(T userGateway, BaseOutputBoundary outputBoundary, F userFactory) { this.userGateway = userGateway; - this.userFactory = userFactory; this.outputBoundary = outputBoundary; + this.userFactory = userFactory; } - @Override - public abstract BaseResponseModel create(RegistrationData requestModel); + public BaseResponseModel create(RegistrationData requestModel) { + try {checkCredential(requestModel);} + catch (ApplicationException e) { + return outputBoundary.prepareFail(e.getMessage()); + } + int userId = generateId(); + requestModel.setUserId(userId); + U user = userFactory.createUser(requestModel); + userGateway.save(user); + return outputBoundary.prepareSuccess(String.valueOf(userId)); + } - /** - * Generates a unique user ID. - * - * @return A unique user ID. - */ protected int generateId() { RandomNumberGenerator generator = new RandomNumberGenerator(); int randomUserId = generator.generateClientId(8); @@ -51,4 +58,30 @@ protected int generateId() { exists = userGateway.existsById(randomUserId); } return randomUserId; } + + protected void checkCredential(RegistrationData requestModel) throws ApplicationException { + // prepare input data + String inputUserName = requestModel.userName; + String inputEmail = requestModel.email; + String inputPassword1 = requestModel.password; + String inputPassword2 = requestModel.password2; + String inputPostalCode = requestModel.postalCode; + int inputAge = requestModel.age; + + // validate input data + CredentialChecker checker = new CredentialChecker(); + if (userGateway.existsByName(inputUserName)) { + throw new ApplicationException("User name already exists"); + } else if (!inputPassword1.equals(inputPassword2)) { + throw new ApplicationException("Passwords does not match"); + } else if (inputPassword1.length() < 8) { + throw new ApplicationException("Password is less than 8 characters"); + } else if (!checker.checkEmail(inputEmail)) { + throw new ApplicationException("Email is invalid"); + } else if (!checker.checkAge(inputAge)) { + throw new ApplicationException("Age is invalid"); + } else if (!checker.checkPostalCode(inputPostalCode)) { + throw new ApplicationException("Postal Code is invalid"); + } + } } diff --git a/src/main/java/usecases/requests/AttorneyRegistrationData.java b/src/main/java/usecases/requests/AttorneyRegistrationData.java new file mode 100644 index 00000000..8e18a905 --- /dev/null +++ b/src/main/java/usecases/requests/AttorneyRegistrationData.java @@ -0,0 +1,38 @@ +package usecases.requests; + +import java.util.Set; + +public class AttorneyRegistrationData extends RegistrationData { + + public AttorneyRegistrationData(Builder builder) { + super(builder.userName, builder.email, builder.password, builder.password2, builder.stateAbb, builder.postalCode); + this.professionals = builder.professionals; + + } + + public static class Builder { + private final String userName; + private final String email; + private final String password; + private final String stateAbb; + private final String postalCode; + private final String password2; + private Set professionals; + + public Builder(RegistrationData registrationData) { + this.userName = registrationData.userName; + this.email = registrationData.email; + this.password = registrationData.password; + this.password2 = registrationData.password2; + this.stateAbb = registrationData.stateAbb; + this.postalCode = registrationData.postalCode; + } + + public AttorneyRegistrationData.Builder professionals(Set professionals) { + this.professionals = professionals; + return this; + } + + public AttorneyRegistrationData build() {return new AttorneyRegistrationData(this);} + } +} diff --git a/src/main/java/usecases/requests/ClientRegistrationData.java b/src/main/java/usecases/requests/ClientRegistrationData.java new file mode 100644 index 00000000..58693ef1 --- /dev/null +++ b/src/main/java/usecases/requests/ClientRegistrationData.java @@ -0,0 +1,69 @@ +package usecases.requests; + +public class ClientRegistrationData extends RegistrationData { + public ClientRegistrationData(Builder builder) { + super(builder.userName, builder.email, builder.password, builder.password2, builder.stateAbb, builder.postalCode); + this.ethnicity = builder.ethnicity; + this.age = builder.age; + this.gender = builder.gender; + this.maritalStatus = builder.maritalStatus; + this.numberOfHousehold = builder.numberOfHousehold; + this.annualIncome = builder.annualIncome; + } + + public static class Builder { + private final String userName; + private final String email; + private final String password; + private final String stateAbb; + private final String postalCode; + private String ethnicity; + private int age; + private String gender; + private String maritalStatus; + private int numberOfHousehold; + private float annualIncome; + private final String password2; + + public Builder(RegistrationData registrationData) { + this.userName = registrationData.userName; + this.email = registrationData.email; + this.password = registrationData.password; + this.password2 = registrationData.password2; + this.stateAbb = registrationData.stateAbb; + this.postalCode = registrationData.postalCode; + } + + public ClientRegistrationData.Builder ethnicity(String ethnicity) { + this.ethnicity = ethnicity; + return this; + } + + public ClientRegistrationData.Builder age(int age) { + this.age = age; + return this; + } + + public ClientRegistrationData.Builder gender(String gender) { + this.gender = gender; + return this; + } + + public ClientRegistrationData.Builder maritalStatus(String maritalStatus) { + this.maritalStatus = maritalStatus; + return this; + } + + public ClientRegistrationData.Builder numberOfHousehold(int numberOfHousehold) { + this.numberOfHousehold = numberOfHousehold; + return this; + } + + public ClientRegistrationData.Builder annualIncome(float annualIncome) { + this.annualIncome = annualIncome; + return this; + } + + public ClientRegistrationData build() {return new ClientRegistrationData(this);} + } +} diff --git a/src/main/java/usecases/requests/RegistrationData.java b/src/main/java/usecases/requests/RegistrationData.java index 1bbec0c5..025f01bf 100644 --- a/src/main/java/usecases/requests/RegistrationData.java +++ b/src/main/java/usecases/requests/RegistrationData.java @@ -25,53 +25,68 @@ public class RegistrationData { // fields for attorney registration public Set professionals; - // for user - /** - * Constructor for user registration. - */ - public RegistrationData(String userName, String email, String password, String password2, String stateAbb, String postalCode) { - this.userName = userName; - this.email = email; - this.password = password; - this.password2 = password2; - this.stateAbb = stateAbb; - this.postalCode = postalCode; + + public RegistrationData() { } - /** - * Constructor for client registration. - */ - // for client registration - public RegistrationData(String userName, String email, String password, String password2, String stateAbb, String postalCode, String ethnicity, int age, String gender, String maritalStatus, int numberOfHousehold, float annualIncome) { + public RegistrationData(String userName, String email, String password, String password2, String stateAbb, String postalCode) { this.userName = userName; this.email = email; this.password = password; this.password2 = password2; this.stateAbb = stateAbb; this.postalCode = postalCode; - this.ethnicity = ethnicity; - this.age = age; - this.gender = gender; - this.maritalStatus = maritalStatus; - this.numberOfHousehold = numberOfHousehold; - this.annualIncome = annualIncome; } - /** - * Constructor for attorney registration. - */ - public RegistrationData(String userName, String email, String password, String password2, String stateAbb, String postalCode, Set professionals) { - this.userName = userName; - this.email = email; - this.password = password; - this.password2 = password2; - this.stateAbb = stateAbb; - this.postalCode = postalCode; - this.professionals = professionals; + public RegistrationData(Builder builder) { + this.userName = builder.userName; + this.email = builder.email; + this.password = builder.password; + this.password2 = builder.password2; + this.stateAbb = builder.stateAbb; + this.postalCode = builder.postalCode; } - /** - * Sets the user ID. - */ public void setUserId(int userId) {this.userId = userId;} + + public static class Builder { + private String userName; + private String email; + private String password; + private String stateAbb; + private String postalCode; + private String password2; + + public Builder userName(String userName) { + this.userName = userName; + return this; + } + + public Builder email(String email) { + this.email = email; + return this; + } + + public Builder password(String password) { + this.password = password; + return this; + } + + public Builder stateAbb(String stateAbb) { + this.stateAbb = stateAbb; + return this; + } + + public Builder postalCode(String postalCode) { + this.postalCode = postalCode; + return this; + } + + public Builder password2(String password) { + this.password2 = password; + return this; + } + + public RegistrationData build() {return new RegistrationData(this);} + } } diff --git a/src/main/java/usecases/utils/BuilderService.java b/src/main/java/usecases/utils/BuilderService.java index 92b6c95f..98576ba1 100644 --- a/src/main/java/usecases/utils/BuilderService.java +++ b/src/main/java/usecases/utils/BuilderService.java @@ -6,7 +6,6 @@ import usecases.responses.UserResponseModel; import usecases.responses.ViewResponseModel; import entities.Question; - import java.util.Map; /** diff --git a/src/test/java/controllertesting/ControlContainerTest.java b/src/test/java/controllertesting/ControlContainerTest.java index 0a00c552..c077b8bf 100644 --- a/src/test/java/controllertesting/ControlContainerTest.java +++ b/src/test/java/controllertesting/ControlContainerTest.java @@ -16,9 +16,9 @@ public class ControlContainerTest { */ @Test public void testGetClientRegisterControl() { - ClientRegisterControl mockClientRegisterControl = mock(ClientRegisterControl.class); - ControlContainer controlContainer = new ControlContainer(mockClientRegisterControl, null, null, null, null, null, null, null, null, null); - assertEquals(mockClientRegisterControl, controlContainer.getClientRegisterControl()); + RegisterControl mockRegisterControl = mock(RegisterControl.class); + ControlContainer controlContainer = new ControlContainer(mockRegisterControl, null, null, null, null, null, null, null, null, null, null); + assertEquals(mockRegisterControl, controlContainer.getClientRegisterControl()); } /** @@ -27,7 +27,7 @@ public void testGetClientRegisterControl() { @Test public void testGetCloseQuestionControl() { CloseQuestionControl mockCloseQuestionControl = mock(CloseQuestionControl.class); - ControlContainer controlContainer = new ControlContainer(null, mockCloseQuestionControl, null, null, null, null, null, null, null, null); + ControlContainer controlContainer = new ControlContainer(null, mockCloseQuestionControl, null, null, null, null, null, null, null, null, null); assertEquals(mockCloseQuestionControl, controlContainer.getCloseQuestionControl()); } @@ -37,7 +37,7 @@ public void testGetCloseQuestionControl() { @Test public void testGetPostControl() { PostControl mockPostControl = mock(PostControl.class); - ControlContainer controlContainer = new ControlContainer(null, null, mockPostControl, null, null, null, null, null, null, null); + ControlContainer controlContainer = new ControlContainer(null, null, mockPostControl, null, null, null, null, null, null, null, null); assertEquals(mockPostControl, controlContainer.getPostControl()); } @@ -47,7 +47,7 @@ public void testGetPostControl() { @Test public void testGetQuestionControl() { QuestionControl mockQuestionControl = mock(QuestionControl.class); - ControlContainer controlContainer = new ControlContainer(null, null, null, mockQuestionControl, null, null, null, null, null, null); + ControlContainer controlContainer = new ControlContainer(null, null, null, mockQuestionControl, null, null, null, null, null, null, null); assertEquals(mockQuestionControl, controlContainer.getQuestionControl()); } @@ -57,7 +57,7 @@ public void testGetQuestionControl() { @Test public void testGetRateControl() { RateControl mockRateControl = mock(RateControl.class); - ControlContainer controlContainer = new ControlContainer(null, null, null, null, mockRateControl, null, null, null, null, null); + ControlContainer controlContainer = new ControlContainer(null, null, null, null, mockRateControl, null, null, null, null, null, null); assertEquals(mockRateControl, controlContainer.getRateControl()); } @@ -67,7 +67,7 @@ public void testGetRateControl() { @Test public void testGetSelectQuestionControl() { SelectQuestionControl mockSelectQuestionControl = mock(SelectQuestionControl.class); - ControlContainer controlContainer = new ControlContainer(null, null, null, null, null, mockSelectQuestionControl, null, null, null, null); + ControlContainer controlContainer = new ControlContainer(null, null, null, null, null, mockSelectQuestionControl, null, null, null, null, null); assertEquals(mockSelectQuestionControl, controlContainer.getSelectQuestionControl()); } @@ -77,7 +77,7 @@ public void testGetSelectQuestionControl() { @Test public void testGetUserLoginControl() { UserLoginControl mockUserLoginControl = mock(UserLoginControl.class); - ControlContainer controlContainer = new ControlContainer(null, null, null, null, null, null, mockUserLoginControl, null, null, null); + ControlContainer controlContainer = new ControlContainer(null, null, null, null, null, null, mockUserLoginControl, null, null, null, null); assertEquals(mockUserLoginControl, controlContainer.getUserLoginControl()); } @@ -87,21 +87,21 @@ public void testGetUserLoginControl() { @Test public void testGetViewQuestionControl() { ViewQuestionControl mockViewQuestionControl = mock(ViewQuestionControl.class); - ControlContainer controlContainer = new ControlContainer(null, null, null, null, null, null, null, mockViewQuestionControl, null, null); + ControlContainer controlContainer = new ControlContainer(null, null, null, null, null, null, null, mockViewQuestionControl, null, null, null); assertEquals(mockViewQuestionControl, controlContainer.getViewQuestionControl()); } @Test public void testGetBrowseQuestionControl() { ViewQuestionControl mockBrowseQuestionControl = mock(ViewQuestionControl.class); - ControlContainer controlContainer = new ControlContainer(null, null, null, null, null, null, null, null, mockBrowseQuestionControl, null); + ControlContainer controlContainer = new ControlContainer(null, null, null, null, null, null, null, null, mockBrowseQuestionControl, null, null); assertEquals(mockBrowseQuestionControl, controlContainer.getBrowseQuestionControl()); } @Test public void testGetRecommendationControl() { ViewQuestionControl mockRecommendationControl = mock(ViewQuestionControl.class); - ControlContainer controlContainer = new ControlContainer(null, null, null, null, null, null, null, null, null, mockRecommendationControl); + ControlContainer controlContainer = new ControlContainer(null, null, null, null, null, null, null, null, null, mockRecommendationControl, null); assertEquals(mockRecommendationControl, controlContainer.getRecommendationControl()); } } diff --git a/src/test/java/controllertesting/ClientRegisterControlTest.java b/src/test/java/controllertesting/RegisterControlTest.java similarity index 71% rename from src/test/java/controllertesting/ClientRegisterControlTest.java rename to src/test/java/controllertesting/RegisterControlTest.java index da149c57..4ffc74e3 100644 --- a/src/test/java/controllertesting/ClientRegisterControlTest.java +++ b/src/test/java/controllertesting/RegisterControlTest.java @@ -1,7 +1,8 @@ package controllertesting; -import adapters.controllers.ClientRegisterControl; +import adapters.controllers.RegisterControl; import usecases.inputboundary.UserRegisterInputBoundary; +import usecases.requests.ClientRegistrationData; import usecases.requests.RegistrationData; import usecases.responses.BaseResponseModel; @@ -13,7 +14,7 @@ /** * This class contains unit tests for the ClientRegisterControl class. */ -public class ClientRegisterControlTest { +public class RegisterControlTest { private static final String USER_NAME = "SampleUser"; private static final String EMAIL = "sample@example.com"; private static final String PASSWORD1 = "test password"; @@ -47,11 +48,20 @@ public void testCreateClientRegistration() { UserRegisterInputBoundary mockInputBoundary = mock(UserRegisterInputBoundary.class); when(mockInputBoundary.create(any(RegistrationData.class))).thenReturn(expectedResponse); - ClientRegisterControl control = new ClientRegisterControl(mockInputBoundary); + RegisterControl control = new RegisterControl(mockInputBoundary); + + RegistrationData data = new RegistrationData(USER_NAME, EMAIL, PASSWORD1, PASSWORD2, STATE_ABB, POSTAL_CODE); + ClientRegistrationData inputData = new ClientRegistrationData.Builder(data) + .age(AGE) + .annualIncome(ANNUAL_INCOME) + .gender(GENDER) + .maritalStatus(MARITAL_STATUS) + .numberOfHousehold(NUMBER_OF_HOUSEHOLD) + .ethnicity(ETHNICITY) + .build(); // Act - BaseResponseModel actualResponse = control.create(USER_NAME, EMAIL, PASSWORD1, PASSWORD2, STATE_ABB, - POSTAL_CODE, ETHNICITY, AGE, GENDER, MARITAL_STATUS, NUMBER_OF_HOUSEHOLD, ANNUAL_INCOME); + BaseResponseModel actualResponse = control.create(inputData); // Assert assertNotNull(actualResponse); diff --git a/src/test/java/entitytesting/ClientTest.java b/src/test/java/entitytesting/ClientTest.java index 4bbefcc1..6b00d269 100644 --- a/src/test/java/entitytesting/ClientTest.java +++ b/src/test/java/entitytesting/ClientTest.java @@ -1,5 +1,6 @@ package entitytesting; +import usecases.requests.ClientRegistrationData; import usecases.requests.RegistrationData; import entities.user.Client; import entities.Question; @@ -35,9 +36,16 @@ class ClientTest { @Test void testConstructorAndGetter() { // constructor - RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, - expectedPostalCode, expectedEthnicity, expectedAge, expectedGender, expectedMaritalStatus, - expectedNumberOfHousehold, expectedAnnualIncome); + RegistrationData data = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, + expectedPostalCode); + ClientRegistrationData registrationData = new ClientRegistrationData.Builder(data) + .age(expectedAge) + .annualIncome(expectedAnnualIncome) + .gender(expectedGender) + .maritalStatus(expectedMaritalStatus) + .numberOfHousehold(expectedNumberOfHousehold) + .ethnicity(expectedEthnicity) + .build(); ClientFactory clientFactory = new ClientFactory(); Client client = clientFactory.createUser(registrationData); client.setUserId(expectedUserId); @@ -101,9 +109,16 @@ void testSetters() { */ @Test void testClientIsQuestionCloseableSucceed() { - RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, - expectedPostalCode, expectedEthnicity, expectedAge, expectedGender, expectedMaritalStatus, - expectedNumberOfHousehold, expectedAnnualIncome); + RegistrationData data = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, + expectedPostalCode); + ClientRegistrationData registrationData = new ClientRegistrationData.Builder(data) + .age(expectedAge) + .annualIncome(expectedAnnualIncome) + .gender(expectedGender) + .maritalStatus(expectedMaritalStatus) + .numberOfHousehold(expectedNumberOfHousehold) + .ethnicity(expectedEthnicity) + .build(); ClientFactory clientFactory = new ClientFactory(); Client client = clientFactory.createUser(registrationData); @@ -118,9 +133,16 @@ void testClientIsQuestionCloseableSucceed() { */ @Test void testClientIsQuestionCloseableFail() { - RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, - expectedPostalCode, expectedEthnicity, expectedAge, expectedGender, expectedMaritalStatus, - expectedNumberOfHousehold, expectedAnnualIncome); + RegistrationData data = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, + expectedPostalCode); + ClientRegistrationData registrationData = new ClientRegistrationData.Builder(data) + .age(expectedAge) + .annualIncome(expectedAnnualIncome) + .gender(expectedGender) + .maritalStatus(expectedMaritalStatus) + .numberOfHousehold(expectedNumberOfHousehold) + .ethnicity(expectedEthnicity) + .build(); ClientFactory clientFactory = new ClientFactory(); Client client = clientFactory.createUser(registrationData); @@ -135,9 +157,16 @@ void testClientIsQuestionCloseableFail() { */ @Test void testClientIsQuestionSelectable() { - RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, - expectedPostalCode, expectedEthnicity, expectedAge, expectedGender, expectedMaritalStatus, - expectedNumberOfHousehold, expectedAnnualIncome); + RegistrationData data = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, + expectedPostalCode); + ClientRegistrationData registrationData = new ClientRegistrationData.Builder(data) + .age(expectedAge) + .annualIncome(expectedAnnualIncome) + .gender(expectedGender) + .maritalStatus(expectedMaritalStatus) + .numberOfHousehold(expectedNumberOfHousehold) + .ethnicity(expectedEthnicity) + .build(); ClientFactory clientFactory = new ClientFactory(); Client client = clientFactory.createUser(registrationData); Question question = new Question(); @@ -151,9 +180,16 @@ void testClientIsQuestionSelectable() { */ @Test void testClientIsQuestionReplyableSucceed() { - RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, - expectedPostalCode, expectedEthnicity, expectedAge, expectedGender, expectedMaritalStatus, - expectedNumberOfHousehold, expectedAnnualIncome); + RegistrationData data = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, + expectedPostalCode); + ClientRegistrationData registrationData = new ClientRegistrationData.Builder(data) + .age(expectedAge) + .annualIncome(expectedAnnualIncome) + .gender(expectedGender) + .maritalStatus(expectedMaritalStatus) + .numberOfHousehold(expectedNumberOfHousehold) + .ethnicity(expectedEthnicity) + .build(); ClientFactory clientFactory = new ClientFactory(); Client client = clientFactory.createUser(registrationData); @@ -169,9 +205,16 @@ void testClientIsQuestionReplyableSucceed() { */ @Test void testClientIsQuestionReplyableFail() { - RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, - expectedPostalCode, expectedEthnicity, expectedAge, expectedGender, expectedMaritalStatus, - expectedNumberOfHousehold, expectedAnnualIncome); + RegistrationData data = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, + expectedPostalCode); + ClientRegistrationData registrationData = new ClientRegistrationData.Builder(data) + .age(expectedAge) + .annualIncome(expectedAnnualIncome) + .gender(expectedGender) + .maritalStatus(expectedMaritalStatus) + .numberOfHousehold(expectedNumberOfHousehold) + .ethnicity(expectedEthnicity) + .build(); ClientFactory clientFactory = new ClientFactory(); Client client = clientFactory.createUser(registrationData); Question question = new Question(); @@ -186,9 +229,16 @@ void testClientIsQuestionReplyableFail() { */ @Test void testAddQuestion() { - RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, - expectedPostalCode, expectedEthnicity, expectedAge, expectedGender, expectedMaritalStatus, - expectedNumberOfHousehold, expectedAnnualIncome); + RegistrationData data = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, + expectedPostalCode); + ClientRegistrationData registrationData = new ClientRegistrationData.Builder(data) + .age(expectedAge) + .annualIncome(expectedAnnualIncome) + .gender(expectedGender) + .maritalStatus(expectedMaritalStatus) + .numberOfHousehold(expectedNumberOfHousehold) + .ethnicity(expectedEthnicity) + .build(); ClientFactory clientFactory = new ClientFactory(); Client client = clientFactory.createUser(registrationData); @@ -204,9 +254,16 @@ void testAddQuestion() { */ @Test void testHashCodeSucceed() { - RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, - expectedPostalCode, expectedEthnicity, expectedAge, expectedGender, expectedMaritalStatus, - expectedNumberOfHousehold, expectedAnnualIncome); + RegistrationData data = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, + expectedPostalCode); + ClientRegistrationData registrationData = new ClientRegistrationData.Builder(data) + .age(expectedAge) + .annualIncome(expectedAnnualIncome) + .gender(expectedGender) + .maritalStatus(expectedMaritalStatus) + .numberOfHousehold(expectedNumberOfHousehold) + .ethnicity(expectedEthnicity) + .build(); ClientFactory clientFactory = new ClientFactory(); Client client = clientFactory.createUser(registrationData); client.setUserId(expectedUserId); @@ -219,9 +276,16 @@ void testHashCodeSucceed() { */ @Test void testHashCodeFail() { - RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, - expectedPostalCode, expectedEthnicity, expectedAge, expectedGender, expectedMaritalStatus, - expectedNumberOfHousehold, expectedAnnualIncome); + RegistrationData data = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, + expectedPostalCode); + ClientRegistrationData registrationData = new ClientRegistrationData.Builder(data) + .age(expectedAge) + .annualIncome(expectedAnnualIncome) + .gender(expectedGender) + .maritalStatus(expectedMaritalStatus) + .numberOfHousehold(expectedNumberOfHousehold) + .ethnicity(expectedEthnicity) + .build(); ClientFactory clientFactory = new ClientFactory(); Client client = clientFactory.createUser(registrationData); @@ -233,12 +297,28 @@ void testHashCodeFail() { */ @Test void testEqualsFailByNotEqual() { - RegistrationData registrationData1 = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, - expectedPostalCode, expectedEthnicity, expectedAge, expectedGender, expectedMaritalStatus, - expectedNumberOfHousehold, expectedAnnualIncome); - RegistrationData registrationData2 = new RegistrationData("joseph", expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, - expectedPostalCode, expectedEthnicity, expectedAge, expectedGender, expectedMaritalStatus, - expectedNumberOfHousehold, expectedAnnualIncome); + RegistrationData data1 = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, + expectedPostalCode); + ClientRegistrationData registrationData1 = new ClientRegistrationData.Builder(data1) + .age(expectedAge) + .annualIncome(expectedAnnualIncome) + .gender(expectedGender) + .maritalStatus(expectedMaritalStatus) + .numberOfHousehold(expectedNumberOfHousehold) + .ethnicity(expectedEthnicity) + .build(); + + RegistrationData data2 = new RegistrationData("test", expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, + expectedPostalCode); + ClientRegistrationData registrationData2 = new ClientRegistrationData.Builder(data2) + .age(expectedAge) + .annualIncome(expectedAnnualIncome) + .gender(expectedGender) + .maritalStatus(expectedMaritalStatus) + .numberOfHousehold(expectedNumberOfHousehold) + .ethnicity(expectedEthnicity) + .build(); + ClientFactory clientFactory = new ClientFactory(); Client client1 = clientFactory.createUser(registrationData1); client1.setUserId(1); @@ -253,9 +333,16 @@ void testEqualsFailByNotEqual() { */ @Test void testToStringSucceed() { - RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, - expectedPostalCode, expectedEthnicity, expectedAge, expectedGender, expectedMaritalStatus, - expectedNumberOfHousehold, expectedAnnualIncome); + RegistrationData data = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, + expectedPostalCode); + ClientRegistrationData registrationData = new ClientRegistrationData.Builder(data) + .age(expectedAge) + .annualIncome(expectedAnnualIncome) + .gender(expectedGender) + .maritalStatus(expectedMaritalStatus) + .numberOfHousehold(expectedNumberOfHousehold) + .ethnicity(expectedEthnicity) + .build(); ClientFactory clientFactory = new ClientFactory(); Client client = clientFactory.createUser(registrationData); @@ -268,9 +355,16 @@ void testToStringSucceed() { */ @Test void testToStringFail() { - RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, - expectedPostalCode, expectedEthnicity, expectedAge, expectedGender, expectedMaritalStatus, - expectedNumberOfHousehold, expectedAnnualIncome); + RegistrationData data = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, + expectedPostalCode); + ClientRegistrationData registrationData = new ClientRegistrationData.Builder(data) + .age(expectedAge) + .annualIncome(expectedAnnualIncome) + .gender(expectedGender) + .maritalStatus(expectedMaritalStatus) + .numberOfHousehold(expectedNumberOfHousehold) + .ethnicity(expectedEthnicity) + .build(); ClientFactory clientFactory = new ClientFactory(); Client client = clientFactory.createUser(registrationData); @@ -283,9 +377,16 @@ void testToStringFail() { */ @Test void testIsQuestionRateableSucceed() { - RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, - expectedPostalCode, expectedEthnicity, expectedAge, expectedGender, expectedMaritalStatus, - expectedNumberOfHousehold, expectedAnnualIncome); + RegistrationData data = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, + expectedPostalCode); + ClientRegistrationData registrationData = new ClientRegistrationData.Builder(data) + .age(expectedAge) + .annualIncome(expectedAnnualIncome) + .gender(expectedGender) + .maritalStatus(expectedMaritalStatus) + .numberOfHousehold(expectedNumberOfHousehold) + .ethnicity(expectedEthnicity) + .build(); ClientFactory clientFactory = new ClientFactory(); Client client = clientFactory.createUser(registrationData); Question question = new Question(); @@ -298,9 +399,16 @@ void testIsQuestionRateableSucceed() { */ @Test void testIsQuestionRateableFail() { - RegistrationData registrationData = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, - expectedPostalCode, expectedEthnicity, expectedAge, expectedGender, expectedMaritalStatus, - expectedNumberOfHousehold, expectedAnnualIncome); + RegistrationData data = new RegistrationData(expectedName, expectedEmail, expectedPassword, expectedPassword2, expectedStateAbb, + expectedPostalCode); + ClientRegistrationData registrationData = new ClientRegistrationData.Builder(data) + .age(expectedAge) + .annualIncome(expectedAnnualIncome) + .gender(expectedGender) + .maritalStatus(expectedMaritalStatus) + .numberOfHousehold(expectedNumberOfHousehold) + .ethnicity(expectedEthnicity) + .build(); ClientFactory clientFactory = new ClientFactory(); Client client = clientFactory.createUser(registrationData); Question question = new Question(); diff --git a/src/test/java/factorytesting/ClientFactoryTest.java b/src/test/java/factorytesting/ClientFactoryTest.java index c97cdfba..f1f1f5a7 100644 --- a/src/test/java/factorytesting/ClientFactoryTest.java +++ b/src/test/java/factorytesting/ClientFactoryTest.java @@ -1,5 +1,6 @@ package factorytesting; +import usecases.requests.ClientRegistrationData; import usecases.requests.RegistrationData; import entities.user.Client; import entities.factories.ClientFactory; @@ -32,8 +33,15 @@ public void testCreate() { int numberOfHousehold = 1; float annualIncome = 50000.0f; - RegistrationData inputData = new RegistrationData(userName, email, password, password2, stateAbb, - postalCode, ethnicity, age, gender, maritalStatus, numberOfHousehold, annualIncome); + RegistrationData registrationData = new RegistrationData(userName, email, password, password2, stateAbb, + postalCode); + ClientRegistrationData inputData= new ClientRegistrationData.Builder(registrationData).age(age) + .annualIncome(annualIncome) + .ethnicity(ethnicity) + .gender(gender) + .maritalStatus(maritalStatus) + .numberOfHousehold(numberOfHousehold) + .build(); Client client = factory.createUser(inputData); client.setUserId(userId); diff --git a/src/test/java/gatewaytesting/AttorneyRepositoryTest.java b/src/test/java/gatewaytesting/AttorneyRepositoryTest.java index 7114c675..23327c1d 100644 --- a/src/test/java/gatewaytesting/AttorneyRepositoryTest.java +++ b/src/test/java/gatewaytesting/AttorneyRepositoryTest.java @@ -1,5 +1,6 @@ package gatewaytesting; +import usecases.requests.ClientRegistrationData; import usecases.requests.RegistrationData; import infrastructure.database.*; import entities.Question; @@ -71,7 +72,15 @@ public static void setUp() { int clientNumHouseHold = 1; float clientAnnualIncome = 100; - RegistrationData registrationData2 = new RegistrationData(clientUsername, clientEmail, clientPassword, clientPassword2, clientState, clientPostalCode, clientEthnicity, clientAge, clientGender, clientMaritalStatus, clientNumHouseHold, clientAnnualIncome); + RegistrationData data = new RegistrationData(clientUsername, clientEmail, clientPassword, clientPassword2, clientState, clientPostalCode); + ClientRegistrationData registrationData2 = new ClientRegistrationData.Builder(data) + .age(clientAge) + .annualIncome(clientAnnualIncome) + .gender(clientGender) + .maritalStatus(clientMaritalStatus) + .numberOfHousehold(clientNumHouseHold) + .ethnicity(clientEthnicity) + .build(); ClientFactory clientFactory = new ClientFactory(); Client c = clientFactory.createUser(registrationData2); @@ -264,8 +273,15 @@ public void testDeleteAllUser() { Attorney a1 = attorneyFactory.createUser(registrationData2); a.setUserId(attorneyId2); - RegistrationData registrationData3 = new RegistrationData("bob", "bob.bob@gmail.com", "bob123321", "bob123321", "ON", - "M1MA6A", "asian", 20, "Male", "Single", 1, 1000.0f); + RegistrationData data = new RegistrationData("bob", "bob.bob@gmail.com", "bob123321", "bob123321", "ON", "M1MA6A"); + ClientRegistrationData registrationData3 = new ClientRegistrationData.Builder(data) + .age(20) + .annualIncome(1000.0f) + .gender("Male") + .maritalStatus("Single") + .numberOfHousehold(1) + .ethnicity("asian") + .build(); ClientFactory clientFactory = new ClientFactory(); Client c = clientFactory.createUser(registrationData3); diff --git a/src/test/java/gatewaytesting/ClientRepositoryTest.java b/src/test/java/gatewaytesting/ClientRepositoryTest.java index bb383d55..0d7df38a 100644 --- a/src/test/java/gatewaytesting/ClientRepositoryTest.java +++ b/src/test/java/gatewaytesting/ClientRepositoryTest.java @@ -1,5 +1,6 @@ package gatewaytesting; +import usecases.requests.ClientRegistrationData; import usecases.requests.RegistrationData; import infrastructure.database.AttorneyRepository; import infrastructure.database.ClientRepository; @@ -54,7 +55,16 @@ public static void setUp() { int clientNumHouseHold = 1; float clientAnnualIncome = 100; - RegistrationData registrationData = new RegistrationData(clientName, clientEmail, clientPassword, clientPassword2, clientState, clientPostalCode, clientEthnicity, clientAge, clientGender, clientMaritalStatus, clientNumHouseHold, clientAnnualIncome); + RegistrationData data = new RegistrationData(clientName, clientEmail, clientPassword, clientPassword2, clientState, clientPostalCode); + ClientRegistrationData registrationData = new ClientRegistrationData.Builder(data) + .age(clientAge) + .annualIncome(clientAnnualIncome) + .gender(clientGender) + .maritalStatus(clientMaritalStatus) + .numberOfHousehold(clientNumHouseHold) + .ethnicity(clientEthnicity) + .build(); + ClientFactory clientFactory = new ClientFactory(); Client c = clientFactory.createUser(registrationData); @@ -167,7 +177,15 @@ public void testGetUser() { float clientAnnualIncome = 100; //constructors - RegistrationData registrationData = new RegistrationData(clientUsername, clientEmail, clientPassword, clientPassword2, clientState, clientPostalCode, clientEthnicity, clientAge, clientGender, clientMaritalStatus, clientNumHouseHold, clientAnnualIncome); + RegistrationData data = new RegistrationData(clientUsername, clientEmail, clientPassword, clientPassword2, clientState, clientPostalCode); + ClientRegistrationData registrationData = new ClientRegistrationData.Builder(data) + .age(clientAge) + .annualIncome(clientAnnualIncome) + .gender(clientGender) + .maritalStatus(clientMaritalStatus) + .numberOfHousehold(clientNumHouseHold) + .ethnicity(clientEthnicity) + .build(); ClientFactory clientFactory = new ClientFactory(); Client c = clientFactory.createUser(registrationData); @@ -200,7 +218,15 @@ public void testAddUser() { float clientAnnualIncome = 100; //constructors - RegistrationData registrationData = new RegistrationData(clientUsername, clientEmail, clientPassword, clientPassword2, clientState, clientPostalCode, clientEthnicity, clientAge, clientGender, clientMaritalStatus, clientNumHouseHold, clientAnnualIncome); + RegistrationData data = new RegistrationData(clientUsername, clientEmail, clientPassword, clientPassword2, clientState, clientPostalCode); + ClientRegistrationData registrationData = new ClientRegistrationData.Builder(data) + .age(clientAge) + .annualIncome(clientAnnualIncome) + .gender(clientGender) + .maritalStatus(clientMaritalStatus) + .numberOfHousehold(clientNumHouseHold) + .ethnicity(clientEthnicity) + .build(); ClientFactory clientFactory = new ClientFactory(); Client c = clientFactory.createUser(registrationData); @@ -234,7 +260,15 @@ public void testDeleteUser() { float clientAnnualIncome = 100; //constructors - RegistrationData registrationData = new RegistrationData(clientUsername, clientEmail, clientPassword, clientPassword2, clientState, clientPostalCode, clientEthnicity, clientAge, clientGender, clientMaritalStatus, clientNumHouseHold, clientAnnualIncome); + RegistrationData data = new RegistrationData(clientUsername, clientEmail, clientPassword, clientPassword2, clientState, clientPostalCode); + ClientRegistrationData registrationData = new ClientRegistrationData.Builder(data) + .age(clientAge) + .annualIncome(clientAnnualIncome) + .gender(clientGender) + .maritalStatus(clientMaritalStatus) + .numberOfHousehold(clientNumHouseHold) + .ethnicity(clientEthnicity) + .build(); ClientFactory clientFactory = new ClientFactory(); Client c = clientFactory.createUser(registrationData); @@ -274,12 +308,28 @@ public void testDeleteAllUser() { float clientAnnualIncome = 100; //constructors - RegistrationData registrationData = new RegistrationData(clientUsername, clientEmail, clientPassword, clientPassword2, clientState, clientPostalCode, clientEthnicity, clientAge, clientGender, clientMaritalStatus, clientNumHouseHold, clientAnnualIncome); + RegistrationData data = new RegistrationData(clientUsername, clientEmail, clientPassword, clientPassword2, clientState, clientPostalCode); + ClientRegistrationData registrationData = new ClientRegistrationData.Builder(data) + .age(clientAge) + .annualIncome(clientAnnualIncome) + .gender(clientGender) + .maritalStatus(clientMaritalStatus) + .numberOfHousehold(clientNumHouseHold) + .ethnicity(clientEthnicity) + .build(); ClientFactory clientFactory = new ClientFactory(); Client c = clientFactory.createUser(registrationData); c.setUserId(clientId); - RegistrationData registrationData2 = new RegistrationData(clientUsername, clientEmail, clientPassword, clientPassword2, clientState, clientPostalCode, clientEthnicity, clientAge, clientGender, clientMaritalStatus, clientNumHouseHold, clientAnnualIncome); + + ClientRegistrationData registrationData2 = new ClientRegistrationData.Builder(data) + .age(clientAge) + .annualIncome(clientAnnualIncome) + .gender(clientGender) + .maritalStatus(clientMaritalStatus) + .numberOfHousehold(clientNumHouseHold) + .ethnicity(clientEthnicity) + .build(); Client c1 = clientFactory.createUser(registrationData2); c1.setUserId(clientId2); diff --git a/src/test/java/usecasetesting/ClientRegisterUseCaseTest.java b/src/test/java/usecasetesting/ClientRegisterUseCaseTest.java index 390c9672..5de41192 100644 --- a/src/test/java/usecasetesting/ClientRegisterUseCaseTest.java +++ b/src/test/java/usecasetesting/ClientRegisterUseCaseTest.java @@ -3,6 +3,7 @@ import usecases.gateway.ClientGateway; import usecases.inputboundary.UserRegisterInputBoundary; import usecases.outputboundary.BaseOutputBoundary; +import usecases.requests.ClientRegistrationData; import usecases.requests.RegistrationData; import usecases.responses.BaseResponseModel; import usecases.interactors.ClientRegisterInteractor; @@ -52,7 +53,7 @@ public BaseResponseModel prepareFail(String msg) { } }; - clientRegisterInputBoundary = new ClientRegisterInteractor(clientGateway, clientFactory, baseOutputBoundary); + clientRegisterInputBoundary = new ClientRegisterInteractor(clientGateway, baseOutputBoundary, clientFactory); } @@ -63,7 +64,15 @@ public BaseResponseModel prepareFail(String msg) { public void TestSuccessfulRegistration(){ setUpClientRegisterUseCase(); - RegistrationData inputData = new RegistrationData(USER_NAME, EMAIL, PASSWORD, PASSWORD2, STATE_ABB, POSTALCODE, ETHNICITY, AGE, GENDER, MARITAL_STATUS, NUMBER_OF_HOUSEHOLD, ANNUAL_INCOME); + RegistrationData data = new RegistrationData(USER_NAME, EMAIL, PASSWORD, PASSWORD2, STATE_ABB, POSTALCODE); + ClientRegistrationData inputData = new ClientRegistrationData.Builder(data) + .age(AGE) + .annualIncome(ANNUAL_INCOME) + .gender(GENDER) + .maritalStatus(MARITAL_STATUS) + .numberOfHousehold(NUMBER_OF_HOUSEHOLD) + .ethnicity(ETHNICITY) + .build(); clientRegisterInputBoundary.create(inputData); ClearAllRepository(); @@ -76,7 +85,15 @@ public void TestSuccessfulRegistration(){ public void TestRegistrationFailByAlreadyExists(){ setUpClientRegisterUseCase(); - RegistrationData inputData = new RegistrationData(USER_NAME, EMAIL, PASSWORD, PASSWORD2, STATE_ABB, POSTALCODE, ETHNICITY, AGE, GENDER, MARITAL_STATUS, NUMBER_OF_HOUSEHOLD, ANNUAL_INCOME); + RegistrationData data = new RegistrationData(USER_NAME, EMAIL, PASSWORD, PASSWORD2, STATE_ABB, POSTALCODE); + ClientRegistrationData inputData = new ClientRegistrationData.Builder(data) + .age(AGE) + .annualIncome(ANNUAL_INCOME) + .gender(GENDER) + .maritalStatus(MARITAL_STATUS) + .numberOfHousehold(NUMBER_OF_HOUSEHOLD) + .ethnicity(ETHNICITY) + .build(); clientRegisterInputBoundary.create(inputData); clientRegisterInputBoundary.create(inputData); @@ -90,7 +107,15 @@ public void TestRegistrationFailByAlreadyExists(){ public void TestRegistrationFailByPasswordDoesNotMatch(){ setUpClientRegisterUseCase(); - RegistrationData inputData = new RegistrationData(USER_NAME, EMAIL, PASSWORD, "a", STATE_ABB, POSTALCODE, ETHNICITY, AGE, GENDER, MARITAL_STATUS, NUMBER_OF_HOUSEHOLD, ANNUAL_INCOME); + RegistrationData data = new RegistrationData(USER_NAME, EMAIL, PASSWORD, "a", STATE_ABB, POSTALCODE); + ClientRegistrationData inputData = new ClientRegistrationData.Builder(data) + .age(AGE) + .annualIncome(ANNUAL_INCOME) + .gender(GENDER) + .maritalStatus(MARITAL_STATUS) + .numberOfHousehold(NUMBER_OF_HOUSEHOLD) + .ethnicity(ETHNICITY) + .build(); clientRegisterInputBoundary.create(inputData); ClearAllRepository(); } @@ -102,7 +127,15 @@ public void TestRegistrationFailByPasswordDoesNotMatch(){ public void TestRegistrationFailByPasswordLengthTooSmall(){ setUpClientRegisterUseCase(); - RegistrationData inputData = new RegistrationData(USER_NAME, EMAIL, "a", "a", STATE_ABB, POSTALCODE, ETHNICITY, AGE, GENDER, MARITAL_STATUS, NUMBER_OF_HOUSEHOLD, ANNUAL_INCOME); + RegistrationData data = new RegistrationData(USER_NAME, EMAIL, "a", "a", STATE_ABB, POSTALCODE); + ClientRegistrationData inputData = new ClientRegistrationData.Builder(data) + .age(AGE) + .annualIncome(ANNUAL_INCOME) + .gender(GENDER) + .maritalStatus(MARITAL_STATUS) + .numberOfHousehold(NUMBER_OF_HOUSEHOLD) + .ethnicity(ETHNICITY) + .build(); clientRegisterInputBoundary.create(inputData); ClearAllRepository(); @@ -115,8 +148,15 @@ public void TestRegistrationFailByPasswordLengthTooSmall(){ public void TestRegistrationFailByInvalidEmail(){ setUpClientRegisterUseCase(); - RegistrationData inputData = new RegistrationData(USER_NAME, "abcd", PASSWORD, PASSWORD2, STATE_ABB, POSTALCODE, ETHNICITY, AGE, GENDER, MARITAL_STATUS, NUMBER_OF_HOUSEHOLD, ANNUAL_INCOME); - + RegistrationData data = new RegistrationData(USER_NAME, "abcd", PASSWORD, PASSWORD2, STATE_ABB, POSTALCODE); + ClientRegistrationData inputData = new ClientRegistrationData.Builder(data) + .age(AGE) + .annualIncome(ANNUAL_INCOME) + .gender(GENDER) + .maritalStatus(MARITAL_STATUS) + .numberOfHousehold(NUMBER_OF_HOUSEHOLD) + .ethnicity(ETHNICITY) + .build(); clientRegisterInputBoundary.create(inputData); ClearAllRepository(); } @@ -128,7 +168,15 @@ public void TestRegistrationFailByInvalidEmail(){ public void TestRegistrationFailByInvalidAge(){ setUpClientRegisterUseCase(); - RegistrationData inputData = new RegistrationData(USER_NAME, EMAIL, PASSWORD, PASSWORD2, STATE_ABB, POSTALCODE, ETHNICITY, 300, GENDER, MARITAL_STATUS, NUMBER_OF_HOUSEHOLD, ANNUAL_INCOME); + RegistrationData data = new RegistrationData(USER_NAME, EMAIL, PASSWORD, PASSWORD2, STATE_ABB, POSTALCODE); + ClientRegistrationData inputData = new ClientRegistrationData.Builder(data) + .age(300) + .annualIncome(ANNUAL_INCOME) + .gender(GENDER) + .maritalStatus(MARITAL_STATUS) + .numberOfHousehold(NUMBER_OF_HOUSEHOLD) + .ethnicity(ETHNICITY) + .build(); clientRegisterInputBoundary.create(inputData); ClearAllRepository(); @@ -141,7 +189,15 @@ public void TestRegistrationFailByInvalidAge(){ public void TestRegistrationFailByInvalidPostalCode(){ setUpClientRegisterUseCase(); - RegistrationData inputData = new RegistrationData(USER_NAME, EMAIL, PASSWORD, PASSWORD2, STATE_ABB, "test code", ETHNICITY, AGE, GENDER, MARITAL_STATUS, NUMBER_OF_HOUSEHOLD, ANNUAL_INCOME); + RegistrationData data = new RegistrationData(USER_NAME, EMAIL, PASSWORD, PASSWORD2, STATE_ABB, "test code"); + ClientRegistrationData inputData = new ClientRegistrationData.Builder(data) + .age(AGE) + .annualIncome(ANNUAL_INCOME) + .gender(GENDER) + .maritalStatus(MARITAL_STATUS) + .numberOfHousehold(NUMBER_OF_HOUSEHOLD) + .ethnicity(ETHNICITY) + .build(); clientRegisterInputBoundary.create(inputData); ClearAllRepository();