Skip to content

Commit

Permalink
[Fixes kbss-cvut/fta-fmea-ui#567] Throw exception on system delete if…
Browse files Browse the repository at this point in the history
… system has fault trees
  • Loading branch information
kostobog committed Aug 20, 2024
1 parent 5b465b6 commit 71dad88
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/dao/SystemDao.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cz.cvut.kbss.analysis.dao;

import cz.cvut.kbss.analysis.config.conf.PersistenceConf;
import cz.cvut.kbss.analysis.exception.PersistenceException;
import cz.cvut.kbss.analysis.model.Component;
import cz.cvut.kbss.analysis.model.System;
import cz.cvut.kbss.analysis.service.IdentifierService;
Expand Down Expand Up @@ -48,4 +49,28 @@ public List<Component> findComponents(URI systemURI){
.setParameter("hasComponentPartProp", HAS_COMPONENT_PART)
.getResultList();
}

public List<URI> findSystemsFaultTrees(URI uri){
try {
return em.createNativeQuery("""
PREFIX fta: <http://onto.fel.cvut.cz/ontologies/fta-fmea-application/>
SELECT DISTINCT ?ftUri WHERE {
?uri a ?type.
?_subsystemUri fta:is-part-of* ?uri.
?behavior fta:has-component ?_subsystemUri.
?rootEventType fta:is-manifestation-of ?behavior .
?rootEvent fta:is-derived-from ?rootEventType.
?ftUri fta:is-manifested-by ?rootEvent .
?ftUri a fta:fault-tree.
}
""",
URI.class)
.setParameter("uri", uri)
.setParameter("type", typeUri)
.getResultList();
} catch (RuntimeException e) {
throw new PersistenceException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import cz.cvut.kbss.analysis.model.opdata.OperationalDataFilter;
import cz.cvut.kbss.analysis.service.security.SecurityUtils;
import cz.cvut.kbss.analysis.util.Vocabulary;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
Expand Down Expand Up @@ -78,6 +79,20 @@ public System create(System system){
return system;
}

@Override
public void remove(@NonNull URI instanceUri) {
System system = findAllSummary(instanceUri);
List<URI> faultTrees = systemDao.findSystemsFaultTrees(instanceUri);
if(!faultTrees.isEmpty()) {

throw new LogicViolationException((
"Cannot delete system \"%s\" (<%s>), " +
"the system has fault %d trees.")
.formatted(system.getName(), instanceUri, faultTrees.size()));
}
super.remove(instanceUri);
}

@Transactional
public System rename(System systemRename) {
log.info("> rename - {}", systemRename);
Expand Down

0 comments on commit 71dad88

Please sign in to comment.