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

Fix/fta mfea 374 update get all reusable fault events api #110

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ public List<FaultEventType> getTopFaultEvents(@PathVariable String systemFragmen
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);
@GetMapping(value = "/all-fault-events/{faultTreeFragment}", produces = {MediaType.APPLICATION_JSON_VALUE, JsonLd.MEDIA_TYPE})
public List<FaultEventType> getAllFaultEvents(@PathVariable String faultTreeFragment){
log.info("> getFaultEventTypes - {}", faultTreeFragment);
URI systemUri = identifierService.composeIdentifier(Vocabulary.s_c_fault_tree, faultTreeFragment);
return repositoryService.getAllFaultEvents(systemUri);
}

Expand Down
66 changes: 44 additions & 22 deletions src/main/java/cz/cvut/kbss/analysis/dao/FaultTreeDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

Expand Down Expand Up @@ -80,9 +81,30 @@ public Optional<FaultTree> find(URI id) {
@Override
public List<FaultTree> findAllSummaries() {
try {
List<FaultTreeSummary> ret = em.createNativeQuery("""
List<FaultTreeSummary> ret = getSummariesQuery()
.getResultList();
return ret.stream().map(s -> s.asEntity(type)).toList();
} catch (RuntimeException e) {
throw new PersistenceException(e);
}
}

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

public Query getSummariesQuery() {
return em.createNativeQuery("""
PREFIX fta: <http://onto.fel.cvut.cz/ontologies/fta-fmea-application/>
SELECT * WHERE {
SELECT * WHERE {
BIND(?_uri as ?uri)
?uri a ?type.
?uri ?pName ?name.
OPTIONAL{?uri ?pDescription ?description.}
Expand All @@ -91,35 +113,41 @@ public List<FaultTree> findAllSummaries() {
OPTIONAL{?uri ?pCreator ?creator.}
OPTIONAL{?uri ?pLastEditor ?lastEditor.}
OPTIONAL{
?uri fta:is-manifested-by ?root .
?root fta:is-derived-from ?sup.
?uri fta:is-manifested-by ?rootEvent .
?rootEvent fta:is-derived-from ?rootEventType.
OPTIONAL{
?root fta:probability ?calculatedFailureRate.
?rootEvent fta:probability ?calculatedFailureRate.
}
OPTIONAL{
?sup fta:has-failure-rate ?failureRate.
?rootEventType fta:has-failure-rate ?failureRate.
?failureRate fta:has-requirement ?failureRateRequirement.
?failureRateRequirement fta:to ?requiredFailureRate.
}
OPTIONAL{
?sup fta:is-derived-from ?supsup.
?rootEventType fta:is-derived-from ?supsup.
?supsup fta:has-failure-rate ?fhaFailureRateQ.
?fhaFailureRateQ fta:has-estimate ?fhaFailureRateP.
?fhaFailureRateP a fta:failure-rate-estimate;
fta:value ?fhaBasedFailureRate.
}
OPTIONAL{
?sup fta:is-manifestation-of ?behavior .
?behavior fta:has-component ?subsystemUri.
?subsystemUri fta:is-derived-from ?subsystemType.
?subsystemType fta:name ?subsystemTypeLabel.
?subsystemType fta:ata-code ?subsystemTypeCode.
BIND(CONCAT(str(?subsystemTypeCode), " - ", str(?subsystemTypeLabel)) as ?subsystemName)
?subsystemUri fta:is-part-of+ ?systemUri.
?rootEventType fta:is-manifestation-of ?behavior .
?behavior fta:has-component ?_subsystemUri.
?_subsystemUri fta:is-part-of* ?systemUri.
FILTER NOT EXISTS{
?systemUri fta:is-part-of ?system2.
?systemUri fta:is-part-of ?system2.
}
?systemUri fta:name ?systemName.

OPTIONAL{
FILTER(?systemUri != ?_subsystemUri)
BIND(?_subsystemUri as ?subsystemUri)
?subsystemUri fta:is-derived-from ?subsystemType.
?subsystemType fta:name ?subsystemTypeLabel.
?subsystemType fta:ata-code ?subsystemTypeCode.
BIND(CONCAT(str(?subsystemTypeCode), " - ", str(?subsystemTypeLabel)) as ?subsystemName)
?subsystemUri fta:is-part-of+ ?systemUri.
}
}
}
}""", "FaultTreeSummary")
Expand All @@ -129,12 +157,6 @@ public List<FaultTree> findAllSummaries() {
.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("pLastEditor", P_LAST_EDITOR);
}
}
19 changes: 19 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/model/FaultTreeSummary.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package cz.cvut.kbss.analysis.model;


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

import java.net.URI;
import java.util.HashSet;


@SparqlResultSetMappings(
Expand All @@ -19,6 +21,12 @@
@Setter
public class FaultTreeSummary extends ManagedEntity{

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

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

@OWLObjectProperty(iri = Vocabulary.s_p_is_artifact_of)
protected URI systemUri;

Expand All @@ -43,6 +51,17 @@ public class FaultTreeSummary extends ManagedEntity{

public void copyTo(FaultTree faultTree){
super.copyTo(faultTree);
if(this.getRootEvent() != null){
FaultEvent root = new FaultEvent();
root.setUri(this.getRootEvent());
faultTree.setManifestingEvent(root);
if(this.getRootEventType() != null){
FHAEventType rootType = new FHAEventType();
rootType.setUri(this.getRootEventType());
root.setSupertypes(new HashSet<>());
root.getSupertypes().add(rootType);
}
}
if(this.getSystemUri() != null){
faultTree.setSystem(new System());
faultTree.getSystem().setUri(this.getSystemUri());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.net.URI;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

@Slf4j
Expand Down Expand Up @@ -194,7 +196,16 @@ protected void setChange(FaultEvent instance){
public List<FaultEventType> getTopFaultEvents(URI systemUri) {
return faultEventDao.getTopFaultEvents(systemUri);
}
public List<FaultEventType> getAllFaultEvents(URI systemUri) {
return faultEventDao.getAllFaultEvents(systemUri);

public List<FaultEventType> getAllFaultEvents(URI faultTreeUri) {
FaultTree ftSummary = faultTreeDao.findSummary(faultTreeUri);
List<FaultEventType> ret = faultEventDao.getAllFaultEvents(ftSummary.getSystem().getUri());
Set<URI> typesToRemove = Optional.ofNullable(ftSummary.getManifestingEvent()).map(r -> r.getSupertypes())
.filter(s -> s !=null && !s.isEmpty())
.map(s -> s.stream().map(t -> t.getUri()).collect(Collectors.toSet()))
.orElse(null);
return typesToRemove != null
? ret.stream().filter(t -> !typesToRemove.contains(t.getUri())).toList()
: ret;
}
}
Loading