Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor optional attributes for linked data search/fetch to pass as hash #279

Merged
merged 2 commits into from Nov 8, 2019

Conversation

elrayle
Copy link
Contributor

@elrayle elrayle commented Nov 6, 2019

The list of parameters that are passed to search and find methods for the linked data module are long. There is a need to add another parameter. In prep for that, this refactors the optional parameters into a single request_header parameter. This same change is also in AuthorityUrlService which builds the URLs used in search and find and is the primary consumer of the optional params.

All other changes are in the callers of these methods, which is coming from LinkdedDataTermsController actions.

The longer individual parameter lists are deprecated.


delegate :cors_allow_origin_header, to: Qa::ApplicationController

class_attribute :request_header_service_class
self.request_header_service_class = Qa::LinkedData::RequestHeaderService
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This service is moving some of the parameter processing out of the controller. It simplifies the controller code and allows the service to focus on the parameter processing and construction of the request_header being passed to search and find.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks much cleaner 👍

@@ -190,64 +200,19 @@ def id
params[:id]
end

def language
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removed parameter processing methods now live in the RequestHeaderService

def build_url(action_config:, action:, action_request:, substitutions: {}, subauthority: nil, language: nil) # rubocop:disable Metrics/ParameterLists
# @note All parameters after request_header are deprecated and will be removed in the next major release.
def build_url(action_config:, action:, action_request:, request_header: {}, substitutions: {}, subauthority: nil, language: nil) # rubocop:disable Metrics/ParameterLists
request_header = build_request_header(substitutions, subauthority, language) if request_header.empty?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call is to provide deprecated availability of the individual parameters.

@@ -37,29 +42,36 @@ def action_request_variable(action_config, action)
action_config.qa_replacement_patterns[key]
end

def supports_subauthorities?(action_config)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is only called once from a private method, it is collapsed into the caller.

action_config.subauthorities[subauthority.to_sym]
end

def supports_language_parameter?(action_config)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is only called once from a private method, it is collapsed into the caller.

request_header.fetch(:language, []).first
end

def build_request_header(substitutions, subauthority, language) # rubocop:disable Metrics/CyclomaticComplexity
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

providing support for deprecated individual parameters

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that worth a comment?

def find(id, language: nil, replacements: {}, subauth: nil, format: nil, jsonld: false, performance_data: false) # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
# TODO: When jsonld parameter is removed, the format parameter should default to 'json'. Not making this change now for backward compatibility of the default for jsonld parameter.
def find(id, request_header: {}, language: nil, replacements: {}, subauth: nil, format: 'json', performance_data: false) # rubocop:disable Metrics/ParameterLists
request_header = build_request_header(language: language, replacements: replacements, subauth: subauth, format: format, performance_data: performance_data) if request_header.empty?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call is to provide deprecated availability of the individual parameters.

@@ -290,6 +288,22 @@ def append_performance_data(results)
total_time_s: (access_time_s + normalize_time_s) }
{ performance: performance, results: results }
end

def build_request_header(language:, replacements:, subauth:, format:, performance_data:) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

providing support for deprecated individual parameters

@id = id
@performance_data = performance_data
@format = format
@jsonld = jsonld if @format.blank?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this PR and another one coming soon will require a major release change. So support of the deprecated jsonld parameter is being removed. There will be more deprecation removals before the major release, but they will come in a separate PR. This was removed now because of the parameter changes happening in this PR.

@@ -75,14 +73,14 @@ def load_graph(url:)
def normalize_results
normalize_start_dt = Time.now.utc

json = perform_normalization
results = perform_normalization
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Results is more accurate name. It should have changed when support for n3 and ntriples was added.

# @example Json Results for Linked Data Search
# [ {"uri":"http://id.worldcat.org/fast/5140","id":"5140","label":"Cornell, Joseph"},
# {"uri":"http://id.worldcat.org/fast/72456","id":"72456","label":"Cornell, Sarah Maria, 1802-1832"},
# {"uri":"http://id.worldcat.org/fast/409667","id":"409667","label":"Cornell, Ezra, 1807-1874"} ]
def search(query, language: nil, replacements: {}, subauth: nil, context: false, performance_data: false) # rubocop:disable Metrics/ParameterLists
def search(query, request_header: {}, language: nil, replacements: {}, subauth: nil, context: false, performance_data: false) # rubocop:disable Metrics/ParameterLists
request_header = build_request_header(language: language, replacements: replacements, subauth: subauth, context: context, performance_data: performance_data) if request_header.empty?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call is to provide deprecated availability of the individual parameters.

@@ -180,6 +184,22 @@ def append_performance_data(results)
total_time_s: (access_time_s + normalize_time_s) }
{ performance: performance, results: results }
end

def build_request_header(language:, replacements:, subauth:, context:, performance_data:) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

providing support for deprecated individual parameters

@elrayle elrayle force-pushed the refactor_opt_attrs branch 3 times, most recently from 709be1c to 7835382 Compare November 6, 2019 20:27
@elrayle elrayle changed the title [WIP] refactor optional attributes for linked data search/fetch to pass as hash refactor optional attributes for linked data search/fetch to pass as hash Nov 6, 2019

delegate :cors_allow_origin_header, to: Qa::ApplicationController

class_attribute :request_header_service_class
self.request_header_service_class = Qa::LinkedData::RequestHeaderService
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks much cleaner 👍

request_header.fetch(:language, []).first
end

def build_request_header(substitutions, subauthority, language) # rubocop:disable Metrics/CyclomaticComplexity
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that worth a comment?

@elrayle
Copy link
Contributor Author

elrayle commented Nov 8, 2019

@geekscruff Thanks for the review. I added in a comment about deprecation of individual parameter above each of the build_request_header methods.

@elrayle elrayle merged commit 56e683e into master Nov 8, 2019
@elrayle elrayle deleted the refactor_opt_attrs branch November 8, 2019 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant