Commit 6615a363 authored by Maxime Chaillet's avatar Maxime Chaillet
Browse files

Merge branch 'issue68' into 'master'

Use sessionDate and publication year to infere the publication date. Fix bug...

Closes #68

See merge request icat/doi-landing-page!79
parents 59838ab0 265cd582
...@@ -20,11 +20,13 @@ module.exports = function (config) { ...@@ -20,11 +20,13 @@ module.exports = function (config) {
'src/constants.js', 'src/constants.js',
'src/doicontroller.js', 'src/doicontroller.js',
'src/doiview.js', 'src/doiview.js',
'src/doiData.js',
'src/experimentalreportcontroller.js', 'src/experimentalreportcontroller.js',
'src/event.js', 'src/event.js',
'src/jsonextractor.js', 'src/jsonextractor.js',
'tests/jsonExtractor.test.js', 'tests/jsonExtractor.test.js',
'tests/doiController.test.js', 'tests/doiController.test.js',
'tests/doiData.test.js',
'bower_components/lodash/lodash.js', 'bower_components/lodash/lodash.js',
'bower_components/moment/moment.js' 'bower_components/moment/moment.js'
......
This diff is collapsed.
This diff is collapsed.
function DoiData(doi, dataciteLink, publisher, creator, publication_year) { function DoiData() {
this.doi = doi;
this.dataciteLink = dataciteLink;
this.publisher = publisher;
this.creator = creator;
this.publiclyAccessibleYear = publication_year;
} }
/** /**
...@@ -20,7 +15,8 @@ DoiData.prototype.getAccessibilityStatus = function (resourceType, sessionDate, ...@@ -20,7 +15,8 @@ DoiData.prototype.getAccessibilityStatus = function (resourceType, sessionDate,
if (resourceType) { if (resourceType) {
if (resourceType === CONSTANTS.ES_RESOURCE_TYPE) { if (resourceType === CONSTANTS.ES_RESOURCE_TYPE) {
if (publiclyAccessibleYear && sessionDate) { if (publiclyAccessibleYear && sessionDate) {
var publiclyAvailableDate = moment(publiclyAccessibleYear, "YYYY"); // take day and month of sessionDate and year of publiclyAccessibleYear
var publiclyAvailableDate = moment(sessionDate).year(parseInt(publiclyAccessibleYear));
var now = moment(); var now = moment();
if (now > publiclyAvailableDate) { if (now > publiclyAvailableDate) {
...@@ -29,7 +25,7 @@ DoiData.prototype.getAccessibilityStatus = function (resourceType, sessionDate, ...@@ -29,7 +25,7 @@ DoiData.prototype.getAccessibilityStatus = function (resourceType, sessionDate,
return "Restricted access"; return "Restricted access";
} }
} }
} else if (resourceType === CONSTANTS.DC_RESOURCE_TYPE){ } else if (resourceType === CONSTANTS.DC_RESOURCE_TYPE) {
return "Open access"; return "Open access";
} }
} }
......
...@@ -40,10 +40,7 @@ DOIController.prototype.render = function (doi, data) { ...@@ -40,10 +40,7 @@ DOIController.prototype.render = function (doi, data) {
} else { } else {
// Extract data and fill doiData with it // Extract data and fill doiData with it
var doiData = new DoiData(); 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(); var jsonExtractor = new JsonExtractor();
doiData.title = jsonExtractor.getTitle(data); doiData.title = jsonExtractor.getTitle(data);
...@@ -53,6 +50,8 @@ DOIController.prototype.render = function (doi, data) { ...@@ -53,6 +50,8 @@ DOIController.prototype.render = function (doi, data) {
doiData.creators = jsonExtractor.getCreators(data); doiData.creators = jsonExtractor.getCreators(data);
doiData.publiclyAccessibleYear = jsonExtractor.getPubliclyAccessibleYear(data); doiData.publiclyAccessibleYear = jsonExtractor.getPubliclyAccessibleYear(data);
console.log(doiData.publiclyAccessibleYear );
doiData.abstract = jsonExtractor.getAbstract(data); doiData.abstract = jsonExtractor.getAbstract(data);
doiData.investigationId = jsonExtractor.getInvestigationId(data); doiData.investigationId = jsonExtractor.getInvestigationId(data);
doiData.resourceType = jsonExtractor.getResourceType(data); doiData.resourceType = jsonExtractor.getResourceType(data);
......
...@@ -17,11 +17,11 @@ ...@@ -17,11 +17,11 @@
<div class="col-6 col-md"> <div class="col-6 col-md">
<div class="myBorder-left"> <div class="myBorder-left">
<label> Publication year </label> <label> Publication year </label>
{?data.mintingYear} {?data.publiclyAccessibleYear}
<div class="padding-left-15">{data.mintingYear}</div> <div class="padding-left-15">{data.publiclyAccessibleYear}</div>
{:else} {:else}
<div class="padding-left-15"> Not available</div> <div class="padding-left-15"> Not available</div>
{/data.mintingYear} {/data.publiclyAccessibleYear}
</div> </div>
</div> </div>
......
describe('DoiData', () => {
describe('getAccessibilityStatus', () => {
it('Returns open access when today is after publication date', () => {
let doiData = new DoiData();
let actualReourceType = CONSTANTS.ES_RESOURCE_TYPE;
let actualSessionDate = "2017-01-01"
let actualPubliclyAccessibleYear = "2018"
expect(doiData.getAccessibilityStatus(actualReourceType, actualSessionDate, actualPubliclyAccessibleYear)).toEqual("Open access");
})
it('Returns Restricted access when today is before publication date', () => {
let doiData = new DoiData();
let actualReourceType = CONSTANTS.ES_RESOURCE_TYPE;
let actualSessionDate = "2017-01-01"
let actualPubliclyAccessibleYear = "2020"
expect(doiData.getAccessibilityStatus(actualReourceType, actualSessionDate, actualPubliclyAccessibleYear)).toEqual("Restricted access");
})
})
})
\ No newline at end of file
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