Skip to content

Commit

Permalink
Merge pull request #54 from kbss-cvut/feature/persist-diagram-layout
Browse files Browse the repository at this point in the history
Feature/persist diagram layout
  • Loading branch information
blcham authored Jan 10, 2024
2 parents 199ebd7 + 4f618b5 commit 3650224
Show file tree
Hide file tree
Showing 18 changed files with 211 additions and 51 deletions.
52 changes: 52 additions & 0 deletions ontology-generator/ontology/diagram.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@prefix : <http://onto.fel.cvut.cz/ontologies/diagram#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@base <http://onto.fel.cvut.cz/ontologies/diagram> .

<http://onto.fel.cvut.cz/ontologies/diagram> rdf:type owl:Ontology .

#################################################################
# Object Properties
#################################################################

### http://onto.fel.cvut.cz/ontologies/diagram/has-rectangle
<http://onto.fel.cvut.cz/ontologies/diagram/has-rectangle> rdf:type owl:ObjectProperty ;
rdfs:range <http://onto.fel.cvut.cz/ontologies/diagram/rectangle> .


#################################################################
# Data properties
#################################################################

### http://onto.fel.cvut.cz/ontologies/diagram/height
<http://onto.fel.cvut.cz/ontologies/diagram/height> rdf:type owl:DatatypeProperty ;
rdfs:range xsd:double .


### http://onto.fel.cvut.cz/ontologies/diagram/width
<http://onto.fel.cvut.cz/ontologies/diagram/width> rdf:type owl:DatatypeProperty ;
rdfs:range xsd:double .


### http://onto.fel.cvut.cz/ontologies/diagram/x
<http://onto.fel.cvut.cz/ontologies/diagram/x> rdf:type owl:DatatypeProperty ;
rdfs:range xsd:double .


### http://onto.fel.cvut.cz/ontologies/diagram/y
<http://onto.fel.cvut.cz/ontologies/diagram/y> rdf:type owl:DatatypeProperty ;
rdfs:range xsd:double .


#################################################################
# Classes
#################################################################

### http://onto.fel.cvut.cz/ontologies/diagram/rectangle
<http://onto.fel.cvut.cz/ontologies/diagram/rectangle> rdf:type owl:Class .


### Generated by the OWL API (version 4.5.9.2019-02-01T07:24:44Z) https://github.com/owlcs/owlapi
4 changes: 3 additions & 1 deletion ontology-generator/ontology/fta-fmea-model.ttl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@prefix termit: <http://onto.fel.cvut.cz/ontologies/application/termit/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
Expand All @@ -7,6 +6,9 @@
@prefix dc-terms: <http://purl.org/dc/terms/> .


<http://onto.fel.cvut.cz/ontologies/reliability-analysis-application> rdf:type owl:Ontology ;
owl:imports <http://onto.fel.cvut.cz/ontologies/diagram> .

fta-fmea:summary
rdf:type owl:Class ;
rdfs:label "Summary".
Expand Down
3 changes: 2 additions & 1 deletion ontology-generator/src/main/resources/mapping
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
http://onto.fel.cvut.cz/ontologies/fta-fmea-application > ../../../ontology/fta-fmea-model.ttl
http://onto.fel.cvut.cz/ontologies/fta-fmea-application > ../../../ontology/fta-fmea-model.ttl
http://onto.fel.cvut.cz/ontologies/diagram > ../../../ontology/diagram.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cz.cvut.kbss.analysis.model.FailureMode;
import cz.cvut.kbss.analysis.model.FaultEvent;
import cz.cvut.kbss.analysis.model.diagram.Rectangle;
import cz.cvut.kbss.analysis.service.FaultEventRepositoryService;
import cz.cvut.kbss.analysis.service.IdentifierService;
import cz.cvut.kbss.analysis.util.Vocabulary;
Expand Down Expand Up @@ -47,6 +48,14 @@ public void update(@RequestBody FaultEvent faultEvent) {
repositoryService.update(faultEvent);
}

@ResponseStatus(HttpStatus.NO_CONTENT)
@PutMapping(value = "/{faultEventFragment}/rectangle", consumes = {MediaType.APPLICATION_JSON_VALUE, JsonLd.MEDIA_TYPE}, produces = {JsonLd.MEDIA_TYPE, MediaType.APPLICATION_JSON_VALUE})
public void updateRectangle(@PathVariable(name = "faultEventFragment") String faultEventFragment, @RequestBody Rectangle rectangle) {
URI faultEventUri = identifierService.composeIdentifier(Vocabulary.s_c_FaultEvent, faultEventFragment);
log.trace("> update - updating rectangle - {} for event <{}>", rectangle, faultEventUri);
repositoryService.update(rectangle);
}

@ResponseStatus(HttpStatus.CREATED)
@PostMapping(value = "/{faultEventFragment}/inputEvents", consumes = {MediaType.APPLICATION_JSON_VALUE, JsonLd.MEDIA_TYPE})
public FaultEvent addInputEvent(@PathVariable(name = "faultEventFragment") String faultEventFragment, @RequestBody FaultEvent inputEvent) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cz.cvut.kbss.analysis.dao;

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.diagram.Rectangle;
import cz.cvut.kbss.analysis.util.Vocabulary;
import cz.cvut.kbss.jopa.model.EntityManager;
import org.springframework.stereotype.Repository;
Expand All @@ -23,4 +25,12 @@ public boolean isChild(URI faultEventIri) {
.getSingleResult();
}

public Rectangle update(Rectangle rect){
try{
return em.merge(rect);
}catch (RuntimeException e){
throw new PersistenceException(e);
}
}

}
12 changes: 8 additions & 4 deletions src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package cz.cvut.kbss.analysis.model;

import cz.cvut.kbss.analysis.model.util.EventType;
import cz.cvut.kbss.analysis.model.util.GateType;
import cz.cvut.kbss.analysis.model.fta.FtaEventType;
import cz.cvut.kbss.analysis.model.fta.GateType;
import cz.cvut.kbss.analysis.model.diagram.Rectangle;
import cz.cvut.kbss.analysis.util.Vocabulary;
import cz.cvut.kbss.jopa.model.annotations.*;
import lombok.Getter;
import lombok.Setter;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.net.URI;
import java.util.*;
Expand All @@ -19,11 +19,15 @@ public class FaultEvent extends Event {
@NotNull(message = "EventType must be defined")
@ParticipationConstraints(nonEmpty = true)
@OWLDataProperty(iri = Vocabulary.s_p_hasFaultEventType)
private EventType eventType;
private FtaEventType eventType;

@OWLDataProperty(iri = Vocabulary.s_p_hasGateType)
private GateType gateType;

@ParticipationConstraints(nonEmpty = true)
@OWLObjectProperty(iri = Vocabulary.s_p_has_rectangle, fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private Rectangle rectangle = new Rectangle();

@OWLDataProperty(iri = Vocabulary.s_p_hasProbability)
private Double probability;

Expand Down
55 changes: 55 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/model/diagram/Rectangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package cz.cvut.kbss.analysis.model.diagram;


import cz.cvut.kbss.analysis.util.Vocabulary;
import cz.cvut.kbss.jopa.model.annotations.Id;
import cz.cvut.kbss.jopa.model.annotations.OWLClass;
import cz.cvut.kbss.jopa.model.annotations.OWLDataProperty;
import cz.cvut.kbss.jopa.model.annotations.Transient;
import lombok.Getter;
import lombok.Setter;

import java.net.URI;

@OWLClass(iri = Vocabulary.s_c_rectangle)
@Getter
@Setter
public class Rectangle {

@Id(generated = true)
private URI uri;

@OWLDataProperty(iri = Vocabulary.s_p_x)
private Double x;
@OWLDataProperty(iri = Vocabulary.s_p_y)
private Double y;

@OWLDataProperty(iri = Vocabulary.s_p_width)
private Double width;
@OWLDataProperty(iri = Vocabulary.s_p_height)
private Double height;

public Rectangle() {
}
public Rectangle(Double[] array){
this(array[0], array[1], array[2], array[3]);
}

public Rectangle(Double x, Double y, Double width, Double height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}

@Override
public String toString() {
return "Rectangle[" +
"x=" + x +
", y=" + y +
", width=" + width +
", height=" + height +
']';
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cz.cvut.kbss.analysis.model.util;
package cz.cvut.kbss.analysis.model.fta;

public enum EventType {
public enum FtaEventType {
BASIC,
EXTERNAL,
UNDEVELOPED,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cz.cvut.kbss.analysis.model.util;
package cz.cvut.kbss.analysis.model.fta;

public enum GateType {
AND,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import cz.cvut.kbss.analysis.model.Component;
import cz.cvut.kbss.analysis.model.FailureMode;
import cz.cvut.kbss.analysis.model.FaultEvent;
import cz.cvut.kbss.analysis.model.util.EventType;
import cz.cvut.kbss.analysis.model.fta.FtaEventType;
import cz.cvut.kbss.analysis.model.diagram.Rectangle;
import cz.cvut.kbss.analysis.service.strategy.GateStrategyFactory;
import cz.cvut.kbss.analysis.service.validation.FaultEventValidator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
Expand Down Expand Up @@ -67,7 +67,7 @@ public FaultEvent addInputEvent(URI eventUri, FaultEvent inputEvent) {
public Double propagateProbability(FaultEvent event) {
log.info("> propagateProbability - {}", event);

if (event.getEventType() == EventType.INTERMEDIATE) {
if (event.getEventType() == FtaEventType.INTERMEDIATE) {
List<Double> childProbabilities = event.getChildren().stream()
.map(this::propagateProbability).collect(Collectors.toList());

Expand Down Expand Up @@ -136,6 +136,12 @@ public void updateChildrenSequence(URI faultEventUri, List<URI> childrenSequence
log.info("< updateChildrenSequence");
}

@Transactional
public void update(Rectangle rect){
faultEventDao.update(rect);
log.trace("< updateRectangle");
}

@Transactional(readOnly = true)
public boolean isRootEventReused(FaultEvent rootEvent) {
return faultEventDao.isChild(rootEvent.getUri());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import cz.cvut.kbss.analysis.dao.FaultTreeDao;
import cz.cvut.kbss.analysis.dao.GenericDao;
import cz.cvut.kbss.analysis.model.*;
import cz.cvut.kbss.analysis.model.util.EventType;
import cz.cvut.kbss.analysis.model.util.GateType;
import cz.cvut.kbss.analysis.model.fta.FtaEventType;
import cz.cvut.kbss.analysis.model.fta.GateType;
import cz.cvut.kbss.analysis.service.util.FaultTreeTraversalUtils;
import cz.cvut.kbss.analysis.util.Vocabulary;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -180,7 +180,7 @@ public FaultTree generateFunctionDependencyTree(URI functionUri, String faultTre

if(!function.getChildBehaviors().isEmpty() || !functionRepositoryService.getImpairingBehaviors(functionUri).isEmpty() || !function.getRequiredBehaviors().isEmpty()) {
processBehavior(function, faultEvent);
faultEvent.setEventType(EventType.INTERMEDIATE);
faultEvent.setEventType(FtaEventType.INTERMEDIATE);
}
cleanTreeGeneration();
persist(faultTree);
Expand Down Expand Up @@ -283,7 +283,7 @@ private FaultEvent processImpairingBehavior(Behavior impairingBehavior, FaultEve
faultEventUri = createUri(impairingBehavior, impairedBehaviorEvent, "");
faultEvent.setUri(faultEventUri);
faultEvent.setName(impairingBehavior.getName());
faultEvent.setEventType(EventType.INTERMEDIATE);
faultEvent.setEventType(FtaEventType.INTERMEDIATE);
faultEvent.setGateType(impairingBehavior.getBehaviorType() == BehaviorType.OrBehavior ? GateType.OR : GateType.AND);

for (Behavior behaviorChild : impairingBehavior.getChildBehaviors()) {
Expand All @@ -298,7 +298,7 @@ private FaultEvent processImpairingBehavior(Behavior impairingBehavior, FaultEve
faultEventChild.setUri(faultEventUri);
faultEventChild.setBehavior(behaviorChild);
faultEventChild.setName(behaviorChild.getName() + " event");
faultEventChild.setEventType(EventType.BASIC);
faultEventChild.setEventType(FtaEventType.BASIC);
faultEventChild.setGateType(GateType.UNUSED);
faultEventChild.setProbability(1.);
faultEventRepositoryService.persist(faultEventChild);
Expand All @@ -323,7 +323,7 @@ private void processChildBehaviors(Behavior behavior,FaultEvent parentFaultEvent
faultEvent = new FaultEvent();
faultEvent.setBehavior(behavior);
faultEvent.setName(behavior.getName() + " fails b/c its parts fail");
faultEvent.setEventType(EventType.INTERMEDIATE);
faultEvent.setEventType(FtaEventType.INTERMEDIATE);
faultEvent.setGateType(behavior.getBehaviorType() == BehaviorType.AndBehavior ? GateType.OR : GateType.AND);
faultEvent.setUri(faultEventUri);
faultEventRepositoryService.persist(faultEvent);
Expand All @@ -340,7 +340,7 @@ private void processChildBehaviors(Behavior behavior,FaultEvent parentFaultEvent
} else {
fEvent.setBehavior(behaviorChild);
fEvent.setName(behavior.getName() + " fails b/c " + behaviorChild.getName() + " fails");
fEvent.setEventType(EventType.INTERMEDIATE);
fEvent.setEventType(FtaEventType.INTERMEDIATE);
fEvent.setGateType(GateType.OR);
fEvent.setUri(faultEventUri);
faultEventRepositoryService.persist(fEvent);
Expand Down Expand Up @@ -383,11 +383,11 @@ private void setFaultEventTypes(Behavior behaviorChild, FaultEvent fEvent) {

private void setFaultEventTypes(boolean isBasic, FaultEvent fEvent){
if(isBasic){
fEvent.setEventType(EventType.BASIC);
fEvent.setEventType(FtaEventType.BASIC);
fEvent.setGateType(GateType.UNUSED);
fEvent.setProbability(1.);
}else{
fEvent.setEventType(EventType.INTERMEDIATE);
fEvent.setEventType(FtaEventType.INTERMEDIATE);
fEvent.setGateType(GateType.OR);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cz.cvut.kbss.analysis.service.strategy;

import cz.cvut.kbss.analysis.model.util.GateType;
import cz.cvut.kbss.analysis.model.fta.GateType;
import cz.cvut.kbss.analysis.service.strategy.probability.ProbabilityPropagationStrategy;

import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import cz.cvut.kbss.analysis.exception.LogicViolationException;
import cz.cvut.kbss.analysis.model.FaultEvent;
import cz.cvut.kbss.analysis.model.FaultTree;
import cz.cvut.kbss.analysis.model.util.EventType;
import cz.cvut.kbss.analysis.model.fta.FtaEventType;
import lombok.extern.slf4j.Slf4j;

import java.net.URI;
Expand Down Expand Up @@ -44,7 +43,7 @@ public static List<FaultEvent> rootToLeafPath(FaultEvent rootEvent, URI leafEven

for (FaultEvent child : currentEvent.getChildren()) {
if (child.getUri().equals(leafEventUri)) {
if (child.getEventType() == EventType.INTERMEDIATE) {
if (child.getEventType() == FtaEventType.INTERMEDIATE) {
String message = "Intermediate event must not be the end of the path!";
log.warn(message);
throw new LogicViolationException(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import cz.cvut.kbss.analysis.dao.FaultEventDao;
import cz.cvut.kbss.analysis.model.FaultEvent;
import cz.cvut.kbss.analysis.model.util.EventType;
import cz.cvut.kbss.analysis.model.util.GateType;
import cz.cvut.kbss.analysis.model.fta.FtaEventType;
import cz.cvut.kbss.analysis.model.fta.GateType;
import cz.cvut.kbss.analysis.util.Vocabulary;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -39,11 +39,11 @@ public void validate(Object target, Errors errors) {
errors.rejectValue("name", "name.duplicate");
}

if (instance.getEventType() == EventType.INTERMEDIATE && (instance.getGateType() == null || instance.getGateType() == GateType.UNUSED)) {
if (instance.getEventType() == FtaEventType.INTERMEDIATE && (instance.getGateType() == null || instance.getGateType() == GateType.UNUSED)) {
errors.rejectValue("gateType", "gateType.invalid");
}

if (instance.getEventType() != EventType.INTERMEDIATE && instance.getGateType() != GateType.UNUSED) {
if (instance.getEventType() != FtaEventType.INTERMEDIATE && instance.getGateType() != GateType.UNUSED) {
errors.rejectValue("gateType", "gateType.invalid");
}
}
Expand Down
Loading

0 comments on commit 3650224

Please sign in to comment.