ddr-core 1.11.0 → 1.12.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: 24f4fed2b42d1f48074cd74968a711b515f908027a2b80c8d326f35241fcda3b
4
- data.tar.gz: d6c8439ba1348b4d150664d030969d6dfa7f39d115895a4cbfe3a0c1fe22590d
3
+ metadata.gz: 065474e311bb6fd9a3e68160663e2ff260e4a54bb776ca99b48aa495c661f640
4
+ data.tar.gz: c7feea4281623cece301fc5737b345a813e4209093653e434815e98dd7497925
5
5
  SHA512:
6
- metadata.gz: df5920709b822332092b9e27d7f9c244667841e47cdafc6ddbaadb60d18d744189872d7c916c4a1f866bf5f6312846ac11c29d15cfe041be5aa1eb7d9e465995
7
- data.tar.gz: 7ab212e5d5ad58ca775f676213034a504643a02ce20e15b76c39a0be7ecb6684f7eb995e1fe8c65a0112251081fc64fc15b062492c8083d269bd31f181fce429
6
+ metadata.gz: 1da3b51a355114e10ef605f394eabc2e9da4fbaaf559dd4bb339f5267c309ecd8c78b11f1cedf7a64e71db03f28f1f6722855b9925b89c5cccc0e2974a52ddb9
7
+ data.tar.gz: 00f40e7bb02b46faa8acb4f6da8789d224591f0f5ef98431c764c7be2cd8d4af3c4f9b9669579507c82dfd52015508f0f79f2ab1f279d90f05603f9c5866c12d
data/lib/ddr/core.rb CHANGED
@@ -20,11 +20,6 @@ module Ddr
20
20
  extend ActiveSupport::Autoload
21
21
  autoload :Agent
22
22
  autoload :Div
23
- autoload :File
24
- autoload :FileGrp
25
- autoload :FileSec
26
- autoload :FLocat
27
- autoload :Fptr
28
23
  autoload :MetsHdr
29
24
  autoload :Mptr
30
25
  autoload :StructMap
data/lib/ddr/structure.rb CHANGED
@@ -11,43 +11,16 @@ module Ddr
11
11
 
12
12
  TYPE_DEFAULT = 'default'.freeze
13
13
 
14
- # Based on the PCDM Extension 'Use' ontology -- https://github.com/duraspace/pcdm/blob/master/pcdm-ext/use.rdf
15
- USE_EXTRACTED_TEXT = 'ExtractedText'.freeze
16
- USE_INTERMEDIATE_FILE = 'IntermediateFile'.freeze
17
- USE_ORIGINAL_FILE = 'OriginalFile'.freeze
18
- USE_PRESERVATION_MASTER_FILE = 'PreservationMasterFile'.freeze
19
- USE_SERVICE_FILE = 'ServiceFile'.freeze
20
- USE_THUMBNAIL_IMAGE = 'ThumbnailImage'.freeze
21
- USE_TRANSCRIPT = 'Transcript'.freeze
22
-
23
- def filesec
24
- @filesec ||= Ddr::Structures::FileSec.new(fileSec_node)
25
- end
26
-
27
- def files
28
- @files ||= collect_files
29
- end
30
-
31
- def uses
32
- @uses ||= collect_uses
33
- end
34
-
35
- def structmap(type=nil)
36
- sm = type ? structMap_node(type) : structMap_nodes.first
37
- @structmap ||= Ddr::Structures::StructMap.new(sm)
38
- end
39
-
40
14
  def structmaps
41
15
  @structmaps ||= structMap_nodes.map { |sm| Ddr::Structures::StructMap.new(sm) }
42
16
  end
43
17
 
44
18
  def metshdr
45
- @metshdr ||= Ddr::Structures::MetsHdr.new(metsHdr_node)
19
+ @metshdr ||= Ddr::Structures::MetsHdr.new(metsHdr_node)
46
20
  end
47
21
 
48
22
  def creator
49
- @creator ||= metshdr.empty? ? nil
50
- : Ddr::Structures::MetsHdr.new(metsHdr_node).agents.first.name
23
+ metshdr.agents.first&.name
51
24
  end
52
25
 
53
26
  def repository_maintained?
@@ -55,89 +28,49 @@ module Ddr
55
28
  end
56
29
 
57
30
  def dereferenced_structure
58
- deref_struct = {}
59
- structmaps.each do |sm|
60
- deref_struct[sm.type] = sm.dereferenced_hash
61
- end
62
- deref_struct
31
+ Hash[structmaps.map { |sm| [sm.type, sm.dereferenced_hash] }]
63
32
  end
64
33
 
65
34
  def as_xml_document
66
35
  __getobj__
67
36
  end
68
37
 
69
- def add_metshdr(id:nil, createdate:nil, lastmoddate:nil, recordstatus:nil)
38
+ def add_metshdr(id: nil, createdate: nil, lastmoddate: nil, recordstatus: nil)
70
39
  metshdr = Ddr::Structures::MetsHdr.build(id: id, createdate: createdate, lastmoddate: lastmoddate,
71
- recordstatus: recordstatus, document: as_xml_document)
40
+ recordstatus: recordstatus, document: as_xml_document)
72
41
  root.add_child(metshdr)
73
42
  metshdr
74
43
  end
75
44
 
76
- def add_agent(parent:, id:nil, role:, otherrole:nil, type:nil, othertype:nil, name:nil)
45
+ def add_agent(parent:, id: nil, role:, otherrole: nil, type: nil, othertype: nil, name: nil)
77
46
  agent = Ddr::Structures::Agent.build(id: id, role: role, otherrole: otherrole, type: type,
78
- othertype: othertype, name: name, document: as_xml_document)
47
+ othertype: othertype, name: name, document: as_xml_document)
79
48
  parent.add_child(agent)
80
49
  agent
81
50
  end
82
51
 
83
- def add_filesec(id:nil)
84
- filesec = Ddr::Structures::FileSec.build(id: id, document: as_xml_document)
85
-
86
- root.add_child(filesec)
87
- filesec
88
- end
89
-
90
- def add_filegrp(parent:, id:nil, use:nil)
91
- filegrp = Ddr::Structures::FileGrp.build(id: id, use: use, document: as_xml_document)
92
- parent.add_child(filegrp)
93
- filegrp
94
- end
95
-
96
- def add_file(parent:, id: "id_" + SecureRandom.uuid, use:nil)
97
- file = Ddr::Structures::File.build(id: id, use: use, document: as_xml_document)
98
- parent.add_child(file)
99
- file
100
- end
101
-
102
- def add_flocat(parent:, id:nil, loctype:'ARK', otherloctype: nil, use:nil, href:)
103
- flocat = Ddr::Structures::FLocat.build(id: id, loctype: loctype, otherloctype: otherloctype, use: use,
104
- href: href, document: as_xml_document)
105
- parent.add_child(flocat)
106
- flocat
107
- end
108
-
109
- def add_structmap(id:nil, label:nil, type:)
52
+ def add_structmap(id: nil, label: nil, type:)
110
53
  structmap = Ddr::Structures::StructMap.build(id: id, label: label, type: type, document: as_xml_document)
111
54
  root.add_child(structmap)
112
55
  structmap
113
56
  end
114
57
 
115
- def add_div(parent:, id:nil, label:nil, order:nil, orderlabel: nil, type:nil)
58
+ def add_div(parent:, id: nil, label: nil, order: nil, orderlabel: nil, type: nil)
116
59
  div = Ddr::Structures::Div.build(id: id, label: label, order:order, orderlabel: orderlabel, type: type,
117
- document: as_xml_document)
60
+ document: as_xml_document)
118
61
  parent.add_child(div)
119
62
  div
120
63
  end
121
64
 
122
- def add_fptr(parent:, id: nil, fileid:)
123
- fptr = Ddr::Structures::Fptr.build(id: id, fileid: fileid, document: as_xml_document)
124
- parent.add_child(fptr)
125
- fptr
126
- end
127
-
128
- def add_mptr(parent:, id: nil, loctype:'ARK', otherloctype: nil, href:)
65
+ def add_mptr(parent:, id: nil, loctype: 'ARK', otherloctype: nil, href:)
129
66
  mptr = Ddr::Structures::Mptr.build(id: id, loctype: loctype, otherloctype: otherloctype, href: href,
130
- document: as_xml_document)
67
+ document: as_xml_document)
131
68
  parent.add_child(mptr)
132
69
  mptr
133
70
  end
134
71
 
135
72
  private
136
73
 
137
- def fileSec_node
138
- xpath("//xmlns:fileSec").first
139
- end
140
-
141
74
  def structMap_nodes
142
75
  xpath("//xmlns:structMap")
143
76
  end
@@ -150,33 +83,6 @@ module Ddr
150
83
  xpath("//xmlns:metsHdr")
151
84
  end
152
85
 
153
- def file_nodes
154
- xpath("//xmlns:file")
155
- end
156
-
157
- def flocat_nodes
158
- xpath("//xmlns:FLocat")
159
- end
160
-
161
- def collect_files
162
- files = {}
163
- file_nodes.each do |file_node|
164
- file = Ddr::Structures::File.new(file_node)
165
- files[file.id] = file
166
- end
167
- files
168
- end
169
-
170
- def collect_uses
171
- uses = {}
172
- flocat_nodes.each do |flocat_node|
173
- flocat = Ddr::Structures::FLocat.new(flocat_node)
174
- uses[flocat.effective_use] ||= []
175
- uses[flocat.effective_use] << flocat
176
- end
177
- uses
178
- end
179
-
180
86
  def self.xml_template
181
87
  Nokogiri::XML(
182
88
  '<mets xmlns="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/1999/xlink" />'
@@ -28,10 +28,6 @@ module Ddr::Structures
28
28
  xpath('xmlns:div').map { |node| Div.new(node) }
29
29
  end
30
30
 
31
- def fptrs
32
- xpath('xmlns:fptr').map { |node| Fptr.new(node) }
33
- end
34
-
35
31
  def mptrs
36
32
  xpath('xmlns:mptr').map { |node| Mptr.new(node) }
37
33
  end
@@ -43,7 +39,6 @@ module Ddr::Structures
43
39
  def dereferenced_hash
44
40
  contents = []
45
41
  contents.concat(divs.map { |div| div.dereferenced_hash }) unless divs.empty?
46
- contents.concat(fptrs.map { |fptr| fptr.dereferenced_hash }) unless fptrs.empty?
47
42
  contents.concat(mptrs.map { |mptr| mptr.dereferenced_hash }) unless mptrs.empty?
48
43
  dh = { id: id, label: label, order: order, orderlabel: orderlabel, type: type }.compact
49
44
  dh[:contents] = contents unless contents.empty?
@@ -24,12 +24,20 @@ module Ddr::Structures
24
24
  loctype == 'ARK'
25
25
  end
26
26
 
27
+ def urn?
28
+ loctype == 'URN'
29
+ end
30
+
27
31
  def ark
28
32
  href if ark?
29
33
  end
30
34
 
31
35
  def repo_id
32
- SolrDocument.find_by_permanent_id(ark).id if ark?
36
+ if ark?
37
+ SolrDocument.find_by_permanent_id(ark).id
38
+ elsif urn?
39
+ href.sub(/^urn:uuid:/, '')
40
+ end
33
41
  end
34
42
 
35
43
  def dereferenced_hash
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddr-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Coble
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2022-03-04 00:00:00.000000000 Z
14
+ date: 2022-03-24 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activeresource
@@ -416,11 +416,6 @@ files:
416
416
  - lib/ddr/structures/agent.rb
417
417
  - lib/ddr/structures/component_type_term.rb
418
418
  - lib/ddr/structures/div.rb
419
- - lib/ddr/structures/f_locat.rb
420
- - lib/ddr/structures/file.rb
421
- - lib/ddr/structures/file_grp.rb
422
- - lib/ddr/structures/file_sec.rb
423
- - lib/ddr/structures/fptr.rb
424
419
  - lib/ddr/structures/mets_hdr.rb
425
420
  - lib/ddr/structures/mptr.rb
426
421
  - lib/ddr/structures/struct_map.rb
@@ -452,7 +447,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
452
447
  - !ruby/object:Gem::Version
453
448
  version: '0'
454
449
  requirements: []
455
- rubygems_version: 3.3.8
450
+ rubygems_version: 3.3.10
456
451
  signing_key:
457
452
  specification_version: 4
458
453
  summary: Models used in the Duke Digital Repository
@@ -1,54 +0,0 @@
1
- module Ddr::Structures
2
- #
3
- # Wraps a Nokogiri (XML) 'FLocat' node
4
- #
5
- class FLocat < SimpleDelegator
6
-
7
- def id
8
- self['ID']
9
- end
10
-
11
- def loctype
12
- self['LOCTYPE']
13
- end
14
-
15
- def otherloctype
16
- self['OTHERLOCTYPE']
17
- end
18
-
19
- def use
20
- self['USE']
21
- end
22
-
23
- def href
24
- self['xlink:href']
25
- end
26
-
27
- def ark?
28
- loctype == 'ARK'
29
- end
30
-
31
- def ark
32
- href if ark?
33
- end
34
-
35
- def effective_use
36
- use ? use : File.new(parent).effective_use
37
- end
38
-
39
- def repo_id
40
- SolrDocument.find_by_permanent_id(ark).id if ark?
41
- end
42
-
43
- def self.build(args)
44
- node = Nokogiri::XML::Node.new('FLocat', args[:document])
45
- node['ID'] = args[:id] if args[:id]
46
- node['LOCTYPE'] = args[:loctype] if args[:loctype]
47
- node['OTHERLOCTYPE'] = args[:otherloctype] if args[:otherloctype]
48
- node['USE'] = args[:use] if args[:use]
49
- node['xlink:href'] = args[:href] if args[:href]
50
- node
51
- end
52
-
53
- end
54
- end
@@ -1,52 +0,0 @@
1
- module Ddr::Structures
2
- #
3
- # Wraps a Nokogiri (XML) 'file' node
4
- #
5
- class File < SimpleDelegator
6
-
7
- def id
8
- self['ID']
9
- end
10
-
11
- def use
12
- self['USE']
13
- end
14
-
15
- def files
16
- xpath('xmlns:file').map { |node| File.new(node) }
17
- end
18
-
19
- def flocats
20
- xpath('xmlns:FLocat').map { |node| FLocat.new(node) }
21
- end
22
-
23
- def effective_use
24
- if use
25
- use
26
- else
27
- case parent.name
28
- when "file"
29
- File.new(parent).effective_use
30
- when "fileGrp"
31
- FileGrp.new(parent).effective_use
32
- end
33
- end
34
- end
35
-
36
- def repo_ids
37
- flocats.map(&:repo_id)
38
- end
39
-
40
- def self.build(args)
41
- node = Nokogiri::XML::Node.new('file', args[:document])
42
- node['ID'] = args[:id] if args[:id]
43
- node['USE'] = args[:use] if args[:use]
44
- node
45
- end
46
-
47
- def self.find(structure, fileid)
48
- structure.files[fileid]
49
- end
50
-
51
- end
52
- end
@@ -1,35 +0,0 @@
1
- module Ddr::Structures
2
- #
3
- # Wraps a Nokogiri (XML) 'fileGrp' node
4
- #
5
- class FileGrp < SimpleDelegator
6
-
7
- def id
8
- self['ID']
9
- end
10
-
11
- def use
12
- self['USE']
13
- end
14
-
15
- def filegrps
16
- xpath('xmlns:filegrp').map { |node| FileGrp.new(node) }
17
- end
18
-
19
- def files
20
- xpath('xmlns:file').map { |node| File.new(node) }
21
- end
22
-
23
- def effective_use
24
- use
25
- end
26
-
27
- def self.build(args)
28
- node = Nokogiri::XML::Node.new('fileGrp', args[:document])
29
- node['ID'] = args[:id] if args[:id]
30
- node['USE'] = args[:use] if args[:use]
31
- node
32
- end
33
-
34
- end
35
- end
@@ -1,22 +0,0 @@
1
- module Ddr::Structures
2
- #
3
- # Wraps a Nokogiri (XML) 'fileSec' node
4
- #
5
- class FileSec < SimpleDelegator
6
-
7
- def id
8
- self['ID']
9
- end
10
-
11
- def filegrps
12
- xpath('xmlns:fileGrp').map { |node| FileGrp.new(node) }
13
- end
14
-
15
- def self.build(args)
16
- node = Nokogiri::XML::Node.new('fileSec', args[:document])
17
- node['ID'] = args[:id] if args[:id]
18
- node
19
- end
20
-
21
- end
22
- end
@@ -1,31 +0,0 @@
1
- module Ddr::Structures
2
- #
3
- # Wraps a Nokogiri (XML) 'fptr' node
4
- #
5
- class Fptr < SimpleDelegator
6
-
7
- def id
8
- self['ID']
9
- end
10
-
11
- def fileid
12
- self['FILEID']
13
- end
14
-
15
- def dereferenced_hash
16
- structure = Ddr::Structure.new(document)
17
- file = File.find(structure, fileid)
18
- repo_id = file.repo_ids.first
19
- use = file.flocats.first.effective_use
20
- { id: id, repo_id: repo_id, use: use }.compact
21
- end
22
-
23
- def self.build(args)
24
- node = Nokogiri::XML::Node.new('fptr', args[:document])
25
- node['ID'] = args[:id] if args[:id]
26
- node['FILEID'] = args[:fileid] if args[:fileid]
27
- node
28
- end
29
-
30
- end
31
- end