dina 1.0.8.0 → 1.1.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: 2b0da0908db1832ae7d9449ea98daeee46b51c95b2122787fc65a400d3d40f1f
4
+ data.tar.gz: 75e4a2f40a4d5ba1951a7c8e92ca5a5eca662f2618c25491c7ba8ac907ec8d1d
5
5
  SHA512:
6
- metadata.gz: d8e655d7ac450c38480dbd9579705db8fcb4ba66a24d17db017a2dd9dcd3e26c2bf01accd258c2add7dd70fb1d49ef5c5063868fd59f81ca4c95bd8322b81829
7
- data.tar.gz: 188fef0f7584d401d0f0f92eb27f00ff727a335fde51b76199924e8ab369cb7fe95f5b1a438f362fbc2151bc131264015a9aba4506a90fd818f81000cce018b3
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
- 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
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 = 1
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.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-08-23 00:00:00.000000000 Z
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