forked from WGBH-MLA/ams
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into ready_set_action
- Loading branch information
Showing
46 changed files
with
1,193 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.