Skip to content

Commit

Permalink
[F] Improve project exportation / Bag-It packaging
Browse files Browse the repository at this point in the history
* Remove remaining simple text files, inline into respective metadata
* Add created_at / updated_at timestamps to various metadata
* Expose external video service url for vimeo / youtube in metadata
* Enumerate text and resource ids in top-level project metadata
* Bump manifold compilation version to 1.2.0 to signify changes
  • Loading branch information
scryptmouse authored and zdavis committed Feb 5, 2024
1 parent 17058f4 commit f2e8ce4
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 32 deletions.
35 changes: 28 additions & 7 deletions api/app/models/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,42 @@ def vimeo?
external_video? && external_type == "vimeo"
end

def external_video_service_url
if youtube?
URI::HTTPS.build(host: "www.youtube.com", path: "/watch", query: { v: external_id }.to_query).to_s
elsif vimeo?
URI.join("https://vimeo.com/", external_id).to_s
end
end

def external_video_packaging_metadata
return {} unless external_video?

slice(:sub_kind, :external_id, :external_type, :external_video_service_url)
end

# @return [{ Symbol => Object }]
def packaging_metadata
simplified = {
title: title_plaintext,
description: description_plaintext,
caption: caption_plaintext,
tags: tag_list,
}.compact

metadata.with_indifferent_access
.merge(id: id)
.merge(slug: slug)
.merge(title: title_plaintext)
.merge(description: description_plaintext)
.merge(caption: caption_plaintext)
.merge(slice(:id, :slug, :kind, :external_url, :created_at, :updated_at))
.merge(**simplified)
.merge(external_video_packaging_metadata)
end

private

def parse_and_set_external_id!
outcome = Resources::ExtractExternalVideoId.run external_id: external_id,
external_type: external_type
outcome = Resources::ExtractExternalVideoId.run(
external_id: external_id,
external_type: external_type
)

if outcome.valid?
self.external_id = outcome.result
Expand Down
4 changes: 1 addition & 3 deletions api/app/models/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,8 @@ def titles_packaging_metadata
# @return [{ Symbol => Object }]
def packaging_metadata
metadata.with_indifferent_access
.merge(id: id)
.merge(slug: slug)
.merge(slice(:id, :slug, :publication_date, :created_at, :updated_at))
.merge(titles: titles_packaging_metadata.compact)
.merge(slice(:publication_date))
.merge(collaborators: collaborator_packaging_metadata)
end

Expand Down
4 changes: 3 additions & 1 deletion api/app/services/packaging/bag_it_spec/compilation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Packaging
module BagItSpec
# The BagIt spec compilation namespace
Expand All @@ -6,7 +8,7 @@ module Compilation
TMP_ROOT = Rails.root.join("tmp", "bagit")

# The compilation pipeline version.
VERSION = Gem::Version.new("1.1.0").freeze
VERSION = Gem::Version.new("1.2.0").freeze
end
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Packaging
module BagItSpec
module Resources
Expand All @@ -24,7 +26,6 @@ class AttachmentProxy
def build_entries(builder)
builder.attachment! :file, root.join(original_filename), uploaded_file
builder.json! :metadata, root.join("metadata.json"), metadata
builder.simple! :mimetype, root.join("mimetype"), content_type
end

private
Expand Down
14 changes: 0 additions & 14 deletions api/app/services/packaging/bag_it_spec/resources/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ class Proxy

include Packaging::BagItSpec::BuildsEntries

# Attributes that should be copied to files
# of the same name in the top-level {#root}.
#
# @see #build_entries
ATTRIBUTE_ENTRIES = %i[
kind sub_kind
external_id external_type external_url
].freeze

param :resource, Types.Instance(::Resource)

delegate :slug, to: :resource
Expand Down Expand Up @@ -61,12 +52,7 @@ def each_entry(include_attachments: true)
end

def build_entries(builder)
ATTRIBUTE_ENTRIES.each do |attr|
builder.simple! attr, root.join(attr.to_s), resource[attr]
end

builder.json! :metadata, root.join("metadata.json"), resource.packaging_metadata
builder.json! :tags, root.join("tags.json"), resource.tag_list
end

private
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Packaging
module Preservation
class ExportProjectMetadata < ActiveInteraction::Base
Expand All @@ -16,8 +18,12 @@ def execute
store :slug
store :description
store :publication_date
store :created_at
store :updated_at
store :metadata
store :collaborators, :collaborator_packaging_metadata
store :text_ids
store :resource_ids
end

private
Expand Down
5 changes: 5 additions & 0 deletions api/app/services/utility/index_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ def each_value
end
end

# @param [#to_s] key
def include?(key)
cache.key? key.to_s
end

# @return [<Object>]
def to_a
each_value.to_a
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Packaging::BagItSpec::Resources::AttachmentProxy do
Expand All @@ -8,5 +10,9 @@

subject { attachment_proxy }

it { is_expected.to have(3).entries }
it { is_expected.to have(2).entries }

its(:entries) { are_expected.to include :file }

its(:entries) { are_expected.to include :metadata }
end
17 changes: 12 additions & 5 deletions api/spec/services/packaging/bag_it_spec/resources/proxy_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Packaging::BagItSpec::Resources::Proxy do
Expand All @@ -7,17 +9,22 @@

let(:attachment_proxy_count) { 3 }

let(:attachment_entry_count) { 3 }
let(:attachment_entry_count) { 2 }

# metadata.json
# tags.json
let(:arbitrary_entry_count) { 2 }
let(:arbitrary_entry_count) { 1 }

let(:proxy_entry_count) { described_class::ATTRIBUTE_ENTRIES.length + arbitrary_entry_count }
let(:proxy_entry_count) { arbitrary_entry_count }
let(:expected_entry_count) { proxy_entry_count + (attachment_proxy_count * attachment_entry_count) }

it "has the expected number of attachment proxies" do
expect(proxy).to have(3).attachments
expect(proxy).to have(attachment_proxy_count).attachments
end

it "has just a single specific entry for metadata" do
expect(proxy.entries).to have(1).entry

expect(proxy.entries).to include :metadata
end

it "has the expected count of entries" do
Expand Down

0 comments on commit f2e8ce4

Please sign in to comment.