Commit 2434ed2a authored by Maxime Chaillet's avatar Maxime Chaillet

Fix investigationId retrieval with data collection DOI because they have no investigationId.

parent 34de74a2
......@@ -68,7 +68,7 @@ DOIController.prototype.getData = function (doi) {
var jsonExtractor = new JsonExtractor();
doiData.abstract = jsonExtractor.getAbstract(data);
doiData.investigationId = jsonExtractor.extractInvestigationId(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);
......
......@@ -7,9 +7,12 @@ function JsonExtractor(json) {
* @param {string} data The data object provided by datacite
* @return {string} investigationId The investigationID requested for accessing data in ICAT.
*/
JsonExtractor.prototype.extractInvestigationId = function (data) {
JsonExtractor.prototype.getInvestigationId = function (data) {
var regExp = RegExp(/\/\w*-*[Ee][Ss][Rr][Ff]-[Ee][Ss]-(\d+)$/);
return regExp.exec( data.doi )[1];
if (regExp.exec( data.doi )){
return regExp.exec( data.doi )[1];
}
return null;
};
/**
......
......@@ -135,4 +135,22 @@ describe("jsonExtractor", () => {
expect(myJsonExtractor.getMergedProposalAndBeamline(actualProposals, actualBeamlines, actualBeamlineUrls)).toEqual(expectedMerge);
})
})
describe("GetInvestigationId", () => {
it("returns investigationId for a experimental session doi", () => {
let actualDOIdata = { doi: "10.15151/ESRF-ES-130874985" };
let expectedInvestigationId = "130874985";
let myJsonExtractor = new JsonExtractor();
expect(myJsonExtractor.getInvestigationId(actualDOIdata)).toEqual(expectedInvestigationId);
})
it("returns null for a data collection doi", () => {
let actualDOIdata = { doi: "10.15151/ESRF-DC-130874985" };
let expectedInvestigationId = null;
let myJsonExtractor = new JsonExtractor();
expect(myJsonExtractor.getInvestigationId(actualDOIdata)).toEqual(expectedInvestigationId);
})
})
})
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