dina 1.2.0.0 → 1.3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dina/models/object_store/file.rb +3 -45
- data/lib/dina/models/object_store/file_connection.rb +50 -0
- data/lib/dina/search/search.rb +11 -16
- data/lib/dina/search/search_autocomplete.rb +13 -25
- data/lib/dina/search/search_connection.rb +64 -0
- data/lib/dina/search/search_count.rb +13 -16
- data/lib/dina/search/search_mapping.rb +12 -13
- data/lib/dina/version.rb +1 -1
- metadata +4 -17
- data/lib/dina/search/base_search.rb +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36ae9a46adaaf1a545511c102afbc5bada1c3ad4632273672253f9191e347459
|
4
|
+
data.tar.gz: 67c1631fad9d7ebb3469a063fc6b22e1d6c9d720a8abe6804ae35c7d4dd83848
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba219ae94560f594838864568429f8c84e4bf86a8c4396a0fd142c8803a0aea03f0da864b7bb9b44f700234d1da7dfbf9b75e6033ad1690fb5b13e69785700b1
|
7
|
+
data.tar.gz: cd564fa3198356107742862c2cc7d45b4c32dace7c3684117ccb9e29d97e066bb0c6fb60dd5ca8aa388afe66c11203fa9d6558efc9f68ee82824536aa076ef4d
|
@@ -1,49 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class FileConnection
|
4
|
-
def initialize(options = {})
|
5
|
-
site = options.fetch(:site)
|
6
|
-
connection_options = options.slice(:proxy, :ssl, :request, :headers, :params)
|
7
|
-
adapter_options = Array(options.fetch(:adapter, Faraday.default_adapter))
|
8
|
-
|
9
|
-
@faraday = Faraday.new(site, connection_options) do |builder|
|
10
|
-
builder.request :multipart
|
11
|
-
builder.use ::JsonApiClient::Middleware::ParseJson
|
12
|
-
builder.adapter(*adapter_options)
|
13
|
-
end
|
14
|
-
yield(self) if block_given?
|
15
|
-
end
|
1
|
+
require_rel '../base_model'
|
2
|
+
require_rel 'file_connection'
|
16
3
|
|
17
|
-
|
18
|
-
path = path + "/#{body[:data]["attributes"]["group"].downcase}"
|
19
|
-
if body[:data]["attributes"].key?("is_derivative")
|
20
|
-
path = path + "/derivative"
|
21
|
-
end
|
22
|
-
file_path = body[:data]["attributes"]["filePath"]
|
23
|
-
mime_type = body[:data]["attributes"]["dcFormat"]
|
24
|
-
file_name = body[:data]["attributes"]["fileName"]
|
25
|
-
|
26
|
-
body[:file] = Faraday::Multipart::FilePart.new(
|
27
|
-
file_path,
|
28
|
-
mime_type,
|
29
|
-
file_name
|
30
|
-
)
|
31
|
-
|
32
|
-
response = @faraday.run_request(request_method, path, body, headers) do |request|
|
33
|
-
request.params.update(params) if params
|
34
|
-
end
|
35
|
-
attributes = response.body.dup
|
36
|
-
response.body["meta"] = {}
|
37
|
-
response.body["errors"] = []
|
38
|
-
response.body["data"] = {
|
39
|
-
"id" => attributes["uuid"],
|
40
|
-
"type" => "file",
|
41
|
-
"relationships" => {},
|
42
|
-
"attributes" => attributes
|
43
|
-
}
|
44
|
-
response
|
45
|
-
end
|
46
|
-
end
|
4
|
+
module Dina
|
47
5
|
|
48
6
|
class File < BaseModel
|
49
7
|
property :id, type: :string, default: SecureRandom.uuid
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require_rel '../base_model'
|
2
|
+
|
3
|
+
module Dina
|
4
|
+
|
5
|
+
class FileConnection
|
6
|
+
def initialize(options = {})
|
7
|
+
site = options.fetch(:site)
|
8
|
+
connection_options = options.slice(:proxy, :ssl, :request, :headers, :params)
|
9
|
+
adapter_options = Array(options.fetch(:adapter, Faraday.default_adapter))
|
10
|
+
|
11
|
+
@faraday = Faraday.new(site, connection_options) do |builder|
|
12
|
+
builder.request :multipart
|
13
|
+
builder.use ::JsonApiClient::Middleware::ParseJson
|
14
|
+
builder.adapter(*adapter_options)
|
15
|
+
end
|
16
|
+
yield(self) if block_given?
|
17
|
+
end
|
18
|
+
|
19
|
+
def run(request_method, path, params: nil, headers: {}, body: nil)
|
20
|
+
path = path + "/#{body[:data]["attributes"]["group"].downcase}"
|
21
|
+
if body[:data]["attributes"].key?("is_derivative")
|
22
|
+
path = path + "/derivative"
|
23
|
+
end
|
24
|
+
file_path = body[:data]["attributes"]["filePath"]
|
25
|
+
mime_type = body[:data]["attributes"]["dcFormat"]
|
26
|
+
file_name = body[:data]["attributes"]["fileName"]
|
27
|
+
|
28
|
+
body[:file] = Faraday::Multipart::FilePart.new(
|
29
|
+
file_path,
|
30
|
+
mime_type,
|
31
|
+
file_name
|
32
|
+
)
|
33
|
+
|
34
|
+
response = @faraday.run_request(request_method, path, body, headers) do |request|
|
35
|
+
request.params.update(params) if params
|
36
|
+
end
|
37
|
+
attributes = response.body.dup
|
38
|
+
response.body["meta"] = {}
|
39
|
+
response.body["errors"] = []
|
40
|
+
response.body["data"] = {
|
41
|
+
"id" => attributes["uuid"],
|
42
|
+
"type" => "file",
|
43
|
+
"relationships" => {},
|
44
|
+
"attributes" => attributes
|
45
|
+
}
|
46
|
+
response
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/lib/dina/search/search.rb
CHANGED
@@ -1,25 +1,20 @@
|
|
1
|
-
require_rel '
|
1
|
+
require_rel '../models/base_model'
|
2
|
+
require_rel 'search_connection'
|
2
3
|
|
3
4
|
module Dina
|
4
|
-
class Search <
|
5
|
+
class Search < BaseModel
|
6
|
+
|
7
|
+
self.connection_class = SearchConnection
|
8
|
+
|
9
|
+
custom_endpoint :execute, on: :collection, request_method: :post
|
5
10
|
|
6
11
|
def self.endpoint_path
|
7
|
-
"search-api/search-ws/
|
12
|
+
"search-api/search-ws/"
|
8
13
|
end
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
# @param index [String] the index, accepted value is one of "agent", "material_sample", "object_store"
|
13
|
-
# @param payload [Hash] the payload hash as an Elasticsearch-formatted body
|
14
|
-
# => { query: { match_all: {} }
|
15
|
-
#
|
16
|
-
# @return [Hash] the search result with symbolized keys
|
17
|
-
def self.execute(index:, payload: { query: { match_all: {} } })
|
18
|
-
params = {
|
19
|
-
indexName: index_name(index: index)
|
20
|
-
}
|
21
|
-
super(params.compact, method: :post, payload: payload)[:hits]
|
15
|
+
def self.table_name
|
16
|
+
"search"
|
22
17
|
end
|
23
18
|
|
24
19
|
end
|
25
|
-
end
|
20
|
+
end
|
@@ -1,34 +1,22 @@
|
|
1
|
-
require_rel '
|
1
|
+
require_rel '../models/base_model'
|
2
|
+
require_rel 'search_connection'
|
3
|
+
|
4
|
+
#TODO: requires testing, likely failing
|
2
5
|
|
3
6
|
module Dina
|
4
|
-
class SearchAutocomplete <
|
7
|
+
class SearchAutocomplete < BaseModel
|
8
|
+
|
9
|
+
self.connection_class = SearchConnection
|
10
|
+
|
11
|
+
custom_endpoint :execute, on: :collection, request_method: :post
|
5
12
|
|
6
13
|
def self.endpoint_path
|
7
|
-
"search-api/search-ws/
|
14
|
+
"search-api/search-ws/"
|
8
15
|
end
|
9
16
|
|
10
|
-
|
11
|
-
|
12
|
-
# Known field values (dependent on chosen index):
|
13
|
-
# agent: data.attributes.displayName
|
14
|
-
# material_sample: included.attributes.dwcRecordedBy, included.attributes.verbatimDeterminer
|
15
|
-
# object_store: none
|
16
|
-
#
|
17
|
-
# @param term [String] the search term
|
18
|
-
# @param index [String] the index, accepted value is one of "agent", "material_sample", "object_store"
|
19
|
-
# @param field [String]
|
20
|
-
# @param group [String] the DINA group name
|
21
|
-
#
|
22
|
-
# @return [Hash] the search result with symbolized keys
|
23
|
-
def self.execute(term:, index:, field: nil, group: nil)
|
24
|
-
params = {
|
25
|
-
prefix: term,
|
26
|
-
indexName: index_name(index: index),
|
27
|
-
autoCompleteField: field,
|
28
|
-
group: group
|
29
|
-
}
|
30
|
-
super(params.compact)[:hits]
|
17
|
+
def self.table_name
|
18
|
+
"auto-complete"
|
31
19
|
end
|
32
20
|
|
33
21
|
end
|
34
|
-
end
|
22
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require_rel '../models/base_model'
|
2
|
+
|
3
|
+
module Dina
|
4
|
+
|
5
|
+
class SearchConnection
|
6
|
+
|
7
|
+
attr_reader :faraday
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
site = options.fetch(:site)
|
11
|
+
connection_options = options.slice(:proxy, :ssl, :request, :headers, :params)
|
12
|
+
adapter_options = Array(options.fetch(:adapter, Faraday.default_adapter))
|
13
|
+
|
14
|
+
@faraday = Faraday.new(site, connection_options) do |builder|
|
15
|
+
builder.request :json
|
16
|
+
builder.use ::JsonApiClient::Middleware::ParseJson
|
17
|
+
builder.adapter(*adapter_options)
|
18
|
+
end
|
19
|
+
yield(self) if block_given?
|
20
|
+
end
|
21
|
+
|
22
|
+
# Sets the search index name
|
23
|
+
#
|
24
|
+
# @param index [String] the search index; options are "agent", "material_sample", "object_store"
|
25
|
+
#
|
26
|
+
# @return [String] the internally-recognized search index name
|
27
|
+
def index_name(index:)
|
28
|
+
return nil if !index
|
29
|
+
"dina_#{index}_index"
|
30
|
+
end
|
31
|
+
|
32
|
+
def custom_headers
|
33
|
+
{ content_type: "application/json", authorization: Dina.header }
|
34
|
+
end
|
35
|
+
|
36
|
+
def run(request_method, path, params: nil, headers: {}, body: nil)
|
37
|
+
#TODO: works for search class, but likely failing for autocomplete, count, and mapping
|
38
|
+
params = {
|
39
|
+
indexName: index_name(index: body[:index])
|
40
|
+
}
|
41
|
+
path.slice!("/execute")
|
42
|
+
payload = JSON.generate(body[:payload]) rescue ""
|
43
|
+
|
44
|
+
response = faraday.run_request(request_method, path, body, headers) do |request|
|
45
|
+
request.params.update(params) if params
|
46
|
+
request.headers = custom_headers
|
47
|
+
request.body = payload
|
48
|
+
end
|
49
|
+
|
50
|
+
attributes = response.body.dup
|
51
|
+
response.body["meta"] = {}
|
52
|
+
response.body["errors"] = []
|
53
|
+
response.body["data"] = attributes["hits"]["hits"].map{|d| d["_source"]["data"]} rescue []
|
54
|
+
response
|
55
|
+
end
|
56
|
+
|
57
|
+
def use(middleware, *args, &block)
|
58
|
+
return if faraday.builder.locked?
|
59
|
+
faraday.builder.insert_before(Middleware::ParseJson, middleware, *args, &block)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -1,25 +1,22 @@
|
|
1
|
-
require_rel '
|
1
|
+
require_rel '../models/base_model'
|
2
|
+
require_rel 'search_connection'
|
3
|
+
|
4
|
+
#TODO: requires testing, likely failing
|
2
5
|
|
3
6
|
module Dina
|
4
|
-
class SearchCount <
|
7
|
+
class SearchCount < BaseModel
|
8
|
+
|
9
|
+
self.connection_class = SearchConnection
|
10
|
+
|
11
|
+
custom_endpoint :execute, on: :collection, request_method: :post
|
5
12
|
|
6
13
|
def self.endpoint_path
|
7
|
-
"search-api/search-ws/
|
14
|
+
"search-api/search-ws/"
|
8
15
|
end
|
9
16
|
|
10
|
-
|
11
|
-
|
12
|
-
# @param index [String] the index, accepted value is one of "agent", "material_sample", "object_store"
|
13
|
-
# @param payload [Hash] the Elasticsearch query hash
|
14
|
-
# => Example: {query: {bool: {filter: {term: {"data.attributes.group": "dao"}}}}}
|
15
|
-
#
|
16
|
-
# @return [Integer] the count of items in the index according to the query/filter
|
17
|
-
def self.execute(index:, payload: { query: { match_all: {} }})
|
18
|
-
params = {
|
19
|
-
indexName: index_name(index: index)
|
20
|
-
}
|
21
|
-
super(params.compact, method: :post, payload: payload)[:count]
|
17
|
+
def self.table_name
|
18
|
+
"count"
|
22
19
|
end
|
23
20
|
|
24
21
|
end
|
25
|
-
end
|
22
|
+
end
|
@@ -1,22 +1,21 @@
|
|
1
|
-
require_rel '
|
1
|
+
require_rel '../models/base_model'
|
2
|
+
require_rel 'search_connection'
|
3
|
+
|
4
|
+
#TODO: requires testing, likely failing
|
2
5
|
|
3
6
|
module Dina
|
4
|
-
class SearchMapping <
|
7
|
+
class SearchMapping < BaseModel
|
8
|
+
|
9
|
+
self.connection_class = SearchConnection
|
10
|
+
|
11
|
+
custom_endpoint :execute, on: :collection, request_method: :get
|
5
12
|
|
6
13
|
def self.endpoint_path
|
7
|
-
"search-api/search-ws/
|
14
|
+
"search-api/search-ws/"
|
8
15
|
end
|
9
16
|
|
10
|
-
|
11
|
-
|
12
|
-
# @param index [String] the index, accepted value is one of "agent", "material_sample", "object_store"
|
13
|
-
#
|
14
|
-
# @return [Hash] the mapping document as a hash with symbolized keys
|
15
|
-
def self.execute(index:)
|
16
|
-
params = {
|
17
|
-
indexName: index_name(index: index)
|
18
|
-
}
|
19
|
-
super(params.compact)
|
17
|
+
def self.table_name
|
18
|
+
"mapping"
|
20
19
|
end
|
21
20
|
|
22
21
|
end
|
data/lib/dina/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dina
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David P. Shorthouse
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-12-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json_api_client
|
@@ -67,20 +67,6 @@ dependencies:
|
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: 3.0.0
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: rest-client
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - "~>"
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: 2.1.0
|
77
|
-
type: :runtime
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - "~>"
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: 2.1.0
|
84
70
|
- !ruby/object:Gem::Dependency
|
85
71
|
name: faraday-multipart
|
86
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,6 +184,7 @@ files:
|
|
198
184
|
- lib/dina/models/material_sample/protocol.rb
|
199
185
|
- lib/dina/models/object_store/derivative.rb
|
200
186
|
- lib/dina/models/object_store/file.rb
|
187
|
+
- lib/dina/models/object_store/file_connection.rb
|
201
188
|
- lib/dina/models/object_store/object_store.rb
|
202
189
|
- lib/dina/models/object_store/object_store_managed_attribute.rb
|
203
190
|
- lib/dina/models/object_store/object_subtype.rb
|
@@ -213,9 +200,9 @@ files:
|
|
213
200
|
- lib/dina/models/storage/storage_unit_type.rb
|
214
201
|
- lib/dina/models/transaction/transaction.rb
|
215
202
|
- lib/dina/models/user.rb
|
216
|
-
- lib/dina/search/base_search.rb
|
217
203
|
- lib/dina/search/search.rb
|
218
204
|
- lib/dina/search/search_autocomplete.rb
|
205
|
+
- lib/dina/search/search_connection.rb
|
219
206
|
- lib/dina/search/search_count.rb
|
220
207
|
- lib/dina/search/search_mapping.rb
|
221
208
|
- lib/dina/utils/identifier.rb
|
@@ -1,57 +0,0 @@
|
|
1
|
-
module Dina
|
2
|
-
class BaseSearch < BaseModel
|
3
|
-
|
4
|
-
def self.verify_ssl
|
5
|
-
begin
|
6
|
-
connection_options[:ssl][:verify]
|
7
|
-
rescue
|
8
|
-
true
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.endpoint
|
13
|
-
Dina.config.endpoint_url
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.endpoint_path
|
17
|
-
"search-api/search-ws/"
|
18
|
-
end
|
19
|
-
|
20
|
-
# Sets the search index name
|
21
|
-
#
|
22
|
-
# @param index [String] the search index; options are "agent", "material_sample", "object_store"
|
23
|
-
#
|
24
|
-
# @return [String] the internally-recognized search index name
|
25
|
-
def self.index_name(index:)
|
26
|
-
return nil if !index
|
27
|
-
"dina_#{index}_index"
|
28
|
-
end
|
29
|
-
|
30
|
-
# Executes a search
|
31
|
-
#
|
32
|
-
# @param params [Hash] the parameters to be included in the endpoint URL
|
33
|
-
# @param method [Symbol] the request type as :get or :post
|
34
|
-
# @param payload [Hash] the elasticsearch query
|
35
|
-
#
|
36
|
-
# @return [Hash] the search response with symbolized keys
|
37
|
-
def self.execute(params, method: :get, payload: {})
|
38
|
-
begin
|
39
|
-
response = RestClient::Request.execute(
|
40
|
-
method: method,
|
41
|
-
url: endpoint + "/" + endpoint_path + "?" + params.to_query,
|
42
|
-
payload: payload.to_json,
|
43
|
-
headers: {
|
44
|
-
accept: 'application/json',
|
45
|
-
content_type: 'application/json',
|
46
|
-
authorization: Dina.header
|
47
|
-
},
|
48
|
-
verify_ssl: verify_ssl
|
49
|
-
)
|
50
|
-
JSON.parse(response, symbolize_names: true)
|
51
|
-
rescue RestClient::ExceptionWithResponse => e
|
52
|
-
e.response
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
end
|