Skip to content

Commit

Permalink
Copy provenance files to subfolders
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcornier committed Nov 2, 2023
1 parent 5c948c1 commit 82f03f5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package fr.insalyon.creatis.vip.application.client.view.system.application;

import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.PopupPanel;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.util.SC;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.insalyon.creatis.vip.application.server.business;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.insalyon.creatis.vip.application.client.bean.AppVersion;
import fr.insalyon.creatis.vip.application.client.bean.InOutData;
Expand Down Expand Up @@ -174,25 +175,50 @@ public List<Path> copyProvenanceFiles(Path reproVipDir, String executionID) {
logger.debug("Workflows path: " + server.getWorkflowsPath());
List<Path> copiedProvenanceFiles = new ArrayList<>();

// Define the directory where provenance files are stored
Path provenanceDirPath = Paths.get(server.getWorkflowsPath() + "/" + executionID + "/provenance");
if ( ! Files.exists(provenanceDirPath)) {
if (!Files.exists(provenanceDirPath)) {
logger.error("Provenance directory does not exist: " + provenanceDirPath);
return copiedProvenanceFiles;
}

ObjectMapper objectMapper = new ObjectMapper();
try (Stream<Path> stream = Files.list(provenanceDirPath)) {
List<Path> provenanceFiles = stream
.filter(path -> path.toString().endsWith(".sh.provenance.json"))
.collect(Collectors.toList());

for (Path provenanceFile : provenanceFiles) {
Files.copy(provenanceFile, reproVipDir.resolve(provenanceFile.getFileName()), StandardCopyOption.REPLACE_EXISTING);
logger.info("{} file successfully copied to ReproVip directory", provenanceFile);
copiedProvenanceFiles.add(reproVipDir.resolve(provenanceFile.getFileName()));
// Read the JSON content of the source file
String jsonContent = Files.readString(provenanceFile);
Map<String, Object> provenanceMap = objectMapper.readValue(jsonContent, new TypeReference<Map<String, Object>>(){});
// Navigate through the nested JSON to find the md5sum
Map<String, Object> outputFilesSection = (Map<String, Object>) ((Map<String, Object>) provenanceMap.get("public-output")).get("output-files");

if (outputFilesSection != null) {
for (Map.Entry<String, Object> entry : outputFilesSection.entrySet()) {
Map<String, String> fileDetails = (Map<String, String>) entry.getValue();
String md5sum = fileDetails.get("md5sum");

// Create subfolder named after md5sum
Path md5Dir = reproVipDir.resolve(md5sum);
if (!Files.exists(md5Dir)) {
Files.createDirectories(md5Dir);
}

// Copy the source file to the new subfolder
Path newLocation = md5Dir.resolve(provenanceFile.getFileName());
Files.copy(provenanceFile, newLocation, StandardCopyOption.REPLACE_EXISTING);
logger.info("Copied provenance file to directory: {}", newLocation);

copiedProvenanceFiles.add(newLocation);
}
}
}
}
return copiedProvenanceFiles;
} catch (IOException e) {
logger.error("Exception creating the a reprovip directory {}", reproVipDir, e);
logger.error("Error while copying provenance files", e);
throw new RuntimeException(e);
}
}
Expand All @@ -202,14 +228,16 @@ public List<String> getFilesToCopyPaths(String executionName, String executionID

List<InOutData> outputData = workflowBusiness.getRawOutputData(executionID);
if (outputData != null && !outputData.isEmpty()) {
String outputPath = outputData.get(0).getPath();
if (outputPath != null) {
paths.add(outputPath);
for (InOutData data : outputData) {
String outputPath = data.getPath();
if (outputPath != null) {
paths.add(outputPath);
}
}
}

AppVersion appVersion = applicationBusiness.getVersion(executionName, version);
if (appVersion != null && appVersion.getJsonLfn() != null) {
if (appVersion != null && appVersion.getJsonLfn() != null && !paths.contains(appVersion.getJsonLfn())) {
paths.add(appVersion.getJsonLfn());
}

Expand Down

0 comments on commit 82f03f5

Please sign in to comment.