diff --git a/vip-application/src/main/java/fr/insalyon/creatis/vip/application/client/rpc/ReproVipService.java b/vip-application/src/main/java/fr/insalyon/creatis/vip/application/client/rpc/ReproVipService.java index 30977430c..1b7c0701b 100644 --- a/vip-application/src/main/java/fr/insalyon/creatis/vip/application/client/rpc/ReproVipService.java +++ b/vip-application/src/main/java/fr/insalyon/creatis/vip/application/client/rpc/ReproVipService.java @@ -25,7 +25,7 @@ public static ReproVipServiceAsync getInstance() { void addExecution(Execution execution) throws CoreException; void updateExecution(String executionID, String newStatus) throws CoreException; void executionOutputData(String executionID) throws CoreException; - String downloadJsonOutputData(String executionID) throws CoreException; + String downloadJsonOutputData(String executionName, String executionID, String version) throws CoreException; void createReproVipDirectory(String executionName, String executionID, String version) throws CoreException; } diff --git a/vip-application/src/main/java/fr/insalyon/creatis/vip/application/client/rpc/ReproVipServiceAsync.java b/vip-application/src/main/java/fr/insalyon/creatis/vip/application/client/rpc/ReproVipServiceAsync.java index 27e8d204c..0ac907bc6 100644 --- a/vip-application/src/main/java/fr/insalyon/creatis/vip/application/client/rpc/ReproVipServiceAsync.java +++ b/vip-application/src/main/java/fr/insalyon/creatis/vip/application/client/rpc/ReproVipServiceAsync.java @@ -9,7 +9,7 @@ public interface ReproVipServiceAsync { void addExecution(Execution execution, AsyncCallback asyncCallback); void updateExecution(String executionID, String newStatus, AsyncCallback asyncCallback); void executionOutputData(String executionID, AsyncCallback callback); - void downloadJsonOutputData(String executionID, AsyncCallback callback); + void downloadJsonOutputData(String executionName, String executionID, String version, AsyncCallback callback); void createReproVipDirectory(String executionName, String execution, String version, AsyncCallback callback); } diff --git a/vip-application/src/main/java/fr/insalyon/creatis/vip/application/client/view/system/application/ExecutionsContextMenu.java b/vip-application/src/main/java/fr/insalyon/creatis/vip/application/client/view/system/application/ExecutionsContextMenu.java index 0cd7a5875..536835321 100644 --- a/vip-application/src/main/java/fr/insalyon/creatis/vip/application/client/view/system/application/ExecutionsContextMenu.java +++ b/vip-application/src/main/java/fr/insalyon/creatis/vip/application/client/view/system/application/ExecutionsContextMenu.java @@ -41,7 +41,7 @@ public void onClick(MenuItemClickEvent event) { DownloadOutputDataItem.addClickHandler(new ClickHandler() { @Override public void onClick(MenuItemClickEvent event) { - DownloadOutputDataExecution(); + DownloadOutputDataExecution(executionName, executionID, version); } }); @@ -63,7 +63,7 @@ public void onSuccess(Void result) { modal.show("Make execution public", true); reproVipServiceAsync.updateExecution(executionID, "Public", callback); } - private void DownloadOutputDataExecution() { + private void DownloadOutputDataExecution(String executionName, String executionID, String version) { final AsyncCallback callback = new AsyncCallback() { @Override public void onFailure(Throwable caught) { @@ -77,7 +77,7 @@ public void onSuccess(String s) { } }; modal.show("Download Outputs", true); - reproVipServiceAsync.downloadJsonOutputData(executionID, callback); + reproVipServiceAsync.downloadJsonOutputData(executionName, executionID, version, callback); } public void createReproVipDirectory(String executionName, String executionID, String version) { reproVipServiceAsync.createReproVipDirectory(executionName, executionID, version, new AsyncCallback() { diff --git a/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/business/ReproVipBusiness.java b/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/business/ReproVipBusiness.java index 537b72ed3..36b1c8424 100644 --- a/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/business/ReproVipBusiness.java +++ b/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/business/ReproVipBusiness.java @@ -23,10 +23,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.io.File; -import java.io.FileWriter; -import java.io.FilenameFilter; -import java.io.IOException; +import java.io.*; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.util.ArrayList; @@ -112,37 +109,51 @@ public ExecutionJobTaskData getExecutionJobTaskData(String executionID) throws B } return new ExecutionJobTaskData(jobList); } - - public String createJsonOutputData(String executionID, User currentUser) + public String createJsonOutputData(String executionName, String executionID, String version, User currentUser) throws ApplicationException, BusinessException { - ExecutionInOutData inOutData = executionOutputData(executionID, currentUser); - //ExecutionJobTaskData jobTaskData = getExecutionJobTaskData(executionID); + List filesToDownload = getFilesToCopyPaths(executionName, executionID, version, currentUser); + + Map structuredJson = new HashMap<>(); + + structuredJson.put("files_to_download", filesToDownload); + + Map metadataOuter = new HashMap<>(); + Map metadataInner = new HashMap<>(); + + metadataInner.put("title", "your title"); + metadataInner.put("upload_type", "workflow"); + metadataInner.put("description", "your description"); - //Map combinedData = new HashMap<>(); - //combinedData.put("inOutData", inOutData); - //combinedData.put("jobs", jobTaskData.getJobs()); + List> creators = new ArrayList<>(); + Map creator = new HashMap<>(); + creator.put("name", currentUser.getFullName()); + creator.put("affiliation", "your affiliation"); + creators.add(creator); + + metadataInner.put("creators", creators); + metadataOuter.put("metadata", metadataInner); + + structuredJson.put("metadata", metadataOuter); ObjectMapper objectMapper = new ObjectMapper(); try { - String json = objectMapper.writeValueAsString(inOutData); - //saveJsonToFile(json, executionID); + String json = objectMapper.writeValueAsString(structuredJson); logger.info(json); + + String filePath = "/vip/ReproVip/structuredOutput.json"; + saveJsonToFile(json, filePath); + return json; } catch (JsonProcessingException e) { - throw new ApplicationException(ApplicationException.ApplicationError.valueOf("Failed to convert Output to JSON"), e); + throw new ApplicationException(ApplicationException.ApplicationError.valueOf("Failed to convert structured output to JSON"), e); + } catch (IOException e) { + throw new BusinessException("Failed to save JSON to file", e); } } - - public void saveJsonToFile(String jsonContent, String executionID) throws IOException { - String filePath = server.getWorkflowsPath() + "/" + executionID + "/inOutPut.json"; - File file = new File(filePath); - - if (!file.exists()) { - file.createNewFile(); - } - - try (FileWriter fileWriter = new FileWriter(file)) { - fileWriter.write(jsonContent); + public void saveJsonToFile(String jsonContent, String filePath) throws IOException { + try (FileWriter fileWriter = new FileWriter(filePath); + BufferedWriter bufferedWriter = new BufferedWriter(fileWriter)) { + bufferedWriter.write(jsonContent); } } public void createReproVipDirectory(String executionName, String executionID, String version, User currentUser) { @@ -165,7 +176,7 @@ public void createReproVipDirectory(String executionName, String executionID, St logger.info(outputData.get(0).getPath()); if (outputData != null && !outputData.isEmpty()) { - String outputPath = outputData.get(0).getPath(); + String outputPath = "/vip/grida/downloads" + outputData.get(0).getPath(); if (outputPath != null) { File outputFile = new File(outputPath); if (outputFile.exists()) { @@ -234,4 +245,38 @@ public boolean accept(File dir, String name) { throw new RuntimeException(e); } } + + public List getFilesToCopyPaths(String executionName, String executionID, String version, User currentUser) throws BusinessException { + List paths = new ArrayList<>(); + + List outputData = workflowBusiness.getOutputData(executionID, currentUser.getFolder(), true); + if (outputData != null && !outputData.isEmpty()) { + String outputPath = outputData.get(0).getPath(); + if (outputPath != null) { + paths.add(outputPath); + } + } + + String workflowPath = String.valueOf(workflowBusiness.getRawApplicationDescriptorPath(currentUser, executionName, version)); + if (workflowPath != null && !workflowPath.isEmpty()) { + paths.add(workflowPath); + } + + String provenanceDirPath = server.getWorkflowsPath() + "/" + executionID + "/provenance"; + File provenanceDir = new File(provenanceDirPath); + if (provenanceDir.exists()) { + FilenameFilter filter = new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return name.endsWith(".sh.provenance.json"); + } + }; + File[] matchingFiles = provenanceDir.listFiles(filter); + if (matchingFiles != null && matchingFiles.length > 0) { + paths.add(matchingFiles[0].getAbsolutePath()); + } + } + + return paths; + } } diff --git a/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/business/WorkflowBusiness.java b/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/business/WorkflowBusiness.java index b45384101..ff8404973 100644 --- a/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/business/WorkflowBusiness.java +++ b/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/business/WorkflowBusiness.java @@ -452,7 +452,7 @@ public String getRawApplicationDescriptorPath(User user, String applicationName, try { AppVersion version = applicationDAO.getVersion(applicationName, applicationVersion); - return dataManagerBusiness.getRemoteFile(user, version.getLfn()); + return dataManagerBusiness.getRemoteFile(user, version.getJsonLfn()); } catch (DAOException | BusinessException ex) { throw new BusinessException(WRONG_APPLICATION_DESCRIPTOR, ex, applicationName + "/" + applicationVersion); } diff --git a/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/rpc/ReproVipServiceImpl.java b/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/rpc/ReproVipServiceImpl.java index 810cd101d..15400f9be 100644 --- a/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/rpc/ReproVipServiceImpl.java +++ b/vip-application/src/main/java/fr/insalyon/creatis/vip/application/server/rpc/ReproVipServiceImpl.java @@ -65,10 +65,10 @@ public void executionOutputData(String executionID) throws CoreException { throw new RuntimeException(e); } } - public String downloadJsonOutputData(String executionID) throws CoreException { + public String downloadJsonOutputData(String executionName, String executionID, String version) throws CoreException { try { User currentUser = getSessionUser(); - String json = reproVipBusiness.createJsonOutputData(executionID, currentUser); + String json = reproVipBusiness.createJsonOutputData(executionName, executionID, version, currentUser); return json; } catch (BusinessException | ApplicationException e) { throw new RuntimeException(e);