ddr-models 2.0.0.pre.2 → 2.0.0.pre.3

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
  SHA1:
3
- metadata.gz: daeaeb1ce7b02969ac1ba49962844211e7269aa5
4
- data.tar.gz: 64a81704bbaf023d596eba10c943285fef47dff7
3
+ metadata.gz: 8f7801ca7ccbd206fbcbf14c003e94e96ec27bd8
4
+ data.tar.gz: aa257065eb2e5633013edde3fbf9dc129c15a797
5
5
  SHA512:
6
- metadata.gz: 4bf9a10f346187f78ac98e17b6ec36fc739b7d67983fdc0c62b07edc0fb15d96aee79fb7b1f768daaed39e55fe1caad3615c13291927755e012510f995cd06b6
7
- data.tar.gz: 9c3b5476c2fe4450edb2c5026af2ffc09703cbd19ba9ec487cf95d025e7e526c5b16911e80465ee2569e3ab29f4daa531a47e164ecf5e8564033e520976a83d7
6
+ metadata.gz: bf466708eec60b41361dee92ece57b90628f6942e6ac6719f4b804ad90e79fa99861de1d3554b217858bc7018f527ff5f0958acca26d4e371871d313913ca4f4
7
+ data.tar.gz: 7c411fd9230412b7d90498125fdadb2e0768192261628dc09e7400927776043af9943b2c4f267cdc9697f714e0d27ce63ab918b4ec62e3f4d0d61c9e077bbeae
@@ -0,0 +1,9 @@
1
+ class ChangeEventsExceptionToText < ActiveRecord::Migration
2
+ def up
3
+ change_column :events, :exception, :text
4
+ end
5
+
6
+ def down
7
+ raise ActiveRecord::IrreversibleMigration
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class AddLimitToEventsException < ActiveRecord::Migration
2
+ def up
3
+ change_column :events, :exception, :text, limit: 65535
4
+ end
5
+
6
+ def down
7
+ raise ActiveRecord::IrreversibleMigration
8
+ end
9
+ end
data/lib/ddr/auth/user.rb CHANGED
@@ -1,62 +1,52 @@
1
- module Ddr
2
- module Auth
3
- module User
4
- extend ActiveSupport::Concern
1
+ module Ddr::Auth
2
+ module User
3
+ extend ActiveSupport::Concern
5
4
 
6
- included do
7
- include Blacklight::User
5
+ included do
6
+ delegate :can, :can?, :cannot, :cannot?, to: :ability
8
7
 
9
- has_many :events, inverse_of: :user, class_name: "Ddr::Events::Event"
8
+ validates_uniqueness_of :username, case_sensitive: false
9
+ validates_format_of :email, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/
10
10
 
11
- delegate :can, :can?, :cannot, :cannot?, to: :ability
11
+ devise :database_authenticatable, :omniauthable, omniauth_providers: [:shibboleth]
12
12
 
13
- validates_uniqueness_of :username, :case_sensitive => false
14
- validates_format_of :email, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/
15
-
16
- devise :database_authenticatable, :omniauthable, omniauth_providers: [:shibboleth]
13
+ class_attribute :user_key_attribute
14
+ self.user_key_attribute = Devise.authentication_keys.first
15
+ end
17
16
 
18
- class_attribute :user_key_attribute
19
- self.user_key_attribute = Devise.authentication_keys.first
17
+ module ClassMethods
18
+ def find_by_user_key(key)
19
+ send("find_by_#{user_key_attribute}", key)
20
20
  end
21
21
 
22
- module ClassMethods
23
- def find_by_user_key(key)
24
- send("find_by_#{user_key_attribute}", key)
25
- end
26
-
27
- def from_omniauth(auth)
28
- user = find_by_user_key(auth.uid) ||
29
- new(user_key_attribute => auth.uid, :password => Devise.friendly_token)
30
- user.update!(email: auth.info.email,
31
- display_name: auth.info.name,
32
- first_name: auth.info.first_name,
33
- last_name: auth.info.last_name,
34
- nickname: auth.info.nickname)
35
- user
36
- end
22
+ def from_omniauth(auth)
23
+ user = find_by_user_key(auth.uid) ||
24
+ new(user_key_attribute => auth.uid, :password => Devise.friendly_token)
25
+ user.update!(email: auth.info.email,
26
+ display_name: auth.info.name,
27
+ first_name: auth.info.first_name,
28
+ last_name: auth.info.last_name,
29
+ nickname: auth.info.nickname)
30
+ user
37
31
  end
32
+ end
38
33
 
39
- # Copied from Hydra::User
40
- def user_key
41
- send(user_key_attribute)
42
- end
34
+ # Copied from Hydra::User
35
+ def user_key
36
+ send(user_key_attribute)
37
+ end
43
38
 
44
- def to_s
45
- user_key
46
- end
39
+ def to_s
40
+ user_key
41
+ end
47
42
 
48
- def agent
49
- user_key
50
- end
43
+ def agent
44
+ user_key
45
+ end
51
46
 
52
- def ability
53
- # warn "[DEPRECATION] `Ddr::Auth::User#ability` is deprecated." \
54
- # " In a web context, please use the `current_ability` helper." \
55
- # " Otherwise, please use `Ddr::Auth::AbilityFactory.call(user)`" \
56
- # " to create an ability instance for the user."
57
- @ability ||= AbilityFactory.call(self)
58
- end
59
-
47
+ def ability
48
+ @ability ||= AbilityFactory.call(self)
60
49
  end
50
+
61
51
  end
62
52
  end
@@ -2,8 +2,6 @@ module Ddr
2
2
  module Events
3
3
  class Event < ActiveRecord::Base
4
4
 
5
- belongs_to :user, inverse_of: :events
6
-
7
5
  # ActiveSupport::Notifications::Instrumenter sets payload[:exception]
8
6
  # to an array of [<exception class name>, <exception message>]
9
7
  # and we want to store this data in a string field.
@@ -95,17 +93,10 @@ module Ddr
95
93
  end
96
94
 
97
95
  # Object getter and setter
98
-
99
96
  def object
100
97
  @object ||= ActiveFedora::Base.find(pid) if pid
101
98
  end
102
99
 
103
- # Sets user_key to user.user_key
104
- # For compatibility with ddr-models <= 1.9.0
105
- def user=(user)
106
- self.user_key = user.user_key
107
- end
108
-
109
100
  def object=(obj)
110
101
  raise ArgumentError, "Can't set to new object" if obj.new_record?
111
102
  self.pid = obj.pid
@@ -125,6 +116,10 @@ module Ddr
125
116
  event_date_time.utc.strftime DATE_TIME_FORMAT
126
117
  end
127
118
 
119
+ def user=(user)
120
+ self.user_key = user.user_key
121
+ end
122
+
128
123
  protected
129
124
 
130
125
  def set_defaults
@@ -14,13 +14,14 @@ module Ddr
14
14
  CONTENT_CONTROL_GROUP = solr_name :content_control_group, :searchable, type: :string
15
15
  CONTENT_SIZE = solr_name :content_size, :stored_sortable, type: :integer
16
16
  CONTENT_SIZE_HUMAN = solr_name :content_size_human, :symbol
17
+ CREATOR_FACET = solr_name :creator_facet, :facetable
18
+ DATE_FACET = solr_name :date_facet, :facetable
19
+ DATE_SORT = solr_name :date_sort, :sortable
17
20
  DEFAULT_LICENSE_DESCRIPTION = solr_name :default_license_description, type: :string
18
21
  DEFAULT_LICENSE_TITLE = solr_name :default_license_title, type: :string
19
22
  DEFAULT_LICENSE_URL = solr_name :default_license_url, type: :string
20
23
  DISPLAY_FORMAT = solr_name :display_format, :stored_sortable
21
24
  EXTRACTED_TEXT = solr_name :extracted_text, :searchable, type: :text
22
- FILE_GROUP = solr_name :struct_metadata__file_group, :stored_sortable
23
- FILE_USE = solr_name :struct_metadata__file_use, :stored_sortable
24
25
  HAS_MODEL = solr_name :has_model, :symbol
25
26
  IDENTIFIER_ALL = solr_name :identifier_all, :symbol
26
27
  INTERNAL_URI = solr_name :internal_uri, :stored_sortable
@@ -46,11 +47,11 @@ module Ddr
46
47
  OBJECT_STATE = solr_name :object_state, :stored_sortable
47
48
  OBJECT_CREATE_DATE = solr_name :system_create, :stored_sortable, type: :date
48
49
  OBJECT_MODIFIED_DATE = solr_name :system_modified, :stored_sortable, type: :date
49
- ORDER = solr_name :struct_metadata__order, :stored_sortable, type: :integer
50
50
  PERMANENT_ID = solr_name :permanent_id, :stored_sortable, type: :string
51
51
  PERMANENT_URL = solr_name :permanent_url, :stored_sortable, type: :string
52
52
  POLICY_ROLE = solr_name :policy_role, :facetable, type: :string
53
53
  RESOURCE_ROLE = solr_name :resource_role, :facetable, type: :string
54
+ STRUCT_MAPS = solr_name :struct_maps, :stored_sortable
54
55
  TITLE = solr_name :title, :stored_sortable
55
56
  WORKFLOW_STATE = solr_name :workflow_state, :stored_sortable
56
57
 
@@ -40,10 +40,10 @@ module Ddr
40
40
  end
41
41
 
42
42
  def create_div(stru)
43
- div_count = stru.structMap('default').xpath('xmlns:div').size
43
+ div_count = stru.structMap_node('default').xpath('xmlns:div').size
44
44
  div = Nokogiri::XML::Node.new('div', stru.as_xml_document)
45
45
  div['ORDER'] = div_count + 1
46
- stru.structMap('default').add_child(div)
46
+ stru.structMap_node('default').add_child(div)
47
47
  div
48
48
  end
49
49
 
@@ -17,14 +17,15 @@ module Ddr
17
17
  WORKFLOW_STATE => workflow_state,
18
18
  LOCAL_ID => local_id,
19
19
  ADMIN_SET => admin_set,
20
- ADMIN_SET_FACET => admin_set_facet,
21
- COLLECTION_FACET => collection_facet,
22
20
  DISPLAY_FORMAT => display_format,
23
- PERMANENT_ID => permanent_id,
24
- PERMANENT_URL => permanent_url,
25
- ACCESS_ROLE => roles.to_json,
26
- RESOURCE_ROLE => roles.in_resource_scope.agents,
27
- POLICY_ROLE => roles.in_policy_scope.agents,
21
+ PERMANENT_ID => permanent_id,
22
+ PERMANENT_URL => permanent_url,
23
+ ACCESS_ROLE => roles.to_json,
24
+ RESOURCE_ROLE => roles.in_resource_scope.agents,
25
+ POLICY_ROLE => roles.in_policy_scope.agents,
26
+ CREATOR_FACET => creator,
27
+ DATE_FACET => date,
28
+ DATE_SORT => date_sort
28
29
  }
29
30
  if respond_to? :fixity_checks
30
31
  last_fixity_check = fixity_checks.last
@@ -50,6 +51,9 @@ module Ddr
50
51
  if has_multires_image?
51
52
  fields[MULTIRES_IMAGE_FILE_PATH] = multires_image_file_path
52
53
  end
54
+ if has_struct_metadata?
55
+ fields[STRUCT_MAPS] = structure.struct_maps.to_json
56
+ end
53
57
  if has_extracted_text?
54
58
  fields[EXTRACTED_TEXT] = extractedText.content
55
59
  end
@@ -60,6 +64,12 @@ module Ddr
60
64
  fields[DEFAULT_LICENSE_DESCRIPTION] = default_license_description
61
65
  fields[DEFAULT_LICENSE_TITLE] = default_license_title
62
66
  fields[DEFAULT_LICENSE_URL] = default_license_url
67
+ fields[ADMIN_SET_FACET] = admin_set_facet
68
+ fields[COLLECTION_FACET] = collection_facet
69
+ end
70
+ if is_a? Item
71
+ fields[ADMIN_SET_FACET] = admin_set_facet
72
+ fields[COLLECTION_FACET] = collection_facet
63
73
  end
64
74
  fields
65
75
  end
@@ -91,6 +101,10 @@ module Ddr
91
101
  associated_collection.internal_uri if associated_collection.present?
92
102
  end
93
103
 
104
+ def date_sort
105
+ date.first
106
+ end
107
+
94
108
  end
95
109
  end
96
110
  end
@@ -216,6 +216,16 @@ module Ddr
216
216
  get(Ddr::IndexFields::DISPLAY_FORMAT)
217
217
  end
218
218
 
219
+ def struct_maps
220
+ JSON.parse(fetch(Ddr::IndexFields::STRUCT_MAPS))
221
+ rescue
222
+ {}
223
+ end
224
+
225
+ def struct_map(type='default')
226
+ struct_maps.present? ? struct_maps.fetch(type) : nil
227
+ end
228
+
219
229
  private
220
230
 
221
231
  def targets_query
@@ -2,7 +2,7 @@ module Ddr
2
2
  module Models
3
3
  class StructDiv
4
4
 
5
- attr_accessor :id, :label, :order, :orderlabel, :type, :objs, :divs
5
+ attr_accessor :id, :label, :order, :orderlabel, :type, :fptrs, :divs
6
6
 
7
7
  def initialize(structmap_or_div_node)
8
8
  @id = structmap_or_div_node['ID']
@@ -10,7 +10,7 @@ module Ddr
10
10
  @order = structmap_or_div_node['ORDER']
11
11
  @orderlabel = structmap_or_div_node['ORDERLABEL']
12
12
  @type = structmap_or_div_node['TYPE']
13
- @objs = obj_pids(structmap_or_div_node) if structmap_or_div_node.node_name == "div"
13
+ @fptrs = fptr_pids(structmap_or_div_node) if structmap_or_div_node.node_name == "div"
14
14
  @divs = subdivs(structmap_or_div_node).sort
15
15
  end
16
16
 
@@ -18,21 +18,31 @@ module Ddr
18
18
  self.order.to_i <=> other.order.to_i
19
19
  end
20
20
 
21
- def objects?
22
- objs.present?
21
+ def pids
22
+ collect_pids(self)
23
23
  end
24
24
 
25
- def object_pids
26
- objs
25
+ def docs
26
+ query = ActiveFedora::SolrService.construct_query_for_pids(pids)
27
+ results = ActiveFedora::SolrService.query(query, rows: 999999)
28
+ results.each_with_object({}) do |r, memo|
29
+ memo[r["id"]] = ::SolrDocument.new(r)
30
+ end
27
31
  end
28
32
 
29
33
  def objects
30
- objs.map { |pid| ActiveFedora::Base.find(pid) }
34
+ pids.each_with_object({}) do |pid, memo|
35
+ memo[pid] = ActiveFedora::Base.find(pid)
36
+ end
37
+ end
38
+
39
+ def as_json(options={})
40
+ super.compact
31
41
  end
32
42
 
33
43
  private
34
44
 
35
- def obj_pids(div_node)
45
+ def fptr_pids(div_node)
36
46
  div_node.xpath('xmlns:fptr').map { |fptr_node| fptr_node["CONTENTIDS"].gsub('info:fedora/', '') }
37
47
  end
38
48
 
@@ -40,6 +50,14 @@ module Ddr
40
50
  structmap_or_div_node.xpath('xmlns:div').map { |div_node| Ddr::Models::StructDiv.new(div_node) }
41
51
  end
42
52
 
53
+ def collect_pids(structdiv)
54
+ pids = structdiv.divs.each_with_object([]) do |div, memo|
55
+ memo << collect_pids(div)
56
+ end
57
+ pids << structdiv.fptrs if structdiv.fptrs
58
+ pids.flatten
59
+ end
60
+
43
61
  end
44
62
  end
45
63
  end
@@ -9,11 +9,11 @@ module Ddr
9
9
  super
10
10
  end
11
11
 
12
- def struct_divs
13
- @struct_divs ||= build_struct_divs(structMaps)
12
+ def struct_maps
13
+ @struct_maps ||= build_struct_maps(structMap_nodes)
14
14
  end
15
15
 
16
- def structMap(type='default')
16
+ def structMap_node(type='default')
17
17
  xpath("//xmlns:structMap[@TYPE='#{type}']").first
18
18
  end
19
19
 
@@ -23,18 +23,18 @@ module Ddr
23
23
 
24
24
  private
25
25
 
26
- def structMaps
26
+ def structMap_nodes
27
27
  xpath("//xmlns:structMap")
28
28
  end
29
29
 
30
- def build_struct_divs(structMaps)
31
- sdivs = {}
32
- structMaps.each do |structMap|
33
- type = structMap['TYPE'] || 'default'
34
- raise StandardError, "Multiple '#{type}' structMaps" if sdivs[type].present?
35
- sdivs[type] = Ddr::Models::StructDiv.new(structMap)
30
+ def build_struct_maps(structMap_nodes)
31
+ smaps = {}
32
+ structMap_nodes.each do |structMap_node|
33
+ type = structMap_node['TYPE'] || 'default'
34
+ raise StandardError, "Multiple '#{type}' structMaps" if smaps[type].present?
35
+ smaps[type] = Ddr::Models::StructDiv.new(structMap_node)
36
36
  end
37
- sdivs
37
+ smaps
38
38
  end
39
39
 
40
40
  def self.template
@@ -1,5 +1,5 @@
1
1
  module Ddr
2
2
  module Models
3
- VERSION = "2.0.0.pre.2"
3
+ VERSION = "2.0.0.pre.3"
4
4
  end
5
5
  end
@@ -2,21 +2,12 @@
2
2
  module Vocab
3
3
  class Asset < RDF::StrictVocabulary("http://repository.lib.duke.edu/vocab/asset/")
4
4
 
5
- property "order",
6
- label: "Order"
7
-
8
5
  property "permanentId",
9
6
  label: "Permanent Identifier"
10
7
 
11
8
  property "permanentUrl",
12
9
  label: "Permanent URL"
13
10
 
14
- property "fileGroup",
15
- label: "File Group"
16
-
17
- property "fileUse",
18
- label: "File Use"
19
-
20
11
  property "workflowState",
21
12
  label: "Workflow State"
22
13
 
@@ -1,5 +1,4 @@
1
1
  class User < ActiveRecord::Base
2
-
3
2
  include Ddr::Auth::User
4
-
3
+ include Blacklight::User
5
4
  end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20150130134416) do
14
+ ActiveRecord::Schema.define(version: 20150713171838) do
15
15
 
16
16
  create_table "events", force: true do |t|
17
17
  t.datetime "event_date_time"
@@ -25,7 +25,7 @@ ActiveRecord::Schema.define(version: 20150130134416) do
25
25
  t.string "summary"
26
26
  t.string "outcome"
27
27
  t.text "detail"
28
- t.string "exception"
28
+ t.text "exception", limit: 65535
29
29
  t.string "user_key"
30
30
  end
31
31
 
@@ -4,8 +4,9 @@ module Ddr
4
4
  module Models
5
5
  RSpec.describe HasStructMetadata, type: :model, structural_metadata: true do
6
6
 
7
+ let(:item) { Item.new(pid: 'test:2') }
8
+
7
9
  describe "#structure" do
8
- let(:item) { Item.new(pid: 'test:2') }
9
10
  context "no existing structural metadata" do
10
11
  it "should return nil" do
11
12
  expect(item.structure).to eq(nil)
@@ -20,7 +21,6 @@ module Ddr
20
21
  end
21
22
 
22
23
  describe "#build_default_structure" do
23
- let(:item) { Item.new(pid: 'test:2') }
24
24
  let(:components) { [ Component.new(pid: 'test:5', identifier: [ 'abc002' ]),
25
25
  Component.new(pid: 'test:6', identifier: [ 'abc001' ]),
26
26
  Component.new(pid: 'test:7', identifier: [ 'abc003' ])
@@ -33,6 +33,16 @@ module Ddr
33
33
  end
34
34
  end
35
35
 
36
+ describe "indexing" do
37
+ let(:expected_json) { multiple_struct_maps_structure_to_json }
38
+ before { item.datastreams[Ddr::Datastreams::STRUCT_METADATA].content = multiple_struct_maps_structure }
39
+ it "should index the JSON representation of the structure" do
40
+ indexing = item.to_solr
41
+ expect(indexing.keys).to include(Ddr::IndexFields::STRUCT_MAPS)
42
+ expect(indexing[Ddr::IndexFields::STRUCT_MAPS]).to eq(expected_json)
43
+ end
44
+ end
45
+
36
46
  end
37
47
  end
38
48
  end
@@ -74,4 +74,39 @@ RSpec.describe SolrDocument, type: :model do
74
74
  its(:display_format) { should eq("Image") }
75
75
  end
76
76
 
77
+ describe "#struct_maps" do
78
+ context "no indexed struct maps" do
79
+ it "should return an empty hash" do
80
+ expect(subject.struct_maps).to be_empty
81
+ end
82
+ end
83
+ context "indexed struct maps" do
84
+ before { subject[Ddr::IndexFields::STRUCT_MAPS] = multiple_struct_maps_structure_to_json }
85
+ it "should return a hash of the struct maps" do
86
+ expect(subject.struct_maps).to eq(JSON.parse(multiple_struct_maps_structure_to_json))
87
+ end
88
+ end
89
+ end
90
+
91
+ describe "#struct_map" do
92
+ context "no indexed struct maps" do
93
+ it "should return nil" do
94
+ expect(subject.struct_map('default')).to be_nil
95
+ end
96
+ end
97
+ context "indexed struct maps" do
98
+ before { subject[Ddr::IndexFields::STRUCT_MAPS] = multiple_struct_maps_structure_to_json }
99
+ context "requested struct map is indexed" do
100
+ it "should return the struct map" do
101
+ expect(subject.struct_map('default')).to eq(JSON.parse(multiple_struct_maps_structure_to_json)["default"])
102
+ end
103
+ end
104
+ context "requested struct map is not indexed" do
105
+ it "should raise a KeyError" do
106
+ expect { subject.struct_map('foo') }.to raise_error(KeyError)
107
+ end
108
+ end
109
+ end
110
+ end
111
+
77
112
  end
@@ -5,8 +5,6 @@ module Ddr
5
5
  module Models
6
6
  RSpec.describe StructDiv, type: :model, structural_metadata: true do
7
7
 
8
- # let(:structure) { FactoryGirl.build(:simple_structure) }
9
- # let(:structDiv) { structure.struct_div_map['default'] }
10
8
  let(:structmap_node) { nested_structure_document.xpath('//xmlns:structMap').first }
11
9
  let(:struct_div) { described_class.new(structmap_node) }
12
10
 
@@ -15,48 +13,55 @@ module Ddr
15
13
  expect(struct_div.divs.size).to eq(2)
16
14
  expect(struct_div.divs.first.label).to eq("Front")
17
15
  expect(struct_div.divs.first.divs).to be_empty
18
- expect(struct_div.divs.first.objs).to eq([ "test:5" ])
16
+ expect(struct_div.divs.first.fptrs).to eq([ "test:5" ])
19
17
  expect(struct_div.divs.last.label).to eq("Back")
20
18
  expect(struct_div.divs.last.divs.size).to eq(2)
21
- expect(struct_div.divs.last.objs).to be_empty
19
+ expect(struct_div.divs.last.fptrs).to be_empty
22
20
  expect(struct_div.divs.last.divs.first.label).to eq("Top")
23
21
  expect(struct_div.divs.last.divs.first.divs).to be_empty
24
- expect(struct_div.divs.last.divs.first.objs).to eq([ "test:7" ])
22
+ expect(struct_div.divs.last.divs.first.fptrs).to eq([ "test:7" ])
25
23
  expect(struct_div.divs.last.divs.last.label).to eq("Bottom")
26
24
  expect(struct_div.divs.last.divs.last.divs).to be_empty
27
- expect(struct_div.divs.last.divs.last.objs).to eq([ "test:6" ])
25
+ expect(struct_div.divs.last.divs.last.fptrs).to eq([ "test:6" ])
28
26
  end
29
27
  end
30
28
 
31
- describe "#objects?" do
32
- context "objects" do
33
- it "should be true" do
34
- expect(struct_div.divs[0].objects?).to be_truthy
35
- end
36
- end
37
- context "no objects" do
38
- it "should be false" do
39
- expect(struct_div.objects?).to_not be_truthy
29
+ describe "#pids" do
30
+ context "top level" do
31
+ it "should return all pids in the structMap" do
32
+ expect(struct_div.pids).to match_array([ 'test:5', 'test:6', 'test:7' ])
40
33
  end
41
34
  end
42
35
  end
43
-
44
- describe "#object_pids" do
45
- it "should return the object pids in order" do
46
- expect(struct_div.divs.last.divs.first.object_pids).to eq([ 'test:7' ])
47
- expect(struct_div.divs.last.divs.last.object_pids).to eq([ 'test:6' ])
36
+
37
+ describe "#docs" do
38
+ let(:solr_response) { [ { 'id'=>'test:5' }, { 'id'=>'test:6' }, { 'id'=>'test:7'} ] }
39
+ before do
40
+ allow(ActiveFedora::SolrService).to receive(:query) { solr_response }
41
+ end
42
+ it "should return a hash of Solr documents" do
43
+ results = struct_div.docs
44
+ expect(results.keys).to match_array([ 'test:5', 'test:6', 'test:7' ])
45
+ results.keys.each do |key|
46
+ expect(results[key]).to be_a(SolrDocument)
47
+ expect(results[key].id).to eq(key)
48
+ end
48
49
  end
49
50
  end
50
51
 
51
52
  describe "#objects" do
52
- let(:repo_objects) { [ Component.new(pid: 'test:6'), Component.new(pid: 'test:7') ] }
53
+ let(:repo_objects) { [ Component.new(pid: 'test:5'), Component.new(pid: 'test:6'), Component.new(pid: 'test:7') ] }
53
54
  before do
54
- allow(ActiveFedora::Base).to receive(:find).with('test:6') { repo_objects.first }
55
- allow(ActiveFedora::Base).to receive(:find).with('test:7') { repo_objects.last }
55
+ allow(ActiveFedora::Base).to receive(:find).with('test:5') { repo_objects[0] }
56
+ allow(ActiveFedora::Base).to receive(:find).with('test:6') { repo_objects[1] }
57
+ allow(ActiveFedora::Base).to receive(:find).with('test:7') { repo_objects[2] }
56
58
  end
57
- it "should return the Active Fedora objects in order" do
58
- expect(struct_div.divs.last.divs.first.objects).to eq([ repo_objects.last ])
59
- expect(struct_div.divs.last.divs.last.objects).to eq([ repo_objects.first ])
59
+ it "should return a hash of Active Fedora objects" do
60
+ results = struct_div.objects
61
+ expect(results.keys).to match_array([ 'test:5', 'test:6', 'test:7' ])
62
+ expect(results['test:5']).to eq(repo_objects[0])
63
+ expect(results['test:6']).to eq(repo_objects[1])
64
+ expect(results['test:7']).to eq(repo_objects[2])
60
65
  end
61
66
  end
62
67
 
@@ -5,13 +5,14 @@ module Ddr
5
5
  module Models
6
6
  RSpec.describe Structure, type: :model, structural_metadata: true do
7
7
 
8
- describe "#struct_divs" do
9
- let(:structure) { FactoryGirl.build(:multiple_struct_maps_structure) }
10
- let(:struct_divs) { structure.struct_divs }
8
+ let(:structure) { FactoryGirl.build(:multiple_struct_maps_structure) }
9
+
10
+ describe "#struct_maps" do
11
+ let(:struct_maps) { structure.struct_maps }
11
12
  it "should include struct divs for each struct map" do
12
- expect(struct_divs.keys).to match_array([ 'default', 'reverse' ])
13
- expect(struct_divs['default']).to be_a(Ddr::Models::StructDiv)
14
- expect(struct_divs['reverse']).to be_a(Ddr::Models::StructDiv)
13
+ expect(struct_maps.keys).to match_array([ 'default', 'reverse' ])
14
+ expect(struct_maps['default']).to be_a(Ddr::Models::StructDiv)
15
+ expect(struct_maps['reverse']).to be_a(Ddr::Models::StructDiv)
15
16
  end
16
17
  end
17
18
 
@@ -87,9 +87,49 @@ def multiple_struct_maps_structure
87
87
  </structMap>
88
88
  </mets>
89
89
  eos
90
-
91
90
  end
92
91
 
93
92
  def simple_structure_query_response
94
93
  [{"system_create_dtsi"=>"2015-06-17T21:04:24Z", "system_modified_dtsi"=>"2015-06-17T21:04:56Z", "object_state_ssi"=>"A", "active_fedora_model_ssi"=>"Component", "id"=>"test:6", "object_profile_ssm"=>["{\"datastreams\":{\"RELS-EXT\":{\"dsLabel\":\"Fedora Object-to-Object Relationship Metadata\",\"dsVersionID\":\"RELS-EXT.1\",\"dsCreateDate\":\"2015-06-17T21:04:56Z\",\"dsState\":\"A\",\"dsMIME\":\"application/rdf+xml\",\"dsFormatURI\":null,\"dsControlGroup\":\"X\",\"dsSize\":408,\"dsVersionable\":true,\"dsInfoType\":null,\"dsLocation\":\"test:6+RELS-EXT+RELS-EXT.1\",\"dsLocationType\":null,\"dsChecksumType\":\"SHA-256\",\"dsChecksum\":\"bf84faa89d6b25924bc06357f7c33347a602e2ec8df9c1020ec98015fe571760\"},\"descMetadata\":{\"dsLabel\":\"Descriptive Metadata for this object\",\"dsVersionID\":\"descMetadata.1\",\"dsCreateDate\":\"2015-06-17T21:04:56Z\",\"dsState\":\"A\",\"dsMIME\":\"application/n-triples\",\"dsFormatURI\":null,\"dsControlGroup\":\"M\",\"dsSize\":70,\"dsVersionable\":true,\"dsInfoType\":null,\"dsLocation\":\"test:6+descMetadata+descMetadata.1\",\"dsLocationType\":\"INTERNAL_ID\",\"dsChecksumType\":\"SHA-256\",\"dsChecksum\":\"4d227bc972634ba2126eefff207fb3b35f6ff802a210ad7945d2ec60360076dd\"},\"rightsMetadata\":{},\"properties\":{},\"thumbnail\":{},\"adminMetadata\":{},\"content\":{},\"extractedText\":{},\"multiresImage\":{},\"structMetadata\":{}},\"objLabel\":null,\"objOwnerId\":\"fedoraAdmin\",\"objModels\":[\"info:fedora/fedora-system:FedoraObject-3.0\"],\"objCreateDate\":\"2015-06-17T21:04:24Z\",\"objLastModDate\":\"2015-06-17T21:04:24Z\",\"objDissIndexViewURL\":\"http://localhost:8983/fedora/objects/test%3A6/methods/fedora-system%3A3/viewMethodIndex\",\"objItemIndexViewURL\":\"http://localhost:8983/fedora/objects/test%3A6/methods/fedora-system%3A3/viewItemIndex\",\"objState\":\"A\"}"], "identifier_tesim"=>["abc001"], "is_part_of_ssim"=>["info:fedora/test:2"], "has_model_ssim"=>["info:fedora/afmodel:Component"], "title_ssi"=>"abc001", "internal_uri_ssi"=>"info:fedora/test:6", "identifier_ssi"=>"abc001", "access_role_ssi"=>"[]", "_version_"=>1504261016868880384, "timestamp"=>"2015-06-17T21:04:56.958Z"}, {"system_create_dtsi"=>"2015-06-17T21:03:58Z", "system_modified_dtsi"=>"2015-06-17T21:04:54Z", "object_state_ssi"=>"A", "active_fedora_model_ssi"=>"Component", "id"=>"test:5", "object_profile_ssm"=>["{\"datastreams\":{\"RELS-EXT\":{\"dsLabel\":\"Fedora Object-to-Object Relationship Metadata\",\"dsVersionID\":\"RELS-EXT.1\",\"dsCreateDate\":\"2015-06-17T21:04:54Z\",\"dsState\":\"A\",\"dsMIME\":\"application/rdf+xml\",\"dsFormatURI\":null,\"dsControlGroup\":\"X\",\"dsSize\":408,\"dsVersionable\":true,\"dsInfoType\":null,\"dsLocation\":\"test:5+RELS-EXT+RELS-EXT.1\",\"dsLocationType\":null,\"dsChecksumType\":\"SHA-256\",\"dsChecksum\":\"6a7f1cbe6e435991ae3bba134e52e7a275af8a232b209ac725fa54fdd81bb973\"},\"descMetadata\":{\"dsLabel\":\"Descriptive Metadata for this object\",\"dsVersionID\":\"descMetadata.1\",\"dsCreateDate\":\"2015-06-17T21:04:54Z\",\"dsState\":\"A\",\"dsMIME\":\"application/n-triples\",\"dsFormatURI\":null,\"dsControlGroup\":\"M\",\"dsSize\":70,\"dsVersionable\":true,\"dsInfoType\":null,\"dsLocation\":\"test:5+descMetadata+descMetadata.1\",\"dsLocationType\":\"INTERNAL_ID\",\"dsChecksumType\":\"SHA-256\",\"dsChecksum\":\"8b106726ca2d39d9a2e187fc9da2e58b25bd3553031012515ae31cf4fbe520e9\"},\"rightsMetadata\":{},\"properties\":{},\"thumbnail\":{},\"adminMetadata\":{},\"content\":{},\"extractedText\":{},\"multiresImage\":{},\"structMetadata\":{}},\"objLabel\":null,\"objOwnerId\":\"fedoraAdmin\",\"objModels\":[\"info:fedora/fedora-system:FedoraObject-3.0\"],\"objCreateDate\":\"2015-06-17T21:03:58Z\",\"objLastModDate\":\"2015-06-17T21:03:58Z\",\"objDissIndexViewURL\":\"http://localhost:8983/fedora/objects/test%3A5/methods/fedora-system%3A3/viewMethodIndex\",\"objItemIndexViewURL\":\"http://localhost:8983/fedora/objects/test%3A5/methods/fedora-system%3A3/viewItemIndex\",\"objState\":\"A\"}"], "identifier_tesim"=>["abc002"], "is_part_of_ssim"=>["info:fedora/test:2"], "has_model_ssim"=>["info:fedora/afmodel:Component"], "title_ssi"=>"abc002", "internal_uri_ssi"=>"info:fedora/test:5", "identifier_ssi"=>"abc002", "access_role_ssi"=>"[]", "_version_"=>1504261014501195776, "timestamp"=>"2015-06-17T21:04:54.701Z"}, {"system_create_dtsi"=>"2015-06-17T21:04:46Z", "system_modified_dtsi"=>"2015-06-17T21:04:59Z", "object_state_ssi"=>"A", "active_fedora_model_ssi"=>"Component", "id"=>"test:7", "object_profile_ssm"=>["{\"datastreams\":{\"RELS-EXT\":{\"dsLabel\":\"Fedora Object-to-Object Relationship Metadata\",\"dsVersionID\":\"RELS-EXT.1\",\"dsCreateDate\":\"2015-06-17T21:04:59Z\",\"dsState\":\"A\",\"dsMIME\":\"application/rdf+xml\",\"dsFormatURI\":null,\"dsControlGroup\":\"X\",\"dsSize\":408,\"dsVersionable\":true,\"dsInfoType\":null,\"dsLocation\":\"test:7+RELS-EXT+RELS-EXT.1\",\"dsLocationType\":null,\"dsChecksumType\":\"SHA-256\",\"dsChecksum\":\"cb385ff9a55b5fe24e8c2a8159fc928e3ee582ef312955132d34282676102a6a\"},\"descMetadata\":{\"dsLabel\":\"Descriptive Metadata for this object\",\"dsVersionID\":\"descMetadata.1\",\"dsCreateDate\":\"2015-06-17T21:04:59Z\",\"dsState\":\"A\",\"dsMIME\":\"application/n-triples\",\"dsFormatURI\":null,\"dsControlGroup\":\"M\",\"dsSize\":70,\"dsVersionable\":true,\"dsInfoType\":null,\"dsLocation\":\"test:7+descMetadata+descMetadata.1\",\"dsLocationType\":\"INTERNAL_ID\",\"dsChecksumType\":\"SHA-256\",\"dsChecksum\":\"523ee1e5d55d188bd17b2789e4c9109c8f9d0170b63af1219de8a74d4f32966a\"},\"rightsMetadata\":{},\"properties\":{},\"thumbnail\":{},\"adminMetadata\":{},\"content\":{},\"extractedText\":{},\"multiresImage\":{},\"structMetadata\":{}},\"objLabel\":null,\"objOwnerId\":\"fedoraAdmin\",\"objModels\":[\"info:fedora/fedora-system:FedoraObject-3.0\"],\"objCreateDate\":\"2015-06-17T21:04:46Z\",\"objLastModDate\":\"2015-06-17T21:04:46Z\",\"objDissIndexViewURL\":\"http://localhost:8983/fedora/objects/test%3A7/methods/fedora-system%3A3/viewMethodIndex\",\"objItemIndexViewURL\":\"http://localhost:8983/fedora/objects/test%3A7/methods/fedora-system%3A3/viewItemIndex\",\"objState\":\"A\"}"], "identifier_tesim"=>["abc003"], "is_part_of_ssim"=>["info:fedora/test:2"], "has_model_ssim"=>["info:fedora/afmodel:Component"], "title_ssi"=>"abc003", "internal_uri_ssi"=>"info:fedora/test:7", "identifier_ssi"=>"abc003", "access_role_ssi"=>"[]", "_version_"=>1504261019487174656, "timestamp"=>"2015-06-17T21:04:59.455Z"}]
94
+ end
95
+
96
+ def simple_structure_to_json
97
+ j = <<-eos
98
+ {\"default\":
99
+ {\"type\":\"default\",
100
+ \"divs\":[{\"order\":\"1\",\"fptrs\":[\"test:6\"],\"divs\":[]},
101
+ {\"order\":\"2\",\"fptrs\":[\"test:5\"],\"divs\":[]},
102
+ {\"order\":\"3\",\"fptrs\":[\"test:7\"],\"divs\":[]}
103
+ ]
104
+ }
105
+ }
106
+ eos
107
+ j.gsub(/\s+/, "")
108
+ end
109
+
110
+ def multiple_struct_maps_structure_to_json
111
+ j = <<-eos
112
+ {\"default\":
113
+ {\"type\":\"default\",
114
+ \"divs\":[{\"label\":\"Front\",\"order\":\"1\",\"fptrs\":[\"test:5\"],\"divs\":[]},
115
+ {\"label\":\"Back\",\"order\":\"2\",\"fptrs\":[],
116
+ \"divs\":[{\"label\":\"Top\",\"order\":\"1\",\"fptrs\":[\"test:7\"],\"divs\":[]},
117
+ {\"label\":\"Bottom\",\"order\":\"2\",\"fptrs\":[\"test:6\"],\"divs\":[]}
118
+ ]
119
+ }
120
+ ]
121
+ },
122
+ \"reverse\":
123
+ {\"type\":\"reverse\",
124
+ \"divs\":[{\"label\":\"Back\",\"order\":\"1\",\"fptrs\":[],
125
+ \"divs\":[{\"label\":\"Bottom\",\"order\":\"1\",\"fptrs\":[\"test:6\"],\"divs\":[]},
126
+ {\"label\":\"Top\",\"order\":\"2\",\"fptrs\":[\"test:7\"],\"divs\":[]}
127
+ ]
128
+ },
129
+ {\"label\":\"Front\",\"order\":\"2\",\"fptrs\":[\"test:5\"],\"divs\":[]}
130
+ ]
131
+ }
132
+ }
133
+ eos
134
+ j.gsub(/\s+/, "")
95
135
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddr-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.2
4
+ version: 2.0.0.pre.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Coble
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-09 00:00:00.000000000 Z
12
+ date: 2015-07-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -351,6 +351,8 @@ files:
351
351
  - db/migrate/20141218020612_add_exception_to_events.rb
352
352
  - db/migrate/20150110023410_drop_workflow_states.rb
353
353
  - db/migrate/20150130134416_add_user_key_to_events.rb
354
+ - db/migrate/20150710211530_change_events_exception_to_text.rb
355
+ - db/migrate/20150713171838_add_limit_to_events_exception.rb
354
356
  - ddr-models.gemspec
355
357
  - lib/ddr-models.rb
356
358
  - lib/ddr/actions.rb
@@ -622,7 +624,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
622
624
  version: 1.3.1
623
625
  requirements: []
624
626
  rubyforge_project:
625
- rubygems_version: 2.4.6
627
+ rubygems_version: 2.2.2
626
628
  signing_key:
627
629
  specification_version: 4
628
630
  summary: Models used in the Duke Digital Repository