dina 1.0.8.0 → 1.2.0.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e1d7ef84d82908a0cfa2bacbf9b71dc311ec9a255b8a3598d292cd0997ef9e5
|
4
|
+
data.tar.gz: c2982683e2b041eae5b1978de2dbc4d72feaae334e67650168e31a430de9a7c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c0228419cb5b4cd6754e5de928198d346f13c11a2b7a589814c2be08e152e0cc1bd93de724fd9a9641e2eb9616f6b9a3e871ec1d15fc96aad12a64c28ba172d
|
7
|
+
data.tar.gz: 80396b5d6e83c16c7dff385d21b94ef9c86981e1b14f93b741b0c6501d9f38f6b9f1b8619883341420375568dbe58253b95c668416db3b0ac556da5d6bd79469
|
@@ -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
|
@@ -25,7 +25,7 @@ module Dina
|
|
25
25
|
property :publiclyReleasable, type: :boolean, default: true
|
26
26
|
property :notPubliclyReleasableReason, type: :string
|
27
27
|
property :managedAttributes, type: :hash
|
28
|
-
property :acTags, type: :
|
28
|
+
property :acTags, type: :array
|
29
29
|
property :orientation, type: :integer
|
30
30
|
property :resourceExternalURL, type: :string
|
31
31
|
|
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.2.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-28 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
|