Skip to content

Commit

Permalink
Merge pull request #130 from kbss-cvut/fix/fta-fmea-ui-455-fix-saving…
Browse files Browse the repository at this point in the history
…-triples-in-default-context

Fix/fta fmea UI 455 fix saving triples in default context
  • Loading branch information
blcham authored Jun 27, 2024
2 parents fbe5d86 + ab88263 commit a8d6eca
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/cz/cvut/kbss/analysis/dao/BaseDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public List<T> findAll(URI contenxt) {
public Optional<T> 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);
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/dao/FaultEventTypeDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.net.URI;
import java.util.List;
import java.util.Optional;

@Repository
public class FaultEventTypeDao extends NamedEntityDao<FaultEventType> {
Expand Down Expand Up @@ -117,4 +118,16 @@ public List<FaultEventType> getAllFaultEvents(URI systemUri) {
throw new PersistenceException(e);
}
}

public FaultEventType getFaultEventSupertype(URI faultEventUri){
Optional<URI> 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);
}
}
11 changes: 0 additions & 11 deletions src/main/java/cz/cvut/kbss/analysis/dao/FaultTreeDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,16 +49,6 @@ public EntityDescriptor getEntityDescriptor(URI uri) {
EntityDescriptor entityDescriptor = new EntityDescriptor(uri);
super.setEntityDescriptor(entityDescriptor);
EntityType<FaultTree> ft = em.getMetamodel().entity(type);
EntityType<FaultEvent> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.stereotype.Repository;

import java.net.URI;
import java.util.Optional;

@Repository
public class OperationalDataFilterDao extends BaseDao<OperationalDataFilter> {
Expand All @@ -20,12 +21,14 @@ public OperationalDataFilterDao( EntityManager em, PersistenceConf config, Ident
}

public OperationalDataFilter findByEntity(URI entity) {
return em.createNativeQuery("""
Optional<URI> 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);
}

/**
Expand All @@ -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;
}
}
5 changes: 4 additions & 1 deletion src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ public static FaultEvent create(){
@Sequence
@OWLObjectProperty(iri = Vocabulary.s_p_has_child_sequence, fetch = FetchType.EAGER)
private List<URI> childrenSequence = new ArrayList<>();

public FailureMode getFailureMode(){
return getBehavior() instanceof FailureMode ? (FailureMode) getBehavior() : null;
}

public Function getFunction(){
return getBehavior() instanceof Function ? (Function) getBehavior() : null;
}
Expand All @@ -74,11 +76,12 @@ public void setFailureMode(FailureMode failureMode){
setBehavior(failureMode);
}


public void addChild(FaultEvent child) {
getChildren().add(child);
}

public void addChildren(Set<FaultEvent> children){getChildren().addAll(children);}

public void addChildSequenceUri(URI childUri) {getChildrenSequence().add(childUri);}

public Set<FaultEvent> getAllEventParts(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ public void updateChildrenSequence(URI faultEventUri, List<URI> 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());
Expand Down Expand Up @@ -239,4 +238,8 @@ public List<FaultEventType> getAllFaultEvents(URI faultTreeUri) {
? ret.stream().filter(t -> !typesToRemove.contains(t.getUri())).toList()
: ret;
}

public FaultEventType getFaultEventSupertype(URI faultEventUri) {
return faultEventTypeDao.getFaultEventSupertype(faultEventUri);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event> 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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public FaultTreeService(FaultEventRepositoryService faultEventRepositoryService,
}

public FaultTree findWithDetails(URI id) {
FaultTree ft = faultTreeRepositoryService.findRequired(id);
FaultTree ft = faultTreeRepositoryService.findWithRelatedEventTypes(id);
Collection<Event> events = faultTreeDao.getRelatedEventTypes(ft);
setRelatedBehaviors(events);

Expand Down

0 comments on commit a8d6eca

Please sign in to comment.