diff --git a/src/main/java/cz/cvut/kbss/analysis/dao/FailureRateDao.java b/src/main/java/cz/cvut/kbss/analysis/dao/FailureRateDao.java new file mode 100644 index 0000000..7e1689d --- /dev/null +++ b/src/main/java/cz/cvut/kbss/analysis/dao/FailureRateDao.java @@ -0,0 +1,24 @@ +package cz.cvut.kbss.analysis.dao; + +import cz.cvut.kbss.analysis.config.conf.PersistenceConf; +import cz.cvut.kbss.analysis.model.FailureRate; +import cz.cvut.kbss.analysis.service.IdentifierService; +import cz.cvut.kbss.analysis.util.Vocabulary; +import cz.cvut.kbss.jopa.model.EntityManager; +import org.springframework.stereotype.Repository; + +import java.net.URI; + +@Repository +public class FailureRateDao extends BaseDao { + public static final URI HAS_FAILURE_RATE_PROP = URI.create(Vocabulary.s_p_has_failure_rate); + + public FailureRateDao(EntityManager em, PersistenceConf config, IdentifierService identifierService) { + super(FailureRate.class, em, config, identifierService); + } + + public void setFailureRate(URI eventUri, FailureRate fr, URI context){ + addOrReplaceValue(eventUri, HAS_FAILURE_RATE_PROP, fr.getUri(), context); + + } +} 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 2939e24..b536d28 100755 --- a/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java @@ -47,8 +47,8 @@ public class FaultTreeRepositoryService extends ComplexManagedEntityRepositorySe private final OperationalDataService operationalDataService; private final FaultEventTypeService faultEventTypeService; private final FailureRateEstimateDao failureRateEstimateDao; - private final SystemDao systemDao; private final SystemRepositoryService systemRepositoryService; + private final FailureRateDao failureRateDao; @Autowired public FaultTreeRepositoryService(@Qualifier("defaultValidator") Validator validator, @@ -63,7 +63,7 @@ public FaultTreeRepositoryService(@Qualifier("defaultValidator") Validator valid OperationalDataFilterService operationalDataFilterService, OperationalDataService operationalDataService, FaultEventTypeService faultEventTypeService, - FailureRateEstimateDao failureRateEstimateDao, SystemDao systemDao, SystemRepositoryService systemRepositoryService) { + FailureRateEstimateDao failureRateEstimateDao, SystemRepositoryService systemRepositoryService, FailureRateDao failureRateDao) { super(validator, userDao, securityUtils); this.faultTreeDao = faultTreeDao; this.faultEventScenarioDao = faultEventScenarioDao; @@ -75,8 +75,8 @@ public FaultTreeRepositoryService(@Qualifier("defaultValidator") Validator valid this.operationalDataService = operationalDataService; this.faultEventTypeService = faultEventTypeService; this.failureRateEstimateDao = failureRateEstimateDao; - this.systemDao = systemDao; this.systemRepositoryService = systemRepositoryService; + this.failureRateDao = failureRateDao; } @Override @@ -581,15 +581,21 @@ public void updateFaultTreeOperationalFailureRates(FaultTree faultTree, Operatio ItemFailureRate[] operationalFailureRateEstimates = operationalDataService.fetchFailureRates(filter, map.keySet()); if(operationalFailureRateEstimates == null) return; - - URI systemContext = getToolContext(faultTree.getSystem().getUri()); + URI systemContext = systemRepositoryService.getToolContextForGeneralSystem(faultTree.getSystem().getUri()); for(ItemFailureRate estimate : operationalFailureRateEstimates){ if(estimate.getFailureRate() == null) continue; Pair p = map.get(estimate.getUri()); FaultEvent ft = p.getFirst(); - FailureRate fr = ((FaultEventType)p.getSecond()).getFailureRate(); - + FaultEventType ftt = (FaultEventType)p.getSecond(); + FailureRate fr = ftt.getFailureRate(); + if(fr == null){ + fr = new FailureRate(); + fr.setContext(systemContext); + failureRateDao.persist(fr); + failureRateDao.setFailureRate(ftt.getUri(), fr, systemContext); + ftt.setFailureRate(fr); + } updateOperationalFailureRate(systemContext, faultTreeUri, estimate, ft, fr); } } 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 3ba0cf5..6de5197 100755 --- a/src/main/java/cz/cvut/kbss/analysis/service/SystemRepositoryService.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/SystemRepositoryService.java @@ -10,6 +10,7 @@ import cz.cvut.kbss.analysis.model.System; 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.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -26,6 +27,8 @@ @Slf4j public class SystemRepositoryService extends ComplexManagedEntityRepositoryService { + public static final URI GENERAL_SYSTEM_CONTEXT = URI.create(Vocabulary.s_c_ata_system + "/tool-context"); + private final SystemDao systemDao; private final ComponentRepositoryService componentRepositoryService; private final ComponentDao componentDao; @@ -138,4 +141,8 @@ protected void setOperationalDataFilter(System system) { system.setGlobalOperationalDataFilter(operationalDataFilterService.getDefaultGlobalFilter()); } + public URI getToolContextForGeneralSystem(URI uri){ + return GENERAL_SYSTEM_CONTEXT; + } + }