Skip to content

Commit

Permalink
Fix creating fault tree when root event has supertype.
Browse files Browse the repository at this point in the history
- update BaseDao.getContext to not fail when entity is in multiple contexts.
- add FaultEventDao.findEvent
- fix FaultTreeRepositoryService.createTree to replace root supertypes for managed entities.
  • Loading branch information
kostobog authored and blcham committed Jun 4, 2024
1 parent ddd6fe4 commit fc939e5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
7 changes: 5 additions & 2 deletions src/main/java/cz/cvut/kbss/analysis/dao/BaseDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ public URI getContext(T entity){
}

public URI getContext(URI uri){
return em.createNativeQuery("SELECT DISTINCT ?context {GRAPH ?context {?uri a ?type}}", URI.class)
List<URI> contexts = em.createNativeQuery("SELECT DISTINCT ?context {GRAPH ?context {?uri a ?type}}", URI.class)
.setParameter("uri", uri)
.getSingleResult();
.getResultList();
if(contexts.isEmpty())
return null;
return contexts.get(0);
}

@Override
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import cz.cvut.kbss.analysis.config.conf.PersistenceConf;
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.*;
import cz.cvut.kbss.analysis.model.diagram.Rectangle;
import cz.cvut.kbss.analysis.service.IdentifierService;
import cz.cvut.kbss.analysis.util.Vocabulary;
Expand All @@ -17,6 +14,8 @@

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

@Repository
public class FaultEventDao extends NamedEntityDao<FaultEvent> {
Expand Down Expand Up @@ -75,6 +74,15 @@ public Rectangle update(Rectangle rect){
}
}

public Optional<Event> findEvent(URI id){
Objects.requireNonNull(id);
try {
EntityDescriptor entityDescriptor = getEntityDescriptor(id);
return Optional.ofNullable(em.find(Event.class, id, entityDescriptor));
} catch (RuntimeException e) {
throw new PersistenceException(e);
}
}

public List<FaultEventReference> getFaultEventRootWithSupertype(URI supertype){
try{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package cz.cvut.kbss.analysis.service;

import cz.cvut.kbss.analysis.dao.FaultEventScenarioDao;
import cz.cvut.kbss.analysis.dao.FaultTreeDao;
import cz.cvut.kbss.analysis.dao.GenericDao;
import cz.cvut.kbss.analysis.dao.UserDao;
import cz.cvut.kbss.analysis.dao.*;
import cz.cvut.kbss.analysis.exception.EntityNotFoundException;
import cz.cvut.kbss.analysis.model.*;
import cz.cvut.kbss.analysis.model.diagram.Rectangle;
Expand Down Expand Up @@ -39,6 +36,7 @@ public class FaultTreeRepositoryService extends ComplexManagedEntityRepositorySe
private final IdentifierService identifierService;

private final ThreadLocal<Set<Behavior>> visitedBehaviors = new ThreadLocal<>();
private final FaultEventDao faultEventDao;

@Autowired
public FaultTreeRepositoryService(@Qualifier("defaultValidator") Validator validator,
Expand All @@ -48,14 +46,15 @@ public FaultTreeRepositoryService(@Qualifier("defaultValidator") Validator valid
FunctionRepositoryService functionRepositoryService,
IdentifierService identifierService,
UserDao userDao,
SecurityUtils securityUtils
) {
SecurityUtils securityUtils,
FaultEventDao faultEventDao) {
super(validator, userDao, securityUtils);
this.faultTreeDao = faultTreeDao;
this.faultEventScenarioDao = faultEventScenarioDao;
this.faultEventRepositoryService = faultEventRepositoryService;
this.functionRepositoryService = functionRepositoryService;
this.identifierService = identifierService;
this.faultEventDao = faultEventDao;
}

@Override
Expand All @@ -66,7 +65,16 @@ protected GenericDao<FaultTree> getPrimaryDao() {
@Transactional
public void createTree(FaultTree faultTree){
if(faultTree.getManifestingEvent() != null){
faultTree.getManifestingEvent().setRectangle(new Rectangle());
FaultEvent faultEvent = faultTree.getManifestingEvent();
faultEvent.setRectangle(new Rectangle());
if(faultEvent.getSupertypes() != null) {
Set<Event> managedSupertypes = new HashSet<>();
for(Event event : faultEvent.getSupertypes()){
faultEventDao.findEvent(event.getUri())
.ifPresent(managedSupertypes::add);
}
faultEvent.setSupertypes(managedSupertypes);
}
}
persist(faultTree);
}
Expand Down

0 comments on commit fc939e5

Please sign in to comment.