Skip to content

Commit a7c4600

Browse files
committed
add exclusive hidden label validation
1 parent 504b169 commit a7c4600

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

app/models/concept/validations.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Validations
1212
validate :valid_rank_for_ranked_relations
1313
validate :unique_pref_labels
1414
validate :exclusive_pref_and_alt_labels_per_concept
15+
validate :exclusive_hidden_labels_per_concept
1516
validate :unique_alt_labels
1617
validate :exclusive_broader_and_narrower_concepts
1718
validate :no_self_reference_concept_relation
@@ -101,6 +102,19 @@ def exclusive_pref_and_alt_labels_per_concept
101102
end
102103
end
103104

105+
def exclusive_hidden_labels_per_concept
106+
if self.validatable_for_publishing?
107+
relevant_labels = self.labelings.reject { |lbl| lbl.is_a?(Iqvoc::Concept.hidden_labeling_class) }.collect(&:target)
108+
109+
self.hidden_labels.each do |hidden_label|
110+
if relevant_labels.include? hidden_label
111+
errors.add :base, I18n.t('txt.models.concept.hidden_label_defined_in_other_labels', label: hidden_label.value)
112+
end
113+
end
114+
115+
end
116+
end
117+
104118
def unique_alt_labels
105119
if validatable_for_publishing?
106120
alt_labels = alt_labelings.collect { |l| l.target }

config/locales/de.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ de:
461461
pref_label_not_unique: "Das PrefLabel %{label} ist bereits in Verwendung."
462462
pref_labels_not_unique: "Die PrefLabels %{label} sind bereits in Verwendung."
463463
pref_label_defined_in_alt_labels: "Das AltLabel %{label} wird bereits als PrefLabel verwendet."
464+
hidden_label_defined_in_other_labels: "Das HiddenLabel %{label} wird bereits als Pref- oder AltLabel verwendet."
464465
alt_labels_not_unique: "Das AltLabel %{label} wird zweimal als AltLabel verwendet."
465466
collection:
466467
uri: "Kollektion-URI"

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ en:
471471
pref_label_not_unique: "The preferred label '%{label}' is already in use."
472472
pref_labels_not_unique: "The preferred labels '%{label}' are already in use."
473473
pref_label_defined_in_alt_labels: "The alternative label %{label} is already used as a preferred label."
474+
hidden_label_defined_in_other_labels: "The hidden label %{label} is already used as a preferred or alternative label."
474475
alt_labels_not_unique: "The alternative label %{label} is used twice."
475476
collection:
476477
uri: "Collection URI"

lib/iqvoc/configuration/concept.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ def alt_labeling_class
8383
alt_labeling_class_name.constantize
8484
end
8585

86+
def hidden_labeling_class
87+
hidden_labeling_class_name.constantize
88+
end
89+
8690
def labeling_class_names
8791
{ pref_labeling_class_name => pref_labeling_languages }.merge(further_labeling_class_names)
8892
end

0 commit comments

Comments
 (0)