Skip to content

Commit

Permalink
Feature/support hosted galaxy (#968)
Browse files Browse the repository at this point in the history
* Support hosted galaxy workflows

* Simplify some extendedDescriptorLanguageBean functions

* Use language default descriptor path

* Heavy refactor, little logic change

* Use Sourcefile type

* Strict null check

* Fix primary descriptor Galaxy check

* Handle Galaxy primary descriptor
  • Loading branch information
garyluu authored Apr 27, 2020
1 parent d6a6ebd commit 05264c5
Show file tree
Hide file tree
Showing 10 changed files with 615 additions and 236 deletions.
33 changes: 20 additions & 13 deletions src/app/entry/extendedDescriptorLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ export interface ExtendedDescriptorLanguageBean extends DescriptorLanguageBean {
toolDescriptorEnum: ToolDescriptor.TypeEnum;
workflowDescriptorEnum: Workflow.DescriptorTypeEnum;
plainTRS: string;
sourceFileTypeEnum: SourceFile.TypeEnum[];
descriptorFileTypes: SourceFile.TypeEnum[];
toolTab: {
// Example: If rowIdentifier is "tool ID", then the the first column of each row will say something like "tool ID: hello-world"
rowIdentifier: string;
// This is the header that goes in the second column of the tool tab table (Example: Tool Excerpt)
workflowStepHeader: string;
};
workflowLaunchSupport: boolean;
testParameterFileType: SourceFile.TypeEnum;
}

const extendedCWL: ExtendedDescriptorLanguageBean = {
Expand All @@ -31,12 +32,13 @@ const extendedCWL: ExtendedDescriptorLanguageBean = {
toolDescriptorEnum: ToolDescriptor.TypeEnum.CWL,
workflowDescriptorEnum: Workflow.DescriptorTypeEnum.CWL,
plainTRS: 'PLAIN-CWL',
sourceFileTypeEnum: [SourceFile.TypeEnum.DOCKSTORECWL],
descriptorFileTypes: [SourceFile.TypeEnum.DOCKSTORECWL],
toolTab: {
rowIdentifier: 'tool\xa0ID',
workflowStepHeader: 'Tool Excerpt'
},
workflowLaunchSupport: true
workflowLaunchSupport: true,
testParameterFileType: SourceFile.TypeEnum.CWLTESTJSON
};

const extendedWDL: ExtendedDescriptorLanguageBean = {
Expand All @@ -49,12 +51,13 @@ const extendedWDL: ExtendedDescriptorLanguageBean = {
toolDescriptorEnum: ToolDescriptor.TypeEnum.WDL,
workflowDescriptorEnum: Workflow.DescriptorTypeEnum.WDL,
plainTRS: 'PLAIN-WDL',
sourceFileTypeEnum: [SourceFile.TypeEnum.DOCKSTOREWDL],
descriptorFileTypes: [SourceFile.TypeEnum.DOCKSTOREWDL],
toolTab: {
rowIdentifier: 'task\xa0ID',
workflowStepHeader: 'Task Excerpt'
},
workflowLaunchSupport: true
workflowLaunchSupport: true,
testParameterFileType: SourceFile.TypeEnum.WDLTESTJSON
};

const extendedNFL: ExtendedDescriptorLanguageBean = {
Expand All @@ -67,12 +70,13 @@ const extendedNFL: ExtendedDescriptorLanguageBean = {
toolDescriptorEnum: ToolDescriptor.TypeEnum.NFL,
workflowDescriptorEnum: Workflow.DescriptorTypeEnum.NFL,
plainTRS: 'PLAIN-NFL',
sourceFileTypeEnum: [SourceFile.TypeEnum.NEXTFLOW, SourceFile.TypeEnum.NEXTFLOWCONFIG],
descriptorFileTypes: [SourceFile.TypeEnum.NEXTFLOW, SourceFile.TypeEnum.NEXTFLOWCONFIG],
toolTab: {
rowIdentifier: 'process\xa0name',
workflowStepHeader: 'Process Excerpt'
},
workflowLaunchSupport: true
workflowLaunchSupport: true,
testParameterFileType: SourceFile.TypeEnum.NEXTFLOWTESTPARAMS
};

const extendedService: ExtendedDescriptorLanguageBean = {
Expand All @@ -86,12 +90,13 @@ const extendedService: ExtendedDescriptorLanguageBean = {
toolDescriptorEnum: ToolDescriptor.TypeEnum.SERVICE,
workflowDescriptorEnum: Workflow.DescriptorTypeEnum.Service,
plainTRS: 'PLAIN-SERVICE',
sourceFileTypeEnum: [],
descriptorFileTypes: [],
toolTab: {
rowIdentifier: 'tool\xa0ID',
workflowStepHeader: 'Service'
},
workflowLaunchSupport: true
workflowLaunchSupport: true,
testParameterFileType: SourceFile.TypeEnum.DOCKSTORESERVICETESTJSON
};

const extendedGalaxy: ExtendedDescriptorLanguageBean = {
Expand All @@ -104,12 +109,13 @@ const extendedGalaxy: ExtendedDescriptorLanguageBean = {
toolDescriptorEnum: ToolDescriptor.TypeEnum.GXFORMAT2,
workflowDescriptorEnum: Workflow.DescriptorTypeEnum.Gxformat2,
plainTRS: '<FILL-IN>',
sourceFileTypeEnum: [SourceFile.TypeEnum.DOCKSTOREGXFORMAT2],
descriptorFileTypes: [SourceFile.TypeEnum.DOCKSTOREGXFORMAT2],
toolTab: {
rowIdentifier: 'tool\xa0ID',
workflowStepHeader: 'Tool Excerpt'
},
workflowLaunchSupport: false
workflowLaunchSupport: false,
testParameterFileType: SourceFile.TypeEnum.GXFORMAT2TESTFILE
};

export const extendedUnknownDescriptor: ExtendedDescriptorLanguageBean = {
Expand All @@ -122,12 +128,13 @@ export const extendedUnknownDescriptor: ExtendedDescriptorLanguageBean = {
toolDescriptorEnum: null,
workflowDescriptorEnum: null,
plainTRS: null,
sourceFileTypeEnum: [],
descriptorFileTypes: [],
toolTab: {
rowIdentifier: 'tool\xa0ID',
workflowStepHeader: 'Tool Excerpt'
},
workflowLaunchSupport: false
workflowLaunchSupport: false,
testParameterFileType: null
};
export const extendedDescriptorLanguages: ExtendedDescriptorLanguageBean[] = [
extendedCWL,
Expand Down
175 changes: 24 additions & 151 deletions src/app/shared/code-editor-list/code-editor-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@ import { Component, Input } from '@angular/core';
import { Observable } from 'rxjs';

import { WorkflowQuery } from '../state/workflow.query';
import { SourceFile } from '../swagger';
import { ToolDescriptor } from './../../shared/swagger/model/toolDescriptor';
import { WorkflowVersion } from './../../shared/swagger/model/workflowVersion';
import { CodeEditorListService } from './code-editor-list.service';

export type FileCategory = 'descriptor' | 'dockerfile' | 'testParam';

@Component({
selector: 'app-code-editor-list',
templateUrl: './code-editor-list.component.html',
styleUrls: ['./code-editor-list.component.scss']
})
export class CodeEditorListComponent {
@Input() sourcefiles: Array<any>;
@Input() sourcefiles: SourceFile[];
@Input() editing: boolean;
@Input() fileType: string;
@Input() fileType: FileCategory;
@Input() descriptorType: ToolDescriptor.TypeEnum;
@Input() entryType: string;
@Input() entrypath: string;
@Input() selectedVersion: WorkflowVersion;
protected published$: Observable<boolean>;
public downloadFilePath: string;
NEXTFLOW_CONFIG_PATH = '/nextflow.config';
NEXTFLOW_PATH = '/main.nf';
public DescriptorType = ToolDescriptor.TypeEnum;

constructor(private workflowQuery: WorkflowQuery) {
Expand All @@ -32,21 +34,12 @@ export class CodeEditorListComponent {
* Adds a new file editor
*/
addFile() {
const filesToAdd = [];
const newFilePath = this.getDefaultPath();
if (!this.hasPrimaryDescriptor() && this.fileType === 'descriptor') {
if (this.descriptorType === ToolDescriptor.TypeEnum.NFL) {
filesToAdd.push(this.createFileObject(this.NEXTFLOW_PATH));
filesToAdd.push(this.createFileObject(this.NEXTFLOW_CONFIG_PATH));
} else {
filesToAdd.push(this.createFileObject('/Dockstore' + newFilePath));
}
} else if (!this.hasPrimaryTestParam() && this.fileType === 'testParam') {
filesToAdd.push(this.createFileObject('/test.' + this.descriptorType.toLowerCase() + newFilePath));
} else {
filesToAdd.push(this.createFileObject('/' + newFilePath));
let descriptorType = this.descriptorType;
// determineFilesToAdd gets really confusing when it needs to handle a falsey descriptorType, setting it here (no end effect)
if (this.fileType === 'dockerfile') {
descriptorType = ToolDescriptor.TypeEnum.CWL;
}

const filesToAdd = CodeEditorListService.determineFilesToAdd(descriptorType, this.fileType, this.sourcefiles);
if (this.sourcefiles === undefined) {
this.sourcefiles = [];
}
Expand All @@ -55,14 +48,6 @@ export class CodeEditorListComponent {
});
}

createFileObject(newFilePath) {
return {
content: '',
path: newFilePath,
type: this.getFileType(newFilePath)
};
}

/**
* Deletes the file at the given index by setting content to null.
* If it is a new file being deleted (not from previous version) then just remove from the list
Expand All @@ -76,148 +61,36 @@ export class CodeEditorListComponent {
}

/**
* Get the file type enum
* @return {string} The file type enum
*/
getFileType(filepath) {
if (this.fileType === 'descriptor') {
if (this.descriptorType) {
if (this.descriptorType === ToolDescriptor.TypeEnum.NFL) {
if (filepath === this.NEXTFLOW_CONFIG_PATH) {
return 'NEXTFLOW_CONFIG';
} else {
return 'NEXTFLOW';
}
} else {
return 'DOCKSTORE_' + this.descriptorType;
}
} else {
return 'DOCKSTORE_CWL';
}
} else if (this.fileType === 'testParam') {
if (this.descriptorType) {
if (this.descriptorType === ToolDescriptor.TypeEnum.NFL) {
return 'NEXTFLOW_TEST_PARAMS';
} else {
return this.descriptorType + '_TEST_JSON';
}
} else {
return 'CWL_TEST_JSON';
}
} else if (this.fileType === 'dockerfile') {
return 'DOCKERFILE';
} else {
return null;
}
}

/**
* Get the default path extension
* @return {string}the default path extension
*/
getDefaultPath() {
if (this.fileType === 'descriptor') {
if (this.descriptorType) {
if (this.descriptorType === this.DescriptorType.NFL) {
return '.nf';
} else {
return '.' + this.descriptorType.toLowerCase();
}
} else {
return '.cwl';
}
} else if (this.fileType === 'testParam') {
return '.json';
} else if (this.fileType === 'dockerfile') {
return 'Dockerfile';
}
}

/**
* TODO: Fix the execution of this function. This function is being executed a bajillion times.
* Returns true if path is the primary descriptor, false otherwise
* @param path Path to check
* @return {boolean} Is path for primary descriptor
*
* @param {string} path Path to check
* @returns {boolean} Is path for primary descriptor
* @memberof CodeEditorListComponent
*/
isPrimaryDescriptor(path: string): boolean {
return path === '/Dockstore.cwl' || path === '/Dockstore.wdl' || path === this.NEXTFLOW_CONFIG_PATH || path === this.NEXTFLOW_PATH;
return this.fileType === 'descriptor' && CodeEditorListService.isPrimaryDescriptor(path);
}

/**
* TODO: Fix the execution of this function. This function is being executed a bajillion times.
* Returns true if path is the dockerfile, false otherwise
* @param path Path to check
* @return {boolean} Is path for dockerfile
*/
isDockerFile(path: string): boolean {
return path === '/Dockerfile';
return this.fileType === 'dockerfile' && path === '/Dockerfile';
}

/**
* TODO: Fix this execution of this function. This function is being executed a bajillion times
* TODO: Fix the execution of this function. This function is being executed a bajillion times.
* Determines whether to show the current sourcefile based on the descriptor type and tab
* @param type sourcefile type
* @return {boolean} whether or not to show file
*/
showSourcefile(type: string): boolean {
if (type === null || type === undefined) {
return true;
} else if (this.fileType === 'dockerfile') {
return true;
} else if (this.fileType === 'descriptor') {
return (
(this.descriptorType === ToolDescriptor.TypeEnum.CWL && type === 'DOCKSTORE_CWL') ||
(this.descriptorType === ToolDescriptor.TypeEnum.WDL && type === 'DOCKSTORE_WDL') ||
(this.descriptorType === ToolDescriptor.TypeEnum.NFL && (type === 'NEXTFLOW' || type === 'NEXTFLOW_CONFIG'))
);
} else if (this.fileType === 'testParam') {
return (
(this.descriptorType === ToolDescriptor.TypeEnum.CWL && type === 'CWL_TEST_JSON') ||
(this.descriptorType === ToolDescriptor.TypeEnum.WDL && type === 'WDL_TEST_JSON') ||
(this.descriptorType === ToolDescriptor.TypeEnum.NFL && type === 'NEXTFLOW_TEST_PARAMS')
);
} else {
return true;
}
}

/**
* Checks for the given descriptor type, does there already exist a primary descriptor
* @return {boolean} whether or not version has a primary descriptor
*/
hasPrimaryDescriptor(): boolean {
if (this.descriptorType === null || this.descriptorType === undefined) {
return false;
}

const pathToFind = '/Dockstore.' + this.descriptorType.toLowerCase();
if (this.descriptorType === ToolDescriptor.TypeEnum.NFL) {
return this.hasFilePath(this.NEXTFLOW_PATH) && this.hasFilePath(this.NEXTFLOW_CONFIG_PATH);
}
return this.hasFilePath(pathToFind);
}

/**
* Checks for the given descriptor type, does there already exist a primary test json
* @return {boolean} whether or not version has a primary test json
*/
hasPrimaryTestParam(): boolean {
if (this.descriptorType === null || this.descriptorType === undefined) {
return false;
}
const pathToFind = 'test.' + this.descriptorType.toLowerCase() + '.json';
return this.hasFilePath(pathToFind);
}

/**
* Determines if there exists a sourcefile with the given file path
* @param path File path to look for
* @return {boolean} Whether a sourcefile with the path exists
*/
hasFilePath(path: string): boolean {
for (const sourcefile of this.sourcefiles) {
if (sourcefile.path === path) {
return true;
}
}
return false;
showSourcefile(type: SourceFile.TypeEnum): boolean {
const fileType = this.fileType;
const descriptorType = this.descriptorType;
return CodeEditorListService.showSourcefile(type, fileType, descriptorType);
}
}
Loading

0 comments on commit 05264c5

Please sign in to comment.