diff --git a/src/main/java/cz/cvut/kbss/analysis/controller/FaultTreeController.java b/src/main/java/cz/cvut/kbss/analysis/controller/FaultTreeController.java index a9e08d4..2c01b6e 100755 --- a/src/main/java/cz/cvut/kbss/analysis/controller/FaultTreeController.java +++ b/src/main/java/cz/cvut/kbss/analysis/controller/FaultTreeController.java @@ -2,6 +2,7 @@ import cz.cvut.kbss.analysis.model.*; import cz.cvut.kbss.analysis.model.opdata.OperationalDataFilter; + import cz.cvut.kbss.analysis.service.FaultTreeEvaluationService; import cz.cvut.kbss.analysis.service.FaultTreeRepositoryService; import cz.cvut.kbss.analysis.service.IdentifierService; import cz.cvut.kbss.analysis.util.Vocabulary; @@ -24,6 +25,7 @@ public class FaultTreeController { private final FaultTreeRepositoryService repositoryService; + private final FaultTreeEvaluationService faultTreeEvaluationService; private final IdentifierService identifierService; @GetMapping @@ -132,8 +134,8 @@ public void performCutSetAnalysis(@PathVariable(name = "faultTreeFragment") Stri @PutMapping(value = "/{faultTreeFragment}/evaluate") public void evaluate(@PathVariable(name = "faultTreeFragment") String faultTreeFragment, @RequestBody OperationalDataFilter filter){ URI faultTreeUri = identifierService.composeIdentifier(Vocabulary.s_c_fault_tree, faultTreeFragment); - log.info("> performCutSetAnalysis - {}", faultTreeFragment); - repositoryService.evaluate(faultTreeUri, filter); + log.info("> evaluate - {}", faultTreeFragment); + faultTreeEvaluationService.evaluate(faultTreeUri, filter); } } diff --git a/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventScenarioDao.java b/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventScenarioDao.java index 4e090ba..5a161b3 100644 --- a/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventScenarioDao.java +++ b/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventScenarioDao.java @@ -3,6 +3,7 @@ import cz.cvut.kbss.analysis.config.conf.PersistenceConf; import cz.cvut.kbss.analysis.model.FaultEventScenario; import cz.cvut.kbss.analysis.service.IdentifierService; +import cz.cvut.kbss.analysis.util.Vocabulary; import cz.cvut.kbss.jopa.model.EntityManager; import cz.cvut.kbss.jopa.model.descriptors.EntityDescriptor; import org.springframework.beans.factory.annotation.Autowired; @@ -12,6 +13,8 @@ @Repository public class FaultEventScenarioDao extends BaseDao { + + public static URI HAS_SCENARIO_PROP = URI.create(Vocabulary.s_p_has_scenario); @Autowired protected FaultEventScenarioDao(EntityManager em, PersistenceConf config, IdentifierService identifierService) { super(FaultEventScenario.class, em, config, identifierService); @@ -21,4 +24,12 @@ protected FaultEventScenarioDao(EntityManager em, PersistenceConf config, Identi public EntityDescriptor getEntityDescriptor(URI uri) { return super.getEntityDescriptor(uri); } + + public void addScenarioToTree(URI faultTreeUri, FaultEventScenario scenario){ + persistPropertyInContext(faultTreeUri, HAS_SCENARIO_PROP, scenario.getUri(), scenario.getContext()); + } + + public void removeScenarios(URI faultTreeUri){ + removeAll(faultTreeUri, HAS_SCENARIO_PROP, faultTreeUri); + } } diff --git a/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeEvaluationService.java b/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeEvaluationService.java new file mode 100644 index 0000000..97aeef8 --- /dev/null +++ b/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeEvaluationService.java @@ -0,0 +1,34 @@ +package cz.cvut.kbss.analysis.service; + +import cz.cvut.kbss.analysis.model.FaultTree; +import cz.cvut.kbss.analysis.model.opdata.OperationalDataFilter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.net.URI; + +@Service +@Slf4j +public class FaultTreeEvaluationService +{ + private final FaultTreeRepositoryService faultTreeRepositoryService; + private final OperationalDataFilterService operationalDataFilterService; + private final FaultTreeService faultTreeService; + + public FaultTreeEvaluationService(FaultTreeRepositoryService faultTreeRepositoryService, OperationalDataFilterService operationalDataFilterService, FaultTreeService faultTreeService) { + this.faultTreeRepositoryService = faultTreeRepositoryService; + this.operationalDataFilterService = operationalDataFilterService; + this.faultTreeService = faultTreeService; + } + + public FaultTree evaluate(URI faultTreeUri, OperationalDataFilter filter) { + + operationalDataFilterService.updateFaultTreeFilter(faultTreeUri, filter); + + FaultTree faultTree = faultTreeService.findWithDetails(faultTreeUri); + + faultTreeRepositoryService.updateFaultTreeOperationalFailureRates(faultTree, filter); + + return faultTreeRepositoryService.evaluate(faultTree); + } +} diff --git a/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java b/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java index 296972a..5e9a02b 100755 --- a/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java @@ -536,18 +536,6 @@ public FaultTree performCutSetAnalysis(URI faultTreeUri){ return faultTree; } - @Transactional - public FaultTree evaluate(URI faultTreeUri, OperationalDataFilter filter) { - - operationalDataFilterService.updateFaultTreeFilter(faultTreeUri, filter); - - FaultTree faultTree = findWithDetails(faultTreeUri); - - updateFaultTreeOperationalFailureRates(faultTree, filter); - - return evaluate(faultTree); - } - /** * Updates the provided fault tree sns' failures with operational failure rate calculated based on filter. The update * is reflected in the persistent storage and in the input fault tree. @@ -634,18 +622,25 @@ public FaultTree evaluate(FaultTree faultTree) { if(faultTree.getFaultEventScenarios() != null) { for (FaultEventScenario faultEventScenario : faultTree.getFaultEventScenarios()) - faultEventScenarioDao.remove(faultEventScenario); + faultEventScenarioDao.remove(faultEventScenario.getUri()); + faultEventScenarioDao.removeScenarios(faultTree.getUri()); faultTree.setFaultEventScenarios(null); } FTAMinimalCutSetEvaluation evaluator = new FTAMinimalCutSetEvaluation(); evaluator.evaluate(faultTree); + for(FaultEvent evt : faultTree.getAllEvents().stream().filter(e -> e.getEventType() != FtaEventType.BASIC).toList()){ + faultEventDao.setProbability(evt.getUri(), evt.getProbability(), faultTree.getUri()); + } + if(faultTree.getFaultEventScenarios() != null) { for (FaultEventScenario scenario : faultTree.getFaultEventScenarios()) { + scenario.setContext(faultTree.getUri()); scenario.updateProbability(); + faultEventScenarioDao.persist(scenario); + faultEventScenarioDao.addScenarioToTree(faultTree.getUri(), scenario); } - getPrimaryDao().update(faultTree); } return faultTree; }