Skip to content

Commit

Permalink
Merge branch 'ready_set_action' of github.com:notch8/ams into ready_s…
Browse files Browse the repository at this point in the history
…et_action
  • Loading branch information
orangewolf committed Aug 26, 2022
2 parents f2eb131 + 6f2d8b3 commit df36f1b
Show file tree
Hide file tree
Showing 46 changed files with 1,193 additions and 211 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/ams-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CI RSpec Tests

on: [push, pull_request]

jobs:
tests:
name: CI
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install Redis
run: sudo apt-get install -y redis-tools redis-server

- name: Install libcurl4-openssl-dev for Curb Gem
run: sudo apt-get install libcurl4-openssl-dev

- name: Setup Ruby and Install RubyGems
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.5.3
bundler-cache: true

- name: Install JDK
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '11'

- name: Install Node
shell: bash -l -eo pipefail {0}
run: nvm install 12.9.0

- name: Install Chrome Browser
run: google-chrome-stable --headless --disable-gpu --no-sandbox --remote-debugging-port=9222 http://localhost &

- name: Prepare Test Environment
run: |
cp config/travis/solr_wrapper_test.yml config/solr_wrapper_test.yml
cp config/travis/fcrepo_wrapper_test.yml config/fcrepo_wrapper_test.yml
export DISPLAY=:99.0
RAILS_ENV=test bundle exec rake db:environment:set db:create db:migrate --trace
RAILS_ENV=test npm install yarn
RAILS_ENV=test yarn --ignore-engines install
RAILS_ENV=test bundle exec rake webpacker:compile
- name: Run Rspec specs using CI config
run: bundle exec rake ci
59 changes: 0 additions & 59 deletions .travis.yml

This file was deleted.

3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ gem 'bootstrap-multiselect-rails'
gem 'hyrax-batch_ingest', git: 'https://github.com/samvera-labs/hyrax-batch_ingest'
gem 'pbcore', '~> 0.3.0'
gem 'curb'
gem 'sony_ci_api', '~> 0.2.1'
# gem 'sony_ci_api', '~> 0.2.1'
gem 'sony_ci_api', github: 'WGBH-MLA/sony_ci_api_rewrite', branch: 'v0.1'
# gem 'hyrax-iiif_av', '>= 0.2.0'
# gem 'hyrax-iiif_av', github: 'samvera-labs/hyrax-iiif_av', branch: 'hyrax_master'
gem 'webpacker'
Expand Down
14 changes: 12 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ GIT
rails (>= 5.1.6)
rdf (>= 2.0.2, < 4.0)
simple_form
GIT
remote: https://github.com/WGBH-MLA/sony_ci_api_rewrite.git
revision: f98576c7060e11cc50da0f67cf4642d2b4372517
branch: v0.1
specs:
sony_ci_api (0.1.0)
activesupport
faraday (~> 0.12)
faraday_middleware

GIT
remote: https://github.com/samvera-labs/hyrax-batch_ingest
Expand Down Expand Up @@ -1001,7 +1010,7 @@ GEM
temple (0.8.2)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
thor (0.20.3)
thor (1.1.0)
thread_safe (0.3.6)
tilt (2.0.10)
tinymce-rails (4.9.11)
Expand Down Expand Up @@ -1114,7 +1123,8 @@ DEPENDENCIES
sidekiq
simple_form (= 5.0.0)
solr_wrapper (~> 2.1)
sony_ci_api (~> 0.2.1)
sony_ci_api!
sqlite3 (= 1.3.13)
turbolinks (~> 5)
uglifier (>= 1.3.0)
web-console (>= 3.3.0)
Expand Down
1 change: 0 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//=
//= require turbolinks
//
// Required by Blacklight
Expand Down
103 changes: 103 additions & 0 deletions app/assets/javascripts/sony_ci/find_media.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
class FindSonyCiMediaBehavior
# Select for the search button
searchButtonSelector: '#find_sony_ci_media #search'
# Selector for the div that displays the feedback messages.
feedbackSelector: '#find_sony_ci_media #feedback'
# Selector for the text inputs that have the Sony Ci IDs.
sonyCiIdInputSelector: 'input.asset_sonyci_id'
# Selector for the button to add new Sony Ci IDs
addNewSonyCiIdButtonSelector: '.form-group.asset_sonyci_id button.add'

constructor: (@query) ->

# searchHandler - search Sony Ci for records matching the query and provide
# feedback to the user.
searchHandler: (event) =>
event.preventDefault()
@giveFeedback('searching...')
$.ajax(
context: this,
url: "/sony_ci/api/find_media",
data: { query: @query }
).done ( response ) ->
@giveFeedback(response.length + ' records found')
if response.length > 0
@addFoundRecords(response)

# fetchFilenameHandler - fetches the filename from Sony Ci given a Sony Ci ID
# from an input field.
fetchFilenameHandler: ->
$.ajax(
url: "/sony_ci/api/get_filename",
context: this,
data: { sony_ci_id: $(this).val() }
).done(( response ) ->
$(this).parent().find('.sony_ci_filename').text(response['name'])
).fail(( response ) ->
$(this).parent().find('.sony_ci_filename').text("Could not find Sony Ci record")
)

# Adds a message to give the user feedback on what's happening.
# The element is hidden at first, so set the text and reveal it.
giveFeedback: (msg) =>
$(@feedbackSelector).text(msg).show()

addFoundRecords: (records) =>
# Map the sonyci_id text inputs to their values.
existingSonyCiIds = $(@sonyCiIdInputSelector).map (_, element) ->
$(element).val()

# Map the found records to just the Sony Ci IDs.
# This is not a jQuery.map function, so the index is the 2nd arg instead of
# the first, like in the map function above.
foundSonyCiIds = records.map (record, _) ->
record['id']

# Subtract the existing Sony Ci Ids from the found Sony Ci IDs.
newSonyCiIds = $(foundSonyCiIds).not(existingSonyCiIds).get();

# For each of the new found Sony Ci IDs...
newSonyCiIds.forEach (sonyCiId, index) =>

# Insert the found Sony Ci ID into the last text input and trigger the \
# change() event, because just setting val(x) won't do it.
$(@sonyCiIdInputSelector).last().val(sonyCiId).change()

# If we have more Sony Ci IDs to add
if newSonyCiIds.length > index
# Add another Sony Ci ID field it by clicking the "Add another..."
# button.
$(@addNewSonyCiIdButtonSelector).click()

# Hyrax will simply copy and append the last element, but we don't want
# values for Sony Ci ID or Filename there, so clear them out.
$(@sonyCiIdInputSelector).last().val('')
$('.sony_ci_filename').last().text('')

# Finally, add the handler to the change() event of the input.
$(@sonyCiIdInputSelector).last().change @fetchFilenameHandler

# apply - Attaches handlers to events.
apply: ->
# Attach the search handler to the click event of the search button.
$(@searchButtonSelector).click @searchHandler
# Attach the fetchFilenameHanlder to the change event of the inputs.
$(@sonyCiIdInputSelector).change @fetchFilenameHandler

# When the page loads...
# NOTE: could not get $(document).on('turbolinks:load') to work on initial page
# load; reverting to $(document).ready, which seems to work more consistently.
$(document).ready ->
# This regex matches the 3rd URL segment which should be the GUID.
guid_query_str = window.location.href.match(/concern\/assets\/(.*)\//)[1]

# Create the behavior object, passing in the GUID as the query string.
# NOTE: Sony Ci API has a 20 character limit on it's search terms, so let's
# just pass in the last 20 characters, which will be more unique than the 1st
# 20 chars due to the common prefix of "cpb-aacip-". Supposedly, Michael Potts
# from Sony Ci said that quoted search queries have no such limit, but I could
# not get that to work, nor is it mentioned in the Ci API docs anywhere.
behavior = new FindSonyCiMediaBehavior(guid_query_str.substr(-20))

# apply the behavior
behavior.apply()
38 changes: 38 additions & 0 deletions app/controllers/api/assets_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module API
class AssetsController < APIController
# Authenticate user before all actions.
# NOTE: For Basic HTTP auth to work:
# * the `http_authenticatable` config option for Devise must be set to true
# (see config/initializers/devise.rb).
# * The Authorization request header must be set to "Basic {cred}" where
# {cred} is the base64 encoded username:password.
# TODO: Move authn into base APIController class and make modifications so
# that the SonyCi::APIController will work with authn, which needs to be
# done.
before_action do
authenticate_user!
end


def show
respond_to do |format|
format.json { render json: pbcore_json }
format.xml { render xml: pbcore_xml }
end
end

private

def pbcore_json
@pbcore_json ||= Hash.from_xml(pbcore_xml).to_json
end

def pbcore_xml
@pbcore_xml ||= solr_doc.export_as_pbcore
end

def solr_doc
@solr_doc ||= SolrDocument.find(params[:id])
end
end
end
12 changes: 12 additions & 0 deletions app/controllers/api_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
class APIController < ActionController::API
# Gives us respond_to in controller actions which we use to respond with
# JSON or PBCore XML.
include ActionController::MimeResponds

# Common API features here, e.g. auth.
rescue_from ActiveFedora::ObjectNotFoundError, with: :not_found

private

def not_found(error)
# TODO: render errors in the proper format: xml or json.
render text: "Not Found", status: 404
end
end
Loading

0 comments on commit df36f1b

Please sign in to comment.