Skip to content
This repository has been archived by the owner on Apr 5, 2018. It is now read-only.

Commit

Permalink
Feature/dockstore 193 entry validation (#52)
Browse files Browse the repository at this point in the history
* validation check on tool and workflow

* fixed typos

* refactor validation check code

* added cwl tool & workflow check

there will be error shown if the repo has cwl tool inside 'My Workflow' section,
and same thing with cwl workflow file in 'My Tool' section. This does not apply to WDL,
since WDL can only be workflow

* get rid of unused functions
  • Loading branch information
Janice Patricia authored and denis-yuen committed Jun 20, 2016
1 parent 7e2b0b3 commit 55359d9
Show file tree
Hide file tree
Showing 9 changed files with 324 additions and 47 deletions.
71 changes: 70 additions & 1 deletion app/scripts/controllers/containerdetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ angular.module('dockstore.ui')
$scope.labelsEditMode = false;
$scope.dockerfileEnabled = false;
$scope.descriptorEnabled = false;
$scope.validContent = true;
$scope.missingContent = [];
$scope.missingWarning = false;
$scope.invalidClass = false;
$scope.showEditCWL = true;
$scope.showEditWDL = true;
$scope.showEditDockerfile = true;
Expand Down Expand Up @@ -126,6 +130,52 @@ angular.module('dockstore.ui')
});
};

$scope.checkContentValid = function(){
//will print this when the 'Publish' button is clicked
var message = 'The file is missing some required fields. Please make sure the file has all the required fields. ';
var missingMessage = 'The missing field(s):'
if($scope.validContent){
if($scope.missingContent.length !== 0){
$scope.missingWarning = true;
}
return true;

} else{
if($scope.missingContent.length !== 0){
$scope.missingWarning = false;
for(var i=0;i<$scope.missingContent.length;i++){
missingMessage += ' \''+$scope.missingContent[i]+'\'';
if(i!=$scope.missingContent.length -1){
missingMessage+=',';
}
}
if(!$scope.refreshingWorkflow){
if($scope.containerObj.descriptorType === 'wdl'){
$scope.setContainerDetailsError(
message+missingMessage +
'. Required fields in WDL file: \'task\', \'workflow\', \'call\', \'command\', and \'output\'',''
);
}else{
$scope.setContainerDetailsError(
message+missingMessage +
'. Required fields in CWL Tool file: \'inputs\', \'outputs\', \'class: CommandLineTool\', and \'baseCommand\'',''
);
}
}
}

if($scope.invalidClass){
//file is invalid because class is workflow instead of commandlinetool
$scope.setContainerDetailsError(
'This CWL file is not a CommandLineTool'+
'. Required fields in CWL Tool file: \'inputs\', \'outputs\', \'class: CommandLineTool\', and \'baseCommand\'',''
);
}

return false;
}
};

$scope.setDefaultCWLPath = function(containerId, cwlpath){
var wdlpath = $scope.containerObj.default_wdl_path;
var dfpath = $scope.containerObj.default_dockerfile_path;
Expand Down Expand Up @@ -393,6 +443,25 @@ angular.module('dockstore.ui')
}
};

$scope.isContainerValid = function() {
if ($scope.containerObj.is_published) {
return true;
}

var versionTags = $scope.containerObj.tags;

if (versionTags === null) {
return false;
}

for (var i = 0; i < versionTags.length; i++) {
if (versionTags[i].valid) {
return true;
}
}
return false;
};

$scope.$watch('containerPath', function(newValue, oldValue) {
if (newValue) {
$scope.setContainerDetailsError(null);
Expand All @@ -413,4 +482,4 @@ angular.module('dockstore.ui')
if (newValue) $scope.updateInfoURLs();
});

}]);
}]);
71 changes: 67 additions & 4 deletions app/scripts/controllers/containerfileviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,38 @@
*/
angular.module('dockstore.ui')
.controller('ContainerFileViewerCtrl', [
'$scope',
'$scope',
'$q',
'ContainerService',
'NotificationService',
function ($scope, $q, ContainerService, NtfnService) {
function ($scope, $q, ContainerService, NtfnService) {

var descriptors = ["cwl", "wdl"];

$scope.fileLoaded = false;
$scope.fileContents = null;
$scope.successContent = [];
$scope.fileContent = null;

$scope.checkDescriptor = function() {
$scope.containerTags = $scope.getContainerTags();
$scope.successContent = [];
$scope.fileContent = null;
var accumulator = [];
var index = 0;
var m = [];
var v = false;
var invalidClass = false;
var count = 0;
var cwlFields = ["inputs","outputs","baseCommand","class"];
var wdlFields = ["task","output","workflow","command","call"];
for (var i=0; i<$scope.containerTags.length; i++) {
for (var j=0; j<descriptors.length; j++) {
accumulator[index] = {tag: $scope.containerTags[i], desc: descriptors[j]};
accumulator[index] = {
tag: $scope.containerTags[i],
desc: descriptors[j],
content: null
};
index++;
};
};
Expand All @@ -39,7 +51,11 @@ angular.module('dockstore.ui')
function filePromise(vd){
return $scope.getDescriptorFile($scope.containerObj.id, vd.tag, vd.desc).then(
function(s){
$scope.successContent.push({tag:vd.tag,descriptor:vd.desc});
$scope.successContent.push({
tag:vd.tag,
descriptor:vd.desc,
content:s
});
if(start+1 === acc.length) {
return {success: true, index:start};
} else{
Expand All @@ -66,6 +82,53 @@ angular.module('dockstore.ui')
function(result){
$scope.selTagName = $scope.successContent[0].tag;
$scope.selDescriptorName = $scope.successContent[0].descriptor;
$scope.fileContent = $scope.successContent[0].content;
var result = $scope.fileContent;
m = [];
v = false;
invalidClass = false;
count = 0;
if($scope.selDescriptorName === "cwl"){
//Descriptor: CWL
for(var i=0;i<cwlFields.length;i++){
if(result.search(cwlFields[i]) !==-1){
if(cwlFields[i] === 'class'){
if(result.search("CommandLineTool") === -1 && result.search("Workflow") !== -1){
//class is Workflow instead of CommandLineTool, this is invalid!
invalidClass = true;
break;
}
}
count++;
} else{
m.push(cwlFields[i]);
}
}

if(result.search("cwlVersion:")===-1){
m.push('cwlVersion');
}

if(count===4){
v = true;
}
$scope.$emit('invalidClass', invalidClass); //only for CWL
} else{
//Descriptor: WDL
for(var i=0;i<wdlFields.length;i++){
if(result.search(wdlFields[i]) !==-1){
count++;
} else{
m.push(wdlFields[i]);
}
}

if(count===5){
v = true;
}
}
$scope.$emit('returnMissing',m);
$scope.$emit('returnValid',v);
},
function(e){console.log("error",e)}
);
Expand Down
51 changes: 50 additions & 1 deletion app/scripts/controllers/workflowdetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ angular.module('dockstore.ui')

$scope.labelsEditMode = false;
$scope.descriptorEnabled = false;
$scope.validContent = true;
$scope.missingWarning = false;
$scope.invalidClass = false;
$scope.showEditWorkflowPath = true;
$scope.showEditDescriptorType = true;
if (!$scope.activeTabs) {
Expand Down Expand Up @@ -103,6 +106,52 @@ angular.module('dockstore.ui')
});
};

$scope.checkContentValid = function(){
//will print this when the 'Publish' button is clicked
var message = 'The file is missing some required fields. Please make sure the file has all the required fields. ';
var missingMessage = 'The missing field(s):'
if($scope.validContent){
if($scope.missingContent.length !== 0){
$scope.missingWarning = true;
}
return true;

} else{
if($scope.missingContent.length !== 0){
$scope.missingWarning = false;
for(var i=0;i<$scope.missingContent.length;i++){
missingMessage += ' \''+$scope.missingContent[i]+'\'';
if(i!=$scope.missingContent.length -1){
missingMessage+=',';
}
}
if(!$scope.refreshingWorkflow){
if($scope.workflowObj.descriptorType === 'wdl'){
$scope.setWorkflowDetailsError(
message+missingMessage +
'. Required fields in WDL file: \'task\', \'workflow\', \'call\', \'command\', and \'output\'',''
);
}else{
$scope.setWorkflowDetailsError(
message+missingMessage +
'. Required fields in CWL Workflow file: \'inputs\', \'outputs\', \'class: Workflow\', and \'steps\'',''
);
}
}
}

if($scope.invalidClass){
//file is invalid because class is commandLineTool instead of Workflow
$scope.setContainerDetailsError(
'This CWL file is not a Workflow'+
'. Required fields in CWL Workflow file: \'inputs\', \'outputs\', \'class: Workflow\', and \'steps\'',''
);
}

return false;
}
};

$scope.setDefaultWorkflowPath = function(workflowId, path){
return WorkflowService.setDefaultWorkflowPath(workflowId, path, $scope.workflowObj.workflowName, $scope.workflowObj.descriptorType,
$scope.workflowObj.path, $scope.workflowObj.gitUrl)
Expand Down Expand Up @@ -267,7 +316,7 @@ angular.module('dockstore.ui')
$scope.labelsEditMode = !$scope.labelsEditMode;
};

$scope.submitWorkflowPathEdits = function(type){
$scope.submitWorkflowPathEdits = function(){
if($scope.workflowObj.workflow_path !== 'undefined'){
$scope.setDefaultWorkflowPath($scope.workflowObj.id,
$scope.workflowObj.workflow_path)
Expand Down
Loading

0 comments on commit 55359d9

Please sign in to comment.