From 9448f55e7fff70349d5cd9bfdcc04df846351f89 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Wed, 28 Aug 2024 14:46:02 +0200 Subject: [PATCH] [Fix partially kbss-cvut/fta-fmea-ui#574] Throw exception on system rename if system with the same name exists --- .../kbss/analysis/service/SystemRepositoryService.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/cz/cvut/kbss/analysis/service/SystemRepositoryService.java b/src/main/java/cz/cvut/kbss/analysis/service/SystemRepositoryService.java index f1396f2..b3e7e8f 100755 --- a/src/main/java/cz/cvut/kbss/analysis/service/SystemRepositoryService.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/SystemRepositoryService.java @@ -73,7 +73,7 @@ public System create(System system){ if(!existingSystems.isEmpty()) throw new LogicViolationException(( "Cannot create system with name \"%s\", " + - "the name is already assigned by other system.") + "the name is already assigned to another system.") .formatted(system.getName())); this.persist(system); return system; @@ -96,6 +96,12 @@ public void remove(@NonNull URI instanceUri) { @Transactional public System rename(System systemRename) { log.info("> rename - {}", systemRename); + List existingSystems = systemDao.findUriByName(systemRename.getName()); + if(!existingSystems.isEmpty()) + throw new LogicViolationException(( + "Cannot rename system to \"%s\", " + + "the name is already assigned to another system.") + .formatted(systemRename.getName())); System system = findRequired(systemRename.getUri()); system.setName(systemRename.getName());