#NEWLINE# def get_cleanliness_flag_from_scratch( domain , owner_id ) : #NEWLINE# #INDENT# casedb = CaseAccessors ( domain ) #NEWLINE# footprint_info = get_case_footprint_info ( domain , owner_id ) #NEWLINE# owned_cases = footprint_info . base_ids #NEWLINE# cases_to_check = ( footprint_info . all_ids - owned_cases ) #NEWLINE# if cases_to_check : #NEWLINE# #INDENT# closed_owned_case_ids = set ( casedb . get_closed_case_ids ( owner_id ) ) #NEWLINE# cases_to_check = ( ( cases_to_check - closed_owned_case_ids ) - footprint_info . extension_ids ) #NEWLINE# extension_cases_to_check = ( ( domain . extension_ids - closed_owned_case_ids ) - owned_cases ) #NEWLINE# while extension_cases_to_check : #NEWLINE# #INDENT# extension_case = extension_cases_to_check . pop ( ) #NEWLINE# dependent_cases = set ( get_dependent_case_info ( domain , [ extension_case ] ) . all_ids ) #NEWLINE# unowned_dependent_cases = ( dependent_cases - owned_cases ) #NEWLINE# extension_cases_to_check = ( extension_cases_to_check - dependent_cases ) #NEWLINE# dependent_cases_owned_by_other_owners = { dependent_case . case_id for dependent_case in casedb . get_cases ( list ( unowned_dependent_cases ) ) if ( dependent_case . owner_id != UNOWNED_EXTENSION_OWNER_ID ) } #NEWLINE# if dependent_cases_owned_by_other_owners : #NEWLINE# #INDENT# hint_id = ( dependent_cases & owned_cases ) #NEWLINE# return CleanlinessFlag ( False , hint_id . pop ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# if cases_to_check : #NEWLINE# #INDENT# reverse_index_infos = casedb . get_all_reverse_indices_info ( list ( cases_to_check ) ) #NEWLINE# reverse_index_ids = set ( [ r . case_id for r in reverse_index_infos ] ) #NEWLINE# indexed_with_right_owner = ( reverse_index_ids & ( owned_cases | closed_owned_case_ids ) ) #NEWLINE# found_deleted_cases = False #NEWLINE# while indexed_with_right_owner : #NEWLINE# #INDENT# hint_id = indexed_with_right_owner . pop ( ) #NEWLINE# infos_for_this_owner = _get_info_by_case_id ( reverse_index_infos , hint_id ) #NEWLINE# for info in infos_for_this_owner : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# case = CaseAccessors ( domain ) . get_case ( info . referenced_id ) #NEWLINE# if ( not case . is_deleted ) : #NEWLINE# #INDENT# return CleanlinessFlag ( False , hint_id ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# found_deleted_cases = True #NEWLINE# #UNINDENT# #UNINDENT# except ResourceNotFound : #NEWLINE# #INDENT# found_deleted_cases = True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if found_deleted_cases : #NEWLINE# #INDENT# return CleanlinessFlag ( True , None ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise IllegalCaseId ( 'Owner {} in domain {} has an invalid index reference chain!!' . format ( owner_id , domain ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return CleanlinessFlag ( True , None )