Skip to content

Commit 2d45a0b

Browse files
authored
Merge pull request #1467 from libris/feature/lxl-4504-catalogue-single-item
Make it possible to have linked SingleItem (sv: "Exemplar") inside Item hasComponent. SingleItem is in collection none instead of hold so that we don't get any of the special handling for holdings => it is possible to have multiple SingleItem records per library => it is not involved in MARC export except as an embellished hasComponent of a regular holding record Access control for holdings is extend to all subclasses of Item instead of just collection hold i.e. only owning library + global registrant can write SingleItem See also libris/definitions#494 Later on Item might be replaced by ItemHolding for the holding, with SingleItem and SomeItem for 1 vs many items. See libris/definitions#483
2 parents 01476de + 5ff2e02 commit 2d45a0b

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

rest/src/test/groovy/whelk/rest/api/CrudSpec.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ class CrudSpec extends Specification {
11901190
"@type": "Item",
11911191
"contains": "some new data",
11921192
"heldBy":
1193-
["code": "Ting"]]]]
1193+
["@id": "https://libris.kb.se/library/Ting"]]]]
11941194
request.getInputStream() >> {
11951195
new ServletInputStreamMock(mapper.writeValueAsBytes(postData))
11961196
}
@@ -1201,7 +1201,7 @@ class CrudSpec extends Specification {
12011201
"POST"
12021202
}
12031203
LegacyIntegrationTools.determineLegacyCollection(_, _) >> {
1204-
return "bib"
1204+
return "hold"
12051205
}
12061206
request.getContentType() >> {
12071207
"application/ld+json"

whelk-core/src/main/groovy/whelk/Document.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ class Document {
370370
}
371371

372372
boolean isHolding(JsonLd jsonld) {
373-
return ("hold" == getLegacyCollection(jsonld))
373+
return "hold" == getLegacyCollection(jsonld) || jsonld.isSubClassOf(getThingType(), "Item")
374374
}
375375

376376
String getLegacyCollection(JsonLd jsonld) {

whelk-core/src/main/groovy/whelk/util/LegacyIntegrationTools.groovy

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ class LegacyIntegrationTools {
1818
static final Map<String, String> MARC_COLLECTION_BY_CATEGORY = [
1919
'https://id.kb.se/marc/auth': 'auth',
2020
'https://id.kb.se/marc/bib': 'bib',
21-
'https://id.kb.se/marc/hold': 'hold'
21+
'https://id.kb.se/marc/hold': 'hold',
22+
'https://id.kb.se/marc/none': NO_MARC_COLLECTION
2223
]
23-
24+
2425
static final String NO_MARC_COLLECTION = 'none'
26+
static final String UNDEFINED_MARC_COLLECTION = 'undefined'
2527

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

5052
static String getMarcCollectionInHierarchy(String type, JsonLd jsonld) {
53+
String collection = _getMarcCollectionInHierarchy(type, jsonld)
54+
return collection == UNDEFINED_MARC_COLLECTION ? NO_MARC_COLLECTION : collection
55+
}
56+
57+
static String _getMarcCollectionInHierarchy(String type, JsonLd jsonld) {
5158
Map termMap = jsonld.vocabIndex[type]
5259
if (termMap == null)
53-
return NO_MARC_COLLECTION
60+
return UNDEFINED_MARC_COLLECTION
5461

5562
String marcCategory = getMarcCollectionForTerm(termMap)
56-
if (marcCategory != NO_MARC_COLLECTION) {
63+
if (marcCategory != UNDEFINED_MARC_COLLECTION) {
5764
return marcCategory
5865
}
5966

6067
List superClasses = (List) termMap["subClassOf"]
6168
if (superClasses == null) {
62-
return NO_MARC_COLLECTION
69+
return UNDEFINED_MARC_COLLECTION
6370
}
6471

6572
for (superClass in superClasses) {
6673
if (superClass == null || superClass["@id"] == null) {
6774
continue
6875
}
6976
String superClassType = jsonld.toTermKey( (String) superClass["@id"] )
70-
String category = getMarcCollectionInHierarchy(superClassType, jsonld)
71-
if ( category != NO_MARC_COLLECTION )
77+
String category = _getMarcCollectionInHierarchy(superClassType, jsonld)
78+
if ( category != UNDEFINED_MARC_COLLECTION )
7279
return category
7380
}
7481

75-
return NO_MARC_COLLECTION
82+
return UNDEFINED_MARC_COLLECTION
7683
}
7784

7885
static String getMarcCollectionForTerm(Map termMap) {
@@ -87,7 +94,7 @@ class LegacyIntegrationTools {
8794
return collection
8895
}
8996
}
90-
return NO_MARC_COLLECTION
97+
return UNDEFINED_MARC_COLLECTION
9198
}
9299

93100
/**

whelk-core/src/test/groovy/whelk/LegacyIntegrationToolsSpec.groovy

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ class LegacyIntegrationToolsSpec extends Specification {
2121
"category": [ ["@id": "http://example.org/ns/"] ]],
2222
["@id": "http://example.org/ns/Paperback",
2323
"subClassOf": [ ["@id": "http://example.org/ns/Print"] ],
24-
"category": ["@id": "http://example.org/ns/pending"]]
24+
"category": ["@id": "http://example.org/ns/pending"]],
25+
["@id": "http://example.org/ns/None",
26+
"subClassOf": [ ["@id": "http://example.org/ns/Instance"] ],
27+
"category": [ ["@id": "$MARC/none"] ]],
2528
]
2629
]
2730

@@ -31,14 +34,14 @@ class LegacyIntegrationToolsSpec extends Specification {
3134
expect:
3235
tool.getMarcCollectionForTerm([category: cats]) == id
3336
where:
34-
id | cats
35-
'bib' | ['@id': "$MARC/bib"]
36-
'bib' | [['@id': "$MARC/bib"], ['@id': "pending"]]
37-
'auth' | [['@id': "$MARC/auth"]]
38-
'none' | ['@id': 'other']
39-
'none' | [['@id': 'other']]
40-
'none' | []
41-
'none' | null
37+
id | cats
38+
'bib' | ['@id': "$MARC/bib"]
39+
'bib' | [['@id': "$MARC/bib"], ['@id': "pending"]]
40+
'auth' | [['@id': "$MARC/auth"]]
41+
'undefined' | ['@id': 'other']
42+
'undefined' | [['@id': 'other']]
43+
'undefined' | []
44+
'undefined' | null
4245
}
4346

4447
def "should get marc collection for type"() {
@@ -51,6 +54,7 @@ class LegacyIntegrationToolsSpec extends Specification {
5154
'Print' | 'bib'
5255
'Paperback' | 'bib'
5356
'Other' | 'none'
57+
'None' | 'none'
5458
}
5559

5660
}

0 commit comments

Comments
 (0)