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' 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/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/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/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(){ 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..144c257 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()); @@ -239,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);