Commit 16b18163 authored by Carina Antunes's avatar Carina Antunes
Browse files

[85] edms: file v5 (create record with_bucket flag)

parent d41a4064
......@@ -22,7 +22,7 @@ INVENIO_CERN_APP_CREDENTIALS={'consumer_key':'bah'}
INVENIO_CERN_APP_CREDENTIALS_CONSUMER_KEY=xxx
INVENIO_COLLECT_STORAGE=flask_collect.storage.file
INVENIO_INDEXER_DEFAULT_DOC_TYPE=doc_v0.0.2
INVENIO_INDEXER_DEFAULT_INDEX=cernsearch-test-doc_v0.0.2
INVENIO_INDEXER_DEFAULT_INDEX=test-doc_v0.0.2
INVENIO_LOGGING_CONSOLE='True'
INVENIO_LOGGING_CONSOLE_LEVEL=DEBUG
INVENIO_RATELIMIT_STORAGE_URL='redis://redis:6379/3'
......
......@@ -22,7 +22,7 @@ INVENIO_CERN_APP_CREDENTIALS={'consumer_key':'bah'}
INVENIO_CERN_APP_CREDENTIALS_CONSUMER_KEY=xxx
INVENIO_COLLECT_STORAGE=flask_collect.storage.file
INVENIO_INDEXER_DEFAULT_DOC_TYPE=doc_v0.0.2
INVENIO_INDEXER_DEFAULT_INDEX=cernsearch-test-doc_v0.0.2
INVENIO_INDEXER_DEFAULT_INDEX=test-doc_v0.0.2
INVENIO_LOGGING_CONSOLE='True'
INVENIO_LOGGING_CONSOLE_LEVEL=DEBUG
INVENIO_RATELIMIT_STORAGE_URL='redis://localhost:6379/3'
......
......@@ -4,10 +4,11 @@
# This file is part of CERN Search.
# Copyright (C) 2018-2019 CERN.
#
# CERN Search is free software; you can redistribute it and/or modify it
# Citadel Search is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
""" Record API"""
"""Record API."""
from cern_search_rest_api.modules.cernsearch.utils import default_record_to_mapping
from invenio_pidstore.models import PersistentIdentifier
from invenio_records_files.api import Record
......@@ -15,12 +16,26 @@ from .fetchers import recid_fetcher
class CernSearchRecord(Record):
"""CERN Searc Record."""
"""CERN Search Record."""
record_fetcher = staticmethod(recid_fetcher)
@classmethod
def create(cls, data, id_=None, with_bucket=True, **kwargs):
"""Create a record and the associated bucket.
:param with_bucket: Create a bucket automatically on record creation if mapping allows
"""
bucket_allowed = False
mapping = default_record_to_mapping(data)
if mapping is not None:
bucket_allowed = '_bucket' in mapping['properties']
return super(CernSearchRecord, cls).create(data, id_=id_, with_bucket=bucket_allowed, **kwargs)
@property
def pid(self):
"""Return an instance of record PID."""
pid = self.record_fetcher(self.id, self)
return PersistentIdentifier.get(pid.pid_type, pid.pid_value)
{
"title": "EDMS Object Type Document schema v5.0.0",
"id": "http://0.0.0.0:5000/schemas/edms/document_v5.0.0.json",
"$schema": "http://0.0.0.0:5000/schemas/edms/document_v5.0.0.json",
"type": "object",
"properties": {
"_access": {
"type": "object",
"properties": {
"owner":{
"type": "array",
"items": {
"type": "string"
}
},
"read":{
"type": "array",
"items": {
"type": "string"
}
},
"update":{
"type": "array",
"items": {
"type": "string"
}
},
"delete":{
"type": "array",
"items": {
"type": "string"
}
}
}
},
"_data": {
"type": "object",
"properties": {
"document_id": {
"type": "integer"
},
"document_id_version": {
"type": "string"
},
"cern_id": {
"type": "string"
},
"cern_id_version": {
"type": "string"
},
"external_reference": {
"type": "string"
},
"version": {
"type": "string"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"author": {
"type": "object",
"properties": {
"full_name": {
"type": "string"
},
"email": {
"type": "string"
}
}
},
"keywords": {
"type": "string"
},
"equipment_code": {
"type": "string"
}
}
},
"cid": {
"type": "integer"
},
"owner": {
"type": "string"
},
"group":{
"type": "string"
},
"object_type": {
"type": "string"
},
"parents": {
"type": "array",
"items": {
"type": "object"
}
},
"status": {
"type": "string"
},
"latest_version": {
"type": "boolean"
},
"obsolete": {
"type": "boolean"
},
"context": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"context_id": {
"type": "string"
}
}
},
"document_type": {
"type": "string"
},
"release_procedure": {
"type": "string"
},
"object_properties": {
"type": "array",
"items": {
"type": "object"
}
},
"attributes": {
"type": "array",
"items": {
"type": "string"
}
},
"creation_date": {
"type": "string"
},
"modification_date": {
"type": "string"
},
"control_number": {
"type": "string"
},
"$schema": {
"type": "string"
}
}
}
{
"title": "EDMS Object Type File schema v5.0.0",
"id": "http://0.0.0.0:5000/schemas/edms/file_v5.0.0.json",
"$schema": "http://0.0.0.0:5000/schemas/edms/file_v5.0.0.json",
"type": "object",
"properties": {
"_access": {
"type": "object",
"properties": {
"owner": {
"type": "array",
"items": {
"type": "string"
}
},
"read": {
"type": "array",
"items": {
"type": "string"
}
},
"update": {
"type": "array",
"items": {
"type": "string"
}
},
"delete": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"_data": {
"type": "object",
"properties": {
"file_name": {
"type": "string"
},
"document_id": {
"type": "integer"
},
"document_id_version": {
"type": "string"
},
"cern_id": {
"type": "string"
},
"cern_id_version": {
"type": "string"
},
"external_reference": {
"type": "string"
},
"version": {
"type": "string"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"author": {
"type": "object",
"properties": {
"full_name": {
"type": "string"
},
"email": {
"type": "string"
}
}
},
"keywords": {
"type": "string"
},
"equipment_code": {
"type": "string"
}
}
},
"file_id": {
"type": "integer"
},
"cid": {
"type": "integer"
},
"owner": {
"type": "string"
},
"group": {
"type": "string"
},
"object_type": {
"type": "string"
},
"parents": {
"type": "array",
"items": {
"type": "object",
"properties": {
"parent_type": {
"type": "string"
},
"parent_id": {
"type": "string"
}
}
}
},
"status": {
"type": "string"
},
"latest_version": {
"type": "boolean"
},
"obsolete": {
"type": "boolean"
},
"context": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"context_id": {
"type": "string"
}
}
},
"document_type": {
"type": "string"
},
"release_procedure": {
"type": "string"
},
"object_properties": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
},
"attributes": {
"type": "array",
"items": {
"type": "string"
}
},
"creation_date": {
"type": "string"
},
"modification_date": {
"type": "string"
},
"control_number": {
"type": "string"
},
"$schema": {
"type": "string"
}
}
}
{
"settings": {
"index.percolator.map_unmapped_fields_as_string": true,
"index.mapping.total_fields.limit": 500
},
"mappings": {
"document_v5.0.0": {
"dynamic": "strict",
"numeric_detection": true,
"properties": {
"_access": {
"type": "object",
"properties": {
"owner":{"type": "keyword"},
"read": {"type": "keyword"},
"update": {"type": "keyword"},
"delete": {"type": "keyword"}
}
},
"_data": {
"type": "object",
"properties": {
"document_id": {
"type": "keyword",
"boost": 20
},
"document_id_version": {
"type": "keyword",
"boost": 20
},
"cern_id": {
"type": "keyword",
"boost": 20
},
"cern_id_version": {
"type": "keyword",
"boost": 20
},
"external_reference": {
"type": "text",
"boost": 8,
"fields": {
"exact_match": {
"type": "keyword",
"boost": 8
}
}
},
"version": {
"type": "keyword",
"boost": 1
},
"title": {
"type": "text",
"boost": 8,
"fields": {
"english": {
"type": "text",
"boost": 8,
"analyzer": "english"
},
"french": {
"type": "text",
"boost": 8,
"analyzer": "french"
},
"exact_match": {
"type": "keyword",
"boost": 8
}
}
},
"description": {
"type": "text",
"boost": 4,
"fields": {
"english": {
"type": "text",
"boost": 4,
"analyzer": "english"
},
"french": {
"type": "text",
"boost": 4,
"analyzer": "french"
}
}
},
"author": {
"type": "object",
"properties": {
"full_name": {
"type": "text",
"boost": 2
},
"email": {
"type": "text",
"boost": 2
}
}
},
"keywords": {
"type": "text",
"boost": 6,
"fields": {
"english": {
"type": "text",
"analyzer": "english",
"boost": 6
},
"french": {
"type": "text",
"analyzer": "french",
"boost": 6
},
"exact_match": {
"type": "keyword",
"boost": 6
}
}
},
"equipment_code": {
"type": "keyword",
"boost": 6
}
}
},
"cid": {
"type": "keyword"
},
"owner": {
"type": "keyword"
},
"group": {
"type": "keyword"
},
"object_type": {
"type": "keyword"
},
"parents": {
"type": "object",
"properties": {
"parent_type": {
"type": "keyword"
},
"parent_id": {
"type": "keyword"
}
}
},
"status": {
"type": "keyword"
},
"latest_version": {
"type": "keyword"
},
"obsolete": {
"type": "keyword"
},
"context": {
"type": "object",
"properties": {
"name": {
"type": "keyword"
},
"context_id": {
"type": "keyword"
}
}
},
"document_type": {
"type": "keyword"
},
"release_procedure": {
"type": "keyword"
},
"object_properties": {
"properties": {
"name": {
"type": "keyword"
},
"value": {
"type": "text",
"fields": {
"english": {
"type": "text",
"analyzer": "english"
},
"french": {
"type": "text",