Skip to content

Commit

Permalink
Merge pull request #147 from kbss-cvut/fix/fta-fmea-ui-544-improve-ft…
Browse files Browse the repository at this point in the history
…-evaluation-error-message

Improve fault tree evaluation error message when leaf nodes are missing probability
  • Loading branch information
blcham authored Aug 11, 2024
2 parents f9a4120 + fe6097e commit 7fe0f97
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cz.cvut.kbss.analysis.controller.util;

import cz.cvut.kbss.analysis.dto.error.ErrorInfo;
import cz.cvut.kbss.analysis.exception.CalculationException;
import cz.cvut.kbss.analysis.exception.EntityNotFoundException;
import cz.cvut.kbss.analysis.exception.LogicViolationException;
import cz.cvut.kbss.analysis.exception.ValidationException;
Expand Down Expand Up @@ -53,4 +54,10 @@ public ErrorInfo handleValidationException(HttpServletRequest request, Validatio
return new ErrorInfo(errorMessage, request.getRequestURI());
}

@ExceptionHandler(CalculationException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ErrorInfo handleEvaluationException(HttpServletRequest request, CalculationException e) {
log.warn("> handleEvaluationException - {}", request.getRequestURI());
return new ErrorInfo(e.getMessage(), request.getRequestURI());
}
}
5 changes: 5 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ public Set<FaultEvent> getAllEventParts(){
return result;
}

public boolean isLeafEvent(){
return getEventType() == FtaEventType.BASIC || getChildren() == null || getChildren().isEmpty();
}


@Override
public String toString() {
return "FaultEvent <" + getUri() + "/>";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cz.cvut.kbss.analysis.model.fta;

import cz.cvut.kbss.analysis.exception.CalculationException;
import cz.cvut.kbss.analysis.model.FaultEvent;
import cz.cvut.kbss.analysis.model.FaultEventScenario;
import cz.cvut.kbss.analysis.model.FaultTree;
Expand Down Expand Up @@ -27,6 +28,17 @@ public class FTAMinimalCutSetEvaluation {
* @param faultTree
*/
public void evaluate(FaultTree faultTree){
List<FaultEvent> fe = faultTree.getAllEvents().stream()
.filter(e -> e.isLeafEvent())
.filter(e -> e.getProbability() == null)
.toList();
if(!fe.isEmpty()){
String message =
fe.stream().map(e -> "'%s'".formatted(e.getName()))
.collect(Collectors.joining("\n" , "The following leaf events do not have specified probability: [\n", "]"));

throw new CalculationException(message);
}
minScenarios = null;
evaluate(faultTree.getManifestingEvent());

Expand All @@ -44,7 +56,7 @@ public void evaluate(FaultTree faultTree){
* @return a pair where left is true if faultEvent contains dependent events, false otherwise. Right contains the set of all basic events in the subtree of faultEvent.
*/
public Pair<Boolean, Set<FaultEvent>> evaluate(FaultEvent faultEvent){
if(faultEvent.getEventType() == FtaEventType.BASIC || faultEvent.getChildren() == null || faultEvent.getChildren().isEmpty())
if(faultEvent.isLeafEvent())
return Pair.of(false, Collections.singleton(faultEvent));

List<Pair<Boolean, Set<FaultEvent>>> l = faultEvent.getChildren().stream().map(this::evaluate).collect(Collectors.toList());// RECURSION !for()
Expand Down

0 comments on commit 7fe0f97

Please sign in to comment.