Class: OAIConfig

Inherits:
Sequel::Model
  • Object
show all
Includes:
ASModel
Defined in:
backend/app/model/oai_config.rb

Constant Summary

Constants included from JSONModel

JSONModel::REFERENCE_KEY_REGEX

Instance Method Summary collapse

Methods included from ASModel

all_models, included, update_publish_flag, update_suppressed_flag

Methods included from JSONModel

JSONModel, #JSONModel, add_error_handler, all, allow_unmapped_enum_value, backend_url, check_valid_refs, client_mode?, custom_validations, destroy_model, enum_default_value, enum_values, handle_error, init, load_schema, #models, models, parse_jsonmodel_ref, parse_reference, repository, repository_for, schema_src, set_publish_flags!, set_repository, strict_mode, strict_mode?, validate_schema, with_repository

Instance Method Details

#validateObject

validations only one row in table allowed oai_repository_name must have a value oai_admin_email must have a value and be an email address oai_record_prefix must have a value



13
14
15
16
17
18
19
20
21
22
23
# File 'backend/app/model/oai_config.rb', line 13

def validate
  validate_single_record

  validates_presence :oai_record_prefix
  validates_presence :oai_admin_email
  validates_presence :oai_repository_name

  validate_oai_admin_email_is_email
  validate_repo_set_fields
  validate_sponsor_set_fields
end

#validate_oai_admin_email_is_emailObject



38
39
40
41
42
# File 'backend/app/model/oai_config.rb', line 38

def validate_oai_admin_email_is_email
  unless self.oai_admin_email =~ /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i
    errors.add(:oai_admin_email, 'must be a valid email address')
  end
end

#validate_repo_set_fieldsObject



44
45
46
47
48
49
50
51
52
# File 'backend/app/model/oai_config.rb', line 44

def validate_repo_set_fields
  if self.repo_set_codes && self.repo_set_codes != "[]" && !self.repo_set_description
    errors.add(:repo_set_description, 'repo_set_desc_required')
  end

  if self.repo_set_codes && self.repo_set_codes != "[]" && !self.repo_set_name
    errors.add(:repo_set_name, 'repo_set_name_required')
  end
end

#validate_single_recordObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'backend/app/model/oai_config.rb', line 25

def validate_single_record
  record_count = OAIConfig.all.count

  unless record_count == 0
    # if we have an existing record, we'd better be updating that one record
    first_record = OAIConfig.first

    if self.id.nil? || first_record.id != self.id
      errors.add(:base, 'Cannot have more than one record in oai_config table.')
    end
  end
end

#validate_sponsor_set_fieldsObject



54
55
56
57
58
59
60
61
62
# File 'backend/app/model/oai_config.rb', line 54

def validate_sponsor_set_fields
  if self.sponsor_set_names && self.sponsor_set_names != "[]" && !self.sponsor_set_description
    errors.add(:sponsor_set_description, 'sponsor_set_desc_required')
  end

  if self.sponsor_set_names && self.sponsor_set_names != "[]" && !self.sponsor_set_name
    errors.add(:sponsor_set_name, 'sponsor_set_name_required')
  end
end