Skip to content

Commit

Permalink
[Fix partially kbss-cvut/fta-fmea-ui#428] Implement service layer log…
Browse files Browse the repository at this point in the history
…ic to support FaultTree.status

- update status on filter update
- infer status when not present from system and fault tree filter
  • Loading branch information
kostobog committed Jun 26, 2024
1 parent 88cc67a commit e46936e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cz.cvut.kbss.analysis.controller;

import cz.cvut.kbss.analysis.model.opdata.OperationalDataFilter;
import cz.cvut.kbss.analysis.service.FaultTreeService;
import cz.cvut.kbss.analysis.service.IdentifierService;
import cz.cvut.kbss.analysis.service.OperationalDataFilterService;
import cz.cvut.kbss.analysis.service.external.OperationalDataService;
Expand All @@ -22,11 +23,13 @@ public class OperationalDataFilterController {
private final OperationalDataFilterService filterService;
private final IdentifierService identifierService;
private final OperationalDataService operationalDataService;
private final FaultTreeService faultTreeService;

public OperationalDataFilterController(OperationalDataFilterService filterService, IdentifierService identifierService, OperationalDataService operationalDataService) {
public OperationalDataFilterController(OperationalDataFilterService filterService, IdentifierService identifierService, OperationalDataService operationalDataService, FaultTreeService faultTreeService) {
this.filterService = filterService;
this.identifierService = identifierService;
this.operationalDataService = operationalDataService;
this.faultTreeService = faultTreeService;
}

@PutMapping(path="reset", produces = {JsonLd.MEDIA_TYPE, MediaType.APPLICATION_JSON_VALUE})
Expand All @@ -47,7 +50,7 @@ public void updateSystemFilter(@PathVariable(name = "systemFragment") String sys
public void updateFaultTreeFilter(@PathVariable(name = "faultTreeFragment") String faultTreeFragment, @RequestBody OperationalDataFilter filter){
log.info("> updateFaultTreeFilter - {} to {}", faultTreeFragment, filter);
URI faultTreeUri = identifierService.composeIdentifier(Vocabulary.s_c_fault_tree, faultTreeFragment);
filterService.updateFaultTreeFilter(faultTreeUri, filter);
faultTreeService.updateFilter(faultTreeUri, filter);
}

@GetMapping(value = "/check-service", produces = {MediaType.TEXT_PLAIN_VALUE})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cz.cvut.kbss.analysis.dao.*;
import cz.cvut.kbss.analysis.exception.EntityNotFoundException;
import cz.cvut.kbss.analysis.model.*;
import cz.cvut.kbss.analysis.model.System;
import cz.cvut.kbss.analysis.model.ava.ATASystem;
import cz.cvut.kbss.analysis.model.ava.FHAEventType;
import cz.cvut.kbss.analysis.model.diagram.Rectangle;
Expand Down Expand Up @@ -46,6 +47,8 @@ public class FaultTreeRepositoryService extends ComplexManagedEntityRepositorySe
private final OperationalDataService operationalDataService;
private final FaultEventTypeService faultEventTypeService;
private final FailureRateEstimateDao failureRateEstimateDao;
private final SystemDao systemDao;
private final SystemRepositoryService systemRepositoryService;

@Autowired
public FaultTreeRepositoryService(@Qualifier("defaultValidator") Validator validator,
Expand All @@ -60,7 +63,7 @@ public FaultTreeRepositoryService(@Qualifier("defaultValidator") Validator valid
OperationalDataFilterService operationalDataFilterService,
OperationalDataService operationalDataService,
FaultEventTypeService faultEventTypeService,
FailureRateEstimateDao failureRateEstimateDao) {
FailureRateEstimateDao failureRateEstimateDao, SystemDao systemDao, SystemRepositoryService systemRepositoryService) {
super(validator, userDao, securityUtils);
this.faultTreeDao = faultTreeDao;
this.faultEventScenarioDao = faultEventScenarioDao;
Expand All @@ -72,6 +75,8 @@ public FaultTreeRepositoryService(@Qualifier("defaultValidator") Validator valid
this.operationalDataService = operationalDataService;
this.faultEventTypeService = faultEventTypeService;
this.failureRateEstimateDao = failureRateEstimateDao;
this.systemDao = systemDao;
this.systemRepositoryService = systemRepositoryService;
}

@Override
Expand Down Expand Up @@ -115,11 +120,20 @@ public FaultTree findSummary(URI faultTreeUri){
@Override
public List<FaultTree> findAllSummaries(){
List<FaultTree> summaries = super.findAllSummaries();
Map<URI, System> systemMap = new HashMap<>();
for(FaultTree faultTreeSummary: summaries){
OperationalDataFilter filter = operationalDataFilterService.getFaultTreeFilter(
faultTreeSummary.getUri(),
faultTreeSummary.getSystem().getUri());
faultTreeSummary.setOperationalDataFilter(filter);
if(faultTreeSummary.getSystem().getUri() == null)
continue;
System system = systemMap.computeIfAbsent(
faultTreeSummary.getSystem().getUri(),
uri -> systemRepositoryService.findAllSummary(uri)
);
faultTreeSummary.setSystem(system);
setInferStatus(faultTreeSummary);
}
return summaries;
}
Expand All @@ -138,6 +152,18 @@ public FaultTree findWithPropagation(URI faultTreeUri) {
return faultTree;
}

public void setInferStatus(FaultTree faultTree){
if(faultTree.getStatus() == null)
faultTree.setStatus(getInferedStatus(faultTree));
}

public Status getInferedStatus(FaultTree faultTree ){
return !((System)faultTree.getSystem()).getOperationalDataFilter().getMinOperationalHours()
.equals(faultTree.getOperationalDataFilter().getMinOperationalHours())
? Status.outOfSync
: Status.ok;
}

public FaultTree update(FaultTree instance) {
if(instance.getManifestingEvent() == null && instance.getUri() != null){
FaultTree managedInstance = getPrimaryDao().find(instance.getUri()).orElse(null);
Expand Down
26 changes: 20 additions & 6 deletions src/main/java/cz/cvut/kbss/analysis/service/FaultTreeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

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.model.*;
import cz.cvut.kbss.analysis.model.opdata.OperationalDataFilter;
import cz.cvut.kbss.analysis.service.util.Pair;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -23,12 +21,16 @@ public class FaultTreeService{
private final FailureModeDao failureModeDao;
private final FaultTreeRepositoryService faultTreeRepositoryService;
private final FaultTreeDao faultTreeDao;
private final OperationalDataFilterService operationalDataFilterService;
private final SystemRepositoryService systemRepositoryService;

public FaultTreeService(FaultEventRepositoryService faultEventRepositoryService, FailureModeDao failureModeDao, FaultTreeRepositoryService faultTreeRepositoryService, FaultTreeDao faultTreeDao) {
public FaultTreeService(FaultEventRepositoryService faultEventRepositoryService, FailureModeDao failureModeDao, FaultTreeRepositoryService faultTreeRepositoryService, FaultTreeDao faultTreeDao, OperationalDataFilterService operationalDataFilterService, SystemRepositoryService systemRepositoryService) {
this.faultEventRepositoryService = faultEventRepositoryService;
this.failureModeDao = failureModeDao;
this.faultTreeRepositoryService = faultTreeRepositoryService;
this.faultTreeDao = faultTreeDao;
this.operationalDataFilterService = operationalDataFilterService;
this.systemRepositoryService = systemRepositoryService;
}

public FaultTree findWithDetails(URI id) {
Expand All @@ -49,8 +51,12 @@ public FaultTree findWithDetails(URI id) {

FaultTree summary = faultTreeRepositoryService.findSummary(ft.getUri());
ft.setOperationalDataFilter(summary.getOperationalDataFilter());
ft.setSystem(summary.getSystem());
ft.setSystem(Optional.ofNullable(summary).map(s -> s.getSystem()).map(s -> s.getUri())
.map(u -> systemRepositoryService.findAllSummary(u)).orElse( null)
);
ft.setSubsystem(summary.getSubsystem());
if(ft.getSystem() != null)
faultTreeRepositoryService.setInferStatus(ft);

return ft;
}
Expand All @@ -77,4 +83,12 @@ protected void setRelatedBehaviors(Collection<Event> events){
event.setBehavior(failureModeDao.findByEvent(event.getUri()));
}
}

public void updateFilter(URI faultTreeURI, OperationalDataFilter newFilter){
FaultTree summary = faultTreeRepositoryService.findSummary(faultTreeURI);
operationalDataFilterService.updateFaultTreeFilter(faultTreeURI, newFilter);
summary.setOperationalDataFilter(newFilter);
Status status = faultTreeRepositoryService.getInferedStatus(summary);
faultTreeDao.updateStatus(summary.getUri(), status);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@ public class OperationalDataFilterService extends BaseRepositoryService<Operatio

private final OperationalDataConfig defaultFilter;
private final OperationalDataFilterDao filterDao;
private final OperationalDataFilter globalFilter;

public OperationalDataFilterService(OperationalDataConfig defaultFilter, OperationalDataFilterDao filterDao) {
super(null);
this.defaultFilter = defaultFilter;
this.filterDao = filterDao;
globalFilter = new OperationalDataFilter();
globalFilter.setMinOperationalHours(defaultFilter.getMinOperationalHours());
}

/**
*
* @return default global filter configured by deployment parameters
*/
public OperationalDataFilter getDefaultGlobalFilter(){
OperationalDataFilter filter = new OperationalDataFilter();
filter.setMinOperationalHours(defaultFilter.getMinOperationalHours());
return filter;
return globalFilter;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,22 @@ public void importDocument(URI systemURI, URI contextIRI) {
@Transactional(readOnly = true)
public List<System> findAllSummaries(){
List<System> systems = ((SystemDao)getPrimaryDao()).findAllSummaries();
OperationalDataFilter globalFilter = operationalDataFilterService.getDefaultGlobalFilter();
for(System system : systems){
OperationalDataFilter filter = operationalDataFilterService.getSystemFilter(system.getUri());
system.setOperationalDataFilter(filter);
system.setGlobalOperationalDataFilter(globalFilter);
}
for(System system : systems)
setOperationalDataFilter(system);
return systems;
}

@Transactional(readOnly = true)
public System findAllSummary(URI systemUri){
System system = ((SystemDao)getPrimaryDao()).findSummary(systemUri);
setOperationalDataFilter(system);
return system;
}

protected void setOperationalDataFilter(System system) {
OperationalDataFilter filter = operationalDataFilterService.getSystemFilter(system.getUri());
system.setOperationalDataFilter(filter);
system.setGlobalOperationalDataFilter(operationalDataFilterService.getDefaultGlobalFilter());
}

}

0 comments on commit e46936e

Please sign in to comment.