dina 0.3.0.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9245c7481399aefbf8a290931823fafbc4970c2008ae4e299833c274825353c3
4
- data.tar.gz: 448dcde684c17dd881ee2128f184871d05f690429199b92dd858c5c0735c22b8
3
+ metadata.gz: 4cae0ee74ed1a0967bb360af211c2ab37676dfdb39b54a377ec39b539e0f4301
4
+ data.tar.gz: 45ee9d1cda7f37da9fb5384690751dac5e5cc0fe30153cddf8306e11a20f7151
5
5
  SHA512:
6
- metadata.gz: b8d3ea143e058dab38c1073d6d614539620ceb5b14f3dc394a3b4535e069449b2921fe2365208bb9f8b5f7b2b46afb830edbe5bd0471dbd6c518c3d6cc3b8e2d
7
- data.tar.gz: 9c18d70386ba41207d9d341e3a700e413ba63ddd34d5f81fcacd1f21453d05c84de2738d28b131767a07c649af800da404dcc62475e83055c92bbd44009b29ef
6
+ metadata.gz: 60a62ece7262ab086b88002497bd55f1ea04059b94468134b7c93d35a3349deff0c3ed58c45f634dd07a3149e4895da1525c215aef1895258beb62cf5af0aba5
7
+ data.tar.gz: dba63bace34688530c56cb56af702af39fe36bcb7ba86bf664b1192a7186ca51207ef9cef2deed311993671127772deb4f149f99fd90619ad56408dc379882a7
@@ -81,11 +81,11 @@ module Dina
81
81
  end
82
82
 
83
83
  def access_token
84
- read_token[:access_token] rescue nil
84
+ read_token[:access_token]
85
85
  end
86
86
 
87
87
  def refresh_token
88
- read_token[:refresh_token] rescue nil
88
+ read_token[:refresh_token]
89
89
  end
90
90
 
91
91
  def auth_expiry
@@ -2,4 +2,5 @@ module Dina
2
2
  class DinaException < StandardError; end
3
3
  class TokenStoreFileNotFound < DinaException; end
4
4
  class ObjectInvalid < DinaException; end
5
+ class PropertyValueInvalid < ObjectInvalid; end
5
6
  end
@@ -3,16 +3,19 @@ require_rel 'base_model'
3
3
  module Dina
4
4
  class Derivative < BaseModel
5
5
  property :id, type: :string, default: SecureRandom.uuid
6
+ property :group, type: :string
6
7
  property :bucket, type: :string
7
8
  property :fileIdentifier, type: :string
8
9
  property :fileExtension, type: :string
9
10
  property :dcType, type: :string
10
- property :cdFormat, type: :string
11
+ property :dcFormat, type: :string
11
12
  property :acHashFunction, type: :string, default: "SHA-1"
12
13
  property :acHashValue, type: :string
13
14
  property :derivativeType, type: :string
14
15
 
15
- belongs_to :object_store, shallow_path: true
16
+ belongs_to :ac_derived_from, shallow_path: true, class_name: "ObjectStore"
17
+
18
+ validates_presence_of :group, message: "group is required"
16
19
 
17
20
  def self.endpoint_path
18
21
  "objectstore-api/"
@@ -22,5 +25,14 @@ module Dina
22
25
  "derivative"
23
26
  end
24
27
 
28
+ private
29
+
30
+ def on_before_save
31
+ if self.bucket.nil?
32
+ self.bucket = self.group
33
+ end
34
+ super
35
+ end
36
+
25
37
  end
26
38
  end
@@ -1,6 +1,16 @@
1
1
  module Dina
2
2
  class File
3
- attr_accessor :file_path, :group
3
+ attr_accessor :file_path, :group, :is_derivative, :id
4
+
5
+ def self.find(group:, id:)
6
+ obj = self.new
7
+ obj.group = group
8
+ RestClient::Request.execute(
9
+ method: :get,
10
+ headers: { authorization: Dina::Authentication.header },
11
+ url: obj.url + "/#{id}"
12
+ )
13
+ end
4
14
 
5
15
  def initialize
6
16
  end
@@ -22,22 +32,30 @@ module Dina
22
32
  end
23
33
 
24
34
  def save
25
- if group.nil?
26
- raise ObjectInvalid, "#{self.class} is invalid. group is required."
27
- end
28
- if file_path.nil? || !::File.exist?(file_path)
29
- raise ObjectInvalid, "#{self.class} is invalid. file not found in file_path."
30
- end
35
+ validate_params
31
36
  response = RestClient::Request.execute(
32
37
  method: :post,
33
38
  headers: { authorization: Dina::Authentication.header },
34
- url: url,
39
+ url: (!is_derivative) ? url : url + "/derivative",
35
40
  payload: {
36
41
  multipart: true,
37
42
  file: file
38
43
  }
39
44
  )
40
- JSON.parse(response, symbolize_names: true)
45
+ json = JSON.parse(response, symbolize_names: true)
46
+ self.id = json[:uuid]
47
+ json
48
+ end
49
+
50
+ private
51
+
52
+ def validate_params
53
+ if group.nil?
54
+ raise ObjectInvalid, "#{self.class} is invalid. group is required."
55
+ end
56
+ if file_path.nil? || !::File.exist?(file_path)
57
+ raise ObjectInvalid, "#{self.class} is invalid. file not found in file_path."
58
+ end
41
59
  end
42
60
 
43
61
  end
@@ -6,14 +6,18 @@ module Dina
6
6
  property :group, type: :string
7
7
  property :name, type: :string
8
8
  property :key, type: :string
9
- property :managedAttributeType, type: :string #values = STRING or INTEGER
10
- property :managedAttributeComponent, type: :string #values = COLLECTING_EVENT, MATERIAL_SAMPLE, or DETERMINATION
9
+ property :managedAttributeType, type: :string
10
+ property :managedAttributeComponent, type: :string
11
11
  property :acceptedValues, type: :array
12
12
  property :multilingualDescription, type: :multilingual_description
13
13
  property :createdBy, type: :string
14
14
  property :createdOn, type: :time
15
15
 
16
16
  validates_presence_of :group, message: "group is required"
17
+ validates_presence_of :name, message: "name is required"
18
+ validates_presence_of :managedAttributeType, message: "managedAttributeType is required"
19
+
20
+ attr_accessor :accepted_components, :accepted_types
17
21
 
18
22
  def self.endpoint_path
19
23
  "collection-api/"
@@ -23,6 +27,25 @@ module Dina
23
27
  "managed-attribute"
24
28
  end
25
29
 
30
+ def self.accepted_components
31
+ [
32
+ "COLLECTING_EVENT",
33
+ "MATERIAL_SAMPLE",
34
+ "DETERMINATION",
35
+ "ASSEMBLAGE"
36
+ ]
37
+ end
38
+
39
+ def self.accepted_types
40
+ [
41
+ "INTEGER",
42
+ "STRING",
43
+ "PICKLIST",
44
+ "DATE",
45
+ "BOOL"
46
+ ]
47
+ end
48
+
26
49
  def english_description=(desc)
27
50
  description[:en] = desc
28
51
  end
@@ -39,5 +62,17 @@ module Dina
39
62
  description[:fr]
40
63
  end
41
64
 
65
+ private
66
+
67
+ def on_before_save
68
+ if !self.managedAttributeComponent.nil? && !self.class.accepted_components.include?(self.managedAttributeComponent)
69
+ raise PropertyValueInvalid, "#{self.class} is invalid. Accepted value for managedAttributeComponent is one of #{self.class.accepted_components.join(", ")}"
70
+ end
71
+ if !self.managedAttributeType.nil? && !self.class.accepted_types.include?(self.managedAttributeType)
72
+ raise PropertyValueInvalid, "#{self.class} is invalid. Accepted value for managedAttributeType is one of #{self.class.accepted_types.join(", ")}"
73
+ end
74
+ super
75
+ end
76
+
42
77
  end
43
78
  end
@@ -52,6 +52,9 @@ module Dina
52
52
 
53
53
  validates_presence_of :group, message: "group is required"
54
54
  validates_presence_of :materialSampleName, message: "materialSampleName is required"
55
+ validates_presence_of :materialSampleType, message: "materialSampleType is required"
56
+
57
+ attr_accessor :accepted_types
55
58
 
56
59
  def self.endpoint_path
57
60
  "collection-api/"
@@ -61,5 +64,23 @@ module Dina
61
64
  "material-sample"
62
65
  end
63
66
 
67
+ def self.accepted_types
68
+ [
69
+ "WHOLE_ORGANISM",
70
+ "ORGANISM_PART",
71
+ "MIXED_ORGANISMS",
72
+ "MOLECULAR_SAMPLE"
73
+ ]
74
+ end
75
+
76
+ private
77
+
78
+ def on_before_save
79
+ if !self.materialSampleType.nil? && !self.class.accepted_types.include?(self.materialSampleType)
80
+ raise PropertyValueInvalid, "#{self.class} is invalid. Accepted value for materialSampleType is one of #{self.class.accepted_types.join(", ")}"
81
+ end
82
+ super
83
+ end
84
+
64
85
  end
65
86
  end
@@ -35,6 +35,8 @@ module Dina
35
35
 
36
36
  validates_presence_of :group, message: "group is required"
37
37
 
38
+ attr_accessor :accepted_types
39
+
38
40
  def self.endpoint_path
39
41
  "objectstore-api/"
40
42
  end
@@ -43,11 +45,22 @@ module Dina
43
45
  "metadata"
44
46
  end
45
47
 
48
+ def self.accepted_types
49
+ [
50
+ "IMAGE",
51
+ "MOVING_IMAGE",
52
+ "SOUND",
53
+ "TEXT",
54
+ "DATASET",
55
+ "UNDETERMINED"
56
+ ]
57
+ end
58
+
46
59
  private
47
60
 
48
61
  def on_before_save
49
- if self.bucket.nil?
50
- self.bucket = self.group
62
+ if !self.dcType.nil? && !self.class.accepted_types.include?(self.dcType)
63
+ raise PropertyValueInvalid, "#{self.class} is invalid. Accepted value for dcType is one of #{self.class.accepted_types.join(", ")}"
51
64
  end
52
65
  super
53
66
  end
@@ -19,5 +19,14 @@ module Dina
19
19
  "managed-attribute"
20
20
  end
21
21
 
22
+ private
23
+
24
+ def on_before_save
25
+ if !self.managedAttributeType.nil? && !ManagedAttribute.accepted_types.include?(self.managedAttributeType)
26
+ raise PropertyValueInvalid, "#{self.class} is invalid. Accepted value for managedAttributeType is one of #{ManagedAttribute.accepted_types.join(", ")}"
27
+ end
28
+ super
29
+ end
30
+
22
31
  end
23
32
  end
@@ -15,5 +15,15 @@ module Dina
15
15
  def self.table_name
16
16
  "object-subtype"
17
17
  end
18
+
19
+ private
20
+
21
+ def on_before_save
22
+ if !self.dcType.nil? && !ObjectStore.accepted_types.include?(self.dcType)
23
+ raise PropertyValueInvalid, "#{self.class} is invalid. Accepted value for dcType is one of #{ObjectStore.accepted_types.join(", ")}"
24
+ end
25
+ super
26
+ end
27
+
18
28
  end
19
29
  end
@@ -30,9 +30,9 @@ module Dina
30
30
  # Finds a Person object using an email address
31
31
  #
32
32
  # @param email [String] an email address
33
- # @return Person [Object] a Person object
33
+ # @return array [Array] an array of Person objects
34
34
  def self.find_by_email(email)
35
- where("email": email).all.first
35
+ where("email": email).all
36
36
  end
37
37
 
38
38
  private
@@ -6,6 +6,7 @@ module Dina
6
6
  property :group, type: :string
7
7
  property :name, type: :string
8
8
  property :isInseperable, type: :boolean
9
+ property :gridLayoutDefinition, type: :object
9
10
  property :createdBy, type: :string
10
11
  property :createdOn, type: :time
11
12
 
@@ -27,6 +27,8 @@ module Dina
27
27
 
28
28
  validates_presence_of :group, message: "group is required"
29
29
 
30
+ attr_accessor :accepted_directions
31
+
30
32
  def self.endpoint_path
31
33
  "loan-transaction/"
32
34
  end
@@ -35,5 +37,21 @@ module Dina
35
37
  "transaction"
36
38
  end
37
39
 
40
+ def self.accepted_directions
41
+ [
42
+ "IN",
43
+ "OUT"
44
+ ]
45
+ end
46
+
47
+ private
48
+
49
+ def on_before_save
50
+ if !self.materialDirection.nil? && !self.class.accepted_directions.include?(self.materialDirection)
51
+ raise PropertyValueInvalid, "#{self.class} is invalid. Accepted value for materialDirection is one of #{self.class.accepted_directions.join(", ")}"
52
+ end
53
+ super
54
+ end
55
+
38
56
  end
39
57
  end
data/lib/dina/version.rb CHANGED
@@ -2,7 +2,7 @@ module Dina
2
2
  class Version
3
3
 
4
4
  MAJOR = 0
5
- MINOR = 3
5
+ MINOR = 4
6
6
  PATCH = 0
7
7
  BUILD = 0
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dina
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.0
4
+ version: 0.4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David P. Shorthouse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-29 00:00:00.000000000 Z
11
+ date: 2022-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_api_client