ddr-core 1.10.0 → 1.12.1

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: 7590f4fdb1a8818a13de50cf6f22098ddc0adddf604720776e863ae276a22319
4
- data.tar.gz: eda82847e9603d0099432f6118402bdfa5cce83c199f69a724f234a9f890528d
3
+ metadata.gz: b2fb22566402591b70a20f82b4eb16431e59d2b2cac43598a98177c514dc881b
4
+ data.tar.gz: c1c6c7c5499a5240d884f99e58e48affb3b1db774d6af4e8aafeb53875384981
5
5
  SHA512:
6
- metadata.gz: b02451763ade3265563334b0e5a024c4db4efb23b4a5d396778fa875c0edeed31c7d348f627fdbc2fac021705456f5503af92cfc9ff4b640f25ce92cd7f69743
7
- data.tar.gz: 6d8738aa1ee63f7039ee40960877ac7173f3b2d3e4fdfe55de3773f7af652e155114b86117014e20db05239f66d60db6e4209beaecaeb7310d3f0373cc4f2bf7
6
+ metadata.gz: b7027ca1bd94ffc0f311156a868043de326ac3bbb98d4168d1a3fa074bc92842169b0af2a00cdf7ce47dfed65659f063386d455f4afb65e7147c7b993da722bd
7
+ data.tar.gz: a155703a1c63651a9e3b1b27ea0f0dcebe908b873c5355c97a1b60fe88197ac4ef5bb3cb6aa4ebcfef8865702ac319f3c8ab4f350a3fca5ea08e1fa357b19c50
@@ -9,7 +9,6 @@ module Ddr
9
9
  include HasIntermediateFile
10
10
  include HasMultiresImage
11
11
  include HasParent
12
- include HasStructMetadata
13
12
  include Streamable
14
13
 
15
14
  alias_method :item_id, :parent_id
@@ -4,8 +4,7 @@ module Ddr
4
4
 
5
5
  # An object can't be published if it's already published or not publishable
6
6
  # It can't be unpublished if it's already unpublished
7
- # It can't be made nonpublishable if it's already published (must be unpublished
8
- # first) or already nonpublishable
7
+ # It can't be made nonpublishable if it's already nonpublishable
9
8
  def call
10
9
  cannot :publish, Ddr::Resource do |obj|
11
10
  obj.published? || !obj.publishable?
@@ -14,7 +13,7 @@ module Ddr
14
13
  !obj.published? && !obj.nonpublishable?
15
14
  end
16
15
  cannot :make_nonpublishable, Ddr::Resource do |obj|
17
- obj.published? || !obj.publishable?
16
+ obj.nonpublishable?
18
17
  end
19
18
  end
20
19
 
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.10.0
4
+ version: 1.12.1
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-01 00:00:00.000000000 Z
14
+ date: 2022-04-04 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