-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
files: inject files information in the record index.
* Adds custom mappings and jsonschema. * Reindex record file when a files is added, updated or removed. * Adds the total size taken by the files and the number of main files related to a given record file. Co-Authored-by: Johnny Mariéthoz <Johnny.Mariethoz@rero.ch>
- Loading branch information
Showing
13 changed files
with
418 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# RERO ILS | ||
# Copyright (C) 2019-2024 RERO | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, version 3 of the License. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""API for manipulating record file.""" | ||
|
||
from invenio_records.systemfields import ConstantField | ||
from invenio_records_resources.records.systemfields import IndexField | ||
from rero_invenio_files.records.api import FileRecord | ||
from rero_invenio_files.records.api import RecordWithFile as RecordWithFileBase | ||
|
||
|
||
class RecordWithFile(RecordWithFileBase): | ||
"""Object record with file API.""" | ||
|
||
# Jsonschema | ||
schema = ConstantField("$schema", "local://files/record-v1.0.0.json") | ||
|
||
# Elasticsearch index | ||
index = IndexField("files-record-v1.0.0", search_alias="files") | ||
|
||
|
||
FileRecord.record_cls = RecordWithFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# RERO ILS | ||
# Copyright (C) 2019-2024 RERO | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, version 3 of the License. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
|
||
"""Files indexer dumpers.""" | ||
|
||
from invenio_records.dumpers import SearchDumperExt | ||
|
||
|
||
class FileInformationDumperExt(SearchDumperExt): | ||
"""File information dumper extension.""" | ||
|
||
def dump(self, record, data): | ||
"""Dump additional information. | ||
:param record: The record to dump. | ||
:param data: The initial dump data passed in by ``record.dumps()``. | ||
""" | ||
n_main_files = 0 | ||
size = 0 | ||
# inject files informations | ||
for f in record.files: | ||
file = record.files[f] | ||
f_type = file.get("type") | ||
# main files only | ||
if f_type not in ["fulltext", "thumbnail"]: | ||
n_main_files += 1 | ||
# main files or extracted text | ||
if f_type != "thumbnail": | ||
size += record.files[f].file.size | ||
data["metadata"]["n_files"] = n_main_files | ||
data["metadata"]["file_size"] = size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# RERO ILS | ||
# Copyright (C) 2019-2024 RERO | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, version 3 of the License. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Record File jsonschemas.""" |
59 changes: 59 additions & 0 deletions
59
rero_ils/modules/files/jsonschemas/files/record-v1.0.0.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"description": "Names vocabulary.", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"$schema": { | ||
"title": "Schema", | ||
"description": "Schema to validate user records against.", | ||
"type": "string", | ||
"minLength": 9 | ||
}, | ||
"metadata": { | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"collections": { | ||
"title": "Collections", | ||
"type": "array", | ||
"minItems": 1, | ||
"items": { | ||
"title": "Collection Name", | ||
"type": "string", | ||
"minLength": 1 | ||
} | ||
}, | ||
"owners": { | ||
"title": "Owners", | ||
"type": "array", | ||
"minItems": 1, | ||
"items": { | ||
"title": "Owner", | ||
"type": "string", | ||
"minLength": 1 | ||
} | ||
}, | ||
"links": { | ||
"title": "Links", | ||
"type": "array", | ||
"minItems": 1, | ||
"items": { | ||
"title": "Link", | ||
"type": "string", | ||
"minLength": 1 | ||
} | ||
} | ||
} | ||
}, | ||
"id": { | ||
"$ref": "local://definitions-v1.0.0.json#/identifier" | ||
}, | ||
"pid": { | ||
"$ref": "local://definitions-v2.0.0.json#/internal-pid" | ||
}, | ||
"files": { | ||
"$ref": "local://definitions-v2.0.0.json#/files" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# RERO ILS | ||
# Copyright (C) 2019-2024 RERO | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, version 3 of the License. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Record File Elasticsearch mappings.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# RERO ILS | ||
# Copyright (C) 2019-2024 RERO | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, version 3 of the License. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Record File Elasticsearch mappings.""" |
74 changes: 74 additions & 0 deletions
74
rero_ils/modules/files/mappings/v7/files/record-v1.0.0.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"mappings": { | ||
"properties": { | ||
"$schema": { | ||
"type": "keyword", | ||
"index": "false" | ||
}, | ||
"created": { | ||
"type": "date" | ||
}, | ||
"updated": { | ||
"type": "date" | ||
}, | ||
"files": { | ||
"properties": { | ||
"enabled": { | ||
"type": "boolean" | ||
} | ||
} | ||
}, | ||
"bucket_id": { | ||
"type": "text" | ||
}, | ||
"uuid": { | ||
"type": "keyword" | ||
}, | ||
"version_id": { | ||
"type": "integer" | ||
}, | ||
"indexed_at": { | ||
"type": "date" | ||
}, | ||
"pid": { | ||
"properties": { | ||
"obj_type": { | ||
"type": "keyword" | ||
}, | ||
"pid_type": { | ||
"type": "keyword" | ||
}, | ||
"pk": { | ||
"type": "long" | ||
}, | ||
"status": { | ||
"type": "keyword" | ||
} | ||
} | ||
}, | ||
"metadata": { | ||
"type": "object", | ||
"properties": { | ||
"owners": { | ||
"type": "keyword" | ||
}, | ||
"collections": { | ||
"type": "keyword" | ||
}, | ||
"links": { | ||
"type": "keyword" | ||
}, | ||
"n_files": { | ||
"type": "long" | ||
}, | ||
"file_size": { | ||
"type": "long" | ||
} | ||
} | ||
}, | ||
"id": { | ||
"type": "keyword" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.