Skip to content
Snippets Groups Projects
Commit 3c974ab8 authored by Gyan Gupta's avatar Gyan Gupta Committed by Anusha Ranganathan
Browse files

Implements UI for import verification

parent 7a4aaa08
No related branches found
No related tags found
1 merge request!354Implements UI for import verification
......@@ -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
......@@ -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
......
......@@ -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
......@@ -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
......
......@@ -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>
......
......@@ -69,6 +69,9 @@ Bulkrax::Engine.routes.draw do
concern :range_searchable, BlacklightRangeLimit::Routes::RangeSearchable.new
post 'rerun_failed_entries', to: "rerun_importers#rerun_failed_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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment