def get_outcomes_model_for_given_outcome_names()

in aws-frauddetector-detector/src/aws_frauddetector_detector/helpers/model_helpers.py [0:0]


def get_outcomes_model_for_given_outcome_names(frauddetector_client, outcome_names, reference_outcome_names):
    outcome_models = []
    for outcome_name in outcome_names:
        get_outcomes_response = api_helpers.call_get_outcomes(frauddetector_client, outcome_name)
        outcomes = get_outcomes_response.get("outcomes", [])
        if len(outcomes) != 1:
            raise RuntimeError(
                f"Error! Expected an existing outcome, but outcome did not exist! outcome {outcome_name}"
            )
        outcome = outcomes[0]
        outcome_arn = outcome.get("arn", "")
        LOG.debug(f"checking if outcome {outcome_name} is in {reference_outcome_names}")
        if outcome_name in reference_outcome_names:
            LOG.debug(f"outcome in reference set, {outcome_name} is not defined inline")
            outcome_model = models.Outcome(
                Name=outcome_name,
                Arn=outcome_arn,
                Tags=None,
                Description=None,
                CreatedTime=None,
                LastUpdatedTime=None,
                Inline=False,
            )
        else:
            LOG.debug(f"outcome not in reference set, {outcome_name} is inline")
            outcome_tags = _get_tags_for_given_arn(frauddetector_client, outcome_arn)
            tag_models = get_tag_models_from_tags(outcome_tags)
            outcome_model = models.Outcome(
                Name=outcome_name,
                Tags=tag_models,
                Description=outcome.get("description", ""),
                Arn=outcome_arn,
                CreatedTime=outcome.get("createdTime", ""),
                LastUpdatedTime=outcome.get("lastUpdatedTime", ""),
                Inline=True,
            )
        # remove empty description/tags
        LOG.debug(f"removing empty descriptions/tags from outcome model: {outcome_model}")
        if not outcome_model.Tags:
            del outcome_model.Tags
        if outcome_model.Description is None or outcome_model.Description == "":
            del outcome_model.Description
        outcome_models.append(outcome_model)
    return outcome_models