Commit 14e1ad71 authored by Maxime Chaillet's avatar Maxime Chaillet

add urls to beamlines

parent 08a35f6f
This diff is collapsed.
This diff is collapsed.
...@@ -71,7 +71,7 @@ DOIController.prototype.getData = function (doi) { ...@@ -71,7 +71,7 @@ DOIController.prototype.getData = function (doi) {
doiData.dataciteLink = _this.doiServer + doi; doiData.dataciteLink = _this.doiServer + doi;
doiData.publisher = data.publisher; doiData.publisher = data.publisher;
doiData.creator = data.creator; doiData.creator = data.creator;
var jsonExtractor = new JsonExtractor(); var jsonExtractor = new JsonExtractor();
doiData.abstract = jsonExtractor.getAbstract(data); doiData.abstract = jsonExtractor.getAbstract(data);
doiData.mintingYear = jsonExtractor.getMintingYear(data); doiData.mintingYear = jsonExtractor.getMintingYear(data);
...@@ -80,11 +80,11 @@ DOIController.prototype.getData = function (doi) { ...@@ -80,11 +80,11 @@ DOIController.prototype.getData = function (doi) {
doiData.proposalType = jsonExtractor.getFieldFromSubject(data.subject, "Proposal Type Description"); doiData.proposalType = jsonExtractor.getFieldFromSubject(data.subject, "Proposal Type Description");
doiData.proposalNames = jsonExtractor.getFieldFromSubject(data.subject, "Proposal"); doiData.proposalNames = jsonExtractor.getFieldFromSubject(data.subject, "Proposal");
console.log(doiData.proposalNames);
_this.experimentalReportController.requestFilenameList(doiData.proposalName); _this.experimentalReportController.requestFilenameList(doiData.proposalName);
doiData.beamlines = jsonExtractor.getFieldFromSubject(data.subject, "Instrument"); doiData.beamlines = jsonExtractor.getFieldFromSubject(data.subject, "Instrument");
doiData.mergedProposalBeamlines = jsonExtractor.getMergedProposalAndBeamline(doiData.proposalNames, doiData.beamlines);
doiData.investigationId = jsonExtractor.extractInvestigationId(data); doiData.investigationId = jsonExtractor.extractInvestigationId(data);
doiData.resourceType = jsonExtractor.getResourceType(data); doiData.resourceType = jsonExtractor.getResourceType(data);
...@@ -98,13 +98,21 @@ DOIController.prototype.getData = function (doi) { ...@@ -98,13 +98,21 @@ DOIController.prototype.getData = function (doi) {
doiData.ES_RESOURCE_TYPE = CONSTANTS.ES_RESOURCE_TYPE; doiData.ES_RESOURCE_TYPE = CONSTANTS.ES_RESOURCE_TYPE;
// Set the URL corresponding to the beamline name. // Set the URL corresponding to the beamline name.
if (data.date_collected) { if (doiData.resourceType === CONSTANTS.ES_RESOURCE_TYPE) {
var experimentalDate = moment(data.date_collected); if (data.date_collected) {
doiData.beamlineUrl = _this.getBeamlineUrl(doiData.beamline, experimentalDate); var experimentalDate = moment(data.date_collected);
} else { doiData.beamlineUrls = _this.getBeamlineUrl(doiData.beamlines, experimentalDate);
doiData.beamlineUrl = "noLink"; }
} }
if (doiData.resourceType === CONSTANTS.DC_RESOURCE_TYPE) {
if (data.publication_year) {
var publicationDate = moment(data.publication_year, "YYYY");
doiData.beamlineUrls = _this.getBeamlineUrl(doiData.beamlines, publicationDate);
}
}
doiData.mergedProposalBeamlines = jsonExtractor.getMergedProposalAndBeamline(doiData.proposalNames, doiData.beamlines, doiData.beamlineUrls);
// send to dust render // send to dust render
_this.view.renderDOIData(doiData); _this.view.renderDOIData(doiData);
...@@ -162,23 +170,29 @@ DOIController.prototype.setOrigin = function (origin) { ...@@ -162,23 +170,29 @@ DOIController.prototype.setOrigin = function (origin) {
/** /**
* Get the corresponding url for a given beamline name * Get the corresponding url for a given beamline name
* * @param {array} beamlines The beamline name
* @param {string} * @param {momentJS} date The date the experiment was performed.
* beamline The beamline name * @return {array} an array containing urls of the beamLine(s).
* @param {momnetJS}
* date The date the experiment was performed.
* @return the url of the beamLine, null if it is not found
*/ */
DOIController.prototype.getBeamlineUrl = function (beamline, date) { DOIController.prototype.getBeamlineUrl = function (beamlines, date) {
for (var i = 0; i < BEAMLINEURL.length; i++) { var result = [];
var startDate = moment(BEAMLINEURL[i].startDate); beamlines.forEach(function (beamline) {
var endDate = moment(BEAMLINEURL[i].endDate); for (var i = 0; i < BEAMLINEURL.length; i++) {
if (BEAMLINEURL[i].name.toLowerCase() === beamline.toLowerCase() && date >= startDate && date <= endDate) { var foundUrl = "";
return BEAMLINEURL[i].url; var startDate = moment(BEAMLINEURL[i].startDate);
var endDate = moment(BEAMLINEURL[i].endDate);
if (BEAMLINEURL[i].name.toLowerCase() === beamline.toLowerCase() && date >= startDate && date <= endDate) {
foundUrl = BEAMLINEURL[i].url;
break;
}
} }
} if (foundUrl === "") {
result.push("no link");
return null; } else {
result.push(foundUrl);
}
});
return result;
}; };
/** /**
......
...@@ -23,7 +23,7 @@ JsonExtractor.prototype.extractInvestigationId = function (data) { ...@@ -23,7 +23,7 @@ JsonExtractor.prototype.extractInvestigationId = function (data) {
JsonExtractor.prototype.getFieldFromSubject = function (subject, field) { JsonExtractor.prototype.getFieldFromSubject = function (subject, field) {
if (subject) { if (subject) {
if (subject[0]) { if (subject[0]) {
var regExp = new RegExp("^" + field, 'i'); var regExp = new RegExp("^" + field + "$", 'i');
for (var i = 0; i < subject[0].length; i++) { for (var i = 0; i < subject[0].length; i++) {
if (regExp.test(subject[0][i].subject_scheme)) { if (regExp.test(subject[0][i].subject_scheme)) {
if (subject[0][i].text) { if (subject[0][i].text) {
...@@ -113,19 +113,21 @@ JsonExtractor.prototype.getAbstract = function (data) { ...@@ -113,19 +113,21 @@ JsonExtractor.prototype.getAbstract = function (data) {
* merge proposal and beamlines together and remove proposal, beamline duplicates if any * merge proposal and beamlines together and remove proposal, beamline duplicates if any
* @param {array} proposals the extracted proposals * @param {array} proposals the extracted proposals
* @param {array} beamlines the extracted beamlines * @param {array} beamlines the extracted beamlines
* @return {array} array of the form [ [proposal1, beamline1] , [proposal2, beamline2] ]. Null if input array length are not equal * @param {array} beamlineUrls the extracted beamline urls
* @return {array} array of the form [ {proposal: 'proposal1', beamline: 'beamline1', beamlineUrl: 'beamlineUrl' ] , {}, ... ]. Null if input array length are not equal
*/ */
JsonExtractor.prototype.getMergedProposalAndBeamline = function (proposals, beamlines) { JsonExtractor.prototype.getMergedProposalAndBeamline = function (proposals, beamlines, beamlineUrls) {
console.log(proposals); if (proposals && beamlines && beamlineUrls && proposals.length === beamlines.length && proposals.length === beamlineUrls.length) {
console.log(beamlines);
if (proposals && beamlines && proposals.length === beamlines.length) {
var result = []; var result = [];
for (var index = 0; index < proposals.length; index++) { for (var index = 0; index < proposals.length; index++) {
result.push(new Array(proposals[index], beamlines[index])); result.push({
proposal: proposals[index],
beamline: beamlines[index],
beamlineUrl: beamlineUrls[index]
});
} }
return _.uniqBy(result, function (value) { return JSON.stringify(value); }); return _.uniqBy(result, function (value) { return JSON.stringify(value); });
} }
return null; return null;
} };
...@@ -16,12 +16,18 @@ function proposalBeamlineTable(chunk, context, bodies, params) { ...@@ -16,12 +16,18 @@ function proposalBeamlineTable(chunk, context, bodies, params) {
if (proposalAndBeamlines) { if (proposalAndBeamlines) {
for (var index = 0; index < proposalAndBeamlines.length; index++) { for (var index = 0; index < proposalAndBeamlines.length; index++) {
if (proposalAndBeamlines[index] instanceof Array) { if (proposalAndBeamlines[index]) {
var proposal = proposalAndBeamlines[index][0] || 'unknown'; var proposal = proposalAndBeamlines[index].proposal || 'unknown';
var beamline = proposalAndBeamlines[index][1] || 'unknown'; var beamline = proposalAndBeamlines[index].beamline || 'unknown';
var beamlineUrl = proposalAndBeamlines[index].beamlineUrl;
chunk.write('<tr>'); chunk.write('<tr>');
chunk.write('<td>' + proposal + '</td>'); chunk.write('<td>' + proposal + '</td>');
chunk.write('<td>' + beamline + '</td>'); if (beamlineUrl === "noLink") {
chunk.write('<td>' + beamline + '</td>');
} else {
chunk.write('<td> <a href="' + beamlineUrl + '" target="_blank">' + beamline + ' </a> </td>');
}
chunk.write('</tr>'); chunk.write('</tr>');
} else { } else {
chunk.write('<tr>'); chunk.write('<tr>');
...@@ -47,7 +53,7 @@ function abstract(chunk, context, bodies, params) { ...@@ -47,7 +53,7 @@ function abstract(chunk, context, bodies, params) {
if (abstract) { if (abstract) {
chunk.write(abstract); chunk.write(abstract);
} else { } else {
chunk.write('There is no abstract for this session.') chunk.write('There is no abstract for this session.');
} }
chunk.write('</div >'); chunk.write('</div >');
......
<div class="row margin-left-0 margin-right-0"> <div class="row margin-left-0 margin-right-0">
{@eq key=data.resourceType value=CONSTANTS.ES_RESOURCE_TYPE} {@eq key=data.resourceType value=data.ES_RESOURCE_TYPE}
<div class="col-auto padding-right-2 padding-left-2"> <div class="col-auto padding-right-2 padding-left-2">
<span class="badge badge-secondary font-1p4rem " > Session </span> <span class="badge badge-secondary font-1p4rem " > Session </span>
</div> </div>
{/eq} {/eq}
{@eq key=data.resourceType value=CONSTANTS.DC_RESOURCE_TYPE} {@eq key=data.resourceType value=data.DC_RESOURCE_TYPE}
<div class="col-auto padding-right-2 padding-left-2"> <div class="col-auto padding-right-2 padding-left-2">
<span class="badge badge-secondary font-1p4rem " > Collection </span> <span class="badge badge-secondary font-1p4rem " > Data collection </span>
</div> </div>
{/eq} {/eq}
......
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
<hr> <hr>
<div class="row" id="metadata"> </div> <div id="metadata"> </div>
<hr> <hr>
......
{! Presentation of the metadata for the DOI which are from sessions !}
{@eq key=data.resourceType value=data.ES_RESOURCE_TYPE} {@eq key=data.resourceType value=data.ES_RESOURCE_TYPE}
<div class="col"> <div class="row">
<div class="myBorder-left"> {?data.mergedProposalBeamlines}
<label> Proposal </label> {?data.mergedProposalBeamlines[0]}
{?data.proposalName} <div class="col">
<div class="padding-left-15">{data.proposalName}</div> <div class="myBorder-left">
<label> Proposal </label>
{?data.mergedProposalBeamlines[0].proposal}
<div class="padding-left-15">{data.mergedProposalBeamlines[0].proposal}</div>
{:else}
<div class="padding-left-15"> Not available</div>
{/data.mergedProposalBeamlines[0].proposal}
</div>
</div>
<div class="col">
<div class="myBorder-left">
<label> Publication year </label>
{?data.mintingYear}
<div class="padding-left-15">{data.mintingYear}</div>
{:else} {:else}
<div class="padding-left-15"> Not available</div> <div class="padding-left-15"> Not available</div>
{/data.proposalName} {/data.mintingYear}
</div>
</div> </div>
</div>
<div class="col"> <div class="col">
<div class="myBorder-left"> <div class="myBorder-left">
<label> Publication year </label> <label> Beamline </label>
{?data.mintingYear} {?data.mergedProposalBeamlines[0].beamline}
<div class="padding-left-15">{data.mintingYear}</div> {@eq key=data.mergedProposalBeamlines[0].beamlineUrl value="noLink"}
{:else} <div class="padding-left-15">{data.mergedProposalBeamlines[0].beamline}</div>
<div class="padding-left-15"> Not available</div> {:else}
{/data.mintingYear} <div class="padding-left-15">
<a href="{data.mergedProposalBeamlines[0].beamlineUrl}" target="_blank"> {data.mergedProposalBeamlines[0].beamline} </a>
</div>
{/eq}
{:else}
<div class="padding-left-15">Not available</div>
{/data.mergedProposalBeamlines[0].beamline}
</div>
</div> </div>
</div>
<div class="col"> <div class="col">
<div class="myBorder-left"> <div class="myBorder-left">
<label> Beamline </label> <label> Session date </label>
{?data.beamline} {?data.sessionDate}
{@eq key=data.beamlineUrl value="noLink"} <div class="padding-left-15">{data.sessionDate}</div>
<div class="padding-left-15">{data.beamline}</div>
{:else}
<div class="padding-left-15">
<a href="{data.beamlineUrl}" target="_blank"> {data.beamline} </a>
</div>
{/eq}
{:else} {:else}
<div class="padding-left-15">Not available</div> <div class="padding-left-15"> Not available</div>
{/data.beamline} {/data.sessionDate}
</div> </div>
</div> </div>
<div class="col"> <div class="col-4">
<div class="myBorder-left"> <div class="myBorder-left">
<label> Session date </label> <label>Category </label>
{?data.sessionDate} {?data.proposalType}
<div class="padding-left-15">{data.sessionDate}</div> <div class="padding-left-15">{data.proposalType}</div>
{:else} {:else}
<div class="padding-left-15"> Not available</div> <div class="padding-left-15"> Not available</div>
{/data.sessionDate} {/data.proposalType}
</div> </div>
</div> </div>
{/data.mergedProposalBeamlines[0]}
<div class="col-4"> {/data.mergedProposalBeamlines}
<div class="myBorder-left"> </div>
<label>Category </label>
{?data.proposalType}
<div class="padding-left-15">{data.proposalType}</div>
{:else}
<div class="padding-left-15"> Not available</div>
{/data.proposalType}
</div>
</div>
<hr>
<div class="row"> <hr>
<div class="col-12">
{@abstract abstract=data.abstract} {/abstract} <div class="row">
</div> <div class="col-12">
</div> {@abstract abstract=data.abstract} {/abstract}
</div>
</div>
{/eq}
{/eq}
{! Presentation of the metadata for the DOI which are from dataset collections !}
{@eq key=data.resourceType value=data.DC_RESOURCE_TYPE} {@eq key=data.resourceType value=data.DC_RESOURCE_TYPE}
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
...@@ -97,4 +105,4 @@ ...@@ -97,4 +105,4 @@
</div> </div>
</div> </div>
{/eq} {/eq}
\ No newline at end of file
...@@ -110,19 +110,29 @@ describe("jsonExtractor", () => { ...@@ -110,19 +110,29 @@ describe("jsonExtractor", () => {
it('merge proposals and beamlines in a single table', () => { it('merge proposals and beamlines in a single table', () => {
let actualProposals = ['MA-4196', 'MD-1207']; let actualProposals = ['MA-4196', 'MD-1207'];
let actualBeamlines = ['ID11', 'ID21']; let actualBeamlines = ['ID11', 'ID21'];
let expectedMerge = [['MA-4196', 'ID11'], ['MD-1207', 'ID21']]; let actualBeamlineUrls = ["http://www.esrf.fr/UsersAndScience/Experiments/StructMaterials/ID11", "http://www.esrf.eu/UsersAndScience/Experiments/XNP/ID21"];
let expectedMerge = [
{ proposal: 'MA-4196', beamline: 'ID11', beamlineUrl: "http://www.esrf.fr/UsersAndScience/Experiments/StructMaterials/ID11" },
{ proposal: 'MD-1207', beamline: 'ID21', beamlineUrl: "http://www.esrf.eu/UsersAndScience/Experiments/XNP/ID21" }
];
let myJsonExtractor = new JsonExtractor(); let myJsonExtractor = new JsonExtractor();
expect(myJsonExtractor.getMergedProposalAndBeamline(actualProposals, actualBeamlines)).toEqual(expectedMerge); expect(myJsonExtractor.getMergedProposalAndBeamline(actualProposals, actualBeamlines, actualBeamlineUrls)).toEqual(expectedMerge);
}) })
it('merge proposals and beamlines in a single table and remove duplicates', () => { it('merge proposals and beamlines in a single table and remove duplicates', () => {
let actualProposals = ['MA-4196', 'MD-1207', 'MA-4196']; let actualProposals = ['MA-4196', 'MD-1207', 'MA-4196'];
let actualBeamlines = ['ID11', 'ID21', 'ID11']; let actualBeamlines = ['ID11', 'ID21', 'ID11'];
let expectedMerge = [['MA-4196', 'ID11'], ['MD-1207', 'ID21']]; let actualBeamlineUrls = ["http://www.esrf.fr/UsersAndScience/Experiments/StructMaterials/ID11", "http://www.esrf.eu/UsersAndScience/Experiments/XNP/ID21", "http://www.esrf.fr/UsersAndScience/Experiments/StructMaterials/ID11"];
let expectedMerge = [
{ proposal: 'MA-4196', beamline: 'ID11', beamlineUrl: "http://www.esrf.fr/UsersAndScience/Experiments/StructMaterials/ID11" },
{ proposal: 'MD-1207', beamline: 'ID21', beamlineUrl: "http://www.esrf.eu/UsersAndScience/Experiments/XNP/ID21" },
];
let myJsonExtractor = new JsonExtractor(); let myJsonExtractor = new JsonExtractor();
expect(myJsonExtractor.getMergedProposalAndBeamline(actualProposals, actualBeamlines)).toEqual(expectedMerge); expect(myJsonExtractor.getMergedProposalAndBeamline(actualProposals, actualBeamlines, actualBeamlineUrls)).toEqual(expectedMerge);
}) })
}) })
}) })
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