From ced2d5d7dafa0b723c46f19d60912a5a99df9997 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Tue, 2 Jan 2024 14:23:33 +0100 Subject: [PATCH 1/8] [kbss-cvut/fta-fmea-ui#131] Add ontology diagram - the ontology contains rectangle class and its properties as well as a property to associate other instances with a rectangle. --- ontology-generator/ontology/diagram.ttl | 52 +++++++++++++++++++ .../ontology/fta-fmea-model.ttl | 4 +- ontology-generator/src/main/resources/mapping | 3 +- 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 ontology-generator/ontology/diagram.ttl diff --git a/ontology-generator/ontology/diagram.ttl b/ontology-generator/ontology/diagram.ttl new file mode 100644 index 00000000..2e2f96ff --- /dev/null +++ b/ontology-generator/ontology/diagram.ttl @@ -0,0 +1,52 @@ +@prefix : . +@prefix owl: . +@prefix rdf: . +@prefix xml: . +@prefix xsd: . +@prefix rdfs: . +@base . + + rdf:type owl:Ontology . + +################################################################# +# Object Properties +################################################################# + +### http://onto.fel.cvut.cz/ontologies/diagram/has-rectangle + rdf:type owl:ObjectProperty ; + rdfs:range . + + +################################################################# +# Data properties +################################################################# + +### http://onto.fel.cvut.cz/ontologies/diagram/height + rdf:type owl:DatatypeProperty ; + rdfs:range xsd:double . + + +### http://onto.fel.cvut.cz/ontologies/diagram/width + rdf:type owl:DatatypeProperty ; + rdfs:range xsd:double . + + +### http://onto.fel.cvut.cz/ontologies/diagram/x + rdf:type owl:DatatypeProperty ; + rdfs:range xsd:double . + + +### 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 + rdf:type owl:Class . + + +### Generated by the OWL API (version 4.5.9.2019-02-01T07:24:44Z) https://github.com/owlcs/owlapi diff --git a/ontology-generator/ontology/fta-fmea-model.ttl b/ontology-generator/ontology/fta-fmea-model.ttl index 0442bdf3..197f6fc4 100644 --- a/ontology-generator/ontology/fta-fmea-model.ttl +++ b/ontology-generator/ontology/fta-fmea-model.ttl @@ -1,4 +1,3 @@ -@prefix termit: . @prefix rdf: . @prefix owl: . @prefix xsd: . @@ -7,6 +6,9 @@ @prefix dc-terms: . + rdf:type owl:Ontology ; + owl:imports . + fta-fmea:summary rdf:type owl:Class ; rdfs:label "Summary". diff --git a/ontology-generator/src/main/resources/mapping b/ontology-generator/src/main/resources/mapping index 6a5d9e2c..37d23e1c 100644 --- a/ontology-generator/src/main/resources/mapping +++ b/ontology-generator/src/main/resources/mapping @@ -1 +1,2 @@ -http://onto.fel.cvut.cz/ontologies/fta-fmea-application > ../../../ontology/fta-fmea-model.ttl \ No newline at end of file +http://onto.fel.cvut.cz/ontologies/fta-fmea-application > ../../../ontology/fta-fmea-model.ttl +http://onto.fel.cvut.cz/ontologies/diagram > ../../../ontology/diagram.ttl \ No newline at end of file From a9c0c91c5778878ea1456af2bb4bfdcfe2645d95 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Tue, 2 Jan 2024 14:31:04 +0100 Subject: [PATCH 2/8] [kbss-cvut/fta-fmea-ui#131] Add Rectangle Jopa entity and a rectangle field to FaultEvent --- .../cvut/kbss/analysis/model/FaultEvent.java | 5 ++ .../analysis/model/diagram/Rectangle.java | 55 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/main/java/cz/cvut/kbss/analysis/model/diagram/Rectangle.java 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 f958f013..019f61b6 100755 --- a/src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java +++ b/src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java @@ -2,6 +2,7 @@ import cz.cvut.kbss.analysis.model.util.EventType; import cz.cvut.kbss.analysis.model.util.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; @@ -24,6 +25,10 @@ public class FaultEvent extends Event { @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; diff --git a/src/main/java/cz/cvut/kbss/analysis/model/diagram/Rectangle.java b/src/main/java/cz/cvut/kbss/analysis/model/diagram/Rectangle.java new file mode 100644 index 00000000..50cc892a --- /dev/null +++ b/src/main/java/cz/cvut/kbss/analysis/model/diagram/Rectangle.java @@ -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 = -1.; + @OWLDataProperty(iri = Vocabulary.s_p_y) + private Double y = -1.; + + @OWLDataProperty(iri = Vocabulary.s_p_width) + private Double width = -1.; + @OWLDataProperty(iri = Vocabulary.s_p_height) + private Double height = -1.; + + 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 + + ']'; + } + +} From 3cca340133decb38b912adf12e732d3b18021450 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Tue, 2 Jan 2024 14:37:03 +0100 Subject: [PATCH 3/8] [kbss-cvut/fta-fmea-ui#131] Implement persistence of FaultEvent layout in FTA diagram. --- .../kbss/analysis/controller/FaultEventController.java | 9 +++++++++ .../java/cz/cvut/kbss/analysis/dao/FaultEventDao.java | 10 ++++++++++ .../analysis/service/FaultEventRepositoryService.java | 7 +++++++ 3 files changed, 26 insertions(+) diff --git a/src/main/java/cz/cvut/kbss/analysis/controller/FaultEventController.java b/src/main/java/cz/cvut/kbss/analysis/controller/FaultEventController.java index c955b4c8..ea107fd1 100755 --- a/src/main/java/cz/cvut/kbss/analysis/controller/FaultEventController.java +++ b/src/main/java/cz/cvut/kbss/analysis/controller/FaultEventController.java @@ -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; @@ -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) { diff --git a/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java b/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java index 5ba423cc..11a9902c 100755 --- a/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java +++ b/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java @@ -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; @@ -23,4 +25,12 @@ public boolean isChild(URI faultEventIri) { .getSingleResult(); } + public void update(Rectangle rect){ + try{ + em.persist(rect); + }catch (RuntimeException e){ + throw new PersistenceException(e); + } + } + } 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 7d862813..f5df4fd1 100755 --- a/src/main/java/cz/cvut/kbss/analysis/service/FaultEventRepositoryService.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/FaultEventRepositoryService.java @@ -9,6 +9,7 @@ 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.diagram.Rectangle; import cz.cvut.kbss.analysis.service.strategy.GateStrategyFactory; import cz.cvut.kbss.analysis.service.validation.FaultEventValidator; import lombok.extern.slf4j.Slf4j; @@ -136,6 +137,12 @@ public void updateChildrenSequence(URI faultEventUri, List 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()); From 17ecf96a26abf43a2b67bc1e9900e77ef2d56ee8 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Tue, 2 Jan 2024 14:50:42 +0100 Subject: [PATCH 4/8] [Refactor] Refactor FTA related enums - rename EventType to FtaEventType and move to model.fta package - move GateType to model.fta package --- .../cvut/kbss/analysis/model/FaultEvent.java | 7 +++---- .../EventType.java => fta/FtaEventType.java} | 4 ++-- .../analysis/model/{util => fta}/GateType.java | 2 +- .../service/FaultEventRepositoryService.java | 5 ++--- .../service/FaultTreeRepositoryService.java | 18 +++++++++--------- .../service/strategy/GateStrategyFactory.java | 2 +- .../service/util/FaultTreeTraversalUtils.java | 5 ++--- .../validation/FaultEventValidator.java | 8 ++++---- .../service/validation/FaultTreeValidator.java | 8 ++++---- .../kbss/analysis/dao/FaultEventDaoTest.java | 8 +++++--- .../kbss/analysis/dao/FaultTreeDaoTest.java | 12 ++++++------ .../validation/FaultEventValidatorTest.java | 13 ++++++------- 12 files changed, 45 insertions(+), 47 deletions(-) rename src/main/java/cz/cvut/kbss/analysis/model/{util/EventType.java => fta/FtaEventType.java} (54%) mode change 100755 => 100644 rename src/main/java/cz/cvut/kbss/analysis/model/{util => fta}/GateType.java (69%) mode change 100755 => 100644 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 019f61b6..a85717ec 100755 --- a/src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java +++ b/src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java @@ -1,13 +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.*; @@ -20,7 +19,7 @@ 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; diff --git a/src/main/java/cz/cvut/kbss/analysis/model/util/EventType.java b/src/main/java/cz/cvut/kbss/analysis/model/fta/FtaEventType.java old mode 100755 new mode 100644 similarity index 54% rename from src/main/java/cz/cvut/kbss/analysis/model/util/EventType.java rename to src/main/java/cz/cvut/kbss/analysis/model/fta/FtaEventType.java index 6facd10d..af04bec7 --- a/src/main/java/cz/cvut/kbss/analysis/model/util/EventType.java +++ b/src/main/java/cz/cvut/kbss/analysis/model/fta/FtaEventType.java @@ -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, diff --git a/src/main/java/cz/cvut/kbss/analysis/model/util/GateType.java b/src/main/java/cz/cvut/kbss/analysis/model/fta/GateType.java old mode 100755 new mode 100644 similarity index 69% rename from src/main/java/cz/cvut/kbss/analysis/model/util/GateType.java rename to src/main/java/cz/cvut/kbss/analysis/model/fta/GateType.java index bcb59f97..089d9e90 --- a/src/main/java/cz/cvut/kbss/analysis/model/util/GateType.java +++ b/src/main/java/cz/cvut/kbss/analysis/model/fta/GateType.java @@ -1,4 +1,4 @@ -package cz.cvut.kbss.analysis.model.util; +package cz.cvut.kbss.analysis.model.fta; public enum GateType { AND, 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 f5df4fd1..2835e482 100755 --- a/src/main/java/cz/cvut/kbss/analysis/service/FaultEventRepositoryService.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/FaultEventRepositoryService.java @@ -8,10 +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; @@ -68,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 childProbabilities = event.getChildren().stream() .map(this::propagateProbability).collect(Collectors.toList()); 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 e332735d..d0626e09 100755 --- a/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java @@ -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; @@ -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); @@ -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()) { @@ -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); @@ -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); @@ -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); @@ -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); } } diff --git a/src/main/java/cz/cvut/kbss/analysis/service/strategy/GateStrategyFactory.java b/src/main/java/cz/cvut/kbss/analysis/service/strategy/GateStrategyFactory.java index 2f1b84ec..f47f68bf 100755 --- a/src/main/java/cz/cvut/kbss/analysis/service/strategy/GateStrategyFactory.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/strategy/GateStrategyFactory.java @@ -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; diff --git a/src/main/java/cz/cvut/kbss/analysis/service/util/FaultTreeTraversalUtils.java b/src/main/java/cz/cvut/kbss/analysis/service/util/FaultTreeTraversalUtils.java index 41ccd9c4..26fb6c2f 100755 --- a/src/main/java/cz/cvut/kbss/analysis/service/util/FaultTreeTraversalUtils.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/util/FaultTreeTraversalUtils.java @@ -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; @@ -44,7 +43,7 @@ public static List 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); diff --git a/src/main/java/cz/cvut/kbss/analysis/service/validation/FaultEventValidator.java b/src/main/java/cz/cvut/kbss/analysis/service/validation/FaultEventValidator.java index e9bc87cf..b1c90d93 100755 --- a/src/main/java/cz/cvut/kbss/analysis/service/validation/FaultEventValidator.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/validation/FaultEventValidator.java @@ -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; @@ -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"); } } diff --git a/src/main/java/cz/cvut/kbss/analysis/service/validation/FaultTreeValidator.java b/src/main/java/cz/cvut/kbss/analysis/service/validation/FaultTreeValidator.java index 9496cb9d..55f08c09 100755 --- a/src/main/java/cz/cvut/kbss/analysis/service/validation/FaultTreeValidator.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/validation/FaultTreeValidator.java @@ -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; @@ -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"); } } diff --git a/src/test/java/cz/cvut/kbss/analysis/dao/FaultEventDaoTest.java b/src/test/java/cz/cvut/kbss/analysis/dao/FaultEventDaoTest.java index ce82a7bb..0e991720 100755 --- a/src/test/java/cz/cvut/kbss/analysis/dao/FaultEventDaoTest.java +++ b/src/test/java/cz/cvut/kbss/analysis/dao/FaultEventDaoTest.java @@ -4,6 +4,8 @@ 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.jopa.model.EntityManager; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -23,13 +25,13 @@ class FaultEventDaoTest extends BaseDaoTestRunner{ public void isChild_isChild_shouldReturnTrue() { FaultEvent parent = new FaultEvent(); parent.setName("parentEvent"); - parent.setEventType(EventType.INTERMEDIATE); + parent.setEventType(FtaEventType.INTERMEDIATE); parent.setGateType(GateType.AND); parent.setUri(Generator.generateUri()); FaultEvent child = new FaultEvent(); child.setName("childEvent"); - child.setEventType(EventType.BASIC); + child.setEventType(FtaEventType.BASIC); child.setGateType(GateType.UNUSED); child.setUri(Generator.generateUri()); @@ -47,7 +49,7 @@ public void isChild_isChild_shouldReturnTrue() { public void isChild_isNot_shouldReturnFalse() { FaultEvent notChild = new FaultEvent(); notChild.setName("event"); - notChild.setEventType(EventType.BASIC); + notChild.setEventType(FtaEventType.BASIC); notChild.setGateType(GateType.UNUSED); notChild.setUri(Generator.generateUri()); diff --git a/src/test/java/cz/cvut/kbss/analysis/dao/FaultTreeDaoTest.java b/src/test/java/cz/cvut/kbss/analysis/dao/FaultTreeDaoTest.java index d65b7eac..7c4f46bb 100755 --- a/src/test/java/cz/cvut/kbss/analysis/dao/FaultTreeDaoTest.java +++ b/src/test/java/cz/cvut/kbss/analysis/dao/FaultTreeDaoTest.java @@ -3,8 +3,8 @@ import cz.cvut.kbss.analysis.environment.Generator; 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.util.GateType; +import cz.cvut.kbss.analysis.model.fta.FtaEventType; +import cz.cvut.kbss.analysis.model.fta.GateType; import cz.cvut.kbss.jopa.model.EntityManager; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -35,7 +35,7 @@ public void isRootEvent_isRoot_shouldReturnTrue() { FaultEvent rootEvent = new FaultEvent(); rootEvent.setName("rootEvent"); - rootEvent.setEventType(EventType.INTERMEDIATE); + rootEvent.setEventType(FtaEventType.INTERMEDIATE); rootEvent.setGateType(GateType.AND); rootEvent.setUri(Generator.generateUri()); @@ -56,13 +56,13 @@ public void isRootEvent_isNot_shouldReturnFalse() { FaultEvent rootEvent = new FaultEvent(); rootEvent.setName("rootEvent"); - rootEvent.setEventType(EventType.INTERMEDIATE); + rootEvent.setEventType(FtaEventType.INTERMEDIATE); rootEvent.setGateType(GateType.AND); rootEvent.setUri(Generator.generateUri()); FaultEvent child = new FaultEvent(); child.setName("child"); - child.setEventType(EventType.BASIC); + child.setEventType(FtaEventType.BASIC); child.setGateType(GateType.UNUSED); child.setUri(Generator.generateUri()); @@ -142,7 +142,7 @@ public void symmetricBranches_shouldQueryAll() { private FaultEvent createEvent(String name) { FaultEvent event = new FaultEvent(); event.setName(name); - event.setEventType(EventType.INTERMEDIATE); + event.setEventType(FtaEventType.INTERMEDIATE); event.setGateType(GateType.AND); event.setUri(Generator.generateUri()); return event; diff --git a/src/test/java/cz/cvut/kbss/analysis/service/validation/FaultEventValidatorTest.java b/src/test/java/cz/cvut/kbss/analysis/service/validation/FaultEventValidatorTest.java index 89baac7a..a2fbc2f8 100755 --- a/src/test/java/cz/cvut/kbss/analysis/service/validation/FaultEventValidatorTest.java +++ b/src/test/java/cz/cvut/kbss/analysis/service/validation/FaultEventValidatorTest.java @@ -2,10 +2,9 @@ import cz.cvut.kbss.analysis.dao.FaultEventDao; import cz.cvut.kbss.analysis.environment.Generator; -import cz.cvut.kbss.analysis.exception.ValidationException; 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 org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -49,7 +48,7 @@ void validateDuplicates_duplicateExists_shouldReturnError() { @Test void validateDuplicates_noDuplicate_shouldJustRun() { FaultEvent event = new FaultEvent(); - event.setEventType(EventType.BASIC); + event.setEventType(FtaEventType.BASIC); event.setGateType(GateType.UNUSED); event.setName("Valid Name"); @@ -65,7 +64,7 @@ void validateDuplicates_noDuplicate_shouldJustRun() { void validateTypes_intermediate_nullGate_shouldReturnError() { FaultEvent event = new FaultEvent(); event.setUri(Generator.generateUri()); - event.setEventType(EventType.INTERMEDIATE); + event.setEventType(FtaEventType.INTERMEDIATE); BindingResult bindingResult = ValidationTestUtils.createBinding(event, faultEventValidator); faultEventValidator.validate(event, bindingResult); @@ -78,7 +77,7 @@ void validateTypes_intermediate_nullGate_shouldReturnError() { void validateTypes_intermediate_unusedGate_shouldReturnError() { FaultEvent event = new FaultEvent(); event.setUri(Generator.generateUri()); - event.setEventType(EventType.INTERMEDIATE); + event.setEventType(FtaEventType.INTERMEDIATE); event.setGateType(GateType.UNUSED); BindingResult bindingResult = ValidationTestUtils.createBinding(event, faultEventValidator); @@ -92,7 +91,7 @@ void validateTypes_intermediate_unusedGate_shouldReturnError() { void validateTypes_nonIntermediate_gateNotUnused_shouldReturnError() { FaultEvent event = new FaultEvent(); event.setUri(Generator.generateUri()); - event.setEventType(EventType.BASIC); + event.setEventType(FtaEventType.BASIC); event.setGateType(GateType.AND); BindingResult bindingResult = ValidationTestUtils.createBinding(event, faultEventValidator); From c1599b68c5c3bbbda77886485585ecdc88f5982b Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Tue, 2 Jan 2024 15:36:17 +0100 Subject: [PATCH 5/8] [kbss-cvut/fta-fmea-ui#131] Fix update rectangle --- src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java b/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java index 11a9902c..6ed90510 100755 --- a/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java +++ b/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java @@ -27,7 +27,7 @@ public boolean isChild(URI faultEventIri) { public void update(Rectangle rect){ try{ - em.persist(rect); + em.merge(rect); }catch (RuntimeException e){ throw new PersistenceException(e); } From 9b2185219ea587496bf207d50b536614797a3761 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Thu, 4 Jan 2024 22:10:14 +0100 Subject: [PATCH 6/8] [Fix] FaultEventDao.update(Rectangle) returns update rectangle --- src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java b/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java index 6ed90510..06fe37a7 100755 --- a/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java +++ b/src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java @@ -25,9 +25,9 @@ public boolean isChild(URI faultEventIri) { .getSingleResult(); } - public void update(Rectangle rect){ + public Rectangle update(Rectangle rect){ try{ - em.merge(rect); + return em.merge(rect); }catch (RuntimeException e){ throw new PersistenceException(e); } From f6dea5f07d595035ee816a6644945b8dffa7c9a7 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Thu, 4 Jan 2024 22:15:20 +0100 Subject: [PATCH 7/8] [kbss-cvut/fta-fmea-ui#131] Add FaultEventDaoTest.testUpdateRectangle --- .../kbss/analysis/dao/FaultEventDaoTest.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/test/java/cz/cvut/kbss/analysis/dao/FaultEventDaoTest.java b/src/test/java/cz/cvut/kbss/analysis/dao/FaultEventDaoTest.java index 0e991720..0cac5261 100755 --- a/src/test/java/cz/cvut/kbss/analysis/dao/FaultEventDaoTest.java +++ b/src/test/java/cz/cvut/kbss/analysis/dao/FaultEventDaoTest.java @@ -2,8 +2,7 @@ import cz.cvut.kbss.analysis.environment.Generator; 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.diagram.Rectangle; import cz.cvut.kbss.analysis.model.fta.FtaEventType; import cz.cvut.kbss.analysis.model.fta.GateType; import cz.cvut.kbss.jopa.model.EntityManager; @@ -60,4 +59,26 @@ public void isChild_isNot_shouldReturnFalse() { Assertions.assertFalse(result); } + @Test + void testUpdateRectangle(){ + Rectangle r = new Rectangle(1.,1.,2.,2.); + + transactional(() -> em.persist(r)); + + double newVal = 10.; + + transactional(() -> { + Rectangle r1 = new Rectangle(); + r1.setUri(r.getUri()); + r1.setX(newVal); + r1.setY(r.getY()); + r1.setWidth(r.getWidth()); + r1.setHeight(r.getHeight()); + faultEventDao.update(r1); + }); + + Rectangle r1 = em.find(Rectangle.class, r.getUri()); + Assertions.assertEquals(r1.getX(), newVal); + } + } \ No newline at end of file From 4f618b569569b18a74f2d166b84dce6dce2bdaef Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Thu, 4 Jan 2024 23:07:22 +0100 Subject: [PATCH 8/8] [Update] Do not initialize coordinate and dimensions of Rectangle --- .../cz/cvut/kbss/analysis/model/diagram/Rectangle.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/cz/cvut/kbss/analysis/model/diagram/Rectangle.java b/src/main/java/cz/cvut/kbss/analysis/model/diagram/Rectangle.java index 50cc892a..9ad191cd 100644 --- a/src/main/java/cz/cvut/kbss/analysis/model/diagram/Rectangle.java +++ b/src/main/java/cz/cvut/kbss/analysis/model/diagram/Rectangle.java @@ -20,14 +20,14 @@ public class Rectangle { private URI uri; @OWLDataProperty(iri = Vocabulary.s_p_x) - private Double x = -1.; + private Double x; @OWLDataProperty(iri = Vocabulary.s_p_y) - private Double y = -1.; + private Double y; @OWLDataProperty(iri = Vocabulary.s_p_width) - private Double width = -1.; + private Double width; @OWLDataProperty(iri = Vocabulary.s_p_height) - private Double height = -1.; + private Double height; public Rectangle() { }