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
FieldsModifier and TypeFieldDescriptionprivate final AvailabilityRepositoryRepository forAvailabilityentity.private final JwtServiceJWT service to extract worker id from jwt access token.private final MapAvailabilityService to mapRequesttoAvailability.private final MapRequestService to mapRequestInputtoRequest.private final MapRequestOfficeprivate final MapRequestTypeService to mapStringtoRequestType.private final NotificationRepositoryRepository forNotificationentity.private final OfficeRepositoryRepository forOfficeentity.private final OfficeWorkingDayRepositoryRepository forOfficeWorkingDayentity.private final RequestOfficeRepositoryRepository forRequestOfficeentity.private final RequestRepositoryRepository forRequestentity.private final RequestTypeRepositoryRepository forRequestTypeentity.private final WorkerRepositoryRepository forWorkerentity. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate longcountBusyWorkersInOffice(Office office, RequestInput requestInput) Count busy workers in office, between start and end date and time.private voidCreate availabilities for each office between start and end date and time.createRequest(JWT token, RequestInput requestInput) Create request.private voiddeleteAvailabilities(Request request) Delete availabilities and requestOffice associated to a request.voiddeleteRequest(JWT token, String requestID) Delete request.private LocalTimegetHigherTime(LocalTime time1, LocalTime time2) Get higher time between time 1 and time 2, that is the time that is after the other.private LocalTimegetLowerTime(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 NotificationgetNotification(Request request, Availability availability) Get notification for user that his request has been deleted.private RequestTypegetOrCreateRequestType(String requestTypeName) Get request type if exists, otherwise create it and return it.private booleanisRequestDateInsideNotificationDate(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 booleanisTimeInsideTime(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 booleanisWorkersNotEnoughForRequest(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 voidprocessOfficeWorkingDays(Day day, List<OfficeWorkingDay> officeWorkingDays, LocalDate date, Request request) Process office working days for a specific day.private voidprocessOfficeWorkingDayTimeSlot(OfficeWorkingDay officeWorkingDay, LocalDate date, Request request) Process office working day time slot.private voidsetNotifications(Date startDate, Date endDate, List<Office> offices, RequestType requestType) Set notifications asready = trueif they are between start and end date and time andready = falseotherwise.
-
Field Details
-
jwtService
JWT service to extract worker id from jwt access token. -
workerRepository
Repository forWorkerentity. -
requestTypeRepository
Repository forRequestTypeentity. -
requestRepository
Repository forRequestentity. -
availabilityRepository
Repository forAvailabilityentity. -
officeRepository
Repository forOfficeentity. -
officeWorkingDayRepository
Repository forOfficeWorkingDayentity. -
requestOfficeRepository
Repository forRequestOfficeentity. -
notificationRepository
Repository forNotificationentity. -
mapRequest
Service to mapRequestInputtoRequest. -
mapRequestType
Service to mapStringtoRequestType. -
mapRequestOffice
-
mapAvailability
Service to mapRequesttoAvailability.
-
-
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:
createRequestin 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 asRequestInputoffices- offices- Returns:
trueif 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 = trueif they are between start and end date and time andready = falseotherwise.- 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:
trueif 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:
trueif 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:
modifyRequestin 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:
deleteRequestin 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
-