Skip to content

Commit

Permalink
Merge pull request #816 from WGBH-MLA/sony_cid_wherefor_art_thou
Browse files Browse the repository at this point in the history
add back sony_cid, make admin_data more object like in pbcore_xml_entry
  • Loading branch information
orangewolf authored Dec 20, 2023
2 parents 5fca79c + 7ff28e6 commit 892ba94
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions app/models/bulkrax/pbcore_xml_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,10 @@ def build_metadata
end

if self.raw_metadata['model'] == 'AssetResource'
bulkrax_importer_id = importer.id
admin_data_gid = update_or_create_admin_data_gid(bulkrax_importer_id)

self.parsed_metadata["contributors"] = self.raw_metadata["contributors"]
self.parsed_metadata['bulkrax_importer_id'] = bulkrax_importer_id
self.parsed_metadata['bulkrax_importer_id'] = importer.id
self.parsed_metadata['admin_data_gid'] = admin_data_gid
build_annotations(self.raw_metadata['annotations'], admin_data_gid) if self.raw_metadata['annotations'].present?
build_annotations(self.raw_metadata['annotations']) if self.raw_metadata['annotations'].present?
end

self.parsed_metadata['label'] = nil if self.parsed_metadata['label'] == "[]"
Expand All @@ -71,23 +68,28 @@ def build_metadata
self.parsed_metadata
end

def update_or_create_admin_data_gid(bulkrax_importer_id)
def admin_data
return @admin_data if @admin_data.present?
asset_resource_id = self.raw_metadata['Asset.id'].strip if self.raw_metadata.keys.include?('Asset.id')
asset_resource_id ||= self.raw_metadata['id']
work = Hyrax.query_service.find_by(id: asset_resource_id) if asset_resource_id
admin_data_gid = if work.present? && work.admin_data.present?
work.admin_data.update!(bulkrax_importer_id: bulkrax_importer_id)
work.admin_data_gid
else
AdminData.create(bulkrax_importer_id: bulkrax_importer_id).gid
end
begin
work = Hyrax.query_service.find_by(id: asset_resource_id) if asset_resource_id
rescue Valkyrie::Persistence::ObjectNotFoundError
work = nil
end

@admin_data = work.admin_data if work.present?
@admin_data ||= AdminData.new
@admin_data.bulkrax_importer_id = importer.id
@admin_data.save
@admin_data
end

admin_data_gid
rescue Valkyrie::Persistence::ObjectNotFoundError
AdminData.create(bulkrax_importer_id: bulkrax_importer_id).gid
def admin_data_gid
admin_data.gid
end

def build_annotations(annotations, admin_data_gid)
def build_annotations(annotations)
annotations.each do |annotation|
if annotation['annotation_type'].nil?
raise "annotation_type not registered with the AnnotationTypesService: #{annotation['annotation_type']}."
Expand All @@ -99,7 +101,7 @@ def build_annotations(annotations, admin_data_gid)
value: annotation['value'],
annotation: annotation['annotation'],
version: annotation['version'],
admin_data_id: admin_data_gid.split('/').last
admin_data_id: admin_data.id
)
end
end
Expand Down

0 comments on commit 892ba94

Please sign in to comment.