Skip to content

Commit

Permalink
remove obsolete URL processing methods
Browse files Browse the repository at this point in the history
Ref PR #187 Create models for IRI templates and use IRI template service to build URLs

When IriTemplateService was created, several methods in the config files became obsolete, but didn't get removed as part of that PR.
  • Loading branch information
elrayle committed Jan 10, 2019
1 parent 76a2f4c commit 4fdc552
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 171 deletions.
21 changes: 0 additions & 21 deletions lib/qa/authorities/linked_data/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,6 @@ def self.predicate_uri(config, key)
pred_uri = RDF::URI(pred) unless pred.nil? || pred.length <= 0
pred_uri
end

def self.replace_pattern(url, pattern, value, encode = false)
value = url_encode(value).gsub(".", "%2E") if encode
url.gsub("{?#{pattern}}", value)
end

def self.process_subauthority(url, subauth_pattern, subauthorities, subauth_key)
pattern = subauth_pattern[:pattern]
value = subauthorities[subauth_key] || subauth_pattern[:default]
replace_pattern(url, pattern, value)
end

def self.apply_replacements(url, config, replacements = {})
return url unless config.size.positive?
config.each do |param_key, rep_pattern|
s_param_key = param_key.to_s
value = replacements[param_key] || replacements[s_param_key] || rep_pattern[:default]
url = replace_pattern(url, param_key, value, rep_pattern[:encode])
end
url
end
end
end
end
14 changes: 0 additions & 14 deletions lib/qa/authorities/linked_data/config/search_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,6 @@ def subauthority_replacement_pattern
default = url_mappings[pattern.to_sym][:default]
@subauthority_replacement_pattern ||= { pattern: pattern, default: default }
end

# Build a linked data authority search url
# @param [String] the query
# @param [String] (optional) subauthority key
# @param [Hash] (optional) replacement values with { pattern_name (defined in YAML config) => value }
# @return [String] the search encoded url
def url_with_replacements(query, sub_auth = nil, search_replacements = {})
return nil unless supports_search?
sub_auth = sub_auth.to_sym if sub_auth.present?
url = Config.replace_pattern(url_template, qa_replacement_patterns[:query], query, qa_replacement_encoded?(:query))
url = Config.process_subauthority(url, subauthority_replacement_pattern, subauthorities, sub_auth) if subauthorities?
url = Config.apply_replacements(url, replacements, search_replacements) if replacements?
url
end
end
end
end
14 changes: 0 additions & 14 deletions lib/qa/authorities/linked_data/config/term_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,6 @@ def term_subauthority_replacement_pattern
pattern = term_qa_replacement_patterns[:subauth]
@term_subauthority_replacement_pattern ||= { pattern: pattern, default: term_url_mappings[pattern.to_sym][:default] }
end

# Build a linked data authority term url
# @param [String] the id
# @param [String] (optional) subauthority key
# @param [Hash] (optional) replacement values with { pattern_name (defined in YAML config) => value }
# @return [String] the term encoded url
def term_url_with_replacements(id, sub_auth = nil, replacements = {})
return nil unless supports_term?
sub_auth = sub_auth.to_sym if sub_auth.is_a? String
url = Config.replace_pattern(term_url_template, term_qa_replacement_patterns[:term_id], id, term_qa_replacement_encoded?(:term_id))
url = Config.process_subauthority(url, term_subauthority_replacement_pattern, term_subauthorities, sub_auth) if term_subauthorities?
url = Config.apply_replacements(url, term_replacements, replacements) if term_replacements?
url
end
end
end
end
61 changes: 0 additions & 61 deletions spec/lib/authorities/linked_data/search_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,65 +335,4 @@
expect(full_config.subauthority_replacement_pattern).to eq expected_hash
end
end

# rubocop:disable RSpec/RepeatedExample
describe '#search_url_with_replacements' do
it 'returns nil if only term configuration is defined' do
expect(term_only_config.url_with_replacements('Smith')).to eq nil
end
context 'when subauthorities ARE defined' do
it 'returns the url with query substitution applied' do
expected_url = 'http://localhost/test_default/search?subauth=search_sub1_name&query=Smith&param1=delta&param2=echo'
expect(full_config.url_with_replacements('Smith')).to eq expected_url
end
it 'returns the url with default subauthority when NOT specified' do
expected_url = 'http://localhost/test_default/search?subauth=search_sub1_name&query=Smith&param1=delta&param2=echo'
expect(full_config.url_with_replacements('Smith')).to eq expected_url
end
it 'returns the url with subauthority substitution when specified' do
expected_url = 'http://localhost/test_default/search?subauth=search_sub3_name&query=Smith&param1=delta&param2=echo'
expect(full_config.url_with_replacements('Smith', 'search_sub3_key')).to eq expected_url
end
it 'returns the url with default values when replacements are NOT specified' do
expected_url = 'http://localhost/test_default/search?subauth=search_sub1_name&query=Smith&param1=delta&param2=echo'
expect(full_config.url_with_replacements('Smith')).to eq expected_url
end
it 'returns the url with replacement substitution values when replacements are specified' do
expected_url = 'http://localhost/test_default/search?subauth=search_sub1_name&query=Smith&param1=golf&param2=hotel'
expect(full_config.url_with_replacements('Smith', nil, param1: 'golf', param2: 'hotel')).to eq expected_url
end
end

context 'when subauthorities are not defined' do
it 'returns the url with query substitution applied' do
expected_url = 'http://localhost/test_default/search?query=Smith'
expect(min_config.url_with_replacements('Smith')).to eq expected_url
end
it 'and subauth param is included returns the url with query substitution applied ignoring the subauth' do
expected_url = 'http://localhost/test_default/search?query=Smith'
expect(min_config.url_with_replacements('Smith', 'fake_subauth_key')).to eq expected_url
end
end

context 'when replacements are not defined' do
it 'returns the url with query substitution applied' do
expected_url = 'http://localhost/test_default/search?query=Smith'
expect(min_config.url_with_replacements('Smith')).to eq expected_url
end
it 'and replacements param is included returns the url with query substitution applied ignoring the replacements' do
expected_url = 'http://localhost/test_default/search?query=Smith'
expect(min_config.url_with_replacements('Smith', nil, fake_replacement_key: 'fake_value')).to eq expected_url
end
end

context 'with encoding specified in config' do
it 'returns the uri as the url' do
expected_url = 'http://localhost/test_default/search?query=encoded%20because%3Aencode%3Dtrue&yes%3Aencoded%20here&no:encoding here&defaults:to not encoded'
query = 'encoded because:encode=true'
replacements = { encode_true: 'yes:encoded here', encode_false: 'no:encoding here', encode_not_specified: 'defaults:to not encoded' }
expect(encoding_config.url_with_replacements(query, nil, replacements)).to eq expected_url
end
end
end
# rubocop:enable RSpec/RepeatedExample
end
61 changes: 0 additions & 61 deletions spec/lib/authorities/linked_data/term_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,65 +369,4 @@
expect(full_config.term_subauthority_replacement_pattern).to eq expected_hash
end
end

# rubocop:disable RSpec/RepeatedExample
describe '#term_url_with_replacements' do
it 'returns nil if only search configuration is defined' do
expect(search_only_config.term_url_with_replacements('C123')).to eq nil
end
context 'when subauthorities ARE defined' do
it 'returns the url with query substitution applied' do
expected_url = 'http://localhost/test_default/term/term_sub2_name/C123?param1=alpha&param2=beta'
expect(full_config.term_url_with_replacements('C123')).to eq expected_url
end
it 'returns the url with default subauthority when NOT specified' do
expected_url = 'http://localhost/test_default/term/term_sub2_name/C123?param1=alpha&param2=beta'
expect(full_config.term_url_with_replacements('C123')).to eq expected_url
end
it 'returns the url with subauthority substitution when specified' do
expected_url = 'http://localhost/test_default/term/term_sub3_name/C123?param1=alpha&param2=beta'
expect(full_config.term_url_with_replacements('C123', 'term_sub3_key')).to eq expected_url
end
it 'returns the url with default values when replacements are NOT specified' do
expected_url = 'http://localhost/test_default/term/term_sub2_name/C123?param1=alpha&param2=beta'
expect(full_config.term_url_with_replacements('C123')).to eq expected_url
end
it 'returns the url with replacement substitution values when replacements are specified' do
expected_url = 'http://localhost/test_default/term/term_sub2_name/C123?param1=golf&param2=hotel'
expect(full_config.term_url_with_replacements('C123', nil, param1: 'golf', param2: 'hotel')).to eq expected_url
end
end

context 'when subauthorities are NOT defined' do
it 'returns the url with query substitution applied' do
expected_url = 'http://localhost/test_default/term/C123'
expect(min_config.term_url_with_replacements('C123')).to eq expected_url
end
it 'and subauth param is included returns the url with query substitution applied ignoring the subauth' do
expected_url = 'http://localhost/test_default/term/C123'
expect(min_config.term_url_with_replacements('C123', 'fake_subauth_key')).to eq expected_url
end
end

context 'when replacements are not defined' do
it 'returns the url with query substitution applied' do
expected_url = 'http://localhost/test_default/term/C123'
expect(min_config.term_url_with_replacements('C123')).to eq expected_url
end
it 'and replacements param is included returns the url with query substitution applied ignoring the replacements' do
expected_url = 'http://localhost/test_default/term/C123'
expect(min_config.term_url_with_replacements('C123', nil, fake_replacement_key: 'fake_value')).to eq expected_url
end
end

context 'with encoding specified in config' do
it 'returns the uri as the url' do
expected_url = 'http://localhost/test_default/term?uri=http%3A%2F%2Fencoded%2Ebecause%3Fencode%3Dtrue&yes%3Aencoded%20here&no:encoding here&defaults:to not encoded'
term_uri = 'http://encoded.because?encode=true'
replacements = { encode_true: 'yes:encoded here', encode_false: 'no:encoding here', encode_not_specified: 'defaults:to not encoded' }
expect(encoding_config.term_url_with_replacements(term_uri, nil, replacements)).to eq expected_url
end
end
end
# rubocop:enable RSpec/RepeatedExample
end

0 comments on commit 4fdc552

Please sign in to comment.