Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rest/src/test/groovy/whelk/rest/api/CrudSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ class CrudSpec extends Specification {
"@type": "Item",
"contains": "some new data",
"heldBy":
["code": "Ting"]]]]
["@id": "https://libris.kb.se/library/Ting"]]]]
request.getInputStream() >> {
new ServletInputStreamMock(mapper.writeValueAsBytes(postData))
}
Expand All @@ -1201,7 +1201,7 @@ class CrudSpec extends Specification {
"POST"
}
LegacyIntegrationTools.determineLegacyCollection(_, _) >> {
return "bib"
return "hold"
}
request.getContentType() >> {
"application/ld+json"
Expand Down
2 changes: 1 addition & 1 deletion whelk-core/src/main/groovy/whelk/Document.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ class Document {
}

boolean isHolding(JsonLd jsonld) {
return ("hold" == getLegacyCollection(jsonld))
return "hold" == getLegacyCollection(jsonld) || jsonld.isSubClassOf(getThingType(), "Item")
}

String getLegacyCollection(JsonLd jsonld) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ class LegacyIntegrationTools {
static final Map<String, String> MARC_COLLECTION_BY_CATEGORY = [
'https://id.kb.se/marc/auth': 'auth',
'https://id.kb.se/marc/bib': 'bib',
'https://id.kb.se/marc/hold': 'hold'
'https://id.kb.se/marc/hold': 'hold',
'https://id.kb.se/marc/none': NO_MARC_COLLECTION
]

static final String NO_MARC_COLLECTION = 'none'
static final String UNDEFINED_MARC_COLLECTION = 'undefined'

// FIXME: de-KBV/Libris-ify
static final String BASE_LIBRARY_URI = "https://libris.kb.se/library/"
Expand All @@ -48,31 +50,36 @@ class LegacyIntegrationTools {
}

static String getMarcCollectionInHierarchy(String type, JsonLd jsonld) {
String collection = _getMarcCollectionInHierarchy(type, jsonld)
return collection == UNDEFINED_MARC_COLLECTION ? NO_MARC_COLLECTION : collection
}

static String _getMarcCollectionInHierarchy(String type, JsonLd jsonld) {
Map termMap = jsonld.vocabIndex[type]
if (termMap == null)
return NO_MARC_COLLECTION
return UNDEFINED_MARC_COLLECTION

String marcCategory = getMarcCollectionForTerm(termMap)
if (marcCategory != NO_MARC_COLLECTION) {
if (marcCategory != UNDEFINED_MARC_COLLECTION) {
return marcCategory
}

List superClasses = (List) termMap["subClassOf"]
if (superClasses == null) {
return NO_MARC_COLLECTION
return UNDEFINED_MARC_COLLECTION
}

for (superClass in superClasses) {
if (superClass == null || superClass["@id"] == null) {
continue
}
String superClassType = jsonld.toTermKey( (String) superClass["@id"] )
String category = getMarcCollectionInHierarchy(superClassType, jsonld)
if ( category != NO_MARC_COLLECTION )
String category = _getMarcCollectionInHierarchy(superClassType, jsonld)
if ( category != UNDEFINED_MARC_COLLECTION )
return category
}

return NO_MARC_COLLECTION
return UNDEFINED_MARC_COLLECTION
}

static String getMarcCollectionForTerm(Map termMap) {
Expand All @@ -87,7 +94,7 @@ class LegacyIntegrationTools {
return collection
}
}
return NO_MARC_COLLECTION
return UNDEFINED_MARC_COLLECTION
}

/**
Expand Down
22 changes: 13 additions & 9 deletions whelk-core/src/test/groovy/whelk/LegacyIntegrationToolsSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class LegacyIntegrationToolsSpec extends Specification {
"category": [ ["@id": "http://example.org/ns/"] ]],
["@id": "http://example.org/ns/Paperback",
"subClassOf": [ ["@id": "http://example.org/ns/Print"] ],
"category": ["@id": "http://example.org/ns/pending"]]
"category": ["@id": "http://example.org/ns/pending"]],
["@id": "http://example.org/ns/None",
"subClassOf": [ ["@id": "http://example.org/ns/Instance"] ],
"category": [ ["@id": "$MARC/none"] ]],
]
]

Expand All @@ -31,14 +34,14 @@ class LegacyIntegrationToolsSpec extends Specification {
expect:
tool.getMarcCollectionForTerm([category: cats]) == id
where:
id | cats
'bib' | ['@id': "$MARC/bib"]
'bib' | [['@id': "$MARC/bib"], ['@id': "pending"]]
'auth' | [['@id': "$MARC/auth"]]
'none' | ['@id': 'other']
'none' | [['@id': 'other']]
'none' | []
'none' | null
id | cats
'bib' | ['@id': "$MARC/bib"]
'bib' | [['@id': "$MARC/bib"], ['@id': "pending"]]
'auth' | [['@id': "$MARC/auth"]]
'undefined' | ['@id': 'other']
'undefined' | [['@id': 'other']]
'undefined' | []
'undefined' | null
}

def "should get marc collection for type"() {
Expand All @@ -51,6 +54,7 @@ class LegacyIntegrationToolsSpec extends Specification {
'Print' | 'bib'
'Paperback' | 'bib'
'Other' | 'none'
'None' | 'none'
}

}