Skip to content

Commit

Permalink
Merge pull request #152 from kbss-cvut/fix/fta-fmea-ui-574-should-not…
Browse files Browse the repository at this point in the history
…-rename-system-if-name-exists

Throw exception on system rename if system with the same name exists
  • Loading branch information
kostobog authored Aug 28, 2024
2 parents 340420a + 9448f55 commit 47adeef
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 47adeef

Please sign in to comment.