Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

/**
Expand Down Expand Up @@ -50,26 +49,23 @@ public ResponseEntity<UUID> executeProcess(
@Parameter(description = "Process config uuid") @RequestParam(name = "processConfigUuid") UUID processConfigUuid,
@RequestParam(required = false, defaultValue = "false") boolean isDebug,
@RequestHeader(HEADER_USER_ID) String userId) {
Optional<UUID> executionId = processExecutionService.executeProcess(caseUuid, userId, processConfigUuid, isDebug);
return executionId.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
return ResponseEntity.ok(processExecutionService.executeProcess(caseUuid, userId, processConfigUuid, isDebug));
}

@GetMapping("/executions/{executionId}/reports")
@Operation(summary = "Get reports for an execution")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The execution reports"),
@ApiResponse(responseCode = "404", description = "execution id was not found")})
public ResponseEntity<ReportPage> getExecutionReports(@Parameter(description = "Execution UUID") @PathVariable UUID executionId) {
Optional<ReportPage> reports = processExecutionService.getReports(executionId);
return reports.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
return ResponseEntity.ok(processExecutionService.getReports(executionId));
}

@GetMapping("/executions/{executionId}/results")
@Operation(summary = "Get results for an execution")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The execution results"),
@ApiResponse(responseCode = "404", description = "execution id was not found")})
public ResponseEntity<List<String>> getExecutionResults(@Parameter(description = "Execution UUID") @PathVariable UUID executionId) {
Optional<List<String>> results = processExecutionService.getResults(executionId);
return results.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
return ResponseEntity.ok(processExecutionService.getResults(executionId));
}

@GetMapping("/executions")
Expand All @@ -85,8 +81,7 @@ public ResponseEntity<List<ProcessExecution>> getLaunchedProcesses(@Parameter(de
@ApiResponse(responseCode = "200", description = "The execution steps statuses"),
@ApiResponse(responseCode = "404", description = "execution id was not found")})
public ResponseEntity<List<ProcessExecutionStep>> getStepsInfos(@Parameter(description = "Execution UUID") @PathVariable UUID executionId) {
return processExecutionService.getStepsInfos(executionId).map(list -> ResponseEntity.ok().body(list))
.orElseGet(() -> ResponseEntity.notFound().build());
return ResponseEntity.ok().body(processExecutionService.getStepsInfos(executionId));
}

@GetMapping("/executions/{executionId}/debug-infos")
Expand All @@ -95,23 +90,21 @@ public ResponseEntity<List<ProcessExecutionStep>> getStepsInfos(@Parameter(descr
@ApiResponse(responseCode = "200", description = "Debug file downloaded"),
@ApiResponse(responseCode = "404", description = "execution id was not found")})
public ResponseEntity<byte[]> getDebugInfos(@Parameter(description = "Execution UUID") @PathVariable UUID executionId) {
return processExecutionService.getDebugInfos(executionId)
.map(bytes -> ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION,
"attachment; filename=\"archive.zip\"")
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.contentLength(bytes.length)
.body(bytes))
.orElseGet(() -> ResponseEntity.notFound().build());
byte[] bytes = processExecutionService.getDebugInfos(executionId);
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION,
"attachment; filename=\"archive.zip\"")
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.contentLength(bytes.length)
.body(bytes);
}

@DeleteMapping("/executions/{executionId}")
@Operation(summary = "Delete an execution")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Execution was deleted"),
@ApiResponse(responseCode = "404", description = "execution id was not found")})
public ResponseEntity<Void> deleteExecution(@PathVariable UUID executionId) {
Optional<UUID> deletedExecutionId = processExecutionService.deleteExecution(executionId);
return deletedExecutionId.isPresent() ? ResponseEntity.ok().build() : ResponseEntity.notFound().build();
processExecutionService.deleteExecution(executionId);
return ResponseEntity.ok().build();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.gridsuite.monitor.server.dto.processconfig.PersistedProcessConfig;
import org.gridsuite.monitor.server.dto.processconfig.ProcessConfigComparison;
import org.gridsuite.monitor.server.services.processconfig.ProcessConfigService;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand All @@ -31,7 +30,6 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

/**
Expand Down Expand Up @@ -64,8 +62,7 @@ public ResponseEntity<UUID> createProcessConfig(@Valid @RequestBody ProcessConfi
@ApiResponse(responseCode = "404", description = "process config was not found")})
public ResponseEntity<PersistedProcessConfig> getProcessConfig(
@Parameter(description = "process config UUID") @PathVariable("uuid") UUID processConfigUuid) {
Optional<PersistedProcessConfig> processConfig = processConfigService.getProcessConfig(processConfigUuid);
return processConfig.map(config -> ResponseEntity.ok().body(config)).orElseGet(() -> ResponseEntity.notFound().build());
return ResponseEntity.ok().body(processConfigService.getProcessConfig(processConfigUuid));
}

@GetMapping(value = "/metadata", produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -85,8 +82,8 @@ public ResponseEntity<List<MetadataInfos>> getProcessConfigsMetadata(@RequestPar
public ResponseEntity<Void> updateProcessConfig(
@Parameter(description = "process config UUID") @PathVariable("uuid") UUID processConfigUuid,
@Valid @RequestBody ProcessConfig processConfig) {
Optional<UUID> processConfigUpdated = processConfigService.updateProcessConfig(processConfigUuid, processConfig);
return processConfigUpdated.isPresent() ? ResponseEntity.ok().build() : ResponseEntity.notFound().build();
processConfigService.updateProcessConfig(processConfigUuid, processConfig);
return ResponseEntity.ok().build();
}

@PostMapping(value = "", params = "duplicateFrom", produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -96,10 +93,7 @@ public ResponseEntity<Void> updateProcessConfig(
@ApiResponse(responseCode = "404", description = "process config to duplicate was not found")})
public ResponseEntity<UUID> duplicateProcessConfig(
@Parameter(description = "UUID of the process config to duplicate") @RequestParam("duplicateFrom") UUID sourceProcessConfigUuid) {
Optional<UUID> newProcessConfigUuid = processConfigService.duplicateProcessConfig(sourceProcessConfigUuid);
return newProcessConfigUuid
.map(configUuid -> ResponseEntity.ok().body(configUuid))
.orElseGet(() -> ResponseEntity.notFound().build());
return ResponseEntity.ok().body(processConfigService.duplicateProcessConfig(sourceProcessConfigUuid));
}

@DeleteMapping(value = "/{uuid}", produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -109,8 +103,8 @@ public ResponseEntity<UUID> duplicateProcessConfig(
@ApiResponse(responseCode = "404", description = "process config was not found")})
public ResponseEntity<Void> deleteProcessConfig(
@Parameter(description = "process config UUID") @PathVariable("uuid") UUID processConfigUuid) {
Optional<UUID> deletedProcessConfigId = processConfigService.deleteProcessConfig(processConfigUuid);
return deletedProcessConfigId.isPresent() ? ResponseEntity.ok().build() : ResponseEntity.notFound().build();
processConfigService.deleteProcessConfig(processConfigUuid);
return ResponseEntity.ok().build();
}

@GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -132,7 +126,6 @@ public ResponseEntity<List<PersistedProcessConfig>> getProcessConfigs(
public ResponseEntity<ProcessConfigComparison> compareProcessConfigs(
@Parameter(description = "First process config UUID") @RequestParam("uuid1") UUID uuid1,
@Parameter(description = "Second process config UUID") @RequestParam("uuid2") UUID uuid2) {
Optional<ProcessConfigComparison> comparison = processConfigService.compareProcessConfigs(uuid1, uuid2);
return comparison.map(c -> ResponseEntity.status(HttpStatus.OK).body(c)).orElseGet(() -> ResponseEntity.status(HttpStatus.NOT_FOUND).build());
return ResponseEntity.ok(processConfigService.compareProcessConfigs(uuid1, uuid2));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
public enum MonitorServerBusinessErrorCode implements BusinessErrorCode {
DIFFERENT_PROCESS_CONFIG_TYPE("monitor.server.differentProcessConfigType");
DIFFERENT_PROCESS_CONFIG_TYPE("monitor.server.differentProcessConfigType"),
PROCESS_CONFIG_NOT_FOUND("monitor.server.processConfigNotFound"),
PROCESS_EXECUTION_NOT_FOUND("monitor.server.processExecutionNotFound"),
DEBUG_INFOS_NOT_FOUND("monitor.server.debugInfosNotFound");

private final String code;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected MonitorServerBusinessErrorCode getBusinessCode(MonitorServerException
protected HttpStatus mapStatus(MonitorServerBusinessErrorCode errorCode) {
return switch (errorCode) {
case DIFFERENT_PROCESS_CONFIG_TYPE -> HttpStatus.BAD_REQUEST;
case PROCESS_CONFIG_NOT_FOUND, PROCESS_EXECUTION_NOT_FOUND, DEBUG_INFOS_NOT_FOUND -> HttpStatus.NOT_FOUND;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.stream.Collectors;

import static org.gridsuite.monitor.server.error.MonitorServerBusinessErrorCode.DIFFERENT_PROCESS_CONFIG_TYPE;
import static org.gridsuite.monitor.server.error.MonitorServerBusinessErrorCode.PROCESS_CONFIG_NOT_FOUND;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
Expand Down Expand Up @@ -58,9 +59,8 @@ public UUID createProcessConfig(ProcessConfig processConfig) {
}

@Transactional(readOnly = true)
public Optional<PersistedProcessConfig> getProcessConfig(UUID processConfigUuid) {
return processConfigRepository.findById(processConfigUuid)
.map(this::toPersistedProcessConfig);
public PersistedProcessConfig getProcessConfig(UUID processConfigUuid) {
return toPersistedProcessConfig(getProcessConfigEntity(processConfigUuid));
}

@Transactional(readOnly = true)
Expand All @@ -78,34 +78,28 @@ public List<MetadataInfos> getProcessConfigsMetadata(List<UUID> processConfigUui
}

@Transactional
public Optional<UUID> updateProcessConfig(UUID processConfigUuid, ProcessConfig processConfig) {
return processConfigRepository.findById(processConfigUuid)
.map(entity -> {
if (entity.getProcessType() != processConfig.processType()) {
throw new IllegalArgumentException("Process config type mismatch : " + entity.getProcessType());
}
getHandler(processConfig.processType()).update(processConfig, entity);
return processConfigUuid;
});
public void updateProcessConfig(UUID processConfigUuid, ProcessConfig processConfig) {
ProcessConfigEntity entity = getProcessConfigEntity(processConfigUuid);
if (entity.getProcessType() != processConfig.processType()) {
throw new IllegalArgumentException("Process config type mismatch : " + entity.getProcessType());
}
getHandler(processConfig.processType()).update(processConfig, entity);
}

@Transactional
public Optional<UUID> duplicateProcessConfig(UUID sourceProcessConfigUuid) {
return processConfigRepository.findById(sourceProcessConfigUuid)
.map(sourceEntity -> {
ProcessConfigEntity entity = getHandler(sourceEntity.getProcessType()).copyEntity(sourceEntity);
return processConfigRepository.save(entity).getId();
});
public UUID duplicateProcessConfig(UUID sourceProcessConfigUuid) {
ProcessConfigEntity sourceEntity = getProcessConfigEntity(sourceProcessConfigUuid);
ProcessConfigEntity entity = getHandler(sourceEntity.getProcessType()).copyEntity(sourceEntity);
return processConfigRepository.save(entity).getId();
}

@Transactional
public Optional<UUID> deleteProcessConfig(UUID processConfigUuid) {
public void deleteProcessConfig(UUID processConfigUuid) {
if (processConfigRepository.existsById(processConfigUuid)) {
processConfigRepository.deleteById(processConfigUuid);
return Optional.of(processConfigUuid);
} else {
return Optional.empty();
return;
}
throw processConfigNotFound(processConfigUuid);
}

private PersistedProcessConfig toPersistedProcessConfig(ProcessConfigEntity entity) {
Expand All @@ -117,25 +111,31 @@ private ProcessConfig toProcessConfig(ProcessConfigEntity entity) {
}

@Transactional(readOnly = true)
public Optional<ProcessConfigComparison> compareProcessConfigs(UUID uuid1, UUID uuid2) {
Optional<ProcessConfigEntity> processConfigEntity1 = processConfigRepository.findById(uuid1);
Optional<ProcessConfigEntity> processConfigEntity2 = processConfigRepository.findById(uuid2);

if (processConfigEntity1.isEmpty() || processConfigEntity2.isEmpty()) {
return Optional.empty();
}
public ProcessConfigComparison compareProcessConfigs(UUID uuid1, UUID uuid2) {
ProcessConfigEntity processConfigEntity1 = getProcessConfigEntity(uuid1);
ProcessConfigEntity processConfigEntity2 = getProcessConfigEntity(uuid2);

if (processConfigEntity1.get().getProcessType() != processConfigEntity2.get().getProcessType()) {
if (processConfigEntity1.getProcessType() != processConfigEntity2.getProcessType()) {
throw new MonitorServerException(DIFFERENT_PROCESS_CONFIG_TYPE, "Cannot compare different process config types",
Map.of("processConfigEntity1Type", processConfigEntity1.get().getProcessType(), "processConfigEntity2Type", processConfigEntity2.get().getProcessType()));
Map.of("processConfigEntity1Type", processConfigEntity1.getProcessType(), "processConfigEntity2Type", processConfigEntity2.getProcessType()));
}

ProcessConfig processConfig1 = toProcessConfig(processConfigEntity1.get());
ProcessConfig processConfig2 = toProcessConfig(processConfigEntity2.get());
ProcessConfig processConfig1 = toProcessConfig(processConfigEntity1);
ProcessConfig processConfig2 = toProcessConfig(processConfigEntity2);

List<ProcessConfigFieldComparison> differences = processConfig1.compareWith(processConfig2);
boolean identical = differences.stream().allMatch(ProcessConfigFieldComparison::identical);

return Optional.of(new ProcessConfigComparison(uuid1, uuid2, identical, differences));
return new ProcessConfigComparison(uuid1, uuid2, identical, differences);
}

private ProcessConfigEntity getProcessConfigEntity(UUID processConfigUuid) {
return processConfigRepository.findById(processConfigUuid)
.orElseThrow(() -> processConfigNotFound(processConfigUuid));
}

private MonitorServerException processConfigNotFound(UUID processConfigUuid) {
return new MonitorServerException(PROCESS_CONFIG_NOT_FOUND, "Process config not found",
Map.of("processConfigUuid", processConfigUuid));
}
}
Loading
Loading