Skip to content

Commit

Permalink
ERM-1754: PCI accessStart and accessEnd dates should be ignored when …
Browse files Browse the repository at this point in the history
…PCI added as individual resource to agreement (#460)

* ERM-1754 Lists now compiled correctly

* fix: Change criteria, gson

Changed view file to use default non-expansion rather than special case for 'items' on SubscriptionAgreement. Removed valid access start/access end for direct pci entitlements in criteria

* test: Tweaks and new test

New test for resources attached to an agreement to check that direct entitlements ignore accessStart/accessEnd dates

Co-authored-by: Peter Boehm <[email protected]>
  • Loading branch information
EthanFreestone and peterboehm authored Sep 29, 2021
1 parent ee215e0 commit e8d3d12
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,6 @@ class SubscriptionAgreementController extends OkapiTenantAwareController<Subscri
ge 'activeTo', today
}
}
or {
isNull 'accessStart'
le 'accessStart', today
}
or {
isNull 'accessEnd'
ge 'accessEnd', today
}

projections {
property ('id')
Expand Down Expand Up @@ -415,24 +407,9 @@ class SubscriptionAgreementController extends OkapiTenantAwareController<Subscri
eq 'class', PackageContentItem
eq 'direct_ent.owner.id', subscriptionAgreementId

// Valid access start
or {
isNull 'accessStart'
isNull 'direct_ent.activeTo'
ltProperty 'accessStart', 'direct_ent.activeTo'
}

// Valid access end
or {
isNull 'accessEnd'
isNull 'direct_ent.activeFrom'
gtProperty 'accessEnd', 'direct_ent.activeFrom'
}

// Line or Resource in the past
or {
lt 'direct_ent.activeTo', today
lt 'accessEnd', today
}
}

Expand Down Expand Up @@ -498,24 +475,9 @@ class SubscriptionAgreementController extends OkapiTenantAwareController<Subscri
eq 'class', PackageContentItem
eq 'direct_ent.owner.id', subscriptionAgreementId

// Valid access start
or {
isNull 'accessStart'
isNull 'direct_ent.activeTo'
ltProperty 'accessStart', 'direct_ent.activeTo'
}

// Valid access end
or {
isNull 'accessEnd'
isNull 'direct_ent.activeFrom'
gtProperty 'accessEnd', 'direct_ent.activeFrom'
}

// Line or Resource in the future
or {
gt 'direct_ent.activeFrom', today
gt 'accessStart', today
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ json g.render(subscriptionAgreement, [expand: should_expand, excludes:['alternat
endDate subscriptionAgreement.endDate
cancellationDeadline subscriptionAgreement.cancellationDeadline

if (subscriptionAgreement.items) {
items ( subscriptionAgreement.items ) { Entitlement e ->
id e.id
}
}

if (actionName.toLowerCase() == 'export' && subscriptionAgreement.respondsTo('getResourceList')) {
resources (g.render (template: '/export/results', model: [resources: (subscriptionAgreement.invokeMethod('getResourceList', null) ?: [])]))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
package org.olf

import java.time.LocalDate
import groovy.json.JsonOutput

import grails.testing.mixin.integration.Integration
import spock.lang.*

@Stepwise
@Integration
class AgreementResourcesViewSpec extends BaseSpec {

@Shared
String pkg_id

@Shared
String agg_id

@Shared
int thisYear = LocalDate.now().year

@Shared
int expectedItems = 0;

@Shared
List<String> endpoints = ['current', 'future', 'dropped']

def fetchResourcesForAgreement() {
Map resourceMap = [:]
for (final String endpoint : endpoints) {
List resources = doGet("/erm/sas/${agg_id}/resources/${endpoint}").collect { it.id }
resourceMap[endpoint] = resources
}
return resourceMap
}

def 'Ingest a test package' () {

when: 'Testing package added'
doPost('/erm/packages/import') {
header {
dataSchema {
name "mod-agreements-package"
version 1.0
}
}
records ([
{
source "Folio Testing"
reference "access_start_access_end_examples"
name "access_start_access_end_tests Package"
packageProvider {
name "DIKU"
}
contentItems ([
{
depth "fulltext"
accessStart "${thisYear - 8}-01-01"
accessEnd "${thisYear - 1}-12-31"
coverage ([
{
startDate "${thisYear - 1}-04-01"
startVolume "1"
startIssue "1"
}
])
platformTitleInstance {
platform "EUP Publishing"
platform_url "https://www.euppublishing.com"
url "https://www.euppublishing.com/loi/afg"
titleInstance {
name "Afghanistan"
identifiers ([
{
value "2399-357X"
namespace "issn"
}
{
value "2399-3588"
namespace "eissn"
}
])
type "serial"
}
}
},
{
depth "fulltext"
accessStart "${thisYear - 8}-01-01"
coverage ([
{
startDate "${thisYear - 2}-01-01"
startVolume "1"
startIssue "1"
}
])
platformTitleInstance {
platform "Archaeological and Environmental Forensic Science"
platform_url "http://www.equinoxjournals.com"
url "http://www.equinoxjournals.com/AEFS/"
titleInstance {
name "Archaeological and Environmental Forensic Science"
identifiers ([
{
value "2052-3378"
namespace "issn"
}
{
value "2052-3386"
namespace "eissn"
}
])
type "serial"
}
}
},
{
depth "fulltext"
accessEnd "${thisYear - 1}-12-31"
coverage ([
{
startDate "${thisYear - 9}-02-01"
startVolume "27"
startIssue "1"
}
])
platformTitleInstance {
platform "EUP Publishing"
platform_url "https://www.euppublishing.com"
url "https://www.euppublishing.com/loi/anh"
titleInstance {
name "Archives of Natural History"
identifiers ([
{
value "0260-9541"
namespace "issn"
}
{
value "1755-6260"
namespace "eissn"
}
])
type "serial"
}
}
},
{
depth "fulltext"
accessStart "${thisYear + 6}-01-01"
coverage ([
{
startDate "${thisYear - 4}-01-01"
startVolume "33"
}
])
platformTitleInstance {
platform "JSTOR"
platform_url "https://www.jstor.org"
url "https://www.jstor.org/journal/bethunivj"
titleInstance {
name "Bethlehem University Journal"
identifiers ([
{
value "2521-3695"
namespace "issn"
}
{
value "2410-5449"
namespace "eissn"
}
])
type "serial"
}
}
}
])
}
])
}
and: 'Find the package by name'
List resp = doGet("/erm/packages", [filters: ['name==access_start_access_end_tests Package']])
pkg_id = resp[0].id

then: 'Expect package found'
assert pkg_id != null
assert resp?.getAt(0)?.name == 'access_start_access_end_tests Package'
}

def 'Add an agreement for our package' () {
final LocalDate today = LocalDate.now()
final LocalDate tomorrow = today.plusDays(1)
when: 'Agreement added for package'
Map httpResult = doPost('/erm/sas') {
periods ([{
startDate today.toString()
endDate tomorrow.toString()
}])
name 'Test agreement'
agreementStatus 'Active'
}
agg_id = httpResult?.id

then: 'Agreement saved'
assert agg_id != null
}

@Unroll
def 'Test direct PCI access dates are ignored for PCI #name' (final String name) {
def pci_id = "";

when: 'Agreement read'
Map httpResult = doGet("/erm/sas/${agg_id}", [expand: 'items'])
and: 'Find package by name'
List pci_resp = doGet("/erm/pci", [filters: ["pkg.id==${pkg_id}", "pti.titleInstance.name==${name}"]])
pci_id = pci_resp[0]?.id
then: 'PCI exists'
assert pci_id != null

when: 'attach PCI directly to agreement'
httpResult.items << [resource: [id: pci_id]]

and: 'Update put'
httpResult = doPut("/erm/sas/${agg_id}", httpResult, [expand: 'items'])

expectedItems += 1;

then: 'Agreement saved'
assert httpResult?.id == agg_id
// One new
assert (httpResult?.items?.size() ?: 0) == expectedItems

when: 'agreement line is set to be active this year'
// set agreement line to be activeFrom/activeTo dates
def index = httpResult.items.findIndexOf{ it.resource.id == pci_id }
httpResult.items[index].activeFrom = "${thisYear - 1}-01-01"
httpResult.items[index].activeTo = "${thisYear + 1}-12-31"

and: 'Update put'
httpResult = doPut("/erm/sas/${agg_id}", httpResult, [expand: 'items'])
println("LOGDEBUG CURRENT HTTP AFTER PUT: ${JsonOutput.prettyPrint(JsonOutput.toJson(httpResult))}")
Map resourceMap = fetchResourcesForAgreement()
println("LOGDEBUG CURRENT RESOURCE MAP: ${JsonOutput.prettyPrint(JsonOutput.toJson(resourceMap))}")

then: 'Agreement saved and pci in current block'
assert httpResult?.id == agg_id
assert resourceMap['current'].contains(pci_id)

when: 'agreement line is set to be active in the past'
// set agreement line to be activeFrom/activeTo dates
index = httpResult.items.findIndexOf{ it.resource.id == pci_id }
httpResult.items[index].activeFrom = "${thisYear - 12}-01-01"
httpResult.items[index].activeTo = "${thisYear -10}-12-31"

and: 'Update put'
httpResult = doPut("/erm/sas/${agg_id}", httpResult, [expand: 'items'])
println("LOGDEBUG DROPPED HTTP AFTER PUT: ${JsonOutput.prettyPrint(JsonOutput.toJson(httpResult))}")
resourceMap = fetchResourcesForAgreement()
println("LOGDEBUG DROPPED RESOURCE MAP: ${JsonOutput.prettyPrint(JsonOutput.toJson(resourceMap))}")


then: 'Agreement saved and pci in dropped block'
assert httpResult?.id == agg_id
assert resourceMap['dropped'].contains(pci_id)

when: 'agreement line is set to be active in the future'
// set agreement line to be activeFrom/activeTo dates
index = httpResult.items.findIndexOf{ it.resource.id == pci_id }
httpResult.items[index].activeFrom = "${thisYear + 10}-01-01"
httpResult.items[index].activeTo = "${thisYear + 12}-12-31"

and: 'Update put'
httpResult = doPut("/erm/sas/${agg_id}", httpResult, [expand: 'items'])
println("LOGDEBUG FUTURE HTTP AFTER PUT: ${JsonOutput.prettyPrint(JsonOutput.toJson(httpResult))}")

resourceMap = fetchResourcesForAgreement()
println("LOGDEBUG FUTURE RESOURCE MAP: ${JsonOutput.prettyPrint(JsonOutput.toJson(resourceMap))}")


then: 'Agreement saved and pci in future block'
assert httpResult?.id == agg_id
assert resourceMap['future'].contains(pci_id)

where:
name << [
"Afghanistan",
"Archaeological and Environmental Forensic Science",
"Archives of Natural History",
"Bethlehem University Journal"
]
}
}
Loading

0 comments on commit e8d3d12

Please sign in to comment.