From b730bb418fb6ad930795d0483f829a6aba30c6cf Mon Sep 17 00:00:00 2001 From: Serberx <47865435+Serberx@users.noreply.github.com> Date: Mon, 26 Feb 2024 07:48:30 +0100 Subject: [PATCH] Changes (#33) - Reservation functionality. Issues [- Getting reserved Lagerobject from another user shows 'successful', but it is not. - Deleting reserved storage objects from the reservation is successful. Does not disappear immediately. - Shifting STO succeeds to another storage, but does not disappear immediatelyits not.] Signed-off-by: Kuzu --- package.json | 4 +- .../samic/samic/data/fixture/Fixtures.java | 10 ++--- .../repositories/RepositoryReservation.java | 4 ++ .../repositories/RepositoryStorageObject.java | 4 +- .../samic/services/ServiceReservation.java | 39 ++++++++++++------- .../samic/services/ServiceStorageObject.java | 25 ++++++++++++ .../LagerobjektAufnehmenView.java | 4 +- .../meine_hardware/MeineHardwareView.java | 6 +-- src/main/resources/data.sql | 2 + 9 files changed, 72 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index bb1ae31..c2e0799 100644 --- a/package.json +++ b/package.json @@ -270,9 +270,9 @@ "construct-style-sheets-polyfill": "$construct-style-sheets-polyfill", "lit": "$lit", "@polymer/polymer": "$@polymer/polymer", - "@fontsource/inter": "$@fontsource/inter", "proj4": "$proj4", "@vaadin/vaadin-themable-mixin": "$@vaadin/vaadin-themable-mixin", - "date-fns": "$date-fns" + "date-fns": "$date-fns", + "@fontsource/inter": "$@fontsource/inter" } } diff --git a/src/main/java/com/samic/samic/data/fixture/Fixtures.java b/src/main/java/com/samic/samic/data/fixture/Fixtures.java index 62d5e7e..15026ab 100644 --- a/src/main/java/com/samic/samic/data/fixture/Fixtures.java +++ b/src/main/java/com/samic/samic/data/fixture/Fixtures.java @@ -363,7 +363,7 @@ public static StorageObject giveStorageObject1(){ return StorageObject.builder() .remark("remark1") .objectTypeName(giveObjectType1()) - .verbindungsnummer("1234") +// .verbindungsnummer("1234") .projectDevice(false) .status(Status.AVAILABLE) .build(); @@ -374,7 +374,7 @@ public static StorageObject giveStorageObject2(){ return StorageObject.builder() .remark("remark1") .objectTypeName(giveObjectType2()) - .verbindungsnummer("1234") +// .verbindungsnummer("1234") .projectDevice(false) .status(Status.AVAILABLE) @@ -386,7 +386,7 @@ public static StorageObject giveStorageObject3(){ return StorageObject.builder() .remark("remark1") .objectTypeName(giveObjectType3()) - .verbindungsnummer("1234") +// .verbindungsnummer("1234") .projectDevice(false) .status(Status.AVAILABLE) @@ -398,7 +398,7 @@ public static StorageObject giveStorageObject4(){ return StorageObject.builder() .remark("remark1") .objectTypeName(giveObjectType4()) - .verbindungsnummer("1234") +// .verbindungsnummer("1234") .projectDevice(false) .status(Status.AVAILABLE) @@ -410,7 +410,7 @@ public static StorageObject giveStorageObject5(){ return StorageObject.builder() .remark("remark1") .objectTypeName(giveObjectType5()) - .verbindungsnummer("1234") +// .verbindungsnummer("1234") .projectDevice(false) .status(Status.AVAILABLE) diff --git a/src/main/java/com/samic/samic/data/repositories/RepositoryReservation.java b/src/main/java/com/samic/samic/data/repositories/RepositoryReservation.java index 4f5b865..625b002 100644 --- a/src/main/java/com/samic/samic/data/repositories/RepositoryReservation.java +++ b/src/main/java/com/samic/samic/data/repositories/RepositoryReservation.java @@ -2,6 +2,8 @@ import com.samic.samic.data.entity.Reservation; import com.samic.samic.data.entity.User; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -22,4 +24,6 @@ public interface RepositoryReservation extends JpaRepository{ Optional findAllByReservedFrom_Id(Long id); + Page findAllByReservedFrom_Id(Long id, + Pageable request); } diff --git a/src/main/java/com/samic/samic/data/repositories/RepositoryStorageObject.java b/src/main/java/com/samic/samic/data/repositories/RepositoryStorageObject.java index 41a10b3..03bfc6a 100644 --- a/src/main/java/com/samic/samic/data/repositories/RepositoryStorageObject.java +++ b/src/main/java/com/samic/samic/data/repositories/RepositoryStorageObject.java @@ -48,7 +48,7 @@ public interface RepositoryStorageObject extends JpaRepository findStorageObjectByCpe_Id(Long id); -// Optional findStorageObjectByVerbindungsnummer(String verbinNr); + // Optional findStorageObjectByVerbindungsnummer(String verbinNr); // List findAllByObjectTypeNameLikeIgnoreCase(String keyword, String keyword1, Pageable pageable); @@ -56,6 +56,8 @@ public interface RepositoryStorageObject extends JpaRepository findAllByRemarkIsLikeIgnoreCase(String filterString, Pageable pageable); + StorageObject findStorageObjectsByReservationId(Long id); + // @Query("SELECT emp "+"FROM StorageObject emp "+" inner JOIN ObjectType com ON emp.objectTypeName.id = com.id "+"WHERE ( lower(emp.objectTypeName.name) LIKE lower(:keyword) OR lower(emp.objectTypeName.name) LIKE lower(:keyword) )") // List searchUnemployedWithOr(String keyword, Pageable pageable); // diff --git a/src/main/java/com/samic/samic/services/ServiceReservation.java b/src/main/java/com/samic/samic/services/ServiceReservation.java index 9cc2dc8..1a1f57d 100644 --- a/src/main/java/com/samic/samic/services/ServiceReservation.java +++ b/src/main/java/com/samic/samic/services/ServiceReservation.java @@ -1,6 +1,7 @@ package com.samic.samic.services; import com.samic.samic.data.entity.Reservation; +import com.samic.samic.data.entity.StorageObject; import com.samic.samic.data.entity.User; import com.samic.samic.data.repositories.RepositoryReservation; import com.samic.samic.exceptions.ReservationException; @@ -24,6 +25,8 @@ public class ServiceReservation{ @Autowired private final RepositoryReservation repositoryReservation; + @Autowired + private final ServiceStorageObject serviceStorageObject; // @Autowired // private final AuthenticatedUser authenticatedUser; @@ -31,17 +34,17 @@ public class ServiceReservation{ public Reservation saveReservationByObject(Reservation reservation){ if(reservation != null){ if(reservation.getId() == null){ - System.out.println(reservation.getReservedFrom()+"----------User1"); if(reservation.getReservedFrom() != null){ - System.out.println(reservation.getReservedFrom()+"----------User2"); // reservation.setReservedAt(DateTimeFactory.now()); if(reservation.getCustomer() != null){ - System.out.println(reservation.getReservedFrom()+"----------User3"); reservation.setCustomer(reservation.getCustomer()); } - System.out.println(reservation.getReservedFrom()+"----------User4"); + // if(reservation.getCustomer().connectionNo().isEmpty()){ + // throw new ReservationException("Connection No is not set!"); + // } // reservation.setReservedFrom(authenticatedUser.getUser().get()); - System.out.println(reservation.getReservedFrom()+"----------User5"); + + return repositoryReservation.save(reservation); }else{ @@ -94,7 +97,14 @@ public void deleteReservationById(Long id){ public void deleteByObject(Reservation reservation){ if(reservation != null){ - repositoryReservation.delete(reservation); + if(repositoryReservation.findById(reservation.getId()).isPresent()){ + + reservation.setReservedFrom(null); + StorageObject tempSto = serviceStorageObject.findStorageObjectByReservationID(reservation.getId()); + tempSto.setReservation(null); + repositoryReservation.deleteById(reservation.getId()); + + } }else{ throw new ReservationException("Given Reservation is null!"); } @@ -155,12 +165,15 @@ public Stream findAllReservationByUserIdStream(Long id){ } @Transactional - public Stream findAllReservationByGivenUser(User user){ - Stream reservationOnUser = repositoryReservation.findReservationsByReservedFrom(user); - - - return reservationOnUser/*.peek(u -> System.out.println(u.toString()+"\n"))*/.filter(reservation -> reservation.getReservedFrom() - .getId() - .equals(user.getId())); + public List findAllReservationByGivenUser(User user){ + Stream reservationOnUser = repositoryReservation.findReservationsByReservedFrom(user) + .filter(a -> a.getStorageObject() != null) + .filter(u -> u.getReservedFrom() != null) + /*.filter(c -> c.getCustomer() != null)*/; + + return reservationOnUser.filter(reservation -> reservation.getReservedFrom() + .getId() + .equals(user.getId())) + .toList(); } } diff --git a/src/main/java/com/samic/samic/services/ServiceStorageObject.java b/src/main/java/com/samic/samic/services/ServiceStorageObject.java index 11b190f..7c26d1f 100644 --- a/src/main/java/com/samic/samic/services/ServiceStorageObject.java +++ b/src/main/java/com/samic/samic/services/ServiceStorageObject.java @@ -1,12 +1,16 @@ package com.samic.samic.services; import com.samic.samic.data.entity.ObjectType; +import com.samic.samic.data.entity.Reservation; import com.samic.samic.data.entity.StorageObject; import com.samic.samic.data.entity.User; import com.samic.samic.data.repositories.RepositoryObjectType; +import com.samic.samic.data.repositories.RepositoryReservation; import com.samic.samic.data.repositories.RepositoryStorageObject; import com.samic.samic.exceptions.ObjectTypeException; +import com.samic.samic.exceptions.ReservationException; import com.samic.samic.exceptions.StorageObjectException; +import com.samic.samic.exceptions.UserException; import com.vaadin.flow.data.provider.Query; import com.vaadin.flow.spring.data.VaadinSpringDataHelpers; import jakarta.persistence.EntityManagerFactory; @@ -33,6 +37,8 @@ public class ServiceStorageObject{ @Autowired private final RepositoryStorageObject repositoryStorageObject; @Autowired + private final RepositoryReservation repositoryReservation; + @Autowired private final EntityManagerFactory emf; @Autowired private final RepositoryObjectType repositoryObjectType; @@ -44,6 +50,18 @@ public class ServiceStorageObject{ @Transactional public StorageObject saveStorageObject(StorageObject storageObject){ + /*if(storageObject.getReservation().getReservedFrom() != null){ + throw new ReservationException("StorageObject has a User set!"); + }*/ + + if(storageObject.getStoredAtUser() != null){ + if(storageObject.getReservation() != null ){ + if(storageObject.getReservation().getReservedFrom() != null){ + throw new ReservationException("User already set to STO!"); + } + } + } + if(storageObject != null){ // System.out.println("------------- 1 " + storageObject.getReservation().getReservedFrom()); log.warn("saveStorageObject() | ######################## USER1 ########################, {}: ", @@ -695,4 +713,11 @@ public Long findAmountOfObjectType2(String objectType){ // public Stream findStorageObjectByUserId(Long id, PageRequest query){ // return repositoryStorageObject.findAllByStoredAtUser_Id(id, query).stream(); // } + + public Stream findStorageObjectByUserId(Long id, + PageRequest request){ + return repositoryReservation.findAllByReservedFrom_Id(id, + request) + .stream(); + } } diff --git a/src/main/java/com/samic/samic/views/lagerobjekt_aufnehmen/LagerobjektAufnehmenView.java b/src/main/java/com/samic/samic/views/lagerobjekt_aufnehmen/LagerobjektAufnehmenView.java index 2c95a31..7d46cf1 100644 --- a/src/main/java/com/samic/samic/views/lagerobjekt_aufnehmen/LagerobjektAufnehmenView.java +++ b/src/main/java/com/samic/samic/views/lagerobjekt_aufnehmen/LagerobjektAufnehmenView.java @@ -63,8 +63,8 @@ private void onSave() { Long.valueOf(storageObjectID.getValue())); if (toEdit != null) { if (toEdit.getStoredAtUser() == null) { - toEdit.setStoredAtUser(authenticatedUser.getUser() - .orElse(userService.findUserByID(authenticatedUser.getUser().get().getId()))); +// toEdit.setStoredAtUser(authenticatedUser.getUser() +// .orElse(userService.findUserByID(authenticatedUser.getUser().get().getId()))); toEdit.setStorage(null); storageObjectService.saveStorageObject(toEdit); storageObjectID.setValue(""); diff --git a/src/main/java/com/samic/samic/views/meine_hardware/MeineHardwareView.java b/src/main/java/com/samic/samic/views/meine_hardware/MeineHardwareView.java index abd5db5..176cdd1 100644 --- a/src/main/java/com/samic/samic/views/meine_hardware/MeineHardwareView.java +++ b/src/main/java/com/samic/samic/views/meine_hardware/MeineHardwareView.java @@ -90,9 +90,9 @@ private void initReservationGridData() { // (cut off stream from repository), or make repo return list //TODO reservation does not contain storageobject - // reservationGrid.setItems( - // reservationService.findAllReservationByGivenUser(authenticatedUser.getUser() - // .get()).toList()); + reservationGrid.setItems( + reservationService.findAllReservationByGivenUser(authenticatedUser.getUser() + .get())); } private void initStorageObjectGrid() { diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 72cdfdb..6b7c83f 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -1446,3 +1446,5 @@ insert into reservations (id, reserved_at, fk_user, last_modified, completed, co values (2, TIMESTAMP ' 2023-12-25 11:16:47.678165', 1, TIMESTAMP ' 2023-12-25 11:16:47.678504', 0, '123413521', 'Kunde benötigt PoE fähiges Device'); +select * from CPES where id = 260; +select * from CPES where id = 51; \ No newline at end of file