use of io.dockstore.common.VersionTypeValidation in project dockstore by dockstore.
the class WDLHandler method validateEntrySet.
/**
* A common helper method for validating tool and workflow sets
* @param sourcefiles Set of sourcefiles to validate
* @param primaryDescriptorFilePath Path of primary descriptor
* @param type workflow or tool
* @return
*/
public VersionTypeValidation validateEntrySet(Set<SourceFile> sourcefiles, String primaryDescriptorFilePath, String type) {
File tempMainDescriptor = null;
String mainDescriptor = null;
List<DescriptorLanguage.FileType> fileTypes = new ArrayList<>(Collections.singletonList(DescriptorLanguage.FileType.DOCKSTORE_WDL));
Set<SourceFile> filteredSourceFiles = filterSourcefiles(sourcefiles, fileTypes);
Map<String, String> validationMessageObject = new HashMap<>();
if (filteredSourceFiles.size() > 0) {
try {
Optional<SourceFile> primaryDescriptor = filteredSourceFiles.stream().filter(sourceFile -> Objects.equals(sourceFile.getPath(), primaryDescriptorFilePath)).findFirst();
if (primaryDescriptor.isPresent()) {
if (primaryDescriptor.get().getContent() == null || primaryDescriptor.get().getContent().trim().replaceAll("\n", "").isEmpty()) {
validationMessageObject.put(primaryDescriptorFilePath, "The primary descriptor '" + primaryDescriptorFilePath + "' has no content. Please make it a valid WDL document if you want to save.");
return new VersionTypeValidation(false, validationMessageObject);
}
mainDescriptor = primaryDescriptor.get().getContent();
} else {
validationMessageObject.put(primaryDescriptorFilePath, "The primary descriptor '" + primaryDescriptorFilePath + "' could not be found.");
return new VersionTypeValidation(false, validationMessageObject);
}
Map<String, String> secondaryDescContent = new HashMap<>();
for (SourceFile sourceFile : filteredSourceFiles) {
if (!Objects.equals(sourceFile.getPath(), primaryDescriptorFilePath) && sourceFile.getContent() != null) {
if (sourceFile.getContent().trim().replaceAll("\n", "").isEmpty()) {
if (Objects.equals(sourceFile.getType(), DescriptorLanguage.FileType.DOCKSTORE_WDL)) {
validationMessageObject.put(primaryDescriptorFilePath, "File '" + sourceFile.getPath() + "' has no content. Either delete the file or make it a valid WDL document.");
} else if (Objects.equals(sourceFile.getType(), DescriptorLanguage.FileType.WDL_TEST_JSON)) {
validationMessageObject.put(primaryDescriptorFilePath, "File '" + sourceFile.getPath() + "' has no content. Either delete the file or make it a valid WDL JSON/YAML file.");
} else {
validationMessageObject.put(primaryDescriptorFilePath, "File '" + sourceFile.getPath() + "' has no content. Either delete the file or make it valid.");
}
return new VersionTypeValidation(false, validationMessageObject);
}
secondaryDescContent.put(sourceFile.getAbsolutePath(), sourceFile.getContent());
}
}
tempMainDescriptor = File.createTempFile("main", "descriptor", Files.createTempDir());
Files.asCharSink(tempMainDescriptor, StandardCharsets.UTF_8).write(mainDescriptor);
String content = FileUtils.readFileToString(tempMainDescriptor, StandardCharsets.UTF_8);
try {
checkForRecursiveHTTPImports(content, new HashSet<>());
} catch (IOException e) {
validationMessageObject.put(primaryDescriptorFilePath, e.getMessage());
return new VersionTypeValidation(false, validationMessageObject);
} catch (CustomWebApplicationException e) {
validationMessageObject.put(primaryDescriptorFilePath, e.getErrorMessage());
return new VersionTypeValidation(false, validationMessageObject);
}
Optional<String> optValidationMessage = reportValidationForLocalRecursiveImports(content, sourcefiles, primaryDescriptorFilePath);
if (optValidationMessage.isPresent()) {
validationMessageObject.put(primaryDescriptorFilePath, optValidationMessage.get());
return new VersionTypeValidation(false, validationMessageObject);
}
WdlBridge wdlBridge = new WdlBridge();
wdlBridge.setSecondaryFiles((HashMap<String, String>) secondaryDescContent);
if (Objects.equals(type, "tool")) {
wdlBridge.validateTool(tempMainDescriptor.getAbsolutePath(), primaryDescriptorFilePath);
} else {
wdlBridge.validateWorkflow(tempMainDescriptor.getAbsolutePath(), primaryDescriptor.get().getAbsolutePath());
}
} catch (WdlParser.SyntaxError | IllegalArgumentException e) {
if (tempMainDescriptor != null) {
validationMessageObject.put(primaryDescriptorFilePath, getUnsupportedWDLVersionErrorString(tempMainDescriptor.getAbsolutePath()).orElse(e.getMessage()));
} else {
validationMessageObject.put(primaryDescriptorFilePath, e.getMessage());
}
return new VersionTypeValidation(false, validationMessageObject);
} catch (CustomWebApplicationException e) {
throw e;
} catch (Exception e) {
LOG.error("Unhandled exception", e);
throw new CustomWebApplicationException(e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR);
} finally {
FileUtils.deleteQuietly(tempMainDescriptor);
}
} else {
validationMessageObject.put(primaryDescriptorFilePath, "Primary WDL descriptor is not present.");
return new VersionTypeValidation(false, validationMessageObject);
}
return new VersionTypeValidation(true, Collections.emptyMap());
}
use of io.dockstore.common.VersionTypeValidation in project dockstore by dockstore.
the class HostedToolResource method versionValidation.
@Override
protected Tag versionValidation(Tag version, Tool entry, Optional<SourceFile> mainDescriptor) {
Set<SourceFile> sourceFiles = version.getSourceFiles();
VersionTypeValidation validDockerfile = validateDockerfile(sourceFiles);
Validation dockerfileValidation = new Validation(DescriptorLanguage.FileType.DOCKERFILE, validDockerfile);
version.addOrUpdateValidation(dockerfileValidation);
VersionTypeValidation validCWLDescriptorSet = LanguageHandlerFactory.getInterface(DescriptorLanguage.FileType.DOCKSTORE_CWL).validateToolSet(sourceFiles, "/Dockstore.cwl");
Validation cwlValidation = new Validation(DescriptorLanguage.FileType.DOCKSTORE_CWL, validCWLDescriptorSet);
version.addOrUpdateValidation(cwlValidation);
VersionTypeValidation validCWLTestParameterSet = LanguageHandlerFactory.getInterface(DescriptorLanguage.FileType.DOCKSTORE_CWL).validateTestParameterSet(sourceFiles);
Validation cwlTestParameterValidation = new Validation(DescriptorLanguage.FileType.CWL_TEST_JSON, validCWLTestParameterSet);
version.addOrUpdateValidation(cwlTestParameterValidation);
VersionTypeValidation validWDLDescriptorSet = LanguageHandlerFactory.getInterface(DescriptorLanguage.FileType.DOCKSTORE_WDL).validateToolSet(sourceFiles, "/Dockstore.wdl");
Validation wdlValidation = new Validation(DescriptorLanguage.FileType.DOCKSTORE_WDL, validWDLDescriptorSet);
version.addOrUpdateValidation(wdlValidation);
VersionTypeValidation validWDLTestParameterSet = LanguageHandlerFactory.getInterface(DescriptorLanguage.FileType.DOCKSTORE_WDL).validateTestParameterSet(sourceFiles);
Validation wdlTestParameterValidation = new Validation(DescriptorLanguage.FileType.WDL_TEST_JSON, validWDLTestParameterSet);
version.addOrUpdateValidation(wdlTestParameterValidation);
return version;
}
use of io.dockstore.common.VersionTypeValidation in project dockstore by dockstore.
the class GitHubSourceCodeRepo method setupWorkflowFilesForGitHubVersion.
/**
* Pull descriptor files for the given workflow version and add to version
* @param ref Triple containing reference name, branch date, and SHA
* @param repository GitHub repository object
* @param version Version to update
* @param workflow Workflow to add version to
* @param existingDefaults Existing defaults
* @param dockstoreYml Dockstore YML sourcefile
* @return Version with updated sourcefiles
*/
private WorkflowVersion setupWorkflowFilesForGitHubVersion(Triple<String, Date, String> ref, GHRepository repository, WorkflowVersion version, Workflow workflow, Map<String, WorkflowVersion> existingDefaults, SourceFile dockstoreYml) {
// Determine version information from dockstore.yml
YamlWorkflow theWf = null;
List<String> testParameterPaths = null;
try {
final DockstoreYaml12 dockstoreYaml12 = DockstoreYamlHelper.readAsDockstoreYaml12(dockstoreYml.getContent());
// TODO: Need to handle services; the YAML is guaranteed to have at least one of either
final Optional<YamlWorkflow> maybeWorkflow = dockstoreYaml12.getWorkflows().stream().filter(wf -> {
final String wfName = wf.getName();
final String dockstoreWorkflowPath = "github.com/" + repository.getFullName() + (wfName != null && !wfName.isEmpty() ? "/" + wfName : "");
return (Objects.equals(dockstoreWorkflowPath, workflow.getEntryPath()));
}).findFirst();
if (!maybeWorkflow.isPresent()) {
return null;
}
theWf = maybeWorkflow.get();
testParameterPaths = theWf.getTestParameterFiles();
} catch (DockstoreYamlHelper.DockstoreYamlException ex) {
String msg = "Invalid .dockstore.yml: " + ex.getMessage();
LOG.info(msg, ex);
return null;
}
// No need to check for null, has been validated
String primaryDescriptorPath = theWf.getPrimaryDescriptorPath();
version.setWorkflowPath(primaryDescriptorPath);
Map<String, String> validationMessage = new HashMap<>();
String fileContent = this.readFileFromRepo(primaryDescriptorPath, ref.getLeft(), repository);
if (fileContent != null) {
// Add primary descriptor file and resolve imports
SourceFile primaryDescriptorFile = new SourceFile();
primaryDescriptorFile.setAbsolutePath(primaryDescriptorPath);
primaryDescriptorFile.setPath(primaryDescriptorPath);
primaryDescriptorFile.setContent(fileContent);
DescriptorLanguage.FileType identifiedType = workflow.getDescriptorType().getFileType();
primaryDescriptorFile.setType(identifiedType);
version = combineVersionAndSourcefile(repository.getFullName(), primaryDescriptorFile, workflow, identifiedType, version, existingDefaults);
if (testParameterPaths != null) {
List<String> missingParamFiles = new ArrayList<>();
for (String testParameterPath : testParameterPaths) {
// Only add test parameter file if it hasn't already been added
boolean hasDuplicate = version.getSourceFiles().stream().anyMatch((SourceFile sf) -> sf.getPath().equals(testParameterPath) && sf.getType() == workflow.getDescriptorType().getTestParamType());
if (hasDuplicate) {
continue;
}
String testFileContent = this.readFileFromRepo(testParameterPath, ref.getLeft(), repository);
if (testFileContent != null) {
SourceFile testFile = new SourceFile();
// find type from file type
testFile.setType(workflow.getDescriptorType().getTestParamType());
testFile.setPath(testParameterPath);
testFile.setAbsolutePath(testParameterPath);
testFile.setContent(testFileContent);
version.getSourceFiles().add(testFile);
} else {
missingParamFiles.add(testParameterPath);
}
}
if (missingParamFiles.size() > 0) {
validationMessage.put(DOCKSTORE_YML_PATH, String.format("%s: %s.", missingParamFiles.size() == 1 ? "The following file is missing" : "The following files are missing", missingParamFiles.stream().map(paramFile -> String.format("'%s'", paramFile)).collect(Collectors.joining(", "))));
}
}
} else {
// File not found or null
LOG.info("Could not find the file " + primaryDescriptorPath + " in repo " + repository);
validationMessage.put(DOCKSTORE_YML_PATH, "Could not find the primary descriptor file '" + primaryDescriptorPath + "'.");
}
VersionTypeValidation dockstoreYmlValidationMessage = new VersionTypeValidation(validationMessage.isEmpty(), validationMessage);
Validation dockstoreYmlValidation = new Validation(DescriptorLanguage.FileType.DOCKSTORE_YML, dockstoreYmlValidationMessage);
version.addOrUpdateValidation(dockstoreYmlValidation);
return version;
}
use of io.dockstore.common.VersionTypeValidation in project dockstore by dockstore.
the class SourceCodeRepoInterface method versionValidation.
/**
* Returns a workflow version with validation information updated
* @param version Version to validate
* @param entry Entry containing version to validate
* @param mainDescriptorPath Descriptor path to validate
* @return Workflow version with validation information
*/
public WorkflowVersion versionValidation(WorkflowVersion version, Workflow entry, String mainDescriptorPath) {
Set<SourceFile> sourceFiles = version.getSourceFiles();
DescriptorLanguage.FileType identifiedType = entry.getFileType();
Optional<SourceFile> mainDescriptor = sourceFiles.stream().filter((sourceFile -> Objects.equals(sourceFile.getPath(), mainDescriptorPath))).findFirst();
// Validate descriptor set
if (mainDescriptor.isPresent()) {
VersionTypeValidation validDescriptorSet = LanguageHandlerFactory.getInterface(identifiedType).validateWorkflowSet(sourceFiles, mainDescriptorPath);
Validation descriptorValidation = new Validation(identifiedType, validDescriptorSet);
version.addOrUpdateValidation(descriptorValidation);
} else {
Map<String, String> validationMessage = new HashMap<>();
validationMessage.put(mainDescriptorPath, "Missing the primary descriptor.");
VersionTypeValidation noPrimaryDescriptor = new VersionTypeValidation(false, validationMessage);
Validation noPrimaryDescriptorValidation = new Validation(identifiedType, noPrimaryDescriptor);
version.addOrUpdateValidation(noPrimaryDescriptorValidation);
}
// Validate test parameter set
VersionTypeValidation validTestParameterSet = LanguageHandlerFactory.getInterface(identifiedType).validateTestParameterSet(sourceFiles);
Validation testParameterValidation = new Validation(entry.getTestParameterType(), validTestParameterSet);
version.addOrUpdateValidation(testParameterValidation);
version.setValid(isValidVersion(version));
return version;
}
use of io.dockstore.common.VersionTypeValidation in project dockstore-galaxy-interface by galaxyproject.
the class GalaxyWorkflowLanguagePluginTest method testNativeWorkflowParsing.
@Test
public void testNativeWorkflowParsing() {
final GalaxyWorkflowPlugin.GalaxyWorkflowPluginImpl plugin = new GalaxyWorkflowPlugin.GalaxyWorkflowPluginImpl();
final HttpFileReader reader = new HttpFileReader(REPO_NATIVE);
final String initialPath = EXAMPLE_FILENAME_NATIVE_PATH;
final String contents = reader.readFile(EXAMPLE_FILENAME_NATIVE);
final Map<String, Pair<String, MinimalLanguageInterface.GenericFileType>> fileMap = plugin.indexWorkflowFiles(initialPath, contents, reader);
Assert.assertEquals(1, fileMap.size());
final Pair<String, MinimalLanguageInterface.GenericFileType> discoveredFile = fileMap.get("/Dockstore-test.yml");
Assert.assertEquals(discoveredFile.getRight(), MinimalLanguageInterface.GenericFileType.TEST_PARAMETER_FILE);
final RecommendedLanguageInterface.WorkflowMetadata metadata = plugin.parseWorkflowForMetadata(initialPath, contents, fileMap);
// We don't track these currently - especially with native format.
Assert.assertNull(metadata.getAuthor());
Assert.assertNull(metadata.getEmail());
Assert.assertEquals("This is the documentation for the workflow.", metadata.getDescription());
final VersionTypeValidation wfValidation = plugin.validateWorkflowSet(initialPath, contents, fileMap);
Assert.assertTrue(wfValidation.isValid());
// No validation messages because everything is fine...
Assert.assertTrue(wfValidation.getMessage().isEmpty());
final Map<String, Object> cytoscapeElements = plugin.loadCytoscapeElements(initialPath, contents, fileMap);
// do a sanity check for a valid cytoscape JSON
// http://manual.cytoscape.org/en/stable/Supported_Network_File_Formats.html#cytoscape-js-json
Assert.assertTrue(cytoscapeElements.containsKey("nodes") && cytoscapeElements.containsKey("edges"));
final List<CompleteLanguageInterface.RowData> rowData = plugin.generateToolsTable(initialPath, contents, fileMap);
Assert.assertFalse(rowData.isEmpty());
}
Aggregations