ddr-models 3.0.0.rc4 → 3.0.0.rc5
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 +4 -4
- data/lib/ddr/index/connection.rb +2 -0
- data/lib/ddr/index/csv_options.rb +1 -3
- data/lib/ddr/index/csv_query_result.rb +13 -21
- data/lib/ddr/index/fields.rb +1 -1
- data/lib/ddr/index/query.rb +2 -2
- data/lib/ddr/index/solr_csv_options.rb +5 -2
- data/lib/ddr/models/attached_file_profile.rb +5 -1
- data/lib/ddr/models/attached_files_profile.rb +11 -10
- data/lib/ddr/models/base.rb +1 -1
- data/lib/ddr/models/solr_document.rb +9 -4
- data/lib/ddr/models/version.rb +1 -1
- data/spec/index/csv_query_result_spec.rb +42 -0
- data/spec/models/attached_files_profile_spec.rb +14 -0
- data/spec/models/solr_document_spec.rb +6 -4
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 882499780ce1326eec18ff01bdead5d41dcb0819
|
4
|
+
data.tar.gz: 6c9b5b6edbb3d442b2f5cf6d6d7d74ff31fe7707
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcc433f961a831d8b14bc2825a355351feb9e9be28c68c16e1348b1d5ef7bcd1be692a152026dbad6177a4f65ad7f046f9c9fe75c13e883448a230eea327f9de
|
7
|
+
data.tar.gz: f9778626680a979a3d46768d6e7af65aa7f3d916c3560d0ac52394466b13f6ab377a55a4e084ddeaa61fff372699deec49a6fc798ead1aaf35e3bfe6b7f273ea
|
data/lib/ddr/index/connection.rb
CHANGED
@@ -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:
|
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
|
-
|
7
|
-
MV_SEP = ";"
|
6
|
+
delegate :[], :to_s, :to_csv, to: :table
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
23
|
-
|
14
|
+
def each(&block)
|
15
|
+
table.by_row!.each(&block)
|
24
16
|
end
|
25
17
|
|
26
|
-
def
|
27
|
-
|
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
|
-
|
39
|
-
rows: rows)
|
30
|
+
rows: query.rows)
|
40
31
|
end
|
41
32
|
|
42
33
|
def headers
|
43
|
-
@headers ||= query.fields.map(
|
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
|
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
|
|
data/lib/ddr/index/fields.rb
CHANGED
@@ -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,
|
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
|
data/lib/ddr/index/query.rb
CHANGED
@@ -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",
|
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? }
|
@@ -2,23 +2,24 @@ module Ddr::Models
|
|
2
2
|
class AttachedFilesProfile
|
3
3
|
include ActiveModel::Serializers::JSON
|
4
4
|
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :object
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
@files_hash = files_hash
|
7
|
+
def initialize(object)
|
8
|
+
@object = object
|
10
9
|
end
|
11
10
|
|
12
11
|
def attributes
|
13
|
-
|
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(
|
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
|
data/lib/ddr/models/base.rb
CHANGED
@@ -89,7 +89,12 @@ module Ddr::Models
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def has_datastream?(dsID)
|
92
|
-
|
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
|
-
|
142
|
+
has_attached_file?(Ddr::Models::File::THUMBNAIL)
|
138
143
|
end
|
139
144
|
|
140
145
|
def has_content?
|
141
|
-
|
146
|
+
has_attached_file?(Ddr::Models::File::CONTENT)
|
142
147
|
end
|
143
148
|
|
144
149
|
def has_extracted_text?
|
145
|
-
|
150
|
+
has_attached_file?(Ddr::Datastreams::EXTRACTED_TEXT)
|
146
151
|
end
|
147
152
|
|
148
153
|
def content_ds
|
data/lib/ddr/models/version.rb
CHANGED
@@ -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 "#
|
199
|
+
describe "#has_attached_file?" do
|
200
200
|
before do
|
201
|
-
allow(subject).to receive(:attached_files) {
|
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.
|
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.
|
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.
|
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-
|
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
|