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: 917397652abb2b0768af4cadfe8bf3dd1eb24a68af6e787b391c9d604af9b84c
4
- data.tar.gz: 434bf97f14162b26121f4ce86816bdcf716932c25432b7bb2c4378caa30f26bd
3
+ metadata.gz: 3e1d7ef84d82908a0cfa2bacbf9b71dc311ec9a255b8a3598d292cd0997ef9e5
4
+ data.tar.gz: c2982683e2b041eae5b1978de2dbc4d72feaae334e67650168e31a430de9a7c7
5
5
  SHA512:
6
- metadata.gz: d8e655d7ac450c38480dbd9579705db8fcb4ba66a24d17db017a2dd9dcd3e26c2bf01accd258c2add7dd70fb1d49ef5c5063868fd59f81ca4c95bd8322b81829
7
- data.tar.gz: 188fef0f7584d401d0f0f92eb27f00ff727a335fde51b76199924e8ab369cb7fe95f5b1a438f362fbc2151bc131264015a9aba4506a90fd818f81000cce018b3
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
- Dina.config.endpoint_url + "/" + endpoint_path
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
- def self.verify_ssl
6
- begin
7
- connection_options[:ssl][:verify]
8
- rescue
9
- true
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 self.find(group:, id:)
14
- obj = self.new
15
- obj.group = group
16
- RestClient::Request.execute(
17
- method: :get,
18
- headers: { authorization: Dina.header },
19
- url: obj.url + "/#{id}",
20
- verify_ssl: verify_ssl
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
- def self.create(attributes = {})
25
- new(attributes).tap do |resource|
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
- def initialize(attributes = {})
31
- @id = attributes[:id] || SecureRandom.uuid
32
- @group = attributes[:group] || nil
33
- @is_derivative = attributes[:is_derivative] || false
34
- @file_path = attributes[:file_path] || nil
35
- @filename = attributes[:filename] || File.basename(@file_path) rescue nil
36
- end
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
- def endpoint
39
- Dina.config.endpoint_url
40
- end
56
+ self.connection_class = FileConnection
41
57
 
42
- def endpoint_path
43
- "objectstore-api/"
44
- end
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 url
51
- endpoint + "/" + endpoint_path + table_name
63
+ def self.endpoint_path
64
+ "objectstore-api/"
52
65
  end
53
66
 
54
- def file
55
- new_file = ::File.new(file_path)
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 save
64
- validate_params
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 validate_params
84
- if id.nil? || !id.is_uuid?
85
- raise ObjectInvalid, "#{self.class} is invalid. id is not a UUID."
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: :string
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
@@ -2,8 +2,8 @@ module Dina
2
2
  class Version
3
3
 
4
4
  MAJOR = 1
5
- MINOR = 0
6
- PATCH = 8
5
+ MINOR = 2
6
+ PATCH = 0
7
7
  BUILD = 0
8
8
 
9
9
  def self.version
data/lib/dina.rb CHANGED
@@ -3,6 +3,7 @@ require "json_api_client"
3
3
  require "time"
4
4
  require "date"
5
5
  require "securerandom"
6
+ require 'faraday/multipart'
6
7
  require "require_all"
7
8
  require_all File.join(File.dirname(__FILE__), 'dina')
8
9
 
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.8.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-08-23 00:00:00.000000000 Z
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