hybridge 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 331386a91eca4135d11c45829ea74731c3a4bc80
4
+ data.tar.gz: f9df4cbab4cf1f84d86692c412e712206cd1dcf2
5
+ SHA512:
6
+ metadata.gz: 579b65a48bd2a06cf659b4d38df519f349a5e60f6f14160884c93dd288f4db80c13b1604866f90a523989d87cbe38cfd37cce2c6bc0f81a2a86299e3aee0dae3
7
+ data.tar.gz: eab5b900ac1ca6599940155f18d7a67bb235f61b5c7efc96bb742c183196219b93b7efe055b19ba2e0fdf46bf6ea501e608784375895cb51f0924cbc6762dec9
data/LICENSE.txt ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2018 University of Houston
190
+ Additional copyright may be held by others, as reflected in the commit log
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # HyBridge
2
+
3
+ HyBridge is a ruby gem to ingest a batch of digital objects into the Samvera [Hyku](https://github.com/samvera-labs/hyku) application.
4
+
5
+ Part of the [Bridge2Hyku](https://bridge2hyku.github.io/) project.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'hybridge', git: 'https://github.com/Bridge2Hyku/hybridge'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install hybridge
22
+
23
+ Finally:
24
+
25
+ $ rails g hybridge:install
26
+
27
+ ### Hyku Settings
28
+
29
+ Add the following to your Hyku settings file in `config/settings.yml` or `config/settings/<environment>.yml`
30
+
31
+ ```ruby
32
+ hybridge:
33
+ filesystem: /path/to/ingest/packages
34
+ ```
35
+
36
+ The HyBridge filesystem is the location where ingest packages will be stored for use in HyBridge. Create directories in the HyBridge filesystem location for every Multi tenant domain/repository installed using the repositories CNAME. Example: `/path/to/ingest/packages/myrepository.example.com`
37
+
38
+ ## Usage
39
+
40
+ TODO: Write usage instructions here
41
+
42
+ ## Development
43
+
44
+ TODO: Write development processes here
45
+
46
+ ## License
47
+
48
+ **[Apache-2.0](LICENSE)**
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Hybridge'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'test'
31
+ t.pattern = 'test/**/*_test.rb'
32
+ t.verbose = false
33
+ end
34
+
35
+
36
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/hybridge .js
2
+ //= link_directory ../stylesheets/hybridge .css
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,5 @@
1
+ module Hybridge
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,95 @@
1
+ require_dependency "hybridge/application_controller"
2
+
3
+ module Hybridge
4
+ class IngestController < Hyrax::MyController
5
+ include Hyrax::Breadcrumbs
6
+ before_action :set_current_account, :authenticate_user!
7
+ skip_before_action :require_active_account!
8
+
9
+ delegate :title, :id, to: :solr_document
10
+
11
+ def index
12
+ add_breadcrumbs
13
+ @packages = packages('csv')
14
+ @processing = packages('processing', true)
15
+ @processed = packages('processed', true)
16
+ @collections = collections
17
+ end
18
+
19
+ def perform
20
+ if params[:package_id].nil?
21
+ flash[:error] = "Unable to find selected file in source directory. Please contact your System Administrator"
22
+ else
23
+ params[:package_id].each do | package |
24
+ package_location = staged!(File.join(location, package))
25
+ next if package_location.nil?
26
+ collection_id = params[:collection_id][package]
27
+ Hybridge::IngestPackageJob.perform_later(package_location, collection_id, current_user)
28
+ end
29
+ flash[:notice] = "Successfully started the ingest process. This can take awhile"
30
+ end
31
+ redirect_to hybridge.root_path
32
+ end
33
+
34
+ private
35
+
36
+ def add_breadcrumbs
37
+ add_breadcrumb t(:'hyrax.controls.home'), main_app.root_path
38
+ add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path
39
+ add_breadcrumb t(:'hybridge.admin.sidebar.ingest'), hybridge.root_path
40
+ end
41
+
42
+ def set_current_account
43
+ @account = Site.account rescue nil
44
+ end
45
+
46
+ def location
47
+ if @account.nil?
48
+ Settings.hybridge.filesystem
49
+ else
50
+ File.join(Settings.hybridge.filesystem, @account.cname)
51
+ end
52
+ end
53
+
54
+ def packages(ext, hideext=false)
55
+ files = Dir.glob(location + "/**/*.#{ext}")
56
+ base_path = Pathname.new(location)
57
+ files = files.collect do |file|
58
+ path = Pathname.new(file).relative_path_from(base_path)
59
+ if hideext
60
+ path = "#{File.dirname(path)}/#{File.basename(path, ".#{ext}")}"
61
+ end
62
+ path
63
+ end
64
+ end
65
+
66
+ def staged!(filename)
67
+ if !File.file?(filename)
68
+ flash[:error] = "Unable to find #{package}. Please contact your System Administrator for assistance"
69
+ return nil
70
+ end
71
+ new_filename = filename + '.staged'
72
+ File.rename(filename, new_filename)
73
+ new_filename
74
+ end
75
+
76
+ def collections
77
+ colls = []
78
+ response = self.repository.search(collection_search_builder)
79
+ response.docs.each do |document|
80
+ colls << {
81
+ id: document.id,
82
+ title: document.title.first || document.title
83
+ }
84
+ end
85
+ colls
86
+ end
87
+
88
+ private
89
+
90
+ def collection_search_builder
91
+ Hyrax::CollectionSearchBuilder.new(self).rows(1000).with_access(:edit)
92
+ end
93
+
94
+ end
95
+ end
@@ -0,0 +1,4 @@
1
+ module Hybridge
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Hybridge
2
+ module IngestHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Hybridge
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,10 @@
1
+ require 'hybridge/batch'
2
+ module Hybridge
3
+ class IngestPackageJob < ApplicationJob
4
+ queue_as Hyrax.config.ingest_queue_name
5
+
6
+ def perform(package_location, collection_id, current_user)
7
+ Hybridge::Batch::Ingest.new(package_location, collection_id, current_user)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ module Hybridge
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Hybridge
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,90 @@
1
+ <%= form_tag hybridge.perform_path do %>
2
+ <div class="col-xs-12 main-header">
3
+ <h1><span class="fa fa-magic"></span> HyBridge Ingest</h1>
4
+ <div class="pull-right">
5
+ <%= button_tag("Ingest Selected", type: "submit", class: "btn btn-large btn-primary") %>
6
+ </div>
7
+ </div>
8
+ <div class="row">
9
+ <div class="col-md-12">
10
+ <div class="panel panel-default">
11
+ <div class="panel-heading">
12
+ <h2 class="panel-title h2">Ready</h2>
13
+ <span>Select csv packages to ingest</span>
14
+ </div>
15
+ <div class="panel-body">
16
+ <table class="table table-condensed">
17
+ <thead>
18
+ <th scope="col">Select</th>
19
+ <th scope="col">Filename</th>
20
+ <th scope="col" class="text-right">Collection</th>
21
+ </thead>
22
+ <tbody>
23
+ <% @packages.each do |package| %>
24
+ <tr>
25
+ <td class="col-md-1">
26
+ <label for="package_id_">
27
+ <%= check_box_tag 'package_id[]', package %>
28
+ </label>
29
+ </td>
30
+ <td class="col-md-7"><%= package %></td>
31
+ <td class="col-md-4 text-right">
32
+ <label for="collection_id">
33
+ <%= select_tag "collection_id[#{package}]", options_for_select(@collections.collect {|c| [ c[:title], c[:id] ] }), {:include_blank => '', :class => 'form-control select optional'} %>
34
+ </label>
35
+ </td>
36
+ </tr>
37
+ <% end %>
38
+ </tbody>
39
+ </table>
40
+ </div>
41
+ </div>
42
+ </div>
43
+ </div>
44
+ <% end %>
45
+ <div class="row">
46
+ <div class="col-md-12">
47
+ <div class="panel panel-default">
48
+ <div class="panel-heading">
49
+ <h2 class="panel-title h2">Processing</h2>
50
+ </div>
51
+ <div class="panel-body">
52
+ <table class="table table-condensed">
53
+ <thead>
54
+ <th scope="col">Filename</th>
55
+ </thead>
56
+ <tbody>
57
+ <% @processing.each do |package| %>
58
+ <tr>
59
+ <td class="col-md-11"><%= package %></td>
60
+ </tr>
61
+ <% end %>
62
+ </tbody>
63
+ </table>
64
+ </div>
65
+ </div>
66
+ </div>
67
+ </div>
68
+ <div class="row">
69
+ <div class="col-md-12">
70
+ <div class="panel panel-default">
71
+ <div class="panel-heading">
72
+ <h2 class="panel-title h2">Complete</h2>
73
+ </div>
74
+ <div class="panel-body">
75
+ <table class="table table-condensed">
76
+ <thead>
77
+ <th scope="col">Filename</th>
78
+ </thead>
79
+ <tbody>
80
+ <% @processed.each do |package| %>
81
+ <tr>
82
+ <td class="col-md-11"><%= package %></td>
83
+ </tr>
84
+ <% end %>
85
+ </tbody>
86
+ </table>
87
+ </div>
88
+ </div>
89
+ </div>
90
+ </div>
@@ -0,0 +1 @@
1
+ <h1>Processing</h1>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Hybridge</title>
5
+ <%= stylesheet_link_tag "hybridge/application", media: "all" %>
6
+ <%= javascript_include_tag "hybridge/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,5 @@
1
+ en:
2
+ hybridge:
3
+ admin:
4
+ sidebar:
5
+ ingest: "HyBridge Ingest"
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Hybridge::Engine.routes.draw do
2
+ get 'ingest/index'
3
+ match '/perform', to: "ingest#perform", via: :post
4
+
5
+ root to: "ingest#index"
6
+ end
@@ -0,0 +1,23 @@
1
+ class Hybridge::InstallGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def inject_routes
5
+ insert_into_file "config/routes.rb", after: ".draw do" do
6
+ %(\n mount Hybridge::Engine => '/hybridge'\n)
7
+ end
8
+ end
9
+
10
+ def inject_dashboard_link
11
+ file_path = "app/views/hyrax/dashboard/_sidebar.html.erb"
12
+ if File.file?(file_path)
13
+ insert_into_file file_path, after: /menu\.nav_link\(hyrax\.my_works_path.*?<% end %>/m do
14
+ "\n\n <%= menu.nav_link(hybridge.root_path,\n" \
15
+ " also_active_for: hyrax.dashboard_works_path) do %>\n" \
16
+ " <span class=\"fa fa-magic\"></span> <span class=\"sidebar-action-text\"><%= t('hybridge.admin.sidebar.ingest') %></span>\n" \
17
+ " <% end %>\n"
18
+ end
19
+ end
20
+ copy_file "sidebar/_repository_content.html.erb", "app/views/hyrax/dashboard/sidebar/_repository_content.html.erb"
21
+ end
22
+
23
+ end
@@ -0,0 +1,16 @@
1
+ <li class="h5"><%= t('hyrax.admin.sidebar.repository_objects') %></li>
2
+
3
+ <%= menu.nav_link(hyrax.my_collections_path,
4
+ also_active_for: hyrax.dashboard_collections_path) do %>
5
+ <span class="fa fa-folder-open" aria-hidden="true"></span> <span class="sidebar-action-text"><%= t('hyrax.admin.sidebar.collections') %></span>
6
+ <% end %>
7
+
8
+ <%= menu.nav_link(hyrax.my_works_path,
9
+ also_active_for: hyrax.dashboard_works_path) do %>
10
+ <span class="fa fa-file" aria-hidden="true"></span> <span class="sidebar-action-text"><%= t('hyrax.admin.sidebar.works') %></span>
11
+ <% end %>
12
+
13
+ <%= menu.nav_link(hybridge.root_path,
14
+ also_active_for: hyrax.dashboard_works_path) do %>
15
+ <span class="fa fa-magic"></span> <span class="sidebar-action-text"><%= t('hybridge.admin.sidebar.ingest') %></span>
16
+ <% end %>
data/lib/hybridge.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "hybridge/engine"
2
+
3
+ module Hybridge
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,8 @@
1
+ require 'hybridge/batch/ingest'
2
+ require 'hybridge/batch/entry'
3
+
4
+ module Hybridge
5
+ module Batch
6
+ class Error < ::Exception; end
7
+ end
8
+ end
@@ -0,0 +1,107 @@
1
+ module Hybridge
2
+ module Batch
3
+ class Entry
4
+
5
+ def initialize(work, files, collection_id, current_user, package_location)
6
+ @work = work
7
+ @files = files
8
+ @collection_id = collection_id
9
+ @current_user = current_user
10
+ @package_location = package_location
11
+
12
+ process!
13
+ end
14
+
15
+ def process!
16
+ work_type = @work["Object Type"].constantize.new
17
+ work_form = ("Hyrax::" + @work["Object Type"] + "Form").constantize
18
+
19
+ work_attributes = field_attributes(work_form, work_type)
20
+
21
+ missing = work_form.required_fields - work_attributes.keys
22
+ if !missing.empty?
23
+ message = "Missing required fields: #{missing.map{|m| m.to_s.inspect}.join(', ')} for '#{work_attributes[:title].first}'"
24
+ Hyrax::MessengerService.deliver(User.batch_user, @current_user, message, "HyBridge Warning: Missing required fields")
25
+ end
26
+
27
+ env = Hyrax::Actors::Environment.new(work_type, Ability.new(@current_user), work_attributes)
28
+ work_actor = Hyrax::CurationConcern.actor.create(env)
29
+
30
+ process_files! work_type unless @files.nil?
31
+ end
32
+
33
+ def field_attributes(work_form, work_type)
34
+ data = {}
35
+ @work.each do |key, attribute|
36
+ field_sym = field_to_sym(key)
37
+ if (field_sym.nil? || attribute.nil? || attribute.empty? || key.to_s.include?("Object Type") || !work_form.terms.include?(field_sym))
38
+ next
39
+ elsif(field_sym.id2name == "based_near")
40
+ data[:based_near_attributes] = based_near_attributes(attribute.split("; "))
41
+ elsif(field_sym.id2name == "rights_statement")
42
+ active = Hyrax.config.rights_statement_service_class.new.active?(attribute) rescue false
43
+ if active
44
+ data[field_sym] = attribute
45
+ else
46
+ message = "Invalid/Inactive Rights Statement URL '#{attribute}' for '#{data[:title].first.to_s}'"
47
+ Hyrax::MessengerService.deliver(User.batch_user, @current_user, message, "HyBridge Warning: Invalid/Inactive Rights Statement URL")
48
+ end
49
+ elsif(work_type.send(field_sym).nil?)
50
+ data[field_sym] = attribute
51
+ else
52
+ data[field_sym] = attribute.split "; "
53
+ end
54
+
55
+ if !@collection_id.nil? && !@collection_id.empty?
56
+ data[:member_of_collections_attributes] = {"0" => { "id" => @collection_id, "_destroy" => "false" }}
57
+ end
58
+
59
+ end
60
+ data
61
+ end
62
+
63
+ def based_near_attributes(values)
64
+ based_near_values = {}
65
+ values.each_with_index do |value, index|
66
+ based_near_values[index.to_s] = { "id" => value, "_destroy" => "" }
67
+ end
68
+ based_near_values
69
+ end
70
+
71
+ def file_location(filename)
72
+ File.join(@package_location, filename)
73
+ end
74
+
75
+ def process_files!(work_type)
76
+ work_permissions = work_type.permissions.map(&:to_hash)
77
+ @files.each do |file_object|
78
+ file_path = file_location(file_object["Filename"])
79
+ if !File.file?(file_path)
80
+ message = "Unable to find file '#{file_object["Filename"]}' for '#{work_type[:title].first.to_s}'"
81
+ Hyrax::MessengerService.deliver(User.batch_user, @current_user, message, "HyBridge Warning: Missing file")
82
+ next
83
+ end
84
+
85
+ file_actor = Hyrax::Actors::FileSetActor.new(FileSet.create, @current_user)
86
+ file_actor.create_metadata
87
+ file_actor.create_content(File.new(file_path))
88
+ file_actor.attach_to_work(work_type)
89
+ file_actor.file_set.permissions_attributes = work_permissions
90
+ end
91
+ end
92
+
93
+ def field_to_sym(field)
94
+ if field.downcase == "abstract or summary"
95
+ field = "description"
96
+ elsif field.downcase == "abstract / summary"
97
+ field = "description"
98
+ elsif field.downcase == "location"
99
+ field = "based_near"
100
+ end
101
+
102
+ field.downcase.strip.gsub(/\s/,'_').to_sym
103
+ end
104
+
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,76 @@
1
+ module Hybridge
2
+ module Batch
3
+ class Ingest
4
+
5
+ def initialize(file, collection_id, current_user)
6
+ @file = file
7
+ @collection_id = collection_id
8
+ @current_user = current_user
9
+ load!
10
+ end
11
+
12
+ def load!
13
+
14
+ return unless staged? || processing?
15
+
16
+ processing!
17
+ @works = []
18
+ @files = {}
19
+ good_work = false
20
+
21
+ @csv = CSV.parse(File.read(@file), headers: true, encoding: 'utf-8').map(&:to_hash)
22
+ @csv.each do |row|
23
+ type = row.first.last
24
+ if type.nil?
25
+ good_work = false
26
+ next
27
+ elsif Hyrax.config.registered_curation_concern_types.include? type
28
+ good_work = true
29
+ row.delete("Filename")
30
+ @works << row
31
+ @files[@works.length] = []
32
+ elsif type.include? "File"
33
+ if good_work
34
+ row.delete("Object Type")
35
+ @files[@works.length] << row
36
+ end
37
+ else
38
+ good_work = false
39
+ message = "Unknown work type '#{type}'"
40
+ Hyrax::MessengerService.deliver(User.batch_user, @current_user, message, "HyBridge Warning: Unknown work type")
41
+ end
42
+ end
43
+
44
+ @works.each_with_index do |work, index|
45
+ Entry.new(work, @files[index+1], @collection_id, @current_user, File.dirname(@file))
46
+ end
47
+ processed!
48
+ end
49
+
50
+ def processing!
51
+ new_file = Pathname(@file).sub_ext '' + ".processing"
52
+ File.rename(@file, new_file) unless File.file?(new_file)
53
+ @file = new_file
54
+ end
55
+
56
+ def processed!
57
+ new_file = Pathname(@file).sub_ext '' + ".processed"
58
+ File.rename(@file, new_file)
59
+ @file = new_file
60
+ end
61
+
62
+ def processing?
63
+ File.file?(Pathname(@file).sub_ext '' + ".processing")
64
+ end
65
+
66
+ def processed?
67
+ File.file?(Pathname(@file).sub_ext '' + ".processed")
68
+ end
69
+
70
+ def staged?
71
+ File.file?(Pathname(@file).sub_ext '' + ".staged")
72
+ end
73
+
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,5 @@
1
+ module Hybridge
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Hybridge
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Hybridge
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :hybridge do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hybridge
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Leroy Vallejo
8
+ - Sean Watkins
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2019-07-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '5.1'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '5.1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: config
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.7'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.7'
42
+ description: An ingest tool for Samvera Hyku and Hyrax repositories.
43
+ email:
44
+ - llvallejo@uh.edu
45
+ - slwatkins@uh.edu
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - app/assets/config/hybridge_manifest.js
54
+ - app/assets/javascripts/hybridge/application.js
55
+ - app/assets/javascripts/hybridge/ingest.js
56
+ - app/assets/stylesheets/hybridge/application.css
57
+ - app/assets/stylesheets/hybridge/ingest.css
58
+ - app/controllers/hybridge/application_controller.rb
59
+ - app/controllers/hybridge/ingest_controller.rb
60
+ - app/helpers/hybridge/application_helper.rb
61
+ - app/helpers/hybridge/ingest_helper.rb
62
+ - app/jobs/hybridge/application_job.rb
63
+ - app/jobs/hybridge/ingest_package_job.rb
64
+ - app/mailers/hybridge/application_mailer.rb
65
+ - app/models/hybridge/application_record.rb
66
+ - app/views/hybridge/ingest/index.html.erb
67
+ - app/views/hybridge/ingest/perform.html.erb
68
+ - app/views/layouts/hybridge/application.html.erb
69
+ - config/locales/hybridge.en.yml
70
+ - config/routes.rb
71
+ - lib/generators/hybridge/install/install_generator.rb
72
+ - lib/generators/hybridge/install/templates/sidebar/_repository_content.html.erb
73
+ - lib/hybridge.rb
74
+ - lib/hybridge/batch.rb
75
+ - lib/hybridge/batch/entry.rb
76
+ - lib/hybridge/batch/ingest.rb
77
+ - lib/hybridge/engine.rb
78
+ - lib/hybridge/version.rb
79
+ - lib/tasks/hybridge_tasks.rake
80
+ homepage: https://github.com/Bridge2Hyku/HyBridge
81
+ licenses:
82
+ - Apache-2.0
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.6.14.1
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: HyBridge is a ingest tool for use in Samvera Hyku and Hyrax repositories.
104
+ test_files: []