From 74728e454be45e046f5e4fd326169f5d8df39024 Mon Sep 17 00:00:00 2001 From: Aleksandar Zivkovic Date: Wed, 28 Feb 2024 06:50:44 +0100 Subject: [PATCH] fix user not being set to storageobject when moved via reservation to meineHardware fix storage form not showing up on Dashboard Signed-off-by: Aleksandar Zivkovic --- .../samic/services/ServiceStorageObject.java | 1480 +++++++++-------- .../samic/views/dashboard/DashboardView.java | 3 +- .../meine_hardware/MeineHardwareView.java | 4 +- 3 files changed, 761 insertions(+), 726 deletions(-) diff --git a/src/main/java/com/samic/samic/services/ServiceStorageObject.java b/src/main/java/com/samic/samic/services/ServiceStorageObject.java index 36c4962..8d66bb3 100644 --- a/src/main/java/com/samic/samic/services/ServiceStorageObject.java +++ b/src/main/java/com/samic/samic/services/ServiceStorageObject.java @@ -1,7 +1,9 @@ package com.samic.samic.services; -import com.samic.samic.data.entity.*; -import com.samic.samic.data.foundation.DateTimeFactory; +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; @@ -12,8 +14,15 @@ import com.samic.samic.security.AuthenticatedUser; import com.vaadin.flow.data.provider.Query; import com.vaadin.flow.spring.data.VaadinSpringDataHelpers; -import jakarta.persistence.AttributeOverride; import jakarta.persistence.EntityManagerFactory; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Stream; import lombok.RequiredArgsConstructor; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; @@ -23,9 +32,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.*; -import java.util.stream.Stream; - @Service @Log4j2 @@ -34,737 +40,763 @@ @ComponentScan(basePackages = "com.samic.samic.data.services") @ComponentScan(basePackages = {"com.samic.samic.security"}) -public class ServiceStorageObject{ - - @Autowired - private final RepositoryStorageObject repositoryStorageObject; - @Autowired - private final RepositoryReservation repositoryReservation; - @Autowired - private final EntityManagerFactory emf; - @Autowired - private final RepositoryObjectType repositoryObjectType; - @Autowired - private final RepositoryStorageObjectHistory repositoryStorageObjectHistory; - @Autowired - private final ServiceStorageObjectHistory serviceStorageObjectHistory; - // @Autowired - // private final ServiceReservation serviceReservation; - @Autowired - private final AuthenticatedUser authenticatedUser; - // private final Logger log = LoggerFactory.getLogger(this.getClass()); - // public ServiceStorageObject(@Qualifier("storageObject") RepositoryStorageObject repositoryStorageObject){ - // this.repositoryStorageObject = repositoryStorageObject; - // } - - @Transactional - public StorageObject saveStorageObject(StorageObject storageObject){ +public class ServiceStorageObject { + + @Autowired + private final RepositoryStorageObject repositoryStorageObject; + @Autowired + private final RepositoryReservation repositoryReservation; + @Autowired + private final EntityManagerFactory emf; + @Autowired + private final RepositoryObjectType repositoryObjectType; + @Autowired + private final RepositoryStorageObjectHistory repositoryStorageObjectHistory; + @Autowired + private final ServiceStorageObjectHistory serviceStorageObjectHistory; + // @Autowired + // private final ServiceReservation serviceReservation; + @Autowired + private final AuthenticatedUser authenticatedUser; + // private final Logger log = LoggerFactory.getLogger(this.getClass()); + // public ServiceStorageObject(@Qualifier("storageObject") RepositoryStorageObject repositoryStorageObject){ + // this.repositoryStorageObject = repositoryStorageObject; + // } + + @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(("Storageobject is reserved by '%s'.".formatted(storageObject.getStoredAtUser().getProfile().getUsername()))); - } - } + if (storageObject.getStoredAtUser() != null) { + if (storageObject.getReservation() != null) { + if (storageObject.getReservation() + .getReservedFrom() != null) { + throw new ReservationException(("Storageobject is reserved by '%s'.".formatted( + storageObject.getStoredAtUser().getProfile().getUsername()))); } - - if(storageObject != null){ - // System.out.println("------------- 1 " + storageObject.getReservation().getReservedFrom()); - log.warn("saveStorageObject() | ######################## USER1 ########################, {}: ", - storageObject.getStoredAtUser()); - - log.debug("saveStorageObject() | StorageObject is not null, {}: ------ , {}", - storageObject, - storageObject.getStoredAtUser()); - if(storageObject.getId() != null){ - // System.out.println("------------- 2 " + storageObject.getReservation().getReservedFrom()); - log.warn("saveStorageObject() | ######################## USER2 ########################, {}: ", - storageObject.getStoredAtUser()); - log.debug("saveStorageObject() | StorageObject id is not null, StorageObject ID: {}, \nstorageObject: {}", - storageObject.getId(), - storageObject); - if(doesObjectExistById(storageObject.getId())){ - // System.out.println("------------- 3 " + storageObject.getReservation().getReservedFrom()); - log.warn("saveStorageObject() | ######################## USER3 ########################, {}: ", - storageObject.getStoredAtUser()); - log.debug("saveStorageObject() | StorageObject exists, StorageObject ID: {},\nstorageObject: {}", - storageObject.getId(), - storageObject); - StorageObject fetchedStorageObject = findStorageObjectById(storageObject.getId()); - // System.out.println("------------- 4 " + fetchedStorageObject.getReservation().getReservedFrom()); - log.warn("saveStorageObject() | ######################## USER4 ########################, {}: ", - storageObject.getStoredAtUser()); - log.debug("saveStorageObject() | StorageObject found with ID: {},\nFetched StorageObject{},", - storageObject.getId(), - fetchedStorageObject); - if(fetchedStorageObject != null){ - // System.out.println("------------- 5 " + fetchedStorageObject.getReservation().getReservedFrom()); - log.warn("saveStorageObject() | ######################## USER5 ########################i, {}: ", - storageObject.getStoredAtUser()); - log.debug("saveStorageObject() | in if statement, fetchedStorageObject: {},\nStorageObject: {}", - fetchedStorageObject.getId(), - fetchedStorageObject); - if(fetchedStorageObject.getId() - .equals(storageObject.getId())){ - // System.out.println("------------- 6 " + fetchedStorageObject.getReservation().getReservedFrom()); - log.warn("saveStorageObject() | ######################## USER6 ########################, {}: ", - storageObject.getStoredAtUser()); - log.debug("saveStorageObject() | fetched StorageObject equals given StorageObject, fetchedStorageObject: {},\nStorageObject: {}", - fetchedStorageObject.getId(), - storageObject); - fetchedStorageObject = storageObject; - log.debug("saveStorageObejct() | given StorageObject is set to fetched StorageObject, fetchedStorageObject: {},\n storageObject: {}", - fetchedStorageObject, - storageObject); - serviceStorageObjectHistory.setStorageOBjectHistory(fetchedStorageObject); - return repositoryStorageObject.save(fetchedStorageObject); - }else{ - log.debug("saveStorageObject() | fetched StorageObject does not match with given StorageObject, fetchedStorageObject: {},\nStorageObject: {}", - fetchedStorageObject, - storageObject); - throw new StorageObjectException("StorageObject with id1: '%s' and id2: '%s' does not match. Some error occoured while fetch!!".formatted(fetchedStorageObject.getId(), - storageObject.getId())); - } - }else{ - log.debug("saveStorageObject() | fetched StorageObject is null, fetchedStorageObject: {}", - fetchedStorageObject); - throw new StorageObjectException("StorageObject with id: '%s' does not exist in DB".formatted(storageObject.getId())); - } - }else{ - log.debug("saveStorageObject() | StorageObject does not exist in DB, ID: {},\nStorageObject: {}", - storageObject.getId()); - serviceStorageObjectHistory.setStorageOBjectHistory(storageObject); - return repositoryStorageObject.save(storageObject); - - } - }else{ - log.debug("saveStorageObject() | StorageObject id is null, Saving StorageObject: {}", - storageObject); //TODO T3600 - serviceStorageObjectHistory.setStorageOBjectHistory(storageObject); - StorageObject saved = repositoryStorageObject.save(storageObject); - return saved; + } + } + + if (storageObject != null) { + // System.out.println("------------- 1 " + storageObject.getReservation().getReservedFrom()); + log.warn( + "saveStorageObject() | ######################## USER1 ########################, {}: ", + storageObject.getStoredAtUser()); + + log.debug("saveStorageObject() | StorageObject is not null, {}: ------ , {}", + storageObject, + storageObject.getStoredAtUser()); + if (storageObject.getId() != null) { + // System.out.println("------------- 2 " + storageObject.getReservation().getReservedFrom()); + log.warn( + "saveStorageObject() | ######################## USER2 ########################, {}: ", + storageObject.getStoredAtUser()); + log.debug( + "saveStorageObject() | StorageObject id is not null, StorageObject ID: {}, \nstorageObject: {}", + storageObject.getId(), + storageObject); + if (doesObjectExistById(storageObject.getId())) { + // System.out.println("------------- 3 " + storageObject.getReservation().getReservedFrom()); + log.warn( + "saveStorageObject() | ######################## USER3 ########################, {}: ", + storageObject.getStoredAtUser()); + log.debug( + "saveStorageObject() | StorageObject exists, StorageObject ID: {},\nstorageObject: {}", + storageObject.getId(), + storageObject); + StorageObject fetchedStorageObject = findStorageObjectById(storageObject.getId()); + // System.out.println("------------- 4 " + fetchedStorageObject.getReservation().getReservedFrom()); + log.warn( + "saveStorageObject() | ######################## USER4 ########################, {}: ", + storageObject.getStoredAtUser()); + log.debug( + "saveStorageObject() | StorageObject found with ID: {},\nFetched StorageObject{},", + storageObject.getId(), + fetchedStorageObject); + if (fetchedStorageObject != null) { + // System.out.println("------------- 5 " + fetchedStorageObject.getReservation().getReservedFrom()); + log.warn( + "saveStorageObject() | ######################## USER5 ########################i, {}: ", + storageObject.getStoredAtUser()); + log.debug( + "saveStorageObject() | in if statement, fetchedStorageObject: {},\nStorageObject: {}", + fetchedStorageObject.getId(), + fetchedStorageObject); + if (fetchedStorageObject.getId() + .equals(storageObject.getId())) { + // System.out.println("------------- 6 " + fetchedStorageObject.getReservation().getReservedFrom()); + log.warn( + "saveStorageObject() | ######################## USER6 ########################, {}: ", + storageObject.getStoredAtUser()); + log.debug( + "saveStorageObject() | fetched StorageObject equals given StorageObject, fetchedStorageObject: {},\nStorageObject: {}", + fetchedStorageObject.getId(), + storageObject); + fetchedStorageObject = storageObject; + log.debug( + "saveStorageObejct() | given StorageObject is set to fetched StorageObject, fetchedStorageObject: {},\n storageObject: {}", + fetchedStorageObject, + storageObject); + serviceStorageObjectHistory.setStorageOBjectHistory(fetchedStorageObject); + return repositoryStorageObject.save(fetchedStorageObject); + } else { + log.debug( + "saveStorageObject() | fetched StorageObject does not match with given StorageObject, fetchedStorageObject: {},\nStorageObject: {}", + fetchedStorageObject, + storageObject); + throw new StorageObjectException( + "StorageObject with id1: '%s' and id2: '%s' does not match. Some error occoured while fetch!!".formatted( + fetchedStorageObject.getId(), + storageObject.getId())); } - }else{ - log.debug("saveStorageObject() | StorageObject is null"); - throw new StorageObjectException("StorageObject is null!"); - } - } - - @Transactional - public StorageObject findStorageObjectById(Long id){ - if(id != null){ - log.debug("findStorageObjectById() | id is not null, id: {}", - id); - if(repositoryStorageObject.findById(id) - .isPresent()){ - return repositoryStorageObject.findById(id) - .get(); - }else{ - throw new StorageObjectException("Could not find StorageObject with id: '%s' in DB".formatted(id)); - } - }else{ - throw new StorageObjectException("Given id is null!"); - } - } - - // public StorageObject findStorageObjectByID(Long id){ - // StorageObject sto = new StorageObject(); - // EntityManager em = emf.createEntityManager(); - // em.getTransaction().begin(); - // - // EntityGraph entityGraph = em.createEntityGraph("graph.StorageObjectStorage"); - // TypedQuery query = em.createQuery("SELECT a FROM StorageObject a", StorageObject.class).setHint("javax.persistence.fetchgraph", entityGraph); - // List resultList = query.getResultList(); - // - // em.getTransaction().commit(); - // em.close(); - // - // for(StorageObject so : resultList){ - // if(so.getId().equals(id)){ - // sto = so; - // } - // } - // - // if(sto != null){ - // return sto; - // }else{ - // throw new StorageObjectException("Could not find StorageObject with id: '%s' in DB".formatted(id)); - // } - // } - - @Transactional - public Optional findStorageObjectByIDOptional(Long id){ - if(id != null){ - if(repositoryStorageObject.findById(id) - .isPresent()){ - return repositoryStorageObject.findById(id); - }else{ - throw new StorageObjectException("Could not find StorageObject with id: '%s' in DB".formatted(id)); - } - }else{ - throw new StorageObjectException("Given id is null!"); - } - } - - public void deleteStorageObjectById(Long id){ - if(id != null){ - if(!repositoryStorageObject.findAll() - .isEmpty()){ - repositoryStorageObject.deleteById(id); - }else{ - throw new StorageObjectException("StorageObject DB is empty!"); - } - }else{ - throw new StorageObjectException("StorageObject id is null!"); - } - } - - public void deleteByObject(StorageObject storageObject){ - if(storageObject != null){ - if(!repositoryStorageObject.findAll() - .isEmpty()){ - repositoryStorageObject.delete(storageObject); - }else{ - throw new StorageObjectException("StorageObject DB is empty!"); - } - }else{ - throw new StorageObjectException("StorageObject is null!"); - } - } - - public boolean doesObjectExistById(Long id){ - if(id != null){ - return repositoryStorageObject.existsById(id); - }else{ - throw new StorageObjectException("StorageObject id is null!"); - } - } - - @Transactional - public Optional findStorageByNameOptional(ObjectType objectType){ - if(objectType != null){ - if(repositoryStorageObject.findStorageObjectByObjectTypeName(objectType) - .isPresent()){ - return repositoryStorageObject.findStorageObjectByObjectTypeName(objectType); - }else{ - throw new StorageObjectException("Could not find StorageObject with objectType: '%s' in DB".formatted(objectType.getName())); - } - }else{ - throw new StorageObjectException("Given name is null!"); - } - } - - @Transactional - public Stream findAll(){ - if(repositoryStorageObject.findAll() - .isEmpty()){ - throw new StorageObjectException("StorageObject list is empty!"); - }else{ - return repositoryStorageObject.findAll() - .stream(); - } - } - - @Transactional - public List findNotReservedStorageObjects(){ - List freeStorageObjects = new ArrayList<>(); - if(!repositoryStorageObject.findAll() - .isEmpty()){ - List storageObjectList = repositoryStorageObject.findAll(); - Iterator iter = storageObjectList.iterator(); - while(iter.hasNext()){ - StorageObject TempstorageObject = iter.next(); - if(TempstorageObject.getReservation() == null){ - freeStorageObjects.add(TempstorageObject); - } - } - }else{ - throw new StorageObjectException("StorageObject list is empty!"); - } - if(freeStorageObjects.isEmpty()){ - throw new StorageObjectException("There are no Free StorageObjects in DB!"); - } - return freeStorageObjects; - } - - @Transactional - public List findReservedStorageObjects(){ - List reservedStorageObjects = repositoryStorageObject.findAll(); - // List storageObjectList = repositoryStorageObject.findAll(); - if(!reservedStorageObjects.isEmpty()){ - Iterator iter = reservedStorageObjects.iterator(); - while(iter.hasNext()){ - StorageObject TempstorageObject = iter.next(); - if(TempstorageObject.getReservation() != null){ - reservedStorageObjects.add(TempstorageObject); - } - } - }else{ - throw new StorageObjectException("StorageObject list is empty!"); - } - if(reservedStorageObjects.isEmpty()){ - throw new StorageObjectException("There are no Free StorageObjects in DB!"); - } - return reservedStorageObjects; - } - - - @Transactional - public void deleteAll(){ - if(repositoryStorageObject.count()>0){ - repositoryStorageObject.deleteAll(); - }else{ - throw new StorageObjectException("StorageObject DB is empty!"); - } - } - - - public Stream findAllStorageObjectByUserId(Long id, - PageRequest request){ - if(id != null){ - return repositoryStorageObject.findAllByStoredAtUser_Id(id, - request) - .stream(); - }else{ - throw new StorageObjectException("Given id is null!"); - } - } - - public Stream findAllStorageObjectByUserIdStream(Long id){ - if(id != null){ - return repositoryStorageObject.findStorageObjectsByStoredAtUser_Id(id); - }else{ - throw new StorageObjectException("Given id is null!"); - } - } - - - public StorageObject findStorageObjectByReservationID(Long id){ - if(id != null){ - return repositoryStorageObject.findStorageObjectByReservation_Id(id); - }else{ - throw new StorageObjectException("Given id is null!"); - } - } + } else { + log.debug( + "saveStorageObject() | fetched StorageObject is null, fetchedStorageObject: {}", + fetchedStorageObject); + throw new StorageObjectException( + "StorageObject with id: '%s' does not exist in DB".formatted( + storageObject.getId())); + } + } else { + log.debug( + "saveStorageObject() | StorageObject does not exist in DB, ID: {},\nStorageObject: {}", + storageObject.getId()); + serviceStorageObjectHistory.setStorageOBjectHistory(storageObject); + return repositoryStorageObject.save(storageObject); - //////////////////// - public Stream findAllStoageObjectBySFPID(Long id, - PageRequest request){ - if(id != null){ - return repositoryStorageObject.findStorageObjectsBySfp_Id(id, - request) - .stream(); - }else{ - throw new StorageObjectException("Given id is null!"); } - } - - public Stream findAllStoageObjectBySFPIDStream(Long id){ - if(id != null){ - return repositoryStorageObject.findStorageObjectsBySfp_Id(id); - }else{ - throw new StorageObjectException("Given id is null!"); + } else { + log.debug("saveStorageObject() | StorageObject id is null, Saving StorageObject: {}", + storageObject); //TODO T3600 + serviceStorageObjectHistory.setStorageOBjectHistory(storageObject); + StorageObject saved = repositoryStorageObject.save(storageObject); + return saved; + } + } else { + log.debug("saveStorageObject() | StorageObject is null"); + throw new StorageObjectException("StorageObject is null!"); + } + } + + @Transactional + public StorageObject findStorageObjectById(Long id) { + if (id != null) { + log.debug("findStorageObjectById() | id is not null, id: {}", + id); + if (repositoryStorageObject.findById(id) + .isPresent()) { + return repositoryStorageObject.findById(id) + .get(); + } else { + throw new StorageObjectException( + "Could not find StorageObject with id: '%s' in DB".formatted(id)); + } + } else { + throw new StorageObjectException("Given id is null!"); + } + } + + // public StorageObject findStorageObjectByID(Long id){ + // StorageObject sto = new StorageObject(); + // EntityManager em = emf.createEntityManager(); + // em.getTransaction().begin(); + // + // EntityGraph entityGraph = em.createEntityGraph("graph.StorageObjectStorage"); + // TypedQuery query = em.createQuery("SELECT a FROM StorageObject a", StorageObject.class).setHint("javax.persistence.fetchgraph", entityGraph); + // List resultList = query.getResultList(); + // + // em.getTransaction().commit(); + // em.close(); + // + // for(StorageObject so : resultList){ + // if(so.getId().equals(id)){ + // sto = so; + // } + // } + // + // if(sto != null){ + // return sto; + // }else{ + // throw new StorageObjectException("Could not find StorageObject with id: '%s' in DB".formatted(id)); + // } + // } + + @Transactional + public Optional findStorageObjectByIDOptional(Long id) { + if (id != null) { + if (repositoryStorageObject.findById(id) + .isPresent()) { + return repositoryStorageObject.findById(id); + } else { + throw new StorageObjectException( + "Could not find StorageObject with id: '%s' in DB".formatted(id)); + } + } else { + throw new StorageObjectException("Given id is null!"); + } + } + + public void deleteStorageObjectById(Long id) { + if (id != null) { + if (!repositoryStorageObject.findAll() + .isEmpty()) { + repositoryStorageObject.deleteById(id); + } else { + throw new StorageObjectException("StorageObject DB is empty!"); + } + } else { + throw new StorageObjectException("StorageObject id is null!"); + } + } + + public void deleteByObject(StorageObject storageObject) { + if (storageObject != null) { + if (!repositoryStorageObject.findAll() + .isEmpty()) { + repositoryStorageObject.delete(storageObject); + } else { + throw new StorageObjectException("StorageObject DB is empty!"); + } + } else { + throw new StorageObjectException("StorageObject is null!"); + } + } + + public boolean doesObjectExistById(Long id) { + if (id != null) { + return repositoryStorageObject.existsById(id); + } else { + throw new StorageObjectException("StorageObject id is null!"); + } + } + + @Transactional + public Optional findStorageByNameOptional(ObjectType objectType) { + if (objectType != null) { + if (repositoryStorageObject.findStorageObjectByObjectTypeName(objectType) + .isPresent()) { + return repositoryStorageObject.findStorageObjectByObjectTypeName(objectType); + } else { + throw new StorageObjectException( + "Could not find StorageObject with objectType: '%s' in DB".formatted( + objectType.getName())); + } + } else { + throw new StorageObjectException("Given name is null!"); + } + } + + @Transactional + public Stream findAll() { + if (repositoryStorageObject.findAll() + .isEmpty()) { + throw new StorageObjectException("StorageObject list is empty!"); + } else { + return repositoryStorageObject.findAll() + .stream(); + } + } + + @Transactional + public List findNotReservedStorageObjects() { + List freeStorageObjects = new ArrayList<>(); + if (!repositoryStorageObject.findAll() + .isEmpty()) { + List storageObjectList = repositoryStorageObject.findAll(); + Iterator iter = storageObjectList.iterator(); + while (iter.hasNext()) { + StorageObject TempstorageObject = iter.next(); + if (TempstorageObject.getReservation() == null) { + freeStorageObjects.add(TempstorageObject); } - } - - public Stream findAllStorageObjectByCPEID(Long id, - PageRequest request){ - if(id != null){ - return repositoryStorageObject.findStorageObjectByCpe_Id(id, - request) - .stream(); - }else{ - throw new StorageObjectException("Given id is null!"); - } - } - - public Stream findAllStorageObjectByCPEIDStream(Long id){ - if(id != null){ - return repositoryStorageObject.findStorageObjectByCpe_Id(id); - }else{ - throw new StorageObjectException("Given id is null!"); - } - } - - public Stream findStorageObjectsByStorageId(Long id, - PageRequest request){ - if(id != null){ - return repositoryStorageObject.findStorageObjectsByStorage_Id(id, - request) - .stream(); - }else{ - throw new StorageObjectException("Given id is null!"); + } + } else { + throw new StorageObjectException("StorageObject list is empty!"); + } + if (freeStorageObjects.isEmpty()) { + throw new StorageObjectException("There are no Free StorageObjects in DB!"); + } + return freeStorageObjects; + } + + @Transactional + public List findReservedStorageObjects() { + List reservedStorageObjects = repositoryStorageObject.findAll(); + // List storageObjectList = repositoryStorageObject.findAll(); + if (!reservedStorageObjects.isEmpty()) { + Iterator iter = reservedStorageObjects.iterator(); + while (iter.hasNext()) { + StorageObject TempstorageObject = iter.next(); + if (TempstorageObject.getReservation() != null) { + reservedStorageObjects.add(TempstorageObject); } + } + } else { + throw new StorageObjectException("StorageObject list is empty!"); + } + if (reservedStorageObjects.isEmpty()) { + throw new StorageObjectException("There are no Free StorageObjects in DB!"); } + return reservedStorageObjects; + } + + + @Transactional + public void deleteAll() { + if (repositoryStorageObject.count() > 0) { + repositoryStorageObject.deleteAll(); + } else { + throw new StorageObjectException("StorageObject DB is empty!"); + } + } + + + public Stream findAllStorageObjectByUserId(Long id, + PageRequest request) { + if (id != null) { + return repositoryStorageObject.findAllByStoredAtUser_Id(id, + request) + .stream(); + } else { + throw new StorageObjectException("Given id is null!"); + } + } + + public Stream findAllStorageObjectByUserIdStream(Long id) { + if (id != null) { + return repositoryStorageObject.findStorageObjectsByStoredAtUser_Id(id); + } else { + throw new StorageObjectException("Given id is null!"); + } + } + + + public StorageObject findStorageObjectByReservationID(Long id) { + if (id != null) { + return repositoryStorageObject.findStorageObjectByReservation_Id(id); + } else { + throw new StorageObjectException("Given id is null!"); + } + } + + //////////////////// + public Stream findAllStoageObjectBySFPID(Long id, + PageRequest request) { + if (id != null) { + return repositoryStorageObject.findStorageObjectsBySfp_Id(id, + request) + .stream(); + } else { + throw new StorageObjectException("Given id is null!"); + } + } + + public Stream findAllStoageObjectBySFPIDStream(Long id) { + if (id != null) { + return repositoryStorageObject.findStorageObjectsBySfp_Id(id); + } else { + throw new StorageObjectException("Given id is null!"); + } + } + + public Stream findAllStorageObjectByCPEID(Long id, + PageRequest request) { + if (id != null) { + return repositoryStorageObject.findStorageObjectByCpe_Id(id, + request) + .stream(); + } else { + throw new StorageObjectException("Given id is null!"); + } + } + + public Stream findAllStorageObjectByCPEIDStream(Long id) { + if (id != null) { + return repositoryStorageObject.findStorageObjectByCpe_Id(id); + } else { + throw new StorageObjectException("Given id is null!"); + } + } + + public Stream findStorageObjectsByStorageId(Long id, + PageRequest request) { + if (id != null) { + return repositoryStorageObject.findStorageObjectsByStorage_Id(id, + request) + .stream(); + } else { + throw new StorageObjectException("Given id is null!"); + } + } + + public Stream findStorageObjectsByStorageIdStream(Long id) { + if (id != null) { + return repositoryStorageObject.findStorageObjectsByStorage_Id(id); + } else { + throw new StorageObjectException("Given id is null!"); + } + } + + public Stream findStorageObjectsBySupplyId(Long id, + PageRequest request) { + if (id != null) { + return repositoryStorageObject.findStorageObjectsBySupply_Id(id, + request) + .stream(); + } else { + throw new StorageObjectException("Given id is null!"); + } + } + + public Stream findStorageObjectsBySupplyIdStream(Long id) { + if (id != null) { + return repositoryStorageObject.findStorageObjectsBySupply_Id(id); + } else { + throw new StorageObjectException("Given id is null!"); + } + } + + public Stream findFreeStorageObjects() { + Stream freeStorageObjects = repositoryStorageObject.findAll() + .stream(); + return freeStorageObjects.filter(storageObject -> storageObject.getReservation() == null) + .filter(storageObject -> storageObject.getStoredAtUser() == null); + } + + public Stream findReservedStorageObjectsAsStream() { + Stream reservedStorageObjects = repositoryStorageObject.findAll() + .stream(); + return reservedStorageObjects.filter(storageObject -> storageObject.getReservation() != null) + .filter(storageObject -> storageObject.getStoredAtUser() == null); + } + + public Stream findStorageObjectByGivenUser(User user) { + Stream storageObjectOnUser = repositoryStorageObject.findAll() + .stream(); + return storageObjectOnUser.filter(stor -> stor.getStoredAtUser() != null) + .filter(storageObject -> storageObject.getStoredAtUser() + .getId() + .equals(user.getId())); + } + + // public Optional findStorageObjectByCustomer(String verbindungsnummer){ + // return repositoryStorageObject.findStorageObjectByVerbindungsnummer(verbindungsnummer); + // } + + // public Stream listStorageObjectByName(String filterStrig){ + // String likeFiler = "%"+filterStrig+"%"; + // Page returnTemp = repositoryStorageObject.findAllByObjectTypeNameLikeIgnoreCase(likeFiler, ); return returnTemp.stream(); + // } + + // public Stream searchSpringRepoMethod(String keyword, Query query){ + // keyword = P+keyword+P; + // List data = repositoryStorageObject.findAllByObjectTypeNameLikeIgnoreCase(keyword, keyword, toPageable(query)); + // return data.stream(); + // } + + public Stream searchSto(String filterString, + Pageable pageable, + Long id) { + return repositoryStorageObject.filterStorageObjectsByObjectTypeNameName(filterString, + pageable, + Optional.of(id)) + .stream(); + } + + public Stream searchTempo(String filter, + Pageable pageable) { + return repositoryStorageObject.findAll() + .stream() + .filter(f -> f.getObjectTypeName() + .equals(filter)); + } + + public Pageable toPageable(Query query) { + return PageRequest.of(query.getPage(), + query.getPageSize(), + VaadinSpringDataHelpers.toSpringDataSort(query)); + } + + //Map mit den Geräten und der Anzahl der Geräte mit stream und map hardocded 2 + public Map findAmountOfObjectType1() { + + Map mapList = new HashMap<>(); + + List all = repositoryStorageObject.findAll(); + + if (all.isEmpty()) { + throw new ObjectTypeException("Map is empty!"); + } + + long c927 = all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("C927")) + .count(); + + long C1111 = all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("C1111-4p")) + .count(); + + long asr920 = all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("ASR920-12SZ-IM")) + .count(); + + long C897VAB = all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("C897VAB")) + .count(); + + long C1117 = all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("C1117-4p")) + .count(); - public Stream findStorageObjectsByStorageIdStream(Long id){ - if(id != null){ - return repositoryStorageObject.findStorageObjectsByStorage_Id(id); - }else{ - throw new StorageObjectException("Given id is null!"); - } - } - - public Stream findStorageObjectsBySupplyId(Long id, - PageRequest request){ - if(id != null){ - return repositoryStorageObject.findStorageObjectsBySupply_Id(id, - request) - .stream(); - }else{ - throw new StorageObjectException("Given id is null!"); - } - } - - public Stream findStorageObjectsBySupplyIdStream(Long id){ - if(id != null){ - return repositoryStorageObject.findStorageObjectsBySupply_Id(id); - }else{ - throw new StorageObjectException("Given id is null!"); - } - } - - public Stream findFreeStorageObjects(){ - Stream freeStorageObjects = repositoryStorageObject.findAll() - .stream(); - return freeStorageObjects.filter(storageObject -> storageObject.getReservation() == null) - .filter(storageObject -> storageObject.getStoredAtUser() == null); - } - - public Stream findReservedStorageObjectsAsStream(){ - Stream reservedStorageObjects = repositoryStorageObject.findAll() - .stream(); - return reservedStorageObjects.filter(storageObject -> storageObject.getReservation() != null) - .filter(storageObject -> storageObject.getStoredAtUser() == null); - } - - public Stream findStorageObjectByGivenUser(User user){ - Stream storageObjectOnUser = repositoryStorageObject.findAll() - .stream(); - return storageObjectOnUser.filter(stor -> stor.getStoredAtUser() != null) - .filter(storageObject -> storageObject.getStoredAtUser() - .getId() - .equals(user.getId())); - } - - // public Optional findStorageObjectByCustomer(String verbindungsnummer){ - // return repositoryStorageObject.findStorageObjectByVerbindungsnummer(verbindungsnummer); - // } - - // public Stream listStorageObjectByName(String filterStrig){ - // String likeFiler = "%"+filterStrig+"%"; - // Page returnTemp = repositoryStorageObject.findAllByObjectTypeNameLikeIgnoreCase(likeFiler, ); return returnTemp.stream(); - // } - - // public Stream searchSpringRepoMethod(String keyword, Query query){ - // keyword = P+keyword+P; - // List data = repositoryStorageObject.findAllByObjectTypeNameLikeIgnoreCase(keyword, keyword, toPageable(query)); - // return data.stream(); - // } - - public Stream searchSto(String filterString, - Pageable pageable, - Long id){ - return repositoryStorageObject.filterStorageObjectsByObjectTypeNameName(filterString, - pageable, - Optional.of(id)) - .stream(); - } - - public Stream searchTempo(String filter, - Pageable pageable){ - return repositoryStorageObject.findAll() - .stream() - .filter(f -> f.getObjectTypeName() - .equals(filter)); - } - - public Pageable toPageable(Query query){ - return PageRequest.of(query.getPage(), - query.getPageSize(), - VaadinSpringDataHelpers.toSpringDataSort(query)); - } - - //Map mit den Geräten und der Anzahl der Geräte mit stream und map hardocded 2 - public Map findAmountOfObjectType1(){ - - Map mapList = new HashMap<>(); - - List all = repositoryStorageObject.findAll(); - - if(all.isEmpty()){ - throw new ObjectTypeException("Map is empty!"); - } - - long c927 = all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("C927")) - .count(); - - long C1111 = all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("C1111-4p")) - .count(); - - long asr920 = all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("ASR920-12SZ-IM")) - .count(); - - long C897VAB = all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("C897VAB")) - .count(); - - long C1117 = all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("C1117-4p")) - .count(); - - // - long HP = all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("HP J9050A")) - .count(); - - long Aruba = all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("Aruba 2530 8-PoE+")) - .count(); - long M300 = all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("M300")) - .count(); - long D865 = all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("D865")) - .count(); - long D862 = all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("D862")) - .count(); - long GLC = all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("GLC-LH-SM")) - .count(); - long LC = all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("LC-SX-MM")) - .count(); - - - mapList.put("C927", - c927); - mapList.put("C1111", - C1111); - mapList.put("asr920", - asr920); - mapList.put("C897VAB", - C897VAB); - mapList.put("C1117", - C1117); - mapList.put("HP J9050A", - HP); - mapList.put("Aruba 2530 8-PoE+", - Aruba); - mapList.put("M300", - M300); - mapList.put("D865", - D865); - mapList.put("D862", - D862); - mapList.put("GLC-LH-SM", - GLC); - mapList.put("LC-SX-MM", - LC); - - return mapList; - - } - - //Map mit den Geräten und der Anzahl der Geräte mit stream und map hardcoded 2 - public Map findAmountOfObjectType2(){ - Map maxValues = new HashMap<>(); - - List all = repositoryStorageObject.findAll(); - - if(all.isEmpty()){ - throw new ObjectTypeException("Map is empty!"); - } - - maxValues.put("C927", - all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("C927")) - .count()); - maxValues.put("C1111-4p", - all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("C1111-4p")) - .count()); - maxValues.put("ASR920-12SZ-IM", - all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("ASR920-12SZ-IM")) - .count()); - maxValues.put("C897VAB", - all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("C897VAB")) - .count()); - maxValues.put("C1117-4p", - all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("C1117-4p")) - .count()); - maxValues.put("HP J9050A", - all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("HP J9050A")) - .count()); - maxValues.put("Aruba 2530 8-PoE+", - all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("Aruba 2530 8-PoE+")) - .count()); - maxValues.put("M300", - all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("M300")) - .count()); - maxValues.put("D865", - all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("D865")) - .count()); - maxValues.put("D862", - all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("D862")) - .count()); - maxValues.put("GLC-LH-SM", - all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("GLC-LH-SM")) - .count()); - maxValues.put("LC-SX-MM", - all.stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals("LC-SX-MM")) - .count()); - return maxValues; - } - - //Einzelwert für die Anzahl der Geräte holen - public Long findAmountOfObjectType2(String objectType){ - return repositoryStorageObject.findAll() - .stream() - .filter(a -> a.getObjectTypeName() != null) - .filter(b -> b.getObjectTypeName() - .getName() - .equals(objectType)) - .count(); - // return repositoryStorageObject.findAll() - // .stream() - // .filter(name -> name.getObjectTypeName() - // .getName() - // .equals(objectType)) - // .count(); - } - - // 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(); - } - - public void moveFromReservationToMeineHardware(Reservation reservation){ - if(reservation != null){ - if(reservation.getReservedFrom().getId() == authenticatedUser.getUser() - .get().getId()){ - if(reservation.getId() != null && repositoryReservation.existsById(reservation.getId())){ - Reservation reservationById = repositoryReservation.findById(reservation.getId()) - .get(); - - StorageObject storageObjectByReservationId = repositoryStorageObject.findStorageObjectByReservation_Id(reservationById.getId()); - storageObjectByReservationId.setRemark(reservationById.getReservedDescription()); - - // reservationById.setReservedFrom(null); - // storageObjectByReservationId.setReservation(null); - reservationById.setReservedFrom(null); - storageObjectByReservationId.setReservation(null); - repositoryReservation.deleteById(Objects.requireNonNull(reservationById.getId())); - // serviceReservation.deleteByObject(reservationById); - - serviceStorageObjectHistory.setStorageOBjectHistory(storageObjectByReservationId); - saveStorageObject(storageObjectByReservationId); - - }else{ - throw new StorageObjectException(reservation.getId() == null ? "Reservation ID is null!" : "Reservation doesn't exist in DB!"); - } - }else{ - throw new StorageObjectException("User does not match with the logged-in User!"); - } - }else{ - throw new StorageObjectException("Given Reservation is null!"); + // + long HP = all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("HP J9050A")) + .count(); + + long Aruba = all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("Aruba 2530 8-PoE+")) + .count(); + long M300 = all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("M300")) + .count(); + long D865 = all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("D865")) + .count(); + long D862 = all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("D862")) + .count(); + long GLC = all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("GLC-LH-SM")) + .count(); + long LC = all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("LC-SX-MM")) + .count(); + + mapList.put("C927", + c927); + mapList.put("C1111", + C1111); + mapList.put("asr920", + asr920); + mapList.put("C897VAB", + C897VAB); + mapList.put("C1117", + C1117); + mapList.put("HP J9050A", + HP); + mapList.put("Aruba 2530 8-PoE+", + Aruba); + mapList.put("M300", + M300); + mapList.put("D865", + D865); + mapList.put("D862", + D862); + mapList.put("GLC-LH-SM", + GLC); + mapList.put("LC-SX-MM", + LC); + + return mapList; + + } + + //Map mit den Geräten und der Anzahl der Geräte mit stream und map hardcoded 2 + public Map findAmountOfObjectType2() { + Map maxValues = new HashMap<>(); + + List all = repositoryStorageObject.findAll(); + + if (all.isEmpty()) { + throw new ObjectTypeException("Map is empty!"); + } + + maxValues.put("C927", + all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("C927")) + .count()); + maxValues.put("C1111-4p", + all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("C1111-4p")) + .count()); + maxValues.put("ASR920-12SZ-IM", + all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("ASR920-12SZ-IM")) + .count()); + maxValues.put("C897VAB", + all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("C897VAB")) + .count()); + maxValues.put("C1117-4p", + all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("C1117-4p")) + .count()); + maxValues.put("HP J9050A", + all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("HP J9050A")) + .count()); + maxValues.put("Aruba 2530 8-PoE+", + all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("Aruba 2530 8-PoE+")) + .count()); + maxValues.put("M300", + all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("M300")) + .count()); + maxValues.put("D865", + all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("D865")) + .count()); + maxValues.put("D862", + all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("D862")) + .count()); + maxValues.put("GLC-LH-SM", + all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("GLC-LH-SM")) + .count()); + maxValues.put("LC-SX-MM", + all.stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals("LC-SX-MM")) + .count()); + return maxValues; + } + + //Einzelwert für die Anzahl der Geräte holen + public Long findAmountOfObjectType2(String objectType) { + return repositoryStorageObject.findAll() + .stream() + .filter(a -> a.getObjectTypeName() != null) + .filter(b -> b.getObjectTypeName() + .getName() + .equals(objectType)) + .count(); + // return repositoryStorageObject.findAll() + // .stream() + // .filter(name -> name.getObjectTypeName() + // .getName() + // .equals(objectType)) + // .count(); + } + + // 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(); + } + + public void moveFromReservationToMeineHardware(Reservation reservation) { + if (reservation != null) { + if (reservation.getReservedFrom().getId() == authenticatedUser.getUser() + .get().getId()) { + if (reservation.getId() != null && repositoryReservation.existsById(reservation.getId())) { + Reservation reservationById = repositoryReservation.findById(reservation.getId()) + .get(); + + StorageObject storageObjectByReservationId = repositoryStorageObject.findStorageObjectByReservation_Id( + reservationById.getId()); + storageObjectByReservationId.setRemark(reservationById.getReservedDescription()); + storageObjectByReservationId.setStoredAtUser(authenticatedUser.getUser().get()); + + // reservationById.setReservedFrom(null); + // storageObjectByReservationId.setReservation(null); + reservationById.setReservedFrom(null); + storageObjectByReservationId.setReservation(null); + repositoryReservation.deleteById(Objects.requireNonNull(reservationById.getId())); + // serviceReservation.deleteByObject(reservationById); + + serviceStorageObjectHistory.setStorageOBjectHistory(storageObjectByReservationId); + saveStorageObject(storageObjectByReservationId); + + } else { + throw new StorageObjectException(reservation.getId() == null ? "Reservation ID is null!" + : "Reservation doesn't exist in DB!"); } + } else { + throw new StorageObjectException("User does not match with the logged-in User!"); + } + } else { + throw new StorageObjectException("Given Reservation is null!"); } + } } diff --git a/src/main/java/com/samic/samic/views/dashboard/DashboardView.java b/src/main/java/com/samic/samic/views/dashboard/DashboardView.java index a620b46..e0be448 100644 --- a/src/main/java/com/samic/samic/views/dashboard/DashboardView.java +++ b/src/main/java/com/samic/samic/views/dashboard/DashboardView.java @@ -8,6 +8,7 @@ import com.samic.samic.components.form.UserForm; import com.samic.samic.components.grid.ReservationGrid; import com.samic.samic.components.grid.StorageObjectGrid; +import com.samic.samic.data.entity.Address; import com.samic.samic.data.entity.CPE; import com.samic.samic.data.entity.Producer; import com.samic.samic.data.entity.Profile; @@ -163,7 +164,7 @@ private void initQuickAccess() { menuBar.addItem("Lager hinzufügen", onClick -> { Dialog dialog = new Dialog(); dialog.add(storageForm); - storageForm.setBean(Storage.builder().build()); + storageForm.setBean(Storage.builder().address(Address.builder().build()).build()); dialog.add(UIFactory.btnPrimary("Speichern", e -> { dialog.close(); onSave(storageForm.isValid() ? storageForm.saveBean() : null); 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 6a49b66..257c0bf 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,7 +90,9 @@ private void initReservationGrid() { private void moveToUser(Reservation item) { storageObjectService.moveFromReservationToMeineHardware(item); - + initReservationGridData(); + initStorageObjectGridData(); + } private void initReservationGridData() {