Ejemplo n.º 1
0
class BibliographicRecord(Record):
    """Bibliographic Record API."""

    model_cls = models.RecordMetadata

    index = IndexField('rdmrecords-records-record-v1.0.0',
                       search_alias='rdmrecords-records')

    dumper = ElasticsearchDumper(extensions=[
        EDTFDumperExt('metadata.publication_date'),
        RelationDumperExt('relations'),
    ])

    relations = RelationsField(languages=PIDListRelation(
        'metadata.languages', attrs=['metadata'], pid_field=Language.pid), )

    files = FilesField(
        store=False,
        file_cls=RecordFile,
        # Don't create
        create=False,
        # Don't delete, we'll manage in the service
        delete=False,
    )
    bucket_id = ModelField(dump=False)
    bucket = ModelField(dump=False)
Ejemplo n.º 2
0
class Marc21Draft(Draft):
    """Marc21 draft API."""

    model_cls = DraftMetadata

    index = IndexField("marc21records-drafts-marc21-v1.0.0",
                       search_alias="marc21records-marc21")

    pid = PIDField(
        key="id",
        provider=MarcDraftProvider,
        context_cls=MarcPIDFieldContext,
        resolver_cls=MarcResolver,
        delete=False,
    )

    conceptpid = PIDField(
        key="conceptid",
        provider=MarcDraftProvider,
        context_cls=MarcPIDFieldContext,
        resolver_cls=MarcResolver,
        delete=False,
    )

    files = FilesField(
        store=False,
        file_cls=DraftFile,
        delete=False,
    )

    bucket_id = ModelField(dump=False)

    bucket = ModelField(dump=False)
Ejemplo n.º 3
0
class Marc21Record(Record):
    """Define API for Marc21 create and manipulate."""

    model_cls = RecordMetadata
    versions_model_cls = VersionsState
    parent_record_cls = Marc21Parent

    index = IndexField("marc21records-marc21-marc21-v1.0.0",
                       search_alias="marc21records-marc21")

    parent = ParentField(Marc21Parent,
                         create=True,
                         soft_delete=False,
                         hard_delete=True)

    pid = PIDField(
        key="id",
        provider=MarcRecordProvider,
        context_cls=MarcPIDFieldContext,
        resolver_cls=MarcResolver,
        delete=False,
    )

    files = FilesField(
        store=False,
        file_cls=RecordFile,
        create=False,
        delete=False,
    )

    bucket_id = ModelField(dump=False)

    bucket = ModelField(dump=False)
Ejemplo n.º 4
0
class Vocabulary(Record):
    """A generic vocabulary record."""

    # Configuration
    model_cls = VocabularyMetadata

    # System fields
    # TODO: Can schema name be changed (remove localhost)
    schema = ConstantField(
        "$schema",
        "https://localhost/schemas/vocabularies/vocabulary-v1.0.0.json",
    )

    index = IndexField(
        "vocabularies-vocabulary-v1.0.0", search_alias="vocabularies"
    )

    #: Disable the metadata system field.
    metadata = None

    type = RelatedModelField(VocabularyType, required=True)

    pid = PIDField(
        'id',
        provider=VocabularyIdProvider,
        context_cls=VocabularyPIDFieldContext,
        create=False,
    )
Ejemplo n.º 5
0
class Marc21Draft(Draft):
    """Marc21 draft API."""

    model_cls = DraftMetadata
    versions_model_cls = VersionsState
    parent_record_cls = Marc21Parent

    index = IndexField("marc21records-drafts-marc21-v1.0.0",
                       search_alias="marc21records-marc21")

    parent = ParentField(Marc21Parent,
                         create=True,
                         soft_delete=False,
                         hard_delete=True)

    pid = PIDField(
        key="id",
        provider=MarcDraftProvider,
        context_cls=MarcPIDFieldContext,
        resolver_cls=MarcResolver,
        delete=False,
    )

    files = FilesField(
        store=False,
        file_cls=DraftFile,
        delete=False,
    )

    bucket_id = ModelField(dump=False)

    bucket = ModelField(dump=False)
Ejemplo n.º 6
0
class Draft(DraftBase):
    """Example record API."""

    # Configuration
    model_cls = DraftMetadata
    versions_model_cls = ParentState
    parent_record_cls = ParentRecord

    # System fields
    schema = ConstantField(
        '$schema', 'http://localhost/schemas/records/record-v1.0.0.json')

    index = IndexField('draftsresources-drafts-draft-v1.0.0',
                       search_alias='draftsresources-drafts')

    files = FilesField(
        store=False,
        file_cls=FileDraft,
        # Don't delete, we'll manage in the service
        delete=False,
    )

    bucket_id = ModelField(dump=False)

    bucket = ModelField(dump=False)
Ejemplo n.º 7
0
class Marc21Record(Record):
    """Define API for Marc21 create and manipulate."""

    model_cls = RecordMetadata

    index = IndexField("marc21records-marc21-marc21-v1.0.0",
                       search_alias="marc21records-marc21")

    pid = PIDField(
        key="id",
        provider=MarcRecordProvider,
        delete=False,
        context_cls=MarcPIDFieldContext,
        resolver_cls=MarcResolver,
    )

    conceptpid = PIDField(
        key="conceptid",
        provider=MarcRecordProvider,
        delete=False,
        context_cls=MarcPIDFieldContext,
        resolver_cls=MarcResolver,
    )

    files = FilesField(
        store=False,
        file_cls=RecordFile,
        create=False,
        delete=False,
    )

    bucket_id = ModelField(dump=False)

    bucket = ModelField(dump=False)
Ejemplo n.º 8
0
class LOMDraft(Draft):
    """For representing entries from the 'lom_drafts_metadata'-SQL-table."""

    model_cls = models.LOMDraftMetadata
    parent_record_cls = LOMParent
    versions_model_cls = models.LOMVersionsState

    pid = PIDField(
        key="id",
        provider=LOMDraftRecordIdProvider,
        resolver_cls=LOMResolver,
        context_cls=LOMPIDFieldContext,
        # flag for deleting pid from database on post-record-deletion,
        # delete pid via LOMRecordService instead
        delete=False,
    )
    files = FilesField(
        file_cls=LOMFileDraft,
        delete=False,
        store=False,
    )
    access = RecordAccessField()
    bucket_id = ModelField(dump=False)
    bucket = ModelField(dump=False)
    index = IndexField("lomrecords-drafts-draft-v1.0.0",
                       search_alias="lomrecords")
    is_published = PIDStatusCheckField(status=PIDStatus.REGISTERED, dump=True)
    resource_type = DictField()
Ejemplo n.º 9
0
class Vocabulary(RecordBase):
    """Example record API."""

    # Configuration
    model_cls = VocabularyMetadata

    dumper = ElasticsearchDumper(
        extensions=[VocabularyTypeElasticsearchDumperExt()]
    )

    # System fields
    schema = ConstantField(
        "$schema",
        "https://localhost/schemas/vocabularies/vocabulary-v1.0.0.json",
    )

    index = IndexField(
        "vocabularies-vocabulary-v1.0.0", search_alias="vocabularies"
    )

    # TODO: This should be changed to use something else than the recidv2
    pid = PIDField("id", provider=RecordIdProviderV2)

    vocabulary_type_id = ModelField()

    vocabulary_type = VocabularyTypeField(dump=False)
Ejemplo n.º 10
0
class BibliographicRecord(Record):
    """Bibliographic Record API."""

    model_cls = RecordMetadata

    index = IndexField('rdmrecords-records-record-v1.0.0',
                       search_alias='rdmrecords-records')

    dumper = ElasticsearchDumper(
        extensions=[EDTFDumperExt('metadata.publication_date')])
Ejemplo n.º 11
0
class BibliographicDraft(Draft):
    """Bibliographic draft API."""

    model_cls = DraftMetadata

    index = IndexField('rdmrecords-drafts-draft-v1.0.0',
                       search_alias='rdmrecords-drafts')

    dumper = ElasticsearchDumper(
        extensions=[EDTFDumperExt('metadata.publication_date')])
Ejemplo n.º 12
0
 def create_record_class(self):
     """Create record class."""
     record_class_attributes = {
         "model_cls": self.model_cls,
         "schema": ConstantField("$schema", self.schema_path),
         "index": IndexField(self.index_name),
         "pid": PIDField("id", provider=RecordIdProviderV2),
         "dumper": self.record_dumper or ElasticsearchDumper(),
     }
     self.record_cls = type(self.record_type_name, (Record, ),
                            record_class_attributes)
Ejemplo n.º 13
0
class Draft(DraftBase):
    """Example record API."""

    # Configuration
    model_cls = DraftMetadata

    # System fields
    schema = ConstantField(
        '$schema', 'http://localhost/schemas/records/record-v1.0.0.json')

    index = IndexField('draftsresources-drafts-draft-v1.0.0',
                       search_alias='draftsresources-drafts')
Ejemplo n.º 14
0
    def create_record_class(self):
        """Create record class."""
        pid_field = self.pid_field_cls("id", **self.pid_field_kwargs)

        record_class_attributes = {
            "model_cls": self.model_cls,
            "schema": ConstantField("$schema", self.schema_path),
            "index": IndexField(self.index_name),
            "pid": pid_field,
            "dumper": self.record_dumper or ElasticsearchDumper(),
        }
        self.record_cls = type(self.record_type_name, (Record, ),
                               record_class_attributes)
Ejemplo n.º 15
0
class Record(RecordBase):
    """Example record API."""

    # Configuration
    model_cls = RecordMetadata
    versions_model_cls = ParentState
    parent_record_cls = ParentRecord

    # System fields
    schema = ConstantField(
        '$schema', 'http://localhost/schemas/records/record-v1.0.0.json')

    index = IndexField('draftsresources-records-record-v1.0.0',
                       search_alias='draftsresources-records')
Ejemplo n.º 16
0
class RDMDraft(CommonFieldsMixin, Draft):
    """RDM draft API."""

    model_cls = models.RDMDraftMetadata

    index = IndexField("rdmrecords-drafts-draft-v3.0.0",
                       search_alias="rdmrecords")

    files = FilesField(
        store=False,
        file_cls=RDMFileDraft,
        # Don't delete, we'll manage in the service
        delete=False,
    )

    has_draft = HasDraftCheckField()
Ejemplo n.º 17
0
class Record(RecordBase):
    """Example bibliographic record API."""

    model_cls = models.RecordMetadata
    schema = ConstantField('$schema', 'local://records/record-v1.0.0.json')
    index = IndexField('records-record-v1.0.0', search_alias='records')
    pid = PIDField('id', provider=RecordIdProviderV2)

    # Definitions of relationships from a bibliographic record to the
    # generic vocabularies.
    relations = RelationsField(languages=PIDListRelation(
        'metadata.languages',
        keys=['id', 'title'],
        pid_field=Vocabulary.pid.with_type_ctx('languages')), )

    dumper = ElasticsearchDumper(extensions=[
        RelationDumperExt('relations'),
    ])
Ejemplo n.º 18
0
class RDMRecord(CommonFieldsMixin, Record):
    """RDM Record API."""

    model_cls = models.RDMRecordMetadata

    index = IndexField("rdmrecords-records-record-v3.0.0",
                       search_alias="rdmrecords-records")

    files = FilesField(
        store=False,
        file_cls=RDMFileRecord,
        # Don't create
        create=False,
        # Don't delete, we'll manage in the service
        delete=False,
    )

    has_draft = HasDraftCheckField(RDMDraft)
Ejemplo n.º 19
0
class Record(RecordBase):
    """Example record API."""

    # Configuration
    model_cls = RecordMetadata

    # Model fields
    expires_at = ModelField()

    # System fields
    schema = ConstantField(
        '$schema', 'http://localhost/schemas/records/record-v1.0.0.json')

    index = IndexField('records-record-v1.0.0', search_alias='records')

    pid = PIDField('id', provider=RecordIdProviderV2)

    conceptpid = PIDField('conceptid', provider=RecordIdProviderV2)

    is_published = PIDStatusCheckField(status=PIDStatus.REGISTERED)
Ejemplo n.º 20
0
class Community(Record):
    """Community API."""

    pid = PIDField('id', provider=CommunitiesIdProvider, create=False)
    schema = ConstantField('$schema',
                           'local://communities/communities-v1.0.0.json')

    model_cls = models.CommunityMetadata

    index = IndexField("communities-communities-v1.0.0",
                       search_alias="communities")

    access = CommunityAccessField()

    bucket_id = ModelField(dump=False)
    bucket = ModelField(dump=False)
    files = FilesField(
        store=False,
        file_cls=CommunityFile,
        # Don't delete, we'll manage in the service
        delete=False,
    )
Ejemplo n.º 21
0
class Marc21Draft(Draft):
    """Marc21 draft API."""

    model_cls = models.DraftMetadata

    index = IndexField("marc21records-drafts-marc21-v1.0.0",
                       search_alias="marc21records-marc21")

    pid = PIDField(
        key="id",
        provider=MarcDraftProvider,
        context_cls=MarcPIDFieldContext,
        resolver_cls=MarcResolver,
        delete=False,
    )

    conceptpid = PIDField(
        key="conceptid",
        provider=MarcDraftProvider,
        context_cls=MarcPIDFieldContext,
        resolver_cls=MarcResolver,
        delete=False,
    )
Ejemplo n.º 22
0
class Marc21Record(Record):
    """Define API for Marc21 creation and manipulation."""

    model_cls = models.RecordMetadata

    index = IndexField("marc21records-marc21-marc21-v1.0.0",
                       search_alias="marc21records-marc21")

    pid = PIDField(
        key="id",
        provider=MarcRecordProvider,
        delete=False,
        context_cls=MarcPIDFieldContext,
        resolver_cls=MarcResolver,
    )

    conceptpid = PIDField(
        key="conceptid",
        provider=MarcRecordProvider,
        delete=False,
        context_cls=MarcPIDFieldContext,
        resolver_cls=MarcResolver,
    )
Ejemplo n.º 23
0
class Record(BaseRecord):
    """API for projects resources."""

    # Configuration
    model_cls = models.RecordMetadata

    # System fields
    index = IndexField('projects-project-v1.0.0', search_alias='projects')

    # The `pid_type` must not be filled as argument in this constructor.
    # Instead it is guessed from RecordIdProvider.
    pid = PIDField('id', provider=RecordIdProvider)

    # PID type retrieved from provider
    pid_type = RecordIdProvider.pid_type

    dumper = ElasticsearchDumper(extensions=[ElasticsearchDumperObjectsExt()])

    _extensions = [ValidationExtension()]

    @cached_property
    def schema(self):
        """Return the schema."""
        schema_key = 'projects' if not has_custom_resource(
            'projects') else f'{current_organisation["code"]}/projects'

        schema = f'https://sonar.ch/schemas/{schema_key}/project-v1.0.0.json'

        return ConstantField('$schema', schema)

    def __repr__(self):
        """String representation of object.

        :returns: A string representing the object.
        """
        return self['metadata']['name']