Commit c77a2ebd authored by Maxime Chaillet's avatar Maxime Chaillet

it fixes #76

parent 75806d13
This diff is collapsed.
......@@ -134,7 +134,7 @@ JsonExtractor.prototype.getFieldFromSubject = function (subjects, 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();
......@@ -242,16 +242,30 @@ JsonExtractor.prototype.getAbstract = function (data) {
* @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, beamlineUrls) {
if (proposals && beamlines && beamlineUrls && proposals.length === beamlines.length && proposals.length === beamlineUrls.length) {
if (proposals && beamlines && beamlineUrls) {
var result = [];
for (var index = 0; index < proposals.length; index++) {
result.push({
proposal: proposals[index],
beamline: beamlines[index],
beamlineUrl: beamlineUrls[index]
});
var index = 0;
if (proposals.length === beamlines.length && proposals.length === beamlineUrls.length) {
for (index; index < proposals.length; index++) {
result.push({
proposal: proposals[index],
beamline: beamlines[index],
beamlineUrl: beamlineUrls[index]
});
}
return _.uniqBy(result, function (value) { return JSON.stringify(value); });
}
if (proposals.length >= 1 && beamlines.length === 1 && beamlineUrls.length === 1) {
for (index = 0; index < proposals.length; index++) {
result.push({
proposal: proposals[index],
beamline: beamlines[0],
beamlineUrl: beamlineUrls[0]
});
}
return _.uniqBy(result, function (value) { return JSON.stringify(value); });
}
return _.uniqBy(result, function (value) { return JSON.stringify(value); });
}
return null;
};
......
......@@ -159,6 +159,20 @@ describe("jsonExtractor", () => {
expect(myJsonExtractor.getMergedProposalAndBeamline(actualProposals, actualBeamlines, actualBeamlineUrls)).toEqual(expectedMerge);
})
it('merge proposals and from a single beamline in a single table', () => {
let actualProposals = ['MA-4196', 'MD-1207'];
let actualBeamlines = ['ID21'];
let actualBeamlineUrls = ["http://www.esrf.eu/UsersAndScience/Experiments/XNP/ID21"];
let expectedMerge = [
{ proposal: 'MA-4196', beamline: 'ID21', beamlineUrl: "http://www.esrf.eu/UsersAndScience/Experiments/XNP/ID21" },
{ proposal: 'MD-1207', beamline: 'ID21', beamlineUrl: "http://www.esrf.eu/UsersAndScience/Experiments/XNP/ID21" }
];
let myJsonExtractor = new JsonExtractor();
expect(myJsonExtractor.getMergedProposalAndBeamline(actualProposals, actualBeamlines, actualBeamlineUrls)).toEqual(expectedMerge);
})
})
describe("GetInvestigationId", () => {
......@@ -326,7 +340,7 @@ describe("jsonExtractor", () => {
"familyName": "ZATTERIN"
}
];
let myJsonExtractor = new JsonExtractor();
expect(myJsonExtractor.getCreators(actualDOIdata)).toEqual(expectedCreators);
})
......
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