Skip to content

Commit

Permalink
Changes (#33)
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
Serberx authored Feb 26, 2024
1 parent e31a675 commit b730bb4
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 26 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
10 changes: 5 additions & 5 deletions src/main/java/com/samic/samic/data/fixture/Fixtures.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -374,7 +374,7 @@ public static StorageObject giveStorageObject2(){
return StorageObject.builder()
.remark("remark1")
.objectTypeName(giveObjectType2())
.verbindungsnummer("1234")
// .verbindungsnummer("1234")

.projectDevice(false)
.status(Status.AVAILABLE)
Expand All @@ -386,7 +386,7 @@ public static StorageObject giveStorageObject3(){
return StorageObject.builder()
.remark("remark1")
.objectTypeName(giveObjectType3())
.verbindungsnummer("1234")
// .verbindungsnummer("1234")

.projectDevice(false)
.status(Status.AVAILABLE)
Expand All @@ -398,7 +398,7 @@ public static StorageObject giveStorageObject4(){
return StorageObject.builder()
.remark("remark1")
.objectTypeName(giveObjectType4())
.verbindungsnummer("1234")
// .verbindungsnummer("1234")

.projectDevice(false)
.status(Status.AVAILABLE)
Expand All @@ -410,7 +410,7 @@ public static StorageObject giveStorageObject5(){
return StorageObject.builder()
.remark("remark1")
.objectTypeName(giveObjectType5())
.verbindungsnummer("1234")
// .verbindungsnummer("1234")

.projectDevice(false)
.status(Status.AVAILABLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -22,4 +24,6 @@ public interface RepositoryReservation extends JpaRepository<Reservation, Long>{

Optional<Reservation> findAllByReservedFrom_Id(Long id);

Page<Reservation> findAllByReservedFrom_Id(Long id,
Pageable request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ public interface RepositoryStorageObject extends JpaRepository<StorageObject, Lo

Stream<StorageObject> findStorageObjectByCpe_Id(Long id);

// Optional<StorageObject> findStorageObjectByVerbindungsnummer(String verbinNr);
// Optional<StorageObject> findStorageObjectByVerbindungsnummer(String verbinNr);

// List<StorageObject> findAllByObjectTypeNameLikeIgnoreCase(String keyword, String keyword1, Pageable pageable);

List<StorageObject> findAllByObjectTypeName_Name(String filterString, Pageable pageable);

List<StorageObject> 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<StorageObject> searchUnemployedWithOr(String keyword, Pageable pageable);
//
Expand Down
39 changes: 26 additions & 13 deletions src/main/java/com/samic/samic/services/ServiceReservation.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,24 +25,26 @@ public class ServiceReservation{

@Autowired
private final RepositoryReservation repositoryReservation;
@Autowired
private final ServiceStorageObject serviceStorageObject;
// @Autowired
// private final AuthenticatedUser authenticatedUser;

@Transactional
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{
Expand Down Expand Up @@ -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!");
}
Expand Down Expand Up @@ -155,12 +165,15 @@ public Stream<Reservation> findAllReservationByUserIdStream(Long id){
}

@Transactional
public Stream<Reservation> findAllReservationByGivenUser(User user){
Stream<Reservation> reservationOnUser = repositoryReservation.findReservationsByReservedFrom(user);


return reservationOnUser/*.peek(u -> System.out.println(u.toString()+"\n"))*/.filter(reservation -> reservation.getReservedFrom()
.getId()
.equals(user.getId()));
public List<Reservation> findAllReservationByGivenUser(User user){
Stream<Reservation> 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();
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/samic/samic/services/ServiceStorageObject.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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 ########################, {}: ",
Expand Down Expand Up @@ -695,4 +713,11 @@ public Long findAmountOfObjectType2(String objectType){
// public Stream<StorageObject> findStorageObjectByUserId(Long id, PageRequest query){
// return repositoryStorageObject.findAllByStoredAtUser_Id(id, query).stream();
// }

public Stream<Reservation> findStorageObjectByUserId(Long id,
PageRequest request){
return repositoryReservation.findAllByReservedFrom_Id(id,
request)
.stream();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit b730bb4

Please sign in to comment.