Class WorkerMutationServiceImpl
java.lang.Object
it.univr.passportease.service.worker.impl.WorkerMutationServiceImpl
- All Implemented Interfaces:
WorkerMutationService
Implementation of
WorkerMutationService
. Provides methods to create, modify and delete requests.-
Field Summary
Modifier and TypeFieldDescriptionprivate final AvailabilityRepository
Repository forAvailability
entity.private final JwtService
JWT service to extract worker id from jwt access token.private final MapAvailability
Service to mapRequest
toAvailability
.private final MapRequest
Service to mapRequestInput
toRequest
.private final MapRequestOffice
private final MapRequestType
Service to mapString
toRequestType
.private final NotificationRepository
Repository forNotification
entity.private final OfficeRepository
Repository forOffice
entity.private final OfficeWorkingDayRepository
Repository forOfficeWorkingDay
entity.private final RequestOfficeRepository
Repository forRequestOffice
entity.private final RequestRepository
Repository forRequest
entity.private final RequestTypeRepository
Repository forRequestType
entity.private final WorkerRepository
Repository forWorker
entity. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate long
countBusyWorkersInOffice
(Office office, RequestInput requestInput) Count busy workers in office, between start and end date and time.private void
Create availabilities for each office between start and end date and time.createRequest
(JWT token, RequestInput requestInput) Create request.private void
deleteAvailabilities
(Request request) Delete availabilities and requestOffice associated to a request.void
deleteRequest
(JWT token, String requestID) Delete request.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.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.private static @NotNull Notification
getNotification
(Request request, Availability availability) Get notification for user that his request has been deleted.private RequestType
getOrCreateRequestType
(String requestTypeName) Get request type if exists, otherwise create it and return it.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.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.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.modifyRequest
(JWT token, String requestID, RequestInput requestInput) Modify request.private void
processOfficeWorkingDays
(Day day, List<OfficeWorkingDay> officeWorkingDays, LocalDate date, Request request) Process office working days for a specific day.private void
processOfficeWorkingDayTimeSlot
(OfficeWorkingDay officeWorkingDay, LocalDate date, Request request) Process office working day time slot.private void
setNotifications
(Date startDate, Date endDate, List<Office> offices, RequestType requestType) Set notifications asready = true
if they are between start and end date and time andready = false
otherwise.
-
Field Details
-
jwtService
JWT service to extract worker id from jwt access token. -
workerRepository
Repository forWorker
entity. -
requestTypeRepository
Repository forRequestType
entity. -
requestRepository
Repository forRequest
entity. -
availabilityRepository
Repository forAvailability
entity. -
officeRepository
Repository forOffice
entity. -
officeWorkingDayRepository
Repository forOfficeWorkingDay
entity. -
requestOfficeRepository
Repository forRequestOffice
entity. -
notificationRepository
Repository forNotification
entity. -
mapRequest
Service to mapRequestInput
toRequest
. -
mapRequestType
Service to mapString
toRequestType
. -
mapRequestOffice
-
mapAvailability
Service to mapRequest
toAvailability
.
-
-
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
- requestavailability
- 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 interfaceWorkerMutationService
- Parameters:
token
- jwt access tokenrequestInput
- request input, contains request data asRequestInput
- Returns:
- created request as
Request
- Throws:
WorkerNotFoundException
- if worker is not foundInvalidRequestTypeException
- if request type is invalidOfficeOverloadedException
- 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
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 asRequestInput
offices
- offices- Returns:
true
if there are not enough workers for the request, otherwisefalse
-
countBusyWorkersInOffice
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
- officerequestInput
- request input, contains request data asRequestInput
- 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 asready = true
if they are between start and end date and time andready = false
otherwise.- Parameters:
startDate
- start dateendDate
- end dateoffices
- officesrequestType
- 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 dateendDate
- end dateoffices
- officesrequest
- 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
- dayofficeWorkingDays
- office working daysdate
- daterequest
- 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 daydate
- daterequest
- request
-
getHigherTime
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 timetime2
- 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
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 timetime2
- 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 toisTimeInsideTime(LocalTime, LocalTime, LocalTime, LocalTime)
.- Parameters:
requestStartDate
- request start daterequestEndDate
- request end datenotificationStartDate
- notification start datenotificationEndDate
- notification end date- Returns:
true
if request date is inside notification date, otherwisefalse
-
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 toisRequestDateInsideNotificationDate(Date, Date, Date, Date)
.- Parameters:
requestStartTime
- request start timerequestEndTime
- request end timestartTime
- office start timeendTime
- office end time- Returns:
true
if request time is inside office time, otherwisefalse
-
modifyRequest
public Request modifyRequest(JWT token, String requestID, RequestInput requestInput) throws WorkerNotFoundException, RequestNotFoundException, OfficeOverloadedException Modify request.- Specified by:
modifyRequest
in interfaceWorkerMutationService
- Parameters:
token
- jwt access tokenrequestID
- request idrequestInput
- request input, contains request data asRequestInput
- Returns:
- modified request as
Request
- Throws:
WorkerNotFoundException
- if worker is not foundRequestNotFoundException
- if request is not foundOfficeOverloadedException
- if office doesn't have enough workers
-
deleteRequest
public void deleteRequest(JWT token, String requestID) throws WorkerNotFoundException, RequestNotFoundException Delete request.- Specified by:
deleteRequest
in interfaceWorkerMutationService
- Parameters:
token
- jwt access tokenrequestID
- request id- Throws:
WorkerNotFoundException
- if worker is not foundRequestNotFoundException
- if request is not found
-
deleteAvailabilities
Delete availabilities and requestOffice associated to a request.- Parameters:
request
- request
-