Skip to content

Commit

Permalink
Merge pull request #129 from kbss-cvut/feature/fta-fmea-ui-428-fault-…
Browse files Browse the repository at this point in the history
…tree-moh-synch-status

Implement simple fault tree status
  • Loading branch information
blcham authored Jun 26, 2024
2 parents b690e32 + 26b7817 commit fbe5d86
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 46 deletions.
5 changes: 5 additions & 0 deletions ontology-generator/ontology/fta-fmea-model.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,11 @@ fta-fmea:system-name rdf:type owl:DatatypeProperty ;
fta-fmea:min-operational-hours rdf:type owl:DatatypeProperty ;
rdfs:label "Minimum operational hours" .

### http://onto.fel.cvut.cz/ontologies/fta-fmea-application/status
fta-fmea:status rdf:type owl:DatatypeProperty ;
rdfs:label "status" .


#################################################################
# Classes
#################################################################
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cz.cvut.kbss.analysis.controller;

import cz.cvut.kbss.analysis.model.opdata.OperationalDataFilter;
import cz.cvut.kbss.analysis.service.FaultTreeService;
import cz.cvut.kbss.analysis.service.IdentifierService;
import cz.cvut.kbss.analysis.service.OperationalDataFilterService;
import cz.cvut.kbss.analysis.service.external.OperationalDataService;
Expand All @@ -22,11 +23,13 @@ public class OperationalDataFilterController {
private final OperationalDataFilterService filterService;
private final IdentifierService identifierService;
private final OperationalDataService operationalDataService;
private final FaultTreeService faultTreeService;

public OperationalDataFilterController(OperationalDataFilterService filterService, IdentifierService identifierService, OperationalDataService operationalDataService) {
public OperationalDataFilterController(OperationalDataFilterService filterService, IdentifierService identifierService, OperationalDataService operationalDataService, FaultTreeService faultTreeService) {
this.filterService = filterService;
this.identifierService = identifierService;
this.operationalDataService = operationalDataService;
this.faultTreeService = faultTreeService;
}

@PutMapping(path="reset", produces = {JsonLd.MEDIA_TYPE, MediaType.APPLICATION_JSON_VALUE})
Expand All @@ -47,7 +50,7 @@ public void updateSystemFilter(@PathVariable(name = "systemFragment") String sys
public void updateFaultTreeFilter(@PathVariable(name = "faultTreeFragment") String faultTreeFragment, @RequestBody OperationalDataFilter filter){
log.info("> updateFaultTreeFilter - {} to {}", faultTreeFragment, filter);
URI faultTreeUri = identifierService.composeIdentifier(Vocabulary.s_c_fault_tree, faultTreeFragment);
filterService.updateFaultTreeFilter(faultTreeUri, filter);
faultTreeService.updateFilter(faultTreeUri, filter);
}

@GetMapping(value = "/check-service", produces = {MediaType.TEXT_PLAIN_VALUE})
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/cz/cvut/kbss/analysis/dao/FaultEventTypeDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class FaultEventTypeDao extends NamedEntityDao<FaultEventType> {
public final static URI DERIVED_FROM_PROP = URI.create(Vocabulary.s_p_is_derived_from);
public final static URI FTA_EVENT_TYPE_PROP = URI.create(Vocabulary.s_p_fault_event_type);
public final static URI IS_MANIFESTED_BY_PROP = URI.create(Vocabulary.s_p_is_manifested_by);
public final static URI PROBABILITY_PROP = URI.create(Vocabulary.s_p_probability);
public final static URI STATUS_PROP = URI.create(Vocabulary.s_p_status);
public final static URI FAULT_EVENT_TYPE = URI.create(Vocabulary.s_c_fault_event);

public FaultEventTypeDao(EntityManager em, PersistenceConf config, IdentifierService identifierService) {
super(FaultEventType.class, em, config, identifierService);
Expand All @@ -28,16 +31,20 @@ public List<FaultEventReference> getFaultEventRootWithSupertype(URI supertype){
try{
return em.createNativeQuery(
"""
SELECT DISTINCT ?faultEvent ?faultTree WHERE{
SELECT DISTINCT ?faultEvent ?faultTree ?probability ?status WHERE{
?faultEvent ?derivedFrom ?supertype.
?faultEvent ?ftaEventTypeProp ?ftaEventType.
OPTIONAL{ ?faultEvent ?probabilityProp ?probability. }
?faultEvent a ?type.
?faultTree ?isManifestedByProp ?faultEvent
?faultTree ?isManifestedByProp ?faultEvent.
OPTIONAL{ ?faultTree ?statusProp ?status. }
}""", "FaultEventReference")
.setParameter("derivedFrom", DERIVED_FROM_PROP)
.setParameter("supertype", supertype)
.setParameter("ftaEventTypeProp", FTA_EVENT_TYPE_PROP)
.setParameter("type", this.typeUri)
.setParameter("probabilityProp", PROBABILITY_PROP)
.setParameter("statusProp", STATUS_PROP)
.setParameter("type", FAULT_EVENT_TYPE)
.setParameter("isManifestedByProp", IS_MANIFESTED_BY_PROP)
.getResultList();
}catch (RuntimeException e){
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/dao/FaultTreeDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
@Repository
public class FaultTreeDao extends ManagedEntityDao<FaultTree> {

public static final URI STATUS_PROP = URI.create(Vocabulary.s_p_status);

@Autowired
protected FaultTreeDao(EntityManager em, PersistenceConf config, IdentifierService identifierService, SecurityUtils securityUtils) {
super(FaultTree.class, em, config, identifierService, securityUtils);
Expand Down Expand Up @@ -168,4 +170,8 @@ public Query getSummariesQuery() {
.setParameter("pCreator", P_CREATOR)
.setParameter("pLastEditor", P_LAST_EDITOR);
}

public void updateStatus(URI faultTree, Status status){
super.addOrReplaceValue(faultTree, STATUS_PROP, status, faultTree);
}
}
47 changes: 31 additions & 16 deletions src/main/java/cz/cvut/kbss/analysis/dao/ManagedEntityDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import cz.cvut.kbss.jopa.model.descriptors.EntityDescriptor;
import cz.cvut.kbss.jopa.model.metamodel.Attribute;
import cz.cvut.kbss.jopa.model.metamodel.EntityType;
import cz.cvut.kbss.jopa.model.query.Query;
import cz.cvut.kbss.jopa.vocabulary.DC;

import java.net.URI;
Expand Down Expand Up @@ -75,8 +76,30 @@ public void setChangedByContext(URI context, Date date){

public List<T> findAllSummaries(){
try {
List<ManagedEntity> ret = em.createNativeQuery("""
List<ManagedEntity> ret = getSummariesQuery()
.getResultList();

return ret.stream().map(s -> s.asEntity(type)).toList();
} catch (RuntimeException e) {
throw new PersistenceException(e);
}
}

public T findSummary(URI managedEntityUri){
try {
ManagedEntity ret = (ManagedEntity)getSummariesQuery()
.setParameter("_uri", managedEntityUri)
.getSingleResult();
return ret.asEntity(type);
} catch (RuntimeException e) {
throw new PersistenceException(e);
}
}

public Query getSummariesQuery(){
return em.createNativeQuery("""
SELECT * WHERE {
BIND(?_uri as ?uri)
?uri a ?type.
?uri ?pName ?name.
OPTIONAL{?uri ?pDescription ?description.}
Expand All @@ -85,21 +108,13 @@ public List<T> findAllSummaries(){
OPTIONAL{?uri ?pCreator ?creator.}
OPTIONAL{?uri ?pLastEditor ?lastEditor.}
}""", "ManagedEntitySummary")
.setParameter("type", typeUri)
.setParameter("pName", P_HAS_NAME)
.setParameter("pDescription", P_HAS_DESCRIPTION)
.setParameter("pCreated", P_CREATED)
.setParameter("pModified", P_MODIFIED)
.setParameter("pCreator", P_CREATOR)
.setParameter("pLastEditor", P_LAST_EDITOR)
.getResultList();

return ret.stream().map(s -> s.asEntity(type)).toList();
} catch (RuntimeException e) {
throw new PersistenceException(e);
}
.setParameter("type", typeUri)
.setParameter("pName", P_HAS_NAME)
.setParameter("pDescription", P_HAS_DESCRIPTION)
.setParameter("pCreated", P_CREATED)
.setParameter("pModified", P_MODIFIED)
.setParameter("pCreator", P_CREATOR)
.setParameter("pLastEditor", P_LAST_EDITOR);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@

import java.net.URI;

@SparqlResultSetMapping(name = "FaultEventReference", classes =
@ConstructorResult(targetClass=FaultEventReference.class, variables={
@VariableResult(name="faultEvent"),
@VariableResult(name="faultTree")
})
@SparqlResultSetMapping(name = "FaultEventReference", entities =
{@EntityResult(entityClass=FaultEventReference.class)}
)

@OWLClass(iri = Vocabulary.s_c_fault_event)
@Getter
@Setter
Expand All @@ -30,7 +26,12 @@ public FaultEventReference(URI faultEvent, URI faultTree) {
@Id
protected URI faultEvent;

@Transient
@OWLDataProperty(iri = Vocabulary.s_p_is_part_of)
protected URI faultTree;

@OWLDataProperty(iri = Vocabulary.s_p_probability)
protected Double probability;

@OWLDataProperty(iri = Vocabulary.s_p_status)
protected String status;
}
3 changes: 3 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/model/FaultTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class FaultTree extends ManagedEntity {
@OWLObjectProperty(iri = Vocabulary.s_p_has_operational_data_filter)
protected OperationalDataFilter operationalDataFilter;

@OWLDataProperty(iri = Vocabulary.s_p_status)
protected Status status;

@NotNull(message = "Manifesting event must be chosen")
@ParticipationConstraints(nonEmpty = true)
@OWLObjectProperty(iri = Vocabulary.s_p_is_manifested_by, cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}, fetch = FetchType.EAGER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
@Setter
public class FaultTreeSummary extends ManagedEntity{

@OWLDataProperty(iri = Vocabulary.s_p_status)
protected Status status;

@OWLObjectProperty(iri = Vocabulary.s_p_is_derived_from)
protected URI rootEvent;

Expand Down Expand Up @@ -72,6 +75,7 @@ public void copyTo(FaultTree faultTree){
faultTree.getSubsystem().setUri(this.getSubsystemUri());
faultTree.getSubsystem().setName(this.getSubsystemName());
}
faultTree.setStatus(this.getStatus());
faultTree.setRequiredFailureRate(this.getRequiredFailureRate());
faultTree.setCalculatedFailureRate(this.getCalculatedFailureRate());
faultTree.setFhaBasedFailureRate(this.getFhaBasedFailureRate());
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/model/Status.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package cz.cvut.kbss.analysis.model;

public enum Status {
ok,
outOfSync;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cz.cvut.kbss.analysis.service;

import cz.cvut.kbss.analysis.dao.FaultTreeDao;
import cz.cvut.kbss.analysis.model.FaultTree;
import cz.cvut.kbss.analysis.model.Status;
import cz.cvut.kbss.analysis.model.opdata.OperationalDataFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -14,11 +16,13 @@ public class FaultTreeEvaluationService
private final FaultTreeRepositoryService faultTreeRepositoryService;
private final OperationalDataFilterService operationalDataFilterService;
private final FaultTreeService faultTreeService;
private final FaultTreeDao faultTreeDao;

public FaultTreeEvaluationService(FaultTreeRepositoryService faultTreeRepositoryService, OperationalDataFilterService operationalDataFilterService, FaultTreeService faultTreeService) {
public FaultTreeEvaluationService(FaultTreeRepositoryService faultTreeRepositoryService, OperationalDataFilterService operationalDataFilterService, FaultTreeService faultTreeService, FaultTreeDao faultTreeDao) {
this.faultTreeRepositoryService = faultTreeRepositoryService;
this.operationalDataFilterService = operationalDataFilterService;
this.faultTreeService = faultTreeService;
this.faultTreeDao = faultTreeDao;
}

public FaultTree evaluate(URI faultTreeUri, OperationalDataFilter filter) {
Expand All @@ -29,6 +33,13 @@ public FaultTree evaluate(URI faultTreeUri, OperationalDataFilter filter) {

faultTreeRepositoryService.updateFaultTreeOperationalFailureRates(faultTree, filter);

return faultTreeRepositoryService.evaluate(faultTree);
faultTree = faultTreeRepositoryService.evaluate(faultTree);

Status status = faultTreeRepositoryService.getInferedStatus(faultTree);
faultTreeDao.updateStatus(faultTree.getUri(), status);

return faultTree;


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cz.cvut.kbss.analysis.dao.*;
import cz.cvut.kbss.analysis.exception.EntityNotFoundException;
import cz.cvut.kbss.analysis.model.*;
import cz.cvut.kbss.analysis.model.System;
import cz.cvut.kbss.analysis.model.ava.ATASystem;
import cz.cvut.kbss.analysis.model.ava.FHAEventType;
import cz.cvut.kbss.analysis.model.diagram.Rectangle;
Expand Down Expand Up @@ -46,6 +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;

@Autowired
public FaultTreeRepositoryService(@Qualifier("defaultValidator") Validator validator,
Expand All @@ -60,7 +63,7 @@ public FaultTreeRepositoryService(@Qualifier("defaultValidator") Validator valid
OperationalDataFilterService operationalDataFilterService,
OperationalDataService operationalDataService,
FaultEventTypeService faultEventTypeService,
FailureRateEstimateDao failureRateEstimateDao) {
FailureRateEstimateDao failureRateEstimateDao, SystemDao systemDao, SystemRepositoryService systemRepositoryService) {
super(validator, userDao, securityUtils);
this.faultTreeDao = faultTreeDao;
this.faultEventScenarioDao = faultEventScenarioDao;
Expand All @@ -72,6 +75,8 @@ public FaultTreeRepositoryService(@Qualifier("defaultValidator") Validator valid
this.operationalDataService = operationalDataService;
this.faultEventTypeService = faultEventTypeService;
this.failureRateEstimateDao = failureRateEstimateDao;
this.systemDao = systemDao;
this.systemRepositoryService = systemRepositoryService;
}

@Override
Expand Down Expand Up @@ -115,11 +120,20 @@ public FaultTree findSummary(URI faultTreeUri){
@Override
public List<FaultTree> findAllSummaries(){
List<FaultTree> summaries = super.findAllSummaries();
Map<URI, System> systemMap = new HashMap<>();
for(FaultTree faultTreeSummary: summaries){
OperationalDataFilter filter = operationalDataFilterService.getFaultTreeFilter(
faultTreeSummary.getUri(),
faultTreeSummary.getSystem().getUri());
faultTreeSummary.setOperationalDataFilter(filter);
if(faultTreeSummary.getSystem().getUri() == null)
continue;
System system = systemMap.computeIfAbsent(
faultTreeSummary.getSystem().getUri(),
uri -> systemRepositoryService.findAllSummary(uri)
);
faultTreeSummary.setSystem(system);
setInferStatus(faultTreeSummary);
}
return summaries;
}
Expand All @@ -138,6 +152,18 @@ public FaultTree findWithPropagation(URI faultTreeUri) {
return faultTree;
}

public void setInferStatus(FaultTree faultTree){
if(faultTree.getStatus() == null)
faultTree.setStatus(getInferedStatus(faultTree));
}

public Status getInferedStatus(FaultTree faultTree ){
return !((System)faultTree.getSystem()).getOperationalDataFilter().getMinOperationalHours()
.equals(faultTree.getOperationalDataFilter().getMinOperationalHours())
? Status.outOfSync
: Status.ok;
}

public FaultTree update(FaultTree instance) {
if(instance.getManifestingEvent() == null && instance.getUri() != null){
FaultTree managedInstance = getPrimaryDao().find(instance.getUri()).orElse(null);
Expand Down
Loading

0 comments on commit fbe5d86

Please sign in to comment.