bulk_ops 0.1.19 → 0.1.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 980d5fec0bcc94d2199356f379adeb0cee99a748b159a5b7d2934e26bdf53c9d
4
- data.tar.gz: c4c6ef9e463d35fd408ac6c477a47bee55eb7833c374269e4bc3a98d881713b2
3
+ metadata.gz: b0f3d62a2115d7a69c05a8aac7e13f1badda13bc587474884a089e456c460b96
4
+ data.tar.gz: 3c7027bc6bade6fa01198b4a89675f1fc78b21140042befb52c3219afc92b66d
5
5
  SHA512:
6
- metadata.gz: d9511dad25f5d1f489ad08415b7750fd2264d214b057ea9b2af0fbd2ee83998cbb25f631b8e1432b958bd0a90c85a4507cbc363e21316e981090aa6b42697215
7
- data.tar.gz: 90df61d91db0671690c2fc8199d75feadea833c5ee23e8e4778c855f7a36297cec3ea191741b33d1ad1409e4d43020888fc37f037280de7f0578b9cda285159d
6
+ metadata.gz: 2f1381ef24e117468a3aa134ae19ed64b50c7d37ae0657fc31e06e830ef33471fc2cd35a407d63d5e362b4ba88f24cdfb8b462da55e957f289be3461b27273ce
7
+ data.tar.gz: 91f4661e005d422c39417fa9d6b94d0d4f85d3b8b4f5ca5da375294fbba7b02116c01854aaa1cf30e77326eb44d318e205be38aa7ee4f96516c50caa786dad5f
@@ -102,7 +102,7 @@ module BulkOps
102
102
  proxy.update(message: "interpreted at #{DateTime.now.strftime("%d/%m/%Y %H:%M")} " + proxy.message)
103
103
  data = BulkOps::Parser.new(proxy, @metadata).interpret_data(raw_row: values)
104
104
  next unless proxy.proxy_errors.blank?
105
- BulkOps::CreateWorkJob.perform_later(proxy.work_type || "Work",
105
+ BulkOps::WorkJob.perform_later(proxy.work_type || "Work",
106
106
  user.email,
107
107
  data,
108
108
  proxy.id,
@@ -7,8 +7,14 @@ class BulkOps::Parser
7
7
 
8
8
  def self.is_file_set? metadata, row_number
9
9
  return false unless metadata[row_number].present?
10
- # If there are any valid fields other than relationship or file fields, it is a work
10
+ # If the work type is explicitly specified, use that
11
+ if (type_key = metadata.keys.find{|key| key.downcase.gsub(/[_\-\s]/,"").include?("worktype") })
12
+ return true if metadata[type_key].downcase == "fileset"
13
+ return false if metadata[type_key].present?
14
+ end
15
+ # Otherwise, if there are any valid fields other than relationship or file fields, call it a work
11
16
  metadata[row_number].each do |field, value|
17
+ return true if
12
18
  next if BulkOps::Verification.is_file_field?(field)
13
19
  next if ["parent", "order"].include?(normalize_relationship_field_name(field))
14
20
  next if ["title","label"].include?(field.downcase.strip)
@@ -39,6 +45,7 @@ class BulkOps::Parser
39
45
  interpret_file_fields
40
46
  interpret_controlled_fields
41
47
  interpret_scalar_fields
48
+ connect_existing_work
42
49
  @proxy.update(status: "ERROR", message: "error parsing spreadsheet line") if @parsing_errors.present?
43
50
  @proxy.proxy_errors = (@proxy.proxy_errors || []) + @parsing_errors
44
51
  return @metadata
@@ -57,6 +64,21 @@ class BulkOps::Parser
57
64
  @raw_row = row
58
65
  end
59
66
 
67
+ def connect_existing_work
68
+ return unless (column_name = operation.options["update_identifier"])
69
+ return unless (key = @raw_row.keys.find{|key| key.to_s.parameterize.downcase.gsub("_","") == column_name.to_s.parameterize.downcase.gsub("_","")})
70
+ return unless (value = @raw_row[key])
71
+ return unless (work_id = find_work_id_from_unique_metadata(key, value))
72
+ proxy.update(work_id: work_id)
73
+ end
74
+
75
+ def find_work_id_from_unique_metadata field_name, value
76
+ field_solr_name = schema.get_field(field_name).solr_name
77
+ query = "_query_:\"{!raw f=#{field_name}}#{value}\""
78
+ response = ActiveFedora::SolrService.instance.conn.get(ActiveFedora::SolrService.select_path, params: { fq: query, rows: 1, start: 0})["response"]
79
+ return response["docs"][0]["id"]
80
+ end
81
+
60
82
  def interpret_controlled_fields
61
83
 
62
84
  # The labels array tracks the contents of columns marked as labels,
@@ -1,3 +1,3 @@
1
1
  module BulkOps
2
- VERSION = "0.1.19"
2
+ VERSION = "0.1.20"
3
3
  end
@@ -60,6 +60,20 @@ class BulkOps::WorkJob < ActiveJob::Base
60
60
 
61
61
  private
62
62
 
63
+
64
+ def define_work
65
+ if proxy.work_id.present? && record_exists? proxy.work_id
66
+ begin
67
+ @work = ActiveFedora::Base.find(@work_proxy.work_id)
68
+ rescue ActiveFedora::ObjectNotFoundError
69
+ report_error "Could not find work to update in Fedora (though it shows up in Solr). Work id: #{@work_proxy.work_id}"
70
+ return false
71
+ end
72
+ else
73
+ @work = workClass.capitalize.constantize.new
74
+ end
75
+ end
76
+
63
77
  def record_exists? id
64
78
  begin
65
79
  return true if SolrDocument.find(id)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bulk_ops
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.19
4
+ version: 0.1.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ned Henry, UCSC Library Digital Initiatives
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-16 00:00:00.000000000 Z
11
+ date: 2019-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails