| 1 | package io.github.marcopaglio.booking.service.transactional; | |
| 2 | ||
| 3 | import java.time.LocalDate; | |
| 4 | import java.util.List; | |
| 5 | import java.util.Optional; | |
| 6 | import java.util.UUID; | |
| 7 | ||
| 8 | import org.apache.logging.log4j.LogManager; | |
| 9 | import org.apache.logging.log4j.Logger; | |
| 10 | ||
| 11 | import io.github.marcopaglio.booking.exception.DatabaseException; | |
| 12 | import io.github.marcopaglio.booking.exception.InstanceAlreadyExistsException; | |
| 13 | import io.github.marcopaglio.booking.exception.InstanceNotFoundException; | |
| 14 | import io.github.marcopaglio.booking.exception.TransactionException; | |
| 15 | import io.github.marcopaglio.booking.model.Client; | |
| 16 | import io.github.marcopaglio.booking.model.Reservation; | |
| 17 | import io.github.marcopaglio.booking.repository.ClientRepository; | |
| 18 | import io.github.marcopaglio.booking.repository.ReservationRepository; | |
| 19 | import io.github.marcopaglio.booking.service.BookingService; | |
| 20 | import io.github.marcopaglio.booking.transaction.manager.TransactionManager; | |
| 21 | ||
| 22 | /** | |
| 23 | * Implements methods for operating on repositories of the booking application using transactions. | |
| 24 | * | |
| 25 | * @see <a href="../../repository/ClientRepository.html">ClientRepository</a> | |
| 26 | * @see <a href="../../repository/ReservationRepository.html">ReservationRepository</a> | |
| 27 | */ | |
| 28 | public class TransactionalBookingService implements BookingService{ | |
| 29 | /** | |
| 30 | * Creates meaningful logs on behalf of the class. | |
| 31 | */ | |
| 32 | private static final Logger LOGGER = LogManager.getLogger(TransactionalBookingService.class); | |
| 33 | ||
| 34 | /** | |
| 35 | * Defines an error message used when a client entity is not found. | |
| 36 | */ | |
| 37 | static final String CLIENT_NOT_FOUND_ERROR_MSG = "The requested client was not found in the database."; | |
| 38 | ||
| 39 | /** | |
| 40 | * Defines an error message used when a client entity already exists. | |
| 41 | */ | |
| 42 | static final String CLIENT_ALREADY_EXISTS_ERROR_MSG = "That client is already in the database."; | |
| 43 | ||
| 44 | /** | |
| 45 | * Defines an error message used when a reservation entity is not found. | |
| 46 | */ | |
| 47 | static final String RESERVATION_NOT_FOUND_ERROR_MSG = "The requested reservation was not found in the database."; | |
| 48 | ||
| 49 | /** | |
| 50 | * Defines an error message used when a reservation entity already exists. | |
| 51 | */ | |
| 52 | static final String RESERVATION_ALREADY_EXISTS_ERROR_MSG = "That reservation is already in the database."; | |
| 53 | ||
| 54 | /** | |
| 55 | * Defines an error message used when a database error occurs. | |
| 56 | */ | |
| 57 | static final String DATABASE_ERROR_MSG = "A database error occurs: the request cannot be executed."; | |
| 58 | ||
| 59 | /** | |
| 60 | * Allows the service to execute transactions. | |
| 61 | */ | |
| 62 | private TransactionManager transactionManager; | |
| 63 | ||
| 64 | /** | |
| 65 | * Constructs a service for the booking application with a transaction manager. | |
| 66 | * | |
| 67 | * @param transactionManager the {@code TransactionManager} used for applying transactions. | |
| 68 | */ | |
| 69 | public TransactionalBookingService(TransactionManager transactionManager) { | |
| 70 | this.transactionManager = transactionManager; | |
| 71 | } | |
| 72 | ||
| 73 | /** | |
| 74 | * Retrieves all the clients saved in the database within a transaction. | |
| 75 | * | |
| 76 | * @return the list of clients found in the database. | |
| 77 | * @throws DatabaseException if a database error occurs. | |
| 78 | */ | |
| 79 | @Override | |
| 80 | public List<Client> findAllClients() throws DatabaseException { | |
| 81 | try { | |
| 82 |
1
1. findAllClients : replaced return value with Collections.emptyList for io/github/marcopaglio/booking/service/transactional/TransactionalBookingService::findAllClients → KILLED |
return transactionManager.doInTransaction(ClientRepository::findAll); |
| 83 | } catch(TransactionException e) { | |
| 84 | LOGGER.warn(e.getMessage()); | |
| 85 | throw new DatabaseException(DATABASE_ERROR_MSG, e.getCause()); | |
| 86 | } | |
| 87 | } | |
| 88 | ||
| 89 | /** | |
| 90 | * Retrieves all the reservations saved in the database within a transaction. | |
| 91 | * | |
| 92 | * @return the list of reservations found in the database. | |
| 93 | * @throws DatabaseException if a transaction failure occurs on database. | |
| 94 | */ | |
| 95 | @Override | |
| 96 | public List<Reservation> findAllReservations() throws DatabaseException { | |
| 97 | try { | |
| 98 |
1
1. findAllReservations : replaced return value with Collections.emptyList for io/github/marcopaglio/booking/service/transactional/TransactionalBookingService::findAllReservations → KILLED |
return transactionManager.doInTransaction(ReservationRepository::findAll); |
| 99 | } catch(TransactionException e) { | |
| 100 | LOGGER.warn(e.getMessage()); | |
| 101 | throw new DatabaseException(DATABASE_ERROR_MSG, e.getCause()); | |
| 102 | } | |
| 103 | } | |
| 104 | ||
| 105 | /** | |
| 106 | * Retrieves the client with the specified id from the database within a transaction. | |
| 107 | * | |
| 108 | * @param id the identifier of the client to find. | |
| 109 | * @return the {@code Client} identified by {@code id}. | |
| 110 | * @throws InstanceNotFoundException if there is no client with that id in the database. | |
| 111 | * @throws DatabaseException if a database error occurs. | |
| 112 | */ | |
| 113 | @Override | |
| 114 | public Client findClient(UUID id) throws InstanceNotFoundException, DatabaseException { | |
| 115 | try { | |
| 116 | Optional<Client> possibleClient = transactionManager.doInTransaction( | |
| 117 |
1
1. lambda$findClient$0 : replaced return value with Optional.empty for io/github/marcopaglio/booking/service/transactional/TransactionalBookingService::lambda$findClient$0 → KILLED |
(ClientRepository clientRepository) -> clientRepository.findById(id)); |
| 118 |
1
1. findClient : removed conditional - replaced equality check with false → KILLED |
if (possibleClient.isPresent()) |
| 119 |
1
1. findClient : replaced return value with null for io/github/marcopaglio/booking/service/transactional/TransactionalBookingService::findClient → KILLED |
return possibleClient.get(); |
| 120 | throw new InstanceNotFoundException(CLIENT_NOT_FOUND_ERROR_MSG); | |
| 121 | } catch(TransactionException e) { | |
| 122 | LOGGER.warn(e.getMessage()); | |
| 123 | throw new DatabaseException(DATABASE_ERROR_MSG, e.getCause()); | |
| 124 | } | |
| 125 | } | |
| 126 | ||
| 127 | /** | |
| 128 | * Retrieves the reservation with the specified id from the database within a transaction. | |
| 129 | * | |
| 130 | * @param id the identifier of the reservation to find. | |
| 131 | * @return the {@code Reservation} identified by {@code id}. | |
| 132 | * @throws InstanceNotFoundException if there is no reservation with that id in the database. | |
| 133 | * @throws DatabaseException if a database error occurs. | |
| 134 | */ | |
| 135 | @Override | |
| 136 | public Reservation findReservation(UUID id) throws InstanceNotFoundException, DatabaseException { | |
| 137 | try { | |
| 138 | Optional<Reservation> possibleReservation = transactionManager.doInTransaction( | |
| 139 |
1
1. lambda$findReservation$1 : replaced return value with Optional.empty for io/github/marcopaglio/booking/service/transactional/TransactionalBookingService::lambda$findReservation$1 → KILLED |
(ReservationRepository reservationRepository) -> reservationRepository.findById(id)); |
| 140 |
1
1. findReservation : removed conditional - replaced equality check with false → KILLED |
if (possibleReservation.isPresent()) |
| 141 |
1
1. findReservation : replaced return value with null for io/github/marcopaglio/booking/service/transactional/TransactionalBookingService::findReservation → KILLED |
return possibleReservation.get(); |
| 142 | throw new InstanceNotFoundException(RESERVATION_NOT_FOUND_ERROR_MSG); | |
| 143 | } catch(TransactionException e) { | |
| 144 | LOGGER.warn(e.getMessage()); | |
| 145 | throw new DatabaseException(DATABASE_ERROR_MSG, e.getCause()); | |
| 146 | } | |
| 147 | } | |
| 148 | ||
| 149 | /** | |
| 150 | * Retrieves the client with specified name and surname from the database | |
| 151 | * within a transaction. | |
| 152 | * | |
| 153 | * @param firstName the name of the client to find. | |
| 154 | * @param lastName the surname of the client to find. | |
| 155 | * @return the {@code Client} named {@code firstName} | |
| 156 | * and {@code lastName}. | |
| 157 | * @throws InstanceNotFoundException if there is no client with those names in the database. | |
| 158 | * @throws DatabaseException if a transaction failure occurs on database. | |
| 159 | */ | |
| 160 | @Override | |
| 161 | public Client findClientNamed(String firstName, String lastName) | |
| 162 | throws InstanceNotFoundException, DatabaseException { | |
| 163 | try { | |
| 164 | Optional<Client> possibleClient = transactionManager.doInTransaction( | |
| 165 |
1
1. lambda$findClientNamed$2 : replaced return value with Optional.empty for io/github/marcopaglio/booking/service/transactional/TransactionalBookingService::lambda$findClientNamed$2 → KILLED |
(ClientRepository clientRepository) -> clientRepository.findByName(firstName, lastName)); |
| 166 |
1
1. findClientNamed : removed conditional - replaced equality check with false → KILLED |
if (possibleClient.isPresent()) |
| 167 |
1
1. findClientNamed : replaced return value with null for io/github/marcopaglio/booking/service/transactional/TransactionalBookingService::findClientNamed → KILLED |
return possibleClient.get(); |
| 168 | throw new InstanceNotFoundException(CLIENT_NOT_FOUND_ERROR_MSG); | |
| 169 | } catch(TransactionException e) { | |
| 170 | LOGGER.warn(e.getMessage()); | |
| 171 | throw new DatabaseException(DATABASE_ERROR_MSG, e.getCause()); | |
| 172 | } | |
| 173 | } | |
| 174 | ||
| 175 | /** | |
| 176 | * Retrieves the reservation of the specified date from the database within a transaction. | |
| 177 | * | |
| 178 | * @param date the date of the reservation to find. | |
| 179 | * @return the {@code Reservation} on {@code date}. | |
| 180 | * @throws InstanceNotFoundException if there is no reservation on that date in the database. | |
| 181 | * @throws DatabaseException if a transaction failure occurs on database. | |
| 182 | */ | |
| 183 | @Override | |
| 184 | public Reservation findReservationOn(LocalDate date) throws InstanceNotFoundException, DatabaseException { | |
| 185 | try { | |
| 186 | Optional<Reservation> possibleReservation = transactionManager.doInTransaction( | |
| 187 |
1
1. lambda$findReservationOn$3 : replaced return value with Optional.empty for io/github/marcopaglio/booking/service/transactional/TransactionalBookingService::lambda$findReservationOn$3 → KILLED |
(ReservationRepository reservationRepository) -> reservationRepository.findByDate(date)); |
| 188 |
1
1. findReservationOn : removed conditional - replaced equality check with false → KILLED |
if (possibleReservation.isPresent()) |
| 189 |
1
1. findReservationOn : replaced return value with null for io/github/marcopaglio/booking/service/transactional/TransactionalBookingService::findReservationOn → KILLED |
return possibleReservation.get(); |
| 190 | throw new InstanceNotFoundException(RESERVATION_NOT_FOUND_ERROR_MSG); | |
| 191 | } catch(TransactionException e) { | |
| 192 | LOGGER.warn(e.getMessage()); | |
| 193 | throw new DatabaseException(DATABASE_ERROR_MSG, e.getCause()); | |
| 194 | } | |
| 195 | } | |
| 196 | ||
| 197 | /** | |
| 198 | * Adds a new client in the database within a transaction. | |
| 199 | * This method checks if the client is present in the database before inserting. | |
| 200 | * | |
| 201 | * @param client the client to insert. | |
| 202 | * @return the {@code Client} inserted. | |
| 203 | * @throws InstanceAlreadyExistsException if {@code client} is already in the database. | |
| 204 | * @throws DatabaseException if a transaction failure occurs on database. | |
| 205 | */ | |
| 206 | @Override | |
| 207 | public Client insertNewClient(Client client) | |
| 208 | throws InstanceAlreadyExistsException, DatabaseException { | |
| 209 | try { | |
| 210 |
1
1. insertNewClient : replaced return value with null for io/github/marcopaglio/booking/service/transactional/TransactionalBookingService::insertNewClient → KILLED |
return transactionManager.doInTransaction( |
| 211 | (ClientRepository clientRepository) -> { | |
| 212 | Optional<Client> possibleClient = clientRepository | |
| 213 | .findByName(client.getFirstName(), client.getLastName()); | |
| 214 |
1
1. lambda$insertNewClient$4 : removed conditional - replaced equality check with false → KILLED |
if (possibleClient.isEmpty()) { |
| 215 |
1
1. lambda$insertNewClient$4 : replaced return value with null for io/github/marcopaglio/booking/service/transactional/TransactionalBookingService::lambda$insertNewClient$4 → KILLED |
return clientRepository.save(client); |
| 216 | } | |
| 217 | throw new InstanceAlreadyExistsException(CLIENT_ALREADY_EXISTS_ERROR_MSG); | |
| 218 | } | |
| 219 | ); | |
| 220 | } catch(TransactionException e) { | |
| 221 | LOGGER.warn(e.getMessage()); | |
| 222 | throw new DatabaseException(DATABASE_ERROR_MSG, e.getCause()); | |
| 223 | } | |
| 224 | } | |
| 225 | ||
| 226 | /** | |
| 227 | * Adds a new reservation in the database within a transaction. | |
| 228 | * This method checks if the reservation is not present and the associated client is present | |
| 229 | * in the database before inserting. | |
| 230 | * | |
| 231 | * @param reservation the reservation to insert. | |
| 232 | * @return the {@code Reservation} inserted. | |
| 233 | * @throws InstanceAlreadyExistsException if {@code reservation} is already in the database. | |
| 234 | * @throws InstanceNotFoundException if the associated {@code client} doesn't | |
| 235 | * exist in the database. | |
| 236 | * @throws DatabaseException if a transaction failure occurs on database. | |
| 237 | */ | |
| 238 | @Override | |
| 239 | public Reservation insertNewReservation(Reservation reservation) | |
| 240 | throws InstanceAlreadyExistsException, InstanceNotFoundException, DatabaseException { | |
| 241 | try { | |
| 242 |
1
1. insertNewReservation : replaced return value with null for io/github/marcopaglio/booking/service/transactional/TransactionalBookingService::insertNewReservation → KILLED |
return transactionManager.doInTransaction( |
| 243 | (ClientRepository clientRepository, ReservationRepository reservationRepository) -> { | |
| 244 | Optional<Reservation> possibleReservation = | |
| 245 | reservationRepository.findByDate(reservation.getDate()); | |
| 246 |
1
1. lambda$insertNewReservation$5 : removed conditional - replaced equality check with false → KILLED |
if (possibleReservation.isEmpty()) { |
| 247 | Optional<Client> possibleClient = clientRepository.findById(reservation.getClientId()); | |
| 248 |
1
1. lambda$insertNewReservation$5 : removed conditional - replaced equality check with false → KILLED |
if (possibleClient.isPresent()) { |
| 249 |
1
1. lambda$insertNewReservation$5 : replaced return value with null for io/github/marcopaglio/booking/service/transactional/TransactionalBookingService::lambda$insertNewReservation$5 → KILLED |
return reservationRepository.save(reservation); |
| 250 | } | |
| 251 | throw new InstanceNotFoundException(CLIENT_NOT_FOUND_ERROR_MSG); | |
| 252 | } | |
| 253 | throw new InstanceAlreadyExistsException(RESERVATION_ALREADY_EXISTS_ERROR_MSG); | |
| 254 | } | |
| 255 | ); | |
| 256 | } catch(TransactionException e) { | |
| 257 | LOGGER.warn(e.getMessage()); | |
| 258 | throw new DatabaseException(DATABASE_ERROR_MSG, e.getCause()); | |
| 259 | } | |
| 260 | } | |
| 261 | ||
| 262 | /** | |
| 263 | * Deletes the client with the specified id and all his reservation from the database | |
| 264 | * within a transaction. | |
| 265 | * | |
| 266 | * @param id the identifier of the client to remove. | |
| 267 | * @throws InstanceNotFoundException if there is no client with that identifier | |
| 268 | * in the database. | |
| 269 | * @throws DatabaseException if a database error occurs. | |
| 270 | */ | |
| 271 | @Override | |
| 272 | public void removeClient(UUID id) throws InstanceNotFoundException, DatabaseException { | |
| 273 | try { | |
| 274 | transactionManager.doInTransaction( | |
| 275 | (ClientRepository clientRepository, ReservationRepository reservationRepository) -> { | |
| 276 | Optional<Client> possibleClient = clientRepository.findById(id); | |
| 277 |
1
1. lambda$removeClient$6 : removed conditional - replaced equality check with false → KILLED |
if (possibleClient.isPresent()) { |
| 278 | List<Reservation> reservationList = reservationRepository.findByClient(id); | |
| 279 | for (Reservation reservation : reservationList) | |
| 280 |
1
1. lambda$removeClient$6 : removed call to io/github/marcopaglio/booking/repository/ReservationRepository::delete → KILLED |
reservationRepository.delete(reservation); |
| 281 |
1
1. lambda$removeClient$6 : removed call to io/github/marcopaglio/booking/repository/ClientRepository::delete → KILLED |
clientRepository.delete(possibleClient.get()); |
| 282 | return null; | |
| 283 | } | |
| 284 | throw new InstanceNotFoundException(CLIENT_NOT_FOUND_ERROR_MSG); | |
| 285 | } | |
| 286 | ); | |
| 287 | } catch(TransactionException e) { | |
| 288 | LOGGER.warn(e.getMessage()); | |
| 289 | throw new DatabaseException(DATABASE_ERROR_MSG, e.getCause()); | |
| 290 | } | |
| 291 | } | |
| 292 | ||
| 293 | /** | |
| 294 | * Deletes the reservation with the specified id from the database within a transaction. | |
| 295 | * | |
| 296 | * @param id the identifier of the reservation to remove. | |
| 297 | * @throws InstanceNotFoundException if there is no reservation with that identifier | |
| 298 | * in the database. | |
| 299 | * @throws DatabaseException if a database error occurs. | |
| 300 | */ | |
| 301 | @Override | |
| 302 | public void removeReservation(UUID id) throws InstanceNotFoundException, DatabaseException { | |
| 303 | try { | |
| 304 | transactionManager.doInTransaction( | |
| 305 | (ReservationRepository reservationRepository) -> { | |
| 306 | Optional<Reservation> possibleReservation = reservationRepository.findById(id); | |
| 307 |
1
1. lambda$removeReservation$7 : removed conditional - replaced equality check with false → KILLED |
if (possibleReservation.isPresent()) { |
| 308 |
1
1. lambda$removeReservation$7 : removed call to io/github/marcopaglio/booking/repository/ReservationRepository::delete → KILLED |
reservationRepository.delete(possibleReservation.get()); |
| 309 | return null; | |
| 310 | } | |
| 311 | throw new InstanceNotFoundException(RESERVATION_NOT_FOUND_ERROR_MSG); | |
| 312 | } | |
| 313 | ); | |
| 314 | } catch(TransactionException e) { | |
| 315 | LOGGER.warn(e.getMessage()); | |
| 316 | throw new DatabaseException(DATABASE_ERROR_MSG, e.getCause()); | |
| 317 | } | |
| 318 | } | |
| 319 | ||
| 320 | /** | |
| 321 | * Deletes the client with specified name and surname and all his reservation | |
| 322 | * from the database within a transaction. | |
| 323 | * This method checks if the client is present in the database before removing. | |
| 324 | * | |
| 325 | * @param firstName the name of the client to remove. | |
| 326 | * @param lastName the surname of the client to remove. | |
| 327 | * @throws InstanceNotFoundException if there is no client with those names in the database. | |
| 328 | * @throws DatabaseException if a transaction failure occurs on database. | |
| 329 | */ | |
| 330 | @Override | |
| 331 | public void removeClientNamed(String firstName, String lastName) throws InstanceNotFoundException, DatabaseException { | |
| 332 | try { | |
| 333 | transactionManager.doInTransaction( | |
| 334 | (ClientRepository clientRepository, ReservationRepository reservationRepository) -> { | |
| 335 | Optional<Client> possibleClient = clientRepository.findByName(firstName, lastName); | |
| 336 |
1
1. lambda$removeClientNamed$8 : removed conditional - replaced equality check with false → KILLED |
if (possibleClient.isPresent()) { |
| 337 | Client clientToRemove = possibleClient.get(); | |
| 338 | List<Reservation> reservationList = reservationRepository | |
| 339 | .findByClient(clientToRemove.getId()); | |
| 340 | for (Reservation reservation : reservationList) | |
| 341 |
1
1. lambda$removeClientNamed$8 : removed call to io/github/marcopaglio/booking/repository/ReservationRepository::delete → KILLED |
reservationRepository.delete(reservation); |
| 342 |
1
1. lambda$removeClientNamed$8 : removed call to io/github/marcopaglio/booking/repository/ClientRepository::delete → KILLED |
clientRepository.delete(clientToRemove); |
| 343 | return null; | |
| 344 | } | |
| 345 | throw new InstanceNotFoundException(CLIENT_NOT_FOUND_ERROR_MSG); | |
| 346 | } | |
| 347 | ); | |
| 348 | } catch(TransactionException e) { | |
| 349 | LOGGER.warn(e.getMessage()); | |
| 350 | throw new DatabaseException(DATABASE_ERROR_MSG, e.getCause()); | |
| 351 | } | |
| 352 | } | |
| 353 | ||
| 354 | /** | |
| 355 | * Deletes the reservation of the specified date from the database within a transaction. | |
| 356 | * This method checks if the reservation is present in the database before removing. | |
| 357 | * | |
| 358 | * @param date the date of the reservation to find. | |
| 359 | * @throws InstanceNotFoundException if there is no reservation on that date in the database. | |
| 360 | * @throws DatabaseException if a transaction failure occurs on database. | |
| 361 | */ | |
| 362 | @Override | |
| 363 | public void removeReservationOn(LocalDate date) throws InstanceNotFoundException, DatabaseException { | |
| 364 | try { | |
| 365 | transactionManager.doInTransaction( | |
| 366 | (ReservationRepository reservationRepository) -> { | |
| 367 | Optional<Reservation> possibleReservation = reservationRepository.findByDate(date); | |
| 368 |
1
1. lambda$removeReservationOn$9 : removed conditional - replaced equality check with false → KILLED |
if (possibleReservation.isPresent()) { |
| 369 |
1
1. lambda$removeReservationOn$9 : removed call to io/github/marcopaglio/booking/repository/ReservationRepository::delete → KILLED |
reservationRepository.delete(possibleReservation.get()); |
| 370 | return null; | |
| 371 | } | |
| 372 | throw new InstanceNotFoundException(RESERVATION_NOT_FOUND_ERROR_MSG); | |
| 373 | } | |
| 374 | ); | |
| 375 | } catch(TransactionException e) { | |
| 376 | LOGGER.warn(e.getMessage()); | |
| 377 | throw new DatabaseException(DATABASE_ERROR_MSG, e.getCause()); | |
| 378 | } | |
| 379 | } | |
| 380 | ||
| 381 | /** | |
| 382 | * Changes name and surname of the client with the specified id in the database | |
| 383 | * within a transaction. | |
| 384 | * | |
| 385 | * @param id the identifier of the client to rename. | |
| 386 | * @param newFirstName the new name for the client. | |
| 387 | * @param newLastName the new surname for the client. | |
| 388 | * @return the {@code Client} renamed. | |
| 389 | * @throws InstanceNotFoundException if there is no {@code client} with specified id | |
| 390 | * in the database. | |
| 391 | * @throws InstanceAlreadyExistsException if a {@code Client} with those names is | |
| 392 | * already in the database. | |
| 393 | * @throws DatabaseException if a database error occurs. | |
| 394 | */ | |
| 395 | @Override | |
| 396 | public Client renameClient(UUID id, String newFirstName, String newLastName) | |
| 397 | throws InstanceNotFoundException, InstanceAlreadyExistsException, DatabaseException { | |
| 398 | try { | |
| 399 |
1
1. renameClient : replaced return value with null for io/github/marcopaglio/booking/service/transactional/TransactionalBookingService::renameClient → KILLED |
return transactionManager.doInTransaction( |
| 400 | (ClientRepository clientRepository) -> { | |
| 401 | Optional<Client> possibleClientInDB = clientRepository.findById(id); | |
| 402 |
1
1. lambda$renameClient$10 : removed conditional - replaced equality check with false → KILLED |
if (possibleClientInDB.isEmpty()) |
| 403 | throw new InstanceNotFoundException(CLIENT_NOT_FOUND_ERROR_MSG); | |
| 404 | Optional<Client> possibleSameNameClient = clientRepository | |
| 405 | .findByName(newFirstName, newLastName); | |
| 406 |
1
1. lambda$renameClient$10 : removed conditional - replaced equality check with false → KILLED |
if (possibleSameNameClient.isPresent()) |
| 407 | throw new InstanceAlreadyExistsException(CLIENT_ALREADY_EXISTS_ERROR_MSG); | |
| 408 | Client clientInDB = possibleClientInDB.get(); | |
| 409 |
1
1. lambda$renameClient$10 : removed call to io/github/marcopaglio/booking/model/Client::setFirstName → KILLED |
clientInDB.setFirstName(newFirstName); |
| 410 |
1
1. lambda$renameClient$10 : removed call to io/github/marcopaglio/booking/model/Client::setLastName → KILLED |
clientInDB.setLastName(newLastName); |
| 411 |
1
1. lambda$renameClient$10 : replaced return value with null for io/github/marcopaglio/booking/service/transactional/TransactionalBookingService::lambda$renameClient$10 → KILLED |
return clientRepository.save(clientInDB); |
| 412 | } | |
| 413 | ); | |
| 414 | } catch(TransactionException e) { | |
| 415 | LOGGER.warn(e.getMessage()); | |
| 416 | throw new DatabaseException(DATABASE_ERROR_MSG, e.getCause()); | |
| 417 | } | |
| 418 | } | |
| 419 | ||
| 420 | /** | |
| 421 | * Changes date of the reservation with the specified id in the database | |
| 422 | * within a transaction. | |
| 423 | * | |
| 424 | * @param id the identifier of the reservation to reschedule. | |
| 425 | * @param newDate the new date for the reservation. | |
| 426 | * @return the {@code Reservation} rescheduled. | |
| 427 | * @throws InstanceNotFoundException if there is no {@code reservation} with | |
| 428 | * specified id in the database. | |
| 429 | * @throws InstanceAlreadyExistsException if a {@code reservation} with that date is | |
| 430 | * already in the database. | |
| 431 | * @throws DatabaseException if a database error occurs. | |
| 432 | */ | |
| 433 | @Override | |
| 434 | public Reservation rescheduleReservation(UUID id, LocalDate newDate) | |
| 435 | throws InstanceNotFoundException, InstanceAlreadyExistsException, DatabaseException { | |
| 436 | try { | |
| 437 |
1
1. rescheduleReservation : replaced return value with null for io/github/marcopaglio/booking/service/transactional/TransactionalBookingService::rescheduleReservation → KILLED |
return transactionManager.doInTransaction( |
| 438 | (ReservationRepository reservationRepository) -> { | |
| 439 | Optional<Reservation> possibleReservationInDB = | |
| 440 | reservationRepository.findById(id); | |
| 441 |
1
1. lambda$rescheduleReservation$11 : removed conditional - replaced equality check with false → KILLED |
if (possibleReservationInDB.isEmpty()) |
| 442 | throw new InstanceNotFoundException(RESERVATION_NOT_FOUND_ERROR_MSG); | |
| 443 | Optional<Reservation> possibleSameDateReservation = | |
| 444 | reservationRepository.findByDate(newDate); | |
| 445 |
1
1. lambda$rescheduleReservation$11 : removed conditional - replaced equality check with false → KILLED |
if (possibleSameDateReservation.isPresent()) |
| 446 | throw new InstanceAlreadyExistsException(RESERVATION_ALREADY_EXISTS_ERROR_MSG); | |
| 447 | Reservation reservationInDB = possibleReservationInDB.get(); | |
| 448 |
1
1. lambda$rescheduleReservation$11 : removed call to io/github/marcopaglio/booking/model/Reservation::setDate → KILLED |
reservationInDB.setDate(newDate); |
| 449 |
1
1. lambda$rescheduleReservation$11 : replaced return value with null for io/github/marcopaglio/booking/service/transactional/TransactionalBookingService::lambda$rescheduleReservation$11 → KILLED |
return reservationRepository.save(reservationInDB); |
| 450 | } | |
| 451 | ); | |
| 452 | } catch(TransactionException e) { | |
| 453 | LOGGER.warn(e.getMessage()); | |
| 454 | throw new DatabaseException(DATABASE_ERROR_MSG, e.getCause()); | |
| 455 | } | |
| 456 | } | |
| 457 | } | |
Mutations | ||
| 82 |
1.1 |
|
| 98 |
1.1 |
|
| 117 |
1.1 |
|
| 118 |
1.1 |
|
| 119 |
1.1 |
|
| 139 |
1.1 |
|
| 140 |
1.1 |
|
| 141 |
1.1 |
|
| 165 |
1.1 |
|
| 166 |
1.1 |
|
| 167 |
1.1 |
|
| 187 |
1.1 |
|
| 188 |
1.1 |
|
| 189 |
1.1 |
|
| 210 |
1.1 |
|
| 214 |
1.1 |
|
| 215 |
1.1 |
|
| 242 |
1.1 |
|
| 246 |
1.1 |
|
| 248 |
1.1 |
|
| 249 |
1.1 |
|
| 277 |
1.1 |
|
| 280 |
1.1 |
|
| 281 |
1.1 |
|
| 307 |
1.1 |
|
| 308 |
1.1 |
|
| 336 |
1.1 |
|
| 341 |
1.1 |
|
| 342 |
1.1 |
|
| 368 |
1.1 |
|
| 369 |
1.1 |
|
| 399 |
1.1 |
|
| 402 |
1.1 |
|
| 406 |
1.1 |
|
| 409 |
1.1 |
|
| 410 |
1.1 |
|
| 411 |
1.1 |
|
| 437 |
1.1 |
|
| 441 |
1.1 |
|
| 445 |
1.1 |
|
| 448 |
1.1 |
|
| 449 |
1.1 |