-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactor for kbss-cvut/fta-fmea-ui#390] Move findWithDetails to new …
…FaultTreeService to enable transactions defined by transactional annotation - seems to contribute fixing an issue with loading fault tree details
- Loading branch information
Showing
3 changed files
with
86 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/main/java/cz/cvut/kbss/analysis/service/FaultTreeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package cz.cvut.kbss.analysis.service; | ||
|
||
import cz.cvut.kbss.analysis.dao.FailureModeDao; | ||
import cz.cvut.kbss.analysis.dao.FaultTreeDao; | ||
import cz.cvut.kbss.analysis.model.Event; | ||
import cz.cvut.kbss.analysis.model.FaultEvent; | ||
import cz.cvut.kbss.analysis.model.FaultTree; | ||
import cz.cvut.kbss.analysis.model.Item; | ||
import cz.cvut.kbss.analysis.service.util.Pair; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.net.URI; | ||
import java.util.Collection; | ||
import java.util.Optional; | ||
import java.util.Stack; | ||
|
||
@Service | ||
@Slf4j | ||
public class FaultTreeService{ | ||
|
||
private final FaultEventRepositoryService faultEventRepositoryService; | ||
private final FailureModeDao failureModeDao; | ||
private final FaultTreeRepositoryService faultTreeRepositoryService; | ||
private final FaultTreeDao faultTreeDao; | ||
|
||
public FaultTreeService(FaultEventRepositoryService faultEventRepositoryService, FailureModeDao failureModeDao, FaultTreeRepositoryService faultTreeRepositoryService, FaultTreeDao faultTreeDao) { | ||
this.faultEventRepositoryService = faultEventRepositoryService; | ||
this.failureModeDao = failureModeDao; | ||
this.faultTreeRepositoryService = faultTreeRepositoryService; | ||
this.faultTreeDao = faultTreeDao; | ||
} | ||
|
||
public FaultTree findWithDetails(URI id) { | ||
FaultTree ft = faultTreeRepositoryService.findRequired(id); | ||
Collection<Event> events = faultTreeDao.getRelatedEventTypes(ft); | ||
setRelatedBehaviors(events); | ||
|
||
events.stream().map(e -> e.getBehavior()).forEach(b -> { | ||
Item item = b.getItem(); | ||
if(item == null) | ||
return; | ||
|
||
item.setComponents(null); | ||
Optional.ofNullable(item.getSupertypes()).ifPresent(s -> s.forEach(st -> st.setComponents(null))); | ||
}); | ||
|
||
setReferences(ft); | ||
|
||
FaultTree summary = faultTreeRepositoryService.findSummary(ft.getUri()); | ||
ft.setOperationalDataFilter(summary.getOperationalDataFilter()); | ||
ft.setSystem(summary.getSystem()); | ||
ft.setSubsystem(summary.getSubsystem()); | ||
|
||
return ft; | ||
} | ||
|
||
protected void setReferences(FaultTree faultTree){ | ||
if(faultTree.getManifestingEvent() == null) | ||
return; | ||
|
||
Stack<Pair<URI, FaultEvent>> stack = new Stack<>(); | ||
stack.add(Pair.of(null,faultTree.getManifestingEvent())); | ||
while(!stack.isEmpty()){ | ||
Pair<URI,FaultEvent> p = stack.pop(); | ||
FaultEvent fe = p.getSecond(); | ||
faultEventRepositoryService.setExternalReference(p.getFirst(), fe); | ||
if(fe.getChildren() == null) | ||
continue; | ||
fe.getChildren().forEach(c -> stack.push(Pair.of(fe.getUri(), c))); | ||
} | ||
} | ||
|
||
protected void setRelatedBehaviors(Collection<Event> events){ | ||
for(Event event : events){ | ||
if(event.getBehavior() == null) | ||
event.setBehavior(failureModeDao.findByEvent(event.getUri())); | ||
} | ||
} | ||
} |