Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eitem_type field to EItem and 'MULTIMEDIA' to DOCUMENT_TYPES #1207

Merged
merged 5 commits into from
May 13, 2024
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
1 change: 1 addition & 0 deletions invenio_app_ils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def generate(self):
"value": "demo",
},
"document_pid": random.choice(doc_pids),
"eitem_type": random.choice(EItem.EITEM_TYPES),
"description": "{}".format(lorem.text()),
"internal_notes": "{}".format(lorem.text()),
"urls": [
Expand Down
2 changes: 2 additions & 0 deletions invenio_app_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@ def _(x):
eitems=dict(
aggs=dict(
access=dict(terms=dict(field="open_access")),
eitem_type=dict(terms=dict(field="eitem_type")),
has_files=dict(
filters=dict(
filters=dict(
Expand All @@ -841,6 +842,7 @@ def _(x):
),
),
post_filters=dict(
eitem_type=terms_filter("eitem_type"),
access=terms_filter("open_access"),
has_files=exists_value_filter("files.file_id", filter_value="has_files"),
),
Expand Down
1 change: 1 addition & 0 deletions invenio_app_ils/documents/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Document(IlsRecordWithRelations):
"STANDARD",
"SERIAL_ISSUE",
"ARTICLE",
"MULTIMEDIA",
]

_pid_type = DOCUMENT_PID_TYPE
Expand Down
1 change: 1 addition & 0 deletions invenio_app_ils/documents/jsonresolvers/document_eitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def eitems_resolver(document_pid):
eitems.append(
{
"pid": eitem.get("pid"),
"eitem_type": eitem.get("eitem_type"),
"description": eitem.get("description"),
"identifiers": eitem.get("identifiers", []),
"internal_notes": eitem.get("internal_notes"),
Expand Down
9 changes: 6 additions & 3 deletions invenio_app_ils/documents/jsonresolvers/document_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from werkzeug.routing import Rule

from invenio_app_ils.proxies import current_app_ils
from invenio_app_ils.eitems.api import EItem

# Note: there must be only one resolver per file,
# otherwise only the last one is registered
Expand All @@ -32,9 +33,11 @@ def stock_resolver(document_pid):
mediums = [
bucket.key for bucket in search_response.aggregations.mediums.buckets
]
eitems_count = eitem_search.search_by_document_pid(document_pid).count()
if eitems_count > 0:
mediums.append("E-BOOK")
eitems = eitem_search.search_by_document_pid(document_pid)
for type in EItem.EITEM_TYPES:
type_count = eitems.filter("term", eitem_type=type).count()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check if eitems is immutable? When you use .filter, does it change the eitems object or simply return a new version with the filter applied?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it returns a new version of the object with the filter applied on it, it doesn't apply it in-place

if type_count > 0:
mediums.append(type)
return {
"mediums": mediums,
}
Expand Down
8 changes: 7 additions & 1 deletion invenio_app_ils/eitems/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ def validate(self, record, **kwargs):
class EItem(IlsRecord):
"""EItem record class."""

EITEM_TYPES = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a strong opinion, I would like to also check with the others (could you discuss on a standup?): would it be more flexible to store these types in a vocabulary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will discuss
But wouldn't keeping the type of the record in its class provide better visibility and readability and also be easier to maintain
if we make it a vocabulary, then we would also need do the same for all other record types, and that will require checking if there might be some other flow that'll be affected by this change

"E-BOOK",
"AUDIOBOOK",
"VIDEO",
]

_pid_type = EITEM_PID_TYPE
_schema = "eitems/eitem-v1.0.0.json"
_schema = "eitems/eitem-v2.0.0.json"
_document_resolver_path = (
"{scheme}://{host}/api/resolver/eitems/{eitem_pid}/document"
)
Expand Down
4 changes: 3 additions & 1 deletion invenio_app_ils/eitems/loaders/jsonschemas/eitems.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"""EItems schema for marshmallow loader."""

from invenio_records_rest.schemas import RecordMetadataSchemaJSONV1
from marshmallow import EXCLUDE, Schema, fields, pre_load
from marshmallow import EXCLUDE, Schema, fields, pre_load, validate

from invenio_app_ils.eitems.api import EItem
from invenio_app_ils.documents.loaders.jsonschemas.document import IdentifierSchema
from invenio_app_ils.records.loaders.schemas.changed_by import (
ChangedBySchema,
Expand Down Expand Up @@ -58,6 +59,7 @@ class Meta:
created_by = fields.Nested(ChangedBySchema)
description = fields.Str()
document_pid = fields.Str(required=True)
eitem_type = fields.Str(required=True, validate=validate.OneOf(EItem.EITEM_TYPES))
files = fields.List(fields.Nested(FileSchema))
identifiers = fields.List(fields.Nested(IdentifierSchema))
internal_notes = fields.Str()
Expand Down
142 changes: 142 additions & 0 deletions invenio_app_ils/eitems/mappings/os-v1/eitems/eitem-v2.0.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{
"mappings": {
"date_detection": false,
"numeric_detection": false,
"properties": {
"$schema": {
"type": "keyword"
},
"_created": {
"type": "date"
},
"_updated": {
"type": "date"
},
"bucket_id": {
"type": "keyword"
},
"created_by": {
"properties": {
"type": {
"type": "keyword"
},
"value": {
"type": "keyword"
}
},
"type": "object"
},
"description": {
"type": "text"
},
"document": {
"properties": {
"authors": {
"type": "text"
},
"cover_metadata": {
"properties": {},
"type": "object"
},
"edition": {
"type": "text"
},
"pid": {
"type": "keyword"
},
"publication_year": {
"type": "keyword"
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
},
"type": "object"
},
"document_pid": {
"type": "keyword"
},
"eitem_type": {
"type": "keyword"
},
"files": {
"properties": {
"bucket": {
"type": "keyword"
},
"checksum": {
"type": "keyword"
},
"file_id": {
"type": "keyword"
},
"key": {
"type": "keyword"
},
"size": {
"type": "keyword"
},
"version_id": {
"type": "keyword"
}
},
"type": "object"
},
"identifiers": {
"properties": {
"material": {
"type": "keyword"
},
"scheme": {
"type": "keyword"
},
"value": {
"type": "keyword",
"fields": {
"text": {
"type": "text"
}
}
}
},
"type": "object"
},
"internal_notes": {
"type": "text"
},
"open_access": {
"type": "boolean"
},
"pid": {
"type": "keyword"
},
"source": {
"type": "keyword",
"fields": {
"text": {
"type": "text"
}
}
},
"urls": {
"properties": {
"description": {
"type": "text"
},
"value": {
"type": "keyword"
},
"login_required": {
"type": "boolean"
}
},
"type": "object"
}
}
}
}
142 changes: 142 additions & 0 deletions invenio_app_ils/eitems/mappings/os-v2/eitems/eitem-v2.0.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{
"mappings": {
"date_detection": false,
"numeric_detection": false,
"properties": {
"$schema": {
"type": "keyword"
},
"_created": {
"type": "date"
},
"_updated": {
"type": "date"
},
"bucket_id": {
"type": "keyword"
},
"created_by": {
"properties": {
"type": {
"type": "keyword"
},
"value": {
"type": "keyword"
}
},
"type": "object"
},
"description": {
"type": "text"
},
"document": {
"properties": {
"authors": {
"type": "text"
},
"cover_metadata": {
"properties": {},
"type": "object"
},
"edition": {
"type": "text"
},
"pid": {
"type": "keyword"
},
"publication_year": {
"type": "keyword"
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
},
"type": "object"
},
"document_pid": {
"type": "keyword"
},
"eitem_type": {
"type": "keyword"
},
"files": {
"properties": {
"bucket": {
"type": "keyword"
},
"checksum": {
"type": "keyword"
},
"file_id": {
"type": "keyword"
},
"key": {
"type": "keyword"
},
"size": {
"type": "keyword"
},
"version_id": {
"type": "keyword"
}
},
"type": "object"
},
"identifiers": {
"properties": {
"material": {
"type": "keyword"
},
"scheme": {
"type": "keyword"
},
"value": {
"type": "keyword",
"fields": {
"text": {
"type": "text"
}
}
}
},
"type": "object"
},
"internal_notes": {
"type": "text"
},
"open_access": {
"type": "boolean"
},
"pid": {
"type": "keyword"
},
"source": {
"type": "keyword",
"fields": {
"text": {
"type": "text"
}
}
},
"urls": {
"properties": {
"description": {
"type": "text"
},
"value": {
"type": "keyword"
},
"login_required": {
"type": "boolean"
}
},
"type": "object"
}
}
}
}
Loading
Loading