Package com.inesm.KeyManager.services
Class RequestService
java.lang.Object
com.inesm.KeyManager.services.OperationService
com.inesm.KeyManager.services.RequestService
Provides methods to perform operations on requests.
-
Method Summary
Modifier and TypeMethodDescriptionvoidacceptRequest(Request req, User currentUser, boolean intercepted) Accepts a Request.longCreates a new request.longcreateFromMessage(Message message) Creates a request from a message.voidcreatePasswordRequest(Request req, int operationID) Creates a password request.voiddeleteRequest(long requestID) Deletes a request from the database.voiddenyRequest(Request req, User currentUser) Denies a request.getRequestByID(long requestID) Gets a request from the database.getRequestsForUser(User user) Gets a request for a given user.getRequestsIssueByUser(User user) Gets all requests issued by a given user.getUpdatedRequest(Request update) Gets a request from the database and updates the reason field (if provided).
-
Method Details
-
create
Creates a new request.- Parameters:
user- the user that issued the operationoperationID- the operationID of the operationdata- the input data of the operation- Returns:
- the requestID of the created request
- Throws:
InvalidParametersException- if there where invalid fields in any of the parameters provided
-
createFromMessage
Creates a request from a message.- Parameters:
message- the message to be converted into a request- Returns:
- the requestID of the created request
- Throws:
InvalidParametersException- if the message contained invalid parameters
-
getRequestsForUser
Gets a request for a given user. Will select the requests to display based on the user set of permissions.- Parameters:
user- the user selected, not null, must have roleID set- Returns:
- a list containing the requests for the selected user
-
denyRequest
Denies a request. Updates the state of the request, reason and verifier.- Parameters:
req- the request to be denied, not null, must have requestID, status, verifierFullname,verifierCitizenCard, and (optionally) reason set.currentUser- the user performing the request denial- Throws:
ObjectNotFoundException- if the request referenced could not be found
-
acceptRequest
public void acceptRequest(Request req, User currentUser, boolean intercepted) throws InvalidParametersException, OperationProcessException, ObjectNotFoundException Accepts a Request. Updates state of request upon execution, reason and verifier.- Parameters:
req- the request to be accepted, not null, must have requestID, verifier and reason (optionally) setcurrentUser- the use who accepted the requestintercepted- the flag indicating that this request cannot be executed and was instead transformed into a message- Throws:
InvalidParametersException- if the request received contained invalid parametersOperationProcessException- if the operation processed after accepting the request had an errorObjectNotFoundException- if the request specified could not be found
-
getRequestByID
Gets a request from the database.- Parameters:
requestID- the requestID of the request- Returns:
- the retrieved request
- Throws:
ObjectNotFoundException- if the request could not be found
-
getUpdatedRequest
Gets a request from the database and updates the reason field (if provided).- Parameters:
update- the request to be updated, not null, must have requestID and reason (optionally) set- Returns:
- the updated request
- Throws:
ObjectNotFoundException- if the request specified could not be found
-
getRequestsIssueByUser
Gets all requests issued by a given user.- Parameters:
user- the user, not null, must have userCitizenCard set- Returns:
- the list containing the retrieved requests
-
createPasswordRequest
public void createPasswordRequest(Request req, int operationID) throws ObjectNotFoundException, InvalidParametersException Creates a password request.- Parameters:
req- the request object, not null, must have username setoperationID- the operationID of the operation- Throws:
ObjectNotFoundException- if the username could not be foundInvalidParametersException- if the request contained invalid parameters
-
deleteRequest
Deletes a request from the database.- Parameters:
requestID- the requestID of the request- Throws:
ObjectNotFoundException- if the request could not be found
-