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

Goobi integration #35

Merged
merged 13 commits into from
Nov 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ config/certs
.rvmrc
.bundle
.ruby-*
coverage/*
workflow_service.log*
102 changes: 95 additions & 7 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-01-14 19:01:00 -0800 using RuboCop version 0.35.1.
# on 2016-11-01 16:19:24 -0700 using RuboCop version 0.44.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -11,40 +11,115 @@ Lint/HandleExceptions:
Exclude:
- 'lib/tasks/rspec.rake'

# Offense count: 2
Metrics/AbcSize:
Max: 29

# Offense count: 7
# Configuration parameters: CountComments.
Metrics/BlockLength:
Max: 120

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 161
Max: 300

# Offense count: 1
Metrics/CyclomaticComplexity:
Max: 7

# Offense count: 2
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
# URISchemes: http, https
Metrics/LineLength:
Max: 286

# Offense count: 3
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 17

# Offense count: 1
Metrics/PerceivedComplexity:
Max: 8

# Offense count: 8
Style/AccessorMethodName:
Exclude:
- 'lib/update_marc_record_service.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: prefer_alias, prefer_alias_method
Style/Alias:
Exclude:
- 'config/boot.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
# FunctionalMethods: let, let!, subject, watch
# IgnoredMethods: lambda, proc, it
Style/BlockDelimiters:
Exclude:
- 'old_cap/Capfile'

# Offense count: 2
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
Exclude:
- 'config/boot.rb'

# Offense count: 4
# Configuration parameters: Exclude.
# Offense count: 7
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'config/boot.rb'
- 'lib/dor_services_app.rb'
- 'lib/goobi.rb'
- 'lib/grape_overrides.rb'
- 'lib/registration_response.rb'
- 'lib/service_item.rb'
- 'lib/update_marc_record_service.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty_lines, no_empty_lines
Style/EmptyLinesAroundBlockBody:
Exclude:
- 'config/environments/production.rb'
- 'config/environments/stage.rb'

# Offense count: 40
# Offense count: 55
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
Style/HashSyntax:
Enabled: false
Exclude:
- 'config/deploy.rb'
- 'lib/dor_services_app.rb'
- 'lib/goobi.rb'
- 'lib/grape_overrides.rb'
- 'lib/tasks/rspec.rake'
- 'old_cap/Capfile'
- 'spec/dor_services_app_spec.rb'
- 'spec/registration_response_spec.rb'
- 'spec/service_item_spec.rb'
- 'spec/spec_helper.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: SupportedStyles, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
Style/IndentArray:
EnforcedStyle: consistent

# Offense count: 1
# Cop supports --auto-correct.
Expand All @@ -56,3 +131,16 @@ Style/MultilineBlockLayout:
# Cop supports --auto-correct.
Style/NumericLiterals:
MinDigits: 11

# Offense count: 2
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: snake_case, camelCase
Style/VariableName:
Exclude:
- 'spec/spec_helper.rb'

# Offense count: 2
# Cop supports --auto-correct.
Style/ZeroLengthPredicate:
Exclude:
- 'lib/update_marc_record_service.rb'
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ source 'https://rubygems.org'
gem 'grape', '~> 0.14'
gem 'rack-test'

gem 'faraday'
gem 'rest-client'

# DLSS/domain-specific dependencies
gem 'dor-services', '~> 5.12'
gem 'activesupport', '~> 4.2'
Expand All @@ -16,10 +19,14 @@ end

group :test, :development do
gem 'rspec'
gem 'coveralls', require: false
gem 'simplecov'
gem 'equivalent-xml'
gem 'fakeweb'
gem 'rack-console'
gem 'rubocop'
gem 'rubocop-rspec'
gem 'equivalent-xml'
end

group :deployment do
Expand Down
31 changes: 30 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
ast (2.3.0)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
Expand Down Expand Up @@ -50,6 +51,12 @@ GEM
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
confstruct (0.2.7)
coveralls (0.8.12)
json (~> 1.8)
simplecov (~> 0.11.0)
term-ansicolor (~> 1.3)
thor (~> 0.19.1)
tins (~> 1.6.0)
daemons (1.2.4)
deprecation (1.0.0)
activesupport
Expand Down Expand Up @@ -182,6 +189,9 @@ GEM
activesupport
nokogiri (>= 1.4.2)
solrizer (~> 3.3)
parser (2.3.1.4)
ast (~> 2.2)
powerpack (0.1.1)
rack (1.6.4)
rack-accept (0.4.5)
rack (>= 0.4)
Expand All @@ -192,6 +202,7 @@ GEM
rack (>= 1.0.0)
rack-test (0.6.3)
rack (>= 1.0)
rainbow (2.1.0)
rake (10.5.0)
rdf (1.99.1)
link_header (~> 0.0, >= 0.0.8)
Expand Down Expand Up @@ -235,9 +246,18 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
rubocop (0.44.1)
parser (>= 2.3.1.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
rubocop-rspec (1.8.0)
rubocop (>= 0.42.0)
ruby-cache (0.3.0)
ruby-graphviz (1.2.2)
ruby-oci8 (2.2.1)
ruby-progressbar (1.8.1)
rubydora (1.9.0)
activemodel
activesupport
Expand Down Expand Up @@ -268,15 +288,19 @@ GEM
mods (~> 2.0, >= 2.0.2)
stomp (1.4.3)
systemu (2.6.5)
term-ansicolor (1.4.0)
tins (~> 1.0)
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.5)
tins (1.6.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
uber (0.0.15)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.2)
unicode-display_width (1.1.1)
uuidtools (2.1.5)
validatable (1.6.7)
virtus (1.0.5)
Expand All @@ -299,18 +323,23 @@ DEPENDENCIES
capistrano
capistrano-bundler
capistrano-passenger
coveralls
dlss-capistrano
dor-services (~> 5.12)
equivalent-xml
fakeweb
faraday
grape (~> 0.14)
lyber-core (>= 2.0.2)
rack-console
rack-test
rest-client
rspec
rubocop
rubocop-rspec
ruby-oci8
simplecov
workflow-archiver (~> 2.0)

BUNDLED WITH
1.13.5
1.13.6
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Build Status](https://travis-ci.org/sul-dlss/dor-services-app.png?branch=master)](https://travis-ci.org/sul-dlss/dor-services-app)
[![Build Status](https://travis-ci.org/sul-dlss/dor-services-app.png?branch=master)](https://travis-ci.org/sul-dlss/dor-services-app)
[![Coverage Status](https://coveralls.io/repos/github/sul-dlss/dor-services-app/badge.svg?branch=master)](https://coveralls.io/github/sul-dlss/dor-services-app?branch=master)

# DOR Services App

Expand Down Expand Up @@ -43,6 +44,10 @@ You should now be ready to run `bundle install`. Note that DOR Services App requ
To run the tests:

`bundle exec rake`

To run rubocop separately (auto run with tests):

`bundle exec rake rubocop`

## Console

Expand Down
2 changes: 2 additions & 0 deletions config/boot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

require 'grape_overrides'
require 'dor_services_app'
require 'service_item'
require 'goobi'
require 'registration_response'
require 'update_marc_record_service'

Expand Down
2 changes: 1 addition & 1 deletion config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
set :stages, %w(dev staging production)

set :linked_dirs, %w(log config/environments config/certs)
set :linked_files, %w{bin/write_marc_record}
set :linked_files, %w(bin/write_marc_record)

set :bundle_env_variables, :ld_library_path => '/usr/lib/oracle/11.2/client64/lib:$LD_LIBRARY_PATH'

Expand Down
12 changes: 10 additions & 2 deletions config/environments/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@
release do
symphony_path './'
write_marc_script 'bin/write_marc_record_test'
purl_base_uri "http://purl.stanford.edu"
purl_base_uri 'http://purl.stanford.edu'
end

goobi do
url 'http://localhost:9292'
dpg_workflow_name 'goobiWF' # the dpg workflow name to put into the XML
default_goobi_workflow_name 'Example_Workflow' # the default goobi workflow name to use if none found in the object
max_tries 3 # the number of attempts to retry service calls before failing
max_sleep_seconds 20 # max sleep seconds between tries
base_sleep_seconds 2 # base sleep seconds between tries
end

end

Dor::WorkflowArchiver.config.configure do
Expand Down
9 changes: 7 additions & 2 deletions lib/dor_services_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def proxy_rest_client_response(response)
end

get '/objects/:druid/content/:filename', requirements: { filename: /.*/ } do
query_string = URI.encode_www_form({ version: params[:version].to_s })
query_string = URI.encode_www_form(version: params[:version].to_s)
encoded_filename = URI.encode(params[:filename])
url = "objects/#{params[:druid]}/content/#{encoded_filename}?#{query_string}"
sdr_response = sdr_client[url].get { |response, _request, _result| response }
Expand Down Expand Up @@ -207,7 +207,12 @@ def load_item
post '/update_marc_record' do
Dor::UpdateMarcRecordService.new(@item).update
end


post '/notify_goobi' do
response = Dor::Goobi.new(@item).register
proxy_rest_client_response(response)
end

resource :versions do
post do
@item.open_new_version
Expand Down
37 changes: 37 additions & 0 deletions lib/goobi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Dor
class Goobi < ServiceItem
def register
handler = proc do |exception, attempt_number, _total_delay|
if attempt_number >= Dor::Config.goobi.max_tries
throw :error, :message => "#{exception.class} on goobi notification web service call #{attempt_number} for #{@druid_obj.id}", :status => 500
end
end

# rubocop:disable Metrics/LineLength
with_retries(max_tries: Dor::Config.goobi.max_tries, handler: handler, base_sleep_seconds: Dor::Config.goobi.base_sleep_seconds, max_sleep_seconds: Dor::Config.goobi.max_sleep_seconds) do |_attempt|
response = RestClient.post(Dor::Config.goobi.url, xml_request, :content_type => 'application/xml') { |resp, _request, _result| resp }
response
end
# rubocop:enable Metrics/LineLength
end

def xml_request
<<-END
<stanfordCreationRequest>
<objectId>#{@druid_obj.id}</objectId>
<objectType>#{object_type}</objectType>
<sourceID>#{@druid_obj.source_id.encode(:xml => :text)}</sourceID>
<title>#{@druid_obj.label.encode(:xml => :text)}</title>
<contentType>#{content_type}</contentType>
<project>#{project_name.encode(:xml => :text)}</project>
<catkey>#{ckey}</catkey>
<barcode>#{barcode}</barcode>
<collectionId>#{collection_id}</collectionId>
<collectionName>#{collection_name.encode(:xml => :text)}</collectionName>
<sdrWorkflow>#{Dor::Config.goobi.dpg_workflow_name}</sdrWorkflow>
<goobiWorkflow>#{goobi_workflow_name}</goobiWorkflow>
</stanfordCreationRequest>
END
end
end
end
Loading