Class: Repository

Inherits:
Struct
  • Object
show all
Includes:
ASModel, AutoGenerator, Publishable
Defined in:
backend/app/model/repository.rb,
public/app/models/repository.rb

Constant Summary collapse

@@AllRepos =
{}

Constants included from JSONModel

JSONModel::REFERENCE_KEY_REGEX

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AutoGenerator

included

Methods included from Publishable

db_value_for, included

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

Constructor Details

#initialize(code, name, uri, display_name, parent, parent_url = '') ⇒ Repository

Returns a new instance of Repository.



27
28
29
30
31
32
33
34
# File 'public/app/models/repository.rb', line 27

def initialize(code, name, uri, display_name, parent, parent_url = '')
  self.code = code
  self.name = name
  self.uri = uri
  self.display_name = display_name
  self.parent = parent
  self.parent_url = parent_url if !parent_url.blank? && !parent_url.end_with?("url\.unspecified")
end

Instance Attribute Details

#codeObject

Returns the value of attribute code

Returns:

  • (Object)

    the current value of code



1
2
3
# File 'public/app/models/repository.rb', line 1

def code
  @code
end

#display_nameObject

Returns the value of attribute display_name

Returns:

  • (Object)

    the current value of display_name



1
2
3
# File 'public/app/models/repository.rb', line 1

def display_name
  @display_name
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



1
2
3
# File 'public/app/models/repository.rb', line 1

def name
  @name
end

#parentObject

Returns the value of attribute parent

Returns:

  • (Object)

    the current value of parent



1
2
3
# File 'public/app/models/repository.rb', line 1

def parent
  @parent
end

#parent_urlObject

Returns the value of attribute parent_url

Returns:

  • (Object)

    the current value of parent_url



1
2
3
# File 'public/app/models/repository.rb', line 1

def parent_url
  @parent_url
end

#uriObject

Returns the value of attribute uri

Returns:

  • (Object)

    the current value of uri



1
2
3
# File 'public/app/models/repository.rb', line 1

def uri
  @uri
end

Class Method Details

.badge_list(repo_code) ⇒ Object

determine which badges to display



16
17
18
19
20
21
22
23
24
25
# File 'public/app/models/repository.rb', line 16

def Repository.badge_list(repo_code)
  list = []
  i(resource record digital_object accession subject agent classification).each do |sym|
    badge = "#{sym}_badge".to_sym
    unless AppConfig[:pui_repos].dig(repo_code, :hide, badge).nil? ? AppConfig[:pui_hide][badge] : AppConfig[:pui_repos][repo_code][:hide][badge]
      list.push(sym.to_s)
    end
  end
  list
end

.exists?(id) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'backend/app/model/repository.rb', line 30

def self.exists?(id)
  not Repository[id].nil?
end

.from_json(json) ⇒ Object



36
37
38
# File 'public/app/models/repository.rb', line 36

def self.from_json(json)
  new(json['repo_code'], json['name'], json['uri'], json['display_string'], json['parent_institution_name'], json['url'])
end

.get_reposObject



4
5
6
7
8
9
# File 'public/app/models/repository.rb', line 4

def Repository.get_repos
  if @@AllRepos.blank?
    @@AllRepos = ArchivesSpaceClient.new.list_repositories
  end
  @@AllRepos
end

.GLOBALObject



40
41
42
43
# File 'backend/app/model/repository.rb', line 40

def self.GLOBAL
  # The repository code indicating that this group is global to all repositories
  ASConstants::Repository.GLOBAL
end

.global_repo_idObject



35
36
37
# File 'backend/app/model/repository.rb', line 35

def self.global_repo_id
  self[:repo_code => Repository.GLOBAL].id
end

.sequel_to_jsonmodel(objs, opts = {}) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'backend/app/model/repository.rb', line 152

def self.sequel_to_jsonmodel(objs, opts = {})
  jsons = super

  jsons.zip(objs).each do |json, obj|
    json['display_string'] = obj.display_string
    if (agent_id = obj.agent_representation_id)
      json["agent_representation"] = {
        "ref" => JSONModel(:agent_corporate_entity).uri_for(agent_id)
      }
    end
  end

  jsons
end

.set_repos(repos) ⇒ Object



11
12
13
# File 'public/app/models/repository.rb', line 11

def Repository.set_repos(repos)
  @@AllRepos = repos
end

Instance Method Details

#after_createObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'backend/app/model/repository.rb', line 46

def after_create
  if self.repo_code == Repository.GLOBAL
    # No need for standard groups on this one.
    return
  end

  standard_groups = [{
                       :group_code => "repository-managers",
                       :description => I18n.t("group.default_group_names.repository_managers", :repo_code => repo_code),
                       :grants_permissions => ["manage_repository", "update_location_record", "update_subject_record",
                                               "update_agent_record", "update_accession_record", "update_resource_record",
                                               "update_digital_object_record", "update_event_record", "delete_event_record", "update_container_record",
                                               "update_container_profile_record", "update_location_profile_record",
                                               "view_repository", "delete_archival_record", "suppress_archival_record",
                                               "manage_subject_record", "manage_agent_record", "view_agent_contact_record", "manage_vocabulary_record",
                                               "manage_rde_templates", "manage_container_record", "manage_container_profile_record",
                                               "manage_location_profile_record", "import_records", "cancel_job",
                                               "update_assessment_record", "delete_assessment_record", "manage_assessment_attributes",
                                               "update_enumeration_record", "manage_enumeration_record",
                                               "show_full_agents", "manage_custom_report_templates"]
                     },
                     {
                       :group_code => "repository-archivists",
                       :description => I18n.t("group.default_group_names.repository_archivists", :repo_code => repo_code),
                       :grants_permissions => ["update_subject_record", "update_agent_record", "update_accession_record",
                                               "update_resource_record", "update_digital_object_record", "update_event_record",
                                               "update_container_record", "update_container_profile_record",
                                               "update_location_profile_record", "view_repository", "manage_subject_record",
                                               "manage_agent_record", "view_agent_contact_record", "manage_vocabulary_record", "manage_container_record",
                                               "manage_container_profile_record", "manage_location_profile_record", "import_records",
                                               "update_assessment_record", "delete_assessment_record", "create_job", "cancel_job",
                                               "update_enumeration_record", "manage_enumeration_record",
                                               "show_full_agents", "manage_custom_report_templates"]
                     },
                     {
                       :group_code => "repository-project-managers",
                       :description => I18n.t("group.default_group_names.project_managers", :repo_code => repo_code),
                       :grants_permissions => ["view_repository", "update_accession_record", "update_resource_record",
                                               "update_digital_object_record", "update_event_record", "delete_event_record", "update_subject_record",
                                               "update_agent_record", "update_container_record",
                                               "update_container_profile_record", "update_location_profile_record",
                                               "delete_archival_record", "suppress_archival_record",
                                               "manage_subject_record", "manage_agent_record", "view_agent_contact_record", "manage_vocabulary_record",
                                               "manage_container_record", "manage_container_profile_record",
                                               "manage_location_profile_record", "import_records", 'merge_agents_and_subjects',
                                               "update_assessment_record", "delete_assessment_record", "update_enumeration_record",
                                               "manage_enumeration_record"]
                     },
                     {
                       :group_code => "repository-advanced-data-entry",
                       :description => I18n.t("group.default_group_names.advanced_data_entry", :repo_code => repo_code),
                       :grants_permissions => ["view_repository", "update_accession_record", "update_resource_record",
                                               "update_digital_object_record", "update_event_record", "update_subject_record",
                                               "update_agent_record", "update_container_record",
                                               "update_container_profile_record", "update_location_profile_record",
                                               "manage_subject_record", "manage_agent_record",
                                               "manage_vocabulary_record", "manage_container_record",
                                               "manage_container_profile_record", "manage_location_profile_record",
                                               "import_records", "update_assessment_record", "delete_assessment_record",
                                               "update_enumeration_record", "manage_enumeration_record"]
                     },
                     {
                       :group_code => "repository-basic-data-entry",
                       :description => I18n.t("group.default_group_names.basic_data_entry", :repo_code => repo_code),
                       :grants_permissions => ["view_repository", "update_accession_record", "update_resource_record",
                                               "update_digital_object_record", "create_job"]
                     },
                     {
                       :group_code => "repository-viewers",
                       :description => I18n.t("group.default_group_names.repository_viewers", :repo_code => repo_code),
                       :grants_permissions => ["view_repository"]
                     }]

  RequestContext.open(:repo_id => self.id) do
    standard_groups.each do |group_data|
      Group.create_from_json(JSONModel(:group).from_hash(group_data),
                             :repo_id => self.id)
    end
  end

  Notifications.notify("REPOSITORY_CHANGED")
end

#assimilate(other_repository) ⇒ Object



143
144
145
146
147
148
149
# File 'backend/app/model/repository.rb', line 143

def assimilate(other_repository)
  ASModel.all_models.each do |model|
    if model.model_scope(true) == :repository
      model.transfer_all(other_repository, self) unless [ Preference ].include?(model)
    end
  end
end

#deleteObject



130
131
132
133
134
135
136
137
138
139
140
# File 'backend/app/model/repository.rb', line 130

def delete
  # this is very expensive...probably need to come up with something
  # better...
  [ Classification, Event, Resource, DigitalObject, Accession ].each do |klass|
    klass.send(:filter, :repo_id => self.id ).destroy
  end

  super

  Notifications.notify("REPOSITORY_CHANGED")
end

#display_stringObject



168
169
170
# File 'backend/app/model/repository.rb', line 168

def display_string
  "#{name} (#{repo_code})"
end

#reindex_classification_recordsObject



196
197
198
199
# File 'backend/app/model/repository.rb', line 196

def reindex_classification_records
  ClassificationTerm.update_mtime_for_repo_id(self.id)
  Classification.update_mtime_for_repo_id(self.id)
end

#reindex_repository_recordsObject



188
189
190
191
192
193
194
# File 'backend/app/model/repository.rb', line 188

def reindex_repository_records
  ASModel.all_models.each do |model|
    if model.model_scope(true) == :repository && model.publishable?
      model.update_mtime_for_repo_id(self.id)
    end
  end
end

#update_from_json(json, opts = {}, apply_nested_records = true) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'backend/app/model/repository.rb', line 173

def update_from_json(json, opts = {}, apply_nested_records = true)
  reindex_required = self.publish != (json['publish'] ? 1 : 0)
  classification_reindex_required = self.name != json['name']

  result = super

  if reindex_required
    reindex_repository_records
  elsif classification_reindex_required
    reindex_classification_records
  end

  result
end

#validateObject



22
23
24
25
26
27
# File 'backend/app/model/repository.rb', line 22

def validate
  super
  validates_unique(:repo_code, :message => "short name already in use")
  validates_presence(:repo_code, :message => "You must supply a short name for your repository")
  validates_presence(:name, :message => "You must give your repository a name")
end