'The designation of a ToolDependency into the "orphan" category has evolved over time,
and is significantly restricted since the introduction of the TOOL_DEPENDENCY_DEFINITION
repository type.  This designation is still critical, however, in that it handles the
case where a repository contains both tools and a tool_dependencies.xml file, but the
definition in the tool_dependencies.xml file is in no way related to anything defined
by any of the contained tool\'s requirements tag sets.  This is important in that it is
often a result of a typo (e.g., dependency name or version) that differs between the tool
dependency definition within the tool_dependencies.xml file and what is defined in the
tool config\'s <requirements> tag sets.  In these cases, the user should be presented with
a warning message, and this warning message is is in fact displayed if the following
is_orphan attribute is True.  This is tricky because in some cases it may be intentional,
and tool dependencies that are categorized as "orphan" are in fact valid.'

def generate_message_for_orphan_tool_dependencies(self, repository, metadata_dict):

    has_orphan_package_dependencies = False
    has_orphan_set_environment_dependencies = False
    message = ''
    package_orphans_str = ''
    set_environment_orphans_str = ''
    if metadata_dict:
        tools = metadata_dict.get('tools', [])
        tool_dependencies = metadata_dict.get('tool_dependencies', {})
        orphan_tool_dependencies = metadata_dict.get('orphan_tool_dependencies', {})
        tool_dependencies.update(orphan_tool_dependencies)
        if (tool_dependencies and tools):
            for (td_key, requirements_dict) in tool_dependencies.items():
                if (td_key == 'set_environment'):
                    for env_requirements_dict in requirements_dict:
                        name = env_requirements_dict['name']
                        type = env_requirements_dict['type']
                        if self.tool_dependency_is_orphan(type, name, None, tools):
                            if (not has_orphan_set_environment_dependencies):
                                has_orphan_set_environment_dependencies = True
                            set_environment_orphans_str += ('<b>*    name:</b>    %s,    <b>type:</b>    %s<br/>' % (str(name), str(type)))
                else:
                    name = requirements_dict['name']
                    type = requirements_dict['type']
                    version = requirements_dict['version']
                    if self.tool_dependency_is_orphan(type, name, version, tools):
                        if (not has_orphan_package_dependencies):
                            has_orphan_package_dependencies = True
                        package_orphans_str += ('<b>*    name:</b>    %s,    <b>type:</b>    %s,    <b>version:</b>    %s<br/>' % (str(name), str(type), str(version)))
    if has_orphan_package_dependencies:
        message += 'The    settings    for    <b>name</b>,    <b>version</b>    and    <b>type</b>    from    a    '
        message += "contained    tool    configuration    file's    <b>requirement</b>    tag    does    not    match    "
        message += 'the    information    for    the    following    tool    dependency    definitions    in    the    '
        message += '<b>tool_dependencies.xml</b>    file,    so    these    tool    dependencies    have    no    '
        message += 'relationship    with    any    tools    within    this    repository.<br/>'
        message += package_orphans_str
    if has_orphan_set_environment_dependencies:
        message += 'The    settings    for    <b>name</b>    and    <b>type</b>    from    a    contained    tool    '
        message += "configuration    file's    <b>requirement</b>    tag    does    not    match    the    information    "
        message += 'for    the    following    tool    dependency    definitions    in    the    <b>tool_dependencies.xml</b>    '
        message += 'file,    so    these    tool    dependencies    have    no    relationship    with    any    tools    within    '
        message += 'this    repository.<br/>'
        message += set_environment_orphans_str
    return message
