Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Maxime Chaillet
doi-landing-page
Commits
610a0eab
Commit
610a0eab
authored
Jan 17, 2019
by
Chaillet Maxime
Browse files
Write more tests on the json extractor.
parent
42abc767
Pipeline
#7477
failed with stages
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
www/karma.conf.js
View file @
610a0eab
...
...
@@ -55,26 +55,12 @@ module.exports = function (config) {
// enable / disable colors in the output (reporters and logs)
colors
:
true
,
client
:
{
captureConsole
:
true
},
browserConsoleLogOptions
:
{
level
:
'
log
'
,
format
:
'
%b %T: %m
'
,
terminal
:
true
},
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel
:
config
.
LOG_INFO
,
// enable / disable watching file and executing tests whenever any file changes
autoWatch
:
true
,
...
...
www/src/doicontroller.js
View file @
610a0eab
...
...
@@ -57,6 +57,7 @@ DOIController.prototype.render = function (doi, data) {
doiData
.
dataciteLink
=
_this
.
doiServer
+
doi
;
doiData
.
publisher
=
jsonExtractor
.
getPublisher
(
data
);
doiData
.
creators
=
jsonExtractor
.
getCreators
(
data
);
doiData
.
publiclyAccessibleYear
=
jsonExtractor
.
getPubliclyAccessibleYear
(
data
);
...
...
www/src/jsonextractor.js
View file @
610a0eab
...
...
@@ -7,7 +7,7 @@ function JsonExtractor() {
/**
* Extract the DOI title from the datacite's JSON response.
* @param {
string
} data The data object provided by datacite
* @param {
json
} data The data object provided by datacite
* @return {string} doi title. Null if it does not exist
*/
JsonExtractor
.
prototype
.
getTitle
=
function
(
data
)
{
...
...
@@ -20,12 +20,13 @@ JsonExtractor.prototype.getTitle = function (data) {
}
}
}
console
.
log
(
'
[JSON EXTRACTOR ERROR] title extraction failed.
'
);
return
null
;
}
/**
* Extract the DOI number from the datacite's JSON response.
* @param {
string
} data The data object provided by datacite
* @param {
json
} data The data object provided by datacite
* @return {string} doi number. Null if it does not exist.
*/
JsonExtractor
.
prototype
.
getDOI
=
function
(
data
)
{
...
...
@@ -34,12 +35,13 @@ JsonExtractor.prototype.getDOI = function (data) {
return
data
.
doi
.
toUpperCase
();
}
}
console
.
log
(
'
[JSON EXTRACTOR ERROR] doi extraction failed.
'
);
return
null
;
}
/**
* Extract the DOI publisher from the datacite's JSON response.
* @param {
string
} data The data object provided by datacite
* @param {
json
} data The data object provided by datacite
* @return {string} doi publisher. Null if it does not exist.
*/
JsonExtractor
.
prototype
.
getPublisher
=
function
(
data
)
{
...
...
@@ -48,49 +50,77 @@ JsonExtractor.prototype.getPublisher = function (data) {
return
data
.
publisher
;
}
}
console
.
log
(
'
[JSON EXTRACTOR ERROR] publisher extraction failed.
'
);
return
null
;
}
/**
* Extract the DOI authors/creators from the datacite's JSON response.
* @param {
string
} data The data object provided by datacite
* @return {array} doi creators. Null if
it
does not exist. When creators details are not available, it returns
* a
null
item within the
table
.
* @param {
json
} data The data object provided by datacite
* @return {array} doi creators. Null if
creators
does not exist. When creators details are not available, it returns
* a
n empty
item within the
array for each badly extracted creator
.
*/
JsonExtractor
.
prototype
.
getCreators
=
function
(
data
)
{
console
.
log
(
'
salut
'
)
if
(
data
)
{
if
(
data
.
creators
)
{
var
test
=
_
.
map
(
data
.
creators
,
(
item
)
=>
{
if
((
item
.
givenName
&&
item
.
familyName
)
||
item
.
name
)
{
return
item
;
}
else
{
return
null
;
}
})
console
.
log
(
test
)
return
{
creators
:
test
creators
:
_
.
map
(
data
.
creators
,
(
item
)
=>
{
if
((
item
.
givenName
&&
item
.
familyName
)
||
item
.
name
)
{
return
item
;
}
else
{
console
.
log
(
'
[JSON EXTRACTOR ERROR] one of the creator could not be properly extracted.
'
);
return
{};
}
})
}
}
}
console
.
log
(
'
[JSON EXTRACTOR ERROR] Extraction of the creators failed.
'
);
return
null
;
}
/**
* Extract the year the DOI referenced data will become publicly available.
* @param {json} data json datacite object
* @return {string} the year. Null if extraction failed.
*/
JsonExtractor
.
prototype
.
getPubliclyAccessibleYear
=
function
(
data
)
{
if
(
data
&&
data
.
publicationYear
)
{
return
data
.
publicationYear
}
console
.
log
(
'
[JSON EXTRACTOR ERROR] Extraction of the publication year failed.
'
);
return
null
;
}
/**
* Extract investigationId from the data.doi field as received from the json
* response.
* Extract investigationId from the data.doi field as received from the json response.
* @param {string} data The data object provided by datacite
* @return {string}
investigationId The
investigationID requested for accessing data in ICAT.
* @return {string} investigationID requested for accessing data in ICAT.
Null if it failed
*/
JsonExtractor
.
prototype
.
getInvestigationId
=
function
(
data
)
{
var
regExp
=
RegExp
(
/
\/\w
*-*
[
Ee
][
Ss
][
Rr
][
Ff
]
-
[
Ee
][
Ss
]
-
(\d
+
)
$/
);
if
(
regExp
.
exec
(
data
.
doi
))
{
return
regExp
.
exec
(
data
.
doi
)[
1
];
}
console
.
log
(
'
[JSON EXTRACTOR ERROR] investigationId extraction failed.
'
);
return
null
;
};
/**
* Extract field value (beamline, proposal number and proposal type) from the
* data json object. Returns null if the field is not found.
...
...
www/tests/jsonExtractor.test.js
View file @
610a0eab
...
...
@@ -238,23 +238,84 @@ describe("jsonExtractor", () => {
let
actualDOIdata
=
{
"
creators
"
:
[
{
"
nameType
"
:
"
Personal
"
,
"
name
"
:
"
LEAKE, Steven
"
,
"
givenName
"
:
"
Steven
"
,
"
familyName
"
:
"
LEAKE
"
"
nameType
"
:
"
Personal
"
,
"
name
"
:
"
LEAKE, Steven
"
,
"
givenName
"
:
"
Steven
"
,
"
familyName
"
:
"
LEAKE
"
},
{
"
nameType
"
:
"
Personal
"
,
"
name
"
:
"
ZATTERIN, Edoardo
"
,
"
givenName
"
:
"
Edoardo
"
,
"
familyName
"
:
"
ZATTERIN
"
"
nameType
"
:
"
Personal
"
,
"
name
"
:
"
ZATTERIN, Edoardo
"
,
"
givenName
"
:
"
Edoardo
"
,
"
familyName
"
:
"
ZATTERIN
"
}
]
]
};
let
expectedCreators
=
actualDOIdata
;
let
myJsonExtractor
=
new
JsonExtractor
();
expect
(
myJsonExtractor
.
get
Publisher
(
actualDOIdata
)).
toEqual
(
expectedCreators
);
expect
(
myJsonExtractor
.
get
Creators
(
actualDOIdata
)).
toEqual
(
expectedCreators
);
})
it
(
'
returns only the creators for which givenName && familyName is defined or name is defined
'
,
()
=>
{
let
actualDOIdata
=
{
"
creators
"
:
[
{
"
nameType
"
:
"
Personal
"
,
"
name
"
:
"
LEAKE, Steven
"
,
},
{
"
nameType
"
:
"
Personal
"
,
},
{
"
nameType
"
:
"
Personal
"
,
"
name
"
:
"
ZATTERIN, Edoardo
"
,
"
givenName
"
:
"
Edoardo
"
,
"
familyName
"
:
"
ZATTERIN
"
}
]
};
let
expectedCreators
=
{
"
creators
"
:
[
{
"
nameType
"
:
"
Personal
"
,
"
name
"
:
"
LEAKE, Steven
"
,
},
{},
{
"
nameType
"
:
"
Personal
"
,
"
name
"
:
"
ZATTERIN, Edoardo
"
,
"
givenName
"
:
"
Edoardo
"
,
"
familyName
"
:
"
ZATTERIN
"
}
]
};;
let
myJsonExtractor
=
new
JsonExtractor
();
expect
(
myJsonExtractor
.
getCreators
(
actualDOIdata
)).
toEqual
(
expectedCreators
);
})
})
describe
(
"
GetPubliclyAccessibleYear
"
,
()
=>
{
it
(
'
returns the year the data will be publicly accessible
'
,
()
=>
{
let
actualDOIdata
=
{
"
publicationYear
"
:
2021
};
let
expectedCreators
=
2021
;
let
myJsonExtractor
=
new
JsonExtractor
();
expect
(
myJsonExtractor
.
getPubliclyAccessibleYear
(
actualDOIdata
)).
toEqual
(
expectedCreators
);
})
it
(
'
returns null when the year the data will be publicly accessible is not available
'
,
()
=>
{
let
actualDOIdata
=
{
"
publicationYear
"
:
null
};
let
expectedCreators
=
null
;
let
myJsonExtractor
=
new
JsonExtractor
();
expect
(
myJsonExtractor
.
getPubliclyAccessibleYear
(
actualDOIdata
)).
toEqual
(
expectedCreators
);
})
})
})
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment