Skip to content

Commit

Permalink
bumped v to 2.6.0 in this branch; added back the lat/lon contained-in…
Browse files Browse the repository at this point in the history
… box logic, new release notes
  • Loading branch information
punkish committed Apr 18, 2020
1 parent 5949a1f commit 039c519
Show file tree
Hide file tree
Showing 33 changed files with 3,108 additions and 3,595 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
164 changes: 122 additions & 42 deletions api/v2/lib/dd2datadictionary.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,153 @@
'use strict';

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

module.exports = (function() {
/***********************************************************************
*
* 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 dataDictionary = [];
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] = [];
const resources = dd[rg];

for (let r in resources) {

resources[r].push(...commonParams['all']);
resourceGroups[rg] = [];

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

// this ensures that nothing is added to 'treatments'
if (commonParams[rg].length) {
resources[r].push(...commonParams[rg]);
}



//if (rg === 'zenodo') {

// resources[r].push(...commonZenodoQueryParams);
//}
//else if (rg === 'zenodeo') {

// if (r !== 'treatments') {
// 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) {

// resources[r].push(...commonZenodeoQueryParams);
// }
//}
// 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 (let i = 0, j = resources[r].length; i < j; i++) {
// 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 (rg !== 'lookups') {

resourceGroups[rg].push({
name: r,
resourceId: ''
});
break;
}
else {
if (gr[i].resourceId) {

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

resourceGroups[rg].push({
name: r,
resourceId: resources[r][i].plaziName
});
break;
resourceId = gr[i].plaziName;
break;
}
}

}

}

dataDictionary.push(...resources[r]);
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 039c519

Please sign in to comment.