Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/controllers/accession_renewals/files_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AccessionRenewals::FilesController < ApplicationController
def show
renewal = current_user.accession_renewals.find(params.expect(:accession_renewal_id))

redirect_to renewal.file.url, allow_other_host: true
end
end
22 changes: 22 additions & 0 deletions app/controllers/accession_renewals_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class AccessionRenewalsController < ApplicationController
def show
@renewal = current_user.accession_renewals.find(params.expect(:id))
end

def create
accession = current_user.accessions.find_by!(number: params.expect(:accession_number))
@renewal = accession.renewals.create!(renewal_params)

RenewAccessionJob.perform_later @renewal

render :show, status: :created
end

private

def renewal_params
params.expect(accession_renewal: [
:file
])
end
end
25 changes: 14 additions & 11 deletions app/controllers/validations/via_ddbj_records_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
class Validations::ViaDDBJRecordsController < ApplicationController
def create
@validation = current_user.validations.create!(
@validation = create_validation

ValidateJob.perform_later @validation

render status: :created
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
render status: :created
render status: :accepted

end

private

def create_validation
current_user.validations.create!(
db: params.expect(:db),
via: :ddbj_record,
progress: :finished,
finished_at: Time.current
) {|validation|
validation.objs.build _id: '_base', validity: 'valid'

Expand All @@ -14,28 +22,23 @@ def create
if file = record_params[:file]
validation.objs.build(
_id: 'DDBJRecord',
validity: 'valid',
file:,
destination:
)
elsif path = record_params['path']
obj_schema = db[:objects][:ddbj_record].first

obj = validation.build_obj_from_path(path, **{
validation.build_obj_from_path(path, **{
obj_schema:,
destination:,
user: current_user
})

obj.validity = 'valid'
end
}

render status: :created
validation
}
end

private

def record_params
params.expect(DDBJRecord: [
:file,
Expand Down
26 changes: 26 additions & 0 deletions app/jobs/renew_accession_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class RenewAccessionJob < ApplicationJob
def perform(renewal)
renewal.update! progress: :running, started_at: Time.current

sleep 3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sleep 3


ActiveRecord::Base.transaction do
begin
JSON.parse renewal.file.download
rescue JSON::ParserError => e
renewal.validation_details.create!(
severity: 'error',
message: e.message
)
end

if renewal.validation_details.empty?
renewal.validity_valid!
else
renewal.validity_invalid!
end
end
ensure
renewal.update! progress: :finished, finished_at: Time.current unless renewal.canceled?
end
end
2 changes: 1 addition & 1 deletion app/jobs/validate_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def perform(validation)
validation.update! progress: :running, started_at: Time.current

ActiveRecord::Base.transaction do
validator = "Database::#{validation.db}::Validator".constantize.new
validator = "Database::#{validation.db}::#{validation.via.camelize}Validator".constantize.new

begin
validator.validate validation
Expand Down
2 changes: 2 additions & 0 deletions app/models/accession.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class Accession < ApplicationRecord
belongs_to :submission

has_many :renewals, dependent: :destroy, class_name: 'AccessionRenewal'
end
10 changes: 10 additions & 0 deletions app/models/accession_renewal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AccessionRenewal < ApplicationRecord
belongs_to :accession, inverse_of: :renewals

has_many :validation_details, dependent: :destroy, class_name: 'AccessionRenewalValidationDetail', inverse_of: :renewal

has_one_attached :file

enum :progress, %w[waiting running finished canceled].index_by(&:to_sym)
enum :validity, %w[valid invalid error].index_by(&:to_sym), prefix: true
end
3 changes: 3 additions & 0 deletions app/models/accession_renewal_validation_detail.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class AccessionRenewalValidationDetail < ApplicationRecord
belongs_to :renewal, class_name: 'AccessionRenewal'
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Database::BioProject::Validator
class Database::BioProject::FileValidator
include DDBJValidator

def translate_error(error)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Database::BioSample::Validator
class Database::BioSample::FileValidator
include DDBJValidator

def translate_error(error)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Database::DRA::Validator
class Database::DRA::FileValidator
def validate(validation)
objs = validation.objs.without_base.index_by(&:_id)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Database::GEA::Validator
class Database::GEA::FileValidator
def validate(validation)
objs = validation.objs.without_base.index_by(&:_id)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Database::JVar::Validator
class Database::JVar::FileValidator
def validate(validation)
validation.objs.without_base.each(&:validity_valid!)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Database::MetaboBank::Validator
class Database::MetaboBank::FileValidator
def validate(validation)
objs = validation.objs.without_base.index_by(&:_id)

Expand Down
18 changes: 18 additions & 0 deletions app/models/database/trad/ddbj_record_validator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Database::Trad::DDBJRecordValidator
def validate(validation)
obj = validation.objs.without_base.last

begin
JSON.parse(obj.file.download)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
JSON.parse(obj.file.download)
JSON.parse obj.file.download


obj.validity_valid! if obj.validation_details.empty?
rescue JSON::ParserError => e
obj.validity_invalid!

obj.validation_details.create!(
severity: 'error',
message: e.message
)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Database::Trad::Validator
class Database::Trad::FileValidator
class MissingContactPersonInformation < StandardError; end
class DuplicateContactPersonInformation < StandardError; end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Database::Trad2::Validator
class Database::Trad2::FileValidator
include TradValidation

ASSOC = {
Expand Down
5 changes: 3 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ def self.generate_api_key

has_many :validations, dependent: :destroy

has_many :submissions, through: :validations
has_many :accessions, through: :submissions
has_many :submissions, through: :validations
has_many :accessions, through: :submissions
has_many :accession_renewals, through: :accessions, source: :renewals

before_create do |user|
user.api_key ||= self.class.generate_api_key
Expand Down
25 changes: 25 additions & 0 deletions app/views/accession_renewals/_accession_renewal.json.jb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
**accession_renewal.slice(
:id,
:started_at,
:finished_at,
:progress,
:validity,
:created_at
),

file: {
filename: accession_renewal.file.filename,
url: accession_renewal_file_url(accession_renewal)
},

validation_details: accession_renewal.validation_details.map {|detail|
{
**detail.slice(
:severity
),

message: detail.message.scrub
}
}
}
1 change: 1 addition & 0 deletions app/views/accession_renewals/show.json.jb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
render(@renewal)
16 changes: 10 additions & 6 deletions app/views/accessions/_accession.json.jb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# locals: (accession:)

accession.slice(
:number,
:entry_id,
:version,
:last_updated_at
)
{
**accession.slice(
:number,
:entry_id,
:version,
:last_updated_at
),

renewals: render(partial: 'accession_renewals/accession_renewal', collection: accession.renewals)
}
11 changes: 9 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@
end
end

resources :submissions, only: %i[index show create]
resources :accessions, only: %i[show update], param: :number
resources :submissions, only: %i[index show create] do
resources :accessions, only: %i[show update], param: :number, shallow: true do
resources :accession_renewals, only: %i[show create] do
scope module: 'accession_renewals' do
resource :file, only: %i[show], shallow: false
end
end
end
end
end

get 'web/*paths', to: 'webs#show'
Expand Down
23 changes: 23 additions & 0 deletions db/migrate/20250924000504_create_accession_renewals.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class CreateAccessionRenewals < ActiveRecord::Migration[8.0]
def change
create_table :accession_renewals do |t|
t.references :accession, null: false, foreign_key: true

t.string :progress, null: false, default: "waiting"
t.string :validity
t.datetime :started_at
t.datetime :finished_at

t.timestamps
end

create_table :accession_renewal_validation_details do |t|
t.references :renewal, null: false, foreign_key: {to_table: :accession_renewals}

t.string :severity, null: false
t.string :message, null: false

t.timestamps
end
end
end
24 changes: 23 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions schema/openapi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,29 @@ export interface components {
version: number;
/** Format: date-time */
last_updated_at: string;
renewals?: components["schemas"]["AccessionRenewal"][];
};
AccessionRenewal: {
id: number;
/** Format: date-time */
created_at: string;
/** Format: date-time */
started_at: string | null;
/** Format: date-time */
finished_at: string | null;
/** @enum {string} */
progress: "waiting" | "running" | "finished" | "canceled";
/** @enum {string|null} */
validity: "valid" | "invalid" | "error" | null;
file: {
filename: string;
/** Format: url */
url: string;
} | null;
validation_details: {
severity: string;
message: string;
}[];
};
ValidationResult: {
/** @enum {string} */
Expand Down
Loading
Loading