Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/fta fmea UI 150 fault event update not persisted #56

Merged
merged 4 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public FaultTree find(@PathVariable(name = "faultTreeFragment") String faultTree
@PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, JsonLd.MEDIA_TYPE})
public FaultTree create(@RequestBody FaultTree faultTree) {
log.info("> create - {}", faultTree);
repositoryService.persist(faultTree);
repositoryService.createTree(faultTree);
return faultTree;
}

Expand Down
13 changes: 11 additions & 2 deletions src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
@Setter
public class FaultEvent extends Event {

/**
* Use this factory method to create a FaultEvent with a rectangle. Rectangle cannot be initialized because it will cause
blcham marked this conversation as resolved.
Show resolved Hide resolved
* @return returns a new FaultEvent instance with initialized FaultEvent.rectangle field containing a new Rectangle instance.
*/
public static FaultEvent create(){
FaultEvent faultEvent = new FaultEvent();
faultEvent.setRectangle(new Rectangle());
return faultEvent;
}

@NotNull(message = "EventType must be defined")
@ParticipationConstraints(nonEmpty = true)
@OWLDataProperty(iri = Vocabulary.s_p_hasFaultEventType)
Expand All @@ -24,9 +34,8 @@ 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();
private Rectangle rectangle;

@OWLDataProperty(iri = Vocabulary.s_p_hasProbability)
private Double probability;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ protected void preRemove(FaultEvent instance) {
public FaultEvent addInputEvent(URI eventUri, FaultEvent inputEvent) {
FaultEvent currentEvent = findRequired(eventUri);

if(inputEvent.getUri() == null && inputEvent.getRectangle() == null)
inputEvent.setRectangle(new Rectangle());

currentEvent.addChild(inputEvent);
update(currentEvent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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.diagram.Rectangle;
import cz.cvut.kbss.analysis.model.fta.FtaEventType;
import cz.cvut.kbss.analysis.model.fta.GateType;
import cz.cvut.kbss.analysis.service.util.FaultTreeTraversalUtils;
Expand Down Expand Up @@ -49,6 +50,14 @@ protected GenericDao<FaultTree> getPrimaryDao() {
return faultTreeDao;
}

@Transactional
public void createTree(FaultTree faultTree){
if(faultTree.getManifestingEvent() != null){
faultTree.getManifestingEvent().setRectangle(new Rectangle());
}
persist(faultTree);
}

@Transactional
public FaultTree findWithPropagation(URI faultTreeUri) {
log.info("> findWithPropagation - {}", faultTreeUri);
Expand Down Expand Up @@ -183,7 +192,7 @@ public FaultTree generateFunctionDependencyTree(URI functionUri, String faultTre
faultEvent.setEventType(FtaEventType.INTERMEDIATE);
}
cleanTreeGeneration();
persist(faultTree);
createTree(faultTree);
return faultTree;
}

Expand Down Expand Up @@ -229,7 +238,8 @@ private FaultEvent transferBehaviorToFaultEvent(Behavior behavior, FaultEvent pa
} else if(faultEventRepositoryService.existsInContext(faultEventUri2)){
return faultEventRepositoryService.findRequired(faultEventUri2);
} else {
FaultEvent faultEvent = new FaultEvent();
FaultEvent faultEvent = FaultEvent.create();

faultEvent.setUri(faultEventUri);
faultEvent.setBehavior(behavior);

Expand Down Expand Up @@ -271,7 +281,7 @@ private FaultEvent processImpairingBehavior(Behavior impairingBehavior, FaultEve
}else if(faultEventRepositoryService.existsInContext(faultEventUriTypeEvent)){
faultEvent = faultEventRepositoryService.findRequired(faultEventUriTypeEvent);
}else {
faultEvent = new FaultEvent();
faultEvent = FaultEvent.create();
faultEvent.setUri(faultEventUri);
faultEvent.setBehavior(impairingBehavior);
if(impairingBehavior.getBehaviorType() == BehaviorType.AtomicBehavior){
Expand All @@ -289,7 +299,7 @@ private FaultEvent processImpairingBehavior(Behavior impairingBehavior, FaultEve
for (Behavior behaviorChild : impairingBehavior.getChildBehaviors()) {
if(behaviorChild.isFailureModeCause()) continue;

FaultEvent faultEventChild = new FaultEvent();
FaultEvent faultEventChild = FaultEvent.create();
faultEventChild.setBehavior(behaviorChild);
faultEventUri = createUri(behaviorChild, faultEvent, "e");
if (faultEventRepositoryService.existsInContext(faultEventUri)) {
Expand All @@ -299,7 +309,7 @@ private FaultEvent processImpairingBehavior(Behavior impairingBehavior, FaultEve
faultEventChild.setBehavior(behaviorChild);
faultEventChild.setName(behaviorChild.getName() + " event");
faultEventChild.setEventType(FtaEventType.BASIC);
faultEventChild.setGateType(GateType.UNUSED);
faultEventChild.setGateType(null);
faultEventChild.setProbability(1.);
faultEventRepositoryService.persist(faultEventChild);
}
Expand All @@ -320,7 +330,7 @@ private void processChildBehaviors(Behavior behavior,FaultEvent parentFaultEvent
if (faultEventRepositoryService.existsInContext(faultEventUri)) {
faultEvent = faultEventRepositoryService.findRequired(faultEventUri);
} else {
faultEvent = new FaultEvent();
faultEvent = FaultEvent.create();
faultEvent.setBehavior(behavior);
faultEvent.setName(behavior.getName() + " fails b/c its parts fail");
faultEvent.setEventType(FtaEventType.INTERMEDIATE);
Expand All @@ -333,7 +343,7 @@ private void processChildBehaviors(Behavior behavior,FaultEvent parentFaultEvent
for (Behavior behaviorChild : behavior.getChildBehaviors()) {
if(isVisited(behaviorChild))
continue;
FaultEvent fEvent = new FaultEvent();
FaultEvent fEvent = FaultEvent.create();
faultEventUri = createUri(behaviorChild, faultEvent, "");
if (faultEventRepositoryService.existsInContext(faultEventUri)) {
fEvent = faultEventRepositoryService.findRequired(faultEventUri);
Expand Down Expand Up @@ -384,7 +394,7 @@ private void setFaultEventTypes(Behavior behaviorChild, FaultEvent fEvent) {
private void setFaultEventTypes(boolean isBasic, FaultEvent fEvent){
if(isBasic){
fEvent.setEventType(FtaEventType.BASIC);
fEvent.setGateType(GateType.UNUSED);
fEvent.setGateType(null);
fEvent.setProbability(1.);
}else{
fEvent.setEventType(FtaEventType.INTERMEDIATE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void validate(Object target, Errors errors) {
errors.rejectValue("gateType", "gateType.invalid");
}

if (instance.getEventType() != FtaEventType.INTERMEDIATE && instance.getGateType() != GateType.UNUSED) {
if (instance.getEventType() != FtaEventType.INTERMEDIATE && (instance.getGateType() != null && instance.getGateType() != GateType.UNUSED)) {
errors.rejectValue("gateType", "gateType.invalid");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void validate(Object target, Errors errors) {
errors.rejectValue("gateType", "gateType.invalid");
}

if (instance.getEventType() != FtaEventType.INTERMEDIATE && instance.getGateType() != GateType.UNUSED) {
if (instance.getEventType() != FtaEventType.INTERMEDIATE && (instance.getGateType() != null || instance.getGateType() != GateType.UNUSED)) {
errors.rejectValue("gateType", "gateType.invalid");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public void isChild_isChild_shouldReturnTrue() {
FaultEvent child = new FaultEvent();
child.setName("childEvent");
child.setEventType(FtaEventType.BASIC);
child.setGateType(GateType.UNUSED);
child.setUri(Generator.generateUri());

parent.addChild(child);
Expand All @@ -49,7 +48,6 @@ public void isChild_isNot_shouldReturnFalse() {
FaultEvent notChild = new FaultEvent();
notChild.setName("event");
notChild.setEventType(FtaEventType.BASIC);
notChild.setGateType(GateType.UNUSED);
notChild.setUri(Generator.generateUri());

transactional(() -> em.persist(notChild));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public void isRootEvent_isNot_shouldReturnFalse() {
FaultEvent child = new FaultEvent();
child.setName("child");
child.setEventType(FtaEventType.BASIC);
child.setGateType(GateType.UNUSED);
child.setUri(Generator.generateUri());

rootEvent.addChild(child);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ void validateDuplicates_duplicateExists_shouldReturnError() {
void validateDuplicates_noDuplicate_shouldJustRun() {
FaultEvent event = new FaultEvent();
event.setEventType(FtaEventType.BASIC);
event.setGateType(GateType.UNUSED);
event.setName("Valid Name");

Mockito.when(faultEventDao.existsWithPredicate(Vocabulary.s_p_hasName, event.getName())).thenReturn(false);
Expand Down Expand Up @@ -78,7 +77,7 @@ void validateTypes_intermediate_unusedGate_shouldReturnError() {
FaultEvent event = new FaultEvent();
event.setUri(Generator.generateUri());
event.setEventType(FtaEventType.INTERMEDIATE);
event.setGateType(GateType.UNUSED);
event.setGateType(null);

BindingResult bindingResult = ValidationTestUtils.createBinding(event, faultEventValidator);
faultEventValidator.validate(event, bindingResult);
Expand Down
Loading