dina 1.0.8.0 → 1.1.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/base_model.rb +2 -1
- data/lib/dina/models/object_store/derivative.rb +1 -0
- data/lib/dina/models/object_store/file.rb +60 -71
- data/lib/dina/version.rb +2 -2
- data/lib/dina.rb +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b0da0908db1832ae7d9449ea98daeee46b51c95b2122787fc65a400d3d40f1f
|
4
|
+
data.tar.gz: 75e4a2f40a4d5ba1951a7c8e92ca5a5eca662f2618c25491c7ba8ac907ec8d1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47370d47608879648438e719efaea10e00534e25604f644719e57b4d202662894186e569e708dcb930dbbe6d3a4437dcbe18aa6c6eb96599172c58584efabcf6
|
7
|
+
data.tar.gz: a2bb7d19dfb476a294b5b80ea62d76f2da0842879b5ffe66ef45d79149e045060db849205b9336ea3272fd51d620933b92ac5347bcd1e2dd583634bc5ce34b19
|
@@ -18,7 +18,8 @@ module Dina
|
|
18
18
|
# Required by json_api_client
|
19
19
|
def self.site
|
20
20
|
raise ConfigItemMissing, "Missing endpoint_url from config. Perhaps Dina.config has not yet been called." unless Dina.config.endpoint_url
|
21
|
-
|
21
|
+
raise PropertyInvalid, "Missing endpoint_path in class." unless !endpoint_path.nil?
|
22
|
+
Dina.config.endpoint_url + "/" + endpoint_path.to_s
|
22
23
|
end
|
23
24
|
|
24
25
|
# injects keycloak bearer token with all json_api_client calls
|
@@ -11,6 +11,7 @@ module Dina
|
|
11
11
|
property :acHashFunction, type: :string, default: "SHA-1"
|
12
12
|
property :acHashValue, type: :string
|
13
13
|
property :derivativeType, type: :string
|
14
|
+
property :publiclyReleasable, type: :boolean, default: true
|
14
15
|
|
15
16
|
has_one :ac_derived_from, class_name: "ObjectStore"
|
16
17
|
|
@@ -1,96 +1,85 @@
|
|
1
1
|
module Dina
|
2
|
-
class File < BaseModel
|
3
|
-
attr_accessor :id, :file_path, :filename, :group, :is_derivative
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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)
|
10
13
|
end
|
14
|
+
yield(self) if block_given?
|
11
15
|
end
|
12
16
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def run(request_method, path, params: nil, headers: {}, body: nil)
|
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
|
21
30
|
)
|
22
|
-
end
|
23
31
|
|
24
|
-
|
25
|
-
|
26
|
-
resource.save
|
32
|
+
response = @faraday.run_request(request_method, path, body, headers) do |request|
|
33
|
+
request.params.update(params) if params
|
27
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
|
28
45
|
end
|
46
|
+
end
|
29
47
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
48
|
+
class File < BaseModel
|
49
|
+
property :id, type: :string, default: SecureRandom.uuid
|
50
|
+
property :group, type: :string
|
51
|
+
property :filePath, type: :string
|
52
|
+
property :fileName, type: :string
|
53
|
+
property :dcFormat, type: :string
|
54
|
+
property :is_derivative, type: :boolean
|
37
55
|
|
38
|
-
|
39
|
-
Dina.config.endpoint_url
|
40
|
-
end
|
56
|
+
self.connection_class = FileConnection
|
41
57
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
def table_name
|
47
|
-
"file/#{group.downcase}"
|
48
|
-
end
|
58
|
+
validates_presence_of :group, message: "group is required"
|
59
|
+
validates_presence_of :filePath, message: "filePath is required"
|
60
|
+
validates_presence_of :fileName, message: "fileName is required"
|
61
|
+
validates_presence_of :dcFormat, message: "dcFormat is required"
|
49
62
|
|
50
|
-
def
|
51
|
-
|
63
|
+
def self.endpoint_path
|
64
|
+
"objectstore-api/"
|
52
65
|
end
|
53
66
|
|
54
|
-
def
|
55
|
-
|
56
|
-
bound = filename.dup
|
57
|
-
new_file.define_singleton_method(:original_filename) do
|
58
|
-
bound
|
59
|
-
end
|
60
|
-
new_file
|
67
|
+
def self.table_name
|
68
|
+
"file"
|
61
69
|
end
|
62
70
|
|
63
|
-
def
|
64
|
-
|
65
|
-
response = RestClient::Request.execute(
|
66
|
-
method: :post,
|
67
|
-
headers: { authorization: Dina.header },
|
68
|
-
url: (!is_derivative) ? url : url + "/derivative",
|
69
|
-
payload: {
|
70
|
-
multipart: true,
|
71
|
-
file: file
|
72
|
-
},
|
73
|
-
verify_ssl: self.class.verify_ssl
|
74
|
-
)
|
75
|
-
json = JSON.parse(response, symbolize_names: true)
|
76
|
-
self.id = json[:uuid]
|
77
|
-
json.each{ |k,v| define_singleton_method(k.to_sym) { v } }
|
78
|
-
json
|
71
|
+
def self.custom_headers
|
72
|
+
{ content_type: "multipart/form-data", authorization: Dina.header }
|
79
73
|
end
|
80
74
|
|
81
75
|
private
|
82
76
|
|
83
|
-
def
|
84
|
-
if
|
85
|
-
raise
|
86
|
-
end
|
87
|
-
if group.nil?
|
88
|
-
raise ObjectInvalid, "#{self.class} is invalid. group is required."
|
89
|
-
end
|
90
|
-
if file_path.nil? || !::File.exist?(file_path)
|
91
|
-
raise ObjectInvalid, "#{self.class} is invalid. file not found in file_path."
|
77
|
+
def on_before_save
|
78
|
+
if !self.filePath.nil? && !::File.exist?(self.filePath)
|
79
|
+
raise PropertyValueInvalid, "#{self.class} is invalid. File not found in filePath."
|
92
80
|
end
|
81
|
+
super
|
93
82
|
end
|
94
83
|
|
95
84
|
end
|
96
|
-
end
|
85
|
+
end
|
data/lib/dina/version.rb
CHANGED
data/lib/dina.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.0.
|
4
|
+
version: 1.1.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-11-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json_api_client
|
@@ -81,6 +81,20 @@ dependencies:
|
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: 2.1.0
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: faraday-multipart
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.0.4
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 1.0.4
|
84
98
|
- !ruby/object:Gem::Dependency
|
85
99
|
name: rake
|
86
100
|
requirement: !ruby/object:Gem::Requirement
|