Skip to content

Commit

Permalink
Changed: Remove null descriptions of notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Dec 19, 2024
1 parent d73da3b commit 4ef403e
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/main/java/de/samply/exporter/ExporterService.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,24 @@ public ExporterService(
}

public Mono<ExporterServiceResult> sendQueryToBridgehead(ProjectBridgehead projectBridgehead) throws ExporterServiceException {
log.info("Sending query of project " + projectBridgehead.getProject().getCode() + " to bridgehead " + projectBridgehead.getBridgehead() + " ...");
String description = "Sending query of project " + projectBridgehead.getProject().getCode() + " to bridgehead " + projectBridgehead.getBridgehead() + " ...";
log.info(description);
TaskType taskType = TaskType.CREATE;
return postRequest(projectBridgehead, generateFocusBody(projectBridgehead, taskType), taskType);
return postRequest(projectBridgehead, generateFocusBody(projectBridgehead, taskType), taskType, description);
}

public Mono<ExporterServiceResult> sendQueryToBridgeheadAndExecute(ProjectBridgehead projectBridgehead) throws ExporterServiceException {
log.info("Sending query of project " + projectBridgehead.getProject().getCode() + " to bridgehead " + projectBridgehead.getBridgehead() + " to be executed...");
String description = "Sending query of project " + projectBridgehead.getProject().getCode() + " to bridgehead " + projectBridgehead.getBridgehead() + " to be executed...";
log.info(description);
TaskType taskType = TaskType.EXECUTE;
return postRequest(projectBridgehead, generateFocusBody(projectBridgehead, taskType), taskType);
return postRequest(projectBridgehead, generateFocusBody(projectBridgehead, taskType), taskType, description);
}

public Mono<ExporterServiceResult> checkExecutionStatus(ProjectBridgehead projectBridgehead) {
log.info("Checking export execution status of project " + projectBridgehead.getProject().getCode() + " in bridgehead " + projectBridgehead.getBridgehead());
String description = "Checking export execution status of project " + projectBridgehead.getProject().getCode() + " in bridgehead " + projectBridgehead.getBridgehead();
log.info(description);
TaskType taskType = TaskType.STATUS;
return postRequest(projectBridgehead, generateFocusBody(projectBridgehead, taskType), taskType);
return postRequest(projectBridgehead, generateFocusBody(projectBridgehead, taskType), taskType, description);
}

@Async()
Expand All @@ -144,8 +147,9 @@ public boolean isExportFileTransferredToResearchEnvironment(@NotNull String proj

@Async
public void transferFileToResearchEnvironment(ProjectCoder projectCoder) {
log.info("Transfering file to Coder for project " + projectCoder.getProjectBridgeheadUser().getProjectBridgehead().getProject().getCode() + " in bridgehead " + projectCoder.getProjectBridgeheadUser().getProjectBridgehead().getBridgehead());
postRequest(projectCoder.getProjectBridgeheadUser().getProjectBridgehead(), generateTransferFileBeamRequest(projectCoder), TaskType.FILE_TRANSFER).subscribe(result -> {
String description = "Transfering file to Research Environment for project " + projectCoder.getProjectBridgeheadUser().getProjectBridgehead().getProject().getCode() + " in bridgehead " + projectCoder.getProjectBridgeheadUser().getProjectBridgehead().getBridgehead();
log.info(description);
postRequest(projectCoder.getProjectBridgeheadUser().getProjectBridgehead(), generateTransferFileBeamRequest(projectCoder), TaskType.FILE_TRANSFER, description).subscribe(result -> {
projectCoder.setExportTransferred(true);
this.projectCoderRepository.save(projectCoder);
});
Expand All @@ -163,7 +167,7 @@ private String fetchCoderFileBeamId(ProjectCoder projectCoder) {
return projectCoder.getAppId() + ((coderBeamIdSuffix.startsWith(".")) ? "" : ".") + coderBeamIdSuffix;
}

private Mono<ExporterServiceResult> postRequest(ProjectBridgehead projectBridgehead, BeamRequest beamRequest, TaskType taskType) {
private Mono<ExporterServiceResult> postRequest(ProjectBridgehead projectBridgehead, BeamRequest beamRequest, TaskType taskType, String description) {
return webClient.post()
.uri(uriBuilder -> uriBuilder.path(ProjectManagerConst.BEAM_TASK_PATH).build())
.header(HttpHeaders.AUTHORIZATION, fetchAuthorization())
Expand All @@ -172,7 +176,7 @@ private Mono<ExporterServiceResult> postRequest(ProjectBridgehead projectBridgeh
.exchangeToMono(clientResponse -> {
if (clientResponse.statusCode().equals(HttpStatus.OK) || clientResponse.statusCode().equals(HttpStatus.CREATED)) {
fetchBridgeheadOperationType(taskType).ifPresent(operationType ->
createBridgeheadNotification((HttpStatus) clientResponse.statusCode(), null, projectBridgehead, projectBridgehead.getExporterUser(), operationType));
createBridgeheadNotification((HttpStatus) clientResponse.statusCode(), null, projectBridgehead, projectBridgehead.getExporterUser(), operationType, description));
resetProjectBridgeheadDataShield(projectBridgehead);
return Mono.just(new ExporterServiceResult(projectBridgehead, beamService.serializeFocusQuery(beamRequest)));
} else {
Expand All @@ -191,9 +195,9 @@ private String fetchAuthorization() {
}

private void createBridgeheadNotification(
HttpStatus status, String error, ProjectBridgehead projectBridgehead, String email, OperationType operationType) {
HttpStatus status, String error, ProjectBridgehead projectBridgehead, String email, OperationType operationType, String description) {
notificationService.createNotification(
projectBridgehead.getProject().getCode(), projectBridgehead.getBridgehead(), email, operationType, null, error, status);
projectBridgehead.getProject().getCode(), projectBridgehead.getBridgehead(), email, operationType, description, error, status);
}

private Optional<OperationType> fetchBridgeheadOperationType(TaskType taskType) {
Expand Down Expand Up @@ -334,7 +338,9 @@ public Mono<ExporterServiceResult> checkIfQueryIsAlreadySentOrExecuted(ProjectBr
case SENDING_AND_EXECUTING -> Optional.of(OperationType.CHECK_SEND_AND_EXECUTE_QUERY);
default -> Optional.empty();
};
operationType.ifPresent(type -> createBridgeheadNotification(HttpStatus.OK, null, projectBridgehead, projectBridgehead.getExporterUser(), type));
operationType.ifPresent(type -> createBridgeheadNotification(
HttpStatus.OK, null, projectBridgehead, projectBridgehead.getExporterUser(),
type, "Quecking if query is already sent or executed"));
return clientResponse.bodyToMono(BeamRequest[].class).filter(focusQueries -> focusQueries != null && focusQueries.length > 0).flatMap(newBeamRequest -> {
if (projectBridgehead.getQueryState() == QueryState.EXPORT_RUNNING_2) {
if (newBeamRequest[0].getBody() == null) {
Expand Down

0 comments on commit 4ef403e

Please sign in to comment.