ddr-models 3.0.0.beta.3 → 3.0.0.beta.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -3
  3. data/config/locales/ddr-models.en.yml +74 -0
  4. data/ddr-models.gemspec +3 -2
  5. data/lib/ddr/auth.rb +5 -2
  6. data/lib/ddr/auth/roles.rb +0 -2
  7. data/lib/ddr/auth/roles/role_set.rb +1 -0
  8. data/lib/ddr/derivatives/generators/png_generator.rb +1 -1
  9. data/lib/ddr/index.rb +6 -2
  10. data/lib/ddr/index/abstract_query_result.rb +1 -1
  11. data/lib/ddr/index/csv_options.rb +14 -0
  12. data/lib/ddr/index/csv_query_result.rb +39 -32
  13. data/lib/ddr/index/field.rb +11 -1
  14. data/lib/ddr/index/field_attribute.rb +22 -0
  15. data/lib/ddr/index/fields.rb +29 -20
  16. data/lib/ddr/index/filter.rb +81 -30
  17. data/lib/ddr/index/filters.rb +15 -10
  18. data/lib/ddr/index/query.rb +34 -13
  19. data/lib/ddr/index/query_builder.rb +150 -30
  20. data/lib/ddr/index/query_clause.rb +64 -19
  21. data/lib/ddr/index/query_params.rb +40 -0
  22. data/lib/ddr/index/solr_csv_options.rb +18 -0
  23. data/lib/ddr/index/sort_order.rb +28 -0
  24. data/lib/ddr/jobs.rb +5 -1
  25. data/lib/ddr/jobs/fits_file_characterization.rb +3 -41
  26. data/lib/ddr/jobs/fixity_check.rb +13 -0
  27. data/lib/ddr/jobs/job.rb +36 -0
  28. data/lib/ddr/jobs/queue.rb +27 -0
  29. data/lib/ddr/jobs/update_index.rb +13 -0
  30. data/lib/ddr/models.rb +20 -3
  31. data/lib/ddr/models/admin_set.rb +7 -3
  32. data/lib/ddr/models/contact.rb +19 -0
  33. data/lib/ddr/models/error.rb +3 -0
  34. data/lib/ddr/models/file_characterization.rb +37 -0
  35. data/lib/ddr/models/finding_aid.rb +35 -2
  36. data/lib/ddr/models/has_admin_metadata.rb +5 -1
  37. data/lib/ddr/models/has_content.rb +4 -2
  38. data/lib/ddr/models/indexing.rb +7 -0
  39. data/lib/ddr/models/licenses/license.rb +7 -3
  40. data/lib/ddr/models/solr_document.rb +2 -2
  41. data/lib/ddr/models/version.rb +1 -1
  42. data/lib/ddr/models/with_content_file.rb +37 -0
  43. data/lib/ddr/vocab/asset.rb +3 -0
  44. data/spec/derivatives/png_generator_spec.rb +8 -1
  45. data/spec/fixtures/arrow1rightred_e0.gif +0 -0
  46. data/spec/index/fields_spec.rb +197 -0
  47. data/spec/index/filter_spec.rb +155 -30
  48. data/spec/index/query_builder_spec.rb +116 -0
  49. data/spec/index/query_clause_spec.rb +58 -0
  50. data/spec/index/query_spec.rb +39 -10
  51. data/spec/jobs/fits_file_characterization_spec.rb +7 -43
  52. data/spec/jobs/fixity_check_spec.rb +22 -0
  53. data/spec/jobs/job_spec.rb +40 -0
  54. data/spec/jobs/update_index_spec.rb +22 -0
  55. data/spec/managers/derivatives_manager_spec.rb +15 -11
  56. data/spec/models/admin_set_spec.rb +28 -10
  57. data/spec/models/contact_spec.rb +42 -0
  58. data/spec/models/effective_license_spec.rb +17 -7
  59. data/spec/models/file_characterization_spec.rb +38 -0
  60. data/spec/models/finding_aid_spec.rb +31 -8
  61. data/spec/models/has_admin_metadata_spec.rb +8 -5
  62. data/spec/models/indexing_spec.rb +2 -0
  63. data/spec/models/license_spec.rb +31 -10
  64. data/spec/models/solr_document_spec.rb +23 -3
  65. data/spec/models/with_content_file_spec.rb +32 -0
  66. data/spec/spec_helper.rb +2 -0
  67. metadata +66 -28
  68. data/lib/ddr/contacts.rb +0 -25
  69. data/lib/ddr/index/query_value.rb +0 -18
  70. data/lib/ddr/models/access_controllable.rb +0 -12
  71. data/spec/auth/ldap_gateway_spec.rb +0 -9
  72. data/spec/contacts/contacts_spec.rb +0 -26
  73. data/spec/index/filters_spec.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88f17b85f90657e216998de459b6e4ebd08334e6
4
- data.tar.gz: 073db6c4741c656699531369123246d0ddcc1375
3
+ metadata.gz: ec966b30c1ee1106c893b7bcf914015a74d6a872
4
+ data.tar.gz: 4780ab2e5ec085392cf788e79cf920fed807ad0a
5
5
  SHA512:
6
- metadata.gz: 65c74339f0e42019ae99099d3f1e382751e8cddf32e1a2fc578c52df44d9987227625890f1886f2ad18076fd3e8b8d45258d6b75d101ce4661b1dc16c6eb4bf2
7
- data.tar.gz: 40c13719805412f5760c3b5ae72807636dc0c3f2f7f75206c647ec7555ea42a26977b9bf4dd24c692d911a2ee5deb5aa3961e56b0e004012281113c5d00d77d3
6
+ metadata.gz: 78bfd911fbcaebc909ad6ab26bef1efdc6447eb4c99f9733abc36b75f6ba1a6ea6acbe6856d379bbadcbf46476d8d9cdbf5d61bb9f23400ab9f62aff6bf75a79
7
+ data.tar.gz: d32e38fec5818a9887061e9a84bcee2cb471b080d9353ff85c04ce535c76525781e9b56eb42cdd6c41813f0ca1e52cbe12ae3b312d24def4639a60acc0103e86
data/.travis.yml CHANGED
@@ -6,9 +6,9 @@ before_install:
6
6
  rvm:
7
7
  - 2.1.5
8
8
  script: "bundle exec rake ci"
9
- notifications:
10
- email:
11
- - lib-drs@duke.edu
12
9
  bundler_args: --without production
13
10
  jdk:
14
11
  - oraclejdk8
12
+ env:
13
+ - DDR_AUX_API_URL=http://localhost:3000/api
14
+
@@ -0,0 +1,74 @@
1
+ en:
2
+ ddr:
3
+ index:
4
+ fields:
5
+ id:
6
+ label: "Fedora PID"
7
+ heading: pid
8
+ active_fedora_model:
9
+ label: Model
10
+ heading: model
11
+ aspace_id:
12
+ label: "ArchivesSpace ID"
13
+ doi:
14
+ label: DOI
15
+ ead_id:
16
+ label: "EAD ID"
17
+ local_id:
18
+ label: "Local ID"
19
+ system_create:
20
+ label: "Creation Date"
21
+ heading: creation_date
22
+ system_modified:
23
+ label: "Modification Date"
24
+ heading: modification_date
25
+ permanent_id:
26
+ label: "Permanent ID"
27
+ permanent_url:
28
+ label: "Permanent URL"
29
+ techmd_color_space:
30
+ label: "Color Space"
31
+ heading: color_space
32
+ techmd_creating_application:
33
+ label: "Creating Application"
34
+ heading: creating_application
35
+ techmd_creation_time:
36
+ label: "Creation Time"
37
+ heading: creation_time
38
+ techmd_file_size:
39
+ label: "File Size"
40
+ heading: "file_size"
41
+ techmd_fits_version:
42
+ label: "FITS Version"
43
+ heading: fits_version
44
+ techmd_fits_datetime:
45
+ label: "FITS Run At"
46
+ heading: fits_datetime
47
+ techmd_format_label:
48
+ label: "Format Label"
49
+ heading: format_label
50
+ techmd_format_version:
51
+ label: "Format Version"
52
+ heading: format_version
53
+ techmd_image_height:
54
+ label: "Image Height"
55
+ heading: image_height
56
+ techmd_image_width:
57
+ label: "Image Width"
58
+ heading: image_width
59
+ techmd_media_type:
60
+ label: "Media Type"
61
+ heading: media_type
62
+ techmd_modification_time:
63
+ label: "Modification Time"
64
+ heading: modification_time
65
+ techmd_pronom_identifier:
66
+ label: "PRONOM Unique ID"
67
+ heading: "pronom_uid"
68
+ techmd_valid:
69
+ label: Valid
70
+ heading: valid
71
+ techmd_well_formed:
72
+ label: "Well-formed"
73
+ heading: well_formed
74
+
data/ddr-models.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib", "app/models"]
20
20
 
21
21
  s.add_dependency "rails", "~> 4.1.13"
22
+ s.add_dependency "activeresource"
22
23
  s.add_dependency "active-triples", "~> 0.7.2"
23
24
  s.add_dependency "active-fedora", "~> 9.6.2"
24
25
  s.add_dependency "hydra-validations", "~> 0.5"
@@ -30,11 +31,11 @@ Gem::Specification.new do |s|
30
31
  s.add_dependency "rdf-vocab", "~> 0.8"
31
32
  s.add_dependency "net-ldap", "~> 0.11"
32
33
  s.add_dependency "cancancan", "~> 1.12"
33
- s.add_dependency "ddr-aux-client", "~> 1.2", ">= 1.2.2"
34
34
  s.add_dependency "ddr-antivirus", "~> 2.1.1"
35
35
  s.add_dependency "virtus", "~> 1.0.5"
36
+ s.add_dependency "hashie", "~> 3.4.3"
36
37
 
37
- s.add_development_dependency "bundler", "~> 1.10"
38
+ s.add_development_dependency "bundler", "~> 1.11", ">= 1.11.2"
38
39
  s.add_development_dependency "rake"
39
40
  s.add_development_dependency "sqlite3"
40
41
  s.add_development_dependency "rspec-rails", "~> 3.1"
data/lib/ddr/auth.rb CHANGED
@@ -71,8 +71,11 @@ module Ddr
71
71
  "::Ability"
72
72
  end
73
73
 
74
- mattr_accessor :repository_group_filter do
75
- ENV["REPOSITORY_GROUP_FILTER"]
74
+ def self.repository_group_filter
75
+ if filter = ENV["REPOSITORY_GROUP_FILTER"]
76
+ return filter
77
+ end
78
+ raise Ddr::Models::Error, "The \"REPOSITORY_GROUP_FILTER\" environment variable is not set."
76
79
  end
77
80
 
78
81
  end
@@ -18,7 +18,6 @@ module Ddr::Auth
18
18
  SCOPES = [RESOURCE_SCOPE, POLICY_SCOPE].freeze
19
19
 
20
20
  class << self
21
-
22
21
  def type_map
23
22
  @type_map ||= role_types.map { |role_type| [role_type.to_s, role_type] }.to_h
24
23
  end
@@ -26,7 +25,6 @@ module Ddr::Auth
26
25
  def role_types
27
26
  @role_types ||= RoleTypes.constants(false).map { |const| RoleTypes.const_get(const) }
28
27
  end
29
-
30
28
  end
31
29
 
32
30
  end
@@ -3,6 +3,7 @@ require "virtus"
3
3
 
4
4
  module Ddr::Auth
5
5
  module Roles
6
+ extend Deprecation
6
7
  #
7
8
  # Wraps a set of Roles
8
9
  #
@@ -13,7 +13,7 @@ module Ddr
13
13
  end
14
14
 
15
15
  def generate(source_path, output_path)
16
- command = "convert #{source_path} #{options} png:#{output_path}"
16
+ command = "convert #{source_path}[0] #{options} png:#{output_path}"
17
17
  out, err, s = Open3.capture3(command)
18
18
  GeneratorResult.new(output_path, out, err, s)
19
19
  end
data/lib/ddr/index.rb CHANGED
@@ -4,9 +4,11 @@ module Ddr
4
4
 
5
5
  autoload :AbstractQueryResult
6
6
  autoload :Connection
7
+ autoload :CSVOptions
7
8
  autoload :CSVQueryResult
8
9
  autoload :DocumentBuilder
9
10
  autoload :Field
11
+ autoload :FieldAttribute
10
12
  autoload :Fields
11
13
  autoload :Filter
12
14
  autoload :Filters
@@ -14,13 +16,15 @@ module Ddr
14
16
  autoload :Query
15
17
  autoload :QueryBuilder
16
18
  autoload :QueryClause
19
+ autoload :QueryParams
17
20
  autoload :QueryResult
18
- autoload :QueryValue
19
21
  autoload :Response
22
+ autoload :SolrCSVOptions
23
+ autoload :SortOrder
20
24
  autoload :UniqueKeyField
21
25
 
22
26
  def self.pids
23
- builder = QueryBuilder.new
27
+ builder = QueryBuilder.new { field UniqueKeyField.instance }
24
28
  query = builder.query
25
29
  query.pids
26
30
  end
@@ -6,7 +6,7 @@ module Ddr::Index
6
6
  delegate :params, to: :query
7
7
 
8
8
  def initialize(query)
9
- @query = query
9
+ @query = query.dup.freeze
10
10
  @conn = Connection.new
11
11
  end
12
12
 
@@ -0,0 +1,14 @@
1
+ require "csv"
2
+ require "hashie"
3
+
4
+ module Ddr::Index
5
+ class CSVOptions < Hashie::Dash
6
+
7
+ property :headers, default: CSV::DEFAULT_OPTIONS[:headers]
8
+ property :return_headers, default: true
9
+ property :write_headers, default: true
10
+ property :col_sep, default: CSV::DEFAULT_OPTIONS[:col_sep]
11
+ property :quote_char, default: CSV::DEFAULT_OPTIONS[:quote_char]
12
+
13
+ end
14
+ end
@@ -4,57 +4,64 @@ module Ddr::Index
4
4
  class CSVQueryResult < AbstractQueryResult
5
5
 
6
6
  MAX_ROWS = 10**8
7
+ MV_SEP = ";"
7
8
 
8
- COL_SEP = CSV::DEFAULT_OPTIONS[:col_sep].freeze
9
- QUOTE_CHAR = CSV::DEFAULT_OPTIONS[:quote_char].freeze
9
+ attr_reader :mv_sep
10
10
 
11
- SOLR_CSV_OPTS = {
12
- "csv.header" => "false",
13
- "csv.mv.separator" => "|",
14
- "wt" => "csv",
15
- }.freeze
11
+ delegate :read, :each, to: :csv
16
12
 
17
- CSV_OPTS = {
18
- return_headers: true,
19
- write_headers: true,
20
- }.freeze
21
-
22
- attr_reader :csv_opts, :solr_csv_opts
23
-
24
- def initialize(query, **opts)
13
+ def initialize(query, mv_sep: MV_SEP)
25
14
  super(query)
15
+ @mv_sep = mv_sep
16
+ end
17
+
18
+ def csv
19
+ CSV.new(data, csv_opts.to_h)
20
+ end
26
21
 
27
- @solr_csv_opts = SOLR_CSV_OPTS.dup
28
- @solr_csv_opts[:rows] ||= MAX_ROWS
22
+ def to_s
23
+ read.to_csv
24
+ end
29
25
 
30
- @csv_opts = CSV_OPTS.dup
31
- @csv_opts[:headers] = query.fields.map(&:label)
26
+ def rows
27
+ query.rows || MAX_ROWS
28
+ end
32
29
 
33
- # Set column separator and quote character consistently
34
- @csv_opts[:col_sep] = @solr_csv_opts["csv.separator"] = opts.fetch(:col_sep, COL_SEP)
35
- @csv_opts[:quote_char] = @solr_csv_opts["csv.encapsulator"] = opts.fetch(:quote_char, QUOTE_CHAR)
30
+ def csv_opts
31
+ @csv_opts ||= CSVOptions.new(headers: csv_headers)
36
32
  end
37
33
 
38
- def csv
39
- CSV.new(data, csv_opts)
34
+ def solr_csv_opts
35
+ @solr_csv_opts ||= SolrCSVOptions.new(col_sep: csv_opts.col_sep,
36
+ quote_char: csv_opts.quote_char,
37
+ header: solr_csv_header,
38
+ mv_sep: mv_sep,
39
+ rows: rows)
40
40
  end
41
41
 
42
- def each
43
- csv.each
42
+ def headers
43
+ @headers ||= query.fields.map(&:heading)
44
44
  end
45
45
 
46
- def to_s
47
- csv.string
46
+ def csv_headers
47
+ if headers.empty?
48
+ :first_row
49
+ else
50
+ headers
51
+ end
48
52
  end
49
53
 
50
- private
54
+ def solr_csv_header
55
+ csv_headers == :first_row
56
+ end
51
57
 
52
- def csv_params
53
- params.merge(solr_csv_opts)
58
+ def solr_csv_params
59
+ params.merge solr_csv_opts.params
54
60
  end
55
61
 
56
62
  def data
57
- conn.get "select", params: csv_params
63
+ raw = conn.get("select", params: solr_csv_params)
64
+ raw.gsub(/\\#{mv_sep}/, mv_sep)
58
65
  end
59
66
 
60
67
  end
@@ -16,7 +16,17 @@ module Ddr::Index
16
16
  end
17
17
 
18
18
  def label
19
- I18n.t "ddr.index.fields.#{base}", default: base.titleize
19
+ I18n.t "#{i18n_base}.label", default: base.titleize
20
+ end
21
+
22
+ def heading
23
+ I18n.t "#{i18n_base}.heading", default: base
24
+ end
25
+
26
+ private
27
+
28
+ def i18n_base
29
+ "ddr.index.fields.#{base}"
20
30
  end
21
31
 
22
32
  end
@@ -0,0 +1,22 @@
1
+ require "virtus"
2
+
3
+ module Ddr::Index
4
+ class FieldAttribute < Virtus::Attribute
5
+
6
+ def self.coerce(value)
7
+ case value
8
+ when Field
9
+ value
10
+ when String
11
+ Field.new(value)
12
+ when Symbol
13
+ Fields.get(value)
14
+ end
15
+ end
16
+
17
+ def coerce(value)
18
+ self.class.coerce(value)
19
+ end
20
+
21
+ end
22
+ end
@@ -2,36 +2,20 @@ module Ddr::Index
2
2
  module Fields
3
3
  extend Deprecation
4
4
 
5
- def self.get(name)
6
- const_get(name.to_s.upcase, false)
7
- end
8
-
9
- def self.techmd
10
- constants(false)
11
- .select { |c| c =~ /\ATECHMD_/ }
12
- .map { |c| const_get(c) }
13
- end
14
-
15
- def self.const_missing(name)
16
- if name == :PID
17
- Deprecation.warn(Fields, "The constant `:PID` is deprecated; use `:ID` instead.")
18
- return ID
19
- end
20
- super
21
- end
22
-
23
5
  ID = UniqueKeyField.instance
24
6
 
25
7
  ACCESS_ROLE = Field.new :access_role, :stored_sortable
26
8
  ACTIVE_FEDORA_MODEL = Field.new :active_fedora_model, :stored_sortable
27
9
  ADMIN_SET = Field.new :admin_set, :stored_sortable
28
10
  ADMIN_SET_FACET = Field.new :admin_set_facet, :facetable
11
+ ASPACE_ID = Field.new :aspace_id, :stored_sortable
29
12
  ATTACHED_FILES = Field.new :attached_files, solr_name: "attached_files_ss"
30
13
  BOX_NUMBER_FACET = Field.new :box_number_facet, :facetable
31
14
  COLLECTION_FACET = Field.new :collection_facet, :facetable
32
15
  COLLECTION_URI = Field.new :collection_uri, :symbol
33
- CONTENT_SIZE = Field.new :content_size, :stored_sortable, type: :integer
16
+ CONTENT_SIZE = Field.new :content_size, solr_name: "content_size_lsi"
34
17
  CONTENT_SIZE_HUMAN = Field.new :content_size_human, :symbol
18
+ CONTRIBUTOR_FACET = Field.new :contributor_facet, :facetable
35
19
  CREATOR_FACET = Field.new :creator_facet, :facetable
36
20
  DATE_FACET = Field.new :date_facet, :facetable
37
21
  DATE_SORT = Field.new :date_sort, :sortable
@@ -73,10 +57,11 @@ module Ddr::Index
73
57
  SERIES_FACET = Field.new :series_facet, :facetable
74
58
  SPATIAL_FACET = Field.new :spatial_facet, :facetable
75
59
  STRUCT_MAPS = Field.new :struct_maps, :stored_sortable
60
+ SUBJECT_FACET = Field.new :subject_facet, :facetable
76
61
  TECHMD_COLOR_SPACE = Field.new :techmd_color_space, :symbol
77
62
  TECHMD_CREATING_APPLICATION = Field.new :techmd_creating_application, :symbol
78
63
  TECHMD_CREATION_TIME = Field.new :techmd_creation_time, :stored_searchable, type: :date
79
- TECHMD_FILE_SIZE = Field.new :techmd_file_size, :stored_searchable, type: :integer
64
+ TECHMD_FILE_SIZE = Field.new :techmd_file_size, solr_name: "techmd_file_size_lsi"
80
65
  TECHMD_FITS_VERSION = Field.new :techmd_fits_version, :stored_sortable
81
66
  TECHMD_FITS_DATETIME = Field.new :techmd_fits_datetime, :stored_sortable, type: :date
82
67
  TECHMD_FORMAT_LABEL = Field.new :techmd_format_label, :symbol
@@ -93,5 +78,29 @@ module Ddr::Index
93
78
  WORKFLOW_STATE = Field.new :workflow_state, :stored_sortable
94
79
  YEAR_FACET = Field.new :year_facet, solr_name: "year_facet_iim"
95
80
 
81
+ def self.get(name)
82
+ const_get(name.to_s.upcase, false)
83
+ end
84
+
85
+ def self.techmd
86
+ @techmd ||= constants(false).select { |c| c =~ /\ATECHMD_/ }.map { |c| const_get(c) }
87
+ end
88
+
89
+ def self.descmd
90
+ @descmd ||= Ddr::Datastreams::DescriptiveMetadataDatastream.properties.map do |base, config|
91
+ Field.new base, *(config.behaviors)
92
+ end
93
+ end
94
+
95
+ def self.const_missing(name)
96
+ if name == :PID
97
+ Deprecation.warn(Ddr::Index::Fields,
98
+ "`Ddr::Index::Fields::#{name}` is deprecated." \
99
+ " Use `Ddr::Index::Fields::ID` instead.")
100
+ return ID
101
+ end
102
+ super
103
+ end
104
+
96
105
  end
97
106
  end