-
Notifications
You must be signed in to change notification settings - Fork 5
Fixes - #270 Implemented mapping from DAMS4 to SHARE V2 API and updat… #460
Conversation
lib/dams/controller_helper.rb
Outdated
'tags': osf_mads_fields(document), | ||
'extra': osf_extra(document) | ||
} | ||
json_data = {"jsonData": field_map} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UselessAssignment: Useless assignment to variable - json_data.
Layout/SpaceInsideHashLiteralBraces: Space inside { missing.
Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
lib/dams/controller_helper.rb
Outdated
} | ||
json_data = {"jsonData": field_map} | ||
end | ||
def export_to_API(document) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming/MethodName: Use snake_case for method names.
lib/dams/controller_helper.rb
Outdated
dams_data.each do |datum| | ||
osf_data << datum | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingWhitespace: Trailing whitespace detected.
lib/dams/controller_helper.rb
Outdated
if dams_data.kind_of?(String) | ||
osf_data << dams_data | ||
elsif dams_data.kind_of?(Array) | ||
dams_data.each do |datum| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingWhitespace: Trailing whitespace detected.
lib/dams/controller_helper.rb
Outdated
dams_data = document["#{field_name}"] | ||
if dams_data.kind_of?(String) | ||
osf_data << dams_data | ||
elsif dams_data.kind_of?(Array) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/ClassCheck: Prefer Object#is_a? over Object#kind_of?.
lib/dams/controller_helper.rb
Outdated
end | ||
osf_data | ||
end | ||
def osf_mads_fields(document) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/MethodLength: Method has too many lines. [27/15]
lib/dams/controller_helper.rb
Outdated
end | ||
osf_data | ||
end | ||
osf_data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingWhitespace: Trailing whitespace detected.
lib/dams/controller_helper.rb
Outdated
langs.each do |lang| | ||
osf_data << lang | ||
end | ||
langs.each do |lang| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingWhitespace: Trailing whitespace detected.
lib/dams/controller_helper.rb
Outdated
dams_data = document["#{field_name}"] | ||
def osf_languages(document) | ||
field_name = "language_tesim" | ||
dams_data = document["#{field_name}"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/UnneededInterpolation: Prefer to_s over string interpolation.
lib/dams/controller_helper.rb
Outdated
field_name = "language_tesim" | ||
dams_data = document["#{field_name}"] | ||
def osf_languages(document) | ||
field_name = "language_tesim" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
lib/dams/controller_helper.rb
Outdated
'tags': osf_mads_fields(document), | ||
'extra': osf_extra(document) | ||
} | ||
{'jsonData': field_map} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceInsideHashLiteralBraces: Space inside { missing.
Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
lib/dams/controller_helper.rb
Outdated
'languages': osf_languages(document), | ||
'date_published': osf_date_published(document), | ||
'tags': osf_mads_fields(document), | ||
'extra': osf_extra(document) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingWhitespace: Trailing whitespace detected.
lib/dams/controller_helper.rb
Outdated
json_data = {"jsonData": field_map} | ||
end | ||
def export_to_api(document) | ||
field_map = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingWhitespace: Trailing whitespace detected.
lib/dams/controller_helper.rb
Outdated
mads_field ||= YAML.load(ERB.new(IO.read(File.join(Rails.root, 'config', 'mads_field.yml'))).result) | ||
field_names = mads_field.fetch('key') | ||
field_names.each do |field_name| | ||
dams_data = document["#{field_name}"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/UnneededInterpolation: Prefer to_s over string interpolation.
lib/dams/controller_helper.rb
Outdated
end | ||
def osf_mads_fields(document) | ||
osf_data = [] | ||
mads_field ||= YAML.load(ERB.new(IO.read(File.join(Rails.root, 'config', 'mads_field.yml'))).result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Security/YAMLLoad: Prefer using YAML.safe_load over YAML.load.
Rails/FilePath: Please use Rails.root.join('path', 'to') instead.
lib/dams/controller_helper.rb
Outdated
|
||
def osf_date_published(document) | ||
field_name = 'date_json_tesim' | ||
dams_data = document["#{field_name}"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/UnneededInterpolation: Prefer to_s over string interpolation.
lib/dams/controller_helper.rb
Outdated
|
||
if dams_data != nil | ||
url = "http://library.ucsd.edu/dc/collection/#{dams_data}" | ||
osf_data = {'canonicalUri': url, 'providerUris': url} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceInsideHashLiteralBraces: Space inside { missing.
Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
lib/dams/controller_helper.rb
Outdated
dams_data = document["#{field_name}"] | ||
osf_data = {} | ||
|
||
if dams_data != nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/NonNilCheck: Prefer !expression.nil? over expression != nil.
lib/dams/controller_helper.rb
Outdated
|
||
def osf_uris(document) | ||
field_name = 'id' | ||
dams_data = document["#{field_name}"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/UnneededInterpolation: Prefer to_s over string interpolation.
lib/dams/controller_helper.rb
Outdated
end | ||
end | ||
osf_data | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingWhitespace: Trailing whitespace detected.
lib/dams/controller_helper.rb
Outdated
'tags': osf_mads_fields(document), | ||
'extra': osf_extra(document) | ||
} | ||
{'jsonData': field_map} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceInsideHashLiteralBraces: Space inside { missing.
Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
lib/dams/controller_helper.rb
Outdated
mads_field ||= YAML.safe_load(ERB.new(IO.read(Rails.root.join('config', 'mads_field.yml'))).result) | ||
field_names = mads_field.fetch('key') | ||
field_names.each do |field_name| | ||
dams_data = document["#{field_name}"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/UnneededInterpolation: Prefer to_s over string interpolation.
lib/dams/controller_helper.rb
Outdated
dams_data = document['date_json_tesim'] | ||
osf_data = '' | ||
|
||
if !dams_data.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/NegatedIf: Favor unless over if for negative conditions.
lib/dams/controller_helper.rb
Outdated
def osf_date_published(document) | ||
dams_data = document['date_json_tesim'] | ||
osf_data = '' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingWhitespace: Trailing whitespace detected.
lib/dams/controller_helper.rb
Outdated
dams_data = document['id'] | ||
osf_data = {} | ||
|
||
if !dams_data.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/NegatedIf: Favor unless over if for negative conditions.
lib/dams/controller_helper.rb
Outdated
osf_data = (osf_data.is_a?(Time) || osf_data.is_a?(DateTime)) ? osf_data : Time.now | ||
end | ||
def agent_type(type) | ||
type = 'principalinvestigator' if type == 'principal investigator' || type == 'Principal Investigator' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/MultipleComparison: Avoid comparing a variable with multiple items in a conditional, use Array#include? instead.
lib/dams/controller_helper.rb
Outdated
end | ||
end | ||
end | ||
osf_data << {agent_type: 'Publisher', type: 'Organization', 'name': 'UC San Diego Library Digital Collections'} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceInsideHashLiteralBraces: Space inside { missing.
Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
lib/dams/controller_helper.rb
Outdated
relationships = JSON.parse(datum) | ||
relationships.each do |key, value| | ||
value.each do |v| | ||
osf_data << {agent_type: agent_type(key), type: 'Person', 'name': v} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceInsideHashLiteralBraces: Space inside { missing.
Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
lib/dams/controller_helper.rb
Outdated
dams_data = document['relationship_json_tesim'] | ||
osf_data =[] | ||
|
||
if !dams_data.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/NegatedIf: Favor unless over if for negative conditions.
lib/dams/controller_helper.rb
Outdated
end | ||
def osf_related_agents(document) | ||
dams_data = document['relationship_json_tesim'] | ||
osf_data =[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceAroundOperators: Surrounding space missing for operator =.
lib/dams/controller_helper.rb
Outdated
dams_data.each do |datum| | ||
date = JSON.parse(datum) | ||
if date['type'] == 'issued' | ||
d_date = date['beginDate']|| '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceAroundOperators: Surrounding space missing for operator ||.
lib/dams/controller_helper.rb
Outdated
end | ||
end | ||
end | ||
osf_data = (osf_data.blank?) ? osf_data << { 'name': 'UC San Diego Library' } : osf_data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/RedundantParentheses: Don't use parentheses around a method call.
Style/TernaryParentheses: Omit parentheses for ternary conditions.
lib/dams/controller_helper.rb
Outdated
relationships = JSON.parse(datum) | ||
relationships.each do |key, value| | ||
value.each do |v| | ||
osf_data << {"name": v} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceInsideHashLiteralBraces: Space inside { missing.
Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
unless dams_data.nil? | ||
dams_data.each do |datum| | ||
relationships = JSON.parse(datum) | ||
relationships.each do |key, value| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UnusedBlockArgument: Unused block argument - key. If it's necessary, use _ or _key as an argument name to indicate that it won't be used.
lib/dams/controller_helper.rb
Outdated
end | ||
def osf_contributors(document) | ||
dams_data = document['relationship_json_tesim'] | ||
osf_data =[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceAroundOperators: Surrounding space missing for operator =.
lib/dams/controller_helper.rb
Outdated
dams_data.each do |datum| | ||
title = JSON.parse(datum) | ||
osf_data = title['name'] ? title['name'] : '' | ||
osf_data += title['name'] && !title['translationVariant'].blank? ? ' : ' : '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rails/Present: Use title['translationVariant'].present? instead of !title['translationVariant'].blank?.
lib/dams/controller_helper.rb
Outdated
end | ||
def osf_title(document) | ||
dams_data= document['title_json_tesim'] | ||
osf_data='' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceAroundOperators: Surrounding space missing for operator =.
lib/dams/controller_helper.rb
Outdated
osf_data | ||
end | ||
def osf_title(document) | ||
dams_data= document['title_json_tesim'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceAroundOperators: Surrounding space missing for operator =.
end | ||
osf_data | ||
end | ||
def osf_title(document) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/CyclomaticComplexity: Cyclomatic complexity for osf_title is too high. [8/7]
Metrics/MethodLength: Method has too many lines. [18/15]
@@ -224,8 +224,15 @@ def osf_delete | |||
def osf_push | |||
@document = get_single_doc_via_search(1, {:q => "id:#{params[:id]}"} ) | |||
authorize! :show, @document | |||
document = ShareNotify::PushDocument.new("http://library.ucsd.edu/dc/collection/#{params[:id]}", osf_date(@document)) | |||
document = ShareNotify::PushDocument.new("http://library.ucsd.edu/dc/collection/#{params[:id]}") | |||
document.type = "DataSet" if @document["unit_code_tesim"].first == "rdcp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
lib/dams/controller_helper.rb
Outdated
date = JSON.parse(datum) | ||
if date['type'] == 'issued' | ||
d_date = date['beginDate'] || '' | ||
osf_data = DateTime.new(d_date.to_i,1,1) if d_date.match( '^\d{4}$' ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/DateTime: Prefer Date or Time over DateTime.
Rails/TimeZone: Do not use DateTime.new without zone. Use one of Time.zone.local, DateTime.current, DateTime.new.in_time_zone, DateTime.new.utc, DateTime.new.getlocal, DateTime.new.iso8601, DateTime.new.jisx0301, DateTime.new.rfc3339, DateTime.new.to_i, DateTime.new.to_f instead.
Layout/SpaceAfterComma: Space missing after comma.
Performance/RedundantMatch: Use =~ in places where the MatchData returned by #match will not be used.
Layout/SpaceInsideParens: Space inside parentheses detected.
lib/dams/controller_helper.rb
Outdated
type = 'principalinvestigator' if ['principal investigator', 'Principal Investigator'].include? type | ||
agent_dataset ||= YAML.safe_load(ERB.new(IO.read(Rails.root.join('config', 'share_agent_type.yml'))).result) | ||
share_agent_type = agent_dataset.fetch('key') | ||
type = (share_agent_type.include? type) ? type : 'Contributor' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UselessAssignment: Useless assignment to variable - type.
Style/TernaryParentheses: Omit parentheses for ternary conditions.
lib/dams/controller_helper.rb
Outdated
end | ||
end | ||
end | ||
osf_data = osf_data.blank? ? osf_data << { 'name': 'UC San Diego Library' } : osf_data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rails/Presence: Use osf_data.presence || osf_data << { 'name': 'UC San Diego Library' } instead of osf_data.blank? ? osf_data << { 'name': 'UC San Diego Library' } : osf_data.
lib/dams/controller_helper.rb
Outdated
end | ||
end | ||
end | ||
osf_data = (osf_data.is_a?(Time) || osf_data.is_a?(DateTime)) ? osf_data : Time.now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/TernaryParentheses: Omit parentheses for ternary conditions.
Rails/TimeZone: Do not use Time.now without zone. Use one of Time.zone.now, Time.current, Time.now.in_time_zone, Time.now.utc, Time.now.getlocal, Time.now.iso8601, Time.now.jisx0301, Time.now.rfc3339, Time.now.to_i, Time.now.to_f instead.
lib/dams/controller_helper.rb
Outdated
date = JSON.parse(datum) | ||
if date['type'] == 'issued' | ||
d_date = date['beginDate'] || '' | ||
osf_data = Time.utc(d_date.to_i, 1, 1) if d_date.match('^\d{4}$') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performance/RedundantMatch: Use =~ in places where the MatchData returned by #match will not be used.
lib/dams/controller_helper.rb
Outdated
def agent_type(type) | ||
type = 'principalinvestigator' if ['principal investigator', 'Principal Investigator'].include? type | ||
agent_dataset ||= YAML.safe_load(ERB.new(IO.read(Rails.root.join('config', 'share_agent_type.yml'))).result) | ||
(agent_dataset.fetch('key').include? type) ? type : 'Contributor' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/TernaryParentheses: Omit parentheses for ternary conditions.
lib/dams/controller_helper.rb
Outdated
end | ||
end | ||
end | ||
osf_data = osf_data.presence || osf_data << { 'name': 'UC San Diego Library' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingWhitespace: Trailing whitespace detected.
…ed push function. Refactor code to pass rubocop sytle check. Refactor the mapping code to use Rails.root.join to fetch config file. Refactor code to Array#include? for comparison and use to_s over string interpolation Refactored argument name and remove all trailing whitespace Refactor to use Time instead of DateTime and use Rails/Presence Refactor the regex and reduce the title method Complexity refactor for Style/TernaryParentheses Fixing failed tests.
0dcec0e
to
c9e0605
Compare
@mcritchlow I moved to this this PR as there are fair amount of refactoring for old code according to Rubocop. And the agent_type, mads_type was moved to config file as you suggested. |
@ucsdlib/developers - All Hound Rubocop check passed, please review. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
👍 |
1 similar comment
👍 |
Fixes #270
Local Checklist
master
branch?What does this PR do?
@ucsdlib/developers - please review