-
Notifications
You must be signed in to change notification settings - Fork 0
Delete an execution #27
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
Changes from all commits
0748f14
8e66fdf
6180444
b07dc08
f6f7dba
609ee92
a07f70c
5a26cc7
a180a83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,6 @@ | |
| */ | ||
| package org.gridsuite.monitor.server.services; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.gridsuite.monitor.commons.ProcessConfig; | ||
| import org.gridsuite.monitor.commons.ProcessExecutionStep; | ||
| import org.gridsuite.monitor.commons.ProcessStatus; | ||
|
|
@@ -23,6 +22,7 @@ | |
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
|
|
@@ -31,14 +31,23 @@ | |
| * @author Antoine Bouhours <antoine.bouhours at rte-france.com> | ||
| */ | ||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class MonitorService { | ||
|
|
||
| private final ProcessExecutionRepository executionRepository; | ||
| private final NotificationService notificationService; | ||
| private final ReportService reportService; | ||
| private final ResultService resultService; | ||
|
|
||
| public MonitorService(ProcessExecutionRepository executionRepository, | ||
| NotificationService notificationService, | ||
| ReportService reportService, | ||
| ResultService resultService) { | ||
| this.executionRepository = executionRepository; | ||
| this.notificationService = notificationService; | ||
| this.reportService = reportService; | ||
| this.resultService = resultService; | ||
| } | ||
|
|
||
| @Transactional | ||
| public UUID executeProcess(UUID caseUuid, String userId, ProcessConfig processConfig) { | ||
| ProcessExecutionEntity execution = ProcessExecutionEntity.builder() | ||
|
|
@@ -180,4 +189,29 @@ public Optional<List<ProcessExecutionStep>> getStepsInfos(UUID executionId) { | |
| return Optional.empty(); | ||
| } | ||
| } | ||
|
|
||
| @Transactional | ||
| public boolean deleteExecution(UUID executionId) { | ||
| List<ResultInfos> resultIds = new ArrayList<>(); | ||
| List<UUID> reportIds = new ArrayList<>(); | ||
|
|
||
| Optional<ProcessExecutionEntity> executionEntity = executionRepository.findById(executionId); | ||
| if (executionEntity.isPresent()) { | ||
| Optional.ofNullable(executionEntity.get().getSteps()).orElse(List.of()).forEach(step -> { | ||
| if (step.getResultId() != null && step.getResultType() != null) { | ||
|
Comment on lines
+200
to
+201
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you choose to rely on Optional to check for null values here, you must ensure that the same checks are applied consistently throughout the codebase. In fact, Hibernate always initializes a collection when loading a relationship of a collection type. However, to be extra safe, we can explicitly initialize an empty ArrayList in the parent entity, i.e. ProcessExecutionEntity |
||
| resultIds.add(new ResultInfos(step.getResultId(), step.getResultType())); | ||
| } | ||
| if (step.getReportId() != null) { | ||
| reportIds.add(step.getReportId()); | ||
| } | ||
| }); | ||
| resultIds.forEach(resultService::deleteResult); | ||
| reportIds.forEach(reportService::deleteReport); | ||
|
|
||
| executionRepository.deleteById(executionId); | ||
|
|
||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.