File tree Expand file tree Collapse file tree
concerns/digital_object/assets Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,16 +46,11 @@ def validate_import_file_data_if_present
4646 @errors . add ( :import_file , "import_file.#{ resource_name } .original_file_path contains invalid UTF-8 characters." )
4747 end
4848
49- # Make sure that there isn't already another Asset with a main file that points to this same file
50- pid = Hyacinth ::Utils ::FedoraUtils . find_object_pid_by_filesystem_path ( import_location )
51- if pid . present?
52- # If this object is in Fedora but isn't in Hyacinth, then there's no problem here.
53- # But if it's in Hyacinth AND that Hyacinth object is active, then that is a problem
54- # and we should prevent a duplicate import.
55- possible_hyacinth_object = DigitalObject ::Base . find_by_pid ( pid )
56- if possible_hyacinth_object . present? && possible_hyacinth_object . state == ::DigitialObject ::Base ::STATE_ACTIVE
57- @errors . add ( :import_file , "Found existing active Hyacinth Asset (#{ pid } ) with main file path: #{ import_location } " )
58- end
49+ # Make sure that there isn't already another active Asset in Hyacinth with a main file that points to this same file
50+ import_location_as_uri = import_location . start_with? ( '/' ) ? Hyacinth ::Utils ::UriUtils . file_path_to_location_uri ( import_location ) : import_location
51+ possible_asset = DigitalObject ::Asset . find_by_resource_location_uri ( ::DigitalObject ::Asset ::MAIN_RESOURCE_NAME , import_location_as_uri )
52+ if possible_asset . present? && possible_asset . state == ::DigitalObject ::Base ::STATE_ACTIVE
53+ @errors . add ( :import_file , "Found existing active Hyacinth Asset (#{ possible_asset . pid } ) with main file path: #{ possible_asset . location_uri_for_resource ( ::DigitalObject ::Asset ::MAIN_RESOURCE_NAME ) } " )
5954 end
6055 end
6156
Original file line number Diff line number Diff line change @@ -36,6 +36,18 @@ class DigitalObject::Asset < DigitalObject::Base
3636
3737 attr_accessor :restricted_size_image , :restricted_onsite
3838
39+
40+ def self . find_by_resource_location_uri ( resource_name , location_uri )
41+ pid_for_possible_asset = DigitalObject ::Base . search (
42+ 'fq' => { "resource_#{ resource_name } _location_si" => [ { 'equals' => location_uri } ] } , 'fl' => 'pid' , 'per_page' => 1
43+ ) . dig ( 'results' , 0 , 'pid' )
44+
45+ return nil if pid_for_possible_asset . nil?
46+ asset = DigitalObject ::Base . find_by_pid ( pid_for_possible_asset )
47+
48+ asset . state == ::DigitalObject ::Base ::STATE_ACTIVE ? asset : nil
49+ end
50+
3951 def initialize
4052 super
4153
You can’t perform that action at this time.
0 commit comments