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

Commit

Permalink
Added default definition for datasetName
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan271 committed Dec 21, 2018
1 parent 4aa0218 commit c0e21a4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
14 changes: 14 additions & 0 deletions common/models/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ module.exports = function (Dataset) {
}
ctx.instance.version = p.version;

// sourceFolder handling
if(ctx.instance.sourceFolder){
// remove trailing slashes
ctx.instance.sourceFolder = ctx.instance.sourceFolder.replace(/\/$/, "");
// autofill datasetName
if (!ctx.instance.datasetName){
var arr=ctx.instance.sourceFolder.split("/")
if(arr.length == 1){
ctx.instance.datasetName=arr[0]
} else {
ctx.instance.datasetName=arr[arr.length-2]+"/"+arr[arr.length-1]
}
}
}

// auto fill classification
if (!ctx.instance.ownerGroup) {
Expand Down
4 changes: 2 additions & 2 deletions common/models/dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"type": "string",
"required": true,
"index": true,
"description": "Absolute file path on file server containing the files of this dataset, optionally including protocol and file server hostname, e.g. nfs://fileserver1.example.com/some/path/to/sourcefolder. In case of a single file dataset, e.g. HDF5 data it contains the path up to, but excluding the filename."
"description": "Absolute file path on file server containing the files of this dataset, optionally including protocol and file server hostname, e.g. nfs://fileserver1.example.com/some/path/to/sourcefolder. In case of a single file dataset, e.g. HDF5 data, it contains the path up to, but excluding the filename. Trailing slashes are removed."
},
"size": {
"type": "number",
Expand Down Expand Up @@ -80,7 +80,7 @@
},
"datasetName": {
"type": "string",
"description": "A name for the dataset, given by the creator to carry some semantic meaning. Useful for display purposes e.g. instead of displaying the pid"
"description": "A name for the dataset, given by the creator to carry some semantic meaning. Useful for display purposes e.g. instead of displaying the pid. Will be autofilled if missing using info from sourceFolder"
},
"userTargetLocation": {
"type": "string",
Expand Down
1 change: 1 addition & 0 deletions test/Dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('Simple Dataset tests', () => {
res.body.should.have.property('version').and.be.string;
res.body.should.have.property('type').and.equal('raw');
res.body.should.have.property('pid').and.be.string;
res.body.should.have.property('datasetName').and.be.string;
pid = encodeURIComponent(res.body['pid']);
done();
});
Expand Down

0 comments on commit c0e21a4

Please sign in to comment.