Search in sources :

Example 1 with VersionTypeValidation

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());
}
Also used : DescriptorLanguage(io.dockstore.common.DescriptorLanguage) BoundedInputStream(org.apache.commons.io.input.BoundedInputStream) VersionTypeValidation(io.dockstore.common.VersionTypeValidation) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) HttpStatus(org.apache.http.HttpStatus) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) SourceFile(io.dockstore.webservice.core.SourceFile) ArrayList(java.util.ArrayList) LanguageHandlerHelper(io.dockstore.common.LanguageHandlerHelper) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) DescriptionSource(io.dockstore.webservice.core.DescriptionSource) Strings(com.google.common.base.Strings) Matcher(java.util.regex.Matcher) Files(com.google.common.io.Files) Map(java.util.Map) DockerParameter(io.dockstore.common.DockerParameter) ParseException(java.text.ParseException) NoSuchElementException(java.util.NoSuchElementException) LexerException(com.github.zafarkhaja.semver.expr.LexerException) ToolDAO(io.dockstore.webservice.jdbi.ToolDAO) Logger(org.slf4j.Logger) WdlParser(wdl.draft3.parser.WdlParser) UnexpectedCharacterException(com.github.zafarkhaja.semver.UnexpectedCharacterException) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) SourceCodeRepoInterface(io.dockstore.webservice.helpers.SourceCodeRepoInterface) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) ParsedInformation(io.dockstore.webservice.core.ParsedInformation) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) DockerImageReference(io.dockstore.common.DockerImageReference) UnexpectedTokenException(com.github.zafarkhaja.semver.expr.UnexpectedTokenException) Version(io.dockstore.webservice.core.Version) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) WdlBridge(io.dockstore.common.WdlBridge) Collections(java.util.Collections) InputStream(java.io.InputStream) Validation(io.dockstore.webservice.core.Validation) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) WdlBridge(io.dockstore.common.WdlBridge) ArrayList(java.util.ArrayList) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) IOException(java.io.IOException) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) ParseException(java.text.ParseException) NoSuchElementException(java.util.NoSuchElementException) LexerException(com.github.zafarkhaja.semver.expr.LexerException) UnexpectedCharacterException(com.github.zafarkhaja.semver.UnexpectedCharacterException) IOException(java.io.IOException) UnexpectedTokenException(com.github.zafarkhaja.semver.expr.UnexpectedTokenException) SourceFile(io.dockstore.webservice.core.SourceFile) VersionTypeValidation(io.dockstore.common.VersionTypeValidation) SourceFile(io.dockstore.webservice.core.SourceFile) File(java.io.File)

Example 2 with VersionTypeValidation

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;
}
Also used : VersionTypeValidation(io.dockstore.common.VersionTypeValidation) Validation(io.dockstore.webservice.core.Validation) SourceFile(io.dockstore.webservice.core.SourceFile) VersionTypeValidation(io.dockstore.common.VersionTypeValidation)

Example 3 with VersionTypeValidation

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;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) WorkflowVersion(io.dockstore.webservice.core.WorkflowVersion) Arrays(java.util.Arrays) GHRepository(org.kohsuke.github.GHRepository) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) HttpStatus(org.apache.http.HttpStatus) StringUtils(org.apache.commons.lang3.StringUtils) SourceFile(io.dockstore.webservice.core.SourceFile) GitHubBuilder(org.kohsuke.github.GitHubBuilder) Matcher(java.util.regex.Matcher) GHBranch(org.kohsuke.github.GHBranch) YamlWorkflow(io.dockstore.common.yaml.YamlWorkflow) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) TokenType(io.dockstore.webservice.core.TokenType) User(io.dockstore.webservice.core.User) Triple(org.apache.commons.lang3.tuple.Triple) GitHub(org.kohsuke.github.GitHub) SKIP_COMMIT_ID(io.dockstore.webservice.Constants.SKIP_COMMIT_ID) GHContent(org.kohsuke.github.GHContent) Service(io.dockstore.webservice.core.Service) LAMBDA_FAILURE(io.dockstore.webservice.Constants.LAMBDA_FAILURE) Set(java.util.Set) Instant(java.time.Instant) Tool(io.dockstore.webservice.core.Tool) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) ImpatientHttpConnector(org.kohsuke.github.extras.ImpatientHttpConnector) DOCKSTORE_YML_PATH(io.dockstore.webservice.Constants.DOCKSTORE_YML_PATH) Objects(java.util.Objects) List(java.util.List) HttpConnector(org.kohsuke.github.HttpConnector) BioWorkflow(io.dockstore.webservice.core.BioWorkflow) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) CacheHitListener(io.dockstore.webservice.CacheHitListener) GHRateLimit(org.kohsuke.github.GHRateLimit) FilenameUtils(org.apache.commons.io.FilenameUtils) GHCommit(org.kohsuke.github.GHCommit) Joiner(com.google.common.base.Joiner) Validation(io.dockstore.webservice.core.Validation) DescriptorLanguage(io.dockstore.common.DescriptorLanguage) VersionTypeValidation(io.dockstore.common.VersionTypeValidation) RateLimitHandler(org.kohsuke.github.RateLimitHandler) WorkflowMode(io.dockstore.webservice.core.WorkflowMode) HashMap(java.util.HashMap) ArrayUtils(org.apache.commons.lang3.ArrayUtils) GHFileNotFoundException(org.kohsuke.github.GHFileNotFoundException) AbuseLimitHandler(org.kohsuke.github.AbuseLimitHandler) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) LicenseInformation(io.dockstore.webservice.core.LicenseInformation) GHUser(org.kohsuke.github.GHUser) SourceControl(io.dockstore.common.SourceControl) GHEmail(org.kohsuke.github.GHEmail) GHMyself(org.kohsuke.github.GHMyself) Token(io.dockstore.webservice.core.Token) Workflow(io.dockstore.webservice.core.Workflow) GHRef(org.kohsuke.github.GHRef) DockstoreYaml12(io.dockstore.common.yaml.DockstoreYaml12) DockstoreYamlHelper(io.dockstore.common.yaml.DockstoreYamlHelper) Logger(org.slf4j.Logger) SourceControlOrganization(io.dockstore.webservice.core.SourceControlOrganization) DOCKSTORE_YML_PATHS(io.dockstore.webservice.Constants.DOCKSTORE_YML_PATHS) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) DescriptorLanguageSubclass(io.dockstore.common.DescriptorLanguageSubclass) DockstoreWebserviceApplication(io.dockstore.webservice.DockstoreWebserviceApplication) IOException(java.io.IOException) OkHttpClient(okhttp3.OkHttpClient) Version(io.dockstore.webservice.core.Version) Entry(io.dockstore.webservice.core.Entry) TokenDAO(io.dockstore.webservice.jdbi.TokenDAO) ObsoleteUrlFactory(org.kohsuke.github.extras.okhttp3.ObsoleteUrlFactory) Service12(io.dockstore.common.yaml.Service12) Validation(io.dockstore.webservice.core.Validation) VersionTypeValidation(io.dockstore.common.VersionTypeValidation) YamlWorkflow(io.dockstore.common.yaml.YamlWorkflow) DockstoreYaml12(io.dockstore.common.yaml.DockstoreYaml12) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DescriptorLanguage(io.dockstore.common.DescriptorLanguage) DockstoreYamlHelper(io.dockstore.common.yaml.DockstoreYamlHelper) SourceFile(io.dockstore.webservice.core.SourceFile) VersionTypeValidation(io.dockstore.common.VersionTypeValidation)

Example 4 with VersionTypeValidation

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;
}
Also used : VersionTypeValidation(io.dockstore.common.VersionTypeValidation) Validation(io.dockstore.webservice.core.Validation) HashMap(java.util.HashMap) DescriptorLanguage(io.dockstore.common.DescriptorLanguage) SourceFile(io.dockstore.webservice.core.SourceFile) VersionTypeValidation(io.dockstore.common.VersionTypeValidation)

Example 5 with VersionTypeValidation

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());
}
Also used : RecommendedLanguageInterface(io.dockstore.language.RecommendedLanguageInterface) MinimalLanguageInterface(io.dockstore.language.MinimalLanguageInterface) VersionTypeValidation(io.dockstore.common.VersionTypeValidation) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Aggregations

VersionTypeValidation (io.dockstore.common.VersionTypeValidation)18 SourceFile (io.dockstore.webservice.core.SourceFile)12 HashMap (java.util.HashMap)10 CustomWebApplicationException (io.dockstore.webservice.CustomWebApplicationException)9 DescriptorLanguage (io.dockstore.common.DescriptorLanguage)8 Validation (io.dockstore.webservice.core.Validation)8 Pair (org.apache.commons.lang3.tuple.Pair)6 Test (org.junit.Test)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 MinimalLanguageInterface (io.dockstore.language.MinimalLanguageInterface)4 RecommendedLanguageInterface (io.dockstore.language.RecommendedLanguageInterface)4 List (java.util.List)4 Map (java.util.Map)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 HashSet (java.util.HashSet)3 Yaml (org.yaml.snakeyaml.Yaml)3