curation_concerns-models 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.md +177 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/app/actors/concerns/curation_concerns/manages_embargoes_actor.rb +99 -0
- data/app/actors/curation_concerns/base_actor.rb +90 -0
- data/app/actors/curation_concerns/generic_file_actor.rb +150 -0
- data/app/actors/curation_concerns/work_actor_behavior.rb +88 -0
- data/app/jobs/active_fedora_id_based_job.rb +22 -0
- data/app/jobs/active_fedora_pid_based_job.rb +6 -0
- data/app/jobs/audit_job.rb +58 -0
- data/app/jobs/characterize_job.rb +11 -0
- data/app/jobs/copy_permissions_job.rb +24 -0
- data/app/jobs/create_derivatives_job.rb +15 -0
- data/app/jobs/import_url_job.rb +56 -0
- data/app/jobs/ingest_local_file_job.rb +48 -0
- data/app/jobs/resolrize_job.rb +9 -0
- data/app/models/checksum_audit_log.rb +21 -0
- data/app/models/concerns/curation_concerns/ability.rb +34 -0
- data/app/models/concerns/curation_concerns/basic_metadata.rb +87 -0
- data/app/models/concerns/curation_concerns/collection_behavior.rb +47 -0
- data/app/models/concerns/curation_concerns/generic_file/belongs_to_works.rb +53 -0
- data/app/models/concerns/curation_concerns/generic_file/characterization.rb +89 -0
- data/app/models/concerns/curation_concerns/generic_file/content.rb +8 -0
- data/app/models/concerns/curation_concerns/generic_file/export.rb +343 -0
- data/app/models/concerns/curation_concerns/generic_file/full_text_indexing.rb +12 -0
- data/app/models/concerns/curation_concerns/generic_file/indexing.rb +14 -0
- data/app/models/concerns/curation_concerns/generic_file/versions.rb +16 -0
- data/app/models/concerns/curation_concerns/generic_file.rb +5 -0
- data/app/models/concerns/curation_concerns/generic_file_behavior.rb +44 -0
- data/app/models/concerns/curation_concerns/generic_work_behavior.rb +38 -0
- data/app/models/concerns/curation_concerns/has_representative.rb +14 -0
- data/app/models/concerns/curation_concerns/human_readable_type.rb +23 -0
- data/app/models/concerns/curation_concerns/permissions/readable.rb +19 -0
- data/app/models/concerns/curation_concerns/permissions/writable.rb +75 -0
- data/app/models/concerns/curation_concerns/permissions.rb +7 -0
- data/app/models/concerns/curation_concerns/serializers.rb +15 -0
- data/app/models/concerns/curation_concerns/solr_document_behavior.rb +135 -0
- data/app/models/concerns/curation_concerns/user.rb +65 -0
- data/app/models/concerns/curation_concerns/with_basic_metadata.rb +98 -0
- data/app/models/concerns/curation_concerns/with_generic_files.rb +29 -0
- data/app/models/curation_concerns/classify_concern.rb +47 -0
- data/app/models/curation_concerns/quick_classification_query.rb +31 -0
- data/app/models/datastreams/fits_datastream.rb +148 -0
- data/app/models/version_committer.rb +2 -0
- data/app/services/curation_concerns/characterization_service.rb +71 -0
- data/app/services/curation_concerns/full_text_extraction_service.rb +38 -0
- data/app/services/curation_concerns/generic_file_audit_service.rb +85 -0
- data/app/services/curation_concerns/generic_file_indexing_service.rb +14 -0
- data/app/services/curation_concerns/generic_work_indexing_service.rb +16 -0
- data/app/services/curation_concerns/noid.rb +23 -0
- data/app/services/curation_concerns/repository_audit_service.rb +9 -0
- data/app/services/curation_concerns/versioning_service.rb +27 -0
- data/config/locales/curation_concerns.en.yml +6 -0
- data/curation_concerns-models.gemspec +34 -0
- data/lib/curation_concerns/messages.rb +66 -0
- data/lib/curation_concerns/models/engine.rb +61 -0
- data/lib/curation_concerns/models/resque.rb +36 -0
- data/lib/curation_concerns/models/utils.rb +22 -0
- data/lib/curation_concerns/models/version.rb +5 -0
- data/lib/curation_concerns/models.rb +32 -0
- data/lib/generators/curation_concerns/models/abstract_migration_generator.rb +30 -0
- data/lib/generators/curation_concerns/models/clamav_generator.rb +19 -0
- data/lib/generators/curation_concerns/models/fulltext_generator.rb +28 -0
- data/lib/generators/curation_concerns/models/install_generator.rb +70 -0
- data/lib/generators/curation_concerns/models/templates/app/models/collection.rb +4 -0
- data/lib/generators/curation_concerns/models/templates/app/models/generic_file.rb +4 -0
- data/lib/generators/curation_concerns/models/templates/config/clamav.rb +1 -0
- data/lib/generators/curation_concerns/models/templates/config/curation_concerns.rb +123 -0
- data/lib/generators/curation_concerns/models/templates/config/mime_types.rb +6 -0
- data/lib/generators/curation_concerns/models/templates/config/redis.yml +9 -0
- data/lib/generators/curation_concerns/models/templates/config/redis_config.rb +32 -0
- data/lib/generators/curation_concerns/models/templates/config/resque-pool.yml +1 -0
- data/lib/generators/curation_concerns/models/templates/config/resque_admin.rb +10 -0
- data/lib/generators/curation_concerns/models/templates/config/resque_config.rb +5 -0
- data/lib/generators/curation_concerns/models/templates/migrations/create_checksum_audit_logs.rb +19 -0
- data/lib/generators/curation_concerns/models/templates/migrations/create_version_committers.rb +15 -0
- data/lib/tasks/curation_concerns-models_tasks.rake +75 -0
- data/lib/tasks/migrate.rake +13 -0
- data/lib/tasks/resque.rake +13 -0
- data/lib/tasks/solr_reindex.rake +8 -0
- metadata +282 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 51998b654c32654d086cbeb388436dff6db4c186
|
4
|
+
data.tar.gz: 59caa819f6745297082809edb2cf38b50ca43c4e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3c0af2087c9ec611684b8f6c12bcc62386d7c44837338f08659ca0a2bd6fcbff6538f9e25abc42479f38147553087fd84381deb91aedfaa4637b4a79b6ee7fa0
|
7
|
+
data.tar.gz: 5079fdbb1d714c8a9b8ef18124da0777e407a0ce877ac748a5bf90fde98617ba88eb6f30480f88435f8b51d2820dc4baef2e8765a6fdc8f34900689ee26b53f7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# CurationConcerns::Models
|
2
|
+
|
3
|
+
Models extracted from worthwhile-models and sufia-models.
|
4
|
+
|
5
|
+
## Dependencies
|
6
|
+
|
7
|
+
### FITS 0.6.2
|
8
|
+
|
9
|
+
To install FITS:
|
10
|
+
* Go to http://projects.iq.harvard.edu/fits/downloads, download __fits-0.6.2.zip__, and unpack it somewhere on your machine. You can also install FITS on OSX with homebrew: `brew install fits` (you may also have to create a symlink from fits.sh -> fits in the next step).
|
11
|
+
* Mark fits.sh as executable (chmod a+x fits.sh)
|
12
|
+
* Run "fits.sh -h" from the command line and see a help message to ensure FITS is properly installed
|
13
|
+
* Give your app access to FITS by:
|
14
|
+
* Adding the full fits.sh path to your PATH (e.g., in your .bash_profile), OR
|
15
|
+
* Changing config/initializers/sufia.rb to point to your FITS location: config.fits_path = "/<your full path>/fits.sh"
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
Add this line to your application's Gemfile:
|
22
|
+
|
23
|
+
gem 'curation_concerns-models'
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
Or install it yourself as:
|
30
|
+
|
31
|
+
$ gem install curation_concerns-models
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module CurationConcerns
|
2
|
+
# To use this module, include it in your Actor class
|
3
|
+
# and then add its interpreters wherever you want them to run.
|
4
|
+
# They should be called _before_ apply_attributes is called because
|
5
|
+
# they intercept values in the attributes Hash.
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# class MyActorClass < BaseActor
|
9
|
+
# include Worthwile::ManagesEmbargoesActor
|
10
|
+
#
|
11
|
+
# def create
|
12
|
+
# interpret_visibility && super && copy_visibility
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# def update
|
16
|
+
# interpret_visibility && super && copy_visibility
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
module ManagesEmbargoesActor
|
21
|
+
extend ActiveSupport::Concern
|
22
|
+
|
23
|
+
# Interprets embargo & lease visibility if necessary
|
24
|
+
# returns false if there are any errors
|
25
|
+
def interpret_visibility(attributes=self.attributes)
|
26
|
+
should_continue = interpret_embargo_visibility(attributes) && interpret_lease_visibility(attributes)
|
27
|
+
if attributes[:visibility]
|
28
|
+
curation_concern.visibility = attributes[:visibility]
|
29
|
+
end
|
30
|
+
return should_continue
|
31
|
+
end
|
32
|
+
|
33
|
+
# If user has set visibility to embargo, interprets the relevant information and applies it
|
34
|
+
# Returns false if there are any errors and sets an error on the curation_concern
|
35
|
+
def interpret_embargo_visibility(attributes=self.attributes)
|
36
|
+
if attributes[:visibility] == Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO
|
37
|
+
if !attributes[:embargo_release_date]
|
38
|
+
curation_concern.errors.add(:visibility, 'When setting visibility to "embargo" you must also specify embargo release date.')
|
39
|
+
should_continue = false
|
40
|
+
else
|
41
|
+
attributes.delete(:visibility)
|
42
|
+
curation_concern.apply_embargo(attributes[:embargo_release_date], attributes.delete(:visibility_during_embargo),
|
43
|
+
attributes.delete(:visibility_after_embargo))
|
44
|
+
if curation_concern.embargo
|
45
|
+
curation_concern.embargo.save # See https://github.com/projecthydra/hydra-head/issues/226
|
46
|
+
end
|
47
|
+
@needs_to_copy_visibility = true
|
48
|
+
should_continue = true
|
49
|
+
end
|
50
|
+
else
|
51
|
+
should_continue = true
|
52
|
+
# clear embargo_release_date if it isn't being used. Otherwise it sets the embargo_date
|
53
|
+
# even though they didn't select embargo on the form.
|
54
|
+
attributes.delete(:embargo_release_date)
|
55
|
+
end
|
56
|
+
|
57
|
+
attributes.delete(:visibility_during_embargo)
|
58
|
+
attributes.delete(:visibility_after_embargo)
|
59
|
+
|
60
|
+
return should_continue
|
61
|
+
end
|
62
|
+
|
63
|
+
# If user has set visibility to lease, interprets the relevant information and applies it
|
64
|
+
# Returns false if there are any errors and sets an error on the curation_concern
|
65
|
+
def interpret_lease_visibility(attributes=self.attributes)
|
66
|
+
if attributes[:visibility] == Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_LEASE
|
67
|
+
if !attributes[:lease_expiration_date]
|
68
|
+
curation_concern.errors.add(:visibility, 'When setting visibility to "lease" you must also specify lease expiration date.')
|
69
|
+
should_continue = false
|
70
|
+
else
|
71
|
+
curation_concern.apply_lease(attributes[:lease_expiration_date], attributes.delete(:visibility_during_lease),
|
72
|
+
attributes.delete(:visibility_after_lease))
|
73
|
+
if curation_concern.lease
|
74
|
+
curation_concern.lease.save # See https://github.com/projecthydra/hydra-head/issues/226
|
75
|
+
end
|
76
|
+
@needs_to_copy_visibility = true
|
77
|
+
attributes.delete(:visibility)
|
78
|
+
should_continue = true
|
79
|
+
end
|
80
|
+
else
|
81
|
+
# clear lease_expiration_date if it isn't being used. Otherwise it sets the lease_expiration
|
82
|
+
# even though they didn't select lease on the form.
|
83
|
+
attributes.delete(:lease_expiration_date)
|
84
|
+
should_continue = true
|
85
|
+
end
|
86
|
+
|
87
|
+
attributes.delete(:visibility_during_lease)
|
88
|
+
attributes.delete(:visibility_after_lease)
|
89
|
+
|
90
|
+
return should_continue
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
def copy_visibility
|
95
|
+
CurationConcerns.queue.push(VisibilityCopyWorker.new(curation_concern.id)) if @needs_to_copy_visibility
|
96
|
+
true
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
|
2
|
+
module CurationConcerns
|
3
|
+
# The CurationConcern base actor should respond to three primary actions:
|
4
|
+
# * #create
|
5
|
+
# * #update
|
6
|
+
# * #delete
|
7
|
+
class BaseActor
|
8
|
+
attr_reader :curation_concern, :user, :attributes, :cloud_resources
|
9
|
+
def initialize(curation_concern, user, input_attributes)
|
10
|
+
@curation_concern = curation_concern
|
11
|
+
@user = user
|
12
|
+
@attributes = input_attributes.dup.with_indifferent_access
|
13
|
+
@visibility = attributes[:visibility]
|
14
|
+
@cloud_resources= attributes.delete(:cloud_resources.to_s)
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :visibility
|
18
|
+
protected :visibility
|
19
|
+
|
20
|
+
delegate :visibility_changed?, to: :curation_concern
|
21
|
+
|
22
|
+
def create
|
23
|
+
apply_creation_data_to_curation_concern
|
24
|
+
apply_save_data_to_curation_concern
|
25
|
+
save
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
apply_update_data_to_curation_concern
|
30
|
+
apply_save_data_to_curation_concern
|
31
|
+
save
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
def apply_creation_data_to_curation_concern
|
36
|
+
apply_depositor_metadata
|
37
|
+
apply_deposit_date
|
38
|
+
end
|
39
|
+
|
40
|
+
def apply_update_data_to_curation_concern
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
44
|
+
def apply_depositor_metadata
|
45
|
+
curation_concern.apply_depositor_metadata(user.user_key)
|
46
|
+
curation_concern.edit_users += [user.user_key]
|
47
|
+
end
|
48
|
+
|
49
|
+
def apply_deposit_date
|
50
|
+
curation_concern.date_uploaded = Date.today
|
51
|
+
end
|
52
|
+
|
53
|
+
def save
|
54
|
+
curation_concern.save
|
55
|
+
end
|
56
|
+
|
57
|
+
def apply_save_data_to_curation_concern
|
58
|
+
attributes[:rights] = Array(attributes[:rights]) if attributes.key? :rights
|
59
|
+
remove_blank_attributes!
|
60
|
+
curation_concern.attributes = attributes.symbolize_keys
|
61
|
+
curation_concern.date_modified = Date.today
|
62
|
+
end
|
63
|
+
|
64
|
+
def attach_file(generic_file, file_to_attach)
|
65
|
+
ActiveSupport::Deprecation.warn("removing #{self.class}#attach_file, use CurationConcern.attach_file instead")
|
66
|
+
CurationConcern.attach_file(generic_file, user, file_to_attach)
|
67
|
+
end
|
68
|
+
|
69
|
+
# If any attributes are blank remove them
|
70
|
+
# e.g.:
|
71
|
+
# self.attributes = { 'title' => ['first', 'second', ''] }
|
72
|
+
# remove_blank_attributes!
|
73
|
+
# self.attributes
|
74
|
+
# => { 'title' => ['first', 'second'] }
|
75
|
+
def remove_blank_attributes!
|
76
|
+
multivalued_form_attributes.each_with_object(attributes) do |(k, v), h|
|
77
|
+
if v.instance_of? Array
|
78
|
+
h[k] = v.select(&:present?)
|
79
|
+
else
|
80
|
+
h[k] = v
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Return the hash of attributes that are multivalued and not uploaded files
|
86
|
+
def multivalued_form_attributes
|
87
|
+
attributes.select {|_, v| v.respond_to?(:select) && !v.respond_to?(:read) }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
module CurationConcerns
|
2
|
+
# Actions are decoupled from controller logic so that they may be called from a controller or a background job.
|
3
|
+
class GenericFileActor
|
4
|
+
include CurationConcerns::ManagesEmbargoesActor
|
5
|
+
|
6
|
+
attr_reader :generic_file, :user, :attributes, :curation_concern
|
7
|
+
|
8
|
+
def initialize(generic_file, user)
|
9
|
+
# we're setting attributes and curation_concern to bridge the difference
|
10
|
+
# between CurationConcerns::GenericFileActor and ManagesEmbargoesActor
|
11
|
+
@curation_concern = generic_file
|
12
|
+
@generic_file = generic_file
|
13
|
+
@user = user
|
14
|
+
end
|
15
|
+
|
16
|
+
# Adds the appropriate metadata, visibility and relationships to generic_file
|
17
|
+
#
|
18
|
+
# *Note*: In past versions of Sufia this method did not perform a save because it is mainly used in conjunction with
|
19
|
+
# create_content, which also performs a save. However, due to the relationship between Hydra::PCDM objects,
|
20
|
+
# we have to save both the parent work and the generic_file in order to record the "metadata" relationship
|
21
|
+
# between them.
|
22
|
+
# @param [String] batch_id id of the batch that the file was uploaded within
|
23
|
+
# @param [String] work_id id of the parent work that will contain the generic_file.
|
24
|
+
# @param [Hash] generic_file_params specifying the visibility, lease and/or embargo of the generic file. If you don't provide at least one of visibility, embargo_release_date or lease_expiration_date, visibility will be copied from the parent.
|
25
|
+
|
26
|
+
def create_metadata(batch_id, work_id, generic_file_params={})
|
27
|
+
generic_file.apply_depositor_metadata(user)
|
28
|
+
time_in_utc = DateTime.now.new_offset(0)
|
29
|
+
generic_file.date_uploaded = time_in_utc
|
30
|
+
generic_file.date_modified = time_in_utc
|
31
|
+
generic_file.creator = [user.name]
|
32
|
+
# TODO: Remove this? see https://github.com/projecthydra-labs/curation_concerns/issues/27
|
33
|
+
if batch_id && generic_file.respond_to?(:batch_id=)
|
34
|
+
generic_file.batch_id = batch_id
|
35
|
+
else
|
36
|
+
ActiveFedora::Base.logger.warn "unable to find batch to attach to"
|
37
|
+
end
|
38
|
+
|
39
|
+
unless work_id.blank?
|
40
|
+
work = ActiveFedora::Base.find(work_id)
|
41
|
+
|
42
|
+
if !((generic_file_params || {}).keys & ["visibility", "embargo_release_date", "lease_expiration_date"]).empty?
|
43
|
+
interpret_visibility generic_file_params
|
44
|
+
else
|
45
|
+
copy_visibility(work, generic_file)
|
46
|
+
end
|
47
|
+
work.generic_files << generic_file
|
48
|
+
# Save the work so the association between the work and the generic_file is persisted (head_id)
|
49
|
+
work.save
|
50
|
+
end
|
51
|
+
yield(generic_file) if block_given?
|
52
|
+
end
|
53
|
+
|
54
|
+
def create_content(file)
|
55
|
+
# Tell UploadFileToGenericFile service to skip versioning because versions will be minted by VersionCommitter (called by save_characterize_and_record_committer) when necessary
|
56
|
+
Hydra::Works::UploadFileToGenericFile.call(generic_file, file, versioning: false)
|
57
|
+
generic_file.label ||= file.original_filename
|
58
|
+
generic_file.title = [generic_file.label] if generic_file.title.blank?
|
59
|
+
save_characterize_and_record_committer do
|
60
|
+
if CurationConcerns.config.respond_to?(:after_create_content)
|
61
|
+
CurationConcerns.config.after_create_content.call(generic_file, user)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def revert_content(revision_id)
|
67
|
+
generic_file.original_file.restore_version(revision_id)
|
68
|
+
save_characterize_and_record_committer do
|
69
|
+
if CurationConcerns.config.respond_to?(:after_revert_content)
|
70
|
+
CurationConcerns.config.after_revert_content.call(generic_file, user, revision_id)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def update_content(file)
|
76
|
+
# Tell UploadFileToGenericFile service to skip versioning because versions will be minted by VersionCommitter (called by save_characterize_and_record_committer) when necessary
|
77
|
+
Hydra::Works::UploadFileToGenericFile.call(generic_file, file, versioning: false)
|
78
|
+
save_characterize_and_record_committer do
|
79
|
+
if CurationConcerns.config.respond_to?(:after_update_content)
|
80
|
+
CurationConcerns.config.after_update_content.call(generic_file, user)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def update_metadata(model_attributes, all_attributes)
|
86
|
+
update_visibility(all_attributes)
|
87
|
+
model_attributes.delete(:visibility) # Applying this attribute is handled by update_visibility
|
88
|
+
generic_file.attributes = model_attributes
|
89
|
+
generic_file.date_modified = DateTime.now
|
90
|
+
save do
|
91
|
+
if CurationConcerns.config.respond_to?(:after_update_metadata)
|
92
|
+
CurationConcerns.config.after_update_metadata.call(generic_file, user)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def destroy
|
98
|
+
generic_file.destroy
|
99
|
+
if CurationConcerns.config.respond_to?(:after_destroy)
|
100
|
+
CurationConcerns.config.after_destroy.call(generic_file.id, user)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# Saves the generic file, queues a job to characterize it, and records the committer.
|
105
|
+
# Takes a block which is run if the save was successful.
|
106
|
+
def save_characterize_and_record_committer
|
107
|
+
save do
|
108
|
+
push_characterize_job
|
109
|
+
CurationConcerns::VersioningService.create(generic_file.original_file, user)
|
110
|
+
yield if block_given?
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# Takes an optional block and executes the block if the save was successful.
|
115
|
+
# returns false if the save was unsuccessful
|
116
|
+
def save
|
117
|
+
save_tries = 0
|
118
|
+
begin
|
119
|
+
return false unless generic_file.save
|
120
|
+
rescue RSolr::Error::Http => error
|
121
|
+
ActiveFedora::Base.logger.warn "CurationConcerns::GenericFileActor#save Caught RSOLR error #{error.inspect}"
|
122
|
+
save_tries+=1
|
123
|
+
# fail for good if the tries is greater than 3
|
124
|
+
raise error if save_tries >=3
|
125
|
+
sleep 0.01
|
126
|
+
retry
|
127
|
+
end
|
128
|
+
yield if block_given?
|
129
|
+
true
|
130
|
+
end
|
131
|
+
|
132
|
+
def push_characterize_job
|
133
|
+
CurationConcerns.queue.push(CharacterizeJob.new(@generic_file.id))
|
134
|
+
end
|
135
|
+
|
136
|
+
protected
|
137
|
+
|
138
|
+
# This method can be overridden in case there is a custom approach for visibility (e.g. embargo)
|
139
|
+
def update_visibility(attributes)
|
140
|
+
interpret_visibility(attributes) # relies on CurationConcerns::ManagesEmbargoesActor to interpret and apply visibility
|
141
|
+
end
|
142
|
+
|
143
|
+
private
|
144
|
+
|
145
|
+
# copy visibility from source_concern to destination_concern
|
146
|
+
def copy_visibility(source_concern, destination_concern)
|
147
|
+
destination_concern.visibility = source_concern.visibility
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
|
2
|
+
module CurationConcerns::WorkActorBehavior
|
3
|
+
include CurationConcerns::ManagesEmbargoesActor
|
4
|
+
|
5
|
+
def create
|
6
|
+
# set the @files ivar then remove the files attribute so it isn't set by default.
|
7
|
+
files && attributes.delete(:files)
|
8
|
+
# Files must be attached before saving in order to persist their relationship to the work
|
9
|
+
assign_pid && interpret_visibility && attach_files && super && assign_representative && copy_visibility
|
10
|
+
end
|
11
|
+
|
12
|
+
def update
|
13
|
+
add_to_collections(attributes.delete(:collection_ids)) &&
|
14
|
+
interpret_visibility && super && attach_files && copy_visibility
|
15
|
+
end
|
16
|
+
|
17
|
+
delegate :visibility_changed?, to: :curation_concern
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
# Is this here to ensure that the curation_concern has a pid set before any of the other methods are executed?
|
22
|
+
def assign_pid
|
23
|
+
curation_concern.send(:assign_id)
|
24
|
+
end
|
25
|
+
|
26
|
+
def files
|
27
|
+
return @files if defined?(@files)
|
28
|
+
@files = [attributes[:files]].flatten.compact
|
29
|
+
end
|
30
|
+
|
31
|
+
def attach_files
|
32
|
+
files.all? do |file|
|
33
|
+
attach_file(file)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# The default behavior of active_fedora's aggregates association,
|
38
|
+
# when assigning the id accessor (e.g. collection_ids = ['foo:1']) is to add
|
39
|
+
# to new collections, but not remove from old collections.
|
40
|
+
# This method ensures it's removed from the old collections.
|
41
|
+
def add_to_collections(new_collection_ids)
|
42
|
+
return true unless new_collection_ids
|
43
|
+
# remove from old collections
|
44
|
+
# TODO Implement parent_collection_ids https://github.com/projecthydra-labs/hydra-pcdm/issues/157
|
45
|
+
(curation_concern.parent_collections.map(&:id) - new_collection_ids).each do |old_id|
|
46
|
+
Collection.find(old_id).members.delete(curation_concern)
|
47
|
+
end
|
48
|
+
|
49
|
+
#add to new
|
50
|
+
new_collection_ids.each do |coll_id|
|
51
|
+
collection = Collection.find(coll_id)
|
52
|
+
collection.members << curation_concern
|
53
|
+
collection.save
|
54
|
+
end
|
55
|
+
true
|
56
|
+
end
|
57
|
+
|
58
|
+
def assign_representative
|
59
|
+
@generic_files ||= []
|
60
|
+
unless curation_concern.representative
|
61
|
+
curation_concern.representative = @generic_files.first.id unless @generic_files.empty?
|
62
|
+
end
|
63
|
+
curation_concern.save
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def attach_file(file)
|
69
|
+
generic_file = ::GenericFile.new
|
70
|
+
generic_file_actor = CurationConcerns::GenericFileActor.new(generic_file, user)
|
71
|
+
#TODO we're passing an ID rather than an object. This means the actor does an unnecessary lookup
|
72
|
+
generic_file_actor.create_metadata(curation_concern.id, curation_concern.id)
|
73
|
+
generic_file.visibility = visibility
|
74
|
+
generic_file_actor.create_content(file)
|
75
|
+
@generic_files ||= []
|
76
|
+
@generic_files << generic_file # This is so that other methods like assign_representative can access the generic_files wihtout reloading them from fedora
|
77
|
+
curation_concern.generic_files << generic_file
|
78
|
+
end
|
79
|
+
|
80
|
+
def valid_file?(file_path)
|
81
|
+
return file_path.present? && File.exists?(file_path) && !File.zero?(file_path)
|
82
|
+
end
|
83
|
+
|
84
|
+
# The path of the fedora node where we store the file data
|
85
|
+
def file_path
|
86
|
+
'content'
|
87
|
+
end
|
88
|
+
end
|