ddr-models 3.0.0.beta.7 → 3.0.0.beta.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +0 -2
  4. data/config/fedora.yml +15 -0
  5. data/config/initializers/subscriptions.rb +1 -0
  6. data/config/solr.yml +6 -0
  7. data/ddr-models.gemspec +1 -1
  8. data/lib/ddr/datastreams.rb +27 -20
  9. data/lib/ddr/datastreams/fits_datastream.rb +1 -5
  10. data/lib/ddr/events/event.rb +3 -1
  11. data/lib/ddr/index/query_builder.rb +0 -17
  12. data/lib/ddr/jobs.rb +1 -0
  13. data/lib/ddr/jobs/delete_multires_image.rb +21 -0
  14. data/lib/ddr/models.rb +8 -11
  15. data/lib/ddr/models/auto_version.rb +13 -0
  16. data/lib/ddr/models/base.rb +6 -1
  17. data/lib/ddr/{datastreams/datastream_behavior.rb → models/file.rb} +14 -13
  18. data/lib/ddr/models/files/fits_xml_file.rb +85 -0
  19. data/lib/ddr/models/files/structural_metadata_file.rb +9 -0
  20. data/lib/ddr/models/has_content.rb +3 -3
  21. data/lib/ddr/models/has_multires_image.rb +9 -7
  22. data/lib/ddr/models/has_thumbnail.rb +15 -17
  23. data/lib/ddr/models/solr_document.rb +3 -3
  24. data/lib/ddr/models/version.rb +1 -1
  25. data/lib/ddr/models/versionable.rb +12 -0
  26. data/lib/ddr/models/with_content_file.rb +3 -3
  27. data/spec/dummy/config/fedora.yml +15 -0
  28. data/spec/dummy/config/solr.yml +6 -0
  29. data/spec/models/{active_fedora_datastream_spec.rb → file_spec.rb} +33 -8
  30. data/spec/models/has_multires_image_spec.rb +23 -0
  31. data/spec/models/with_content_file_spec.rb +4 -4
  32. data/spec/support/shared_examples_for_ddr_models.rb +20 -0
  33. metadata +20 -11
  34. data/config/initializers/active_fedora_file.rb +0 -5
  35. data/lib/ddr/datastreams/metadata_datastream.rb +0 -44
  36. data/lib/ddr/datastreams/plain_text_datastream.rb +0 -9
  37. data/lib/ddr/datastreams/structural_metadata_datastream.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 060df180f9e6610db843d353037b1686bb9b6e31
4
- data.tar.gz: 487bafe0d10284c8033ba37fb578aeb8f9e949aa
3
+ metadata.gz: b9040fdb0b6cda2736d299291211c5a4dde620d7
4
+ data.tar.gz: 42b318beb27882963fc49a4d1278cb94e1116851
5
5
  SHA512:
6
- metadata.gz: deef36f8b5996ad1df4852a3d4849f2543d907659f8ab27ab50e4b8dfbb0ba5f8e90b50d37d6b16568f68bd05f7af87cbdbed7face50f42fd346dfb8bb069f5b
7
- data.tar.gz: b5483a469cadbf2ba1075470dcaefc363c792077694c7b091045bc83242f6d28789dfdcb2017a01a189d62ef92c6efcc60eee5f04dcb70d08f8a2de0a03fd2c1
6
+ metadata.gz: 54f897c2bd20fe04d9877aa5e7b761fe3a29896128009d03d2cf2b80ab3cca5761cfac041bf11043e2fff9cf879f0bfdd714eb72a4355a934876f76c00a33515
7
+ data.tar.gz: 8a7a65a4d731561e19baf8b19439bffd467d0ec02cfcf68951af458c4645e1238b04aee7b8497ce2f16d1d015423cf6dc8e99776b5f431d94fdf44ae3ce71332
data/.gitignore CHANGED
@@ -6,3 +6,4 @@ spec/dummy/db/*.sqlite3
6
6
  spec/dummy/db/*.sqlite3-journal
7
7
  spec/dummy/log/*
8
8
  tmp
9
+ .bundle
data/README.md CHANGED
@@ -4,8 +4,6 @@ A Rails engine providing Hydra and ActiveRecord models and common services for t
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/ddr-models.svg)](http://badge.fury.io/rb/ddr-models)
6
6
  [![Build Status](https://travis-ci.org/duke-libraries/ddr-models.svg?branch=develop)](https://travis-ci.org/duke-libraries/ddr-models)
7
- [![Coverage Status](https://coveralls.io/repos/duke-libraries/ddr-models/badge.png?branch=develop)](https://coveralls.io/r/duke-libraries/ddr-models?branch=develop)
8
- [![Code Climate](https://codeclimate.com/github/duke-libraries/ddr-models/badges/gpa.svg)](https://codeclimate.com/github/duke-libraries/ddr-models)
9
7
 
10
8
  ## Installation
11
9
 
@@ -0,0 +1,15 @@
1
+ development:
2
+ user: fedoraAdmin
3
+ password: fedoraAdmin
4
+ url: http://127.0.0.1:8983/fedora/rest
5
+ base_path: /dev
6
+ test:
7
+ user: fedoraAdmin
8
+ password: fedoraAdmin
9
+ url: http://127.0.0.1:8983/fedora/rest
10
+ base_path: /test
11
+ production:
12
+ user: fedoraAdmin
13
+ password: fedoraAdmin
14
+ url: http://127.0.0.1:8080/fedora/rest
15
+ base_path: /prod
@@ -16,3 +16,4 @@ ActiveSupport::Notifications.subscribe(Ddr::Notifications::UPDATE, Ddr::Events::
16
16
 
17
17
  # Deletion
18
18
  ActiveSupport::Notifications.subscribe(Ddr::Notifications::DELETION, Ddr::Events::DeletionEvent)
19
+ ActiveSupport::Notifications.subscribe(Ddr::Notifications::DELETION, Ddr::Jobs::DeleteMultiresImage)
@@ -0,0 +1,6 @@
1
+ development:
2
+ url: http://localhost:8983/solr/development
3
+ test:
4
+ url: <%= "http://localhost:#{ENV['TEST_JETTY_PORT'] || 8983}/solr/test" %>
5
+ production:
6
+ url: http://your.production.server:8080/bl_solr/core0
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.add_dependency "rails", "~> 4.1.13"
22
22
  s.add_dependency "activeresource"
23
23
  s.add_dependency "active-triples", "~> 0.7.2"
24
- s.add_dependency "active-fedora", "~> 9.6.2"
24
+ s.add_dependency "active-fedora", "~> 9.8.1"
25
25
  s.add_dependency "hydra-validations", "~> 0.5"
26
26
  s.add_dependency "devise", "~> 3.4"
27
27
  s.add_dependency "omniauth-shibboleth", "~> 1.2.0"
@@ -1,34 +1,41 @@
1
- require 'active_fedora'
2
-
3
1
  module Ddr
4
2
  module Datastreams
5
3
  extend ActiveSupport::Autoload
4
+ extend Deprecation
6
5
 
7
- CONTENT = "content"
8
- DC = "DC"
9
- DEFAULT_RIGHTS = "defaultRights"
10
- DESC_METADATA = "descMetadata"
11
- EXTRACTED_TEXT = "extractedText"
12
- FITS = "fits".freeze
13
- RELS_EXT = "RELS-EXT"
14
- RIGHTS_METADATA = "rightsMetadata"
15
- STRUCT_METADATA = "structMetadata"
16
- THUMBNAIL = "thumbnail"
6
+ CONTENT = "content".freeze
7
+ DESC_METADATA = "descMetadata".freeze
8
+ EXTRACTED_TEXT = "extractedText".freeze
9
+ FITS = "fits".freeze
10
+ STRUCT_METADATA = "structMetadata".freeze
11
+ THUMBNAIL = "thumbnail".freeze
17
12
 
18
- CHECKSUM_TYPE_MD5 = "MD5"
19
- CHECKSUM_TYPE_SHA1 = "SHA-1"
13
+ CHECKSUM_TYPE_MD5 = "MD5"
14
+ CHECKSUM_TYPE_SHA1 = "SHA-1"
20
15
  CHECKSUM_TYPE_SHA256 = "SHA-256"
21
16
  CHECKSUM_TYPE_SHA384 = "SHA-384"
22
17
  CHECKSUM_TYPE_SHA512 = "SHA-512"
23
18
 
24
19
  CHECKSUM_TYPES = [ CHECKSUM_TYPE_MD5, CHECKSUM_TYPE_SHA1, CHECKSUM_TYPE_SHA256, CHECKSUM_TYPE_SHA384, CHECKSUM_TYPE_SHA512 ]
25
20
 
26
- autoload :DatastreamBehavior
27
- autoload :DescriptiveMetadataDatastream
28
- autoload :FitsDatastream
29
- autoload :MetadataDatastream
30
- autoload :PlainTextDatastream
31
- autoload :StructuralMetadataDatastream
21
+ def self.const_missing(name)
22
+ case name
23
+ when :FitsDatastream
24
+ Deprecation.warn(self, "Ddr::Datastreams::FitsDatastream is deprecated." \
25
+ " Use Ddr::Models::FitsXmlFile instead.")
26
+ Ddr::Models::FitsXmlFile
27
+ when :StructuralMetadataDatastream
28
+ Deprecation.warn(self, "Ddr::Datastreams::StructuralMetadataDatastream is deprecated." \
29
+ " Use Ddr::Models::StructuralMetadataFile instead.")
30
+ Ddr::Models::StructuralMetadataFile
31
+ when :PlainTextDatastream
32
+ Deprecation.warn(self, "Ddr::Datastreams::PlainTextDatastream is deprecated." \
33
+ " Use Ddr::Models::File instead.")
34
+ Ddr::Models::File
35
+ else
36
+ super
37
+ end
38
+ end
32
39
 
33
40
  end
34
41
  end
@@ -1,5 +1,6 @@
1
1
  module Ddr::Datastreams
2
2
  class FitsDatastream < ActiveFedora::OmDatastream
3
+ extend AutoVersion
3
4
 
4
5
  FITS_XMLNS = "http://hul.harvard.edu/ois/xml/ns/fits/fits_output".freeze
5
6
  FITS_SCHEMA = "http://hul.harvard.edu/ois/xml/xsd/fits/fits_output.xsd".freeze
@@ -74,11 +75,6 @@ module Ddr::Datastreams
74
75
  builder.doc
75
76
  end
76
77
 
77
- # TODO fix or remove
78
- # def prefix
79
- # "fits__"
80
- # end
81
-
82
78
  def modified
83
79
  ng_xml
84
80
  .xpath("//fits:fileinfo/fits:lastmodified[@toolname != '#{EXIFTOOL}']", fits: FITS_XMLNS)
@@ -39,7 +39,9 @@ module Ddr
39
39
  # Receive message sent by ActiveSupport::Notifications
40
40
  def self.call(*args)
41
41
  notification = ActiveSupport::Notifications::Event.new(*args)
42
- create(notification.payload)
42
+ evt = new
43
+ attrs = notification.payload.dup.keep_if { |k, v| evt.has_attribute?(k) }
44
+ evt.update(attrs)
43
45
  end
44
46
 
45
47
  # Scopes
@@ -91,18 +91,6 @@ module Ddr::Index
91
91
  #
92
92
  class QueryBuilder
93
93
 
94
- # Builds a Query object
95
- # @yield [builder] a new QueryBuilder instance.
96
- # @return [Query]
97
- def self.build
98
- Deprecation.warn(self,
99
- "`Ddr::Index::QueryBuilder.build` is deprecated and will be removed in ddr-models 3.0." \
100
- " Use `Ddr::Index::QueryBuilder.new` instead.")
101
- builder = new
102
- yield builder
103
- builder.query
104
- end
105
-
106
94
  attr_reader :query
107
95
 
108
96
  def initialize(query = nil, &block)
@@ -146,11 +134,6 @@ module Ddr::Index
146
134
  # @param orderings [Hash<Field, String>]
147
135
  # @return [QueryBuilder] self
148
136
  def order_by(*orderings)
149
- unless orderings.first.is_a? Hash
150
- Deprecation.warn(QueryBuilder, "`order_by` will require a hash of orderings in ddr-models 3.0.")
151
- field, order = orderings
152
- return order_by(field => order)
153
- end
154
137
  query.sort += orderings.first.map { |field, order| SortOrder.new(field: field, order: order) }
155
138
  self
156
139
  end
@@ -2,6 +2,7 @@ module Ddr
2
2
  module Jobs
3
3
  extend ActiveSupport::Autoload
4
4
 
5
+ autoload :DeleteMultiresImage
5
6
  autoload :FitsFileCharacterization
6
7
  autoload :FixityCheck
7
8
  autoload :Job
@@ -0,0 +1,21 @@
1
+ module Ddr::Jobs
2
+ class DeleteMultiresImage
3
+ extend Job
4
+
5
+ @queue = :general
6
+
7
+ def self.call(*args)
8
+ event = ActiveSupport::Notifications::Event.new(*args)
9
+ if event.name == Ddr::Notifications::DELETION &&
10
+ file_uri = event.payload[:multires_image_file_path]
11
+ Resque.enqueue(self, file_uri)
12
+ end
13
+ end
14
+
15
+ def self.perform(file_uri)
16
+ path = Ddr::Utils.path_from_uri(file_uri)
17
+ File.unlink(path)
18
+ end
19
+
20
+ end
21
+ end
@@ -7,7 +7,6 @@ require 'hydra/validations'
7
7
 
8
8
  module Ddr
9
9
  extend ActiveSupport::Autoload
10
- extend Deprecation
11
10
 
12
11
  autoload :Actions
13
12
  autoload :Auth
@@ -22,22 +21,13 @@ module Ddr
22
21
  autoload :Utils
23
22
  autoload :Vocab
24
23
 
25
- def self.const_missing(name)
26
- if name == :IndexFields
27
- Deprecation.warn(Ddr::Models, "`Ddr::IndexFields` is deprecated and will be removed in ddr-models 3.0." \
28
- " Use `Ddr::Index::Fields` instead.")
29
- Index::Fields
30
- else
31
- super
32
- end
33
- end
34
-
35
24
  module Models
36
25
  extend ActiveSupport::Autoload
37
26
 
38
27
  autoload :AdminSet
39
28
  autoload :AttachedFileProfile
40
29
  autoload :AttachedFilesProfile
30
+ autoload :AutoVersion
41
31
  autoload :Base
42
32
  autoload :ChecksumInvalid, 'ddr/models/error'
43
33
  autoload :Contact
@@ -45,6 +35,7 @@ module Ddr
45
35
  autoload :DerivativeGenerationFailure, 'ddr/models/error'
46
36
  autoload :Error
47
37
  autoload :EventLoggable
38
+ autoload :File
48
39
  autoload :FileCharacterization
49
40
  autoload :FileManagement
50
41
  autoload :FindingAid
@@ -66,9 +57,15 @@ module Ddr
66
57
  autoload :UrlSafeId
67
58
  autoload :Validatable
68
59
  autoload :Validator
60
+ autoload :Versionable
69
61
  autoload :WithContentFile
70
62
  autoload :YearFacet
71
63
 
64
+ autoload_under "files" do
65
+ autoload :FitsXmlFile
66
+ autoload :StructuralMetadataFile
67
+ end
68
+
72
69
  autoload_under "licenses" do
73
70
  autoload :AdminPolicyLicense
74
71
  autoload :EffectiveLicense
@@ -0,0 +1,13 @@
1
+ module Ddr::Models
2
+ module AutoVersion
3
+
4
+ def self.extended(base)
5
+ base.include Versionable
6
+
7
+ base.class_eval do
8
+ after_save :create_version
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -11,9 +11,10 @@ module Ddr::Models
11
11
  include Indexing
12
12
  include Hydra::Validations
13
13
  include HasAdminMetadata
14
+ extend AutoVersion
14
15
 
15
16
  after_destroy do
16
- notify_event :deletion
17
+ notify_event(:deletion, deletion_event_payload)
17
18
  end
18
19
 
19
20
  DescriptiveMetadata.mapping.each do |name, term|
@@ -115,5 +116,9 @@ module Ddr::Models
115
116
  self
116
117
  end
117
118
 
119
+ def deletion_event_payload
120
+ {}
121
+ end
122
+
118
123
  end
119
124
  end
@@ -1,28 +1,29 @@
1
- module Ddr::Datastreams
2
- module DatastreamBehavior
1
+ require 'tempfile'
2
+
3
+ module Ddr::Models
4
+ class File < ActiveFedora::File
5
+ extend AutoVersion
3
6
  extend Deprecation
4
7
 
5
8
  DEFAULT_FILE_EXTENSION = "bin"
6
9
  STRFTIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%LZ"
7
10
 
8
11
  def dsid
9
- Deprecation.warn(DatastreamBehavior,
10
- "`dsid` is no longer a datastream/file method. Use `File.basename(id)`.")
12
+ Deprecation.warn(File, "`dsid` is no longer a file method. Use `::File.basename(id)`.")
11
13
  if id
12
14
  ::File.basename(id)
13
15
  end
14
16
  end
15
17
 
16
18
  def dsCreateDate
17
- Deprecation.warn(DatastreamBehavior,
18
- "`dsCreateDate` is no longer a datastream/file method. Use `create_date` instead.")
19
+ Deprecation.warn(File, "`dsCreateDate` is no longer a file method. Use `create_date` instead.")
19
20
  create_date
20
21
  end
21
22
 
22
23
  def validate_checksum!(checksum_value, checksum_type=nil)
23
- raise Ddr::Models::Error, "Checksum cannot be validated on new datastream." if new_record?
24
- raise Ddr::Models::Error, "Checksum cannot be validated on unpersisted content." if content_changed?
25
- raise Ddr::Models::ChecksumInvalid, "The repository internal checksum validation failed." unless check_fixity
24
+ raise Error, "Checksum cannot be validated on new file." if new_record?
25
+ raise Error, "Checksum cannot be validated on unpersisted content." if content_changed?
26
+ raise ChecksumInvalid, "The repository internal checksum validation failed." unless check_fixity
26
27
  algorithm = checksum_type || checksum.algorithm
27
28
  calculated_checksum = if algorithm == checksum.algorithm
28
29
  checksum.value
@@ -30,9 +31,9 @@ module Ddr::Datastreams
30
31
  content_digest(algorithm)
31
32
  end
32
33
  if checksum_value == calculated_checksum
33
- "The checksum #{algorithm}:#{checksum_value} is valid for datastream #{dsid}."
34
+ "The checksum #{algorithm}:#{checksum_value} is valid for file #{dsid}."
34
35
  else
35
- raise Ddr::Models::ChecksumInvalid, "The checksum #{algorithm}:#{checksum_value} is not valid for datastream #{dsid}."
36
+ raise ChecksumInvalid, "The checksum #{algorithm}:#{checksum_value} is not valid for file #{dsid}."
36
37
  end
37
38
  end
38
39
 
@@ -44,7 +45,7 @@ module Ddr::Datastreams
44
45
  Ddr::Utils.digest(content, algorithm)
45
46
  end
46
47
 
47
- # Return default file extension for datastream based on MIME type
48
+ # Return default file extension for file based on MIME type
48
49
  def default_file_extension
49
50
  mimetypes = MIME::Types[mime_type]
50
51
  return mimetypes.first.extensions.first unless mimetypes.empty?
@@ -67,7 +68,7 @@ module Ddr::Datastreams
67
68
 
68
69
  def tempfile(prefix: nil, suffix: nil)
69
70
  if empty?
70
- raise Ddr::Models::Error, "Refusing to create tempfile for empty datastream!"
71
+ raise Error, "Refusing to create tempfile for empty file!"
71
72
  end
72
73
  prefix ||= default_file_prefix + "--"
73
74
  suffix ||= "." + default_file_extension
@@ -0,0 +1,85 @@
1
+ module Ddr::Models
2
+ class FitsXmlFile < ActiveFedora::OmDatastream
3
+ extend AutoVersion
4
+
5
+ FITS_XMLNS = "http://hul.harvard.edu/ois/xml/ns/fits/fits_output".freeze
6
+ FITS_SCHEMA = "http://hul.harvard.edu/ois/xml/xsd/fits/fits_output.xsd".freeze
7
+
8
+ EXIFTOOL = "Exiftool"
9
+
10
+ set_terminology do |t|
11
+ t.root(path: "fits",
12
+ xmlns: FITS_XMLNS,
13
+ schema: FITS_SCHEMA)
14
+ t.version(path: {attribute: "version"})
15
+ t.timestamp(path: {attribute: "timestamp"})
16
+ t.identification {
17
+ t.identity {
18
+ t.mimetype(path: {attribute: "mimetype"})
19
+ t.format_label(path: {attribute: "format"})
20
+ t.version
21
+ t.externalIdentifier
22
+ t.pronom_identifier(path: "externalIdentifier", attributes: {type: "puid"})
23
+ }
24
+ }
25
+ t.fileinfo {
26
+ t.size
27
+ t.creatingApplicationName
28
+ t.created
29
+ t.lastmodified
30
+ }
31
+ t.filestatus {
32
+ t.valid
33
+ t.well_formed(path: "well-formed")
34
+ }
35
+ t.metadata {
36
+ t.image {
37
+ t.imageWidth
38
+ t.imageHeight
39
+ t.colorSpace
40
+ }
41
+ t.document {
42
+ # TODO - configure to get from Tika?
43
+ # t.encoding
44
+ }
45
+ t.text
46
+ t.audio
47
+ t.video
48
+ }
49
+
50
+ ## proxy terms
51
+ # identification / identity
52
+ t.media_type proxy: [:identification, :identity, :mimetype]
53
+ t.format_label proxy: [:identification, :identity, :format_label]
54
+ t.format_version proxy: [:identification, :identity, :version]
55
+ t.pronom_identifier proxy: [:identification, :identity, :pronom_identifier]
56
+ # filestatus
57
+ t.valid proxy: [:filestatus, :valid]
58
+ t.well_formed proxy: [:filestatus, :well_formed]
59
+ # fileinfo
60
+ t.created proxy: [:fileinfo, :created]
61
+ t.creating_application proxy: [:fileinfo, :creatingApplicationName]
62
+ t.extent proxy: [:fileinfo, :size]
63
+ # image metadata
64
+ t.image_width proxy: [:metadata, :image, :imageWidth]
65
+ t.image_height proxy: [:metadata, :image, :imageHeight]
66
+ t.color_space proxy: [:metadata, :image, :colorSpace]
67
+ end
68
+
69
+ def self.xml_template
70
+ builder = Nokogiri::XML::Builder.new do |xml|
71
+ xml.fits("xmlns"=>FITS_XMLNS,
72
+ "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance",
73
+ "xsi:schemaLocation"=>"http://hul.harvard.edu/ois/xml/ns/fits/fits_output http://hul.harvard.edu/ois/xml/xsd/fits/fits_output.xsd")
74
+ end
75
+ builder.doc
76
+ end
77
+
78
+ def modified
79
+ ng_xml
80
+ .xpath("//fits:fileinfo/fits:lastmodified[@toolname != '#{EXIFTOOL}']", fits: FITS_XMLNS)
81
+ .map(&:text)
82
+ end
83
+
84
+ end
85
+ end
@@ -0,0 +1,9 @@
1
+ module Ddr::Models
2
+ class StructuralMetadataFile < File
3
+
4
+ def default_mime_type
5
+ 'text/xml'
6
+ end
7
+
8
+ end
9
+ end
@@ -5,9 +5,9 @@ module Ddr
5
5
  extend Deprecation
6
6
 
7
7
  included do
8
- contains Ddr::Datastreams::CONTENT
9
- contains Ddr::Datastreams::EXTRACTED_TEXT, class_name: 'Ddr::Datastreams::PlainTextDatastream'
10
- contains Ddr::Datastreams::FITS, class_name: 'Ddr::Datastreams::FitsDatastream'
8
+ contains Ddr::Datastreams::CONTENT, class_name: 'Ddr::Models::File'
9
+ contains Ddr::Datastreams::EXTRACTED_TEXT, class_name: 'Ddr::Models::File'
10
+ contains Ddr::Datastreams::FITS, class_name: 'Ddr::Models::FitsXmlFile'
11
11
 
12
12
  property :legacy_original_filename,
13
13
  predicate: RDF::Vocab::PREMIS.hasOriginalName,
@@ -1,12 +1,14 @@
1
- module Ddr
2
- module Models
3
- module HasMultiresImage
4
- extend ActiveSupport::Concern
1
+ module Ddr::Models
2
+ module HasMultiresImage
3
+ extend ActiveSupport::Concern
5
4
 
6
- included do
7
- property :multires_image_file_path, predicate: Ddr::Vocab::Asset.multiresImageFilePath, multiple: false
8
- end
5
+ included do
6
+ property :multires_image_file_path, predicate: Ddr::Vocab::Asset.multiresImageFilePath, multiple: false
7
+ end
9
8
 
9
+ def deletion_event_payload
10
+ super.merge(multires_image_file_path: multires_image_file_path)
10
11
  end
12
+
11
13
  end
12
14
  end
@@ -1,24 +1,22 @@
1
- module Ddr
2
- module Models
3
- module HasThumbnail
4
- extend ActiveSupport::Concern
1
+ module Ddr::Models
2
+ module HasThumbnail
3
+ extend ActiveSupport::Concern
5
4
 
6
- included do
7
- contains Ddr::Datastreams::THUMBNAIL
8
- end
5
+ included do
6
+ contains Ddr::Datastreams::THUMBNAIL, class_name: "Ddr::Models::File"
7
+ end
9
8
 
10
- def thumbnail_changed?
11
- thumbnail.content_changed?
12
- end
9
+ def thumbnail_changed?
10
+ thumbnail.content_changed?
11
+ end
13
12
 
14
- def copy_thumbnail_from(other)
15
- if other && other.has_thumbnail?
16
- self.thumbnail.content = other.thumbnail.content
17
- self.thumbnail.mimeType = other.thumbnail.mimeType if thumbnail_changed?
18
- end
19
- thumbnail_changed?
13
+ def copy_thumbnail_from(other)
14
+ if other && other.has_thumbnail?
15
+ self.thumbnail.content = other.thumbnail.content
16
+ self.thumbnail.mimeType = other.thumbnail.mimeType if thumbnail_changed?
20
17
  end
21
-
18
+ thumbnail_changed?
22
19
  end
20
+
23
21
  end
24
22
  end
@@ -9,12 +9,12 @@ module Ddr::Models
9
9
  class NotFound < Error; end
10
10
 
11
11
  module ClassMethods
12
- def find(id)
13
- query = Ddr::Index::QueryBuilder.build { |q| q.id(id) }
12
+ def find(doc_id)
13
+ query = Ddr::Index::Query.new { id doc_id }
14
14
  if doc = query.docs.first
15
15
  return doc
16
16
  end
17
- raise NotFound, "SolrDocument not found for \"#{id}\"."
17
+ raise NotFound, "SolrDocument not found for \"#{doc_id}\"."
18
18
  end
19
19
  end
20
20
 
@@ -1,5 +1,5 @@
1
1
  module Ddr
2
2
  module Models
3
- VERSION = "3.0.0.beta.7"
3
+ VERSION = "3.0.0.beta.8"
4
4
  end
5
5
  end
@@ -0,0 +1,12 @@
1
+ module Ddr::Models
2
+ module Versionable
3
+
4
+ # Override AF::Versionable
5
+ # @example
6
+ # => "version.20160205153424.643252000"
7
+ def version_name
8
+ "version.#{Time.now.utc.strftime('%Y%m%d%H%M%S.%N')}"
9
+ end
10
+
11
+ end
12
+ end
@@ -13,7 +13,7 @@ module Ddr::Models
13
13
  # @yield [String] the path to the tempfile containing content
14
14
  def with_temp_file
15
15
  filename = original_filename || content.default_file_name
16
- basename = [ File.basename(filename, ".*"), File.extname(filename) ]
16
+ basename = [ ::File.basename(filename, ".*"), ::File.extname(filename) ]
17
17
  infile = Tempfile.open(basename, Ddr::Models.tempdir, encoding: 'ascii-8bit')
18
18
  begin
19
19
  infile.write(content.content)
@@ -22,12 +22,12 @@ module Ddr::Models
22
22
  yield infile.path
23
23
  ensure
24
24
  infile.close unless infile.closed?
25
- File.unlink(infile)
25
+ ::File.unlink(infile)
26
26
  end
27
27
  end
28
28
 
29
29
  def verify_checksum!(file)
30
- digest = Ddr::Utils.digest(File.read(file), content.checksum.algorithm)
30
+ digest = Ddr::Utils.digest(::File.read(file), content.checksum.algorithm)
31
31
  if digest != content.checksum.value
32
32
  raise ChecksumInvalid, "The checksum of the downloaded file does not match the stored checksum of the content."
33
33
  end
@@ -0,0 +1,15 @@
1
+ development:
2
+ user: fedoraAdmin
3
+ password: fedoraAdmin
4
+ url: http://127.0.0.1:8983/fedora/rest
5
+ base_path: /dev
6
+ test:
7
+ user: fedoraAdmin
8
+ password: fedoraAdmin
9
+ url: http://127.0.0.1:8983/fedora/rest
10
+ base_path: /test
11
+ production:
12
+ user: fedoraAdmin
13
+ password: fedoraAdmin
14
+ url: http://127.0.0.1:8080/fedora/rest
15
+ base_path: /prod
@@ -0,0 +1,6 @@
1
+ development:
2
+ url: http://localhost:8983/solr/development
3
+ test:
4
+ url: <%= "http://localhost:#{ENV['TEST_JETTY_PORT'] || 8983}/solr/test" %>
5
+ production:
6
+ url: http://your.production.server:8080/bl_solr/core0
@@ -1,12 +1,34 @@
1
1
  require 'spec_helper'
2
2
 
3
- module ActiveFedora
4
- RSpec.describe Datastream do
3
+ module Ddr::Models
4
+ RSpec.describe File do
5
+
6
+ describe "versioning" do
7
+ let(:obj) { FactoryGirl.build(:component) }
8
+ describe "on create" do
9
+ it "creates a version" do
10
+ expect { obj.save }.to change { obj.content.has_versions? }.from(false).to(true)
11
+ obj.save
12
+ expect(obj.content.versions.all.size).to eq 1
13
+ end
14
+ end
15
+ describe "on update" do
16
+ it "creates a version" do
17
+ obj.save
18
+ expect {
19
+ obj.upload fixture_file_upload("imageB.tif", "image/tiff")
20
+ obj.save
21
+ }.to change {
22
+ obj.content.versions.all.size
23
+ }.by(1)
24
+ end
25
+ end
26
+ end
5
27
 
6
28
  describe "#tempfile" do
7
29
  describe "when the datastream has no content" do
8
30
  it "should raise an exception" do
9
- expect { subject.tempfile { |f| puts f.path } }.to raise_error(Ddr::Models::Error)
31
+ expect { subject.tempfile { |f| puts f.path } }.to raise_error(Error)
10
32
  end
11
33
  end
12
34
  describe "when the datastream has content" do
@@ -37,7 +59,8 @@ module ActiveFedora
37
59
  it "should start with the id" do
38
60
  allow(subject).to receive(:id) { "4f/78/97/71/4f789771-c663-466a-98a8-fd7c6fa0f452/foo" }
39
61
  subject.tempfile do |f|
40
- expect(::File.basename(f.path).start_with?("4f_78_97_71_4f789771-c663-466a-98a8-fd7c6fa0f452_foo--")).to be true
62
+ expect(::File.basename(f.path).start_with?("4f_78_97_71_4f789771-c663-466a-98a8-fd7c6fa0f452_foo--"))
63
+ .to be true
41
64
  end
42
65
  end
43
66
  end
@@ -66,13 +89,15 @@ module ActiveFedora
66
89
  context "the datstream is new" do
67
90
  before { allow(subject).to receive(:new_record?) { true } }
68
91
  it "should raise an exception" do
69
- expect { subject.validate_checksum!("bb3200c2ddaee4bd7b9a4dc1ad3e10ed886eaef1") }.to raise_error(Ddr::Models::Error)
92
+ expect { subject.validate_checksum!("bb3200c2ddaee4bd7b9a4dc1ad3e10ed886eaef1") }
93
+ .to raise_error(Error)
70
94
  end
71
95
  end
72
96
  context "the datastream content has changed" do
73
97
  before { allow(subject).to receive(:content_changed?) { true } }
74
98
  it "should raise an exception" do
75
- expect { subject.validate_checksum!("bb3200c2ddaee4bd7b9a4dc1ad3e10ed886eaef1") }.to raise_error(Ddr::Models::Error)
99
+ expect { subject.validate_checksum!("bb3200c2ddaee4bd7b9a4dc1ad3e10ed886eaef1") }
100
+ .to raise_error(Error)
76
101
  end
77
102
  end
78
103
  end
@@ -86,7 +111,7 @@ module ActiveFedora
86
111
  before { allow(subject).to receive(:check_fixity) { false } }
87
112
  it "should raise an error" do
88
113
  expect { subject.validate_checksum!(checksum.value, checksum.algorithm) }
89
- .to raise_error(Ddr::Models::ChecksumInvalid)
114
+ .to raise_error(ChecksumInvalid)
90
115
  end
91
116
  end
92
117
  context "and the repository internal checksum is valid" do
@@ -118,7 +143,7 @@ module ActiveFedora
118
143
  context "and the checksum doesn't match" do
119
144
  it "should raise an exception" do
120
145
  expect { subject.validate_checksum!("0123456789abcdef", checksum.algorithm) }
121
- .to raise_error(Ddr::Models::ChecksumInvalid)
146
+ .to raise_error(ChecksumInvalid)
122
147
  end
123
148
  end
124
149
  end
@@ -0,0 +1,23 @@
1
+ module Ddr::Models
2
+ RSpec.describe HasMultiresImage do
3
+
4
+ subject { FactoryGirl.create(:component) }
5
+
6
+ describe "cleaning up multires image file after destroy" do
7
+ before {
8
+ @file = Tempfile.create('foo')
9
+ @path = @file.path
10
+ }
11
+ after {
12
+ ::File.unlink(@path) if ::File.exist?(@path)
13
+ }
14
+ it "deletes the file" do
15
+ subject.multires_image_file_path = "file:#{@path}"
16
+ subject.save!
17
+ subject.destroy
18
+ expect(::File.exist?(@path)).to be false
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -6,20 +6,20 @@ module Ddr::Models
6
6
  it "yields a temp file path to the block and deletes the temp file afterwards" do
7
7
  WithContentFile.new(obj) do |path|
8
8
  @path = path
9
- expect(File.exist?(path)).to be true
9
+ expect(::File.exist?(path)).to be true
10
10
  end
11
- expect(File.exist?(@path)).to be false
11
+ expect(::File.exist?(@path)).to be false
12
12
  end
13
13
 
14
14
  it "deletes the temp file even when an exception is raised in the block" do
15
15
  begin
16
16
  WithContentFile.new(obj) do |path|
17
17
  @path = path
18
- expect(File.exist?(path)).to be true
18
+ expect(::File.exist?(path)).to be true
19
19
  raise Error, "error"
20
20
  end
21
21
  rescue Error
22
- expect(File.exist?(@path)).to be false
22
+ expect(::File.exist?(@path)).to be false
23
23
  end
24
24
  end
25
25
 
@@ -22,4 +22,24 @@ RSpec.shared_examples "a DDR model" do
22
22
  end
23
23
  end
24
24
 
25
+ describe "versioning" do
26
+ describe "on create" do
27
+ it "creates a version" do
28
+ expect { subject.save(validate: false) }
29
+ .to change(subject, :has_versions?).from(false).to(true)
30
+ end
31
+ end
32
+ describe "on update" do
33
+ before { subject.save(validate: false) }
34
+ it "creates a version" do
35
+ expect {
36
+ subject.dc_title = ["Changed Title"]
37
+ subject.save(validate: false)
38
+ }.to change {
39
+ subject.versions.all.size
40
+ }.by(1)
41
+ end
42
+ end
43
+ end
44
+
25
45
  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.beta.7
4
+ version: 3.0.0.beta.8
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-02-02 00:00:00.000000000 Z
12
+ date: 2016-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -59,14 +59,14 @@ dependencies:
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: 9.6.2
62
+ version: 9.8.1
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: 9.6.2
69
+ version: 9.8.1
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: hydra-validations
72
72
  requirement: !ruby/object:Gem::Requirement
@@ -399,12 +399,13 @@ files:
399
399
  - app/views/devise/sessions/new.html.erb
400
400
  - app/views/devise/shared/_links.erb
401
401
  - bin/rails
402
+ - config/fedora.yml
402
403
  - config/initializers/active_fedora_base.rb
403
- - config/initializers/active_fedora_file.rb
404
404
  - config/initializers/devise.rb
405
405
  - config/initializers/subscriptions.rb
406
406
  - config/locales/ddr-models.en.yml
407
407
  - config/routes.rb
408
+ - config/solr.yml
408
409
  - db/migrate/20141021233359_create_events.rb
409
410
  - db/migrate/20141021234156_create_minted_ids.rb
410
411
  - db/migrate/20141103192146_create_workflow_state.rb
@@ -468,12 +469,8 @@ files:
468
469
  - lib/ddr/auth/user.rb
469
470
  - lib/ddr/auth/web_auth_context.rb
470
471
  - lib/ddr/datastreams.rb
471
- - lib/ddr/datastreams/datastream_behavior.rb
472
472
  - lib/ddr/datastreams/descriptive_metadata_datastream.rb
473
473
  - lib/ddr/datastreams/fits_datastream.rb
474
- - lib/ddr/datastreams/metadata_datastream.rb
475
- - lib/ddr/datastreams/plain_text_datastream.rb
476
- - lib/ddr/datastreams/structural_metadata_datastream.rb
477
474
  - lib/ddr/derivatives.rb
478
475
  - lib/ddr/derivatives/derivative.rb
479
476
  - lib/ddr/derivatives/generators/generator.rb
@@ -513,6 +510,7 @@ files:
513
510
  - lib/ddr/index/sort_order.rb
514
511
  - lib/ddr/index/unique_key_field.rb
515
512
  - lib/ddr/jobs.rb
513
+ - lib/ddr/jobs/delete_multires_image.rb
516
514
  - lib/ddr/jobs/fits_file_characterization.rb
517
515
  - lib/ddr/jobs/fixity_check.rb
518
516
  - lib/ddr/jobs/job.rb
@@ -531,13 +529,17 @@ files:
531
529
  - lib/ddr/models/admin_set.rb
532
530
  - lib/ddr/models/attached_file_profile.rb
533
531
  - lib/ddr/models/attached_files_profile.rb
532
+ - lib/ddr/models/auto_version.rb
534
533
  - lib/ddr/models/base.rb
535
534
  - lib/ddr/models/contact.rb
536
535
  - lib/ddr/models/engine.rb
537
536
  - lib/ddr/models/error.rb
538
537
  - lib/ddr/models/event_loggable.rb
538
+ - lib/ddr/models/file.rb
539
539
  - lib/ddr/models/file_characterization.rb
540
540
  - lib/ddr/models/file_management.rb
541
+ - lib/ddr/models/files/fits_xml_file.rb
542
+ - lib/ddr/models/files/structural_metadata_file.rb
541
543
  - lib/ddr/models/finding_aid.rb
542
544
  - lib/ddr/models/fixity_checkable.rb
543
545
  - lib/ddr/models/governable.rb
@@ -570,6 +572,7 @@ files:
570
572
  - lib/ddr/models/validatable.rb
571
573
  - lib/ddr/models/validator.rb
572
574
  - lib/ddr/models/version.rb
575
+ - lib/ddr/models/versionable.rb
573
576
  - lib/ddr/models/with_content_file.rb
574
577
  - lib/ddr/models/year_facet.rb
575
578
  - lib/ddr/notifications.rb
@@ -633,6 +636,7 @@ files:
633
636
  - spec/dummy/config/environments/development.rb
634
637
  - spec/dummy/config/environments/production.rb
635
638
  - spec/dummy/config/environments/test.rb
639
+ - spec/dummy/config/fedora.yml
636
640
  - spec/dummy/config/initializers/assets.rb
637
641
  - spec/dummy/config/initializers/backtrace_silencers.rb
638
642
  - spec/dummy/config/initializers/cookies_serializer.rb
@@ -644,6 +648,7 @@ files:
644
648
  - spec/dummy/config/locales/en.yml
645
649
  - spec/dummy/config/routes.rb
646
650
  - spec/dummy/config/secrets.yml
651
+ - spec/dummy/config/solr.yml
647
652
  - spec/dummy/db/schema.rb
648
653
  - spec/dummy/lib/assets/.keep
649
654
  - spec/dummy/log/.keep
@@ -688,7 +693,6 @@ files:
688
693
  - spec/managers/derivatives_manager_spec.rb
689
694
  - spec/managers/technical_metadata_manager_spec.rb
690
695
  - spec/models/active_fedora_base_spec.rb
691
- - spec/models/active_fedora_datastream_spec.rb
692
696
  - spec/models/admin_set_spec.rb
693
697
  - spec/models/attachment_spec.rb
694
698
  - spec/models/collection_spec.rb
@@ -699,9 +703,11 @@ files:
699
703
  - spec/models/events_spec.rb
700
704
  - spec/models/file_characterization_spec.rb
701
705
  - spec/models/file_management_spec.rb
706
+ - spec/models/file_spec.rb
702
707
  - spec/models/finding_aid_spec.rb
703
708
  - spec/models/has_admin_metadata_spec.rb
704
709
  - spec/models/has_children_spec.rb
710
+ - spec/models/has_multires_image_spec.rb
705
711
  - spec/models/has_struct_metadata_spec.rb
706
712
  - spec/models/indexing_spec.rb
707
713
  - spec/models/item_spec.rb
@@ -804,6 +810,7 @@ test_files:
804
810
  - spec/dummy/config/environments/development.rb
805
811
  - spec/dummy/config/environments/production.rb
806
812
  - spec/dummy/config/environments/test.rb
813
+ - spec/dummy/config/fedora.yml
807
814
  - spec/dummy/config/initializers/assets.rb
808
815
  - spec/dummy/config/initializers/backtrace_silencers.rb
809
816
  - spec/dummy/config/initializers/cookies_serializer.rb
@@ -815,6 +822,7 @@ test_files:
815
822
  - spec/dummy/config/locales/en.yml
816
823
  - spec/dummy/config/routes.rb
817
824
  - spec/dummy/config/secrets.yml
825
+ - spec/dummy/config/solr.yml
818
826
  - spec/dummy/db/schema.rb
819
827
  - spec/dummy/lib/assets/.keep
820
828
  - spec/dummy/log/.keep
@@ -859,7 +867,6 @@ test_files:
859
867
  - spec/managers/derivatives_manager_spec.rb
860
868
  - spec/managers/technical_metadata_manager_spec.rb
861
869
  - spec/models/active_fedora_base_spec.rb
862
- - spec/models/active_fedora_datastream_spec.rb
863
870
  - spec/models/admin_set_spec.rb
864
871
  - spec/models/attachment_spec.rb
865
872
  - spec/models/collection_spec.rb
@@ -870,9 +877,11 @@ test_files:
870
877
  - spec/models/events_spec.rb
871
878
  - spec/models/file_characterization_spec.rb
872
879
  - spec/models/file_management_spec.rb
880
+ - spec/models/file_spec.rb
873
881
  - spec/models/finding_aid_spec.rb
874
882
  - spec/models/has_admin_metadata_spec.rb
875
883
  - spec/models/has_children_spec.rb
884
+ - spec/models/has_multires_image_spec.rb
876
885
  - spec/models/has_struct_metadata_spec.rb
877
886
  - spec/models/indexing_spec.rb
878
887
  - spec/models/item_spec.rb
@@ -1,5 +0,0 @@
1
- module ActiveFedora
2
- class File
3
- include Ddr::Datastreams::DatastreamBehavior
4
- end
5
- end
@@ -1,44 +0,0 @@
1
- module Ddr
2
- module Datastreams
3
- class MetadataDatastream < ActiveFedora::NtriplesRDFDatastream
4
-
5
- def self.term_names
6
- properties.keys.map(&:to_sym).sort
7
- end
8
-
9
- # Returns ActiveTriplesTerm now that this is an RDF datastream
10
- def values term
11
- term == :format ? self.format : self.send(term)
12
- end
13
-
14
- # Update term with values
15
- # Note that empty values (nil or "") are rejected from values array
16
- def set_values term, values
17
- if values.respond_to?(:reject!)
18
- values.reject! { |v| v.blank? }
19
- else
20
- values = nil if values.blank?
21
- end
22
- begin
23
- self.send("#{term}=", values)
24
- rescue NoMethodError
25
- raise ArgumentError, "No such term: #{term}"
26
- end
27
- end
28
-
29
- # Add value to term
30
- # Note that empty value (nil or "") is not added
31
- def add_value term, value
32
- begin
33
- unless value.blank?
34
- values = values(term).to_a << value
35
- set_values term, values
36
- end
37
- rescue NoMethodError
38
- raise ArgumentError, "No such term: #{term}"
39
- end
40
- end
41
-
42
- end
43
- end
44
- end
@@ -1,9 +0,0 @@
1
- module Ddr
2
- module Datastreams
3
- class PlainTextDatastream < ActiveFedora::Datastream
4
- def self.default_attributes
5
- super.merge(mimeType: "text/plain")
6
- end
7
- end
8
- end
9
- end
@@ -1,11 +0,0 @@
1
- require "rdf/vocab"
2
-
3
- module Ddr
4
- module Datastreams
5
- class StructuralMetadataDatastream < ActiveFedora::Datastream
6
- def self.default_attributes
7
- super.merge({ mimeType: 'text/xml', dsLabel: 'Structural metadata for this object' })
8
- end
9
- end
10
- end
11
- end