Esempio n. 1
0
class DatasetSchemaV3(CreatorMixinSchemaV3, EntitySchemaV3):
    """Dataset schema."""
    class Meta:
        """Meta class."""

        rdf_type = schema.Dataset
        model = Dataset
        unknown = EXCLUDE

    creators = fields.Nested(schema.creator, PersonSchemaV3, many=True)
    date_created = fields.DateTime(schema.dateCreated, missing=None)
    date_published = fields.DateTime(schema.datePublished, missing=None)
    description = fields.String(schema.description, missing=None)
    files = fields.Nested(schema.hasPart, DatasetFileSchemaV3, many=True)
    identifier = fields.String(schema.identifier)
    in_language = fields.Nested(schema.inLanguage,
                                LanguageSchemaV5,
                                missing=None)
    keywords = fields.List(schema.keywords, fields.String())
    license = fields.Uri(schema.license, missing=None, allow_none=True)
    name = fields.String(schema.alternateName, missing=None)
    same_as = fields.Nested(schema.sameAs, UrlSchemaV5, missing=None)
    tags = fields.Nested(schema.subjectOf, DatasetTagSchemaV5, many=True)
    title = fields.String(schema.name)
    url = fields.String(schema.url)
    version = fields.String(schema.version, missing=None)

    @pre_load
    def fix_files_context(self, data, **kwargs):
        """Fix DatasetFile context for _label and external fields."""
        from renku.core.utils.migrate import migrate_types

        data = migrate_types(data)

        if "@context" not in data:
            return data

        context = data["@context"]
        if not isinstance(context, dict) or "files" not in context:
            return data

        context.setdefault("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
        context.setdefault("_label", "rdfs:label")

        files = data["@context"]["files"]
        if not isinstance(files, dict) or "@context" not in files:
            return data

        context = files["@context"]
        context.setdefault("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
        context.setdefault("_label", "rdfs:label")
        context.setdefault("external", "renku:external")
        context.setdefault(
            "renku",
            "https://swissdatasciencecenter.github.io/renku-ontology#")

        return data
Esempio n. 2
0
class UrlSchemaV5(JsonLDSchema):
    """Url schema."""
    class Meta:
        """Meta class."""

        rdf_type = schema.URL
        model = Url
        unknown = EXCLUDE

    _id = fields.Id(missing=None)
    url = fields.Uri(schema.url, missing=None)
Esempio n. 3
0
class UrlSchema(JsonLDSchema):
    """Url schema."""
    class Meta:
        """Meta class."""

        rdf_type = schema.URL
        model = Url
        unknown = EXCLUDE

    url = fields.Uri(schema.url, missing=None)
    _id = fields.Id(init_name="id", missing=None)
Esempio n. 4
0
class DatasetSchema(EntitySchema, CreatorMixinSchema):
    """Dataset schema."""
    class Meta:
        """Meta class."""

        rdf_type = schema.Dataset
        model = Dataset
        unknown = EXCLUDE

    _id = fields.Id(init_name="id", missing=None)
    _label = fields.String(rdfs.label, init_name="label", missing=None)
    date_published = fields.DateTime(
        schema.datePublished,
        missing=None,
        allow_none=True,
        format="%Y-%m-%d",
        extra_formats=("iso", "%Y-%m-%dT%H:%M:%S"),
    )
    description = fields.String(schema.description, missing=None)
    identifier = fields.String(schema.identifier)
    in_language = Nested(schema.inLanguage, LanguageSchema, missing=None)
    keywords = fields.List(schema.keywords,
                           fields.String(),
                           missing=None,
                           allow_none=True)
    license = fields.Uri(schema.license, missing=None, allow_none=True)
    title = fields.String(schema.name)
    url = fields.String(schema.url)
    version = fields.String(schema.version, missing=None)
    date_created = fields.DateTime(schema.dateCreated,
                                   missing=None,
                                   allow_none=True,
                                   format="iso",
                                   extra_formats=("%Y-%m-%d", ))
    files = Nested(schema.hasPart, DatasetFileSchema, many=True)
    tags = Nested(schema.subjectOf, DatasetTagSchema, many=True)
    same_as = Nested(schema.sameAs, UrlSchema, missing=None)
    name = fields.String(schema.alternateName)

    @pre_dump
    def fix_datetimes(self, obj, many=False, **kwargs):
        """Pre dump hook."""
        if many:
            return [self.fix_datetimes(o, many=False, **kwargs) for o in obj]
        obj.date_published = self._fix_timezone(obj.date_published)
        obj.date_created = self._fix_timezone(obj.date_created)
        return obj
Esempio n. 5
0
class DatasetSchema(EntitySchema, CreatorMixinSchema):
    """Dataset schema."""

    class Meta:
        """Meta class."""

        rdf_type = schema.Dataset
        model = Dataset
        unknown = EXCLUDE

    _id = fields.Id(init_name='id', missing=None)
    _label = fields.String(rdfs.label, init_name='label', missing=None)
    date_published = fields.DateTime(schema.datePublished, missing=None)
    description = fields.String(schema.description, missing=None)
    identifier = fields.String(schema.identifier)
    in_language = fields.Nested(
        schema.inLanguage, LanguageSchema, missing=None
    )
    keywords = fields.List(schema.keywords, fields.String())
    license = fields.Uri(schema.license, missing=None, allow_none=True)
    name = fields.String(schema.name)
    url = fields.String(schema.url)
    version = fields.String(schema.version, missing=None)
    created = fields.DateTime(schema.dateCreated, missing=None)
    files = fields.Nested(schema.hasPart, DatasetFileSchema, many=True)
    tags = fields.Nested(schema.subjectOf, DatasetTagSchema, many=True)
    same_as = fields.Nested(schema.sameAs, UrlSchema, missing=None)
    short_name = fields.String(schema.alternateName)

    @pre_load
    def fix_files_context(self, data, **kwargs):
        """Fix DatasetFile context for _label and external fields."""
        context = None
        if '@context' not in data:
            return data

        context = data['@context']
        if not isinstance(context, dict) or 'files' not in context:
            return data

        context.setdefault('rdfs', 'http://www.w3.org/2000/01/rdf-schema#')

        files = data['@context']['files']
        if not isinstance(files, dict) or '@context' not in files:
            return data

        context = files['@context']
        context.setdefault('rdfs', 'http://www.w3.org/2000/01/rdf-schema#')
        context.setdefault('_label', 'rdfs:label')
        context.setdefault('external', 'renku:external')
        context.setdefault(
            'renku', 'https://swissdatasciencecenter.github.io/renku-ontology#'
        )

        return data

    @pre_load
    def migrate_types(self, data, **kwargs):
        """Fix types."""
        from renku.core.utils.migrate import migrate_types
        return migrate_types(data)
Esempio n. 6
0
    class EntitySchema(JsonLDSchema):
        field = fields.Uri(schema.field, allow_none=True)

        class Meta:
            rdf_type = schema.Entity
            model = Entity