Skip to content

Commit

Permalink
Merge pull request #91 from kbss-cvut/feature/72-add-api-to-fetch-fha…
Browse files Browse the repository at this point in the history
…-event-summary

Feature/72 add api to fetch fha event summary
  • Loading branch information
blcham authored May 15, 2024
2 parents 4f13178 + a4647ad commit 3e9324b
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cz.cvut.kbss.analysis.model.FailureMode;
import cz.cvut.kbss.analysis.model.FaultEvent;
import cz.cvut.kbss.analysis.model.FaultEventType;
import cz.cvut.kbss.analysis.model.diagram.Rectangle;
import cz.cvut.kbss.analysis.service.FaultEventRepositoryService;
import cz.cvut.kbss.analysis.service.IdentifierService;
Expand Down Expand Up @@ -73,6 +74,20 @@ public FailureMode getFailureMode(@PathVariable(name = "faultEventFragment") Str
return repositoryService.getFailureMode(faultEventUri);
}

@GetMapping(value = "/top-fault-events/{systemFragment}", produces = {MediaType.APPLICATION_JSON_VALUE, JsonLd.MEDIA_TYPE})
public List<FaultEventType> getTopFaultEvents(@PathVariable String systemFragment){
log.info("> getFaultEventTypes - {}", systemFragment);
URI systemUri = identifierService.composeIdentifier(Vocabulary.s_c_system, systemFragment);
return repositoryService.getTopFaultEvents(systemUri);
}

@GetMapping(value = "/all-fault-events/{systemFragment}", produces = {MediaType.APPLICATION_JSON_VALUE, JsonLd.MEDIA_TYPE})
public List<FaultEventType> getAllFaultEvents(@PathVariable String systemFragment){
log.info("> getFaultEventTypes - {}", systemFragment);
URI systemUri = identifierService.composeIdentifier(Vocabulary.s_c_system, systemFragment);
return repositoryService.getAllFaultEvents(systemUri);
}

@ResponseStatus(HttpStatus.CREATED)
@PostMapping(value = "/{faultEventFragment}/failureMode", consumes = {MediaType.APPLICATION_JSON_VALUE, JsonLd.MEDIA_TYPE})
public FailureMode addFailureMode(@PathVariable(name = "faultEventFragment") String faultEventFragment, @RequestBody FailureMode failureMode) {
Expand Down
70 changes: 70 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 @@ -4,6 +4,8 @@
import cz.cvut.kbss.analysis.exception.PersistenceException;
import cz.cvut.kbss.analysis.model.FaultEvent;
import cz.cvut.kbss.analysis.model.FaultEventReference;
import cz.cvut.kbss.analysis.model.FaultEventType;
import cz.cvut.kbss.analysis.model.FaultEventTypeSummary;
import cz.cvut.kbss.analysis.model.diagram.Rectangle;
import cz.cvut.kbss.analysis.service.IdentifierService;
import cz.cvut.kbss.analysis.util.Vocabulary;
Expand Down Expand Up @@ -94,4 +96,72 @@ public List<FaultEventReference> getFaultEventRootWithSupertype(URI supertype){
throw new PersistenceException(e);
}
}

public List<FaultEventType> getTopFaultEvents(URI systemUri) {
try{
List<FaultEventTypeSummary> ret = em.createNativeQuery("""
PREFIX fta: <http://onto.fel.cvut.cz/ontologies/fta-fmea-application/>
SELECT ?uri ?name ?componentName ?eventType {
?uri a fta:fha-fault-event ;
fta:name ?name ;
fta:is-manifestation-of/fta:has-component/((^fta:has-part-component)+) ?system ;
fta:is-derived-from ?generalEvent .
FILTER NOT EXISTS{
?system1 fta:has-part-component ?system.
}
?generalEvent fta:is-manifestation-of ?fm .
?fm fta:has-component ?component .
?component fta:name ?componentLabel ;
fta:ata-code ?code .
BIND(CONCAT(str(?code), " - ", str(?componentLabel)) as ?componentName)
BIND("INTERMEDIATE" as ?eventType)
}
""", "FaultEventSummary")
.setParameter("system", systemUri)
.getResultList();
List<FaultEventType> ret1 = ret.stream().map(fe -> fe.asEntity(FaultEventType.class)).toList();
return ret1;
}catch (RuntimeException e){
throw new PersistenceException(e);
}
}

public List<FaultEventType> getAllFaultEvents(URI systemUri) {
try{
List<FaultEventTypeSummary> ret = em.createNativeQuery("""
PREFIX fta: <http://onto.fel.cvut.cz/ontologies/fta-fmea-application/>
SELECT ?uri ?name ?componentName ?eventType {
?uri a ?eventClass.
FILTER(?eventClass in (fta:fha-fault-event, fta:fault-event-type))
?uri fta:name ?name ;
fta:is-manifestation-of/fta:has-component/((^fta:has-part-component)+) ?system ;
fta:is-derived-from ?generalEvent .
FILTER NOT EXISTS{
?system1 fta:has-part-component ?system.
}
?generalEvent fta:is-manifestation-of ?fm .
?fm fta:has-component ?component .
?component fta:name ?componentLabel ;
fta:ata-code ?code .
BIND(CONCAT(str(?code), " - ", str(?componentLabel)) as ?componentName)
BIND(IF(?eventClass = fta:fha-fault-event, "INTERMEDIATE", "BASIC") as ?eventType)
}
""", "FaultEventSummary")
.setParameter("system", systemUri)
.getResultList();

List<FaultEventType> ret1 = ret.stream().map(fe -> fe.asEntity(FaultEventType.class)).toList();
return ret1;
}catch (RuntimeException e){
throw new PersistenceException(e);
}
}
}
21 changes: 17 additions & 4 deletions src/main/java/cz/cvut/kbss/analysis/model/FaultEventType.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package cz.cvut.kbss.analysis.model;

import cz.cvut.kbss.analysis.util.Vocabulary;
import cz.cvut.kbss.jopa.model.annotations.CascadeType;
import cz.cvut.kbss.jopa.model.annotations.FetchType;
import cz.cvut.kbss.jopa.model.annotations.OWLClass;
import cz.cvut.kbss.jopa.model.annotations.OWLObjectProperty;
import cz.cvut.kbss.jopa.model.annotations.*;
import lombok.Getter;
import lombok.Setter;

Expand All @@ -16,4 +13,20 @@ public class FaultEventType extends Event{
@OWLObjectProperty(iri = Vocabulary.s_p_has_failure_rate, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private FailureRate failureRate;

@Transient
@OWLDataProperty(iri = Vocabulary.s_p_is_performed_by)
private String componentName;

@Transient
@OWLDataProperty(iri = Vocabulary.s_p_fault_event_type)
private String eventType;

@Override
public void setAs(NamedEntity namedEntity) {
if(namedEntity instanceof FaultEventTypeSummary)
((FaultEventTypeSummary)namedEntity).copyTo(this);
else
super.setAs(namedEntity);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cz.cvut.kbss.analysis.model;

import cz.cvut.kbss.analysis.util.Vocabulary;
import cz.cvut.kbss.jopa.model.annotations.*;
import lombok.Getter;
import lombok.Setter;

@SparqlResultSetMappings(
@SparqlResultSetMapping(name="FaultEventSummary", entities = {
@EntityResult(entityClass=FaultEventTypeSummary.class)
})
)
@OWLClass(iri = Vocabulary.s_c_fault_event_type)
@Getter
@Setter
public class FaultEventTypeSummary extends NamedEntity{

@OWLDataProperty(iri = Vocabulary.s_p_is_performed_by)
private String componentName;

@OWLDataProperty(iri = Vocabulary.s_p_fault_event_type)
private String eventType;


// private

public void copyTo(FaultEventType faultEventType){
super.copyTo(faultEventType);
faultEventType.setComponentName(componentName);
faultEventType.setEventType(eventType);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cz.cvut.kbss.analysis.model.ava;

import cz.cvut.kbss.analysis.model.Event;
import cz.cvut.kbss.analysis.model.FaultEventType;
import cz.cvut.kbss.analysis.model.method.VerificationMethod;
import cz.cvut.kbss.analysis.util.Vocabulary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,10 @@ protected void setChange(FaultEvent instance){
faultTreeDao.setChangedByContext(context, new Date());
}

public List<FaultEventType> getTopFaultEvents(URI systemUri) {
return faultEventDao.getTopFaultEvents(systemUri);
}
public List<FaultEventType> getAllFaultEvents(URI systemUri) {
return faultEventDao.getAllFaultEvents(systemUri);
}
}

0 comments on commit 3e9324b

Please sign in to comment.