Skip to content

Add contributor descriptor function, update graph config - #1690

Closed
bferguso wants to merge 1 commit into
ts/bugfix/general_fixesfrom
brf/feat/update_contributor_descriptors
Closed

Add contributor descriptor function, update graph config#1690
bferguso wants to merge 1 commit into
ts/bugfix/general_fixesfrom
brf/feat/update_contributor_descriptors

Conversation

@bferguso

Copy link
Copy Markdown
Collaborator

No description provided.

@bferguso
bferguso requested a review from seeker25 August 21, 2026 16:35
Comment on lines +29 to +83
class ContributorDescriptors(BCPrimaryDescriptorsFunction):
# For Name part of descriptor
_graph_slug = GraphSlugs.CONTRIBUTOR
_graph_lookup = None

_name_nodes = [aliases.CONTRIBUTOR_NAME, aliases.FIRST_NAME]
_card_nodes = [aliases.CONTRIBUTOR_TYPE, aliases.CONTRIBUTOR_ROLE]

def __init__(self):
super(ContributorDescriptors).__init__()
self._graph_lookup = GraphLookup(
ContributorDescriptors._graph_slug,
ContributorDescriptors._name_nodes + ContributorDescriptors._card_nodes,
)

def get_primary_descriptor_from_nodes(
self, resource, config, context=None, descriptor=None
):
return_value = ""

try:
if descriptor == "name":
return self._get_name(resource)

for node_alias in self._card_nodes:
value = self.get_value_from_node(
self._graph_lookup.get_node(node_alias),
self._graph_lookup.get_datatype(node_alias),
resource,
)
if value:
return_value += self.format_value(
self._graph_lookup.get_node(node_alias).name, value, True
)

return return_value

except ValueError as e:
print(e, "invalid nodegroupid participating in descriptor function.")

def _get_name(self, resource):
contributor_name = self.get_value_from_node(
self._graph_lookup.get_node(aliases.CONTRIBUTOR_NAME),
self._graph_lookup.get_datatype(aliases.CONTRIBUTOR_NAME),
resource,
)
first_name = self.get_value_from_node(
self._graph_lookup.get_node(aliases.FIRST_NAME),
self._graph_lookup.get_datatype(aliases.FIRST_NAME),
resource,
)
name = str(contributor_name) if contributor_name else ""
if first_name:
name = f"{name}, {first_name}"
return name

@seeker25 seeker25 Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an easier way to accomplish this

from bcap.util.bcap_aliases import GraphSlugs
from bcap.util.aliases.contributor import ContributorAliases as aliases
from bcgov_arches_common.util.bc_primary_descriptors_function import (
    BCPrimaryDescriptorsFunction,
)
from bcgov_arches_common.util.graph_lookup import GraphLookup

details = {
    "functionid": "60000000-0000-0000-0000-000000001007",
    "name": "Contributor Descriptors",
    "type": "primarydescriptors",
    "modulename": "contributor_descriptors.py",
    "description": "Function that provides the primary descriptors for BCAP Contributors",
    "defaultconfig": {
        "module": "bcap.functions.contributor_descriptors",
        "class_name": "ContributorDescriptors",
        "descriptor_types": {
            "name": {},
            "description": {},
            "map_popup": {},
        },
        "triggering_nodegroups": [],
    },
    "classname": "ContributorDescriptors",
    "component": "views/components/functions/contributor-descriptors",
}


# The node aliases each contributor descriptor is built from.
class ContributorDescriptorNodes:
    NAME = [aliases.CONTRIBUTOR_NAME, aliases.FIRST_NAME]
    CARD = [aliases.CONTRIBUTOR_TYPE, aliases.CONTRIBUTOR_ROLE]


class ContributorDescriptors(BCPrimaryDescriptorsFunction):
    # Arches builds a fresh instance per descriptor per resource, and a lookup
    # re-reads its nodes on first use, so share one for the whole process.
    _graph_lookup = GraphLookup(
        GraphSlugs.CONTRIBUTOR,
        ContributorDescriptorNodes.NAME + ContributorDescriptorNodes.CARD,
    )

    def get_primary_descriptor_from_nodes(
        self, resource, config, context=None, descriptor=None
    ):
        match descriptor:
            case "name":
                node_aliases = ContributorDescriptorNodes.NAME
            case "description":
                node_aliases = ContributorDescriptorNodes.CARD
            case "map_popup":
                return ""
            case _:
                return ""

        values = [
            self.format_value(
                None,
                self.get_value_from_node(
                    self._graph_lookup.get_node(alias),
                    self._graph_lookup.get_datatype(alias),
                    resource,
                    context=context,
                ),
                show_name=False,
            )
            for alias in node_aliases
        ]

        return ", ".join(value for value in values if value)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks similar

@seeker25

seeker25 commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

if we don't do a migration to update the contributors they will be stuck on our machines with the coma in it?

eg.

    contributors = list(Resource.objects.filter(graph__slug=GraphSlugs.CONTRIBUTOR))
    for contributor in contributors:
        contributor.save_descriptors()
    Resource.objects.bulk_update(contributors, ["descriptors"], batch_size=1000)
    bulk_index(contributors)

If you build a migration for it, takes a while to run too..
I started working on this before you said you'd work on it

property.string_template(template);
}, this);
}
// if (property.card_names) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth removing? is it used? will it be used?

@seeker25 seeker25 closed this Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants