Module: BulkOps::Verification
Class Method Summary collapse
Instance Method Summary collapse
- #find_field_name(fieldname) ⇒ Object
- #get_file_paths(filestring) ⇒ Object
- #notify(subject:, message:) ⇒ Object
- #verify ⇒ Object
Class Method Details
.is_file_field?(fieldname) ⇒ Boolean
34 35 36 37 38 39 40 41 |
# File 'lib/bulk_ops/verification.rb', line 34 def self.is_file_field?(fieldname) return false if fieldname.blank? return false if ScoobySnacks::METADATA_SCHEMA.get_field(fieldname) field_parts = fieldname.underscore.humanize.downcase.gsub(/[-_]/,' ').split(" ") return false unless field_parts.any?{ |field_type| BulkOps::FILE_FIELDS.include?(field_type) } return "remove" if field_parts.any?{ |field_type| ['remove','delete'].include?(field_type) } return "add" end |
Instance Method Details
#find_field_name(fieldname) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/bulk_ops/verification.rb', line 43 def find_field_name(fieldname) name = fieldname.dup name.gsub!(/[_\s-]?[aA]ttributes$/,'') name.gsub!(/[_\s-]?[lL]abel$/,'') name.gsub!(/^[rR]emove[_\s-]?/,'') name.gsub!(/^[dD]elete[_\s-]?/,'') possible_fields = ((Work.attribute_names || []) + schema.all_field_names).uniq matching_fields = possible_fields.select{|pfield| pfield.gsub(/[_\s-]/,'').parameterize == name.gsub(/[_\s-]/,'').parameterize } return false if matching_fields.blank? # raise Exception "Ambiguous metadata fields!" if matching_fields.uniq.count > 1 return matching_fields.first end |
#get_file_paths(filestring) ⇒ Object
56 57 58 59 60 |
# File 'lib/bulk_ops/verification.rb', line 56 def get_file_paths(filestring) return [] if filestring.blank? filenames = filestring.split(BulkOps::SEPARATOR) filenames.map { |filename| File.join(BulkOps::INGEST_MEDIA_PATH, ['file_prefix'] || "", filename) } end |
#notify(subject:, message:) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/bulk_ops/verification.rb', line 25 def notify(subject: , message:) ["notifications"].each do |email| ActionMailer::Base.mail(from: "[email protected]", to: email, subject: subject, body: ).deliver end end |
#verify ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bulk_ops/verification.rb', line 5 def verify @verification_errors ||= [] update(message: "verifying spreadsheet column headers") verify_column_headers update(message: "verifying controlled vocab urls (starting)") verify_remote_urls update(message: "verifying complex object structures") verify_internal_references update(message: "verifying that all files exist") verify_files verify_works_to_update if operation_type.to_s == "update" unless @verification_errors.blank? error_file_name = BulkOps::Error.write_errors!(@verification_errors, git) #notify everybody notify(subject: "Errors verifying bulk #{operation_type} in Hycruz", message: "Hyrax ran a verification step to make sure that the spreadsheet for this bulk #{operation_type} is formatted correctly and won't create any errors. We found some problems. You can see a summary of the issues at this url: https://github.com/#{git.repo}/blob/#{git.name}/#{git.name}/errors/#{error_file_name}. Please fix these problems and run this verification again. The bulk #{operation_type} will not be allowed to move forward until all verification issues are resolved.") return false end return true end |