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

PI format not required #938

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion app/forms/hyrax/physical_instantiation_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PhysicalInstantiationForm < Hyrax::Forms::WorkForm
:keyword, :license, :rights_statement, :publisher, :subject, :identifier, :based_near, :related_url,
:bibliographic_citation, :source]
self.required_fields -= [:creator, :keyword, :rights_statement]
self.required_fields += [:format, :location, :media_type, :holding_organization]
self.required_fields += [:location, :media_type, :holding_organization]

self.single_valued_fields = [:title]

Expand Down
2 changes: 1 addition & 1 deletion app/forms/physical_instantiation_resource_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PhysicalInstantiationResourceForm < Hyrax::Forms::ResourceForm(PhysicalIns

attr_accessor :controller, :current_ability

self.required_fields += [:format, :location, :media_type, :holding_organization]
self.required_fields += [:location, :media_type, :holding_organization]

self.single_valued_fields = [:title]

Expand Down
1 change: 0 additions & 1 deletion app/models/physical_instantiation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class PhysicalInstantiation < ActiveFedora::Base

before_save :save_instantiation_admin_data

validates :format, presence: { message: 'Your work must have a format.' }
validates :location, presence: { message: 'Your work must have a location.' }
validates :media_type, presence: { message: 'Your work must have a media type.' }
validates :duration, format: { with: AMS::TimeCodeService.regex, allow_blank: true, message: "Invalid format for duration. Use HH:MM:SS, H:MM:SS, MM:SS, or M:SS" }
Expand Down
1 change: 0 additions & 1 deletion app/models/physical_instantiation_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def aapb_valid?

def aapb_invalid_message
msg = []
msg << "#{self.id} format is required" unless format.present?
msg << "#{self.id} location is required" unless location.present?
msg << "#{self.id} media_type is required" unless media_type.present?
msg << "#{self.id} holding_organization is required" unless holding_organization.present?
Expand Down
4 changes: 2 additions & 2 deletions app/parsers/pbcore_xml_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ def set_objects(file, index)
def instantiation_rows(instantiations, xml_asset, asset, asset_id)
xml_records = []
instantiations.each.with_index do |inst, i|
instantiation_class = 'PhysicalInstantiationResource' if inst.physical
instantiation_class ||= 'DigitalInstantiationResource' if inst.digital
instantiation_class = 'PhysicalInstantiationResource' if inst.nil? || inst.physical
instantiation_class ||= 'DigitalInstantiationResource' if inst&.digital
next unless instantiation_class
xml_record = AAPB::BatchIngest::PBCoreXMLMapper.new(inst.to_xml).send("#{instantiation_class.to_s.underscore}_attributes").merge!({ pbcore_xml: inst.to_xml, skip_file_upload_validation: true })
# Find members of the asset that have the same class and local identifier. If no asset, then no digital instantiation can exist
Expand Down
8 changes: 8 additions & 0 deletions spec/factories/physical_instantiation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
local_instantiation_identifier { [ "1234" ] }
location { "Test location" }
media_type { "Test media_type" }

trait :without_format do
format { nil }
end
end

factory :minimal_physical_instantiation, class: PhysicalInstantiation do
Expand All @@ -16,5 +20,9 @@
annotation { ["Minimal annotation"] }
location { "Minimal location" }
media_type { "Minimal media_type" }

trait :without_format do
format { nil }
end
end
end
7 changes: 6 additions & 1 deletion spec/models/physical_instantiation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@
expect(physical_instantiation.resource.dump(:ttl)).to match(/ebucore#hasFormat/)
expect(physical_instantiation.format.include?("Test format")).to be true
end
end
it "handles absence of format gracefully" do
physical_instantiation.format = nil
expect(physical_instantiation.resource.dump(:ttl)).not_to match(/ebucore#hasFormat/)
expect(physical_instantiation.format).to be_nil
end
end

context "standard" do
let(:physical_instantiation) { FactoryBot.build(:physical_instantiation) }
Expand Down
Loading