Class: Collection::Base

Inherits:
Concept::Base show all
Defined in:
app/models/collection/base.rb

Overview

Copyright 2011-2013 innoQ Deutschland GmbH

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Direct Known Subclasses

SKOS::Base

Instance Attribute Summary

Attributes inherited from Concept::Base

#reverse_match_service

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Concept::Base

#additional_info, #assigned_collection_origins, #assigned_collection_origins=, #associated_objects_in_editing_mode, broader_tops, #concept_relations_by_id, #concept_relations_by_id=, #concept_relations_by_id_and_rank, expired, #expired?, for_dashboard, inline_partial_name, #jobs, #labelings_by_text, #labelings_by_text=, #labels_for_labeling_class_and_language, #matches_for_class, not_expired, #notations_for_class, #notes_for_class, parentless, #pref_label, #related_concepts_for_relation_class, #to_s, with_associations

Methods included from FirstLevelObjectValidations

#distinct_versions, #origin_has_to_be_escaped

Methods included from Concept::Validations

#exclusive_broader_and_narrower_concepts, #exclusive_pref_and_alt_labels_per_concept, #exclusive_top_term, #no_self_reference_concept_relation, #pref_label_in_primary_thesaurus_language, #rooted_top_terms, #unique_alt_labels, #unique_pref_label_language, #unique_pref_labels, #valid_rank_for_ranked_relations

Methods included from Versioning

#branch, #disable_validations_for_publishing, #editor_selectable?, #enable_validations_for_publishing, #in_review?, #never_published?, #publish, #publish!, #publishable?, #published?, #state, #to_review, #unpublish, #unpublished?, #validatable_for_publishing?, #with_validations_for_publishing

Class Method Details

.by_label_value(val) ⇒ Object



81
82
83
# File 'app/models/collection/base.rb', line 81

def self.by_label_value(val)
  includes(:labels).merge(Label::Base.by_query_value(val))
end

.by_origin(origin) ⇒ Object



77
78
79
# File 'app/models/collection/base.rb', line 77

def self.by_origin(origin)
  where(origin: origin)
end

.by_parent_id(parent_id) ⇒ Object



90
91
92
93
# File 'app/models/collection/base.rb', line 90

def self.by_parent_id(parent_id)
  includes(:parent_collection_members).
      where(Collection::Member::Base.arel_table[:collection_id].eq(parent_id))
end

.dashboard_pathObject



95
96
97
# File 'app/models/collection/base.rb', line 95

def self.dashboard_path
  'collection_dashboard_path'
end


99
100
101
# File 'app/models/collection/base.rb', line 99

def self.edit_link_partial_name
  'partials/collection/edit_link_base'
end


103
104
105
# File 'app/models/collection/base.rb', line 103

def self.new_link_partial_name
  'partials/collection/new_link_base'
end

.topsObject



85
86
87
88
# File 'app/models/collection/base.rb', line 85

def self.tops
  includes(:parent_collection_members).
      where("#{Collection::Member::Base.table_name}.target_id IS NULL")
end

.with_pref_labelsObject



70
71
72
73
74
75
# File 'app/models/collection/base.rb', line 70

def self.with_pref_labels
  preload(:pref_labels)
    .joins(:pref_labels)
    .references(:collection_members)
    .distinct
end

Instance Method Details

#build_rdf_subject(&block) ⇒ Object



119
120
121
# File 'app/models/collection/base.rb', line 119

def build_rdf_subject(&block)
  IqRdf.build_uri(self.origin, IqRdf::Skos::build_uri('Collection'), &block)
end

#circular_subcollectionsObject

This only prevent circles of length 2. TODO: This should be a real circle detector (but still performant) or be removed (seems to me like the better idea).



192
193
194
195
196
197
198
199
# File 'app/models/collection/base.rb', line 192

def circular_subcollections
  Iqvoc::Collection.base_class.by_origin(@member_collection_origins).includes(members: :target).each do |subcollection|
    if subcollection.subcollections.include?(self)
      errors.add(:base,
        I18n.t('txt.controllers.collections.circular_error', label: subcollection.pref_label))
    end
  end
end

#class_pathObject



107
108
109
# File 'app/models/collection/base.rb', line 107

def class_path
  'collection_path'
end

#inline_member_collection_originsObject



145
146
147
# File 'app/models/collection/base.rb', line 145

def inline_member_collection_origins
  @member_collection_origins || subcollections.map(&:origin).uniq
end

#inline_member_collection_origins=(origins) ⇒ Object



140
141
142
143
# File 'app/models/collection/base.rb', line 140

def inline_member_collection_origins=(origins)
  @member_collection_origins = origins.to_s.
      split(InlineDataHelper::SPLITTER).map(&:strip)
end

#inline_member_collectionsObject



149
150
151
152
153
154
155
# File 'app/models/collection/base.rb', line 149

def inline_member_collections
  if @member_collection_origins
    Collection::Base.where(origin: @member_collection_origins)
  else
    subcollections
  end
end

#inline_member_concept_originsObject



128
129
130
# File 'app/models/collection/base.rb', line 128

def inline_member_concept_origins
  @member_concept_origins || concepts.map { |m| m.origin }.uniq
end

#inline_member_concept_origins=(origins) ⇒ Object



123
124
125
126
# File 'app/models/collection/base.rb', line 123

def inline_member_concept_origins=(origins)
  @member_concept_origins = origins.to_s.
      split(InlineDataHelper::SPLITTER).map(&:strip)
end

#inline_member_conceptsObject



132
133
134
135
136
137
138
# File 'app/models/collection/base.rb', line 132

def inline_member_concepts
  if @member_concept_origins
    Concept::Base.editor_selectable.where(origin: @member_concept_origins)
  else
    concepts.select{ |c| c.editor_selectable? }
  end
end

#labelObject



115
116
117
# File 'app/models/collection/base.rb', line 115

def label
  pref_label
end

#regenerate_collection_membersObject



183
184
185
# File 'app/models/collection/base.rb', line 183

def regenerate_collection_members
  regenerate_members(Collection::Base, @member_collection_origins)
end

#regenerate_concept_membersObject



179
180
181
# File 'app/models/collection/base.rb', line 179

def regenerate_concept_members
  regenerate_members(Concept::Base, @member_concept_origins)
end

#regenerate_members(target_class, target_origins) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'app/models/collection/base.rb', line 157

def regenerate_members(target_class, target_origins)
  return if target_origins.nil? # There is nothing to do
  existing = self.members.includes(:target)
  existing = if target_class <= Collection::Base
    existing.select { |m| m.target.is_a?(Collection::Base) }
  else
    existing.reject { |m| m.target.is_a?(Collection::Base) }
  end
  new = []
  target_origins.each do |new_origin|
    member = existing.find{ |m| m.target.origin == new_origin }
    unless member
      c = target_class.by_origin(new_origin).first
      member = Iqvoc::Collection.member_class.create(collection: self, target: c) if c
    end
    new << member if member
  end
  (existing - new).each do |m|
    m.destroy
  end
end

#to_paramObject



111
112
113
# File 'app/models/collection/base.rb', line 111

def to_param
  origin
end