collectionspace-client 0.14.1 → 0.15.1

Sign up to get free protection for your applications and to get access to all the features.
data/examples/reports.rb CHANGED
@@ -1,178 +1,45 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
- require 'awesome_print'
5
- require 'collectionspace/client'
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+ require "awesome_print"
5
+ require "collectionspace/client"
6
6
 
7
- client = CollectionSpace::Client.new(
8
- CollectionSpace::Configuration.new(
9
- base_uri: 'https://core.dev.collectionspace.org/cspace-services',
10
- username: 'admin@core.collectionspace.org',
11
- password: 'Administrator'
12
- )
13
- )
7
+ STANDARD_TENANTS = [
8
+ :anthro,
9
+ :bonsai,
10
+ :botgarden,
11
+ :core,
12
+ :fcart,
13
+ :herbarium,
14
+ :lhmc,
15
+ :materials,
16
+ :publicart
17
+ ]
14
18
 
15
19
  # https://github.com/collectionspace/Tools/blob/master/scripts/install_report_records.sh
16
20
  # https://github.com/collectionspace/Tools/blob/master/scripts/create-report-records.sh
17
21
 
18
- STANDARD_REPORTS = [
19
- {
20
- name: 'Acquisition Summary',
21
- notes: 'An acquisition summary report. Runs on a single record only.',
22
- doctype: 'Acquisition',
23
- supports_single_doc: 'true',
24
- supports_doc_list: 'false',
25
- supports_group: 'false',
26
- supports_no_context: 'false',
27
- filename: 'acq_basic.jrxml',
28
- mimetype: 'application/pdf'
29
- },
30
- {
31
- name: 'Acquisition Basic List',
32
- notes: 'Catalog info for objects related to an acquisition record. Runs on a single record only.',
33
- doctype: 'Acquisition',
34
- supports_single_doc: 'true',
35
- supports_doc_list: 'false',
36
- supports_group: 'false',
37
- supports_no_context: 'false',
38
- filename: 'Acq_List_Basic.jrxml',
39
- mimetype: 'application/pdf'
40
- },
41
- {
42
- name: 'Condition Check Basic List',
43
- notes: 'Catalog info for objects related to a condition check record. Runs on a single record only.',
44
- doctype: 'Conditioncheck',
45
- supports_single_doc: 'true',
46
- supports_doc_list: 'false',
47
- supports_group: 'false',
48
- supports_no_context: 'false',
49
- filename: 'CC_List_Basic.jrxml',
50
- mimetype: 'application/pdf'
51
- },
52
- {
53
- name: 'Exhibition Basic List',
54
- notes: 'Catalog info for objects related to a exhibition record. Runs on a single record only.',
55
- doctype: 'Exhibition',
56
- supports_single_doc: 'true',
57
- supports_doc_list: 'false',
58
- supports_group: 'false',
59
- supports_no_context: 'false',
60
- filename: 'Exhibition_List_Basic.jrxml',
61
- mimetype: 'application/pdf'
62
- },
63
- {
64
- name: 'Group Basic List',
65
- notes: 'Catalog info for objects related to a group record. Runs on a single record only.',
66
- doctype: 'Group',
67
- supports_single_doc: 'true',
68
- supports_doc_list: 'false',
69
- supports_group: 'false',
70
- supports_no_context: 'false',
71
- filename: 'Group_List_Basic.jrxml',
72
- mimetype: 'application/pdf'
73
- },
74
- {
75
- name: 'Loan In Basic List',
76
- notes: 'Catalog info for objects related to a loan in record. Runs on a single record only.',
77
- doctype: 'Loanin',
78
- supports_single_doc: 'true',
79
- supports_doc_list: 'false',
80
- supports_group: 'false',
81
- supports_no_context: 'false',
82
- filename: 'LoansIn_List_Basic.jrxml',
83
- mimetype: 'application/pdf'
84
- },
85
- {
86
- name: 'Loan Out Basic List',
87
- notes: 'Catalog info for objects related to a loan out record. Runs on a single record only.',
88
- doctype: 'Loanout',
89
- supports_single_doc: 'true',
90
- supports_doc_list: 'false',
91
- supports_group: 'false',
92
- supports_no_context: 'false',
93
- filename: 'LoansOut_List_Basic.jrxml',
94
- mimetype: 'application/pdf'
95
- },
96
- {
97
- name: 'Acquisition Ethnographic Object List',
98
- notes: 'Core acquisition report. Runs on a single record only.',
99
- doctype: 'Acquisition',
100
- supports_single_doc: 'true',
101
- supports_doc_list: 'false',
102
- supports_group: 'false',
103
- supports_no_context: 'false',
104
- filename: 'coreAcquisition.jrxml',
105
- mimetype: 'application/pdf'
106
- },
107
- {
108
- name: 'Group Object Ethnographic Object List',
109
- notes: 'Core group object report. Runs on a single record only.',
110
- doctype: 'Group',
111
- supports_single_doc: 'true',
112
- supports_doc_list: 'false',
113
- supports_group: 'false',
114
- supports_no_context: 'false',
115
- filename: 'coreGroupObject.jrxml',
116
- mimetype: 'application/pdf'
117
- },
118
- {
119
- name: 'Intake Ethnographic Object List',
120
- notes: 'Core intake report. Runs on a single record only.',
121
- doctype: 'Intake',
122
- supports_single_doc: 'true',
123
- supports_doc_list: 'false',
124
- supports_group: 'false',
125
- supports_no_context: 'false',
126
- filename: 'coreIntake.jrxml',
127
- mimetype: 'application/pdf'
128
- },
129
- {
130
- name: 'Loan In Ethnographic Object List',
131
- notes: 'Core loan in report. Runs on a single record only.',
132
- doctype: 'Loanin',
133
- supports_single_doc: 'true',
134
- supports_doc_list: 'false',
135
- supports_group: 'false',
136
- supports_no_context: 'false',
137
- filename: 'coreLoanIn.jrxml',
138
- mimetype: 'application/pdf'
139
- },
140
- {
141
- name: 'Loan Out Ethnographic Object List',
142
- notes: 'Core loan out report. Runs on a single record only.',
143
- doctype: 'Loanout',
144
- supports_single_doc: 'true',
145
- supports_doc_list: 'false',
146
- supports_group: 'false',
147
- supports_no_context: 'false',
148
- filename: 'coreLoanOut.jrxml',
149
- mimetype: 'application/pdf'
150
- },
151
- {
152
- name: 'Object Exit Ethnographic Object List',
153
- notes: 'Core object exit report. Runs on a single record only.',
154
- doctype: 'ObjectExit',
155
- supports_single_doc: 'true',
156
- supports_doc_list: 'false',
157
- supports_group: 'false',
158
- supports_no_context: 'false',
159
- filename: 'coreObjectExit.jrxml',
160
- mimetype: 'application/pdf'
161
- },
162
- {
163
- name: 'Systematic Inventory',
164
- notes: 'Generate a checklist for performing an inventory on a range of storage locations. Runs on all records, using the provided start and end locations.',
165
- doctype: 'Locationitem',
166
- supports_single_doc: 'false',
167
- supports_doc_list: 'false',
168
- supports_group: 'false',
169
- supports_no_context: 'true',
170
- filename: 'systematicInventory.jrxml',
171
- mimetype: 'application/pdf'
172
- }
173
- ]
22
+ STANDARD_REPORTS = CollectionSpace::Report.all
23
+
24
+ STANDARD_TENANTS.each do |tenant|
25
+ client = CollectionSpace::Client.new(
26
+ CollectionSpace::Configuration.new(
27
+ base_uri: "https://#{tenant}.dev.collectionspace.org/cspace-services",
28
+ username: "admin@#{tenant}.collectionspace.org",
29
+ password: "Administrator"
30
+ )
31
+ )
32
+ base = client.config.base_uri
33
+ .delete_suffix("/cspace-services")
34
+ .delete_prefix("https://")
174
35
 
175
- STANDARD_REPORTS.each do |report|
176
- response = client.add_report(report)
177
- puts response.inspect
36
+ STANDARD_REPORTS.each do |report|
37
+ response = client.add_report(report)
38
+ if response.result.success?
39
+ puts "Added #{report[:name]} to #{base}"
40
+ else
41
+ puts "FAILED TO ADD #{report[:name]} to #{base}"
42
+ puts response.inspect
43
+ end
44
+ end
178
45
  end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+ require "awesome_print"
5
+ require "collectionspace/client"
6
+ require "csv"
7
+
8
+ client = CollectionSpace::Client.new(
9
+ CollectionSpace::Configuration.new(
10
+ base_uri: "https://core.dev.collectionspace.org/cspace-services",
11
+ username: "admin@core.collectionspace.org",
12
+ password: "Administrator"
13
+ )
14
+ )
15
+ client.config.throttle = 1
16
+
17
+ path = File.expand_path("~/your/path/here.csv")
18
+
19
+ CSV.foreach(path, headers: true) do |row|
20
+ client.reset_media_blob(
21
+ id: row["identificationnumber"],
22
+ url: row["mediafileuri"],
23
+ verbose: true,
24
+ # client files are on same server as CS instance, and ingestable
25
+ # file paths do not all parse as URIs safely
26
+ ensure_safe_url: false,
27
+ # This example script used to fix media where the blobs had already
28
+ # been deleted, but the blobcsid value was not removed from the
29
+ # media record. Attempts to delete the media failed, so this option
30
+ # was used to add new blobs without attempting to delete the already
31
+ # deleted old blobs (and erroring out)
32
+ delete_existing_blob: false
33
+ )
34
+ sleep 1.5
35
+ end
data/examples/search.rb CHANGED
@@ -1,34 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
- require 'awesome_print'
5
- require 'collectionspace/client'
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+ require "awesome_print"
5
+ require "collectionspace/client"
6
6
 
7
7
  config = CollectionSpace::Configuration.new(
8
- base_uri: 'https://core.dev.collectionspace.org/cspace-services',
9
- username: 'admin@core.collectionspace.org',
10
- password: 'Administrator'
8
+ base_uri: "https://core.dev.collectionspace.org/cspace-services",
9
+ username: "admin@core.collectionspace.org",
10
+ password: "Administrator"
11
11
  )
12
12
 
13
13
  client = CollectionSpace::Client.new(config)
14
14
 
15
15
  search_args = {
16
- path: 'groups',
17
- namespace: 'groups_common',
18
- field: 'title',
16
+ path: "groups",
17
+ namespace: "groups_common",
18
+ field: "title",
19
19
  expression: "ILIKE '%D%'"
20
20
  }
21
21
 
22
- puts 'Search: %D'
22
+ puts "Search: %D"
23
23
  response = client.search(
24
24
  CollectionSpace::Search.new.from_hash(search_args),
25
- { sortBy: CollectionSpace::Search::DEFAULT_SORT }
25
+ {sortBy: CollectionSpace::Search::DEFAULT_SORT}
26
26
  )
27
27
  if response.result.success?
28
- response.parsed['abstract_common_list']['list_item'].map do |i|
29
- puts i['uri']
28
+ response.parsed["abstract_common_list"]["list_item"].map do |i|
29
+ puts i["uri"]
30
30
  end
31
31
  end
32
32
 
33
- puts 'Object and authority term searches have been moved to spec.'
34
- puts 'See helpers_spec.rb examples describing find'
33
+ puts "Object and authority term searches have been moved to spec."
34
+ puts "See helpers_spec.rb examples describing find"
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- puts 'Update password has been moved to Rake task: `cli:update_password[args...]`'
3
+ puts "Update password has been moved to Rake task: `cli:update_password[args...]`"
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CollectionSpace
4
+ # CollectionSpace batch
5
+ class Batch
6
+ def self.all
7
+ [
8
+ {
9
+ name: "Update Current Location",
10
+ notes: "Recompute the current location of Object records, based on the " \
11
+ "related Location/Movement/Inventory records. Runs on a single record " \
12
+ "or all records.",
13
+ doctype: %w[CollectionObject],
14
+ supports_single_doc: "true",
15
+ supports_doc_list: "false",
16
+ supports_group: "false",
17
+ supports_no_context: "true",
18
+ creates_new_focus: "false",
19
+ classname:
20
+ "org.collectionspace.services.batch.nuxeo.UpdateObjectLocationBatchJob"
21
+ },
22
+ {
23
+ name: "Update Inventory Status",
24
+ notes: "Set the inventory status of selected Object records. Runs on a " \
25
+ "record list only.",
26
+ doctype: %w[CollectionObject],
27
+ supports_single_doc: "false",
28
+ supports_doc_list: "true",
29
+ supports_group: "false",
30
+ supports_no_context: "false",
31
+ creates_new_focus: "false",
32
+ classname:
33
+ "org.collectionspace.services.batch.nuxeo.UpdateInventoryStatusBatchJob"
34
+ },
35
+ {
36
+ name: "Merge Authority Items",
37
+ notes: "Merge an authority item into a target, and update all " \
38
+ "referencing records. Runs on a single record only.",
39
+ doctype: %w[],
40
+ supports_single_doc: "true",
41
+ supports_doc_list: "false",
42
+ supports_group: "false",
43
+ supports_no_context: "false",
44
+ creates_new_focus: "false",
45
+ classname:
46
+ "org.collectionspace.services.batch.nuxeo.MergeAuthorityItemsBatchJob"
47
+ }
48
+ ]
49
+ end
50
+
51
+ def self.find(key, value)
52
+ all.find { |batch| batch[key] == value }
53
+ end
54
+ end
55
+ end
@@ -8,28 +8,39 @@ module CollectionSpace
8
8
 
9
9
  def initialize(config = Configuration.new)
10
10
  unless config.is_a? CollectionSpace::Configuration
11
- raise CollectionSpace::ArgumentError, 'Invalid configuration object'
11
+ raise CollectionSpace::ArgumentError, "Invalid configuration object"
12
12
  end
13
13
 
14
14
  @config = config
15
15
  end
16
16
 
17
17
  def get(path, options = {})
18
- request 'GET', path, options
18
+ request "GET", path, options
19
19
  end
20
20
 
21
21
  def post(path, payload, options = {})
22
22
  check_payload(payload)
23
- request 'POST', path, { body: payload }.merge(options)
23
+ request "POST", path, {body: payload}.merge(options)
24
+ end
25
+
26
+ def post_file(file, options = {})
27
+ file = File.expand_path(file)
28
+ raise ArgumentError, "cannot find file #{file}" unless File.exist? file
29
+
30
+ request "POST", "blobs", {
31
+ body: {
32
+ file: File.open(file)
33
+ }
34
+ }.merge(options)
24
35
  end
25
36
 
26
37
  def put(path, payload, options = {})
27
38
  check_payload(payload)
28
- request 'PUT', path, { body: payload }.merge(options)
39
+ request "PUT", path, {body: payload}.merge(options)
29
40
  end
30
41
 
31
42
  def delete(path)
32
- request 'DELETE', path
43
+ request "DELETE", path
33
44
  end
34
45
 
35
46
  private
@@ -10,10 +10,11 @@ module CollectionSpace
10
10
  page_size: 25,
11
11
  include_deleted: false,
12
12
  throttle: 0,
13
+ verbose: false,
13
14
  verify_ssl: true
14
15
  }.freeze
15
16
 
16
- attr_accessor :base_uri, :username, :password, :page_size, :include_deleted, :throttle, :verify_ssl
17
+ attr_accessor :base_uri, :username, :password, :page_size, :include_deleted, :throttle, :verbose, :verify_ssl
17
18
 
18
19
  def initialize(settings = {})
19
20
  settings = DEFAULTS.merge(settings)