Commit 1c8bd6ee authored by Maxime Chaillet's avatar Maxime Chaillet

Fix bugs associated to the new JSON from datacite. It fixes #61.

parent 610a0eab
This diff is collapsed.
This diff is collapsed.
var ESRF_DC_142893590 = {
"id": "https://doi.org/10.15151/ESRF-DC-142893590",
"id": "https://doi.org/10.15151/esrf-dc-142893590",
"doi": "10.15151/ESRF-DC-142893590",
"creator": [
{
"type": "Person",
"url": "https://doi.esrf.fr/10.15151/ESRF-DC-142893590",
"types": {
"ris": "DATA",
"bibtex": "misc",
"citeproc": "dataset",
"schemaOrg": "Dataset",
"resourceType": "Datacollection",
"resourceTypeGeneral": "Dataset"
},
"creators": [
{
"name": "Naschberger, Andreas",
"nameType": "Personal",
"givenName": "Andreas",
"familyName": "Naschberger"
},
{
"type": "Person",
"name": "Bowler, Matthew W.",
"nameType": "Personal",
"givenName": "Matthew W.",
"familyName": "Bowler"
},
{
"type": "Person",
{
"name": "Rupp, Bernhard",
"nameType": "Personal",
"givenName": "Bernhard",
"familyName": "Rupp"
}
],
"title": "Structural Evidence for a Role of the Multi-functional Human Glycoprotein Afamin in Wnt Transport",
"titles": [
{
"title": "Structural Evidence for a Role of the Multi-functional Human Glycoprotein Afamin in Wnt Transport"
}
],
"publisher": "European Synchrotron Radiation Facility",
"resource_type_general": "Dataset",
"resource_type": "Datacollection",
"subject": [
[
{
"subject_scheme": "Proposal",
"text": "OPID-30A1"
},
{
"subject_scheme": "instrument",
"text": "ID30A1"
}
]
"container": {},
"subjects": [
{
"subject": "OPID-1",
"subjectScheme": "Proposal"
},
{
"subject": "ID30A1",
"subjectScheme": "Instrument"
}
],
"description": {
"type": "Abstract",
"text": "Afamin, a human plasma glycoprotein and putative transporter of hydrophobic molecules, has been shown to act as extracellular chaperone for poorly soluble, acylated Wnt proteins, forming a stable, soluble complex with functioning Wnt proteins. The 2.1-Å crystal structure of glycosylated human afamin reveals an almost exclusively hydrophobic binding cleft capable of harboring large hydrophobic moieties. Lipid analysis confirms the presence of lipids, and density in the primary binding pocket of afamin was modeled as palmitoleic acid, presenting the native O-acylation on serine 209 in human Wnt3a. The modeled complex between the experimental afamin structure and a Wnt3a homology model based on the XWnt8-Fz8-CRD fragment complex crystal structure is compelling, with favorable interactions comparable with the crystal structure complex. Afamin readily accommodates the conserved palmitoylated serine 209 of Wnt3a, providing a structural basis how afamin solubilizes hydrophobic and poorly soluble Wnt proteins."
},
"date_collected": "2018-03-07",
"date_published": "2018",
"date_registered": "2018-03-07T14:37:09Z",
"date_updated": "2018-03-08T16:30:22Z",
"publication_year": 2018,
"language": "eng",
"contributors": [],
"dates": [
{
"date": "2018",
"dateType": "Issued"
}
],
"publicationYear": 2018,
"language": "en",
"identifiers": [
{
"identifier": "https://doi.org/10.15151/esrf-dc-142893590",
"identifierType": "DOI"
}
],
"sizes": [],
"formats": [],
"rightsList": [],
"descriptions": [
{
"description": "Afamin, a human plasma glycoprotein and putative transporter of hydrophobic molecules, has been shown to act as extracellular chaperone for poorly soluble, acylated Wnt proteins, forming a stable, soluble complex with functioning Wnt proteins. The 2.1-Å crystal structure of glycosylated human afamin reveals an almost exclusively hydrophobic binding cleft capable of harboring large hydrophobic moieties. Lipid analysis confirms the presence of lipids, and density in the primary binding pocket of afamin was modeled as palmitoleic acid, presenting the native O-acylation on serine 209 in human Wnt3a. The modeled complex between the experimental afamin structure and a Wnt3a homology model based on the XWnt8-Fz8-CRD fragment complex crystal structure is compelling, with favorable interactions comparable with the crystal structure complex. Afamin readily accommodates the conserved palmitoylated serine 209 of Wnt3a, providing a structural basis how afamin solubilizes hydrophobic and poorly soluble Wnt proteins.",
"descriptionType": "Abstract"
}
],
"geoLocations": [],
"fundingReferences": [],
"relatedIdentifiers": [],
"schemaVersion": "http://datacite.org/schema/kernel-3",
"provider_id": "INIST",
"client_id": "INIST.ESRF"
};
\ No newline at end of file
"providerId": "inist",
"clientId": "inist.esrf",
"state": "findable"
};
// {
// "id": "https://doi.org/10.15151/ESRF-DC-142893590",
// "doi": "10.15151/ESRF-DC-142893590",
// "creator": [
// {
// "type": "Person",
// "name": "Naschberger, Andreas",
// "givenName": "Andreas",
// "familyName": "Naschberger"
// },
// {
// "type": "Person",
// "name": "Bowler, Matthew W.",
// "givenName": "Matthew W.",
// "familyName": "Bowler"
// },
// {
// "type": "Person",
// "name": "Rupp, Bernhard",
// "givenName": "Bernhard",
// "familyName": "Rupp"
// }
// ],
// "title": "Structural Evidence for a Role of the Multi-functional Human Glycoprotein Afamin in Wnt Transport",
// "publisher": "European Synchrotron Radiation Facility",
// "resource_type_general": "Dataset",
// "resource_type": "Datacollection",
// "subject": [
// [
// {
// "subject_scheme": "Proposal",
// "text": "OPID-30A1"
// },
// {
// "subject_scheme": "instrument",
// "text": "ID30A1"
// }
// ]
// ],
// "description": {
// "type": "Abstract",
// "text": "Afamin, a human plasma glycoprotein and putative transporter of hydrophobic molecules, has been shown to act as extracellular chaperone for poorly soluble, acylated Wnt proteins, forming a stable, soluble complex with functioning Wnt proteins. The 2.1-Å crystal structure of glycosylated human afamin reveals an almost exclusively hydrophobic binding cleft capable of harboring large hydrophobic moieties. Lipid analysis confirms the presence of lipids, and density in the primary binding pocket of afamin was modeled as palmitoleic acid, presenting the native O-acylation on serine 209 in human Wnt3a. The modeled complex between the experimental afamin structure and a Wnt3a homology model based on the XWnt8-Fz8-CRD fragment complex crystal structure is compelling, with favorable interactions comparable with the crystal structure complex. Afamin readily accommodates the conserved palmitoylated serine 209 of Wnt3a, providing a structural basis how afamin solubilizes hydrophobic and poorly soluble Wnt proteins."
// },
// "date_collected": "2018-03-07",
// "date_published": "2018",
// "date_registered": "2018-03-07T14:37:09Z",
// "date_updated": "2018-03-08T16:30:22Z",
// "publication_year": 2018,
// "language": "eng",
// "schemaVersion": "http://datacite.org/schema/kernel-3",
// "provider_id": "INIST",
// "client_id": "INIST.ESRF"
// };
\ No newline at end of file
var ESRF_DC_142915526 = {
"id": "https://doi.org/10.15151/esrf-dc-142915526",
"doi": "10.15151/ESRF-DC-142915526",
"creator": [
{
"type": "Person",
"name": "Naschberger, Andreas",
"givenName": "Andreas",
"familyName": "Naschberger"
},
{
"type": "Person",
"name": "Bowler, Matthew W.",
"givenName": "Matthew W.",
"familyName": "Bowler"
},
{
"type": "Person",
"name": "Rupp, Bernhard",
"givenName": "Bernhard",
"familyName": "Rupp"
}
"url": "https://doi.esrf.fr/10.15151/ESRF-DC-142915526",
"types": {
"ris": "DATA",
"bibtex": "misc",
"citeproc": "dataset",
"schemaOrg": "Dataset",
"resourceType": "Datacollection",
"resourceTypeGeneral": "Dataset"
},
"creators": [
{
"name": "Naschberger, Andreas",
"nameType": "Personal",
"givenName": "Andreas",
"familyName": "Naschberger"
},
{
"name": "Bowler, Matthew W.",
"nameType": "Personal",
"givenName": "Matthew W.",
"familyName": "Bowler"
},
{
"name": "Rupp, Bernhard",
"nameType": "Personal",
"givenName": "Bernhard",
"familyName": "Rupp"
}
],
"titles": [
{
"title": "Controlled dehydration, structural flexibility, and Gadolinium MRI contrast compound binding in human plasma glycoprotein afamin"
}
],
"title": "Controlled dehydration, structural flexibility, and Gadolinium MRI contrast compound binding in human plasma glycoprotein afamin",
"publisher": "European Synchrotron Radiation Facility",
"resource_type_general": "Dataset",
"resource_type": "Datacollection",
"subject": [
[
{
"subject_scheme": "Proposal",
"text": "OPID-30A1"
},
{
"subject_scheme": "instrument",
"text": "ID30A1"
}
]
"container": {},
"subjects": [
{
"subject": "OPID-1",
"subjectScheme": "Proposal"
},
{
"subject": "ID30A1",
"subjectScheme": "Instrument"
}
],
"description": {
"type": "Abstract",
"text": "Afamin, a human blood plasma glycoprotein, a putative multi-functional transporter of hydrophobic molecules and a marker for metabolic syndrome, poses multiple challenges for crystallographic structure determination, both practically and in analysis of the models. Several hundred crystals were analysed, and unusual variability in cell volume and difficulty solving the structure despite a ~34% sequence identity with non-glycosylated human serum albumin indicated that the molecule exhibits variable and context-sensitive packing, despite greatly simplified glycosylation in insect cell expressed recombinant afamin. Controlled dehydration of the crystals was able to stabilise the orthorhombic crystal form reducing the number of molecules in the asymmetric unit from the monoclinic form and changing the conformational states of the protein. An iterative strategy using fully automatic experiments available on MASSIF-1 was used to quickly determine the optimal protocol to achieve the phase transition that should be readily applicable to many types of sample. The study also highlights the drawback of using a single crystallographic structure model for computation modelling purposes given that conformational state of the binding sites and electron density in the binding site, likely resulting from PEGs, greatly varies between models. This also holds for the analysis of unspecific low-affinity ligands, where often a variety fragments with similar uncertainty can be modelled, inviting interpretative bias. As a promiscuous transporter, afamin can also bind Gadoteridol, a magnetic resonance imaging contrast compound in two sites, one near the human albumin Sudlow-site and a second hitherto unknown binding site."
},
"date_collected": "2018-03-07",
"date_published": "2018",
"date_registered": "2018-03-07T14:37:09Z",
"date_updated": "2018-03-08T16:30:22Z",
"publication_year": 2018,
"language": "eng",
"contributors": [],
"dates": [
{
"date": "2018",
"dateType": "Issued"
}
],
"publicationYear": 2018,
"language": "en",
"identifiers": [
{
"identifier": "https://doi.org/10.15151/esrf-dc-142915526",
"identifierType": "DOI"
}
],
"sizes": [],
"formats": [],
"rightsList": [],
"descriptions": [
{
"description": "Afamin, a human blood plasma glycoprotein, a putative multi-functional transporter of hydrophobic molecules and a marker for metabolic syndrome, poses multiple challenges for crystallographic structure determination, both practically and in analysis of the models. Several hundred crystals were analysed, and unusual variability in cell volume and difficulty solving the structure despite a ~34% sequence identity with non-glycosylated human serum albumin indicated that the molecule exhibits variable and context-sensitive packing, despite greatly simplified glycosylation in insect cell expressed recombinant afamin. Controlled dehydration of the crystals was able to stabilise the orthorhombic crystal form reducing the number of molecules in the asymmetric unit from the monoclinic form and changing the conformational states of the protein. An iterative strategy using fully automatic experiments available on MASSIF-1 was used to quickly determine the optimal protocol to achieve the phase transition that should be readily applicable to many types of sample. The study also highlights the drawback of using a single crystallographic structure model for computation modelling purposes given that conformational state of the binding sites and electron density in the binding site, likely resulting from PEGs, greatly varies between models. This also holds for the analysis of unspecific low-affinity ligands, where often a variety fragments with similar uncertainty can be modelled, inviting interpretative bias. As a promiscuous transporter, afamin can also bind Gadoteridol, a magnetic resonance imaging contrast compound in two sites, one near the human albumin Sudlow-site and a second hitherto unknown binding site.",
"descriptionType": "Abstract"
}
],
"geoLocations": [],
"fundingReferences": [],
"relatedIdentifiers": [],
"schemaVersion": "http://datacite.org/schema/kernel-3",
"provider_id": "INIST",
"client_id": "INIST.ESRF"
};
\ No newline at end of file
"providerId": "inist",
"clientId": "inist.esrf",
"state": "findable"
};
\ No newline at end of file
function Citation(data) {
this.isBuildable = (data && data.creator && data.creator.length !== 0 &&
data.date_registered && data.title && data.publisher && data.doi) ? true
: false;
function Citation(doiData) {
function isBuildable() {
if (doiData && doiData.creators && doiData.creators.length !== 0 &&
doiData.title && doiData.publisher && doiData.doi) {
if (doiData.resourceType === CONSTANTS.ES_RESOURCE_TYPE && doiData.sessionDate) {
return true;
}
if (doiData.resourceType === CONSTANTS.DC_RESOURCE_TYPE && doiData.publiclyAccessibleYear) {
return true;
}
}
return false;
}
this.isBuildable = isBuildable();
}
/**
......@@ -14,43 +26,55 @@ function Citation(data) {
* @return {string} The formated list of authors to be used for the citation. An
* empty string when the list could not be generated.
*/
Citation.prototype.getAuthorsForCitation = function(creator) {
if (this.isBuildable) {
var authorList = _.transform(creator, function(result, val, key, obj) {
if (!(obj instanceof Array)) {
val = obj;
}
var author = null;
if (val.givenName) {
author = new Author();
author.setFamilyName(val.familyName);
author.setFirstName(val.givenName);
result.push(author.getTitleCaseFamilyName() + ' ' +
author.getFirstNameInitials());
} else {
// Here first name and last name are in a single string field
// creator.name
author = new Author();
author.setSingleName(val.name);
if (!author.getRawFamilyName() || !author.getRawFirstName()) {
result.push(val.name);
} else {
// FirstName and family name are not in a single string
result.push(author.getTitleCaseFamilyName() + " " +
author.getFirstNameInitials());
}
}
if (!(obj instanceof Array)) {
return false;
}
}, []);
Citation.prototype.getAuthorsForCitation = function (creator) {
if (this.isBuildable) {
var authorList = _.transform(creator, function (result, val, key, obj) {
if (!(obj instanceof Array)) {
val = obj;
}
var author = null;
if (val.givenName) {
author = new Author();
author.setFamilyName(val.familyName);
author.setFirstName(val.givenName);
result.push(author.getTitleCaseFamilyName() + ' ' +
author.getFirstNameInitials());
} else {
// Here first name and last name are in a single string field
// creator.name
author = new Author();
author.setSingleName(val.name);
if (!author.getRawFamilyName() || !author.getRawFirstName()) {
result.push(val.name);
} else {
// FirstName and family name are not in a single string
result.push(author.getTitleCaseFamilyName() + " " +
author.getFirstNameInitials());
}
}
if (!(obj instanceof Array)) {
return false;
}
}, []);
return _.join(authorList, ', ');
} else {
console.log("[CITATION GENERATION] Author list for the citation could not be generated.");
return "";
}
};
Citation.prototype.getDOIRegistrationYear = function (doiData) {
if (doiData.resourceType === CONSTANTS.ES_RESOURCE_TYPE) {
return moment(doiData.sessionDate).year();
}
if (doiData.resourceType === CONSTANTS.DC_RESOURCE_TYPE) {
return doiData.publiclyAccessibleYear;
}
return _.join(authorList, ', ');
} else {
console.log("the author list for the citation could not be generated.");
console.log("[CITATION GENERATION] Could not get the year to generate the citation.");
return "";
}
};
\ No newline at end of file
......@@ -48,8 +48,8 @@ DOIController.prototype.render = function (doi, data) {
//var doiData = new doiData();
var doiData = new DoiData(data.doi.toUpperCase(), _this.doiServer + doi, data.publisher, data.creator, data.publication_year);
var doiData = new DoiData();
// var doiData = new DoiData(data.doi.toUpperCase(), _this.doiServer + doi, data.publisher, data.creator, data.publication_year);
var jsonExtractor = new JsonExtractor();
doiData.title = jsonExtractor.getTitle(data);
......@@ -59,37 +59,39 @@ DOIController.prototype.render = function (doi, data) {
doiData.creators = jsonExtractor.getCreators(data);
doiData.publiclyAccessibleYear = jsonExtractor.getPubliclyAccessibleYear(data);
doiData.abstract = jsonExtractor.getAbstract(data);
doiData.investigationId = jsonExtractor.getInvestigationId(data);
doiData.resourceType = jsonExtractor.getResourceType(data);
// doiData.mintingYear = jsonExtractor.getMintingYear(data);
//console.log("minting year = " + doiData.mintingYear);
doiData.proposalType = jsonExtractor.getFieldFromSubject(data.subjects, "Proposal Type Description");
doiData.resourceTypeGeneral = jsonExtractor.getResourceTypeGeneral(data);
doiData.sessionDate = jsonExtractor.getSessionDate(data);
var proposalNames = jsonExtractor.getFieldFromSubject(data.subjects, "Proposal");
var beamlines = jsonExtractor.getFieldFromSubject(data.subjects, "Instrument");
_this.experimentalReportController.requestFilenameList(proposalNames[0]);
doiData.accessibility = doiData.getAccessibilityStatus(doiData.resourceType, doiData.sessionDate, doiData.publiclyAccessibleYear);
doiData.accessMessage = _this.view.setDataAccessMessage(doiData);
// var jsonExtractor = new JsonExtractor();
// doiData.abstract = jsonExtractor.getAbstract(data);
// doiData.investigationId = jsonExtractor.getInvestigationId(data);
// doiData.mintingYear = jsonExtractor.getMintingYear(data);
// doiData.proposalType = jsonExtractor.getFieldFromSubject(data.subject, "Proposal Type Description");
// doiData.resourceType = jsonExtractor.getResourceType(data);
// doiData.resourceTypeGeneral = jsonExtractor.getResourceTypeGeneral(data);
// doiData.sessionDate = jsonExtractor.getSessionDate(data);
// var proposalNames = jsonExtractor.getFieldFromSubject(data.subject, "Proposal");
// var beamlines = jsonExtractor.getFieldFromSubject(data.subject, "Instrument");
// _this.experimentalReportController.requestFilenameList(proposalNames[0]);
// doiData.accessibility = doiData.getAccessibilityStatus(doiData.resourceType, doiData.sessionDate, doiData.publiclyAccessibleYear);
// doiData.accessMessage = _this.view.setDataAccessMessage(doiData);
// doiData.citation = _this.createCitation(data);
doiData.citation = _this.createCitation(doiData);
// if (doiData.resourceType === CONSTANTS.ES_RESOURCE_TYPE) {
// doiData.beamlineUrls = _this.getBeamlineUrl(beamlines, data.date_collected, doiData.resourceType);
// }
if (doiData.resourceType === CONSTANTS.ES_RESOURCE_TYPE) {
doiData.beamlineUrls = _this.getBeamlineUrl(beamlines, doiData.sessionDate, doiData.resourceType);
doiData.mintingYear = moment(doiData.sessionDate).year();
}
// if (doiData.resourceType === CONSTANTS.DC_RESOURCE_TYPE) {
// doiData.beamlineUrls = _this.getBeamlineUrl(beamlines, data.publication_year, doiData.resourceType);
// }
if (doiData.resourceType === CONSTANTS.DC_RESOURCE_TYPE) {
doiData.beamlineUrls = _this.getBeamlineUrl(beamlines, doiData.publiclyAccessibleYear, doiData.resourceType);
doiData.mintingYear = doiData.publiclyAccessibleYear;
}
// Create a table containing unique tuples [proposal, beamline, beamlineUrl]
doiData.mergedProposalBeamlines = jsonExtractor.getMergedProposalAndBeamline(proposalNames, beamlines, doiData.beamlineUrls);
......@@ -226,25 +228,22 @@ DOIController.prototype.getBeamlineUrl = function (beamlines, date, resourceType
/**
* Create the citation for the current work. Citation proposes a recommendation
* to the reader on how to cite this work.
*
* @param {string}
* data: the data object, it is a reference
* @return {string}
* citation : the citation to be displayed
* @param {object} doiData the doiData object we have constructed from JSON datacite
* @return {string} the citation to be displayed
*/
DOIController.prototype.createCitation = function (data) {
DOIController.prototype.createCitation = function (doiData) {
// Authors sent in json can be in several format. The following call find
// first name and last name when possible.
var citation = new Citation(data);
var citation = new Citation(doiData);
if (!citation.isBuildable) {
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>";
var authorInCitation = citation.getAuthorsForCitation(doiData.creators);
var doiRegistrationYear = citation.getDOIRegistrationYear(doiData);
var fullCitation = authorInCitation + ' (' + doiRegistrationYear + '). ' + doiData.title + '. ' + doiData.publisher + ' (ESRF). ' +
" <a href='https://doi.esrf.fr/" + doiData.doi + "'> doi:" + doiData.doi.toUpperCase() + "</a>";
return fullCitation;
}
};
......@@ -53,6 +53,7 @@ DOIView.prototype.renderExperimentalReportData = function (data) {
DOIView.prototype.renderDOIData = function (doiData) {
var _this = this;
console.log(doiData);
dust.render('landingpage_tpl', {
data: doiData,
constants : CONSTANTS
......
......@@ -22,7 +22,7 @@ JsonExtractor.prototype.getTitle = function (data) {
}
console.log('[JSON EXTRACTOR ERROR] title extraction failed.');
return null;
}
};
/**
* Extract the DOI number from the datacite's JSON response.
......@@ -37,7 +37,7 @@ JsonExtractor.prototype.getDOI = function (data) {
}
console.log('[JSON EXTRACTOR ERROR] doi extraction failed.');
return null;
}
};
/**
* Extract the DOI publisher from the datacite's JSON response.
......@@ -50,9 +50,10 @@ JsonExtractor.prototype.getPublisher = function (data) {
return data.publisher;
}
}
console.log('[JSON EXTRACTOR ERROR] publisher extraction failed.');
return null;
}
};
/**
* Extract the DOI authors/creators from the datacite's JSON response.
......@@ -63,21 +64,19 @@ JsonExtractor.prototype.getPublisher = function (data) {
JsonExtractor.prototype.getCreators = function (data) {
if (data) {
if (data.creators) {
return {
creators: _.map(data.creators, (item) => {
if ((item.givenName && item.familyName) || item.name) {
return item;
} else {
console.log('[JSON EXTRACTOR ERROR] one of the creator could not be properly extracted.');
return {};
}
})
}
return _.map(data.creators, function (item) {
if ((item.givenName && item.familyName) || item.name) {
return item;
} else {
console.log('[JSON EXTRACTOR ERROR] one of the creator could not be properly extracted.');
return {};
}
});
}
}
console.log('[JSON EXTRACTOR ERROR] Extraction of the creators failed.');
return null;
}
};
/**
......@@ -87,11 +86,11 @@ JsonExtractor.prototype.getCreators = function (data) {
*/
JsonExtractor.prototype.getPubliclyAccessibleYear = function (data) {
if (data && data.publicationYear) {
return data.publicationYear
return data.publicationYear;
}
console.log('[JSON EXTRACTOR ERROR] Extraction of the publication year failed.');
return null;
}
};
/**
* Extract investigationId from the data.doi field as received from the json response.
......@@ -128,15 +127,13 @@ JsonExtractor.prototype.getInvestigationId = function (data) {
* @param {string} field The text field which is searched
* @returns {array} the found field in an array. When the field is string composed of coma separated items, each item is returned in the array. When there is no text, an empty array is returned
*/
JsonExtractor.prototype.getFieldFromSubject = function (subject, field) {
if (subject) {
if (subject[0]) {
var regExp = new RegExp("^" + field + "$", 'i');
for (var i = 0; i < subject[0].length; i++) {
if (regExp.test(subject[0][i].subject_scheme)) {
if (subject[0][i].text) {
return _.split(subject[0][i].text, ',');
}
JsonExtractor.prototype.getFieldFromSubject = function (subjects, field) {
if (subjects) {
var regExp = new RegExp("^" + field + "$", 'i');
for (var i = 0; i < subjects.length; i++) {
if (regExp.test(subjects[i].subjectScheme)) {
if (subjects[i].subject) {
return _.split(subjects[i].subject, ',');
}
}
}
......@@ -150,12 +147,14 @@ JsonExtractor.prototype.getFieldFromSubject = function (subject, field) {
* @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();
}
}
return null;
// if (data) {
// if (data.date_registered && data.date_registered != null) {
// return moment(data.date_registered).year();
// }
// }
// return null;
};
/**
......@@ -165,10 +164,20 @@ JsonExtractor.prototype.getMintingYear = function (data) {
*/
JsonExtractor.prototype.getSessionDate = function (data) {
if (data) {
if (data.date_collected && data.date_collected != null) {
return moment(data.date_collected).format('YYYY-M-D');
if (data.dates && data.dates instanceof Array) {
var sessionDate = _.find(data.dates, function (item) {
if (item.dateType) {
return item.dateType.toLowerCase() === "collected";
}
});
if (sessionDate && sessionDate.date) {
return moment(sessionDate.date).format('YYYY-M-D');
}
}
}
console.log('[JSON EXTRACTOR ERROR] Extraction of session date failed.');
return null;
};
......@@ -179,26 +188,43 @@ JsonExtractor.prototype.getSessionDate = function (data) {
* @return {string} The resource type general. Null if it does not exist.
* */
JsonExtractor.prototype.getResourceTypeGeneral = function (data) {
if (data && data.resource_type_general) {
return data.resource_type_general;
// if (data && data.resource_type_general) {
// return data.resource_type_general;
// }
// return null;
if (data && data.types) {
for (var key in data.types) {
if (key === 'resourceTypeGeneral') {
return data.types[key];
}
}
}
console.log('[JSON EXTRACTOR ERROR] Extraction of resource type general failed.');
return null;
};
/**
* Get the resource type
* Get the resource type ("Experiment Session" or "Datacollection")
* @param {object} data The data object provided by datacite
* @return {string} Resource type. Null if it does not exist.
* */
JsonExtractor.prototype.getResourceType = function (data) {
if (data && data.resource_type) {
if (data.resource_type === "Experiment Session") {
return CONSTANTS.ES_RESOURCE_TYPE;
}
if (data.resource_type === "Datacollection") {
return CONSTANTS.DC_RESOURCE_TYPE;
if (data && data.types) {
for (var key in data.types) {
if (key === 'resourceType') {
if (data.types[key] === "Experiment Session") {
return CONSTANTS.ES_RESOURCE_TYPE;
}