6/25/2018 - 6:38 AM


def _check_relational_existence(list_of_values, root_limetype):
  check if the last element of the array is a valid lime property,
  other elements must be valid lime type and has BelongTo relationship to next element
    list_of_values: an array  contains lime type chain
    root_limetype: the limetype to start property checking
    raise Exception if not valid limetype detect, otherwise return True
  assert(len(list_of_values) > 0)

  type_str = list_of_values[0]
  limetype = root_limetype.get_property(type_str)
  if len(list_of_values) == 1:
    if type_str not in [p.name for p in root_limetype.properties]:
      raise ValidationError('\'{}\' is not a property of \'{}\''.format(type_str, root_limetype.name))      
    return True
  else: # multiple element, check the first element is a valid lime type
    if not limetype:
      raise ValidationError('\'{}\' is not a valid limetype'.format(type_str))
    if not limetype.is_relation():
      raise ValidationError('\'{}\' is not a relation of \'{}\''.format(type_str, root_limetype.name))
    if not (limetype.type == 'belongsto'):
      raise ValidationError('Property \'{}\' is not a to one relation for \'{}\''.format(type_str, root_limetype.name))
    return _check_relational_existence(list_of_values[1:], limetype)