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,
    )
Exemple #2
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)
Exemple #3
0
class CommonFieldsMixin:
    """Common system fields between records and drafts."""

    versions_model_cls = models.RDMVersionsState
    parent_record_cls = RDMParent

    schema = ConstantField(
       '$schema', 'http://localhost/schemas/records/record-v2.0.0.json')

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

    relations = RelationsField(
        languages=PIDListRelation(
            'metadata.languages',
            attrs=['id', 'title'],
            pid_field=Vocabulary.pid.with_type_ctx('languages')
        ),
    )

    bucket_id = ModelField(dump=False)

    bucket = ModelField(dump=False)

    access = RecordAccessField()

    # We redefine the property as we extend the `PIDStatusCheckField` to dump
    # the property in ES in order to be available for aggregation
    is_published = IsPublishedField(status=PIDStatus.REGISTERED)
Exemple #4
0
class CommonFieldsMixin:
    """Common system fields between records and drafts."""

    versions_model_cls = models.RDMVersionsState
    parent_record_cls = RDMParent

    schema = ConstantField(
       '$schema', 'local://records/record-v2.0.0.json')

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

    relations = RelationsField(
        languages=PIDListRelation(
            'metadata.languages',
            attrs=['id', 'title'],
            pid_field=Vocabulary.pid.with_type_ctx('languages')
        ),
    )

    bucket_id = ModelField(dump=False)

    bucket = ModelField(dump=False)

    access = RecordAccessField()

    is_published = PIDStatusCheckField(status=PIDStatus.REGISTERED, dump=True)

    pids = DictField("pids")
Exemple #5
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)
Exemple #6
0
    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)
Exemple #7
0
class ParentRecord(ParentRecordBase):
    """Example parent record."""

    # Configuration
    model_cls = ParentRecordMetadata

    # System fields
    schema = ConstantField(
        '$schema', 'http://localhost/schemas/records/parent-v1.0.0.json')
Exemple #8
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)
Exemple #9
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')
Exemple #10
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)
Exemple #11
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')
Exemple #12
0
class RDMParent(ParentRecordBase):
    """Example parent record."""

    # Configuration
    model_cls = models.RDMParentMetadata

    dumper = ElasticsearchDumper(extensions=[
        GrantTokensDumperExt("access.grant_tokens"),
    ])

    # System fields
    schema = ConstantField('$schema', 'local://records/parent-v1.0.0.json')

    access = ParentRecordAccessField()
Exemple #13
0
class Marc21Parent(BaseParentRecord):
    """Parent record."""

    versions_model_cls = VersionsState
    model_cls = ParentMetadata

    schema = ConstantField("$schema", "local://marc21/parent-v1.0.0.json")

    pid = PIDField(
        key="id",
        provider=MarcDraftProvider,
        context_cls=MarcPIDFieldContext,
        resolver_cls=MarcResolver,
        delete=False,
    )
Exemple #14
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'),
    ])
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)
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,
    )
Exemple #17
0
class RDMParent(ParentRecordBase):
    """Example parent record."""

    # Configuration
    model_cls = models.RDMParentMetadata

    dumper = ElasticsearchDumper(
        extensions=[
            GrantTokensDumperExt("access.grant_tokens"),
        ]
    )

    # System fields
    schema = ConstantField(
        '$schema', 'local://records/parent-v2.0.0.json')

    access = ParentRecordAccessField()

    review = RelatedRecord(
        Request,
        keys=['type', 'receiver', 'status'],
    )

    communities = CommunitiesField(models.RDMParentCommunity)
Exemple #18
0
 class MyRecord(SystemRecord):
     # Defined in only MyRecord
     schema = ConstantField("$schema", testschema)
     # Defined in both SystemRecord and MyRecord
     base = ConstantField("base", "myrecord")
Exemple #19
0
 class A(Record, SystemFieldsMixin):
     test = ConstantField("test", "a")
Exemple #20
0
 class B(A):
     test = ConstantField("test", "b")
Exemple #21
0
 class D(B, C):
     test = ConstantField("test", "d")
Exemple #22
0
 class TestRecord(Record, SystemFieldsMixin):
     afield = ConstantField(value='test')
Exemple #23
0
 class SystemRecord(Record, SystemFieldsMixin):
     # Only defined in SystemRecord:
     test = ConstantField("test", "test")
     # Defined in both SystemRecord and MyRecord:
     base = ConstantField("base", "systemrecord")
Exemple #24
0
class CommonFieldsMixin:
    """Common system fields between records and drafts."""

    versions_model_cls = models.RDMVersionsState
    parent_record_cls = RDMParent

    schema = ConstantField(
       '$schema', 'local://records/record-v5.0.0.json')

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

    relations = RelationsField(
        creator_affiliations=PIDNestedListRelation(
            'metadata.creators',
            relation_field='affiliations',
            keys=['name'],
            pid_field=Affiliation.pid,
            cache_key='affiliations',
        ),
        contributor_affiliations=PIDNestedListRelation(
            'metadata.contributors',
            relation_field='affiliations',
            keys=['name'],
            pid_field=Affiliation.pid,
            cache_key='affiliations',
        ),
        languages=PIDListRelation(
            'metadata.languages',
            keys=['title'],
            pid_field=Vocabulary.pid.with_type_ctx('languages'),
            cache_key='languages',
        ),
        resource_type=PIDRelation(
            'metadata.resource_type',
            keys=['title', 'props.type', 'props.subtype'],
            pid_field=Vocabulary.pid.with_type_ctx('resourcetypes'),
            cache_key='resource_type',
            value_check=dict(tags=['depositable']),
        ),
        subjects=PIDListRelation(
            'metadata.subjects',
            keys=['subject', 'scheme'],
            pid_field=Subject.pid,
            cache_key='subjects',
        ),
        licenses=PIDListRelation(
            'metadata.rights',
            keys=['title', 'description',
                  'icon', 'props.url', 'props.scheme'],
            pid_field=Vocabulary.pid.with_type_ctx('licenses'),
            cache_key='licenses',
        ),
        related_identifiers=PIDListRelation(
            'metadata.related_identifiers',
            keys=['title'],
            pid_field=Vocabulary.pid.with_type_ctx('resourcetypes'),
            cache_key='resource_type',
            relation_field='resource_type',
            value_check=dict(tags=['linkable']),
        ),
        title_types=PIDListRelation(
            'metadata.additional_titles',
            keys=['title'],
            pid_field=Vocabulary.pid.with_type_ctx('titletypes'),
            cache_key='title_type',
            relation_field='type',
        ),
        title_languages=PIDListRelation(
            'metadata.additional_titles',
            keys=['title'],
            pid_field=Vocabulary.pid.with_type_ctx('languages'),
            cache_key='languages',
            relation_field='lang',
        ),
        creators_role=PIDListRelation(
            'metadata.creators',
            keys=['title'],
            pid_field=Vocabulary.pid.with_type_ctx('creatorsroles'),
            cache_key='role',
            relation_field='role'
        ),
        contributors_role=PIDListRelation(
            'metadata.contributors',
            keys=['title'],
            pid_field=Vocabulary.pid.with_type_ctx('contributorsroles'),
            cache_key='role',
            relation_field='role'
        ),
        description_type=PIDListRelation(
            'metadata.additional_descriptions',
            keys=['title'],
            pid_field=Vocabulary.pid.with_type_ctx('descriptiontypes'),
            cache_key='description_type',
            relation_field='type',
        ),
        description_languages=PIDListRelation(
            'metadata.additional_descriptions',
            keys=['title'],
            pid_field=Vocabulary.pid.with_type_ctx('languages'),
            cache_key='languages',
            relation_field='lang',
        ),
        date_types=PIDListRelation(
            'metadata.dates',
            keys=['title'],
            pid_field=Vocabulary.pid.with_type_ctx('datetypes'),
            cache_key='date_types',
            relation_field='type',
        ),
        relation_types=PIDListRelation(
            'metadata.related_identifiers',
            keys=['title'],
            pid_field=Vocabulary.pid.with_type_ctx('relationtypes'),
            cache_key='relation_types',
            relation_field='relation_type',
        ),
    )

    bucket_id = ModelField(dump=False)

    bucket = ModelField(dump=False)

    access = RecordAccessField()

    is_published = PIDStatusCheckField(status=PIDStatus.REGISTERED, dump=True)

    pids = DictField("pids")