diff --git a/hyrax/app/assets/stylesheets/rdms.scss b/hyrax/app/assets/stylesheets/rdms.scss index d2d648a7d1fb8fc10b5a7f601f1708b01cab7b47..cb87141888e9d881a6dfcb141b09069ca95b7889 100644 --- a/hyrax/app/assets/stylesheets/rdms.scss +++ b/hyrax/app/assets/stylesheets/rdms.scss @@ -370,3 +370,10 @@ form .field-wrapper label[required="required"]::after { margin: 4em auto 0; padding: 20px; } + +#work-entries { + .work-tab-actions { + display: flex; + gap: 10px; + } +} \ No newline at end of file diff --git a/hyrax/app/controllers/bulkrax/importers_controller.rb b/hyrax/app/controllers/bulkrax/importers_controller.rb index d16c9d75a0d77dbd29d07c174ed086674271c206..284dac27c0fbe90294c7e9e97a53324414daa09e 100644 --- a/hyrax/app/controllers/bulkrax/importers_controller.rb +++ b/hyrax/app/controllers/bulkrax/importers_controller.rb @@ -10,11 +10,12 @@ module Bulkrax include Bulkrax::DownloadBehavior include Bulkrax::API include Bulkrax::ValidationHelper + include HyraxHelper protect_from_forgery unless: -> { api_request? } before_action :token_authenticate!, if: -> { api_request? }, only: [:create, :update, :delete] before_action :authenticate_user!, unless: -> { api_request? } - before_action :set_importer, only: [:show, :edit, :update, :destroy] + before_action :set_importer, only: [:show, :edit, :update, :destroy, :verify_and_generate_work] with_themed_layout 'dashboard' # GET /importers @@ -212,6 +213,23 @@ module Bulkrax send_content end + def verify_and_generate_work + entry = Bulkrax::Entry.find_by(id: params[:entry_id]) + varification_status, date, report_path = latest_varification_report_details(entry) + + if params[:verify] + experiment_status, report_path = VerifyCRCDatasetImport.verify_experiment_and_report(@importer.id, params[:entry_id]) + end + + return head :not_found unless File.exists?(report_path) + + respond_to do |format| + format.html {redirect_to bulkrax.importer_path(@importer.id) } + format.csv { send_file report_path, type: 'application/csv', disposition: 'attachment' } + format.any { head :unsupported_media_type } + end + end + private def files_for_import(file, cloud_files) @@ -229,7 +247,7 @@ module Bulkrax # Use callbacks to share common setup or constraints between actions. def set_importer - @importer = Importer.find(params[:id]) + @importer = Importer.find(params[:id] || params[:importer_id]) end def importable_params diff --git a/hyrax/app/helpers/hyrax_helper.rb b/hyrax/app/helpers/hyrax_helper.rb index 125a88543fdc9a66c7d5639b952ffcdb6cfc47a9..90ffd21576d24dcc9a0521e18e9745dbbcce6331 100644 --- a/hyrax/app/helpers/hyrax_helper.rb +++ b/hyrax/app/helpers/hyrax_helper.rb @@ -187,4 +187,29 @@ module HyraxHelper "fa fa-file-o" end end + + def latest_varification_report_details(entry) + # Define the file pattern and search path + download_path = ENV.fetch('DOWNLOAD_PATH', '/shared/downloads') + report_pattern = "analysis_report_#{entry.importerexporter_id}_#{entry.id}_*.csv" + matching_files = Dir.glob(File.join(download_path, report_pattern)) + + # Return nil if no matching files are found + return [nil, nil, nil] if matching_files.empty? + + # Find the newest file based on modification time + newest_file = matching_files.max_by { |file| File.mtime(file) } + + # Extract file details + base_name = File.basename(newest_file, ".*") + extension = File.extname(newest_file) + date_time_str, status = base_name.split('_')[-2..] + + # Parse the date and time + date, raw_time = date_time_str.split('T') + formatted_time = raw_time.gsub('-', ':') + parsed_datetime = Time.parse("#{date} #{formatted_time}") + + [status.titleize, parsed_datetime, newest_file] + end end diff --git a/hyrax/app/services/verify_crc_dataset_import.rb b/hyrax/app/services/verify_crc_dataset_import.rb index 5c15153d359abaa771ea56ab2cbebb3f1ae1c85e..539141f67e83aff62ade8ba27a5a8cfed1e3e483 100644 --- a/hyrax/app/services/verify_crc_dataset_import.rb +++ b/hyrax/app/services/verify_crc_dataset_import.rb @@ -2,6 +2,7 @@ require 'json' require 'csv' class VerifyCRCDatasetImport + extend ComplexHelper def self.verify_import(import_id) importer = ::Bulkrax::Importer.find(import_id) work_entries = importer.entries.select {|e| e.class.name == "Bulkrax::CrcFolderEntry"} @@ -19,9 +20,9 @@ class VerifyCRCDatasetImport verification_status, message, paths_compared, analysis = self.verify_experiment(entry_id, import_id) # prepare csv report - report_name = "analysis_report_#{import_id}_#{entry_id}_#{Time.now.strftime("%m-%d_%H-%M-%S")}.csv" + report_name = "analysis_report_#{import_id}_#{entry_id}_#{Time.now.strftime("%Y-%m-%dT%H-%M-%S")}_#{ verification_status ? "success" : "failure"}.csv" report_path = File.join(ENV.fetch('DOWNLOAD_PATH', '/shared/downloads'), report_name) - headers = %w(id, status, message) + headers = %w(id status message) CSV.open(report_path, "w") do |csv| # Write headers @@ -135,7 +136,7 @@ class VerifyCRCDatasetImport all_parts = fp.split('/') if all_parts.size > 1 parts = all_parts[0...-1] - parts.map {|p| p.downcase!} + parts = parts.map {|p| p.length > 3 ? sanitize_title(p) :sanitize_title(p.rjust(3, '0'))} new_path = File.join(parts.join("/"), all_parts[-1]) sanitised_input_list[fp] = new_path end @@ -150,7 +151,7 @@ class VerifyCRCDatasetImport sanitised_input_list.each do |fp, new_path| parts = new_path.split('/') if parts.size == 3 - sanitised_input_list[fp] = File.join(parts[0], 'ses 01', parts[1], parts[2]) + sanitised_input_list[fp] = File.join(sanitize_title(parts[0]), 'ses 01', sanitize_title(parts[1]), parts[2]) end end end diff --git a/hyrax/app/views/bulkrax/shared/_work_entries_tab.html.erb b/hyrax/app/views/bulkrax/shared/_work_entries_tab.html.erb index 1fac7b9ab64991622d6bdcf4129fef66f4e95366..6fcb1d2a24e8f73ae733fdd3cb4f429973e27ccd 100644 --- a/hyrax/app/views/bulkrax/shared/_work_entries_tab.html.erb +++ b/hyrax/app/views/bulkrax/shared/_work_entries_tab.html.erb @@ -29,7 +29,27 @@ <td></td> <% end %> <td><%= e.status_at %></td> - <td><%= link_to raw('<span class="glyphicon glyphicon-info-sign"></span>'), entry_path %></td> + <td> + <div class="work-tab-actions"> + <%= link_to raw('<span class="glyphicon glyphicon-info-sign"></span>'), entry_path %> + <% varification_status, date, file_path = latest_varification_report_details(e) %> + <% if varification_status.present? %> + <% if varification_status == "Success" %> + <span class="glyphicon glyphicon-ok text-success" title="Verified successfully on (<%= date %>)"></span> + <% else %> + <span class="glyphicon glyphicon-remove text-danger" title="Verification failed on (<%= date %>)"></span> + <% end %> + <%= link_to url_for(controller: params[:controller], action: "verify_and_generate_work", importer_id: e.importerexporter_id, entry_id: e.id, format: :csv) do %> + <span class="glyphicon glyphicon-download-alt" title="Download csv report of last verification"></span> + <% end %> + <% end %> + <% if !varification_status || varification_status == "Failure" %> + <%= link_to url_for(controller: params[:controller], action: "verify_and_generate_work", importer_id: e.importerexporter_id, entry_id: e.id, verify: true) do %> + <span class="glyphicon glyphicon-refresh"></span> + <% end %> + <% end%> + </div> + </td> </tr> <% end %> </tbody> diff --git a/hyrax/config/routes.rb b/hyrax/config/routes.rb index ff28a3281801c156d5dce1bda9870518b3d7a921..fc5a607d5bc099f76433607a2fd2893879344a34 100644 --- a/hyrax/config/routes.rb +++ b/hyrax/config/routes.rb @@ -70,6 +70,9 @@ Bulkrax::Engine.routes.draw do post 'rerun_failed_entries', to: "rerun_importers#rerun_failed_entries" post 'rerun_pending_entries', to: "rerun_importers#rerun_panding_entries" post 'marked_as_complete', to: "rerun_importers#marked_as_complete" + resources :importers do + get 'verify_and_generate_work/:entry_id', to: "importers#verify_and_generate_work" + end end Hyrax::Engine.routes.draw do