Add contributor descriptor function, update graph config - #1690
Closed
bferguso wants to merge 1 commit into
Closed
Conversation
seeker25
reviewed
Aug 21, 2026
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 |
Collaborator
There was a problem hiding this comment.
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)
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.. |
seeker25
reviewed
Aug 21, 2026
| property.string_template(template); | ||
| }, this); | ||
| } | ||
| // if (property.card_names) { |
Collaborator
There was a problem hiding this comment.
worth removing? is it used? will it be used?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.