Skip to content

Commit

Permalink
[Fix partially kbss-cvut/fta-fmea-ui#574] Throw exception on system r…
Browse files Browse the repository at this point in the history
…ename if system with the same name exists
  • Loading branch information
kostobog committed Aug 28, 2024
1 parent 340420a commit 9448f55
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -96,6 +96,12 @@ public void remove(@NonNull URI instanceUri) {
@Transactional
public System rename(System systemRename) {
log.info("> rename - {}", systemRename);
List<URI> 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());
Expand Down

0 comments on commit 9448f55

Please sign in to comment.