- java.lang.Object
-
- models.Request
-
- Direct Known Subclasses:
AllocateProjectRequest
,ChangeProjectTitleRequest
,DeregisterProjectRequest
,TransferStudentRequest
public abstract class Request extends java.lang.Object
The abstract classRequest
represents a request made by a user to a supervisor or FYP coordinator to perform a certain action on a project. Each request has a unique ID, type, status, sender and receiver IDs, project ID, and a history of status changes. This is an abstract class and therefore cannot be instantiated directly. Subclasses that represent specific types of requests must be created.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayList<java.lang.String>
history
The history of the status changes of the request.private static int
lastRequestID
The ID of the last request created.private int
projectID
The ID of the project associated with the request.private java.lang.String
receiverID
The ID of the receiver of the request.private int
requestID
The ID of the request.private java.lang.String
senderID
The ID of the sender making the request.private RequestStatus
status
The status of the request.private RequestType
type
The type of request.
-
Constructor Summary
Constructors Constructor Description Request(java.lang.String senderID, java.lang.String receiverID, int projectID)
Constructs a newRequest
object with a new request ID, pending status, empty history, sender ID, receiver ID, and project ID.Request(java.lang.String senderID, java.lang.String receiverID, int projectID, int requestID, RequestStatus status, java.util.ArrayList<java.lang.String> history)
Constructs aRequest
object with existing request ID, status, history, sender ID, receiver ID, and project ID.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addHistory(java.util.Date date, RequestStatus status)
Adds a status change to the history of the request.boolean
approve()
Changes the status of the request to APPROVED and updates the request history.private java.lang.String
formatHistory(java.util.Date date, RequestStatus status)
Returns a string representation of the status change with the given date and status.java.util.ArrayList<java.lang.String>
getHistory()
Returns the history of status changes of the request.Project
getProject()
Returns the project associated with the request.User
getReceiver()
Returns the receiver of the request.int
getRequestID()
Returns the ID of the request.User
getSender()
Returns the sender of the request.RequestStatus
getStatus()
Returns the status of the request.RequestType
getType()
Returns the type of the request.boolean
reject()
Changes the status of the request to REJECTED and updates the request history.boolean
setHistory(java.util.ArrayList<java.lang.String> history)
Sets the history of status changes of the request.boolean
setStatus(RequestStatus status)
Sets the status of the request.boolean
setType(RequestType type)
Sets the type of the request.
-
-
-
Field Detail
-
lastRequestID
private static int lastRequestID
The ID of the last request created.
-
requestID
private int requestID
The ID of the request.
-
type
private RequestType type
The type of request.
-
status
private RequestStatus status
The status of the request.
-
history
private java.util.ArrayList<java.lang.String> history
The history of the status changes of the request.
-
senderID
private java.lang.String senderID
The ID of the sender making the request.
-
receiverID
private java.lang.String receiverID
The ID of the receiver of the request.
-
projectID
private int projectID
The ID of the project associated with the request.
-
-
Constructor Detail
-
Request
public Request(java.lang.String senderID, java.lang.String receiverID, int projectID, int requestID, RequestStatus status, java.util.ArrayList<java.lang.String> history)
Constructs aRequest
object with existing request ID, status, history, sender ID, receiver ID, and project ID. This is for initializing existing requests- Parameters:
senderID
- the ID of the sender making the requestreceiverID
- the ID of the receiver of the requestprojectID
- the ID of the project associated with the requestrequestID
- the ID of the request itselfstatus
- the status of the requesthistory
- the history of the status changes of the request
-
Request
public Request(java.lang.String senderID, java.lang.String receiverID, int projectID)
Constructs a newRequest
object with a new request ID, pending status, empty history, sender ID, receiver ID, and project ID. This is for creating new requests- Parameters:
senderID
- the ID of the sender making the requestreceiverID
- the ID of the receiver of the requestprojectID
- the ID of the project associated with the request
-
-
Method Detail
-
approve
public boolean approve()
Changes the status of the request to APPROVED and updates the request history.- Returns:
- true if the status of the request is updated successfully in the data store, false otherwise
-
reject
public boolean reject()
Changes the status of the request to REJECTED and updates the request history.- Returns:
- true if the status of the request is updated successfully in the data store, false otherwise
-
getRequestID
public int getRequestID()
Returns the ID of the request.- Returns:
- the request ID
-
getType
public RequestType getType()
Returns the type of the request.- Returns:
- the request type
-
setType
public boolean setType(RequestType type)
Sets the type of the request.- Parameters:
type
- theRequestType
to set- Returns:
- true if the request type is set successfully, false otherwise
-
getStatus
public RequestStatus getStatus()
Returns the status of the request.- Returns:
- the
RequestStatus
-
setStatus
public boolean setStatus(RequestStatus status)
Sets the status of the request.- Parameters:
status
- theRequestStatus
to set- Returns:
- true if the request status is set successfully, false otherwise
-
getSender
public User getSender()
Returns the sender of the request.- Returns:
- the sender of the request as a
User
object, null if the sender ID is invalid or not found
-
getReceiver
public User getReceiver()
Returns the receiver of the request.- Returns:
- the receiver of the request as a
User
object, null if the receiver ID is invalid or not found
-
getProject
public Project getProject()
Returns the project associated with the request.- Returns:
- the project of the request as a
Project
object, null if the project ID is invalid or not found
-
getHistory
public java.util.ArrayList<java.lang.String> getHistory()
Returns the history of status changes of the request.- Returns:
- the history of the request
-
setHistory
public boolean setHistory(java.util.ArrayList<java.lang.String> history)
Sets the history of status changes of the request.- Parameters:
history
- the history of the request to set- Returns:
- true if the history of the request is set successfully, false otherwise
-
addHistory
public boolean addHistory(java.util.Date date, RequestStatus status)
Adds a status change to the history of the request.- Parameters:
date
- the date of the status changestatus
- the status after the change- Returns:
- true if the status change is added successfully to the history, false otherwise
-
formatHistory
private java.lang.String formatHistory(java.util.Date date, RequestStatus status)
Returns a string representation of the status change with the given date and status.- Parameters:
date
- the date of the status changestatus
- the status after the change- Returns:
- a formatted string with the date and status
-
-