Skip to content

Commit

Permalink
Merge pull request #226 from geo-knowledge-hub/master
Browse files Browse the repository at this point in the history
Updating branch b-0.8
  • Loading branch information
M3nin0 authored May 8, 2024
2 parents e1741c0 + 003705f commit 2fb65c5
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 99 deletions.
8 changes: 8 additions & 0 deletions geo_rdm_records/base/resources/schema/ui/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ class UIRecordSchema(UIRecordSchemaBase):
attribute="metadata.related_identifiers",
)

resource_type = fields.Nested(
VocabularyL10Schema,
# In the GEO Knowledge Hub, the unique case where `resource type` is unavailable
# is in the package record.
attribute="metadata.resource_type",
dump_default={"id": "knowledge", "title": {"en": "Knowledge Package"}},
)

#
# Custom fields
#
Expand Down
23 changes: 18 additions & 5 deletions geo_rdm_records/base/services/facets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,27 @@
from invenio_vocabularies.services.facets import VocabularyLabels

#
# GEO Work Programme Activities Facet
# Record category
#
record_category = TermsFacet(
field="parent.category",
label=_("Category"),
value_labels={
"open": "Open",
"marketplace": "Marketplace",
"marketplace": "Commercial",
},
)

#
# Record type
#
record_type = TermsFacet(
field="parent.type",
label=_("Record Type"),
value_labels={
"package": "Knowledge Package",
"resource": "Knowledge Resource",
"marketplace-item": "Marketplace Item",
},
)

Expand Down Expand Up @@ -63,12 +76,12 @@
)

#
# Record type (or Resource type)
# Resource type
#
record_type = NestedTermsFacet(
resource_type = NestedTermsFacet(
field="metadata.resource_type.props.type",
subfield="metadata.resource_type.props.subtype",
splitchar="::",
label=_("Record Type"),
label=_("Resource Type"),
value_labels=VocabularyLabels("resourcetypes"),
)
7 changes: 7 additions & 0 deletions geo_rdm_records/base/services/schemas/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ class MetadataSchema(BaseMetadataSchema):
contributors = fields.List(fields.Nested(ContributorSchema))
related_identifiers = fields.List(fields.Nested(RelatedIdentifierSchema))

resource_type = fields.Nested(
VocabularySchema,
# In the GEO Knowledge Hub, the unique case where `resource type` is unavailable
# is in the package record.
dump_default={"id": "knowledge", "title": {"en": "Knowledge Package"}},
)

#
# Locations
#
Expand Down
6 changes: 5 additions & 1 deletion geo_rdm_records/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,12 @@
"field": "languages",
},
},
"resource_type": {
"record_type": {
"facet": geo_facets.record_type,
"ui": {"field": "parent.type"},
},
"resource_type": {
"facet": geo_facets.resource_type,
"ui": {
"field": "resource_type.type",
"childAgg": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@
},
"uniqueItems": true
},

"resource_type": {
"$ref": "local://records/definitions-v2.0.0.json#/resource_type"
},
"creators": {
"description": "Creators of the resource.",
"type": "array",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -811,35 +811,6 @@
}
}
},
"resource_type": {
"type": "object",
"properties": {
"@v": {
"type": "keyword"
},
"id": {
"type": "keyword"
},
"title": {
"type": "object",
"dynamic": true
},
"props": {
"type": "object",
"properties": {
"type": {
"type": "keyword"
},
"subtype": {
"type": "keyword"
},
"basetype": {
"type": "keyword"
}
}
}
}
},
"rights": {
"type": "object",
"properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,35 +767,6 @@
}
}
},
"resource_type": {
"type": "object",
"properties": {
"@v": {
"type": "keyword"
},
"id": {
"type": "keyword"
},
"title": {
"type": "object",
"dynamic": true
},
"props": {
"type": "object",
"properties": {
"type": {
"type": "keyword"
},
"subtype": {
"type": "keyword"
},
"basetype": {
"type": "keyword"
}
}
}
}
},
"rights": {
"type": "object",
"properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class PackageResourceTypeComponent(ServiceComponent):
def _fix_resource_type(self, obj):
"""Fix the resource type of the package."""
metadata = obj.get("metadata", {})
dict_set(metadata, "resource_type", {"id": "knowledge"})

if "resource_type" in metadata:
del metadata["resource_type"]

return metadata

Expand All @@ -34,6 +36,8 @@ def update_draft(self, identity, data=None, record=None, **kwargs):
def publish(self, identity, draft=None, record=None, **kwargs):
"""Update draft metadata."""
metadata_fixed = self._fix_resource_type(draft)

draft.metadata = metadata_fixed
record.metadata = metadata_fixed

def edit(self, identity, draft=None, record=None, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion geo_rdm_records/modules/packages/services/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ class GEOPackageRecordServiceConfig(BaseGEOServiceConfig):
PackageResourceIntegrationComponent,
PackageResourceAccessComponent,
PackageResourceCommunityComponent,
PackageResourceTypeComponent,
PackageContextComponent,
MetadataComponent,
PackageResourceTypeComponent,
CustomFieldsComponent,
AccessComponent,
DraftFilesComponent,
Expand Down
26 changes: 5 additions & 21 deletions geo_rdm_records/modules/packages/services/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,19 @@
"""GEO RDM Records Packages API Schemas."""

from invenio_rdm_records.services.schemas import RDMRecordSchema as BaseRecordSchema
from invenio_rdm_records.services.schemas.metadata import VocabularySchema
from marshmallow import fields
from marshmallow_utils.fields import NestedAttribute

from geo_rdm_records.base.services.schemas import HarvesterSchema
from geo_rdm_records.base.services.schemas import MetadataSchema as BaseMetadataSchema
from geo_rdm_records.base.services.schemas import ParentSchema
from geo_rdm_records.base.services.schemas.validator import ResourceType
from geo_rdm_records.base.services.schemas import (
HarvesterSchema,
MetadataSchema,
ParentSchema,
)

from .relationship import RelationshipSchema
from .requests import RequestSchema


class MetadataSchema(BaseMetadataSchema):
"""Package metadata schema."""

# Packages are created using the same metadata model as a record, but
# we can't allow users to define the same values. One example
# of this is the `resource type`. A package can only have a one
# resource type, which is the `knowledge` (Knowledge Package type
# identifier in the GEO Knowledge Hub types vocabulary).
resource_type = fields.Nested(
VocabularySchema,
required=False,
validate=ResourceType("knowledge"),
dump_only=False,
)


class GEOPackageRecordSchema(BaseRecordSchema):
"""Record schema."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_package_relationship_constraint(
anyuser_identity,
draft_resource_record,
published_resource_record,
minimal_record,
minimal_package,
es_clear,
):
"""Test the Package Relationship constraint."""
Expand All @@ -144,7 +144,7 @@ def test_package_relationship_constraint(
# 2. Resources linked to a package must have the relationship ``Related``

# 2.1. Valid case
package = GEOPackageDraft.create(minimal_record)
package = GEOPackageDraft.create(minimal_package)
package.commit()
db.session.commit()

Expand All @@ -160,7 +160,7 @@ def test_package_relationship_constraint(
)

# 2.2. Invalid case
package2 = GEOPackageDraft.create(minimal_record)
package2 = GEOPackageDraft.create(minimal_package)
package2.commit()
db.session.commit()

Expand All @@ -179,7 +179,7 @@ def test_published_package_constraint(
running_app,
draft_resource_record,
published_resource_record,
minimal_record,
minimal_package,
es_clear,
):
"""Test the Published Package constraint."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
from geo_rdm_records.modules.rdm.records.api import GEODraft


def test_package_resource_access_component(running_app, minimal_record, es_clear):
def test_package_resource_access_component(
running_app, minimal_package, minimal_record, es_clear
):
"""Test the ``access`` component for package resources."""
# 1. Creating a restricted package (`record` and `files`)
package_access = dict(record="restricted", files="restricted")

package_metadata = copy(minimal_record)
package_metadata = copy(minimal_package)
package_metadata.update({"access": package_access})

package_draft = GEOPackageDraft.create(package_metadata)
Expand All @@ -49,11 +51,11 @@ def test_package_resource_access_component(running_app, minimal_record, es_clear


def test_package_resource_community_component(
running_app, minimal_record, community_record, es_clear
running_app, minimal_package, minimal_record, community_record, es_clear
):
"""Test the ``community`` component for package resources."""
# 1. Creating a package
package_metadata = copy(minimal_record)
package_metadata = copy(minimal_package)

package_draft = GEOPackageDraft.create(package_metadata)
package_draft.commit()
Expand Down

0 comments on commit 2fb65c5

Please sign in to comment.