cdm_migrator 1.4.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c5aca97a42ea960dfc0b343b405eacfbe9a79201
4
- data.tar.gz: 820bd32a36ee44ceca81754af82afd998f364439
2
+ SHA256:
3
+ metadata.gz: e8c4fdc95bd2d038a441f126555e80767c40b05a7f9ed20eb1aae116f2a66921
4
+ data.tar.gz: 1a9a1695951cbb45f6ad78855223f62900a9033ea6b749db77827b67745b5b4f
5
5
  SHA512:
6
- metadata.gz: fa0f220f7a37fa6fd72a2b02c615c9020a16f9e77f6c92f472dfcde968cd2752d8a2d798e33bc077076e7fa683c0ee0eb37cb891a5a4344b968bb5385a02eba0
7
- data.tar.gz: 93442f8ce2364a64279fd0350e2c7868c8b1e0d20bbc1a1a22db638cc251069a18cea2655cba9e3fb55cdb7416a78a5a336f7b1cab4c2b25a4bab8c85df44ba8
6
+ metadata.gz: f123901208397e46b758690c7de039712b0f3da5d4375e9ca8102668914994c698114f29ac964120fb69e0d88b0964b0e9a25a72dde6b1f6987826c024239e20
7
+ data.tar.gz: ca95b987182c67fdca1d21d3317658f8895b66ca74eb2eb8e57e94d501930799a700c532afc079cfc1509c00ce14ac3d3c9f9e757280d34bfa33e05b1f8bb36c
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # CdmMigrator
2
- This migrator is designed to export individual ContentDM collections to a CSV for refining. It then allows batch importing into Hyrax via a CSV upload.
2
+ This migrator is designed to export individual ContentDM collections to a CSV for refining. It then allows batch importing into Hyku/Hyrax via a CSV upload.
3
3
 
4
4
  ## Installation
5
5
  Add this line to your application's Gemfile:
@@ -10,7 +10,7 @@ gem 'cdm_migrator'
10
10
 
11
11
  And then execute:
12
12
  ```bash
13
- $ bundle
13
+ $ bundle install
14
14
  ```
15
15
 
16
16
  Or install it yourself as:
@@ -22,19 +22,18 @@ Finally, run:
22
22
  ```bash
23
23
  $ rails g cdm_migrator:install
24
24
  ```
25
+ to insert the yml and add a link to your Hyrax dashboard
25
26
 
26
27
  ## Usage
27
28
  1. Add your ContentDM url and api port to the cdm_migrator.yml file.
28
- 2. Navigate to the *cdm_migrator/cdm/collection* url to select your contentdm collection and what type of work you want to export it to and click "choose mappings".
29
+ 2. Navigate to the *cdm_migrator/collection* url to select your contentdm collection and what type of work you want to export it to and click "choose mappings".
29
30
  3. Map the ContentDM fields to your Hyrax work and file fields\* and click "generate CSV".
30
31
  4. Refine the CSV as you see fit.
31
- 5. Navigate to the *cdm_migrator/csv/upload* url; choose your multi-value seperator (default is |) and upload your CSV file.
32
+ 5. Navigate to the *cdm_migrator/upload* url; choose your multi-value seperator (default is |) and upload your CSV file.
32
33
  6. Done.
33
34
 
34
- \* cdm_migrator uses the generated Hyrax forms (ex. Hyrax::Forms::GenericWorkForm) in your host application to obtain it's terms for mapping. If you have added terms to your FileSet model extend the Hyrax::Forms::FileSetEditForm with FileSetForm in your host application so that the changes will be detected by the migrator.
35
+ \* cdm_migrator uses the generated Hyrax forms (ex. Hyrax::Forms::GenericWorkForm) in your host application to obtain it's terms for mapping. If you have added terms to your FileSet model extend the Hyrax::Forms::FileSetEditForm with Hyrax::FileSetForm in your host application so that the changes will be detected by the migrator. You can also add a list of fields in the yml file, under "default fields".
35
36
 
36
- ## Contributing
37
- Contribution directions go here.
38
37
 
39
38
  ## License
40
39
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -1,17 +1,10 @@
1
1
  module CdmMigrator
2
2
  class CdmController < ApplicationController
3
-
3
+ helper_method :default_page_title, :admin_host?, :available_translations, :available_works
4
+ layout 'dashboard' if Hyrax
4
5
  require 'csv'
5
6
 
6
- def initialize
7
- super
8
- @cdm_url = CdmMigrator::Engine.config["cdm_url"]
9
- @cdm_port = CdmMigrator::Engine.config["cdm_port"]
10
- @default_fields = CdmMigrator::Engine.config["default_fields"]
11
- @cdm_dirs = CdmMigrator::Engine.config["cdm_dirs"] || false
12
- @cdm_api = CdmMigrator::Engine.config["api"]
13
- end
14
-
7
+ before_action :load_yaml
15
8
  before_action :set_exclusive_fields, only: [:generate, :mappings]
16
9
  skip_before_action :verify_authenticity_token
17
10
 
@@ -29,37 +22,37 @@ module CdmMigrator
29
22
  @h_to_c[mapping['hydrac']] << mapping['cdm']
30
23
  end
31
24
  end
32
- json = JSON.parse(Net::HTTP.get_response(URI.parse("#{@cdm_url}:#{@cdm_port}/dmwebservices/index.php?q=dmQuery/#{params[:collection]}/0/0/filetype/1024/0/0/0/0/0/1/0/json")).body)
33
- total_recs = json["pager"]["total"].to_i
25
+ json = JSON.parse(Net::HTTP.get_response(URI.parse("#{@cdm_url}:#{@cdm_port}/dmwebservices/index.php?q=dmQuery#{params[:collection]}/0/0/filetype/1024/0/0/0/0/0/1/0/json")).body)
26
+ total_recs = json['pager']['total'].to_i
34
27
  if total_recs > 1024
35
28
  start = 1
36
29
  records = []
37
30
  [0..(total_recs/1024)].each do |index|
38
31
  start = (index*1024) + 1
39
- json = JSON.parse(Net::HTTP.get_response(URI.parse("http://#{@cdm_url}:#{@cdm_port}/dmwebservices/index.php?q=dmQuery/#{params[:collection]}/0/0/filetype/1024/#{start}/0/0/0/0/1/0/json")).body)
40
- records << json["records"].map { |rec| [rec['pointer'], rec['filetype']] }
32
+ json = JSON.parse(Net::HTTP.get_response(URI.parse("http://#{@cdm_url}:#{@cdm_port}/dmwebservices/index.php?q=dmQuery#{params[:collection]}/0/0/filetype/1024/#{start}/0/0/0/0/1/0/json")).body)
33
+ records << json['records'].map { |rec| [rec['pointer'], rec['filetype']] }
41
34
  end
42
35
  else
43
- records = json["records"].map { |rec| [rec['pointer'], rec['filetype']] }
36
+ records = json['records'].map { |rec| [rec['pointer'], rec['filetype']] }
44
37
  end
45
38
  headers = ::CSV.generate_line (['object_type','url']+@terms+@work_only)
46
39
  csv_lines = [] << headers
47
40
  records.each do |rec|
48
- if rec.last == "cpd"
49
- json = JSON.parse(Net::HTTP.get_response(URI.parse("#{@cdm_url}:#{@cdm_port}/dmwebservices/index.php?q=dmGetItemInfo/#{params[:collection]}/#{rec.first}/json")).body)
50
- csv_lines << create_line(params[:work],"",json)
51
- json = JSON.parse(Net::HTTP.get_response(URI.parse("#{@cdm_url}:#{@cdm_port}/dmwebservices/index.php?q=dmGetCompoundObjectInfo/#{params[:collection]}/#{rec.first}/json")).body)
41
+ if rec.last == 'cpd'
42
+ json = JSON.parse(Net::HTTP.get_response(URI.parse("#{@cdm_url}:#{@cdm_port}/dmwebservices/index.php?q=dmGetItemInfo#{params[:collection]}/#{rec.first}/json")).body)
43
+ csv_lines << create_line(params[:work],'',json)
44
+ json = JSON.parse(Net::HTTP.get_response(URI.parse("#{@cdm_url}:#{@cdm_port}/dmwebservices/index.php?q=dmGetCompoundObjectInfo#{params[:collection]}/#{rec.first}/json")).body)
52
45
  rec_pages = json['page'] || json['node']['page']
53
46
  rec_pages.each do |child|
54
- child_json = JSON.parse(Net::HTTP.get_response(URI.parse("#{@cdm_url}:#{@cdm_port}/dmwebservices/index.php?q=dmGetItemInfo/#{params[:collection]}/#{child['pageptr']}/json")).body)
55
- url = api_check rec
56
- csv_lines << create_line("File",url,child_json)
47
+ child_json = JSON.parse(Net::HTTP.get_response(URI.parse("#{@cdm_url}:#{@cdm_port}/dmwebservices/index.php?q=dmGetItemInfo#{params[:collection]}/#{child['pageptr']}/json")).body)
48
+ url = api_check rec, child
49
+ csv_lines << create_line('File',url,child_json)
57
50
  end
58
51
  else
59
- json = JSON.parse(Net::HTTP.get_response(URI.parse("#{@cdm_url}:#{@cdm_port}/dmwebservices/index.php?q=dmGetItemInfo/#{params[:collection]}/#{rec.first}/json")).body)
60
- csv_lines << create_line(params[:work],"",json)
52
+ json = JSON.parse(Net::HTTP.get_response(URI.parse("#{@cdm_url}:#{@cdm_port}/dmwebservices/index.php?q=dmGetItemInfo#{params[:collection]}/#{rec.first}/json")).body)
53
+ csv_lines << create_line(params[:work],'',json)
61
54
  url = api_check rec
62
- csv_lines << create_line("File",url,{})
55
+ csv_lines << create_line('File',url,{})
63
56
  end
64
57
  end
65
58
  render plain: csv_lines.join, content_type: 'text/csv'
@@ -67,17 +60,15 @@ module CdmMigrator
67
60
  end
68
61
 
69
62
  def mappings
70
- json = JSON.parse(Net::HTTP.get_response(URI.parse("#{@cdm_url}:#{@cdm_port}/dmwebservices/index.php?q=dmGetCollectionFieldInfo/"+params['collection']+'/json')).body)
63
+ json = JSON.parse(Net::HTTP.get_response(URI.parse("#{@cdm_url}:#{@cdm_port}/dmwebservices/index.php?q=dmGetCollectionFieldInfo"+params['collection']+'/json')).body)
71
64
  @cdm_terms = json.collect { |c| [c['name'],c['nick']] }
72
- if @cdm_dirs
73
- get_dirs
74
- end
65
+ get_dirs if @cdm_dirs
75
66
  @yaml = YAML.load_file(params['template'].tempfile) if params.has_key? 'template'
76
67
  end
77
68
 
78
69
  def collection
79
70
  json = JSON.parse(Net::HTTP.get_response(URI.parse("#{@cdm_url}:#{@cdm_port}/dmwebservices/index.php?q=dmGetCollectionList/json")).body)
80
- @collections = json.collect { |c| [c['name'],c['secondary_alias']] }
71
+ @collections = json.collect { |c| [c['name'],c['alias']] }
81
72
  load_concerns
82
73
  end
83
74
 
@@ -92,13 +83,49 @@ module CdmMigrator
92
83
 
93
84
  protected
94
85
 
95
- def api_check rec
96
- if params[:file_system]=="true"
86
+ def available_works
87
+ @available_works ||= Hyrax::QuickClassificationQuery.new(current_user).authorized_models
88
+ end
89
+
90
+ def default_page_title
91
+ 'CDM Mapping'
92
+ end
93
+
94
+ def admin_host?
95
+ false unless Settings.multitenancy.enabled rescue nil
96
+ end
97
+
98
+ def available_translations
99
+ {
100
+ 'en' => 'English',
101
+ 'fr' => 'French'
102
+ }
103
+ end
104
+
105
+ def load_yaml
106
+ stripped_url = request.base_url.dup.gsub(/https?:\/\//, '').gsub(/:[0-9]*/,'')
107
+ if CdmMigrator::Engine.config['cdm_api'].key? stripped_url
108
+ tenant = CdmMigrator::Engine.config['cdm_api'][stripped_url]
109
+ else
110
+ tenant = CdmMigrator::Engine.config['cdm_api']['default']
111
+ end
112
+ @cdm_url = tenant['url']
113
+ @cdm_port = tenant['port']
114
+ @cdm_dirs = tenant['dirs'] || false
115
+ @cdm_api = tenant['type']
116
+ @default_fields = CdmMigrator::Engine.config['default_fields']
117
+ end
118
+
119
+ def api_check rec, child=nil
120
+ cisoptr = child ? child['pageptr'] : rec.first
121
+ filename = child ? child['pagefile'] : "#{rec.first}.#{rec.last}"
122
+
123
+ if params[:file_system]=='true'
97
124
  "file://#{file_path(rec.first)}"
98
- elsif @cdm_api == "server"
99
- "#{@cdm_url}:#{@cdm_port}/cgi-bin/showfile.exe?CISOROOT=/#{params[:collection]}&CISOPTR=#{rec.first}"
125
+ elsif @cdm_api == 'server'
126
+ "#{@cdm_url}:#{@cdm_port}/cgi-bin/showfile.exe?CISOROOT=#{params[:collection]}&CISOPTR=#{cisoptr}"
100
127
  else
101
- "#{@cdm_url}/utils/getfile/collection/#{params[:collection]}/id/#{rec.first}/filename/#{rec.first}.#{rec.last}"
128
+ "#{@cdm_url}/utils/getfile/collection#{params[:collection]}/id/#{cisoptr}/filename/#{filename}"
102
129
  end
103
130
  end
104
131
 
@@ -117,11 +144,11 @@ module CdmMigrator
117
144
  end
118
145
 
119
146
  def work_form
120
- Module.const_get("Hyrax::#{params[:work]}Form") rescue nil || Module.const_get("Hyrax::Forms::WorkForm")
147
+ Module.const_get("Hyrax::#{params[:work]}Form") rescue nil || Module.const_get('Hyrax::Forms::WorkForm')
121
148
  end
122
149
 
123
150
  def file_form
124
- Module.const_get("Hyrax::FileSetForm") rescue nil || Module.const_get("Hyrax::Forms::FileSetEditForm")
151
+ Module.const_get('Hyrax::FileSetForm') rescue nil || Module.const_get('Hyrax::Forms::FileSetEditForm')
125
152
  end
126
153
 
127
154
  def secondary_terms form_name
@@ -155,7 +182,7 @@ module CdmMigrator
155
182
  content.delete_if(&:empty?)
156
183
  end
157
184
  if content.nil? || content.empty? || content == [{}]
158
- line << ""
185
+ line << ''
159
186
  else
160
187
  line << content.join('|')
161
188
  end
@@ -1,6 +1,8 @@
1
1
  module CdmMigrator
2
2
  class CsvController < ApplicationController
3
-
3
+ helper_method :default_page_title, :admin_host?, :available_translations, :available_works
4
+ layout 'dashboard'
5
+
4
6
  def generate
5
7
  headers = ['type','url']
6
8
  skip = ["id", "head", "tail", "depositor", "date_uploaded", "date_modified", "import_url", "thumbnail_id", "embargo_id", "lease_id", "access_control_id", "representative_id"]
@@ -16,20 +18,33 @@ module CdmMigrator
16
18
 
17
19
  def upload
18
20
  #byebug
21
+ authorize! :create, available_works.first
22
+ @admin_sets = AdminSet.all.map { |as| [as.title.first, as.id] }
23
+ @collections = Collection.all.map { |col| [col.title.first, col.id] }
19
24
  end
20
25
 
21
26
  def create
22
27
  #byebug
23
- csv = CSV.parse(File.read(params[:csv_import][:csv_file].path), headers: true, encoding: 'utf-8')
24
- CsvUploadJob.perform_later(params[:csv_import][:csv_file].path, params[:csv_import][:mvs], current_user)
28
+ authorize! :create, available_works.first
29
+ dir = Rails.root.join('public', 'uploads', 'csvs')
30
+ Dir.mkdir(dir) unless Dir.exist?(dir)
31
+ File.open(dir.join(params[:csv_import][:csv_file].original_filename), 'wb') do |file|
32
+ file.write(params[:csv_import][:csv_file].read)
33
+ end
34
+ csv = CSV.parse(File.read(dir.join(params[:csv_import][:csv_file].original_filename)), headers: true, encoding: 'utf-8')
35
+ CsvUploadJob.perform_later(dir.join(params[:csv_import][:csv_file].original_filename).to_s, params[:csv_import][:mvs], params[:collection], params[:admin_set], current_user)
25
36
  #perform(params[:csv_import][:csv_file].path, params[:csv_import][:mvs], current_user)
26
37
  flash[:notice] = "csv successfully uploaded"
27
38
  redirect_to csv_upload_path
28
39
  end
40
+
41
+ private
29
42
 
30
43
  def perform(csv, mvs, current_user)
31
44
  @csv = CSV.parse(File.read(csv), headers: true, encoding: 'utf-8').map(&:to_hash)
32
45
  @mvs = mvs
46
+ @collection = Collection.find(params[:csv_import][:collection]) rescue nil
47
+ @admin_set = AdminSet.find(params[:csv_import][:admin_set]) rescue nil
33
48
  @works = []
34
49
  @files = {}
35
50
  @csv.each do |row|
@@ -47,7 +62,24 @@ module CdmMigrator
47
62
  create_works
48
63
  end
49
64
 
50
- private
65
+ def available_works
66
+ @available_works ||= Hyrax::QuickClassificationQuery.new(current_user).authorized_models
67
+ end
68
+
69
+ def default_page_title
70
+ 'CSV Batch Uploader'
71
+ end
72
+
73
+ def admin_host?
74
+ false unless Settings.multitenancy.enabled
75
+ end
76
+
77
+ def available_translations
78
+ {
79
+ 'en' => 'English',
80
+ 'fr' => 'French'
81
+ }
82
+ end
51
83
 
52
84
  def work_form
53
85
  Module.const_get("Hyrax::#{params[:work]}Form") rescue nil || Module.const_get("Hyrax::Forms::WorkForm")
@@ -112,6 +144,8 @@ module CdmMigrator
112
144
  final_work_data = create_data work_data, work_form, work
113
145
  work.apply_depositor_metadata(current_user)
114
146
  work.attributes = final_work_data
147
+ work.member_of_collections = [@collection] if @collection
148
+ work.admin_set = @admin_set if @admin_set
115
149
  work.save
116
150
  create_files(work, index)
117
151
  index+=1
@@ -2,10 +2,12 @@ class CsvUploadJob < ActiveJob::Base
2
2
  queue_as Hyrax.config.ingest_queue_name
3
3
 
4
4
 
5
- def perform(csv, mvs, current_user)
5
+ def perform(csv, mvs, collection, admin_set, current_user)
6
6
  @current_user = current_user
7
7
  @csv = CSV.parse(File.read(csv), headers: true, encoding: 'utf-8').map(&:to_hash)
8
8
  @mvs = mvs
9
+ @collection = Collection.find(collection) rescue nil
10
+ @admin_set = AdminSet.find(admin_set) rescue nil
9
11
  @works = []
10
12
  @files = {}
11
13
  @csv.each do |row|
@@ -15,6 +17,7 @@ class CsvUploadJob < ActiveJob::Base
15
17
  elsif(type.include? "Work")
16
18
  @works << row
17
19
  @files[@works.length] = []
20
+ @worktype = type.dup
18
21
  elsif(type.include? "File")
19
22
  row.delete("object_type")
20
23
  @files[@works.length] << row
@@ -26,7 +29,7 @@ class CsvUploadJob < ActiveJob::Base
26
29
  private
27
30
 
28
31
  def work_form
29
- Module.const_get("Hyrax::#{params[:work]}Form") rescue nil || Module.const_get("Hyrax::Forms::WorkForm")
32
+ Module.const_get("Hyrax::#{@worktype}Form") rescue nil || Module.const_get("Hyrax::Forms::WorkForm")
30
33
  end
31
34
 
32
35
  def file_form
@@ -88,6 +91,8 @@ class CsvUploadJob < ActiveJob::Base
88
91
  final_work_data = create_data work_data, work_form, work
89
92
  work.apply_depositor_metadata(@current_user)
90
93
  work.attributes = final_work_data
94
+ work.member_of_collections = [@collection] if @collection
95
+ work.admin_set = @admin_set if @admin_set
91
96
  work.save
92
97
  create_files(work, index)
93
98
  index+=1
@@ -1,3 +1,6 @@
1
+ <h1><span class="fa fa-map"></span> <%= default_page_title %></h1>
2
+
3
+ <h5>ContentDM API address: <%= @cdm_url %></h5>
1
4
  <%= form_tag cdm_mappings_path, method: "post", multipart: true do %>
2
5
  <table>
3
6
  <tr><td>Collection: </td><td><%= select_tag 'collection', options_for_select(@collections) %></td></tr>
@@ -10,6 +10,8 @@ border:1px solid black;
10
10
  }
11
11
  </style>
12
12
 
13
+ <h1><span class="fa fa-map"></span> <%= default_page_title %></h1>
14
+
13
15
  <%= form_tag cdm_generate_path.gsub("generate","generate.csv") do %>
14
16
  <%= hidden_field_tag "collection", params[:collection] %>
15
17
  <%= hidden_field_tag "file_system", params[:file_system] %>
@@ -1,8 +1,16 @@
1
+ <h1><span class="fa fa-angle-double-up"></span> <%= default_page_title %></h1>
2
+
1
3
  <%= form_for :csv_import, url: csv_create_path do |f| %>
2
4
  <%= f.label 'Multi-value Separator:' %>
3
5
  <%= f.text_field 'mvs' %>
4
6
  <br />
5
7
  <%= f.file_field 'csv_file' %>
8
+ <br />
9
+ <%= f.label 'Admin Set:' %>
10
+ <%= select_tag "admin_set", options_for_select(@admin_sets), :include_blank => true %>
11
+ <br />
12
+ <%= f.label 'Collection:' %>
13
+ <%= select_tag "collection", options_for_select(@collections), :include_blank => true %>
6
14
  <br />
7
15
  <%= f.submit 'Save' %>
8
16
  <% end %>
data/config/routes.rb CHANGED
@@ -1,10 +1,10 @@
1
- CdmMigrator::Engine.routes.draw do
2
- get '/csv/upload', to: 'csv#upload', as: 'csv_upload'
3
- post '/csv/upload', to: 'csv#create', as: 'csv_create'
4
- get '/csv/generate', to: 'csv#generate', as: 'csv_generate'
1
+ Rails.application.routes.draw do
2
+ get '/cdm_migrator/upload', to: 'cdm_migrator/csv#upload', as: 'csv_upload'
3
+ post '/cdm_migrator/upload', to: 'cdm_migrator/csv#create', as: 'csv_create'
4
+ get '/cdm_migrator/generate', to: 'cdm_migrator/csv#generate', as: 'csv_generate'
5
5
 
6
- get 'cdm/collection', to: 'cdm#collection'
7
- post 'cdm/mappings/', to: 'cdm#mappings', as: 'cdm_mappings'
8
- post 'cdm/generate/', to: 'cdm#generate', as: 'cdm_generate'
9
- post 'cdm/template', to: 'cdm#template', as: 'cdm_template'
6
+ get '/cdm_migrator/collection', to: 'cdm_migrator/cdm#collection', as: 'cdm_start'
7
+ post '/cdm_migrator/mappings/', to: 'cdm_migrator/cdm#mappings', as: 'cdm_mappings'
8
+ post '/cdm_migrator/generate/', to: 'cdm_migrator/cdm#generate', as: 'cdm_generate'
9
+ post '/cdm_migrator/template', to: 'cdm_migrator/cdm#template', as: 'cdm_template'
10
10
  end
@@ -3,7 +3,7 @@
3
3
  module CdmMigrator
4
4
  class Engine < ::Rails::Engine
5
5
 
6
- isolate_namespace CdmMigrator
6
+ #isolate_namespace CdmMigrator
7
7
  class << self
8
8
 
9
9
  def config
@@ -1,4 +1,3 @@
1
1
  module CdmMigrator
2
- VERSION = '1.4.4'
2
+ VERSION = '2.0.0'
3
3
  end
4
-
@@ -1,13 +1,56 @@
1
1
  class CdmMigrator::InstallGenerator < Rails::Generators::Base
2
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 CdmMigrator::Engine => '/cdm_migrator'\n)
3
+
4
+ def inject_dashboard_link
5
+ file_path = "app/views/hyrax/dashboard/sidebar/_tasks.html.erb"
6
+ if File.file?(file_path)
7
+ gsub_file file_path,/[ \t]*(<% if can\? :review, :submissions %>)\n[ \t]*(<li class="h5"><%= t\('hyrax\.admin\.sidebar\.tasks'\) %><\/li>)\n/ do |match|
8
+ match.split("\n")[1].to_s+
9
+ "\n <li>\n" \
10
+ " <%= menu.collapsable_section t('CDM Migrator'),\n" \
11
+ " icon_class: \"fa fa-map-signs\",\n" \
12
+ " id: 'collapseCdmMigrator',\n" \
13
+ " open: menu.cdm_migrator_section? do %>\n" \
14
+ " <%= menu.nav_link(main_app.csv_upload_path) do %>\n"\
15
+ " <span class=\"fa fa-angle-double-up\"></span> <span class=\"sidebar-action-text\"><%= t('CSV Batch Uploader') %></span>\n" \
16
+ " <% end %>\n" \
17
+ " <%= menu.nav_link(main_app.cdm_start_path) do %>\n" \
18
+ " <span class=\"fa fa-map\"></span> <span class=\"sidebar-action-text\"><%= t('CDM Mapping Tool') %></span>\n" \
19
+ " <% end %>\n" \
20
+ " <% end %>\n" \
21
+ " </li>\n" + match.split("\n")[0].to_s + "\n"
22
+ end
23
+ else
24
+ copy_file "sidebar/_tasks.html.erb", "app/views/hyrax/dashboard/sidebar/_tasks.html.erb"
7
25
  end
8
26
  end
27
+
28
+ def inject_menu_presenter
29
+ hyku_file_path = "app/presenters/hyku/menu_presenter.rb"
30
+ hyrax_file_path = "app/presenters/hyrax/menu_presenter.rb"
31
+ if File.file?(hyku_file_path)
32
+ insert_into_file hyku_file_path, :after => /def settings_section\?\n.*\(controller_name\)\n[ \t]*end/ do
33
+ "\n\n" \
34
+ " def cdm_migrator_section?\n" \
35
+ " %w[cdm csv].include?(controller_name)\n" \
36
+ " end\n"
37
+ end
38
+ elsif File.file?(hyrax_file_path)
39
+ insert_into_file hyrax_file_path, :after => /def settings_section\?\n.*\(controller_name\)\n[ \t]*end/ do
40
+ "\n\n" \
41
+ " def cdm_migrator_section?\n" \
42
+ " %w[cdm csv].include?(controller_name)\n" \
43
+ " end\n"
44
+ end
45
+ elsif Hyku
46
+ copy_file "presenters/hyku/menu_presenter.rb", "app/presenters/hyku/menu_presenter.rb"
47
+ elsif Hyrax
48
+ copy_file "presenters/hyrax/menu_presenter.rb", "app/presenters/hyrax/menu_presenter.rb"
49
+ end
50
+ end
9
51
 
10
52
  def inject_content_dm_yml
11
53
  copy_file "config/cdm_migrator.yml", "config/cdm_migrator.yml"
12
54
  end
55
+
13
56
  end
@@ -1,9 +1,25 @@
1
- cdm_url: 'http://your-content-dm-host'
2
- cdm_port: 8080
3
- cdm_dirs:
4
- dir1: '/dir1/path/goes/here'
5
- dir2: '/dir2/path/goes/here'
6
- api: 'front'
1
+ cdm_api:
2
+ tenant1.institution.com:
3
+ url: 'http://your-content-dm-host'
4
+ port: 8080
5
+ type: 'front'
6
+ dirs:
7
+ dir1: '/dir1/path/goes/here'
8
+ dir2: '/dir2/path/goes/here'
9
+ tenant2.institution.com:
10
+ url: 'http://your-content-dm-host'
11
+ port: 8080
12
+ type: 'front'
13
+ dirs:
14
+ dir1: '/dir1/path/goes/here'
15
+ dir2: '/dir2/path/goes/here'
16
+ default:
17
+ url: 'http://your-content-dm-host'
18
+ port: 8080
19
+ type: 'front'
20
+ dirs:
21
+ dir1: '/dir1/path/goes/here'
22
+ dir2: '/dir2/path/goes/here'
7
23
  default_fields:
8
24
  - title
9
25
  - creator
@@ -0,0 +1,47 @@
1
+ module Hyku
2
+ # view-model for the admin menu
3
+ class MenuPresenter < Hyrax::MenuPresenter
4
+ # Returns true if the current controller happens to be one of the controllers that deals
5
+ # with settings. This is used to keep the parent section on the sidebar open.
6
+ def settings_section?
7
+ %w[appearances content_blocks labels features pages].include?(controller_name)
8
+ end
9
+
10
+ def cdm_migrator_section?
11
+ %w[cdm csv].include?(controller_name)
12
+ end
13
+
14
+ # Returns true if the current controller happens to be one of the controllers that deals
15
+ # with roles and permissions. This is used to keep the parent section on the sidebar open.
16
+ def roles_and_permissions_section?
17
+ # we're using a case here because we need to differentiate UsersControllers
18
+ # in different namespaces (Hyrax & Admin)
19
+ case controller
20
+ when Hyrax::Admin::UsersController, ::Admin::GroupsController
21
+ true
22
+ else
23
+ false
24
+ end
25
+ end
26
+
27
+ # Returns true if the current controller happens to be one of the controllers that deals
28
+ # with repository activity This is used to keep the parent section on the sidebar open.
29
+ def repository_activity_section?
30
+ %w[admin dashboard status].include?(controller_name)
31
+ end
32
+
33
+ # Returns true if we ought to show the user the 'Configuration' section
34
+ # of the menu
35
+ def show_configuration?
36
+ super ||
37
+ can?(:manage, Site) ||
38
+ can?(:manage, User) ||
39
+ can?(:manage, Hyku::Group)
40
+ end
41
+
42
+ # Returns true if we ought to show the user Admin-only areas of the menu
43
+ def show_admin_menu_items?
44
+ can?(:read, :admin_dashboard)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,66 @@
1
+ module Hyrax
2
+ # view-model for the admin menu
3
+ class MenuPresenter
4
+ def initialize(view_context)
5
+ @view_context = view_context
6
+ end
7
+
8
+ attr_reader :view_context
9
+
10
+ delegate :controller, :controller_name, :action_name, :content_tag,
11
+ :current_page?, :link_to, :can?, to: :view_context
12
+
13
+ # Returns true if the current controller happens to be one of the controllers that deals
14
+ # with settings. This is used to keep the parent section on the sidebar open.
15
+ def settings_section?
16
+ %w[appearances content_blocks features pages collection_types].include?(controller_name)
17
+ end
18
+
19
+ def cdm_migrator_section?
20
+ %w[cdm csv].include?(controller_name)
21
+ end
22
+
23
+ # @param options [Hash, String] a hash or string representing the path. Hash is prefered as it
24
+ # allows us to workaround https://github.com/rails/rails/issues/28253
25
+ # @param also_active_for [Hash, String] a hash or string with alternative paths that should be 'active'
26
+ def nav_link(options, also_active_for: nil, **link_html_options)
27
+ active_urls = [options, also_active_for].compact
28
+ list_options = active_urls.any? { |url| current_page?(url) } ? { class: 'active' } : {}
29
+ content_tag(:li, list_options) do
30
+ link_to(options, link_html_options) do
31
+ yield
32
+ end
33
+ end
34
+ end
35
+
36
+ # @return [Boolean] true if the current controller happens to be one of the controllers that deals
37
+ # with user activity This is used to keep the parent section on the sidebar open.
38
+ def user_activity_section?
39
+ # we're using a case here because we need to differentiate UsersControllers
40
+ # in different namespaces (Hyrax & Admin)
41
+ case controller
42
+ when Hyrax::UsersController, Hyrax::NotificationsController, Hyrax::TransfersController, Hyrax::DepositorsController
43
+ true
44
+ else
45
+ false
46
+ end
47
+ end
48
+
49
+ # Draw a collaspable menu section. The passed block should contain <li> items.
50
+ def collapsable_section(text, id:, icon_class:, open:, &block)
51
+ CollapsableSectionPresenter.new(view_context: view_context,
52
+ text: text,
53
+ id: id,
54
+ icon_class: icon_class,
55
+ open: open).render(&block)
56
+ end
57
+
58
+ # @return [Boolean] will the configuration section be displayed to the user
59
+ def show_configuration?
60
+ can?(:update, :appearance) ||
61
+ can?(:manage, :collection_types) ||
62
+ can?(:manage, Sipity::WorkflowResponsibility) ||
63
+ can?(:manage, Hyrax::Feature)
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,43 @@
1
+ <li class="h5"><%= t('hyrax.admin.sidebar.tasks') %></li>
2
+ <li>
3
+ <%= menu.collapsable_section t('CDM Migrator'),
4
+ icon_class: "fa fa-map-signs",
5
+ id: 'collapseCdmMigrator',
6
+ open: menu.cdm_migrator_section? do %>
7
+ <%= menu.nav_link(main_app.csv_upload_path) do %>
8
+ <span class="fa fa-angle-double-up"></span> <span class="sidebar-action-text"><%= t('CSV Batch Uploader') %></span>
9
+ <% end %>
10
+
11
+ <%= menu.nav_link(main_app.cdm_start_path) do %>
12
+ <span class="fa fa-map"></span> <span class="sidebar-action-text"><%= t('CDM Mapping Tool') %></span>
13
+ <% end %>
14
+ <% end %>
15
+ </li>
16
+
17
+ <% if can? :review, :submissions %>
18
+ <%= menu.nav_link(hyrax.admin_workflows_path) do %>
19
+ <span class="fa fa-flag" aria-hidden="true"></span> <span class="sidebar-action-text"><%= t('hyrax.admin.sidebar.workflow_review') %></span>
20
+ <% end %>
21
+ <% end %>
22
+
23
+ <% if can? :manage, User %>
24
+ <%= menu.nav_link(hyrax.admin_users_path) do %>
25
+ <span class="fa fa-user" aria-hidden="true"></span> <span class="sidebar-action-text"><%= t('hyrax.admin.sidebar.users') %></span>
26
+ <% end %>
27
+ <% end %>
28
+
29
+ <% if can? :manage, Hyku::Group %>
30
+ <%= menu.nav_link(main_app.admin_groups_path) do %>
31
+ <span class="fa fa-users"></span> <span class="sidebar-action-text"><%= t('hyrax.admin.sidebar.manage_groups') %></span>
32
+ <% end %>
33
+ <% end %>
34
+
35
+ <% if can? :read, :admin_dashboard %>
36
+ <%= menu.nav_link(hyrax.embargoes_path) do %>
37
+ <span class="fa fa-flag" aria-hidden="true"></span> <span class="sidebar-action-text"><%= t('hyrax.embargoes.index.manage_embargoes') %></span>
38
+ <% end %>
39
+
40
+ <%= menu.nav_link(hyrax.leases_path) do %>
41
+ <span class="fa fa-flag" aria-hidden="true"></span> <span class="sidebar-action-text"><%= t('hyrax.leases.index.manage_leases') %></span>
42
+ <% end %>
43
+ <% end %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cdm_migrator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sephirothkod
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-27 00:00:00.000000000 Z
11
+ date: 2019-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -99,6 +99,9 @@ files:
99
99
  - lib/cdm_migrator/version.rb
100
100
  - lib/generators/cdm_migrator/install/install_generator.rb
101
101
  - lib/generators/cdm_migrator/install/templates/config/cdm_migrator.yml
102
+ - lib/generators/cdm_migrator/install/templates/presenters/hyku/menu_presenter.rb
103
+ - lib/generators/cdm_migrator/install/templates/presenters/hyrax/menu_presenter.rb
104
+ - lib/generators/cdm_migrator/install/templates/sidebar/_tasks.html.erb
102
105
  - lib/tasks/cdm_migrator_tasks.rake
103
106
  homepage: https://github.com/UVicLibrary/cdm_migrator
104
107
  licenses:
@@ -120,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
123
  version: '0'
121
124
  requirements: []
122
125
  rubyforge_project:
123
- rubygems_version: 2.6.11
126
+ rubygems_version: 2.7.7
124
127
  signing_key:
125
128
  specification_version: 4
126
129
  summary: ContentDM to Hyrax migrator.