Class WorkerMutationServiceImpl

java.lang.Object
it.univr.passportease.service.worker.impl.WorkerMutationServiceImpl
All Implemented Interfaces:
WorkerMutationService

@Service public class WorkerMutationServiceImpl extends Object implements WorkerMutationService
Implementation of WorkerMutationService. Provides methods to create, modify and delete requests.
  • Field Details

  • Constructor Details

    • WorkerMutationServiceImpl

      public WorkerMutationServiceImpl()
  • Method Details

    • getNotification

      @NotNull private static @NotNull Notification getNotification(Request request, Availability availability)
      Get notification for user that his request has been deleted.
      Parameters:
      request - request
      availability - availability
      Returns:
      notification for user that his request has been deleted
    • createRequest

      @PreAuthorize("hasAuthority(\'WORKER\') && hasAuthority(\'VALIDATED\')") public Request createRequest(JWT token, RequestInput requestInput) throws WorkerNotFoundException, InvalidRequestTypeException, OfficeOverloadedException
      Create request.
      Specified by:
      createRequest in interface WorkerMutationService
      Parameters:
      token - jwt access token
      requestInput - request input, contains request data as RequestInput
      Returns:
      created request as Request
      Throws:
      WorkerNotFoundException - if worker is not found
      InvalidRequestTypeException - if request type is invalid
      OfficeOverloadedException - if office doesn't have enough workers
    • getOrCreateRequestType

      private RequestType getOrCreateRequestType(String requestTypeName) throws InvalidRequestTypeException
      Get request type if exists, otherwise create it and return it.
      Parameters:
      requestTypeName - request type name
      Returns:
      request type if exists, otherwise create it and return it
      Throws:
      InvalidRequestTypeException - if request type is invalid
    • isWorkersNotEnoughForRequest

      private boolean isWorkersNotEnoughForRequest(RequestInput requestInput, List<Office> offices)
      Check if there are not enough workers for the request, by checking if there are more requests than workers in each office.
      Parameters:
      requestInput - request input, contains request data as RequestInput
      offices - offices
      Returns:
      true if there are not enough workers for the request, otherwise false
    • countBusyWorkersInOffice

      private long countBusyWorkersInOffice(Office office, RequestInput requestInput)
      Count busy workers in office, between start and end date and time. It does it by counting the number of requests in the office that are between start and end date and time.
      Parameters:
      office - office
      requestInput - request input, contains request data as RequestInput
      Returns:
      number of busy workers in office, between start and end date and time. It does it by counting the number of requests in the office that are between start and end date and time.
    • setNotifications

      private void setNotifications(Date startDate, Date endDate, List<Office> offices, RequestType requestType)
      Set notifications as ready = true if they are between start and end date and time and ready = false otherwise.
      Parameters:
      startDate - start date
      endDate - end date
      offices - offices
      requestType - request type
    • createAvailabilities

      private void createAvailabilities(Date startDate, Date endDate, List<Office> offices, Request request)
      Create availabilities for each office between start and end date and time.
      Parameters:
      startDate - start date
      endDate - end date
      offices - offices
      request - request
    • processOfficeWorkingDays

      private void processOfficeWorkingDays(Day day, List<OfficeWorkingDay> officeWorkingDays, LocalDate date, Request request)
      Process office working days for a specific day. By processing it means to create availabilities for each office working day between start and end date and time.
      Parameters:
      day - day
      officeWorkingDays - office working days
      date - date
      request - request
    • processOfficeWorkingDayTimeSlot

      private void processOfficeWorkingDayTimeSlot(OfficeWorkingDay officeWorkingDay, LocalDate date, Request request)
      Process office working day time slot. By processing it means to create availabilities for each office working day time slot between start and end time.
      Parameters:
      officeWorkingDay - office working day
      date - date
      request - request
    • getHigherTime

      private LocalTime getHigherTime(LocalTime time1, LocalTime time2)
      Get higher time between time 1 and time 2, that is the time that is after the other.
      Parameters:
      time1 - time 1, used as office start time
      time2 - time 2, used as request start time
      Returns:
      higher time between time 1 and time 2, that is the time that is after the other
    • getLowerTime

      private LocalTime getLowerTime(LocalTime time1, LocalTime time2)
      Get lower time between time 1 and time 2, that is the time that is before the other.
      Parameters:
      time1 - time 1, used as office end time
      time2 - time 2, used as request end time
      Returns:
      lower time between time 1 and time 2, that is the time that is before the other
    • isRequestDateInsideNotificationDate

      private boolean isRequestDateInsideNotificationDate(Date requestStartDate, Date requestEndDate, Date notificationStartDate, Date notificationEndDate)
      Check if request date is inside notification date, by checking if the range of request date is inside the range of notification date. Similar to isTimeInsideTime(LocalTime, LocalTime, LocalTime, LocalTime).
      Parameters:
      requestStartDate - request start date
      requestEndDate - request end date
      notificationStartDate - notification start date
      notificationEndDate - notification end date
      Returns:
      true if request date is inside notification date, otherwise false
    • isTimeInsideTime

      private boolean isTimeInsideTime(LocalTime requestStartTime, LocalTime requestEndTime, LocalTime startTime, LocalTime endTime)
      Check if request time is inside office time, by checking if the range of request time is inside the range of office time. Similar to isRequestDateInsideNotificationDate(Date, Date, Date, Date).
      Parameters:
      requestStartTime - request start time
      requestEndTime - request end time
      startTime - office start time
      endTime - office end time
      Returns:
      true if request time is inside office time, otherwise false
    • modifyRequest

      public Request modifyRequest(JWT token, String requestID, RequestInput requestInput) throws WorkerNotFoundException, RequestNotFoundException, OfficeOverloadedException
      Modify request.
      Specified by:
      modifyRequest in interface WorkerMutationService
      Parameters:
      token - jwt access token
      requestID - request id
      requestInput - request input, contains request data as RequestInput
      Returns:
      modified request as Request
      Throws:
      WorkerNotFoundException - if worker is not found
      RequestNotFoundException - if request is not found
      OfficeOverloadedException - if office doesn't have enough workers
    • deleteRequest

      public void deleteRequest(JWT token, String requestID) throws WorkerNotFoundException, RequestNotFoundException
      Delete request.
      Specified by:
      deleteRequest in interface WorkerMutationService
      Parameters:
      token - jwt access token
      requestID - request id
      Throws:
      WorkerNotFoundException - if worker is not found
      RequestNotFoundException - if request is not found
    • deleteAvailabilities

      private void deleteAvailabilities(Request request)
      Delete availabilities and requestOffice associated to a request.
      Parameters:
      request - request