Skip to content

Commit

Permalink
BWF graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
johnf committed Jan 28, 2024
1 parent 2b0ede3 commit 5991507
Show file tree
Hide file tree
Showing 4 changed files with 387 additions and 235 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class Types::ItemBwfXmlType < Types::BaseObject
class Types::ItemBwfCsvType < Types::BaseObject
field :full_identifier, String, null: false
field :collection_identifier, String, null: false
field :item_identifier, String, null: false
field :xml, String, null: false
field :csv, String, null: false
field :created_at, GraphQL::Types::ISO8601DateTime
field :updated_at, GraphQL::Types::ISO8601DateTime
end
36 changes: 30 additions & 6 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ def item(full_identifier:)
collection.items.find_by(identifier: item_identifier)
end

field :item_bwf_xml, ItemBwfXmlType, 'Get the BWF XML for an item' do
field :item_bwf_csv, ItemBwfCsvType, 'Get the BWF XML for an item' do
argument :full_identifier, ID
argument :filename, String
end
def item_bwf_xml(full_identifier:)
def item_bwf_csv(full_identifier:, filename:)
raise(GraphQL::ExecutionError, 'Not authorised') unless context[:admin_authenticated]

collection_identifier, item_identifier = full_identifier.split('-')
Expand All @@ -40,16 +41,39 @@ def item_bwf_xml(full_identifier:)
item = collection.items.find_by(identifier: item_identifier)
raise(GraphQL::ExecutionError, 'Not found') unless item

warden = Warden::Proxy.new({}, Warden::Manager.new({})).tap do |i|
i.set_user(context[:current_user], scope: :user)
desc = [
'# Notes',
'',
"Reference: https://catalog.paradisec.org.au/repository/#{collection.identifier}/#{item.identifier}",
]

unless item.subject_languages.empty?
desc << "Language: #{item.subject_languages.first.name}\" #{item.subject_languages.first.code}"
end

desc << "Country: #{item.countries.first.code}" unless item.countries.empty?
desc << "Description: #{item.description}"

bwf = {
'FileName' => filename,
'Description' => desc.join('\n').truncate(256),
'Originator' => item.collector_name,
'OriginationDate' => item.originated_on,
'BextVersion' => 1,
'CodingHistory' => 'A=PCM,F=96000,W=24,M=stereo,T=Paragest Pipeline'
# 'TBA' => @item.ingest_notes
}

csv = CSV.generate(headers: true) do |c|
c << bwf.keys
c << bwf.values
end
item_renderer = ItemsController.renderer.new('warden' => warden)

{
full_identifier: item.full_identifier,
collection_identifier: collection.identifier,
item_identifier: item.identifier,
xml: item_renderer.render('items/show_bwf', formats: [:xml], assigns: { item: }),
csv:,
created_at: item.created_at,
updated_at: item.updated_at
}
Expand Down
19 changes: 0 additions & 19 deletions app/views/items/show_bwf.xml.haml

This file was deleted.

Loading

0 comments on commit 5991507

Please sign in to comment.