GitLab will be upgraded on June 23rd evening. During the upgrade the service will be unavailable, sorry for the inconvenience.

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