diff --git a/rest/src/test/groovy/whelk/rest/api/CrudSpec.groovy b/rest/src/test/groovy/whelk/rest/api/CrudSpec.groovy index 46c615aa9f..fbdc57f511 100644 --- a/rest/src/test/groovy/whelk/rest/api/CrudSpec.groovy +++ b/rest/src/test/groovy/whelk/rest/api/CrudSpec.groovy @@ -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)) } @@ -1201,7 +1201,7 @@ class CrudSpec extends Specification { "POST" } LegacyIntegrationTools.determineLegacyCollection(_, _) >> { - return "bib" + return "hold" } request.getContentType() >> { "application/ld+json" diff --git a/whelk-core/src/main/groovy/whelk/Document.groovy b/whelk-core/src/main/groovy/whelk/Document.groovy index 83cf543927..04ec0989d7 100644 --- a/whelk-core/src/main/groovy/whelk/Document.groovy +++ b/whelk-core/src/main/groovy/whelk/Document.groovy @@ -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) { diff --git a/whelk-core/src/main/groovy/whelk/util/LegacyIntegrationTools.groovy b/whelk-core/src/main/groovy/whelk/util/LegacyIntegrationTools.groovy index 10b75cfd88..851c11a537 100644 --- a/whelk-core/src/main/groovy/whelk/util/LegacyIntegrationTools.groovy +++ b/whelk-core/src/main/groovy/whelk/util/LegacyIntegrationTools.groovy @@ -18,10 +18,12 @@ class LegacyIntegrationTools { static final Map 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/" @@ -48,18 +50,23 @@ 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) { @@ -67,12 +74,12 @@ class LegacyIntegrationTools { 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) { @@ -87,7 +94,7 @@ class LegacyIntegrationTools { return collection } } - return NO_MARC_COLLECTION + return UNDEFINED_MARC_COLLECTION } /** diff --git a/whelk-core/src/test/groovy/whelk/LegacyIntegrationToolsSpec.groovy b/whelk-core/src/test/groovy/whelk/LegacyIntegrationToolsSpec.groovy index 516ace1720..c2afeaf30c 100644 --- a/whelk-core/src/test/groovy/whelk/LegacyIntegrationToolsSpec.groovy +++ b/whelk-core/src/test/groovy/whelk/LegacyIntegrationToolsSpec.groovy @@ -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"] ]], ] ] @@ -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"() { @@ -51,6 +54,7 @@ class LegacyIntegrationToolsSpec extends Specification { 'Print' | 'bib' 'Paperback' | 'bib' 'Other' | 'none' + 'None' | 'none' } }