Skip to content

Commit

Permalink
Fix: generate display label method if label rule is missing from conf…
Browse files Browse the repository at this point in the history
…ig file (#14)
  • Loading branch information
ehennestad committed Aug 30, 2024
1 parent e86b89d commit de34dc4
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions pipeline/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def _extract_template_variables(self):
embedded_types = [ {'name':prop["name"],'types':prop["type_list"]} for prop in props if prop["is_embedded"] ]

class_name = _generate_class_name(schema[SCHEMA_PROPERTY_TYPE]).split(".")[-1]
display_label_method_expression = _get_display_label_method_expression(class_name)
display_label_method_expression = _get_display_label_method_expression(class_name, schema["properties"].keys())

# TODO: Specify base class. Implement template with configurable base class. Schema or ControlledTerm?
# Or; just remove this as it's not needed when using separate templates.
Expand Down Expand Up @@ -373,7 +373,7 @@ def _list_to_string_array(list_of_strings, do_sort=False):
string_array = "[{}]".format(", ".join(list_of_strings))
return string_array

def _get_display_label_method_expression(schema_short_name):
def _get_display_label_method_expression(schema_short_name, property_names):
"""
Create the display label expression to be added as a getDisplayLabel
method in the schema class
Expand Down Expand Up @@ -403,7 +403,7 @@ def _get_display_label_method_expression(schema_short_name):
str_formatter = this_config['stringFormat']

if not prop_names:
return ""
return "str = '<missing name>'"

if not isinstance(prop_names, list):
prop_names = [prop_names]
Expand All @@ -422,7 +422,19 @@ def _get_display_label_method_expression(schema_short_name):
# Join the lines with newline
return '\n '.join(str_formatter)
else:
return ""
property_names = [_create_matlab_name(name) for name in property_names]

if "lookupLabel" in property_names:
return "str = obj.lookupLabel;"
elif "fullName" in property_names:
return "str = obj.fullName;"
elif "identifier" in property_names:
return "str = obj.identifier;"
elif "name" in property_names:
return "str = obj.name;"
else:
warnings.warn(f"No display label method found for {schema_short_name}.")
return "str = '<missing name>'"

def _create_property_validator_functions(name, property_info):

Expand Down

0 comments on commit de34dc4

Please sign in to comment.