dina 1.0.7.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: 761a480e5d017a1d0d4600cad5adbcb6a0461ca78750a588edb0082676ba6621
4
- data.tar.gz: f049320abf3e40cf1fdc0a8fa3b600687cd57980c7fade955672d66767d0189f
3
+ metadata.gz: 2b0da0908db1832ae7d9449ea98daeee46b51c95b2122787fc65a400d3d40f1f
4
+ data.tar.gz: 75e4a2f40a4d5ba1951a7c8e92ca5a5eca662f2618c25491c7ba8ac907ec8d1d
5
5
  SHA512:
6
- metadata.gz: 245a9196b2a2b2e243d505007ad8e57dacf1db31695d8c1cfdb40b7e0c7565409147eab25ef87bff0004bf1b4b7f93b6234061e2b3348e83695a3f8f50fb7024
7
- data.tar.gz: d3d5e3aabe72117b5b3235ca6a28ed6829991945ff161e5ae78c60a8b7f56a81e2444903445f084afb35bfc37c159ed19d3fcdc813e648601ee65f3f6cb03919
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
@@ -71,16 +71,16 @@ module Dina
71
71
  self.geographicPlaceNameSourceDetail = nil
72
72
  end
73
73
  if self.dwcMinimumDepthInMeters && !Validator.valid_depth_elevation(value: self.dwcMinimumDepthInMeters)
74
- raise PropertyValueInvalid, "#{self.class} is invalid. Accepted value for dwcMinimumDepthInMeters must have no more than two decimal points and be less than or equal to 15000."
74
+ raise PropertyValueInvalid, "#{self.class} is invalid. Accepted value for dwcMinimumDepthInMeters must have no more than two decimal points and be >= 0 and <= 15000."
75
75
  end
76
76
  if self.dwcMaximumDepthInMeters && !Validator.valid_depth_elevation(value: self.dwcMaximumDepthInMeters)
77
- raise PropertyValueInvalid, "#{self.class} is invalid. Accepted value for dwcMaximumDepthInMeters must have no more than two decimal points and be less than or equal to 15000."
77
+ raise PropertyValueInvalid, "#{self.class} is invalid. Accepted value for dwcMaximumDepthInMeters must have no more than two decimal points and be >= 0 and <= 15000."
78
78
  end
79
79
  if self.dwcMinimumElevationInMeters && !Validator.valid_depth_elevation(value: self.dwcMinimumElevationInMeters)
80
- raise PropertyValueInvalid, "#{self.class} is invalid. Accepted value for dwcMinimumElevationInMeters must have no more than two decimal points and be less than or equal to 15000."
80
+ raise PropertyValueInvalid, "#{self.class} is invalid. Accepted value for dwcMinimumElevationInMeters must have no more than two decimal points and be >= 0 and <= 15000."
81
81
  end
82
82
  if self.dwcMaximumElevationInMeters && !Validator.valid_depth_elevation(value: self.dwcMaximumElevationInMeters)
83
- raise PropertyValueInvalid, "#{self.class} is invalid. Accepted value for dwcMaximumElevationInMeters must have no more than two decimal points and be less than or equal to 15000."
83
+ raise PropertyValueInvalid, "#{self.class} is invalid. Accepted value for dwcMaximumElevationInMeters must have no more than two decimal points and be >= 0 and <= 15000."
84
84
  end
85
85
  super
86
86
  end
@@ -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 = 7
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.7.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-21 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