Skip to content

Commit

Permalink
fixed conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
punkish committed Apr 20, 2020
2 parents 168d28e + 0cbb294 commit 685a6eb
Show file tree
Hide file tree
Showing 74 changed files with 6,247 additions and 7,680 deletions.
8 changes: 7 additions & 1 deletion api/v1/resources/authors.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ module.exports = {
responseMessages: ResponseMessages
}
},
validate: Schema.authors,
validate: {
params: Schema.authors.params,
failAction: (request, h, err) => {
throw err;
return;
}
},
notes: [
'This route fetches authors starting with the provided letters.'
]
Expand Down
8 changes: 7 additions & 1 deletion api/v1/resources/families.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ module.exports = {
responseMessages: ResponseMessages
}
},
validate: Schema.families,
validate: {
params: Schema.families.params,
failAction: (request, h, err) => {
throw err;
return;
}
},
notes: [
'This route fetches the families starting with the provided letters.'
]
Expand Down
9 changes: 8 additions & 1 deletion api/v1/resources/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ module.exports = {
responseMessages: ResponseMessages
}
},
validate: Schema.files,
validate: {
params: Schema.files.params,
query: Schema.files.query,
failAction: (request, h, err) => {
throw err;
return;
}
},
notes: [
'Files inside Zenodo records',
]
Expand Down
8 changes: 7 additions & 1 deletion api/v1/resources/keywords.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ module.exports = {
responseMessages: ResponseMessages
}
},
validate: Schema.keywords,
validate: {
params: Schema.keywords.params,
failAction: (request, h, err) => {
throw err;
return;
}
},
notes: [
'This route fetches the keywords starting with the provided letters.'
]
Expand Down
9 changes: 8 additions & 1 deletion api/v1/resources/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ module.exports = {
responseMessages: ResponseMessages
}
},
validate: Schema.record,
validate: {
params: Schema.record.params,
query: Schema.record.query,
failAction: (request, h, err) => {
throw err;
return;
}
},
notes: [
'This is the main route for fetching a record matching an id or a set of records matching the provided query parameters.'
]
Expand Down
9 changes: 8 additions & 1 deletion api/v1/resources/records.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,14 @@ module.exports = {
responseMessages: ResponseMessages
}
},
validate: Schema.records,
validate: {
params: Schema.records.params,
query: Schema.records.query,
failAction: (request, h, err) => {
throw err;
return;
}
},
notes: [
'This is the main route for fetching records matching the provided query parameters.'
]
Expand Down
8 changes: 7 additions & 1 deletion api/v1/resources/taxa.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ module.exports = {
responseMessages: ResponseMessages
}
},
validate: Schema.authors,
validate: {
params: Schema.taxa.params,
failAction: (request, h, err) => {
throw err;
return;
}
},
notes: [
'This route fetches taxa starting with the provided letters.'
]
Expand Down
9 changes: 8 additions & 1 deletion api/v1/resources/treatment.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,14 @@ const treatment = {
responseMessages: ResponseMessages
}
},
validate: Schema.treatments,
validate: {
params: Schema.treatments.params,
query: Schema.treatments.query,
failAction: (request, h, err) => {
throw err;
return;
}
},
notes: [
'This is the main route for fetching a treatment matching an id.'
]
Expand Down
24 changes: 24 additions & 0 deletions api/v1/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,30 @@ const schema = {
refreshCache: Joi.boolean()
.default(false)
})
},

authors: {
params: Joi.object({
term: Joi.string().description('retrieve all authors starting with the provided letters (at leeast 3)').required().min(3).message('at least 3 characters are required (for example, « authors/ago »)')
})
},

taxa: {
params: Joi.object({
term: Joi.string().description('retrieve all taxa starting with the provided letters (at leeast 3)').required().min(3).message('at least 3 characters are required (for example, « authors/ago »)')
})
},

families: {
params: Joi.object({
term: Joi.string().description('retrieve all families starting with the provided letters (at leeast 3)').required().min(3).message('at least 3 characters are required (for example, « authors/ago »)')
})
},

keywords: {
params: Joi.object({
term: Joi.string().description('retrieve all keywords starting with the provided letters (at leeast 3)').required().min(3).message('at least 3 characters are required (for example, « authors/ago »)')
})
}
};

Expand Down
26 changes: 11 additions & 15 deletions api/v2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,16 @@ exports.plugin = {
version: '1.0.1',
register: async function(server, options) {

await server.register([
{ plugin: require('./resources/root') },
{ plugin: require('./resources/treatments'), options: cache },
{ plugin: require('./resources/figureCitations'), options: cache },
{ plugin: require('./resources/treatmentAuthors'), options: cache },
{ plugin: require('./resources/bibRefCitations'), options: cache },
{ plugin: require('./resources/materialsCitations'), options: cache },
{ plugin: require('./resources/images'), options: cache },
{ plugin: require('./resources/publications'), options: cache },
{ plugin: require('./resources/taxa') },
{ plugin: require('./resources/families') },
{ plugin: require('./resources/keywords') },
{ plugin: require('./resources/authors') },
{ plugin: require('./resources/wpsummary'), options: cache }
]);
const rootRoute = [{ plugin: require('./resources/rootRoute') }];

const otherRoutes = require('./resources/otherRoutes');
otherRoutes.forEach(r => r.options = cache);
otherRoutes.push({
plugin: require('./resources/wpsummary'),
options: cache
});

const routes = [].concat(rootRoute, otherRoutes);
await server.register(routes);
}
};
153 changes: 153 additions & 0 deletions api/v2/lib/dd2datadictionary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
'use strict';

/***********************************************************************
*
* Here we import the raw data definitions defined in dd.js and the
* files included therein, and export a combined and flattened data-
* dictionary as well as the resources grouped by resourceGroups to
* facilitate fast and convenient lookups.
*
**********************************************************************/

const { dd, commonParams } = require('../../../dataDictionary/dd');

const dd2datadictionary = function() {

// We will flatten and compile the data dictionary by
// converting the following
//
// dd = {
// zenodeoCore: { treatments: [] },
// zenodeoRelated: {
// figureCitations: [],
// bibRefCitations: [],
// …
// }
// }
//
// to the following
//
// dataDictionary = {
// treatments: [],
// figureCitations: [],
// bibRefCitations: [],
// …
// }
//
// In the process, we will also add the required
// common parameters to all the resources
const dataDictionary = {};

// We will also create a bundle of all the resources
// grouped by their resource groups, and carrying with
// them the name of the 'resource' and the name of the
// 'resourceId'. This will look like
//
// "zenodeoCore": [
// {
// "name": "treatments",
// "resourceId": "treatmentId"
// }
// ],
// "zenodeoRelated": [
// {
// "name": "figureCitations",
// "resourceId": "figureCitationId"
// },
// {
// "name": "bibRefCitations",
// "resourceId": "bibRefCitationId"
// },
const resourceGroups = {};

// loop over each resourceGroup 'rg' in the raw dd
// 'rg' will be one of
// - zenodeoCore
// - zendeoRelated
// - zenodo
// - lookups
for (let rg in dd) {


resourceGroups[rg] = [];

// loop over each resource in the respective resource groups
const groupResources = dd[rg];
for (let resource in groupResources) {


// Add the commonParams to 'all' the resources no matter
// which resourceGroup they are in (hence, the 'all')
let gr = groupResources[resource];
gr.push(...commonParams['all']);

// Don't add any params if a particular resourceGroup's
// specific commonParams are empty. This ensures nothing
// is added to 'treatments' which is a part of 'zenodeoCore'
// and to all the lookups. We do this by testing whether the
// commonParams of a 'rg' are empty by checking its .length()
if (commonParams[rg].length) {

// we are using concat() instead of push() because we
// want to add these parameters in front of the array
// rather than at the end of the array
gr = [].concat(commonParams[rg], gr)
}

// For every resource, we add its name and the name of its
// resourceId key to the resourceGroups hash
let name = resource;
let resourceId = '';
for (let i = 0, j = gr.length; i < j; i++) {

if (rg !== 'lookups') {

if (gr[i].resourceId) {

if (gr[i].resourceId === true) {

resourceId = gr[i].plaziName;
break;
}
}

}

}

resourceGroups[rg].push({
name: name,
resourceId: resourceId
});

dataDictionary[resource] = gr;

}



}

return {
dataDictionary: dataDictionary,
resourceGroups: resourceGroups
};

};

const test = function() {

const dd = dd2datadictionary();
console.log(JSON.stringify(dd, null, ' '));

};

// https://stackoverflow.com/questions/6398196/detect-if-called-through-require-or-directly-by-command-line?rq=1
if (require.main === module) {

test();
}
else {

module.exports = (dd2datadictionary)();
}
Loading

0 comments on commit 685a6eb

Please sign in to comment.