Commit 5d7a48d0 authored by Maxime Chaillet's avatar Maxime Chaillet

change the header on the ajax call to retrieve all the data from datacite....

change the header on the ajax call to retrieve all the data from datacite. Ajust the reading of the data from the JSON because the fields have different name and the json structure is different.
parent 2fbb5f8e
This diff is collapsed.
This diff is collapsed.
...@@ -15,7 +15,7 @@ DOIController.prototype.getData = function(doi) { ...@@ -15,7 +15,7 @@ DOIController.prototype.getData = function(doi) {
if (this.hasAcceptedPrefix(doi)) { if (this.hasAcceptedPrefix(doi)) {
$.ajax({ $.ajax({
headers : { headers : {
Accept : "application/vnd.citationstyles.csl+json" Accept : "application/vnd.datacite.datacite+json"
}, },
type : "GET", type : "GET",
url : this.doiServer + doi, url : this.doiServer + doi,
...@@ -34,10 +34,9 @@ DOIController.prototype.getData = function(doi) { ...@@ -34,10 +34,9 @@ DOIController.prototype.getData = function(doi) {
extractFieldsFromDoi(doiData); extractFieldsFromDoi(doiData);
// create citation // create citation
createCitation(doiData); createCitation(doiData);
// Retrieve the URL corresponding to the beamline name. Currently, the date of the
// experiment is calculated from the publicationYear. // Retrieve the URL corresponding to the beamline name.
var experimentalYear = doiData.issued["date-parts"] - 3 ; var experimentalDate = new Date(doiData.date_collected + "T00:00+00:00");
var experimentalDate = new Date(experimentalYear + "-01-01T00:00+00:00");
doiData.beamlineUrl = _this.findsUrl(doiData.beamline, experimentalDate); doiData.beamlineUrl = _this.findsUrl(doiData.beamline, experimentalDate);
// send to dust render // send to dust render
...@@ -134,24 +133,22 @@ function findRegExpInText(regExp, text) { ...@@ -134,24 +133,22 @@ function findRegExpInText(regExp, text) {
} }
// Extract beamline, proposal number and proposal type from the data.categories fields as received from the json response. // Extract beamline, proposal number and proposal type from the data fields as received from the json response.
// Add the corresponding fields in the data object // Add the corresponding fields in the data object
// @data: the data object, it is a reference // @data: the data object, it is a reference
function extractFieldsFromCategories(data) { function extractFieldsFromCategories(data) {
var catArray = data.categories; _.forEach(data.subject[0], function(value){
var index; switch (value.subject_scheme ) {
for (index in catArray) { case "Proposal Type Description":
// extract beamline from data.categories data.proposalType = value.text;
if ((findRegExpInText(/^id/, catArray[index]) == 0) || (findRegExpInText(/^bm/, catArray[index]) == 0)) { break;
data.beamline = catArray[index]; case "Proposal":
} else if (findRegExpInText(/^\D+-/, catArray[index]) == 0) { data.proposalNumber = value.text;
// extract proposal number from data.categories break;
data.proposalNumber = catArray[index]; case "instrument":
} else { data.beamline = value.text;
// catArray[index] is the proposal type. Note that proposal type can be composed of several words separated by spaces or a single word. }
data.proposalType = catArray[index]; });
}
}
} }
//Extract investigationId from the data.doi field as received from the json response. //Extract investigationId from the data.doi field as received from the json response.
...@@ -160,31 +157,31 @@ function extractFieldsFromCategories(data) { ...@@ -160,31 +157,31 @@ function extractFieldsFromCategories(data) {
function extractFieldsFromDoi(data) { function extractFieldsFromDoi(data) {
//extract the investigationId from the doi. //extract the investigationId from the doi.
var regExp = RegExp(/\/\w*-*[Ee][Ss][Rr][Ff]-[Ee][Ss]-(\d+)$/); var regExp = RegExp(/\/\w*-*[Ee][Ss][Rr][Ff]-[Ee][Ss]-(\d+)$/);
data.investigationId = regExp.exec(data.DOI)[1]; data.investigationId = regExp.exec(data.doi)[1];
} }
// Create the citation for the current work. Citation proposes a recommendation to the reader // Create the citation for the current work. Citation proposes a recommendation to the reader
// on how to cite this work. // on how to cite this work.
//@data: the data object, it is a reference //@data: the data object, it is a reference
function createCitation(data) { function createCitation(data) {
var authorList = _.transform(data.author, function(result, obj) { var authorList = _.transform(data.creator, function(result, obj) {
if (obj.given) { if (obj.givenName) {
result.push(obj.family + ' ' + obj.given); result.push(obj.familyName + ' ' + obj.givenName);
} else { } else {
// cells of data.authors contains First Name FAMILY NAME most of the time. // cells of data.creator.name contains First Name FAMILY NAME most of the time.
// 1 - detect the words in UPPERCASE as FAMILY name // 1 - detect the words in UPPERCASE as FAMILY name
// 2 - detect the words in LOWERcase except first letter which can optionally be uppercase. // 2 - detect the words in lowercase except first letter which can optionally be uppercase.
// 3 - flip them // 3 - flip them
var familyRegExp = new RegExp(/\s([^a-z]+$)/); var familyRegExp = new RegExp(/\s([^a-z]+$)/);
var firstNameRegExp = new RegExp(/^(.[^A-Z]+)+\b/); var firstNameRegExp = new RegExp(/^(.[^A-Z]+)+\b/);
var familyName = familyRegExp.exec(obj.literal); var familyName = familyRegExp.exec(obj.name);
var firstName = firstNameRegExp.exec(obj.literal); var firstName = firstNameRegExp.exec(obj.name);
// Sometime all words are uppercase or lowercase or uppercase for the first letter only. In this case we can not distinguish between family name and firstname. => string unchanged // Sometime all words are uppercase or lowercase or uppercase for the first letter only. In this case we can not distinguish between family name and firstname. => string unchanged
if (!familyName || !firstName ){ if (!familyName || !firstName ){
result.push(obj.literal); result.push(obj.name);
} else { } else {
result.push(familyName[1] + " " + firstName[0].trim()); result.push(familyName[1] + " " + firstName[0].trim());
} }
...@@ -195,12 +192,12 @@ function createCitation(data) { ...@@ -195,12 +192,12 @@ function createCitation(data) {
var citation = authorString + var citation = authorString +
'. (' + '. (' +
data.issued['date-parts'] + data.date_registered +
'). ' + '). ' +
data.title + data.title +
'. ' + '. ' +
data.publisher + data.publisher +
' (ESRF). ' + ' (ESRF). ' +
" <a href='https://doi.esrf.fr/" + data.DOI + "'> doi:" + data.DOI + "</a>"; " <a href='https://doi.esrf.fr/" + data.DOI + "'> doi:" + data.doi + "</a>";
data.citation = citation; data.citation = citation;
} }
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
</div> </div>
<div class="col-3"> <div class="col-3">
<div class="myBorder-left"> <div class="myBorder-left">
<label> Release year </label> <label> Publication year </label>
<div class="padding-left-15">{data.issued.date-parts}</div> <div class="padding-left-15">{data.publication_year}</div>
</div> </div>
</div> </div>
<div class="col-6"> <div class="col-6">
...@@ -121,7 +121,7 @@ ...@@ -121,7 +121,7 @@
<label>Authors </label> <label>Authors </label>
</div> </div>
<div class="card-body text-center"> <div class="card-body text-center">
{#data.author} {?.given} {.given} {.family} </br> {:else} {.literal} </br> {/.given} {/data.author} {#data.creator} {?.givenName} {.givenName} {.familyName} </br> {:else} {.name} </br> {/.givenName} {/data.creator}
</div> </div>
</div> </div>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment