Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fta fmea UI 219 implement reference nodes #74

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ontology-generator/ontology/fta-fmea-model.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ fta-fmea:is-triggered-by rdf:type owl:ObjectProperty ;
rdfs:range fta-fmea:situation ;
rdfs:label "is triggered by" .

### http://onto.fel.cvut.cz/ontologies/fta-fmea-application/is-reference-to
fta-fmea:is-reference-to rdf:type owl:ObjectProperty .

### http://onto.fel.cvut.cz/ontologies/fta-fmea-application/has-trigger
fta-fmea:has-trigger rdf:type owl:ObjectProperty ;
Expand All @@ -333,6 +335,9 @@ fta-fmea:has-trigger rdf:type owl:ObjectProperty ;
# Data properties
#################################################################

### http://onto.fel.cvut.cz/ontologies/fta-fmea-application/is-reference
fta-fmea:is-reference rdf:type owl:DatatypeProperty .

### http://onto.fel.cvut.cz/ontologies/fta-fmea-application/value
fta-fmea:value rdf:type owl:DatatypeProperty .

Expand Down Expand Up @@ -658,6 +663,11 @@ fta-fmea:fault-event-scenario-type rdf:type owl:Class ;
### http://onto.fel.cvut.cz/ontologies/fta-fmea-application/fault-event-type
fta-fmea:fault-event-type rdf:type owl:Class .

### http://onto.fel.cvut.cz/ontologies/fta-fmea-application/atomic-event-type
fta-fmea:atomic-event-type rdf:type owl:Class .

### http://onto.fel.cvut.cz/ontologies/fta-fmea-application/complex-event-type
fta-fmea:complex-event-type rdf:type owl:Class .

### http://onto.fel.cvut.cz/ontologies/fta-fmea-application/fault-tree-cut-set-extraction-method
fta-fmea:fault-tree-cut-set-extraction-method rdf:type owl:Class ;
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@
import org.springframework.stereotype.Repository;

import java.net.URI;
import java.util.List;

@Repository
public class FaultEventDao extends NamedEntityDao<FaultEvent> {

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);

@Autowired
protected FaultEventDao(EntityManager em, PersistenceConf config, IdentifierService identifierService) {
super(FaultEvent.class, em, config, identifierService);
Expand Down Expand Up @@ -65,4 +71,26 @@ public Rectangle update(Rectangle rect){
throw new PersistenceException(e);
}
}


public List<URI> getFaultEventRootWithSupertype(URI supertype){
try{
return em.createNativeQuery(
"""
SELECT DISTINCT ?uri WHERE{
?uri ?derivedFrom ?supertype.
?uri ?ftaEventTypeProp ?ftaEventType.
?uri a ?type.
?faultTree ?isManifestedByProp ?uri
}""", URI.class)
.setParameter("derivedFrom", DERIVED_FROM_PROP)
.setParameter("supertype", supertype)
.setParameter("ftaEventTypeProp", FTA_EVENT_TYPE_PROP)
.setParameter("type", this.typeUri)
.setParameter("isManifestedByProp", IS_MANIFESTED_BY_PROP)
.getResultList();
}catch (RuntimeException e){
throw new PersistenceException(e);
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/model/AbstractEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.Serializable;
import java.net.URI;
import java.util.Objects;
import java.util.Set;

@MappedSuperclass
@Data
Expand All @@ -19,6 +20,9 @@ public abstract class AbstractEntity implements HasIdentifier, Serializable {
@Id(generated = true)
private URI uri;

@Types
private Set<URI> types;

@OWLObjectProperty(iri = Vocabulary.s_p_source, fetch = FetchType.EAGER)
private URI annotationSource;

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public static FaultEvent create(){
return faultEvent;
}

@Transient
@OWLObjectProperty(iri = Vocabulary.s_p_is_reference_to)
private URI references;

@Transient
@OWLDataProperty(iri = Vocabulary.s_p_is_reference)
private boolean isReference;

@NotNull(message = "EventType must be defined")
@ParticipationConstraints(nonEmpty = true)
@OWLDataProperty(iri = Vocabulary.s_p_fault_event_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import cz.cvut.kbss.analysis.dao.FaultTreeDao;
import cz.cvut.kbss.analysis.dao.GenericDao;
import cz.cvut.kbss.analysis.exception.LogicViolationException;
import cz.cvut.kbss.analysis.model.Event;
import cz.cvut.kbss.analysis.model.FailureMode;
import cz.cvut.kbss.analysis.model.FaultEvent;
import cz.cvut.kbss.analysis.model.Item;
import cz.cvut.kbss.analysis.model.diagram.Rectangle;
import cz.cvut.kbss.analysis.model.fta.FtaEventType;
import cz.cvut.kbss.analysis.service.strategy.DirectFtaEvaluation;
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 @@ -18,11 +21,16 @@

import java.net.URI;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class FaultEventRepositoryService extends BaseRepositoryService<FaultEvent> {

public static final URI ATOMIC_TYPE = URI.create(Vocabulary.s_c_atomic_event_type);
public static final URI COMPLEX_TYPE = URI.create(Vocabulary.s_c_complex_event_type);


private final FaultEventDao faultEventDao;
private final ComponentRepositoryService componentRepositoryService;
private final FaultTreeDao faultTreeDao;
Expand Down Expand Up @@ -60,9 +68,43 @@ public FaultEvent addInputEvent(URI eventUri, FaultEvent inputEvent) {
currentEvent.addChildSequenceUri(inputEvent.getUri());
update(currentEvent);

setExternalReference(eventUri, inputEvent);
return inputEvent;
}

protected void setExternalReference(URI eventUri, FaultEvent inputEvent){
if(inputEvent.getSupertypes() == null || inputEvent.getEventType() != FtaEventType.EXTERNAL)
return;

List<Event> supertypes = inputEvent.getSupertypes().stream()
.filter(e -> e.getTypes() != null && !e.getTypes().contains(ATOMIC_TYPE))
.collect(Collectors.toList());
if(supertypes.isEmpty())
return;

inputEvent.setReference(true);

if(supertypes.size() > 1)
log.warn("new event added to event <{}> has multiple supertypes [{}]",
eventUri,
supertypes.stream().map(e -> String.format("<%s>", e.getUri().toString()))
.collect(Collectors.joining(",")));

Event supertype = supertypes.get(0);
List<URI> referencedRoots = faultEventDao.getFaultEventRootWithSupertype(supertype.getUri());

if(referencedRoots == null || referencedRoots.isEmpty())
return;

if(referencedRoots.size() > 1)
log.warn("new event added to event <{}> with supertype <{}> is used in multiple root fault events [{}]",
eventUri, supertype.getUri(),
referencedRoots.stream().map(u -> String.format("<%s>", u.toString()))
.collect(Collectors.joining(",")));

inputEvent.setReferences(referencedRoots.get(0));
}

@Transactional(readOnly = true)
public Double propagateProbability(FaultEvent event) {
log.info("> propagateProbability - {}", event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import cz.cvut.kbss.analysis.model.fta.FtaEventType;
import cz.cvut.kbss.analysis.model.fta.GateType;
import cz.cvut.kbss.analysis.service.util.FaultTreeTraversalUtils;
import cz.cvut.kbss.analysis.service.util.Pair;
import cz.cvut.kbss.analysis.util.Vocabulary;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -64,6 +65,30 @@ public void createTree(FaultTree faultTree){
persist(faultTree);
}

@Transactional
@Override
public FaultTree findRequired(URI id) {
FaultTree faultTree = super.findRequired(id);
setReferences(faultTree);
return faultTree;
}

public void setReferences(FaultTree faultTree){
if(faultTree.getManifestingEvent() == null)
return;

Stack<Pair<URI,FaultEvent>> stack = new Stack<>();
stack.add(Pair.of(null,faultTree.getManifestingEvent()));
while(!stack.isEmpty()){
Pair<URI,FaultEvent> p = stack.pop();
FaultEvent fe = p.getSecond();
faultEventRepositoryService.setExternalReference(p.getFirst(), fe);
if(fe.getChildren() == null)
continue;
fe.getChildren().forEach(c -> stack.push(Pair.of(fe.getUri(), c)));
}
}

@Transactional
public FaultTree findWithPropagation(URI faultTreeUri) {
log.info("> findWithPropagation - {}", faultTreeUri);
Expand Down
Loading