app/models/dataset.rb
def step_validation
    form_steps = form_steps(false, false, true)
    step_index = form_steps[:pages].index(form_step)

    title_step = form_steps[:pages].index('title')
    if title_step && title_step <= step_index
      errors['name'] << 'You must enter a name for the dataset' if name.blank? || name.strip.blank?
    end

    connector_step = form_steps[:pages].index('connector')
    if connector_step && connector_step == step_index
      unless CONNECTOR_TYPES.include? type
        errors['type'] << 'You must enter a connector type'
      end
      unless CONNECTOR_PROVIDERS.include? provider
        errors['provider'] << 'You must enter a connector provider'
      end
      unless connector_url && !connector_url.blank? && valid_url?(connector_url)
        errors['connector_url'] << 'You must enter a valid url'
      end
      if connector_url.present? && data_path.present? && !valid_xpath?(data_path)
        errors['data_path'] << 'If the JSON file is not structured as an array of objects in document root, please provide the path to data in Xpath format. Otherwise leave blank.'
      end
    end

    pages_step = form_steps[:pages].index('labels')

    return unless pages_step && pages_step <= step_index

    unless legend&.is_a?(Hash)
      errors['legend'] << 'Labels not correctly defined'
      return
    end
    if legend[:lat].blank? ^ legend[:long].blank?
      errors['legend'] << 'Latitude and Longitude have to be filled together'
    end
    if legend[:country].blank? ^ legend[:region].blank?
      errors['legend'] << 'Country and Region have to be filled together'
    end
  end
# Validates the dataset according to the current step
Validates the dataset according to the current step
Validates the dataset according to the current step
def step_validation
    form_steps = form_steps(false, false, true)
    step_index = form_steps[:pages].index(form_step)
    title_step = form_steps[:pages].index('title')
    if title_step && title_step <= step_index
      errors['name'] << 'You must enter a name for the dataset' if name.blank? || name.strip.blank?
    end
    connector_step = form_steps[:pages].index('connector')
    if connector_step && connector_step == step_index
      unless CONNECTOR_TYPES.include? type
        errors['type'] << 'You must enter a connector type'
      end
      unless CONNECTOR_PROVIDERS.include? provider
        errors['provider'] << 'You must enter a connector provider'
      end
      unless connector_url && !connector_url.blank? && valid_url?(connector_url)
        errors['connector_url'] << 'You must enter a valid url'
      end
      if connector_url.present? && data_path.present? && !valid_xpath?(data_path)
        errors['data_path'] << 'If the JSON file is not structured as an array of objects in document root, please provide the path to data in Xpath format. Otherwise leave blank.'
      end
    end
    pages_step = form_steps[:pages].index('labels')
    return unless pages_step && pages_step <= step_index
    unless legend&.is_a?(Hash)
      errors['legend'] << 'Labels not correctly defined'
      return
    end
    if legend[:lat].blank? ^ legend[:long].blank?
      errors['legend'] << 'Latitude and Longitude have to be filled together'
    end
    if legend[:country].blank? ^ legend[:region].blank?
      errors['legend'] << 'Country and Region have to be filled together'
    end
  end
def step_validation form_steps = form_steps ( false , false , true ) step_index = form_steps [ :pages ] . index ( form_step ) title_step = form_steps [ :pages ] . index ( 'title' ) if title_step && title_step <= step_index errors [ 'name' ] << 'You must enter a name for the dataset' if name . blank? || name . strip . blank? end connector_step = form_steps [ :pages ] . index ( 'connector' ) if connector_step && connector_step == step_index unless CONNECTOR_TYPES . include? type errors [ 'type' ] << 'You must enter a connector type' end unless CONNECTOR_PROVIDERS . include? provider errors [ 'provider' ] << 'You must enter a connector provider' end unless connector_url && ! connector_url . blank? && valid_url? ( connector_url ) errors [ 'connector_url' ] << 'You must enter a valid url' end if connector_url . present? && data_path . present? && ! valid_xpath? ( data_path ) errors [ 'data_path' ] << 'If the JSON file is not structured as an array of objects in document root, please provide the path to data in Xpath format. Otherwise leave blank.' end end pages_step = form_steps [ :pages ] . index ( 'labels' ) return unless pages_step && pages_step <= step_index unless legend &. is_a? ( Hash ) errors [ 'legend' ] << 'Labels not correctly defined' return end if legend [ :lat ] . blank? ^ legend [ :long ] . blank? errors [ 'legend' ] << 'Latitude and Longitude have to be filled together' end if legend [ :country ] . blank? ^ legend [ :region ] . blank? errors [ 'legend' ] << 'Country and Region have to be filled together' end end
Validates the dataset according to the current step
Validates the dataset according to the current step