コード例 #1
0
def create_edit_component(input_dict: dict) -> str:
    """
    Receives a dict in the form defined under JSON_objects_definitions.py for either
    editing a component or creating a new component
    The answer is a JSON object, only containing the success state, which is True or False
    
    :param input_dict: dict containing all component attributes (special information
    to differentiate edit or create is contained in the UID, which is either -1 or the original UID
    :type input_dict: dict
    :return: A JSON object containing the success state, which is True or False
    """

    if input_dict["uid"] == "-1":
        result_dict = component_handler.add_component(input_dict)
        return processing.dict_to_json(result_dict)
    else:
        result_dict = component_handler.update_component(input_dict)
        return processing.dict_to_json(result_dict)
コード例 #2
0
def get_component_list() -> str:
    """
    Calls the get_component_list method and converts the output to JSON

    :return: Returns a JSON object, structured as described in docu/JSON_objects_definitions.py
    """

    component_list_dict = component_handler.get_component_list()
    output_json = processing.dict_to_json(component_list_dict)

    return output_json
コード例 #3
0
def delete_component(input_dict: dict) -> str:
    """
    Calls the delete_component method and returns whether successful or not in JSON Format

    :param input_dict: dict containing the component uid
    :type input_dict: dict
    :return: A JSON object containing the success state, which is True or False
    """

    result_dict = component_handler.delete_component(input_dict)
    output_json = processing.dict_to_json(result_dict)

    return output_json
コード例 #4
0
def delete_process(input_dict: dict) -> str:
    """
    Calls the delete_process method and returns whether successful or not in JSON Format

    :param input_dict: dict containing the process uid
    :type input_dict: dict
    :return: A JSON object containing either the success state if False, otherwise calls get_process
    """

    result_dict = process_handler.delete_process(input_dict)
    output_json = processing.dict_to_json(result_dict)

    return output_json
コード例 #5
0
def get_component(input_dict: dict) -> str:
    """
    Receives a dict in the form defined under JSON_objects_definitions.py for getting/viewing a component.
    It returns another JSON object, structured as described in docu/JSON_objects_definitions.py
    which is retrieved from the component_handler.

    :param input_dict: dict containing the component uid
    :type input_dict: dict
    :return: Returns a JSON object,
    structured as described in docu/JSON_objects_definitions.py representing a component
    """

    component_dict = component_handler.get_component(input_dict)
    output_json = processing.dict_to_json(component_dict)

    return output_json
コード例 #6
0
def error_handler(error_type: str, error_message: str) -> str:
    """
    Creates and returns an error dict

    :param error_type: The error name, e.g. TypeError
    :type error_type: str
    :param error_message: The error message briefly explaining the error occurrence
    :type error_message: str
    :return: str
    """

    error_response = {
        "success": False,
        "error_type": error_type,
        "error_message": error_message
    }

    return processing.dict_to_json(error_response)
コード例 #7
0
def get_process(input_dict: dict) -> str:
    """
    Receives a dict in the form defined under JSON_objects_definitions.py for getting/viewing a process.
    It returns a JSON object, structured as described in docu/JSON_objects_definitions.py
    which is retrieved from the process_handler.

    :param input_dict: dict containing the process uid
    :type input_dict: dict
    :returns: Returns a JSON object, structured as described in docu/JSON_objects_definitions.py representing a process
    :rtype: str
    """

    process_dict = process_handler.get_process(input_dict)
    metrics_dict = metric_handler.get_metrics_data()
    output_dict = processing.calculations.start_calculate_risk(
        process_dict, metrics_dict)

    output_json = processing.dict_to_json(output_dict)

    return output_json
コード例 #8
0
def get_process_list() -> str:
    """
    Calls the get_process_list method and converts the output to JSON

    :return: Returns a JSON object, structured as described in docu/JSON_objects_definitions.py
    representing a process list
    """

    process_list_dict = process_handler.get_process_list()

    # get the score and amount of components for each process
    for process_sub_dict in process_list_dict["processes"]:
        process = get_process({'uid': process_sub_dict['uid']})
        process_sub_dict["score"] = processing.type_conversion.json_to_dict(
            process)['score']
        process_sub_dict["components_count"] = len(
            processing.type_conversion.json_to_dict(process)['process']
            ['components'])

    output_json = processing.dict_to_json(process_list_dict)

    return output_json