diff --git a/opp/core/src/main/java/OPStaffServiceImpl.java b/opp/core/src/main/java/OPStaffServiceImpl.java index f3b67efcf1b0ed29c7939cb068a84e58ae4e9dff..134be4f836db96d97492d4235fd64bb93a8545b9 100644 --- a/opp/core/src/main/java/OPStaffServiceImpl.java +++ b/opp/core/src/main/java/OPStaffServiceImpl.java @@ -55,8 +55,10 @@ public class OPStaffServiceImpl implements OPStaffService{ public OPStaff delete(OPStaff.Delete del) throws Exception{ - return repo.deleteOPStaff(del.id()); - + if(repo.findOPStaffOperationTeams(del.id())==false){ //wenn false, dann ist er keinem team zugewiesen + return repo.deleteOPStaff(del.id()); + } + return null; } @Override diff --git a/opp/core/src/main/java/OperationServiceImpl.java b/opp/core/src/main/java/OperationServiceImpl.java index 20c683e69b4e0330b0f25eaf93b722d7976b4f7a..c36508e9296184566d3a608bd1745a3ce85ea96b 100644 --- a/opp/core/src/main/java/OperationServiceImpl.java +++ b/opp/core/src/main/java/OperationServiceImpl.java @@ -100,6 +100,10 @@ public class OperationServiceImpl implements OperationService { */ public Operation delete(Operation.Delete del) throws Exception { - return repo.deleteOperation(del.id()); + Optional<Operation> foundOperation = repo.findOperation(del.id()); + if (foundOperation.isPresent()) { + return repo.deleteOperation(del.id()); + } + return null; } } diff --git a/opp/core/src/main/java/OperationTeamImpl.java b/opp/core/src/main/java/OperationTeamImpl.java index 5305756c6dac43de643aa59c265b5c37f7d768e1..e1e50ffa67a6901b599375599cfb0350abdf1899 100644 --- a/opp/core/src/main/java/OperationTeamImpl.java +++ b/opp/core/src/main/java/OperationTeamImpl.java @@ -1,5 +1,6 @@ import java.sql.SQLException; import java.time.Instant; +import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -22,8 +23,23 @@ public class OperationTeamImpl implements OperationTeamService{ }; } - private OperationTeam delete(OperationTeam.Delete del) throws SQLException { - return repo.deleteOperationTeam(del.operationTeamId()); + private OperationTeam delete(OperationTeam.Delete del) throws Exception { + + Optional<OperationTeam> returnedOperationTeam = repo.findOperationTeam(del.operationTeamId()); + + if(returnedOperationTeam.isPresent()) { + if (returnedOperationTeam.get().opStaffs().isEmpty()) { + return repo.deleteOperationTeam(del.operationTeamId()); + } else { + int sizeOPStafflist = returnedOperationTeam.get().opStaffs().size(); + for(int i = 0; i<sizeOPStafflist; i++){ + repo.removeOPStaffInOperationTeam(del.operationTeamId(),returnedOperationTeam.get().opStaffs().get(i).id()); + } + return repo.deleteOperationTeam(del.operationTeamId()); + + } + } + return null; } //Only creates a connection between the newly created operationTeam and the already existing opStaffs. @@ -65,10 +81,13 @@ public class OperationTeamImpl implements OperationTeamService{ private OperationTeam removeStaff(OperationTeam.RemoveStaff rs) throws Exception { - OperationTeam findOperationTeam = repo.getOperationTeam(rs.operationTeamId()); + Optional<OperationTeam> findOperationTeam = repo.findOperationTeam(rs.operationTeamId()); - if(repo.removeOPStaffInOperationTeam(rs.operationTeamId(), rs.opStaffId())){ - return findOperationTeam; + if(findOperationTeam.isPresent()){ + if(repo.removeOPStaffInOperationTeam(rs.operationTeamId(), rs.opStaffId())){ + Optional<OperationTeam> newOperationTeam = repo.findOperationTeam(rs.operationTeamId()); + return newOperationTeam.get(); + } } return null; } diff --git a/opp/core/src/main/java/PreparationNote.java b/opp/core/src/main/java/PreparationNote.java index 073b3efc5e856a3b985083469b314115bf75e666..25bf198499066cc83d5dc5936989bfe6efa5bee8 100644 --- a/opp/core/src/main/java/PreparationNote.java +++ b/opp/core/src/main/java/PreparationNote.java @@ -1,80 +1,31 @@ import java.time.Instant; -import java.time.LocalDateTime; -import java.util.Objects; +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.Optional; -import java.util.Objects; +public record PreparationNote ( -public class PreparationNote { - private String noteId; // Eindeutige Identifikation der Notiz - private String operationId; // ID der zugehörigen Operation - private String content; // Inhalt der Notiz + Id<PreparationNote> id, + String note, + Id<Operation> operationsId, + Instant lastUpdate +) { - // Konstruktor zur Initialisierung der Notiz-Attribute - public PreparationNote(String noteId, String operationId, String content) { - this.noteId = noteId; - this.operationId = operationId; - this.content = content; - } -/* - // Getter und Setter Methoden für die Attribute - public String getId() { - return noteId; - } + public static sealed interface Command permits Create, Update, Delete { } - public void setNoteId(String noteId) { - this.noteId = noteId; - } + public static record Create( + String note, + Id<Operation> operationsId + ) implements Command {} - public String getOperationId() { - return operationId; - } + public static record Update( + Id<PreparationNote> id, + String note + ) implements Command {} - public void setOperationId(String operationId) { - this.operationId = operationId; - } + public static record Delete( + Id<PreparationNote> id + ) implements Command {} - public String getContent() { - return content; - } - public void setContent(String content) { - this.content = content; - } - - // toString Methode zur Darstellung der Notiz als String - @Override - public String toString() { - return "PreparationNote{" + - "noteId='" + noteId + '\'' + - ", operationId='" + operationId + '\'' + - ", content='" + content + '\'' + - '}'; - } - - // equals Methode zum Vergleichen von zwei PreparationNote Objekten - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - PreparationNote that = (PreparationNote) o; - return Objects.equals(noteId, that.NoteId) && - Objects.equals(operationId, that.operationId) && - Objects.equals(content, that.content); - } - // hashCode Methode zur Berechnung des Hashcodes eines PreparationNote Objekts - @Override - public int hashCode() { - return Objects.hash(noteId, operationId, content); - } - - - */ } - -//public record PreparationNote( -// Id<PreparationNote> preparationNoteId, -// String text, -// Operation operationId, -// Instant lastUpdate -//) { - diff --git a/opp/core/src/main/java/PreparationNoteCommand.java b/opp/core/src/main/java/PreparationNoteCommand.java deleted file mode 100644 index 4581407480159030077bd461dc98811926b06ce9..0000000000000000000000000000000000000000 --- a/opp/core/src/main/java/PreparationNoteCommand.java +++ /dev/null @@ -1,27 +0,0 @@ -public class PreparationNoteCommand { - private String operationId; - private String content; - - // Konstruktor zur Initialisierung der Command-Attribute - public PreparationNoteCommand(String operationId, String content) { - this.operationId = operationId; - this.content = content; - } - - // Getter und Setter Methoden für die Attribute - public String getOperationId() { - return operationId; - } - - public void setOperationId(String operationId) { - this.operationId = operationId; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } -} diff --git a/opp/core/src/main/java/PreparationNoteImpl.java b/opp/core/src/main/java/PreparationNoteImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..2b40100f37ea18303b235901b04cb7939d05c485 --- /dev/null +++ b/opp/core/src/main/java/PreparationNoteImpl.java @@ -0,0 +1,71 @@ +import java.time.Instant; +import java.util.Optional; + +public class PreparationNoteImpl implements PreparationNoteService { + + private final Repository repo; + + public PreparationNoteImpl(Repository repo) { + this.repo = repo; + } + + @Override + public PreparationNote process(PreparationNote.Command cmd) throws Exception { + return switch (cmd){ + case PreparationNote.Create cr -> create(cr); + case PreparationNote.Update up -> update(up); + case PreparationNote.Delete del -> delete(del); + }; + } + + public PreparationNote create(PreparationNote.Create cr) throws Exception { + PreparationNote preparationNote = + new PreparationNote( + repo.preparationNoteId(), + cr.note(), + cr.operationsId(), + Instant.now()); + + repo.save(preparationNote); + + return preparationNote; + } + + public PreparationNote update(PreparationNote.Update up) throws Exception { + + Optional<PreparationNote> foundPreparationNote = repo.findPreparationNote(up.id()); + + PreparationNote preparationNote = null; + if (foundPreparationNote.isPresent()) { + PreparationNote currentPreparationNote = foundPreparationNote.get(); + + preparationNote = + new PreparationNote( + currentPreparationNote.id(), + up.note(), + currentPreparationNote.operationsId(), + Instant.now()); + + repo.save(preparationNote); + } + + return preparationNote; + } + + private PreparationNote delete(PreparationNote.Delete del) throws Exception { + + Optional<PreparationNote> returnedPreparationNote = repo.findPreparationNote(del.id()); + + if(returnedPreparationNote.isPresent()) { + return repo.deletePreparationNote(del.id()); + } + return null; + } + + public Optional<PreparationNote> findPreparationNote(Id<PreparationNote> id){ + return repo.findPreparationNote(id); + } + + + +} diff --git a/opp/core/src/main/java/PreparationNoteService.java b/opp/core/src/main/java/PreparationNoteService.java index 485c834dfa8432e1a2432823773422ba9539920d..d2f230ea643fa4410d9d0a071bcba564c3929ba0 100644 --- a/opp/core/src/main/java/PreparationNoteService.java +++ b/opp/core/src/main/java/PreparationNoteService.java @@ -1,9 +1,8 @@ -import java.util.List; +import java.util.Optional; public interface PreparationNoteService { - PreparationNote createNote(PreparationNoteCommand command); // Methode zum Erstellen einer neuen Notiz - PreparationNote updateNote(String noteId, PreparationNoteCommand command); // Methode zum Aktualisieren einer Notiz - void deleteNote(String noteId); // Methode zum Löschen einer Notiz - PreparationNote getNoteById(String noteId); // Methode zum Abrufen einer Notiz nach ID - List<PreparationNote> getNotesByOperationId(String operationId); // Methode zum Abrufen von Notizen nach Operation-ID + + PreparationNote process(PreparationNote.Command cmd) throws Exception; + + Optional<PreparationNote> findPreparationNote(Id<PreparationNote> id); } diff --git a/opp/core/src/main/java/Repository.java b/opp/core/src/main/java/Repository.java index 65b87c926e06c922bad6e09720cac0af70e1a60a..95eae49b8407de71d4151fa5b76a5ccc812fda82 100644 --- a/opp/core/src/main/java/Repository.java +++ b/opp/core/src/main/java/Repository.java @@ -97,4 +97,25 @@ public interface Repository { Boolean findOperationTeamOPStaff(Id<OperationTeam> operationTeamId, Id<OPStaff> opStaffId); + + Boolean findOPStaffOperationTeams(Id<OPStaff> opStaffId); + + + Id<PreparationNote> preparationNoteId(); + + Optional<PreparationNote> findPreparationNote(Id<PreparationNote> id); + + void save(PreparationNote preparationNote); + + PreparationNote deletePreparationNote(Id<PreparationNote> id); + + Id<Room> roomId(); + + Optional<Room> findRoom(Id<Room> id); + + void save(Room room); + + Room deleteRoom(Id<Room> id); + + } diff --git a/opp/core/src/main/java/Room.java b/opp/core/src/main/java/Room.java index d4928475e0da141e1bd394beddaea61a98cecfac..84df18408b1fd9d0be5d9f4b57e7a39e8f33f93f 100644 --- a/opp/core/src/main/java/Room.java +++ b/opp/core/src/main/java/Room.java @@ -1,72 +1,28 @@ import java.time.Instant; -import java.util.Objects; -public class Room { - private String roomId; // Eindeutige Identifikation des Raum - private String roomName;// Name des Raums - private int capacity; // Kapazität des Raums +public record Room ( + Id<Room> id, + String roomName, + Instant lastUpdate +) { - // Konstruktor zur Initialisierung der Raum-Attribute - public Room(String RoomId, String roomName, int capacity) { - this.roomId = roomId; - //this.roomName = RoomName; - this.capacity = capacity; - } + public static sealed interface Command permits + Create, + Update, + Delete + {} - // Getter und Setter Methoden für die Attribute - //public String getRoomId() { - // return RoomId; - //} + public static record Create( + String roomName + ) implements Command {} - //public void setRoomId(String roomId) { - // this.id = RoomId; - //} + public static record Update( + Id<Room> id, + String roomName + ) implements Command{} - public String getRoomName() { - return roomName; - } + public static record Delete( + Id<Room> id + ) implements Command{} - public void setRoomName(String roomName) { - this.roomName = roomName; - } - - public int getCapacity() { - return capacity; - } - - public void setCapacity(int capacity) { - this.capacity = capacity; - } - - // toString Methode zur Darstellung des Raums als String - @Override - public String toString() { - return "Room{" + - "roomId='" + roomId + '\'' + - ", roomName='" + roomName + '\'' + - ", capacity=" + capacity + - '}'; - } - - // equals Methode zum Vergleichen von zwei Room Objekten - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Room room = (Room) o; - return capacity == room.capacity && - Objects.equals(roomId, room.roomId) && - Objects.equals(roomName, room.roomName); - } - // hashCode Methode zur Berechnung des Hashcodes eines Room Objekts - @Override - public int hashCode() { - return Objects.hash(roomId, roomName, capacity); - } } - -//public record Room( -// Id<Room> roomId, -// String roomName, -// Instant lastUpdate -//) { diff --git a/opp/core/src/main/java/RoomCommand.java b/opp/core/src/main/java/RoomCommand.java deleted file mode 100644 index 64b61b069287535d1df32231d151a2cef1404809..0000000000000000000000000000000000000000 --- a/opp/core/src/main/java/RoomCommand.java +++ /dev/null @@ -1,27 +0,0 @@ -public class RoomCommand { - private String roomName; - private int capacity; - - // Konstruktor zur Initialisierung der Kommando-Attribute - public RoomCommand(String roomName, int capacity) { - this.roomName = roomName; - this.capacity = capacity; - } - - // Getter und Setter Methoden für die Attribute - public String getRoomName() { - return roomName; - } - - public void setRoomName(String roomName) { - this.roomName = roomName; - } - - public int getCapacity() { - return capacity; - } - - public void setCapacity(int capacity) { - this.capacity = capacity; - } -} diff --git a/opp/core/src/main/java/RoomService.java b/opp/core/src/main/java/RoomService.java index 35eb0b2002c13e28dd4d8ccd673d1503ddfa5820..9d6b01fc451755c7a1932b770fb8c24623bb3284 100644 --- a/opp/core/src/main/java/RoomService.java +++ b/opp/core/src/main/java/RoomService.java @@ -1,9 +1,8 @@ -import java.util.List; +import java.util.Optional; public interface RoomService { - Room createRoom(RoomCommand command); // Methode zum Erstellen eines neuen Raums - Room updateRoom(String roomId, RoomCommand command); // Methode zum Aktualisieren eines Raums - void deleteRoom(String roomId); // Methode zum Löschen eines Raums - Room getRoomById(String roomId); // Methode zum Abrufen eines Raums nach ID - List<Room> getAllRooms(); // Methode zum Abrufen aller Räume + + Room process(Room.Command cmd) throws Exception; + + Optional<Room> findRoom(Id<Room> id); } diff --git a/opp/core/src/main/java/RoomServiceImpl.java b/opp/core/src/main/java/RoomServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..8c927895975eaab8bc85ea00f7469181ef3b3d26 --- /dev/null +++ b/opp/core/src/main/java/RoomServiceImpl.java @@ -0,0 +1,65 @@ +import java.time.Instant; +import java.util.Optional; + +public class RoomServiceImpl implements RoomService { + + private final Repository repo; + + public RoomServiceImpl(Repository repo) { + this.repo = repo; + } + + @Override + public Room process(Room.Command cmd) throws Exception { + return switch (cmd){ + case Room.Create cr -> create(cr); + case Room.Update up -> update(up); + case Room.Delete del -> delete(del); + }; + } + + public Room create(Room.Create cr) throws Exception { + Room room = new Room( + repo.roomId(), + cr.roomName(), + Instant.now()); + + repo.save(room); + + return room; + } + + public Optional<Room> findRoom(Id<Room> id){ + return repo.findRoom(id); + } + + public Room update(Room.Update up) throws Exception { + + Optional<Room> foundRoom = repo.findRoom(up.id()); + + Room room = null; + if (foundRoom.isPresent()) { + Room currentRoom = foundRoom.get(); + + room = new Room( + currentRoom.id(), + up.roomName(), + Instant.now()); + + repo.save(room); + } + + return room; + } + + private Room delete(Room.Delete del) throws Exception { + + Optional<Room> returnedRoom = repo.findRoom(del.id()); + + if(returnedRoom.isPresent()) { + return repo.deleteRoom(del.id()); + } + return null; + } +} + diff --git a/opp/jdbc-repo-impl/src/main/java/JDBCRepository.java b/opp/jdbc-repo-impl/src/main/java/JDBCRepository.java index ed90a19e108a2ca189476faf3a7f2c5d90d44f6b..9b19fac04e400df8c864d1912e3390c2b3a8ebc9 100644 --- a/opp/jdbc-repo-impl/src/main/java/JDBCRepository.java +++ b/opp/jdbc-repo-impl/src/main/java/JDBCRepository.java @@ -97,6 +97,28 @@ class JDBCRepository implements Repository ); """; + /** + * The structure of the opStaffs table. + */ + private static final String CREATE_PREPARATIONNOTE_TABLE = """ + CREATE TABLE IF NOT EXISTS preparationNote( + id VARCHAR(50) PRIMARY KEY, + note VARCHAR(50) NOT NULL, + operationsId VARCHAR(50) NOT NULL, + lastUpdate TIMESTAMP NOT NULL, + FOREIGN KEY (operationsId) REFERENCES operations(id) + ); + """; + + private static final String CREATE_ROOM_TABLE = """ + CREATE TABLE IF NOT EXISTS room( + id VARCHAR(50) PRIMARY KEY, + roomName VARCHAR(50) NOT NULL, + lastUpdate TIMESTAMP NOT NULL + ); + """; + + //endregion @@ -112,6 +134,8 @@ class JDBCRepository implements Repository stmt.execute(CREATE_OP_STAFF_TABLE); stmt.execute(CREATE_OPERATION_TABLE); stmt.execute(CREATE_OP_STAFF_IN_OPERATION_TEAM_TABLE); + stmt.execute(CREATE_PREPARATIONNOTE_TABLE); + stmt.execute(CREATE_ROOM_TABLE); } catch (SQLException e){ throw new RuntimeException(e); @@ -763,6 +787,22 @@ class JDBCRepository implements Repository } } + @Override + public Boolean findOPStaffOperationTeams(Id<OPStaff> opStaffId){ + + try( + var result = + conn.createStatement() + .executeQuery("SELECT * " + + "FROM opStaffsInOperationTeams " + + "WHERE opStaffsInOperationTeams.opStaffId = " + quoted(opStaffId.value()) + ";") + ) { + return result.next(); + }catch(SQLException e){ + throw new RuntimeException(e); + } + } + /* @Override public List<OPStaff> getOperationTeamOPStaffImpl(Id<OperationTeam> operationTeamId){ @@ -794,6 +834,193 @@ class JDBCRepository implements Repository //endregion + + + @Override + public Id<PreparationNote> preparationNoteId() { + + var id = new Id<PreparationNote>(randomUUID().toString()); + + return findPreparationNote(id).isEmpty() ? id : preparationNoteId(); + } + + public Optional<PreparationNote> findPreparationNote(Id<PreparationNote> id){ + try ( + var result = + conn.createStatement() + .executeQuery("SELECT * FROM preparationNote WHERE id = " + sqlValue(id.value()) + ";") + ){ + return + result.next() ? + Optional.of(readPreparationNoteFromRow(result)) : + Optional.empty(); + + } catch (SQLException e){ + throw new RuntimeException(e); + } + } + + + private static PreparationNote readPreparationNoteFromRow(ResultSet rs) throws SQLException { + + return new PreparationNote( + new Id<>(rs.getString("id")), + rs.getString("note"), + new Id<>(rs.getString("operationsId")), + rs.getTimestamp("lastUpdate").toInstant() + ); + } + + @Override + public void save(PreparationNote preparationNote) { + try ( + var stmt = conn.createStatement() + ){ + var sql = + findPreparationNote (preparationNote.id()).isPresent() ? + updateSQL(preparationNote) : + insertSQL(preparationNote ); + + stmt.executeUpdate(sql); + + } catch (SQLException e){ + throw new RuntimeException(e); + } + } + + /* + CREATE TABLE IF NOT EXISTS preparationNote( + id VARCHAR(50) PRIMARY KEY, + note VARCHAR(50) NOT NULL, + operationsId VARCHAR(50) NOT NULL, + lastUpdate TIMESTAMP NOT NULL, + FOREIGN KEY (operationsId) REFERENCES operations(id) + ); + */ + private static String updateSQL(PreparationNote preparationNote){ + return + "UPDATE preparationNote SET " + + "note = " + sqlValue(preparationNote.note()) + "," + + "lastUpdate = " + sqlValue(preparationNote.lastUpdate()) + " " + + "WHERE id = " + sqlValue(preparationNote.id().value()) + ";"; + } + + private static String insertSQL(PreparationNote preparationNote){ + return + "INSERT INTO preparationNote(" + + "id,note,operationsId,lastUpdate" + + ") VALUES (" + + sqlValue(preparationNote.id().value()) + "," + + sqlValue(preparationNote.note()) + "," + + sqlValue(preparationNote.operationsId()) + "," + + sqlValue(preparationNote.lastUpdate()) + + ");"; + } + + @Override + public PreparationNote deletePreparationNote(Id<PreparationNote> id) { + var preparationNote = findPreparationNote(id); + + if(preparationNote.isPresent()) { + var sql = "DELETE FROM preparationNote WHERE id = " + quoted(id.value()) + ";"; + + try { + conn.createStatement().executeUpdate(sql); + return preparationNote.get(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + return null; + } + + @Override + public Id<Room> roomId() { + + var id = new Id<Room>(randomUUID().toString()); + + return findRoom(id).isEmpty() ? id : roomId(); + } + + public Optional<Room> findRoom(Id<Room> id){ + try ( + var result = + conn.createStatement() + .executeQuery("SELECT * FROM room WHERE id = " +sqlValue(id.value()) + ";") + ){ + return + result.next() ? + Optional.of(readRoomFromRow(result)) : + Optional.empty(); + + } catch (SQLException e){ + throw new RuntimeException(e); + } + } + + private static Room readRoomFromRow(ResultSet rs) throws SQLException { + + return new Room( + new Id<>(rs.getString("id")), + rs.getString("roomName"), + rs.getTimestamp("lastUpdate").toInstant() + ); + } + + @Override + public void save(Room room) { + try ( + var stmt = conn.createStatement() + ){ + var sql = + findRoom(room.id()).isPresent() ? + updateSQL(room) : + insertSQL(room); + + stmt.executeUpdate(sql); + + + } catch (SQLException e){ + throw new RuntimeException(e); + } + } + + private static String updateSQL(Room room){ + return + "UPDATE room SET " + + "roomName = " + sqlValue(room.roomName()) + "," + + "lastUpdate = " + sqlValue(room.lastUpdate()) + " " + + "WHERE id = " + sqlValue(room.id().value()) + ";"; + } + + private static String insertSQL(Room room){ + return + "INSERT INTO room(" + + "id,roomName,lastUpdate" + + ") VALUES (" + + sqlValue(room.id().value()) + "," + + sqlValue(room.roomName()) + "," + + sqlValue(room.lastUpdate()) + + ");"; + } + + @Override + public Room deleteRoom(Id<Room> id) { + var room = findRoom(id); + + if(room.isPresent()) { + var sql = "DELETE FROM room WHERE id =" + quoted(id.value()) + ";"; + + try { + conn.createStatement().executeUpdate(sql); + return room.get(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + return null; + } + } diff --git a/opp/jdbc-repo-impl/src/test/java/Tests.java b/opp/jdbc-repo-impl/src/test/java/Tests.java index 290461dd2e01f8590426ca1f7f73ee694898dac3..8c29b66e51b2e024d1f4c33b74c5093af1c201e5 100644 --- a/opp/jdbc-repo-impl/src/test/java/Tests.java +++ b/opp/jdbc-repo-impl/src/test/java/Tests.java @@ -36,6 +36,14 @@ public final class Tests private static OperationTeamService operationTeamService; + private static PreparationNote testPreparationNote = null; + + private static PreparationNoteService preparationNoteService; + + private static Room testRoom = null; + + private static RoomService roomService; + @BeforeClass public static void init() throws Exception { @@ -90,14 +98,32 @@ public final class Tests Instant.now() ); + testPreparationNote = new PreparationNote( + new Id<>("note1111"), + ("Test notiz!"), + testOperation.id(), + Instant.now() + ); + + testRoom = new Room( + new Id<>("room1111"), + ("Test Raum"), + Instant.now() + ); + operationService = new OperationServiceImpl(repo); opStaffService = new OPStaffServiceImpl(repo); operationTeamService = new OperationTeamImpl(repo); + preparationNoteService = new PreparationNoteImpl(repo); + + roomService = new RoomServiceImpl(repo); + } +@Ignore @Test public void testRepoOperationSave(){ @@ -113,6 +139,168 @@ public final class Tests ); } +@Ignore + @Test + public void testCreatePreparationNote() throws Exception { + + PreparationNote.Create createCommand = new PreparationNote.Create( + ("Notiz erstellt mit Command"), + testOperation.id() + ); + + PreparationNote createdPreparationNote = preparationNoteService.process(createCommand); + + assertTrue( + repo.findPreparationNote(createdPreparationNote.id()).isPresent() + ); + } + + + @Ignore + @Test + public void testUpdatePreparationNote() throws Exception { + + PreparationNote.Update updateCommand = new PreparationNote.Update( + testPreparationNote.id(), + ("COmmand wurde hier geupdaet!?!?!?!?") + ); + + PreparationNote updatePreparationNote = preparationNoteService.process(updateCommand); + + Optional<PreparationNote> readPreparationNote = repo.findPreparationNote(updatePreparationNote.id()); + + if (readPreparationNote.isPresent()) { + assertNotEquals(readPreparationNote.get().note(), testPreparationNote.note()); + + assertEquals(readPreparationNote.get().operationsId(), testPreparationNote.operationsId()); + + assertEquals(readPreparationNote.get().id(), testPreparationNote.id()); + + assertNotEquals(readPreparationNote.get().lastUpdate(), testPreparationNote.lastUpdate()); + } else { + throw new Exception(); + } + } + + + @Ignore + @Test + public void testDeletePreparationNote() throws Exception { + + repo.save(testPreparationNote); + + PreparationNote.Delete deleteCommand = new PreparationNote.Delete( + testPreparationNote.id() + ); + + PreparationNote deletePreparationNote = preparationNoteService.process(deleteCommand); + + assertFalse(repo.findPreparationNote(deletePreparationNote.id()).isPresent()); + } + + @Ignore + @Test + public void testRepoPreparationNoteSave(){ + + try { + repo.save(testPreparationNote); + } catch (Exception e){ + e.printStackTrace(); + } + + assertTrue( + repo.findPreparationNote(testPreparationNote.id()).isPresent() + ); + } + + + + @Ignore + @Test + public void testRepoPreparationNoteUpdate() throws Exception { + + try { + repo.save(testPreparationNote); + } catch (Exception e){ + e.printStackTrace(); + } + + PreparationNote updatedTestPreparatioNote = new PreparationNote( + testPreparationNote.id(), + ("ES WURDE GEUPDATED!!!"), + testPreparationNote.operationsId(), + Instant.now() + ); + + try { + repo.save(updatedTestPreparatioNote); + } catch (Exception e){ + e.printStackTrace(); + } + + Optional<PreparationNote> readPreparationNote = repo.findPreparationNote(updatedTestPreparatioNote.id()); + if (readPreparationNote.isPresent()) { + assertNotEquals(readPreparationNote.get().note(), testPreparationNote.note()); + assertNotEquals(readPreparationNote.get().lastUpdate(), testPreparationNote.lastUpdate()); + } else { + throw new Exception(); + } + } + @Ignore + @Test + public void testCreateRoom() throws Exception{ + + Room.Create createCommand = new Room.Create( + "Neuen Raum erstellt mit Command" + ); + + Room createdRoom = roomService.process(createCommand); + + assertNotNull("Room should be created", createdRoom); + assertNotNull("Room ID should not be null", createdRoom.id()); + assertTrue( + repo.findRoom(createdRoom.id()).isPresent() + ); + } + @Ignore + @Test + public void testRoomUpdate() throws Exception { + // repo.save(testRoom); + Room.Update updateCommand = new Room.Update( + testRoom.id(), + ("COmmand wurde hier geupdaet!?!?!?!?") + ); + + Room updateRoom = roomService.process(updateCommand); + + Optional<Room> readRoom = repo.findRoom(updateRoom.id()); + + if (readRoom.isPresent()) { + assertNotEquals(readRoom.get().roomName(), testRoom.roomName()); + + assertEquals(readRoom.get().id(), testRoom.id()); + + assertNotEquals(readRoom.get().lastUpdate(), testRoom.lastUpdate()); + } else { + throw new Exception(); + } + } + + @Test + public void testDeleteRoom() throws Exception { + + // repo.save(testRoom); + + Room.Delete deleteCommand = new Room.Delete( + testRoom.id() + ); + + Room deleteRoom = roomService.process(deleteCommand); + + assertFalse(repo.findRoom(deleteRoom.id()).isPresent()); + } + + @Ignore @Test public void testRepoOperationUpdate() throws Exception { @@ -148,6 +336,7 @@ public final class Tests } } + @Ignore @Test public void testRepoOperationDelete() { try { @@ -166,7 +355,7 @@ public final class Tests assertFalse(repo.findOperation(testOperation.id()).isPresent()); } - +@Ignore @Test public void testCreateOperation() throws Exception { @@ -186,7 +375,7 @@ public final class Tests repo.findOperation(createdOperation.id()).isPresent() ); } - +@Ignore @Test public void testUpdateOperation() throws Exception { @@ -219,6 +408,7 @@ public final class Tests } } +@Ignore @Test public void testDeleteOperation() throws Exception { @@ -231,9 +421,10 @@ public final class Tests Operation deleteOperation = operationService.process(deleteCommand); - assertFalse(repo.findOperation(deleteOperation.id()).isPresent()); + assertFalse(repo.findOperation(deleteOperation.id()).isPresent()); } + @Ignore @Test public void testGetOperation() throws Exception { repo.save(testOperationTeam1); @@ -253,6 +444,7 @@ public final class Tests } } + @Ignore @Test public void testGetOperations() throws Exception { @@ -270,7 +462,7 @@ public final class Tests assertEquals(operation.date(), testDate); } } - +@Ignore @Test public void testRepoOPStaffSave(){ @@ -284,7 +476,7 @@ public final class Tests repo.findOPStaff(testOPStaff1.id()).isPresent() ); } - +@Ignore @Test public void testRepoOPStaffUpdate() throws Exception { @@ -316,6 +508,7 @@ public final class Tests } } + @Ignore @Test public void testRepoOPStaffDelete() { try { @@ -333,6 +526,7 @@ public final class Tests assertFalse(repo.findOPStaff(testOPStaff1.id()).isPresent()); } + @Ignore @Test public void testCreateOPStaff() throws Exception { @@ -348,6 +542,7 @@ public final class Tests ); } + @Ignore @Test public void testUpdateOPStaff() throws Exception { @@ -374,6 +569,7 @@ public final class Tests } } +@Ignore @Test public void testDeleteOPStaff() throws Exception { @@ -388,6 +584,7 @@ public final class Tests assertFalse(repo.findOPStaff(deletedOPStaff.id()).isPresent()); } + @Ignore @Test public void testGetOPStaff() throws Exception { repo.save(testOPStaff1); @@ -403,6 +600,7 @@ public final class Tests } } + @Ignore @Test public void testGetOPStaffs() throws Exception { @@ -419,6 +617,7 @@ public final class Tests assertEquals(2, filteredList.size()); } + @Ignore @Test public void testRepoOperationTeamAssignStaff(){ @@ -441,6 +640,7 @@ public final class Tests } } + @Ignore @Test public void testCreateOperationTeam() throws Exception { @@ -494,8 +694,7 @@ public final class Tests throw new Exception(); } } - - @Ignore +@Ignore @Test public void testRepoOperationTeamDelete() { try { @@ -517,6 +716,7 @@ public final class Tests assertFalse(repo.findOperationTeam(testOperationTeam1.id()).isPresent()); } + @Ignore @Test public void testDeleteOperationTeam() throws Exception { @@ -581,7 +781,7 @@ public final class Tests assertTrue(result); } - @Ignore +@Ignore @Test public void testAssignStaffToOperationTeam() throws Exception { @@ -600,7 +800,10 @@ public final class Tests assertTrue(result); } - @Ignore + + + +@Ignore @Test public void testRemoveOPStaffsInOperationTeams() throws Exception{ @@ -612,6 +815,7 @@ public final class Tests OperationTeam removedTeam = operationTeamService.process(removeStaffCommand); assertEquals(testOperationTeam1.id().value(), removedTeam.id().value()); + assertFalse(repo.findOperationTeamOPStaff(testOperationTeam1.id(), testOPStaff1.id())); } }