ddr-models 3.0.0.rc4 → 3.0.0.rc5

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: a8155309c431868675c03fbaf02a8799964d2d47
4
- data.tar.gz: b10fd2351e4e63e7fb031bce241aafa358b06002
3
+ metadata.gz: 882499780ce1326eec18ff01bdead5d41dcb0819
4
+ data.tar.gz: 6c9b5b6edbb3d442b2f5cf6d6d7d74ff31fe7707
5
5
  SHA512:
6
- metadata.gz: 9cc4187d72d08043d254be38b77c6bcc40477f7959db80cfc71a6f6ef53c7ff88c86c5919c7183cfe3c0570bb00b50f414aef4d67952e561a73984de41bfd61f
7
- data.tar.gz: 503759f1af8ee9bb73d9631da9dc8c0c3ac92f44625e41e8485205b65354859e8af968190844f3c2d8a955d0223854ab76ee80693682fa297fc4959d557a7845
6
+ metadata.gz: fcc433f961a831d8b14bc2825a355351feb9e9be28c68c16e1348b1d5ef7bcd1be692a152026dbad6177a4f65ad7f046f9c9fe75c13e883448a230eea327f9de
7
+ data.tar.gz: f9778626680a979a3d46768d6e7af65aa7f3d916c3560d0ac52394466b13f6ab377a55a4e084ddeaa61fff372699deec49a6fc798ead1aaf35e3bfe6b7f273ea
@@ -1,3 +1,5 @@
1
+ require "rsolr"
2
+
1
3
  module Ddr::Index
2
4
  class Connection < SimpleDelegator
3
5
 
@@ -3,12 +3,10 @@ require "hashie"
3
3
 
4
4
  module Ddr::Index
5
5
  class CSVOptions < Hashie::Dash
6
-
7
6
  property :headers, default: CSV::DEFAULT_OPTIONS[:headers]
8
- property :return_headers, default: true
7
+ property :return_headers, default: false
9
8
  property :write_headers, default: true
10
9
  property :col_sep, default: CSV::DEFAULT_OPTIONS[:col_sep]
11
10
  property :quote_char, default: CSV::DEFAULT_OPTIONS[:quote_char]
12
-
13
11
  end
14
12
  end
@@ -3,28 +3,20 @@ require "csv"
3
3
  module Ddr::Index
4
4
  class CSVQueryResult < AbstractQueryResult
5
5
 
6
- MAX_ROWS = 10**8
7
- MV_SEP = ";"
6
+ delegate :[], :to_s, :to_csv, to: :table
8
7
 
9
- attr_reader :mv_sep
10
-
11
- delegate :read, :each, to: :csv
12
-
13
- def initialize(query, mv_sep: MV_SEP)
14
- super(query)
15
- @mv_sep = mv_sep
16
- end
17
-
18
- def csv
19
- CSV.new(data, csv_opts.to_h)
8
+ def delete_empty_columns!
9
+ mode = table.mode
10
+ table.by_col!.delete_if { |c, vals| vals.all?(&:nil?) }
11
+ table.send("by_#{mode}!")
20
12
  end
21
13
 
22
- def to_s
23
- read.to_csv
14
+ def each(&block)
15
+ table.by_row!.each(&block)
24
16
  end
25
17
 
26
- def rows
27
- query.rows || MAX_ROWS
18
+ def table
19
+ @table ||= CSV.parse(data, csv_opts.to_h)
28
20
  end
29
21
 
30
22
  def csv_opts
@@ -35,12 +27,11 @@ module Ddr::Index
35
27
  @solr_csv_opts ||= SolrCSVOptions.new(col_sep: csv_opts.col_sep,
36
28
  quote_char: csv_opts.quote_char,
37
29
  header: solr_csv_header,
38
- mv_sep: mv_sep,
39
- rows: rows)
30
+ rows: query.rows)
40
31
  end
41
32
 
42
33
  def headers
43
- @headers ||= query.fields.map(&:heading)
34
+ @headers ||= query.fields.map { |f| f.respond_to?(:heading) ? f.heading : f.to_s }
44
35
  end
45
36
 
46
37
  def csv_headers
@@ -56,11 +47,12 @@ module Ddr::Index
56
47
  end
57
48
 
58
49
  def solr_csv_params
59
- params.merge solr_csv_opts.params
50
+ params.merge(solr_csv_opts.params)
60
51
  end
61
52
 
62
53
  def data
63
54
  raw = conn.get("select", params: solr_csv_params)
55
+ mv_sep = solr_csv_opts["csv.mv.separator"]
64
56
  raw.gsub(/\\#{mv_sep}/, mv_sep)
65
57
  end
66
58
 
@@ -10,7 +10,7 @@ module Ddr::Index
10
10
  ADMIN_SET_FACET = Field.new :admin_set_facet, :facetable
11
11
  ALL_TEXT = Field.new :all_text, solr_name: "all_text_timv"
12
12
  ASPACE_ID = Field.new :aspace_id, :stored_sortable
13
- ATTACHED_FILES = Field.new :attached_files, solr_name: "attached_files_ss"
13
+ ATTACHED_FILES = Field.new :attached_files, :stored_sortable
14
14
  ATTACHED_FILES_HAVING_CONTENT =
15
15
  Field.new :attached_files_having_content, :symbol
16
16
  BOX_NUMBER_FACET = Field.new :box_number_facet, :facetable
@@ -46,8 +46,8 @@ module Ddr::Index
46
46
  QueryResult.new(self)
47
47
  end
48
48
 
49
- def csv(**opts)
50
- CSVQueryResult.new(self, **opts)
49
+ def csv
50
+ CSVQueryResult.new(self)
51
51
  end
52
52
 
53
53
  def filter_clauses
@@ -3,12 +3,15 @@ require "hashie"
3
3
  module Ddr::Index
4
4
  class SolrCSVOptions < Hashie::Trash
5
5
 
6
+ MAX_ROWS = 10**8
7
+ CSV_MV_SEPARATOR = ";"
8
+
6
9
  property "csv.header", from: :header, default: false
7
10
  property "csv.separator", from: :col_sep, default: ","
8
11
  property "csv.encapsulator", from: :quote_char, default: '"'
9
- property "csv.mv.separator", from: :mv_sep, default: ","
12
+ property "csv.mv.separator", default: CSV_MV_SEPARATOR
10
13
  property :wt, default: "csv"
11
- property :rows
14
+ property :rows, default: MAX_ROWS
12
15
 
13
16
  def params
14
17
  to_h.reject { |k, v| v.nil? }
@@ -5,7 +5,11 @@ module Ddr::Models
5
5
  include ActiveModel::Serializers::JSON
6
6
 
7
7
  def attributes
8
- { "size" => nil, "mime_type" => nil }
8
+ { "size"=>nil, "mime_type"=>nil, "sha1"=>nil }
9
+ end
10
+
11
+ def sha1
12
+ checksum.value
9
13
  end
10
14
 
11
15
  end
@@ -2,23 +2,24 @@ module Ddr::Models
2
2
  class AttachedFilesProfile
3
3
  include ActiveModel::Serializers::JSON
4
4
 
5
- attr_reader :files_hash
5
+ attr_reader :object
6
6
 
7
- # @param files_hash [ActiveFedora::FilesHash]
8
- def initialize(files_hash)
9
- @files_hash = files_hash
7
+ def initialize(object)
8
+ @object = object
10
9
  end
11
10
 
12
11
  def attributes
13
- files_hash.keys.each_with_object({}) do |key, memo|
14
- unless files_hash[key].destroyed?
15
- memo[key.to_s] = nil
16
- end
17
- end
12
+ files.keys.map { |k| [k, nil] }.to_h
18
13
  end
19
14
 
20
15
  def read_attribute_for_serialization(key)
21
- AttachedFileProfile.new(files_hash[key])
16
+ AttachedFileProfile.new(files[key])
17
+ end
18
+
19
+ private
20
+
21
+ def files
22
+ object.attached_files_having_content
22
23
  end
23
24
 
24
25
  end
@@ -128,7 +128,7 @@ module Ddr::Models
128
128
  end
129
129
 
130
130
  def attached_files_profile
131
- AttachedFilesProfile.new(attached_files)
131
+ AttachedFilesProfile.new(self)
132
132
  end
133
133
 
134
134
  def copy_admin_policy_or_roles_from(other)
@@ -89,7 +89,12 @@ module Ddr::Models
89
89
  end
90
90
 
91
91
  def has_datastream?(dsID)
92
- attached_files.key?(dsID) && attached_files[dsID]["size"].present?
92
+ Deprecation.warn(SolrDocument, "Use `has_attached_file?` instead.")
93
+ has_attached_file?(dsID)
94
+ end
95
+
96
+ def has_attached_file?(file_id)
97
+ attached_files.key?(file_id)
93
98
  end
94
99
 
95
100
  def has_admin_policy?
@@ -134,15 +139,15 @@ module Ddr::Models
134
139
  end
135
140
 
136
141
  def has_thumbnail?
137
- has_datastream?(Ddr::Models::File::THUMBNAIL)
142
+ has_attached_file?(Ddr::Models::File::THUMBNAIL)
138
143
  end
139
144
 
140
145
  def has_content?
141
- has_datastream?(Ddr::Models::File::CONTENT)
146
+ has_attached_file?(Ddr::Models::File::CONTENT)
142
147
  end
143
148
 
144
149
  def has_extracted_text?
145
- has_datastream?(Ddr::Datastreams::EXTRACTED_TEXT)
150
+ has_attached_file?(Ddr::Datastreams::EXTRACTED_TEXT)
146
151
  end
147
152
 
148
153
  def content_ds
@@ -1,5 +1,5 @@
1
1
  module Ddr
2
2
  module Models
3
- VERSION = "3.0.0.rc4"
3
+ VERSION = "3.0.0.rc5"
4
4
  end
5
5
  end
@@ -0,0 +1,42 @@
1
+ module Ddr::Index
2
+ RSpec.describe CSVQueryResult do
3
+
4
+ subject { described_class.new(query) }
5
+
6
+ before do
7
+ Item.create(dc_title: ["Testing 1"],
8
+ dc_identifier: ["test1"],
9
+ dc_description: ["The process of eliminating errors."])
10
+ Item.create(dc_title: ["Testing 2"],
11
+ dc_identifier: ["test2"])
12
+ Item.create(dc_title: ["Testing 3"])
13
+ end
14
+
15
+ let(:query) {
16
+ Ddr::Index::Query.new do
17
+ fields Ddr::Index::Fields::ID
18
+ fields Ddr::Index::Fields.descmd
19
+ end
20
+ }
21
+
22
+ specify {
23
+ expect(subject["dc_title"]).to contain_exactly("Testing 1", "Testing 2", "Testing 3")
24
+ expect(subject["dc_identifier"]).to contain_exactly("test1", "test2", nil)
25
+ expect(subject["dc_description"]).to contain_exactly("The process of eliminating errors.", nil, nil)
26
+ expect(subject["dc_creator"]).to contain_exactly(nil, nil, nil)
27
+ expect(subject.to_s).to match(/dc_creator/)
28
+ }
29
+
30
+ describe "#delete_empty_columns!" do
31
+ specify {
32
+ subject.delete_empty_columns!
33
+ expect(subject["dc_title"]).to contain_exactly("Testing 1", "Testing 2", "Testing 3")
34
+ expect(subject["dc_identifier"]).to contain_exactly("test1", "test2", nil)
35
+ expect(subject["dc_description"]).to contain_exactly("The process of eliminating errors.", nil, nil)
36
+ expect(subject["dc_creator"]).to contain_exactly(nil, nil, nil)
37
+ expect(subject.to_s).not_to match(/dc_creator/)
38
+ }
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,14 @@
1
+ module Ddr::Models
2
+ RSpec.describe AttachedFilesProfile do
3
+
4
+ subject { described_class.new(obj) }
5
+
6
+ let(:obj) { FactoryGirl.create(:component) }
7
+ let!(:json) {
8
+ '{"content":{"size":230714,"mime_type":"image/tiff","sha1":"75e2e0cec6e807f6ae63610d46448f777591dd6b"}}'
9
+ }
10
+
11
+ its(:to_json) { is_expected.to eq(json) }
12
+
13
+ end
14
+ end
@@ -196,18 +196,20 @@ RSpec.describe SolrDocument, type: :model, contacts: true do
196
196
  end
197
197
  end
198
198
 
199
- describe "#has_datastream?" do
199
+ describe "#has_attached_file?" do
200
200
  before do
201
- allow(subject).to receive(:attached_files) { {"thumbnail"=>{"size"=>nil}, "content"=>{"size"=>987654} }}
201
+ allow(subject).to receive(:attached_files) {
202
+ {"content"=>{"size"=>987654, "sha1"=>"75e2e0cec6e807f6ae63610d46448f777591dd6b", "mime_type"=>"image/tiff"}}
203
+ }
202
204
  end
203
205
  context "when there is no content for the datastream" do
204
206
  it "should return false" do
205
- expect(subject.has_datastream?("thumbnail")).to be false
207
+ expect(subject.has_attached_file?("thumbnail")).to be false
206
208
  end
207
209
  end
208
210
  context "when there is content for the datastream" do
209
211
  it "should return true" do
210
- expect(subject.has_datastream?("content")).to be true
212
+ expect(subject.has_attached_file?("content")).to be true
211
213
  end
212
214
  end
213
215
  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: 3.0.0.rc4
4
+ version: 3.0.0.rc5
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: 2016-05-09 00:00:00.000000000 Z
12
+ date: 2016-05-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -688,6 +688,7 @@ files:
688
688
  - spec/fixtures/sample.docx
689
689
  - spec/fixtures/sample.pdf
690
690
  - spec/fixtures/target.png
691
+ - spec/index/csv_query_result_spec.rb
691
692
  - spec/index/fields_spec.rb
692
693
  - spec/index/filter_spec.rb
693
694
  - spec/index/query_builder_spec.rb
@@ -702,6 +703,7 @@ files:
702
703
  - spec/models/active_fedora_base_spec.rb
703
704
  - spec/models/admin_set_spec.rb
704
705
  - spec/models/administrative_metadata_spec.rb
706
+ - spec/models/attached_files_profile_spec.rb
705
707
  - spec/models/attachment_spec.rb
706
708
  - spec/models/collection_spec.rb
707
709
  - spec/models/component_spec.rb
@@ -862,6 +864,7 @@ test_files:
862
864
  - spec/fixtures/sample.docx
863
865
  - spec/fixtures/sample.pdf
864
866
  - spec/fixtures/target.png
867
+ - spec/index/csv_query_result_spec.rb
865
868
  - spec/index/fields_spec.rb
866
869
  - spec/index/filter_spec.rb
867
870
  - spec/index/query_builder_spec.rb
@@ -876,6 +879,7 @@ test_files:
876
879
  - spec/models/active_fedora_base_spec.rb
877
880
  - spec/models/admin_set_spec.rb
878
881
  - spec/models/administrative_metadata_spec.rb
882
+ - spec/models/attached_files_profile_spec.rb
879
883
  - spec/models/attachment_spec.rb
880
884
  - spec/models/collection_spec.rb
881
885
  - spec/models/component_spec.rb