From 630da9237fa44e55970029ffe70db4de00106619 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Thu, 27 Jun 2024 09:38:22 +0200 Subject: [PATCH 1/4] Reformat FaultEvent --- src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java b/src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java index d1ab5da..1d01bd3 100755 --- a/src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java +++ b/src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java @@ -63,9 +63,11 @@ public static FaultEvent create(){ @Sequence @OWLObjectProperty(iri = Vocabulary.s_p_has_child_sequence, fetch = FetchType.EAGER) private List childrenSequence = new ArrayList<>(); + public FailureMode getFailureMode(){ return getBehavior() instanceof FailureMode ? (FailureMode) getBehavior() : null; } + public Function getFunction(){ return getBehavior() instanceof Function ? (Function) getBehavior() : null; } @@ -74,11 +76,12 @@ public void setFailureMode(FailureMode failureMode){ setBehavior(failureMode); } - public void addChild(FaultEvent child) { getChildren().add(child); } + public void addChildren(Set children){getChildren().addAll(children);} + public void addChildSequenceUri(URI childUri) {getChildrenSequence().add(childUri);} public Set getAllEventParts(){ From 8c5cec25adbaf34c8a207b46c3aad8d83c269b05 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Thu, 27 Jun 2024 09:43:02 +0200 Subject: [PATCH 2/4] [Fix kbss-cvut/fta-fmea-ui#455] Fix updating FaultEvent and OperationalDataFilter stored in default context - updated jopa entities must be read in context in order for the update to be stored there --- .../java/cz/cvut/kbss/analysis/dao/BaseDao.java | 3 ++- .../analysis/dao/OperationalDataFilterDao.java | 14 ++++++++++---- .../service/FaultEventRepositoryService.java | 3 +-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/cz/cvut/kbss/analysis/dao/BaseDao.java b/src/main/java/cz/cvut/kbss/analysis/dao/BaseDao.java index 9c0f740..4da95a7 100755 --- a/src/main/java/cz/cvut/kbss/analysis/dao/BaseDao.java +++ b/src/main/java/cz/cvut/kbss/analysis/dao/BaseDao.java @@ -101,7 +101,8 @@ public List findAll(URI contenxt) { public Optional find(URI id) { Objects.requireNonNull(id); try { - return Optional.ofNullable(em.find(type, id)); + EntityDescriptor entityDescriptor = getEntityDescriptor(id); + return Optional.ofNullable(em.find(type, id, entityDescriptor)); } catch (RuntimeException e) { throw new PersistenceException(e); } diff --git a/src/main/java/cz/cvut/kbss/analysis/dao/OperationalDataFilterDao.java b/src/main/java/cz/cvut/kbss/analysis/dao/OperationalDataFilterDao.java index 9976648..b44ba2f 100644 --- a/src/main/java/cz/cvut/kbss/analysis/dao/OperationalDataFilterDao.java +++ b/src/main/java/cz/cvut/kbss/analysis/dao/OperationalDataFilterDao.java @@ -9,6 +9,7 @@ import org.springframework.stereotype.Repository; import java.net.URI; +import java.util.Optional; @Repository public class OperationalDataFilterDao extends BaseDao { @@ -20,12 +21,14 @@ public OperationalDataFilterDao( EntityManager em, PersistenceConf config, Ident } public OperationalDataFilter findByEntity(URI entity) { - return em.createNativeQuery(""" + Optional optUri = em.createNativeQuery(""" SELECT ?uri WHERE {?entity ?hasOperationalDataFilter ?uri } LIMIT 1 - """, OperationalDataFilter.class) + """, URI.class) .setParameter("hasOperationalDataFilter", HAS_OPERATIONAL_DATA_FILTER_PROP) .setParameter("entity", entity) - .getResultList().stream().findAny().orElse(null); + .getResultList().stream().findAny(); + + return optUri.map( u -> find(u).orElse(null)).orElse(null); } /** @@ -39,6 +42,9 @@ public void persistHasFilter(URI entityURI, OperationalDataFilter filter){ @Override public EntityDescriptor getEntityDescriptor(URI uri) { - return super.getEntityDescriptor(uri); + EntityDescriptor entityDescriptor = super.getEntityDescriptor(uri); + URI context = getContext(uri); + entityDescriptor.addContext(context); + return entityDescriptor; } } 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 c1cd1c4..b8cb066 100755 --- a/src/main/java/cz/cvut/kbss/analysis/service/FaultEventRepositoryService.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/FaultEventRepositoryService.java @@ -173,8 +173,7 @@ public void updateChildrenSequence(URI faultEventUri, List childrenSequence public FaultEvent update(FaultEvent instance) { Objects.requireNonNull(instance); preUpdate(instance); - FaultEvent managedInstance = faultEventDao.find(instance.getUri()).orElse( null); - assert managedInstance != null; + FaultEvent managedInstance = findRequired(instance.getUri()); managedInstance.setName(instance.getName()); managedInstance.setGateType(instance.getGateType()); managedInstance.setEventType(instance.getEventType()); From 94857979fe540f0b6a8087f18bbce7c1cd414e57 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Thu, 27 Jun 2024 10:12:02 +0200 Subject: [PATCH 3/4] [Fix issue caused by solution of kbss-cvut/fta-fmea-ui#455] Fix supertypes not read when fetching fault tree with details. --- .../kbss/analysis/dao/FaultEventTypeDao.java | 13 +++++++++++++ .../cvut/kbss/analysis/dao/FaultTreeDao.java | 11 ----------- .../service/FaultEventRepositoryService.java | 4 ++++ .../service/FaultTreeRepositoryService.java | 19 ++++++++++++++++--- .../analysis/service/FaultTreeService.java | 2 +- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventTypeDao.java b/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventTypeDao.java index 3fb5862..15fd4ec 100644 --- a/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventTypeDao.java +++ b/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventTypeDao.java @@ -12,6 +12,7 @@ import java.net.URI; import java.util.List; +import java.util.Optional; @Repository public class FaultEventTypeDao extends NamedEntityDao { @@ -117,4 +118,16 @@ public List getAllFaultEvents(URI systemUri) { throw new PersistenceException(e); } } + + public FaultEventType getFaultEventSupertype(URI faultEventUri){ + Optional optUri = em.createNativeQuery(""" + SELECT ?uri { + ?faultEventUri ?isDerivedFromProp ?uri. + } + """,URI.class) + .setParameter("isDerivedFromProp", DERIVED_FROM_PROP) + .setParameter("faultEventUri", faultEventUri) + .getResultStream().limit(1).findAny(); + return optUri.map(u -> find(u).orElse(null)).orElse(null); + } } diff --git a/src/main/java/cz/cvut/kbss/analysis/dao/FaultTreeDao.java b/src/main/java/cz/cvut/kbss/analysis/dao/FaultTreeDao.java index 0faa244..4235081 100755 --- a/src/main/java/cz/cvut/kbss/analysis/dao/FaultTreeDao.java +++ b/src/main/java/cz/cvut/kbss/analysis/dao/FaultTreeDao.java @@ -8,7 +8,6 @@ import cz.cvut.kbss.analysis.util.Vocabulary; import cz.cvut.kbss.jopa.model.EntityManager; 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; @@ -50,16 +49,6 @@ public EntityDescriptor getEntityDescriptor(URI uri) { EntityDescriptor entityDescriptor = new EntityDescriptor(uri); super.setEntityDescriptor(entityDescriptor); EntityType ft = em.getMetamodel().entity(type); - EntityType fe = em.getMetamodel().entity(FaultEvent.class); - Attribute manifestingEvent = ft.getAttribute("manifestingEvent"); - Attribute children = fe.getAttribute("children"); - - entityDescriptor.addAttributeContext(manifestingEvent, uri); - entityDescriptor.getAttributeDescriptor(manifestingEvent) - .addAttributeContext(fe.getAttribute("supertypes"), null) - .addAttributeContext(children, uri).getAttributeDescriptor(children) - .addAttributeContext(fe.getAttribute("supertypes"), null); - entityDescriptor.addAttributeContext(ft.getAttribute("failureModesTable"), null); return entityDescriptor; 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 b8cb066..144c257 100755 --- a/src/main/java/cz/cvut/kbss/analysis/service/FaultEventRepositoryService.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/FaultEventRepositoryService.java @@ -238,4 +238,8 @@ public List getAllFaultEvents(URI faultTreeUri) { ? ret.stream().filter(t -> !typesToRemove.contains(t.getUri())).toList() : ret; } + + public FaultEventType getFaultEventSupertype(URI faultEventUri) { + return faultEventTypeDao.getFaultEventSupertype(faultEventUri); + } } diff --git a/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java b/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java index f4f406f..2939e24 100755 --- a/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java @@ -105,9 +105,22 @@ public void createTree(FaultTree faultTree){ persist(faultTree); } - @Transactional - public FaultTree findRequired(URI id) { - return super.findRequired(id); + @Transactional(readOnly = true) + public FaultTree findWithRelatedEventTypes(URI id) { + FaultTree faultTree = findRequired(id); + for( FaultEvent fe : faultTree.getAllEvents()) { + FaultEventType supertype = faultEventRepositoryService.getFaultEventSupertype(fe.getUri()); + if(supertype == null) + continue; + Set supertypes = fe.getSupertypes(); + if(supertypes == null) { + supertypes = new HashSet<>(); + fe.setSupertypes(supertypes); + } + fe.getSupertypes().remove(supertype); + fe.getSupertypes().add(supertype); + } + return faultTree; } public FaultTree findSummary(URI faultTreeUri){ diff --git a/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeService.java b/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeService.java index cd90024..e15fd2f 100644 --- a/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeService.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeService.java @@ -34,7 +34,7 @@ public FaultTreeService(FaultEventRepositoryService faultEventRepositoryService, } public FaultTree findWithDetails(URI id) { - FaultTree ft = faultTreeRepositoryService.findRequired(id); + FaultTree ft = faultTreeRepositoryService.findWithRelatedEventTypes(id); Collection events = faultTreeDao.getRelatedEventTypes(ft); setRelatedBehaviors(events); From ab88263360d278e244a243c1ac71cd593da82032 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Thu, 27 Jun 2024 10:12:53 +0200 Subject: [PATCH 4/4] [Upgrade] Bump jopa version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 0ba59b1..886fd8f 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ war { sourceSets.main.java.srcDirs += "src/main/generated" dependencies { - def jopaVersion = '2.0.0' + def jopaVersion = '2.0.2' implementation "cz.cvut.kbss.jopa:jopa-impl:$jopaVersion" implementation "cz.cvut.kbss.jopa:ontodriver-rdf4j:$jopaVersion" implementation 'cz.cvut.kbss.jsonld:jb4jsonld-jackson:0.14.3'