Class RequestService

java.lang.Object
com.inesm.KeyManager.services.OperationService
com.inesm.KeyManager.services.RequestService

@Service public class RequestService extends OperationService
Provides methods to perform operations on requests.
  • Method Details

    • create

      public long create(User user, int operationID, Resource data) throws InvalidParametersException
      Creates a new request.
      Parameters:
      user - the user that issued the operation
      operationID - the operationID of the operation
      data - 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

      public long createFromMessage(Message message) throws InvalidParametersException
      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

      public List<Request> getRequestsForUser(User user)
      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

      public void denyRequest(Request req, User currentUser) throws ObjectNotFoundException
      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) set
      currentUser - the use who accepted the request
      intercepted - the flag indicating that this request cannot be executed and was instead transformed into a message
      Throws:
      InvalidParametersException - if the request received contained invalid parameters
      OperationProcessException - if the operation processed after accepting the request had an error
      ObjectNotFoundException - if the request specified could not be found
    • getRequestByID

      public Request getRequestByID(long requestID) throws ObjectNotFoundException
      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

      public Request getUpdatedRequest(Request update) throws ObjectNotFoundException
      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

      public List<Request> getRequestsIssueByUser(User user)
      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 set
      operationID - the operationID of the operation
      Throws:
      ObjectNotFoundException - if the username could not be found
      InvalidParametersException - if the request contained invalid parameters
    • deleteRequest

      public void deleteRequest(long requestID) throws ObjectNotFoundException
      Deletes a request from the database.
      Parameters:
      requestID - the requestID of the request
      Throws:
      ObjectNotFoundException - if the request could not be found