Skip to content

Commit

Permalink
Added: Resend export files to research environment
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Jul 8, 2024
1 parent d1410ec commit e22108c
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.0.1 - 2024-07-01]
## [0.0.1 - 2024-07-08]
### Added
- First version of the project
- Spring Application
Expand Down Expand Up @@ -139,3 +139,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Research environment project type
- Upload file to Coder
- Delete Coder workspace job
- Resend export files to research environment
4 changes: 4 additions & 0 deletions src/main/java/de/samply/app/ProjectManagerConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public class ProjectManagerConst {
public final static String SET_PROJECT_CONFIGURATION_ACTION = "SET_PROJECT_CONFIGURATION";
public final static String FETCH_VISIBLE_PROJECT_BRIDGEHEADS_ACTION = "FETCH_VISIBLE_PROJECT_BRIDGEHEADS";
public final static String FETCH_PROJECT_ROLES_ACTION = "FETCH_PROJECT_ROLES";
public final static String SEND_EXPORT_FILES_TO_RESEARCH_ENVIRONMENT_ACTION = "SEND_EXPORT_FILES_TO_RESEARCH_ENVIRONMENT";
public final static String ARE_EXPORT_FILES_TRANSFERRED_TO_RESEARCH_ENVIRONMENT_ACTION = "ARE_EXPORT_FILES_TRANSFERRED_TO_RESEARCH_ENVIRONMENT";


// REST Services
Expand Down Expand Up @@ -176,6 +178,8 @@ public class ProjectManagerConst {
public final static String SAVE_QUERY_IN_BRIDGEHEAD = "/save-query-in-bridgehead";
public final static String SAVE_AND_EXECUTE_QUERY_IN_BRIDGEHEAD = "/save-and-execute-query-in-bridgehead";
public final static String DOWNLOAD_AUTHENTICATION_SCRIPT = "/download-authentication-script";
public final static String SEND_EXPORT_FILES_TO_RESEARCH_ENVIRONMENT = "/send-export-files-to-research-environment";
public final static String ARE_EXPORT_FILES_TRANSFERRED_TO_RESEARCH_ENVIRONMENT = "/export-files-transferred-to-research-environment";
public final static String EXISTS_AUTHENTICATION_SCRIPT = "/exists-authentication-script";
public final static String FETCH_DATASHIELD_STATUS = "/datashield-status";
public final static String FETCH_PUBLICATIONS = "/publications";
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/de/samply/app/ProjectManagerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,34 @@ public ResponseEntity<String> saveAndExecuteQueryInBridgehead(
return convertToResponseEntity(() -> this.projectBridgeheadService.scheduleSendQueryToBridgeheadAndExecute(projectCode, bridgehead));
}

@RoleConstraints(projectRoles = {ProjectRole.DEVELOPER, ProjectRole.PILOT, ProjectRole.FINAL})
@StateConstraints(projectStates = {ProjectState.DEVELOP, ProjectState.PILOT, ProjectState.FINAL},
queryStates = {QueryState.FINISHED})
@ProjectConstraints(projectTypes = {ProjectType.RESEARCH_ENVIRONMENT, ProjectType.DATASHIELD})
@FrontendSiteModule(site = ProjectManagerConst.PROJECT_VIEW_SITE, module = ProjectManagerConst.EXPORT_MODULE)
@FrontendAction(action = ProjectManagerConst.SEND_EXPORT_FILES_TO_RESEARCH_ENVIRONMENT_ACTION)
@PostMapping(value = ProjectManagerConst.SEND_EXPORT_FILES_TO_RESEARCH_ENVIRONMENT)
public ResponseEntity<String> sendExportFilesToResearchEnvironment(
@ProjectCode @RequestParam(name = ProjectManagerConst.PROJECT_CODE) String projectCode,
@Bridgehead @RequestParam(name = ProjectManagerConst.BRIDGEHEAD) String bridgehead
) {
return convertToResponseEntity(() -> exporterService.transferFileToResearchEnvironment(projectCode, bridgehead));
}

@RoleConstraints(projectRoles = {ProjectRole.DEVELOPER, ProjectRole.PILOT, ProjectRole.FINAL})
@StateConstraints(projectStates = {ProjectState.DEVELOP, ProjectState.PILOT, ProjectState.FINAL},
queryStates = {QueryState.FINISHED})
@ProjectConstraints(projectTypes = {ProjectType.RESEARCH_ENVIRONMENT, ProjectType.DATASHIELD})
@FrontendSiteModule(site = ProjectManagerConst.PROJECT_VIEW_SITE, module = ProjectManagerConst.EXPORT_MODULE)
@FrontendAction(action = ProjectManagerConst.ARE_EXPORT_FILES_TRANSFERRED_TO_RESEARCH_ENVIRONMENT_ACTION)
@PostMapping(value = ProjectManagerConst.ARE_EXPORT_FILES_TRANSFERRED_TO_RESEARCH_ENVIRONMENT)
public ResponseEntity<String> isExportFileTransferredToResearchEnvironment(
@ProjectCode @RequestParam(name = ProjectManagerConst.PROJECT_CODE) String projectCode,
@Bridgehead @RequestParam(name = ProjectManagerConst.BRIDGEHEAD) String bridgehead
) {
return convertToResponseEntity(() -> exporterService.isExportFileTransferredToResearchEnvironment(projectCode, bridgehead));
}

@RoleConstraints(projectRoles = {ProjectRole.DEVELOPER, ProjectRole.PILOT, ProjectRole.FINAL})
@StateConstraints(projectStates = {ProjectState.DEVELOP, ProjectState.PILOT, ProjectState.FINAL})
@ProjectConstraints(projectTypes = {ProjectType.DATASHIELD})
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/de/samply/coder/CoderJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.springframework.stereotype.Component;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -49,10 +48,7 @@ public void manageCoderActiveUsers() {
if (projectCoder.isEmpty()) {
this.coderService.createWorkspace(user);
} else if (!projectCoder.get().isExportTransferred()) {
exporterService.transferFileToCoder(user.getProjectBridgehead(), projectCoder.get()).subscribe(result -> {
projectCoder.get().setExportTransferred(true);
this.projectCoderRepository.save(projectCoder.get());
});
exporterService.transferFileToResearchEnvironment(projectCoder.get());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface ProjectCoderRepository extends JpaRepository<ProjectCoder, Long

Optional<ProjectCoder> findByProjectBridgeheadUserAndDeletedAtIsNull(ProjectBridgeheadUser projectBridgeheadUser);

Optional<ProjectCoder> findByProjectBridgeheadUser_ProjectBridgehead_BridgeheadAndProjectBridgeheadUser_ProjectBridgehead_Project_CodeAndProjectBridgeheadUser_Email(String bridgehead, String projectCode, String email);

}
46 changes: 37 additions & 9 deletions src/main/java/de/samply/exporter/ExporterService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import de.samply.db.model.*;
import de.samply.db.repository.ProjectBridgeheadDataShieldRepository;
import de.samply.db.repository.ProjectBridgeheadRepository;
import de.samply.db.repository.ProjectCoderRepository;
import de.samply.exporter.focus.BeamRequest;
import de.samply.exporter.focus.BeamService;
import de.samply.exporter.focus.BeamServiceException;
Expand All @@ -16,6 +17,7 @@
import de.samply.notification.OperationType;
import de.samply.project.ProjectType;
import de.samply.query.QueryState;
import de.samply.security.SessionUser;
import de.samply.utils.Base64Utils;
import de.samply.utils.WebClientFactory;
import jakarta.validation.constraints.NotNull;
Expand All @@ -41,11 +43,14 @@
@Service
@Slf4j
public class ExporterService {
private final ProjectBridgeheadRepository projectBridgeheadRepository;


private final BeamService beamService;
private final WebClient webClient;
private final SessionUser sessionUser;
private final ProjectBridgeheadDataShieldRepository projectBridgeheadDataShieldRepository;
private final ProjectBridgeheadRepository projectBridgeheadRepository;
private final ProjectCoderRepository projectCoderRepository;
private final NotificationService notificationService;
private final Set<String> exportTemplates;
private final Set<String> datashieldTemplates;
Expand Down Expand Up @@ -73,11 +78,14 @@ public ExporterService(
@Value(ProjectManagerConst.MAX_TIME_TO_WAIT_FOCUS_TASK_IN_MINUTES_SV) int maxTimeToWaitFocusTaskInMinutes,
@Value(ProjectManagerConst.CODER_BEAM_ID_SUFFIX_SV) String coderBeamIdSuffix,
@Value(ProjectManagerConst.CODER_TEST_FILE_BEAM_ID_SV) String testCoderFileBeamId,
SessionUser sessionUser,
BeamService beamService,
ProjectBridgeheadDataShieldRepository projectBridgeheadDataShieldRepository,
NotificationService notificationService,
WebClientFactory webClientFactory,
ProjectBridgeheadRepository projectBridgeheadRepository) {
ProjectBridgeheadRepository projectBridgeheadRepository,
ProjectCoderRepository projectCoderRepository) {
this.sessionUser = sessionUser;
this.beamService = beamService;
this.projectBridgeheadDataShieldRepository = projectBridgeheadDataShieldRepository;
this.notificationService = notificationService;
Expand All @@ -90,6 +98,7 @@ public ExporterService(
this.researchEnvironmentTemplates = researchEnvironmentTemplates;
this.coderBeamIdSuffix = coderBeamIdSuffix;
this.testCoderFileBeamId = testCoderFileBeamId;
this.projectCoderRepository = projectCoderRepository;
this.webClient = webClientFactory.createWebClient(focusUrl);
this.exporterApiKey = exporterApiKey;
this.projectBridgeheadRepository = projectBridgeheadRepository;
Expand All @@ -113,18 +122,37 @@ public Mono<ExporterServiceResult> checkExecutionStatus(ProjectBridgehead projec
return postRequest(projectBridgehead, generateFocusBody(projectBridgehead, taskType), taskType);
}

public Mono<ExporterServiceResult> transferFileToCoder(ProjectBridgehead projectBridgehead, ProjectCoder projectCoder) {
log.info("Transfering file to Coder for project " + projectBridgehead.getProject().getCode() + " in bridgehead " + projectBridgehead.getBridgehead());
return postRequest(projectBridgehead, generateTransferFileBeamRequest(projectBridgehead, projectCoder), TaskType.FILE_TRANSFER);
public void transferFileToResearchEnvironment(@NotNull String projectCode, @NotNull String bridgehead) {
Optional<ProjectCoder> projectCoder = this.projectCoderRepository.findByProjectBridgeheadUser_ProjectBridgehead_BridgeheadAndProjectBridgeheadUser_ProjectBridgehead_Project_CodeAndProjectBridgeheadUser_Email(bridgehead, projectCode, sessionUser.getEmail());
if (projectCoder.isEmpty()) {
throw new ExporterServiceException("Project " + projectCode + " for bridgehead " + bridgehead + " for user " + sessionUser.getEmail() + " not found");
}
transferFileToResearchEnvironment(projectCoder.get());
}

public boolean isExportFileTransferredToResearchEnvironment(@NotNull String projectCode, @NotNull String bridgehead) {
Optional<ProjectCoder> projectCoder = this.projectCoderRepository.findByProjectBridgeheadUser_ProjectBridgehead_BridgeheadAndProjectBridgeheadUser_ProjectBridgehead_Project_CodeAndProjectBridgeheadUser_Email(bridgehead, projectCode, sessionUser.getEmail());
if (projectCoder.isEmpty()) {
throw new ExporterServiceException("Project " + projectCode + " for bridgehead " + bridgehead + " for user " + sessionUser.getEmail() + " not found");
}
return projectCoder.get().isExportTransferred();
}

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 -> {
projectCoder.setExportTransferred(true);
this.projectCoderRepository.save(projectCoder);
});
}

private BeamRequest generateTransferFileBeamRequest(ProjectBridgehead projectBridgehead, ProjectCoder projectCoder) {
return beamService.generateExporterFileTransferBeamRequest(projectBridgehead.getBridgehead(),
projectBridgehead.getExporterExecutionId(), fetchCoderFileBeamId(projectCoder));
private BeamRequest generateTransferFileBeamRequest(ProjectCoder projectCoder) {
return beamService.generateExporterFileTransferBeamRequest(projectCoder.getProjectBridgeheadUser().getProjectBridgehead().getBridgehead(),
projectCoder.getProjectBridgeheadUser().getProjectBridgehead().getExporterExecutionId(), fetchCoderFileBeamId(projectCoder));
}

private String fetchCoderFileBeamId(ProjectCoder projectCoder) {
if (testCoderFileBeamId != null){
if (testCoderFileBeamId != null) {
return testCoderFileBeamId;
}
return projectCoder.getAppId() + ((coderBeamIdSuffix.startsWith(".")) ? "" : ".") + coderBeamIdSuffix;
Expand Down

0 comments on commit e22108c

Please sign in to comment.