DoiBoost AccessRigh #4362 - Fixed issue on date formatting. Added test method and associated resource

This commit is contained in:
Miriam Baglioni 2021-07-16 17:30:27 +02:00
parent 3bc9a05bc9
commit 199123b74b
3 changed files with 1600 additions and 9 deletions

View File

@ -149,10 +149,9 @@ object DoiBoostMappingUtil {
//OUP (BUT ONLY AFTER 12 MONTHS FROM THE PUBLICATION DATE, OTHERWISE THEY ARE EMBARGOED)
if(license.equals("https://academic.oup.com/journals/pages/open_access/funder_policies/chorus/standard_publication_model")){
val now = java.time.LocalDate.now
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
val pub_date = LocalDate.parse(date, formatter)
try{
val pub_date = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd"))
if (((now.toEpochDay - pub_date.toEpochDay)/365.0) > 1){
val oaq : AccessRight = getOpenAccessQualifier()
oaq.setOpenAccessRoute(OpenAccessRoute.hybrid)
@ -161,6 +160,39 @@ object DoiBoostMappingUtil {
else{
return getEmbargoedAccessQualifier()
}
}catch {
case e: Exception => {
try{
val pub_date = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"))
if (((now.toEpochDay - pub_date.toEpochDay)/365.0) > 1){
val oaq : AccessRight = getOpenAccessQualifier()
oaq.setOpenAccessRoute(OpenAccessRoute.hybrid)
return oaq
}
else{
return getEmbargoedAccessQualifier()
}
}catch{
case ex: Exception => return getClosedAccessQualifier()
}
}
}
//val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
// val pub_date = LocalDate.parse(date, formatter)
// if (((now.toEpochDay - pub_date.toEpochDay)/365.0) > 1){
// val oaq : AccessRight = getOpenAccessQualifier()
// oaq.setOpenAccessRoute(OpenAccessRoute.hybrid)
// return oaq
// }
// else{
// return getEmbargoedAccessQualifier()
// }
}
return getClosedAccessQualifier()

View File

@ -589,6 +589,27 @@ class CrossrefMappingTest {
}
@Test
def testLicenseEmbargoDateTime() :Unit = {
val json = Source.fromInputStream(getClass.getResourceAsStream("publication_license_embargo_datetime.json")).mkString
assertNotNull(json)
assertFalse(json.isEmpty);
val resultList: List[Oaf] = Crossref2Oaf.convert(json)
assertTrue(resultList.nonEmpty)
val item : Result = resultList.filter(p => p.isInstanceOf[Result]).head.asInstanceOf[Result]
assertTrue(item.getInstance().asScala exists (i => i.getLicense.getValue.equals("https://academic.oup.com/journals/pages/open_access/funder_policies/chorus/standard_publication_model")))
assertTrue(item.getInstance().asScala exists (i => i.getAccessright.getClassid.equals("EMBARGO")))
assertTrue(item.getInstance().asScala exists (i => i.getAccessright.getOpenAccessRoute == null))
mapper.getSerializationConfig.enable(SerializationConfig.Feature.INDENT_OUTPUT)
println(mapper.writeValueAsString(item))
}
}