Skip to content

Commit

Permalink
Merge pull request #132 from kbss-cvut/fix/fta-fmea-ui-429-store-oper…
Browse files Browse the repository at this point in the history
…ational-failure-rate-in-correct-location

Store failure rate estimate in context common for all systems
  • Loading branch information
kostobog authored Jul 1, 2024
2 parents b6f66e3 + 592835e commit 258951f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
24 changes: 24 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/dao/FailureRateDao.java
Original file line number Diff line number Diff line change
@@ -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<FailureRate> {
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);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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<FaultEvent, Event> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,8 @@
@Slf4j
public class SystemRepositoryService extends ComplexManagedEntityRepositoryService<System> {

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;
Expand Down Expand Up @@ -138,4 +141,8 @@ protected void setOperationalDataFilter(System system) {
system.setGlobalOperationalDataFilter(operationalDataFilterService.getDefaultGlobalFilter());
}

public URI getToolContextForGeneralSystem(URI uri){
return GENERAL_SYSTEM_CONTEXT;
}

}

0 comments on commit 258951f

Please sign in to comment.