dina 0.2.0.0 → 0.3.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: ac8691de71d4edf3e8c55134a2eab3907db3330ab74e40d12779c960178d5d23
4
- data.tar.gz: b3f6cb667ce6d648ff804ebec0d172b98801b877d38145d5e819e98f7e489f7d
3
+ metadata.gz: 9245c7481399aefbf8a290931823fafbc4970c2008ae4e299833c274825353c3
4
+ data.tar.gz: 448dcde684c17dd881ee2128f184871d05f690429199b92dd858c5c0735c22b8
5
5
  SHA512:
6
- metadata.gz: e9ba7de4e15555f92494770785e1ac42f97cea709a0542dfedce95fe19227536c36ef6bf5ee8cf009728c75ea4268a685f7bab88948ca277477c179ecfeb639b
7
- data.tar.gz: 75d2b0e52d5399cca2ab1b9785338d5a3f51b58aa1d82452eb103e6bbecce9b4642aab3e1c309a9a1625587edecfd4a380715ed454a72bb53497e8d0737393ae
6
+ metadata.gz: b8d3ea143e058dab38c1073d6d614539620ceb5b14f3dc394a3b4535e069449b2921fe2365208bb9f8b5f7b2b46afb830edbe5bd0471dbd6c518c3d6cc3b8e2d
7
+ data.tar.gz: 9c18d70386ba41207d9d341e3a700e413ba63ddd34d5f81fcacd1f21453d05c84de2738d28b131767a07c649af800da404dcc62475e83055c92bbd44009b29ef
@@ -1,4 +1,3 @@
1
-
2
1
  module Dina
3
2
  class ArrayCaster
4
3
  def self.cast(value, default)
@@ -11,7 +11,7 @@ module Dina
11
11
  property :createdBy, type: :string
12
12
  property :createdOn, type: :time
13
13
 
14
- has_many :attachment, class_name: "ObjectStore"
14
+ has_many :attachment, class_name: "Attachment"
15
15
 
16
16
  validates_presence_of :group, message: "group is required"
17
17
  validates_presence_of :name, message: "name is required"
@@ -4,8 +4,10 @@ module Dina
4
4
  class Attachment < BaseModel
5
5
  property :id, type: :string, default: SecureRandom.uuid
6
6
 
7
- belongs_to :material_sample, shallow_path: true
8
- belongs_to :project, shallow_path: true
7
+ belongs_to :material_sample, shallow_path: true, class_name: "MaterialSample"
8
+ belongs_to :collecting_event, shallow_path: true, class_name: "CollectingEvent"
9
+ belongs_to :project, shallow_path: true, class_name: "Project"
10
+ belongs_to :transaction, shallow_path: true, class_name: "Transaction"
9
11
 
10
12
  def self.endpoint_path
11
13
  "collection-api/"
@@ -15,7 +15,7 @@ module Dina
15
15
  property :createdBy, type: :string
16
16
  property :createdOn, type: :time
17
17
 
18
- has_one :institution, class_name: "Institution"
18
+ belongs_to :institution, shallow_path: true, class_name: "Institution"
19
19
  has_one :parent_collection, class_name: "Collection"
20
20
 
21
21
  validates_presence_of :group, message: "group is required"
@@ -1,40 +1,44 @@
1
- require_rel 'base_model'
2
-
3
1
  module Dina
4
- class File < BaseModel
5
- property :id, type: :string, default: SecureRandom.uuid
2
+ class File
3
+ attr_accessor :file_path, :group
6
4
 
7
- def self.endpoint_path
8
- "objectstore-api/"
5
+ def initialize
9
6
  end
10
7
 
11
- def self.table_name
12
- "file"
8
+ def endpoint_path
9
+ "objectstore-api/"
13
10
  end
14
11
 
15
- #TODO: a "bucket" as part of the path (=table_name) to permit POST with necessary permissions
16
- #TODO: body not JSON but an asset
17
-
18
- =begin
12
+ def table_name
13
+ "file/#{@group}"
14
+ end
19
15
 
20
- def initialize(bucket:, file:)
21
- if !file.is_a?(::File) || !::File.exist?(file)
22
- raise Exception.new "file is not of class File or does not exist"
23
- end
24
- super
25
- set_headers
16
+ def url
17
+ Dina::Authentication.endpoint_url + endpoint_path + table_name
26
18
  end
27
19
 
28
- private
20
+ def file
21
+ ::File.new(file_path)
22
+ end
29
23
 
30
- def set_headers
31
- headers = {
32
- content_type: "application/octet-stream",
33
- content_disposition: "form-data; name=file; filename=#{::File.basename(file.path)}"
34
- }
35
- self.custom_headers.merge(headers)
24
+ 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
31
+ response = RestClient::Request.execute(
32
+ method: :post,
33
+ headers: { authorization: Dina::Authentication.header },
34
+ url: url,
35
+ payload: {
36
+ multipart: true,
37
+ file: file
38
+ }
39
+ )
40
+ JSON.parse(response, symbolize_names: true)
36
41
  end
37
- =end
38
42
 
39
43
  end
40
44
  end
@@ -16,52 +16,5 @@ module Dina
16
16
  "identifier"
17
17
  end
18
18
 
19
- =begin
20
- TODO: fix because identifier has independent model now
21
-
22
- def self.find_by_orcid(orcid)
23
- if orcid.include? "http"
24
- orcid = orcid.orcid_from_url
25
- end
26
- if orcid.is_orcid?
27
- orcid = "https://orcid.org/#{orcid}"
28
- where("identifiers.uri": orcid).all.first
29
- else
30
- nil
31
- end
32
- end
33
-
34
- def self.find_by_wikidata(wikidata)
35
- if wikidata.include? "http"
36
- wikidata = wikidata.wiki_from_url
37
- end
38
- if wikidata.is_wiki_id?
39
- wikidata = "http://www.wikidata.org/entity/#{wikidata}"
40
- where("identifiers.uri": wikidata).all.first
41
- else
42
- nil
43
- end
44
- where("identifiers.uri": wikidata).all.first
45
- end
46
-
47
- def orcid
48
- identifiers.select{|o| o[:type] == "ORCID"}.first[:uri]
49
- end
50
-
51
- def orcid=(uri)
52
- identifiers.delete_if{|o| o[:type] == "ORCID"}
53
- identifiers << { type: "ORCID", uri: uri }
54
- end
55
-
56
- def wikidata
57
- identifiers.select{|o| o[:type] == "WIKIDATA"}.first[:uri]
58
- end
59
-
60
- def wikidata=(id)
61
- identifiers.delete_if{|o| o[:type] == "WIKIDATA"}
62
- identifiers << { type: "WIKIDATA", uri: uri }
63
- end
64
- =end
65
-
66
19
  end
67
20
  end
@@ -12,7 +12,6 @@ module Dina
12
12
  property :group, type: :string
13
13
  property :managedAttributes, type: :object
14
14
  property :dwcOtherCatalogNumbers, type: :array
15
- property :preparationMethod, type: :string
16
15
  property :preservationType, type: :string
17
16
  property :preparationFixative, type: :string
18
17
  property :preparationMaterials, type: :string
@@ -24,6 +23,9 @@ module Dina
24
23
  property :stateChangedOn, type: :time
25
24
  property :stateChangeRemarks, type: :string
26
25
  property :materialSampleRemarks, type: :string
26
+ property :restrictionFieldsExtension, type: :array
27
+ property :restrictionRemarks, type: :string
28
+ property :isRestricted, type: :boolean
27
29
  property :materialSampleChildren, type: :array
28
30
  property :associations, type: :array, default: []
29
31
  property :tags, type: :array, default: []
@@ -34,18 +36,18 @@ module Dina
34
36
  property :hierarchy, type: :object
35
37
  property :allowDuplicateName, type: :boolean
36
38
 
37
- has_one :collection
38
- has_one :parent_material_sample, class_name: "MaterialSample"
39
+ has_one :collection, class_name: "Collection"
39
40
  has_one :collecting_event, class_name: "CollectingEvent"
40
- has_one :preparation_type
41
- has_one :prepared_by, class_name: "Person"
42
- has_one :storage_unit
43
- has_one :acquisition_event
44
-
45
- has_many :assemblages, class_name: "Assemblage"
41
+ has_one :preparation_type, class_name: "PreparationType"
42
+ has_one :preparation_method, class_name: "PreparationMethod"
43
+ has_one :parent_material_sample, class_name: "MaterialSample"
44
+ has_one :preparation_protocol, class_name: "Protocol"
45
+ has_one :acquisition_event, class_name: "AcquisitionEvent"
46
+ has_one :storage_unit, class_name: "StorageUnit"
47
+ has_many :prepared_by, class_name: "Person"
48
+ has_many :attachment, class_name: "Attachment"
46
49
  has_many :projects, class_name: "Project"
47
- has_many :attachment, class_name: "Attachment" #TODO: error requesting Dina::MaterialSample::Metadatum
48
- has_many :preparation_attachment, class_name: "Attachment" #TODO: error requesting Dina::MaterialSample::Metadatum
50
+ has_many :assemblages, class_name: "Assemblage"
49
51
  has_many :organism, class_name: "Organism"
50
52
 
51
53
  validates_presence_of :group, message: "group is required"
@@ -3,34 +3,31 @@ require_rel 'base_model'
3
3
  module Dina
4
4
  class ObjectStore < BaseModel
5
5
  property :id, type: :string, default: SecureRandom.uuid
6
+ property :createdBy, type: :string
7
+ property :createdOn, type: :time
6
8
  property :group, type: :string
7
- property :dcType, type: :string
8
- property :originalFilename, type: :string
9
- property :bucket, type: :string
10
- property :dateTimeDigitized, type: :string
11
- property :fileIdentifier, type: :string
12
- property :fileExtension, type: :string
13
9
  property :dcFormat, type: :string
14
10
  property :dcType, type: :string
15
- property :acDigitizationDate, type: :time
11
+ property :acSubtype, type: :string
12
+ property :fileIdentifier, type: :string
13
+ property :bucket, type: :string
16
14
  property :acCaption, type: :string
15
+ property :acDigitizationDate, type: :time
17
16
  property :xmpMetadataDate, type: :time
18
- property :xmpRightsWebStatement, type: :string, default: "https://open.canada.ca/en/open-government-licence-canada"
19
- property :dcRights, type: :string, default: "© Her Majesty The Queen in Right of Canada, as represented by the Minister of Agriculture and Agri-Food | © Sa Majesté la Reine du chef du Canada, représentée par le ministre de l’Agriculture et de l’Agroalimentaire"
20
- property :xmpRightsOwner, type: :string, default: "Government of Canada"
21
- property :xmpRightsUsageTerms, type: :string, default: "Government of Canada Usage Term"
22
- property :orientation, type: :integer
23
17
  property :originalFilename, type: :string
18
+ property :fileExtension, type: :string
24
19
  property :acHashFunction, type: :string, default: "SHA-1"
25
20
  property :acHashValue, type: :string
26
- property :acSubtype, type: :string
21
+ property :xmpRightsUsageTerms, type: :string, default: "Government of Canada Usage Term"
22
+ property :xmpRightsWebStatement, type: :string, default: "https://open.canada.ca/en/open-government-licence-canada"
23
+ property :dcRights, type: :string, default: "© Her Majesty The Queen in Right of Canada, as represented by the Minister of Agriculture and Agri-Food | © Sa Majesté la Reine du chef du Canada, représentée par le ministre de l’Agriculture et de l’Agroalimentaire"
24
+ property :xmpRightsOwner, type: :string, default: "Government of Canada"
27
25
  property :publiclyReleasable, type: :boolean, default: true
28
26
  property :notPubliclyReleasableReason, type: :string
27
+ property :managedAttributes, type: :object
29
28
  property :acTags, type: :string
29
+ property :orientation, type: :integer
30
30
  property :resourceExternalURL, type: :string
31
- property :managedAttributes, type: :object
32
- property :createdBy, type: :string
33
- property :createdOn, type: :time
34
31
 
35
32
  has_one :ac_metadata_creator, class_name: "Person"
36
33
  has_one :dc_creator, class_name: "Person"
@@ -46,5 +43,14 @@ module Dina
46
43
  "metadata"
47
44
  end
48
45
 
46
+ private
47
+
48
+ def on_before_save
49
+ if self.bucket.nil?
50
+ self.bucket = self.group
51
+ end
52
+ super
53
+ end
54
+
49
55
  end
50
56
  end
@@ -19,21 +19,5 @@ module Dina
19
19
  "managed-attribute"
20
20
  end
21
21
 
22
- def english_description=(desc)
23
- description[:en] = desc
24
- end
25
-
26
- def english_description
27
- description[:en]
28
- end
29
-
30
- def french_description=(desc)
31
- description[:fr] = desc
32
- end
33
-
34
- def french_description
35
- description[:fr]
36
- end
37
-
38
22
  end
39
23
  end
@@ -3,6 +3,10 @@ require_rel 'base_model'
3
3
  module Dina
4
4
  class ObjectSubtype < BaseModel
5
5
  property :id, type: :string, default: SecureRandom.uuid
6
+ property :createdBy, type: :string
7
+ property :createdOn, type: :time
8
+ property :dcType, type: :string
9
+ property :acSubtype, type: :string
6
10
 
7
11
  def self.endpoint_path
8
12
  "objectstore-api/"
@@ -3,7 +3,6 @@ require_rel 'base_model'
3
3
  module Dina
4
4
  class Organization < BaseModel
5
5
  property :id, type: :string, default: SecureRandom.uuid
6
- #NOTE: should be type: :multilingual_description but API not adjusted
7
6
  property :names, type: :array, default: [{languageCode: "EN", name: nil}, {languageCode: "FR", name: nil}]
8
7
  property :aliases, type: :array, default: []
9
8
  property :createdBy, type: :string
@@ -13,8 +13,8 @@ module Dina
13
13
  property :createdBy, type: :string
14
14
  property :createdOn, type: :time
15
15
 
16
- has_many :organizations
17
- has_many :identifiers
16
+ has_many :organizations, class_name: "Organization"
17
+ has_many :identifiers, class_name: "Identifier"
18
18
 
19
19
  validates_presence_of :familyNames, message: "familyNames is required"
20
20
  validates_presence_of :displayName
@@ -0,0 +1,23 @@
1
+ require_rel 'base_model'
2
+
3
+ module Dina
4
+ class PreparationMethod < BaseModel
5
+ property :id, type: :string, default: SecureRandom.uuid
6
+ property :group, type: :string
7
+ property :name, type: :string
8
+ property :multilingualDescription, type: :multilingual_description
9
+ property :createdBy, type: :string
10
+ property :createdOn, type: :time
11
+
12
+ validates_presence_of :group, message: "group is required"
13
+
14
+ def self.endpoint_path
15
+ "collection-api/"
16
+ end
17
+
18
+ def self.table_name
19
+ "preparation-method"
20
+ end
21
+
22
+ end
23
+ end
@@ -12,7 +12,7 @@ module Dina
12
12
  property :createdBy, type: :string
13
13
  property :createdOn, type: :time
14
14
 
15
- has_many :attachment, class_name: "ObjectStore"
15
+ has_many :attachment, class_name: "Attachment"
16
16
 
17
17
  validates_presence_of :group, message: "group is required"
18
18
 
@@ -9,7 +9,7 @@ module Dina
9
9
  property :createdBy, type: :string
10
10
  property :createdOn, type: :time
11
11
 
12
- has_many :attachment, class_name: "ObjectStore"
12
+ has_many :attachment, class_name: "Attachment"
13
13
 
14
14
  validates_presence_of :group, message: "group is required"
15
15
 
@@ -22,7 +22,7 @@ module Dina
22
22
  property :createdOn, type: :time
23
23
 
24
24
  has_many :material_samples, class_name: "MaterialSample"
25
- has_many :attachment
25
+ has_many :attachment, class_name: "Attachment"
26
26
  has_many :involved_agents, class_name: "Person"
27
27
 
28
28
  validates_presence_of :group, message: "group is required"
data/lib/dina/version.rb CHANGED
@@ -2,7 +2,7 @@ module Dina
2
2
  class Version
3
3
 
4
4
  MAJOR = 0
5
- MINOR = 2
5
+ MINOR = 3
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.2.0.0
4
+ version: 0.3.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-28 00:00:00.000000000 Z
11
+ date: 2022-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_api_client
@@ -145,7 +145,6 @@ files:
145
145
  - lib/dina/models/assemblage.rb
146
146
  - lib/dina/models/attachment.rb
147
147
  - lib/dina/models/base_model.rb
148
- - lib/dina/models/bucket.rb
149
148
  - lib/dina/models/collecting_event.rb
150
149
  - lib/dina/models/collecting_method.rb
151
150
  - lib/dina/models/collection.rb
@@ -162,6 +161,7 @@ files:
162
161
  - lib/dina/models/organism.rb
163
162
  - lib/dina/models/organization.rb
164
163
  - lib/dina/models/person.rb
164
+ - lib/dina/models/preparation_method.rb
165
165
  - lib/dina/models/preparation_type.rb
166
166
  - lib/dina/models/project.rb
167
167
  - lib/dina/models/protocol.rb
@@ -1,8 +0,0 @@
1
- require_rel 'base_model'
2
- require_rel 'file'
3
-
4
- module Dina
5
- class Bucket < File
6
- property :id, type: :string, default: SecureRandom.uuid
7
- end
8
- end