diff --git a/src/main/java/cz/cvut/kbss/analysis/controller/FaultEventController.java b/src/main/java/cz/cvut/kbss/analysis/controller/FaultEventController.java index e0202e88..c07d4826 100755 --- a/src/main/java/cz/cvut/kbss/analysis/controller/FaultEventController.java +++ b/src/main/java/cz/cvut/kbss/analysis/controller/FaultEventController.java @@ -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; @@ -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 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 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) { diff --git a/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java b/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java index fb2da05e..c4a4c2c0 100755 --- a/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java +++ b/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java @@ -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; @@ -94,4 +96,72 @@ public List getFaultEventRootWithSupertype(URI supertype){ throw new PersistenceException(e); } } + + public List getTopFaultEvents(URI systemUri) { + try{ + List ret = em.createNativeQuery(""" + PREFIX fta: + 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 ret1 = ret.stream().map(fe -> fe.asEntity(FaultEventType.class)).toList(); + return ret1; + }catch (RuntimeException e){ + throw new PersistenceException(e); + } + } + + public List getAllFaultEvents(URI systemUri) { + try{ + List ret = em.createNativeQuery(""" + PREFIX fta: + 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 ret1 = ret.stream().map(fe -> fe.asEntity(FaultEventType.class)).toList(); + return ret1; + }catch (RuntimeException e){ + throw new PersistenceException(e); + } + } } diff --git a/src/main/java/cz/cvut/kbss/analysis/model/FaultEventType.java b/src/main/java/cz/cvut/kbss/analysis/model/FaultEventType.java index f68db722..0ee6f831 100644 --- a/src/main/java/cz/cvut/kbss/analysis/model/FaultEventType.java +++ b/src/main/java/cz/cvut/kbss/analysis/model/FaultEventType.java @@ -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; @@ -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); + } + } diff --git a/src/main/java/cz/cvut/kbss/analysis/model/FaultEventTypeSummary.java b/src/main/java/cz/cvut/kbss/analysis/model/FaultEventTypeSummary.java new file mode 100644 index 00000000..3b467f9c --- /dev/null +++ b/src/main/java/cz/cvut/kbss/analysis/model/FaultEventTypeSummary.java @@ -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); + } +} diff --git a/src/main/java/cz/cvut/kbss/analysis/model/ava/FHAEventType.java b/src/main/java/cz/cvut/kbss/analysis/model/ava/FHAEventType.java index f54341d2..e5a95a4a 100644 --- a/src/main/java/cz/cvut/kbss/analysis/model/ava/FHAEventType.java +++ b/src/main/java/cz/cvut/kbss/analysis/model/ava/FHAEventType.java @@ -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; diff --git a/src/main/java/cz/cvut/kbss/analysis/service/FaultEventRepositoryService.java b/src/main/java/cz/cvut/kbss/analysis/service/FaultEventRepositoryService.java index 6226f357..caac5368 100755 --- a/src/main/java/cz/cvut/kbss/analysis/service/FaultEventRepositoryService.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/FaultEventRepositoryService.java @@ -191,4 +191,10 @@ protected void setChange(FaultEvent instance){ faultTreeDao.setChangedByContext(context, new Date()); } + public List getTopFaultEvents(URI systemUri) { + return faultEventDao.getTopFaultEvents(systemUri); + } + public List getAllFaultEvents(URI systemUri) { + return faultEventDao.getAllFaultEvents(systemUri); + } }