Skip to content

Commit

Permalink
[FIX #kbss-cvut/fta-fmea-ui#219] Fix for review comments.
Browse files Browse the repository at this point in the history
- remove TODOs
- rename BaseDao.existsInContext to  BaseDao.existsInPersistenceContext
- remove unused FaultEvent.failureMode,
- set default graph for attribute FaultEvent.behavior in FaultEvent EntityDescriptor in FaultEventDao
  • Loading branch information
kostobog committed Apr 4, 2024
1 parent 2dcc3dd commit ddd8365
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/main/java/cz/cvut/kbss/analysis/dao/BaseDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void remove(URI id) {
public boolean exists(URI id) {
Objects.requireNonNull(id);
try {
return em.createNativeQuery("ASK { ?x a ?type . }", Boolean.class) // TODO - consider existence in graph context
return em.createNativeQuery("ASK { ?x a ?type . }", Boolean.class)
.setParameter("x", id)
.setParameter("type", typeUri)
.getSingleResult();
Expand All @@ -177,13 +177,13 @@ public boolean exists(URI id) {
* @return
*/
@Override
public boolean existsInContext(URI id) {
public boolean existsInPersistenceContext(URI id) {
Objects.requireNonNull(id);
return em.find(type, id) != null;// TODO - consider existence in graph context, alternatively consider em.contains
return em.find(type, id) != null;
}

@Override
public boolean existsWithPredicate(String predicate, String value) {// TODO - consider existence in graph context
public boolean existsWithPredicate(String predicate, String value) {
Objects.requireNonNull(value);
return em
.createNativeQuery("ASK WHERE { ?x a ?type ; ?predicate ?value . }", Boolean.class)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ protected EntityDescriptor getEntityDescriptorInContext(URI graph){
EntityDescriptor entityDescriptor = new EntityDescriptor(graph);
EntityType<FaultEvent> fe = em.getMetamodel().entity(FaultEvent.class);
entityDescriptor.addAttributeContext(fe.getAttribute("supertypes"), null);
// TODO - consider not persisting failure mode in graph context
entityDescriptor.addAttributeContext(fe.getAttribute("behavior"), null);

return entityDescriptor;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cz/cvut/kbss/analysis/dao/GenericDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public interface GenericDao<T extends HasIdentifier> {
* @param id Entity identifier
* @return {@literal true} if entity exists, {@literal false} otherwise
*/
boolean existsInContext(URI id);
boolean existsInPersistenceContext(URI id);

/**
* Checks whether an entity with the specified predicate and its value exists (and has the type managed by this
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ public static FaultEvent create(){
@OWLObjectProperty(iri = Vocabulary.s_p_has_child, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private Set<FaultEvent> children = new HashSet<>();

@OWLObjectProperty(iri = Vocabulary.s_p_has_failure_mode, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
private FailureMode failureMode;

@OWLDataProperty(iri = Vocabulary.s_p_sequence_probability)
private Double sequenceProbability;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import com.fasterxml.classmate.ResolvedType;
Expand All @@ -17,9 +16,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.validation.DataBinder;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import org.springframework.validation.beanvalidation.SpringValidatorAdapter;


/**
Expand Down Expand Up @@ -243,13 +240,13 @@ public boolean exists(URI id) {
}

/**
* Checks whether an instance with the specified identifier exists in the current context and or the repository.
* Checks whether an instance with the specified identifier exists in the current persistence context and or the repository.
*
* @param id ID to check
* @return {@code true} if the instance exists, {@code false} otherwise
*/
public boolean existsInContext(URI id) {
return getPrimaryDao().existsInContext(id);
public boolean existsInPersistenceContext(URI id) {
return getPrimaryDao().existsInPersistenceContext(id);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ private FaultEvent transferBehaviorToFaultEvent(Behavior behavior, FaultEvent pa
URI faultEventUri1 = createUri(behavior, parentEvent, "e");
URI faultEventUri2 = createUri(behavior, parentEvent, "f");

if (faultEventRepositoryService.existsInContext(faultEventUri)) {
if (faultEventRepositoryService.existsInPersistenceContext(faultEventUri)) {
return faultEventRepositoryService.findRequired(faultEventUri);
} else if(faultEventRepositoryService.existsInContext(faultEventUri1)){
} else if(faultEventRepositoryService.existsInPersistenceContext(faultEventUri1)){
return faultEventRepositoryService.findRequired(faultEventUri1);
} else if(faultEventRepositoryService.existsInContext(faultEventUri2)){
} else if(faultEventRepositoryService.existsInPersistenceContext(faultEventUri2)){
return faultEventRepositoryService.findRequired(faultEventUri2);
} else {
FaultEvent faultEvent = FaultEvent.create();
Expand Down Expand Up @@ -276,9 +276,9 @@ private FaultEvent processImpairingBehavior(Behavior impairingBehavior, FaultEve
URI faultEventUri = createUri(impairingBehavior, impairedBehaviorEvent, "");
URI faultEventUriTypeEvent = createUri(impairingBehavior, impairedBehaviorEvent, "e");

if(faultEventRepositoryService.existsInContext(faultEventUri)) {
if(faultEventRepositoryService.existsInPersistenceContext(faultEventUri)) {
faultEvent = faultEventRepositoryService.findRequired(faultEventUri);
}else if(faultEventRepositoryService.existsInContext(faultEventUriTypeEvent)){
}else if(faultEventRepositoryService.existsInPersistenceContext(faultEventUriTypeEvent)){
faultEvent = faultEventRepositoryService.findRequired(faultEventUriTypeEvent);
}else {
faultEvent = FaultEvent.create();
Expand All @@ -302,7 +302,7 @@ private FaultEvent processImpairingBehavior(Behavior impairingBehavior, FaultEve
FaultEvent faultEventChild = FaultEvent.create();
faultEventChild.setBehavior(behaviorChild);
faultEventUri = createUri(behaviorChild, faultEvent, "e");
if (faultEventRepositoryService.existsInContext(faultEventUri)) {
if (faultEventRepositoryService.existsInPersistenceContext(faultEventUri)) {
faultEventChild = faultEventRepositoryService.findRequired(faultEventUri);
} else {
faultEventChild.setUri(faultEventUri);
Expand All @@ -327,7 +327,7 @@ private void processChildBehaviors(Behavior behavior,FaultEvent parentFaultEvent
FaultEvent faultEvent;
if(behavior instanceof Function){
URI faultEventUri = createUri(behavior, null, "f");
if (faultEventRepositoryService.existsInContext(faultEventUri)) {
if (faultEventRepositoryService.existsInPersistenceContext(faultEventUri)) {
faultEvent = faultEventRepositoryService.findRequired(faultEventUri);
} else {
faultEvent = FaultEvent.create();
Expand All @@ -345,7 +345,7 @@ private void processChildBehaviors(Behavior behavior,FaultEvent parentFaultEvent
continue;
FaultEvent fEvent = FaultEvent.create();
faultEventUri = createUri(behaviorChild, faultEvent, "");
if (faultEventRepositoryService.existsInContext(faultEventUri)) {
if (faultEventRepositoryService.existsInPersistenceContext(faultEventUri)) {
fEvent = faultEventRepositoryService.findRequired(faultEventUri);
} else {
fEvent.setBehavior(behaviorChild);
Expand Down

0 comments on commit ddd8365

Please sign in to comment.