Skip to content
This repository has been archived by the owner on Mar 24, 2020. It is now read-only.

Fixes #251- Implement the delete function and migrate to SHARE versio… #426

Merged
merged 2 commits into from
Apr 19, 2018

Conversation

hweng
Copy link
Contributor

@hweng hweng commented Mar 29, 2018

…n 2 API.

Fixes #251 ; refs #251

Changes proposed in this pull request:

  • Migrated to SHARE version 2 API.
  • Implemented delete a record from SHARE function.

@ucsdlib/developers - please review

}
@route = "#{share_config.fetch('host')}api/v2/normalizeddata/"
@body = ShareNotify::Graph.new(document).to_share_v2.to_json
@response = with_timeout { HTTParty.post(@route, body: @body, headers: @headers)}

Choose a reason for hiding this comment

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

Layout/SpaceInsideBlockBraces: Space missing inside }.

'Authorization' => "Bearer #{share_config.fetch('token')}",
'Content-Type' => 'application/vnd.api+json'
}
@route = "#{share_config.fetch('host')}api/v2/normalizeddata/"

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.

@headers = {
'Authorization' => "Bearer #{share_config.fetch('token')}",
'Content-Type' => 'application/vnd.api+json'
}

Choose a reason for hiding this comment

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

Layout/IndentHash: Indent the right brace the same as the start of the line where the left brace is.

osf_contributors(@document).each do |contributor|
document.add_contributor(contributor)
end

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.

document.title = osf_title(@document)
document.delete
share_upload(document)
redirect_to dams_collection_path(params[:id]), notice: "Your record has been deleted from OSF Share."

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.

@@ -205,33 +205,44 @@ def osf_data
render :json => @document
end

def osf_delete
@document = get_single_doc_via_search(1, {:q => "id:#{params[:id]}"} )

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.
Style/BracesAroundHashParameters: Redundant curly braces around a hash parameter.
Style/HashSyntax: Use the new Ruby 1.9 hash syntax.
Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
Layout/SpaceInsideParens: Space inside parentheses detected.


def share_config
env = Rails.env || 'test'
@config ||= YAML.safe_load(ERB.new(IO.read(File.join(Rails.root, 'config', 'share_notify.yml'))).result)[env].with_indifferent_access

Choose a reason for hiding this comment

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

Rails/FilePath: Please use Rails.root.join('path', 'to') instead.

def with_timeout(&_block)
Timeout.timeout(5) { yield }
end
def share_upload(document)

Choose a reason for hiding this comment

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

Layout/IndentationWidth: Use 2 (not 0) spaces for rails indentation.

collection_names.collect! { |name| "\"#{solr_escape(name)}\"" }
solr_param_q = collection_names.join ' OR '
solr_params = { q: "type_tesim:Collection AND title_tesim:(#{solr_param_q})", rows: collection_names.count }
cols_response, col_documents = get_search_results(solr_params, spellcheck: 'false')

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 - col_documents. Use _ or _col_documents as a variable name to indicate that it won't be used.

relatedResourceData = collectionDoc['related_resource_json_tesim'] unless collectionDoc.nil?
next if relatedResourceData.nil?
relatedResourceData.each do |datum|
relatedResource = JSON.parse(datum)

Choose a reason for hiding this comment

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

Naming/VariableName: Use snake_case for variable names.

collectionDoc = get_single_doc_via_search(1, q: "id:#{collection['id']}")
relatedResourceData = collectionDoc['related_resource_json_tesim'] unless collectionDoc.nil?
next if relatedResourceData.nil?
relatedResourceData.each do |datum|

Choose a reason for hiding this comment

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

Lint/ShadowingOuterLocalVariable: Shadowing outer local variable - datum.

end
end
collectionDoc = get_single_doc_via_search(1, q: "id:#{collection['id']}")
relatedResourceData = collectionDoc['related_resource_json_tesim'] unless collectionDoc.nil?

Choose a reason for hiding this comment

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

Naming/VariableName: Use snake_case for variable names.

end
end
end
collectionDoc = get_single_doc_via_search(1, q: "id:#{collection['id']}")

Choose a reason for hiding this comment

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

Naming/VariableName: Use snake_case for variable names.

if !collectionData.nil? and collectionData.length > 0
collectionData.each do |datum|
collectionData = @document['collection_json_tesim']
@collectionDocArray = []

Choose a reason for hiding this comment

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

Naming/VariableName: Use snake_case for variable names.

@collectionDocArray = Array.new
if !collectionData.nil? and collectionData.length > 0
collectionData.each do |datum|
collectionData = @document['collection_json_tesim']

Choose a reason for hiding this comment

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

Naming/VariableName: Use snake_case for variable names.

facet_collection_names = []
@facet_collections = @facet_collection_resp[0].facet_counts['facet_fields']['collection_sim']
if @facet_collections.present?
@facet_collections.each_slice(2) do |collectionName, *_|

Choose a reason for hiding this comment

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

Naming/VariableName: Use snake_case for variable names.

def share_upload(document)
@headers =
{
'Authorization' => "Bearer #{share_config.fetch('token')}",

Choose a reason for hiding this comment

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

Layout/IndentHash: Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is.

redirect_to dams_collection_path(params[:id]), notice: "Your record has been pushed to OSF Share."
else
redirect_to dams_collection_path(params[:id]), alert: "Your record is not valid."
end
end

private
def share_upload(document)
@headers =

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.

'Authorization' => "Bearer #{share_config.fetch('token')}",
'Content-Type' => 'application/vnd.api+json'
}
@route = "#{share_config.fetch('host')}api/v2/normalizeddata/"

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.

@VivianChu
Copy link
Member

👍

1 similar comment
@lsitu
Copy link
Member

lsitu commented Apr 5, 2018

👍

@hweng
Copy link
Contributor Author

hweng commented Apr 19, 2018

@ucsdlib/developers Can anyone merge this PR please? Another ticket #270 is depending on it. Thanks!

@mcritchlow mcritchlow merged commit 84da581 into develop Apr 19, 2018
@mcritchlow mcritchlow deleted the feature/update_share branch April 19, 2018 21:59
@hweng
Copy link
Contributor Author

hweng commented Apr 19, 2018

Thank you @ucsdlib/developers for reviewing and @mcritchlow for merged it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants