From 90da750760e1cd8347096ca7f2594c0e828b4ec0 Mon Sep 17 00:00:00 2001 From: Saksham Arora Date: Thu, 4 Apr 2024 13:15:51 +0200 Subject: [PATCH 1/2] items: Add identifiers object list field --- .../documents/jsonresolvers/document_item.py | 1 + .../os-v1/documents/document-v1.0.0.json | 11 ++++++++++ .../os-v2/documents/document-v1.0.0.json | 11 ++++++++++ .../v7/documents/document-v1.0.0.json | 11 ++++++++++ .../items/loaders/jsonschemas/items.py | 2 ++ .../mappings/os-v1/items/item-v1.0.0.json | 11 ++++++++++ .../mappings/os-v2/items/item-v1.0.0.json | 11 ++++++++++ .../items/mappings/v7/items/item-v1.0.0.json | 11 ++++++++++ .../items/schemas/items/item-v1.0.0.json | 22 +++++++++++++++++++ .../records/loaders/schemas/identifiers.py | 22 +++++++++++++++++++ 10 files changed, 113 insertions(+) create mode 100644 invenio_app_ils/records/loaders/schemas/identifiers.py diff --git a/invenio_app_ils/documents/jsonresolvers/document_item.py b/invenio_app_ils/documents/jsonresolvers/document_item.py index 604edc865..592bb965f 100644 --- a/invenio_app_ils/documents/jsonresolvers/document_item.py +++ b/invenio_app_ils/documents/jsonresolvers/document_item.py @@ -37,6 +37,7 @@ def items_resolver(document_pid): "status": item.get("status"), "description": item.get("description"), "shelf": item.get("shelf"), + "identifiers": item.get("identifiers"), "internal_location": { "name": item.get("internal_location", {}).get("name", ""), "location": { diff --git a/invenio_app_ils/documents/mappings/os-v1/documents/document-v1.0.0.json b/invenio_app_ils/documents/mappings/os-v1/documents/document-v1.0.0.json index 5f010133a..4b34a8580 100644 --- a/invenio_app_ils/documents/mappings/os-v1/documents/document-v1.0.0.json +++ b/invenio_app_ils/documents/mappings/os-v1/documents/document-v1.0.0.json @@ -434,6 +434,17 @@ "shelf": { "type": "keyword" }, + "identifiers": { + "properties": { + "description": { + "type": "text" + }, + "value": { + "type": "keyword" + } + }, + "type": "object" + }, "status": { "type": "keyword" } diff --git a/invenio_app_ils/documents/mappings/os-v2/documents/document-v1.0.0.json b/invenio_app_ils/documents/mappings/os-v2/documents/document-v1.0.0.json index 5f010133a..4b34a8580 100644 --- a/invenio_app_ils/documents/mappings/os-v2/documents/document-v1.0.0.json +++ b/invenio_app_ils/documents/mappings/os-v2/documents/document-v1.0.0.json @@ -434,6 +434,17 @@ "shelf": { "type": "keyword" }, + "identifiers": { + "properties": { + "description": { + "type": "text" + }, + "value": { + "type": "keyword" + } + }, + "type": "object" + }, "status": { "type": "keyword" } diff --git a/invenio_app_ils/documents/mappings/v7/documents/document-v1.0.0.json b/invenio_app_ils/documents/mappings/v7/documents/document-v1.0.0.json index 5f010133a..4b34a8580 100644 --- a/invenio_app_ils/documents/mappings/v7/documents/document-v1.0.0.json +++ b/invenio_app_ils/documents/mappings/v7/documents/document-v1.0.0.json @@ -434,6 +434,17 @@ "shelf": { "type": "keyword" }, + "identifiers": { + "properties": { + "description": { + "type": "text" + }, + "value": { + "type": "keyword" + } + }, + "type": "object" + }, "status": { "type": "keyword" } diff --git a/invenio_app_ils/items/loaders/jsonschemas/items.py b/invenio_app_ils/items/loaders/jsonschemas/items.py index eca28490d..881bd3071 100644 --- a/invenio_app_ils/items/loaders/jsonschemas/items.py +++ b/invenio_app_ils/items/loaders/jsonschemas/items.py @@ -16,6 +16,7 @@ set_changed_by, ) from invenio_app_ils.records.loaders.schemas.price import PriceSchema +from invenio_app_ils.records.loaders.schemas.identifiers import IdentifiersSchema class ISBNSchema(Schema): @@ -56,6 +57,7 @@ class Meta: price = fields.Nested(PriceSchema) shelf = fields.Str() status = fields.Str(required=True, validate=validate.OneOf(Item.STATUSES)) + identifiers = fields.List(fields.Nested(IdentifiersSchema)) @pre_load def set_changed_by(self, data, **kwargs): diff --git a/invenio_app_ils/items/mappings/os-v1/items/item-v1.0.0.json b/invenio_app_ils/items/mappings/os-v1/items/item-v1.0.0.json index 6d3274541..32c0ede4e 100644 --- a/invenio_app_ils/items/mappings/os-v1/items/item-v1.0.0.json +++ b/invenio_app_ils/items/mappings/os-v1/items/item-v1.0.0.json @@ -266,6 +266,17 @@ "shelf": { "type": "text" }, + "identifiers": { + "properties": { + "scheme": { + "type": "keyword" + }, + "value": { + "type": "keyword" + } + }, + "type": "object" + }, "status": { "type": "keyword" } diff --git a/invenio_app_ils/items/mappings/os-v2/items/item-v1.0.0.json b/invenio_app_ils/items/mappings/os-v2/items/item-v1.0.0.json index 6d3274541..32c0ede4e 100644 --- a/invenio_app_ils/items/mappings/os-v2/items/item-v1.0.0.json +++ b/invenio_app_ils/items/mappings/os-v2/items/item-v1.0.0.json @@ -266,6 +266,17 @@ "shelf": { "type": "text" }, + "identifiers": { + "properties": { + "scheme": { + "type": "keyword" + }, + "value": { + "type": "keyword" + } + }, + "type": "object" + }, "status": { "type": "keyword" } diff --git a/invenio_app_ils/items/mappings/v7/items/item-v1.0.0.json b/invenio_app_ils/items/mappings/v7/items/item-v1.0.0.json index 6d3274541..32c0ede4e 100644 --- a/invenio_app_ils/items/mappings/v7/items/item-v1.0.0.json +++ b/invenio_app_ils/items/mappings/v7/items/item-v1.0.0.json @@ -266,6 +266,17 @@ "shelf": { "type": "text" }, + "identifiers": { + "properties": { + "scheme": { + "type": "keyword" + }, + "value": { + "type": "keyword" + } + }, + "type": "object" + }, "status": { "type": "keyword" } diff --git a/invenio_app_ils/items/schemas/items/item-v1.0.0.json b/invenio_app_ils/items/schemas/items/item-v1.0.0.json index b1a5e7374..19f09b042 100644 --- a/invenio_app_ils/items/schemas/items/item-v1.0.0.json +++ b/invenio_app_ils/items/schemas/items/item-v1.0.0.json @@ -142,6 +142,28 @@ "type": "string", "title": "The shelf location of this Item" }, + "identifiers": { + "items": { + "additionalProperties": false, + "properties": { + "scheme": { + "type": "string", + "title": "Type of identification" + }, + "value": { + "minLength": 1, + "type": "string", + "title": "Scheme's value" + } + }, + "required": ["scheme", "value"], + "title": "Identifiers", + "type": "object" + }, + "title": "List of Identifiers", + "type": "array", + "uniqueItems": true + }, "status": { "type": "string", "title": "The current status of this Item" diff --git a/invenio_app_ils/records/loaders/schemas/identifiers.py b/invenio_app_ils/records/loaders/schemas/identifiers.py new file mode 100644 index 000000000..fdc79fbaa --- /dev/null +++ b/invenio_app_ils/records/loaders/schemas/identifiers.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# invenio-app-ils is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Identifiers schema for marshmallow loader.""" + +from marshmallow import EXCLUDE, Schema, fields + + +class IdentifiersSchema(Schema): + """Identifiers schema.""" + + class Meta: + """Meta attributes for the schema.""" + + unknown = EXCLUDE + + scheme = fields.Str(required=True) + value = fields.Str(required=True) From c63b48a0bcd4beb96db76011181298ccb33caecd Mon Sep 17 00:00:00 2001 From: Saksham Arora Date: Thu, 11 Apr 2024 10:29:01 +0200 Subject: [PATCH 2/2] items: loaders: reuse IdentifiersSchema from document --- .../items/loaders/jsonschemas/items.py | 4 ++-- .../records/loaders/schemas/identifiers.py | 22 ------------------- 2 files changed, 2 insertions(+), 24 deletions(-) delete mode 100644 invenio_app_ils/records/loaders/schemas/identifiers.py diff --git a/invenio_app_ils/items/loaders/jsonschemas/items.py b/invenio_app_ils/items/loaders/jsonschemas/items.py index 881bd3071..f2ab222e4 100644 --- a/invenio_app_ils/items/loaders/jsonschemas/items.py +++ b/invenio_app_ils/items/loaders/jsonschemas/items.py @@ -16,7 +16,7 @@ set_changed_by, ) from invenio_app_ils.records.loaders.schemas.price import PriceSchema -from invenio_app_ils.records.loaders.schemas.identifiers import IdentifiersSchema +from invenio_app_ils.documents.loaders.jsonschemas.document import IdentifierSchema class ISBNSchema(Schema): @@ -57,7 +57,7 @@ class Meta: price = fields.Nested(PriceSchema) shelf = fields.Str() status = fields.Str(required=True, validate=validate.OneOf(Item.STATUSES)) - identifiers = fields.List(fields.Nested(IdentifiersSchema)) + identifiers = fields.List(fields.Nested(IdentifierSchema)) @pre_load def set_changed_by(self, data, **kwargs): diff --git a/invenio_app_ils/records/loaders/schemas/identifiers.py b/invenio_app_ils/records/loaders/schemas/identifiers.py deleted file mode 100644 index fdc79fbaa..000000000 --- a/invenio_app_ils/records/loaders/schemas/identifiers.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2024 CERN. -# -# invenio-app-ils is free software; you can redistribute it and/or modify it -# under the terms of the MIT License; see LICENSE file for more details. - -"""Identifiers schema for marshmallow loader.""" - -from marshmallow import EXCLUDE, Schema, fields - - -class IdentifiersSchema(Schema): - """Identifiers schema.""" - - class Meta: - """Meta attributes for the schema.""" - - unknown = EXCLUDE - - scheme = fields.Str(required=True) - value = fields.Str(required=True)