Skip to content

Commit

Permalink
[Fix kbss-cvut/fta-fmea-ui#374] Update API fetching list of reusable…
Browse files Browse the repository at this point in the history
… event types for creating fault events in fault tree to take fault tree uri as argument. Exclude root node type from the list.

 -
  • Loading branch information
kostobog committed Jun 9, 2024
1 parent e3fc3eb commit 8c0dea9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ public List<FaultEventType> getTopFaultEvents(@PathVariable String systemFragmen
return repositoryService.getTopFaultEvents(systemUri);
}

@GetMapping(value = "/all-fault-events/{systemFragment}", produces = {MediaType.APPLICATION_JSON_VALUE, JsonLd.MEDIA_TYPE})
public List<FaultEventType> getAllFaultEvents(@PathVariable String systemFragment){
log.info("> getFaultEventTypes - {}", systemFragment);
URI systemUri = identifierService.composeIdentifier(Vocabulary.s_c_system, systemFragment);
@GetMapping(value = "/all-fault-events/{faultTreeFragment}", produces = {MediaType.APPLICATION_JSON_VALUE, JsonLd.MEDIA_TYPE})
public List<FaultEventType> getAllFaultEvents(@PathVariable String faultTreeFragment){
log.info("> getFaultEventTypes - {}", faultTreeFragment);
URI systemUri = identifierService.composeIdentifier(Vocabulary.s_c_fault_tree, faultTreeFragment);
return repositoryService.getAllFaultEvents(systemUri);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,16 @@ protected void setChange(FaultEvent instance){
public List<FaultEventType> getTopFaultEvents(URI systemUri) {
return faultEventDao.getTopFaultEvents(systemUri);
}
public List<FaultEventType> getAllFaultEvents(URI systemUri) {
return faultEventDao.getAllFaultEvents(systemUri);

public List<FaultEventType> getAllFaultEvents(URI faultTreeUri) {
FaultTree ftSummary = faultTreeDao.findSummary(faultTreeUri);
List<FaultEventType> ret = faultEventDao.getAllFaultEvents(ftSummary.getSystem().getUri());
Set<URI> typesToRemove = Optional.ofNullable(ftSummary.getManifestingEvent()).map(r -> r.getSupertypes())
.filter(s -> s !=null && !s.isEmpty())
.map(s -> s.stream().map(t -> t.getUri()).collect(Collectors.toSet()))
.orElse(null);
return typesToRemove != null
? ret.stream().filter(t -> !typesToRemove.contains(t.getUri())).toList()
: ret;
}
}

0 comments on commit 8c0dea9

Please sign in to comment.