Commit 63c4aae7 authored by Maxime Chaillet's avatar Maxime Chaillet

separate object containing data retrieved from datacite from the object used in the template.

parent 7875b6a9
This diff is collapsed.
This diff is collapsed.
......@@ -57,32 +57,35 @@ DOIController.prototype.getData = function(doi) {
}
})
.done(function(doiData) {
if (doiData) {
.done(function(data) {
if (data) {
// Test abnormal length of the json object
if (!_this.isValidDOIData(doiData)) {
if (!_this.isValidDOIData(data)) {
_this.view.renderError("Not Found", _this.origin);
} else {
var doiData = {};
doiData.title = data.title;
doiData.publisher = data.publisher;
doiData.creator = data.creator;
var jsonExtractor = new JsonExtractor();
doiData.mintingYear = jsonExtractor.getMintingYear(doiData);
doiData.sessionDate = jsonExtractor.getSessionDate(doiData);
doiData.mintingYear = jsonExtractor.getMintingYear(data);
doiData.sessionDate = jsonExtractor.getSessionDate(data);
doiData.proposalType = jsonExtractor.getFieldFromSubject(doiData.subject, "Proposal Type Description");
doiData.proposalNumber = jsonExtractor.getFieldFromSubject(doiData.subject, "Proposal");
doiData.proposalType = jsonExtractor.getFieldFromSubject(data.subject, "Proposal Type Description");
doiData.proposalNumber = jsonExtractor.getFieldFromSubject(data.subject, "Proposal");
_this.experimentalReportController.requestFilenameList(doiData.proposalNumber);
doiData.beamline = jsonExtractor.getFieldFromSubject(doiData.subject, "instrument");
doiData.beamline = jsonExtractor.getFieldFromSubject(data.subject, "instrument");
jsonExtractor.extractInvestigationId(doiData);
_this.view.setDataAccessMessage(doiData);
_this.createCitation(doiData);
doiData.investigationId = jsonExtractor.extractInvestigationId(data);
doiData.accessMessage = _this.view.setDataAccessMessage(data);
doiData.citation = _this.createCitation(data);
// Set the URL corresponding to the beamline name.
if (doiData.date_collected) {
var experimentalDate = moment(doiData.date_collected);
if (data.date_collected) {
var experimentalDate = moment(data.date_collected);
doiData.beamlineUrl = _this.getBeamlineUrl(doiData.beamline, experimentalDate);
} else {
doiData.beamlineUrl = "noLink";
......@@ -170,6 +173,8 @@ DOIController.prototype.getBeamlineUrl = function(beamline, date) {
*
* @param {string}
* data: the data object, it is a reference
* @return {string}
* citation : the citation to be displayed
*/
DOIController.prototype.createCitation = function(data) {
// Authors sent in json can be in several format. The following call find
......@@ -177,16 +182,13 @@ DOIController.prototype.createCitation = function(data) {
var citation = new Citation(data);
if (!citation.isBuildable) {
data.citation = "The citation could not be generated.";
return "The citation could not be generated.";
} else {
var authorInCitation = citation.getAuthorsForCitation(data.creator);
var doiRegistrationYear = moment(data.date_registered).year();
var fullCitation = authorInCitation + ' (' + doiRegistrationYear + '). ' + data.title + '. ' + data.publisher + ' (ESRF). ' +
" <a href='https://doi.esrf.fr/" + data.doi + "'> doi:" + data.doi.toUpperCase() + "</a>";
data.citation = fullCitation;
return fullCitation;
}
};
......@@ -32,7 +32,7 @@ DOIView.prototype.setDOI = function( doiCode ) {
};
/**
* Set the doi http link in the doi landing page. It is the http adress at datacite server which will redirect to the DOI landing page.
* Set the doi http link in the doi landing page. It is the http address at datacite server which will redirect to the DOI landing page.
*
*/
DOIView.prototype.setDOILink = function( doiLink ) {
......@@ -40,7 +40,7 @@ DOIView.prototype.setDOILink = function( doiLink ) {
};
/**
* Render experimental Report data *
* Render experimental Report data
*
* @param {array}
* data The filename list to be displayed
......@@ -70,9 +70,10 @@ DOIView.prototype.renderDOIData = function( doiData, target ) {
}, function( err, out ) {
$( '#' + _this.mainPanelId ).html( out );
_this.isDOIAlreadyRendered = true;
/**
* If there are experimental reports already retrieved then reder them after
* the rendering of the DOI *
* If there are experimental reports already retrieved then render them after
* the rendering of the DOI
*/
if ( _this.failedRecievingExpReport ) {
_this.renderErrorForExperimentalReport();
......@@ -135,19 +136,21 @@ DOIView.prototype.renderErrorForExperimentalReport = function() {
};
/**
* Set the message which is displayed just above the "Access data button"
* Set the message which is displayed just above the "Access data button" in experimental data box.
*
* @param {object}
* data The json object reference.
* @return {string}
* the message to display
*/
DOIView.prototype.setDataAccessMessage = function( data ) {
var publicationDate = moment( data.publication_year, "YYYY" );
var now = moment();
if ( now > publicationDate ) {
data.accessMessage = "The data can be accessed by clicking on the link below";
return "The data can be accessed by clicking on the link below";
} else {
data.accessMessage = "The data is under embargo until <b>" + data.publication_year + "</b> but could be released earlier. </p> " +
return "The data is under embargo until <b>" + data.publication_year + "</b> but could be released earlier. </p> " +
" <p> Currently, it is only accessible to proposal team members. </p>";
}
......
function JsonExtractor(json) {
function JsonExtractor( json ) {
}
/**
* Extract investigationId from the data.doi field as received from the json
* response. Add the corresponding fields in the data object
* response.
*
* @param {string}
* data The data object reference which is sent to the dustjs
* template
* @return {string}
* investigationId The investigationID requested for accessing data in ICAT.
*/
JsonExtractor.prototype.extractInvestigationId = function(data) {
var regExp = RegExp(/\/\w*-*[Ee][Ss][Rr][Ff]-[Ee][Ss]-(\d+)$/);
data.investigationId = regExp.exec(data.doi)[1];
JsonExtractor.prototype.extractInvestigationId = function( data ) {
var regExp = RegExp( /\/\w*-*[Ee][Ss][Rr][Ff]-[Ee][Ss]-(\d+)$/ );
return regExp.exec( data.doi )[1];
};
/**
* Extract field value (beamline, proposal number and proposal type) from the
* data json object. Returns nullif the field is not found.
* data json object. Returns null if the field is not found.
*
* @param {array}
* subject The array containing objects of interest template
* @param {string}
* field The text field which is searched
*/
JsonExtractor.prototype.getFieldFromSubject = function(subject, field) {
if (subject) {
if (subject[0]) {
for (var i = 0; i < subject[0].length; i++) {
if (subject[0][i].subject_scheme === field) {
return subject[0][i].text;
JsonExtractor.prototype.getFieldFromSubject = function( subject, field ) {
if ( subject ) {
if ( subject[0] ) {
for ( var i = 0; i < subject[0].length; i++ ) {
if ( subject[0][i].subject_scheme === field ) {
return subject[0][i].text;
}
}
}
}
}
}
return null;
return null;
};
/**
......@@ -44,13 +46,13 @@ JsonExtractor.prototype.getFieldFromSubject = function(subject, field) {
* template
* @return {string} The minting year. Null if it does not exist.
*/
JsonExtractor.prototype.getMintingYear = function(data) {
if (data) {
if (data.date_registered && data.date_registered != null) {
return moment(data.date_registered).year();
JsonExtractor.prototype.getMintingYear = function( data ) {
if ( data ) {
if ( data.date_registered && data.date_registered != null ) {
return moment( data.date_registered ).year();
}
}
}
return null;
return null;
};
/**
......@@ -62,11 +64,11 @@ JsonExtractor.prototype.getMintingYear = function(data) {
* @return {string} The formatted (YYY-M-D) session date. Null if it does not
* exist.
*/
JsonExtractor.prototype.getSessionDate = function(data) {
if (data) {
if (data.date_collected && data.date_collected != null) {
return moment(data.date_collected).format('YYYY-M-D');
JsonExtractor.prototype.getSessionDate = function( data ) {
if ( data ) {
if ( data.date_collected && data.date_collected != null ) {
return moment( data.date_collected ).format( 'YYYY-M-D' );
}
}
}
return null;
return null;
};
<div class="col-12">
<div>
<span class="badge badge-success" style="font-size:14px;"> open Access </span>
</div>
</div>
\ No newline at end of file
......@@ -135,6 +135,10 @@
</div>
<div class="col-4">
<div id="badge" class="row"> </div>
<br>
<div class="row">
<div class="col-12">
<div class="card">
......
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