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

Commit

Permalink
Merge pull request #123 from SciCatProject/feature/autoFillProposalLink
Browse files Browse the repository at this point in the history
If no proposal is linked to rawdataset try to fill one by common ownership
  • Loading branch information
lukegorman authored Jan 8, 2019
2 parents 1c15c66 + 4b5ab89 commit a37cb7d
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 16 deletions.
4 changes: 2 additions & 2 deletions common/models/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ module.exports = function (Dataset) {
if (ctx.instance) {
if (ctx.isNewInstance) {
ctx.instance.pid = config.pidPrefix + '/' + ctx.instance.pid;
console.log(' new pid:', ctx.instance.pid);
console.log('New pid:', ctx.instance.pid);
} else {
console.log(' unmodified pid:', ctx.instance.pid);
console.log('Unmodified pid:', ctx.instance.pid);
}
ctx.instance.version = p.version;

Expand Down
17 changes: 16 additions & 1 deletion common/models/raw-dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
var utils = require('./utils');

module.exports = function(Rawdataset) {
var app = require('../../server/server');

Rawdataset.validatesUniquenessOf('pid');

// filter on dataset type (raw, derived etc)
Expand All @@ -25,7 +27,20 @@ module.exports = function(Rawdataset) {
if (ctx.instance) {
ctx.instance.type = 'raw';
}
next();
// check if proposal is linked, if not try to add one
if(!ctx.instance.proposalId){
var Proposal = app.models.Proposal
const filter = { where: { ownerGroup: ctx.instance.ownerGroup } };
Proposal.findOne(filter,ctx.options).then(instance => {
if(instance){
console.log("Appended Proposal "+instance.proposalId+" to rawdataset "+ctx.instance.pid)
ctx.instance.proposalId=instance.proposalId
}
return next()
})
} else {
return next()
}
});

// put
Expand Down
76 changes: 63 additions & 13 deletions test/RawDataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@ var request = require('supertest');
var should = chai.should();
var utils = require('./LoginUtils');

var accessToken = null,
pid = null;
var accessToken = null;
var pid = null;
var accessProposalToken = null;

var testproposal = {
"proposalId": "someprefix/20170266",
"email": "proposer%40uni.edu",
"title": "A test proposal",
"abstract": "Abstract of test proposal",
"ownerGroup": "p10029"
}

var testraw = {
"principalInvestigator": "[email protected]",
Expand Down Expand Up @@ -80,12 +89,13 @@ var testraw = {
"doi": "not yet defined",
"isPublished": false,
"ownerGroup": "p10029",
"accessGroups": [],
"proposalId": "10.540.16635/20110123"
"accessGroups": []
}

var app
before( function(){
var proposalId = null;

before(function () {
app = require('../server/server')
});

Expand All @@ -97,17 +107,42 @@ describe('RawDatasets', () => {
},
(tokenVal) => {
accessToken = tokenVal;
utils.getToken(app, {
'username': 'proposalIngestor',
'password': 'aman'
},
(tokenVal) => {
accessProposalToken = tokenVal;
done();
});
});
});

it('adds a new proposal', function (done) {
request(app)
.post('/api/v2/Proposals?access_token=' + accessProposalToken)
.send(testproposal)
.set('Accept', 'application/json')
.expect(200)
.expect('Content-Type', /json/)
.end(function (err, res) {
if (err)
return done(err);
res.body.should.have.property('ownerGroup').and.be.string;
res.body.should.have.property('proposalId').and.be.string;
proposalId = encodeURIComponent(res.body['proposalId']);
done();
});
});
it('adds a new raw dataset', function(done) {

it('adds a new raw dataset', function (done) {
request(app)
.post('/api/v2/RawDatasets?access_token=' + accessToken)
.send(testraw)
.set('Accept', 'application/json')
.expect(200)
.expect('Content-Type', /json/)
.end(function(err, res) {
.end(function (err, res) {
if (err)
return done(err);
res.body.should.have.property('owner').and.be.string;
Expand All @@ -119,7 +154,7 @@ describe('RawDatasets', () => {
});


it('should fetch several raw datasets', function(done) {
it('should fetch several raw datasets', function (done) {
request(app)
.get('/api/v2/RawDatasets?filter=%7B%22limit%22%3A2%7D&access_token=' + accessToken)
.set('Accept', 'application/json')
Expand All @@ -133,7 +168,7 @@ describe('RawDatasets', () => {
});
});

it('should fetch this raw dataset', function(done) {
it('should fetch this raw dataset', function (done) {
request(app)
.get('/api/v2/RawDatasets/' + pid + '?access_token=' + accessToken)
.set('Accept', 'application/json')
Expand All @@ -146,7 +181,7 @@ describe('RawDatasets', () => {
});
});

it('should delete this raw dataset', function(done) {
it('should delete this raw dataset', function (done) {
request(app)
.delete('/api/v2/RawDatasets/' + pid + '?access_token=' + accessToken)
.set('Accept', 'application/json')
Expand All @@ -159,20 +194,35 @@ describe('RawDatasets', () => {
});
});

it('should contain an array of facets', function(done) {

it('should contain an array of facets', function (done) {
request(app)
.get('/api/v2/RawDatasets/fullfacet?access_token=' + accessToken)
.set('Accept', 'application/json')
.send({'ownerGroup': ['p11114']})
.send({
'ownerGroup': ['p11114']
})
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
res.body.should.be.an('array');
if(err)
if (err)
done(err);
done();
});
});

it('should delete this proposal', function(done) {
request(app)
.delete('/api/v2/Proposals/' + proposalId + '?access_token=' + accessProposalToken)
.set('Accept', 'application/json')
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err)
return done(err);
done();
});
});

});

0 comments on commit a37cb7d

Please sign in to comment.