diff --git a/api/Gemfile b/api/Gemfile index 76f565b7..7c28e023 100644 --- a/api/Gemfile +++ b/api/Gemfile @@ -4,11 +4,14 @@ gem "rails", "~> 8.0.0" gem "aws-sdk-s3" gem "base62-rb" +gem "bcrypt_pbkdf" gem "bootsnap", require: false +gem "ed25519" gem "fetch-api" gem "jb" gem "json" gem "metabobank_tools", github: "ddbj/metabobank_tools" +gem "net-ssh" gem "noodles_gff", path: "../noodles_gff-rb" gem "openid_connect" gem "pagy" diff --git a/api/Gemfile.lock b/api/Gemfile.lock index f83337fa..754a1244 100644 --- a/api/Gemfile.lock +++ b/api/Gemfile.lock @@ -121,6 +121,8 @@ GEM aws-eventstream (~> 1, >= 1.0.2) base62-rb (0.3.1) base64 (0.2.0) + bcrypt_pbkdf (1.1.1) + bcrypt_pbkdf (1.1.1-arm64-darwin) benchmark (0.4.0) bigdecimal (3.1.8) bindata (2.5.0) @@ -143,6 +145,7 @@ GEM reline (>= 0.3.8) diff-lcs (1.5.1) drb (2.2.1) + ed25519 (1.3.0) email_validator (2.2.4) activemodel erubi (1.13.0) @@ -221,6 +224,7 @@ GEM timeout net-smtp (0.5.0) net-protocol + net-ssh (7.3.0) nio4r (2.7.4) nokogiri (1.16.8-aarch64-linux) racc (~> 1.4) @@ -431,15 +435,18 @@ PLATFORMS DEPENDENCIES aws-sdk-s3 base62-rb + bcrypt_pbkdf bootsnap brakeman climate_control debug + ed25519 factory_bot_rails fetch-api jb json metabobank_tools! + net-ssh noodles_gff! openid_connect pagy diff --git a/api/app/models/database/bioproject/submitter.rb b/api/app/models/database/bioproject/submitter.rb index c63123fb..2d5c605d 100644 --- a/api/app/models/database/bioproject/submitter.rb +++ b/api/app/models/database/bioproject/submitter.rb @@ -98,15 +98,16 @@ def submit(submission) ) tx.after_commit do - DRMDB::ExtEntity.create!( + entity = DRMDB::ExtEntity.create!( acc_type: :study, ref_name: submission_id, status: :valid - ) do |entity| - entity.ext_permits.build( - submitter_id: - ) - end + ) + + DRMDB::ExtPermit.create!( + ext_id: entity.ext_id, + submitter_id: + ) end end end diff --git a/api/app/models/database/biosample/submitter.rb b/api/app/models/database/biosample/submitter.rb index daa530d2..e772071e 100644 --- a/api/app/models/database/biosample/submitter.rb +++ b/api/app/models/database/biosample/submitter.rb @@ -15,7 +15,6 @@ def submit(submission) BioSample::OperationHistory.create!( type: :fatal, summary: "[repository:CreateNewSubmission] Number of submission surpass the upper limit", - date: Time.current, submitter_id: ) end @@ -27,7 +26,6 @@ def submit(submission) BioSample::OperationHistory.create!( type: :error, summary: "[repository:CreateNewSubmission] rollback transaction", - date: Time.current, submitter_id: ) end @@ -126,22 +124,22 @@ def submit(submission) ) tx.after_commit do - DRMDB::ExtEntity.create!( + entity = DRMDB::ExtEntity.create!( acc_type: :sample, ref_name: sample.smp_id, status: :valid - ) do |entity| - entity.ext_permits.build( - submitter_id: - ) - end + ) + + DRMDB::ExtPermit.create!( + ext_id: entity.ext_id, + submitter_id: + ) end end BioSample::OperationHistory.create!( type: :info, summary: "[repository:CreateNewSubmission] Create new submission", - date: Time.current, submitter_id:, submission_id: ) diff --git a/api/app/models/database/dra/submitter.rb b/api/app/models/database/dra/submitter.rb index 648446b7..64554c9e 100644 --- a/api/app/models/database/dra/submitter.rb +++ b/api/app/models/database/dra/submitter.rb @@ -1,5 +1,97 @@ class Database::DRA::Submitter def submit(submission) - # do nothing + submitter_id = submission.validation.user.uid + user_id = SubmitterDB::Login.where(submitter_id:).pick(:usr_id) + + DRMDB::Record.transaction isolation: Rails.env.test? ? nil : :serializable do + serial = (DRMDB::Submission.where(submitter_id:).maximum(:serial) || 0) + 1 + + dra_submission = DRMDB::Submission.create!( + usr_id: user_id, + submitter_id:, + serial:, + create_date: Date.current + ) + + dra_submission.status_histories.create! status: :data_validated + + submission_group = dra_submission.create_submission_group!( + submit_version: 1, + valid: true, + serial_version: 1 + ) + + submission_id = "#{submitter_id}-#{serial.to_s.rjust(4, '0')}" + center_name = SubmitterDB::Organization.where(submitter_id:).pick(:center_name) + objs = submission.validation.objs.where(_id: %w(Submission Experiment Run Analysis)) + + acc_entities_assoc = objs.map { |obj| + DRMDB::AccessionEntity.create!( + alias: "#{submission_id}_#{obj._id}_0001", + center_name:, + acc_type: obj._id.downcase + ) + }.index_by(&:acc_type) + + objs.each do |obj| + parent_acc_entity = case obj._id + when "Submission" + nil + when "Study", "Sample" + acc_entities_assoc["DRA"] + when "Sample" + acc_entities_assoc["sample"] + when "Experiment" + acc_entities_assoc["sample"] || acc_entities_assoc["study"] + when "Run" + acc_entities_assoc["DRX"] + when "Analysis" + acc_entities_assoc["study"] + else + raise "must not happen" + end + + submission_group.accession_relations.create!( + accession_entity: acc_entity, + parent_accession_entity: parent_acc_entity + ) do |relation| + relation.build_meta_entity( + accession_entity: acc_entity, + meta_version: 1, + type: obj._id.downcase, + content: obj.file.download + ) + end + + ext_entity = DRMDB::ExtEntity.create!( + acc_type: :submission, + ref_name: "160053", + status: :valid + ) + + submission_group.ext_relations.create!( + acc_id: acc_entity.acc_id, + ext_id: ext_entity.ext_id + ) do |relation| + relation.build_ext_permit( + ext_id: ext_entity.ext_id, + submitter_id: + ) + end + end + + host, user, key_data = ENV.values_at("DRA_SSH_HOST", "DRA_SSH_USER", "DRA_SSH_KEY_DATA") + + Net::SSH.start host, user, key_data: [ key_data ] do |ssh| + ssh.exec! "sudo /usr/local/sbin/chroot-createdir.sh #{submitter_id} #{submission_id}" + end + + DRMDB::OperationHistory.create!( + type: :info, + summary: "Direct submission via repository", + usr_id: user_id, + submitter_id: + ) + end end end diff --git a/api/app/models/drmdb/accession_entity.rb b/api/app/models/drmdb/accession_entity.rb new file mode 100644 index 00000000..c5301bc1 --- /dev/null +++ b/api/app/models/drmdb/accession_entity.rb @@ -0,0 +1,12 @@ +class DRMDB::AccessionEntity < DRMDB::Record + self.table_name = "accession_entity" + + belongs_to :accession_relation, optional: true, class_name: "DRMDB::AccessionRelation", foreign_key: "acc_id", primary_key: "acc_id" + + enum :acc_type, { + submission: "DRA", + experiment: "DRX", + run: "DRR", + analysis: "DRZ" + } +end diff --git a/api/app/models/drmdb/accession_relation.rb b/api/app/models/drmdb/accession_relation.rb new file mode 100644 index 00000000..5813a388 --- /dev/null +++ b/api/app/models/drmdb/accession_relation.rb @@ -0,0 +1,10 @@ +class DRMDB::AccessionRelation < DRMDB::Record + self.table_name = "accession_relation" + + belongs_to :submission_group, class_name: "DRMDB::SubmissionGroup", foreign_key: "grp_id", primary_key: "grp_id" + belongs_to :accession_entity, class_name: "DRMDB::AccessionEntity", foreign_key: "acc_id", primary_key: "acc_id" + belongs_to :parent_accession_entity, class_name: "DRMDB::AccessionEntity", foreign_key: "p_acc_id", primary_key: "acc_id", optinal: true + + has_many :accession_entities, class_name: "DRMDB::AccessionEntity", foreign_key: "acc_id", primary_key: "acc_id" + has_one :meta_entity, class_name: "DRMDB::MetaEntity", foreign_key: "acc_id", primary_key: "acc_id" +end diff --git a/api/app/models/drmdb/batch.rb b/api/app/models/drmdb/batch.rb new file mode 100644 index 00000000..e1faff0e --- /dev/null +++ b/api/app/models/drmdb/batch.rb @@ -0,0 +1,3 @@ +class DRMDB::Batch < DRMDB::Record + self.table_name = 'batch' +end diff --git a/api/app/models/drmdb/ext_entity.rb b/api/app/models/drmdb/ext_entity.rb index d3299a51..2c535278 100644 --- a/api/app/models/drmdb/ext_entity.rb +++ b/api/app/models/drmdb/ext_entity.rb @@ -1,7 +1,7 @@ class DRMDB::ExtEntity < DRMDB::Record self.table_name = "ext_entity" - has_many :ext_permits, class_name: "DRMDB::ExtPermit", foreign_key: "ext_id" + belongs_to :ext_relation, optional: true, class_name: "DRMDB::ExtRelation", foreign_key: "ext_id", primary_key: "ext_id" enum :acc_type, { study: "PSUB", diff --git a/api/app/models/drmdb/ext_permit.rb b/api/app/models/drmdb/ext_permit.rb index 3bbbbcff..207280c5 100644 --- a/api/app/models/drmdb/ext_permit.rb +++ b/api/app/models/drmdb/ext_permit.rb @@ -1,3 +1,5 @@ class DRMDB::ExtPermit < DRMDB::Record self.table_name = "ext_permit" + + belongs_to :ext_relation, optional: true, class_name: "DRMDB::ExtRelation", foreign_key: "ext_id", primary_key: "ext_id" end diff --git a/api/app/models/drmdb/ext_relation.rb b/api/app/models/drmdb/ext_relation.rb new file mode 100644 index 00000000..5c1d315f --- /dev/null +++ b/api/app/models/drmdb/ext_relation.rb @@ -0,0 +1,8 @@ +class DRMDB::ExtRelation < DRMDB::Record + self.table_name = "ext_relation" + + belongs_to :submission_group, class_name: "DRMDB::SubmissionGroup", foreign_key: "grp_id", primary_key: "grp_id" + + has_many :ext_entities, class_name: "DRMDB::ExtEntity", foreign_key: "ext_id", primary_key: "ext_id" + has_one :ext_permit, class_name: "DRMDB::ExtPermit", foreign_key: "ext_id", primary_key: "ext_id" +end diff --git a/api/app/models/drmdb/meta_entity.rb b/api/app/models/drmdb/meta_entity.rb new file mode 100644 index 00000000..7f11fc0c --- /dev/null +++ b/api/app/models/drmdb/meta_entity.rb @@ -0,0 +1,7 @@ +class DRMDB::MetaEntity < DRMDB::Record + self.table_name = "meta_entity" + self.inheritance_column = nil + + belongs_to :accession_relation, class_name: "DRMDB::AccessionRelation", foreign_key: "acc_id", primary_key: "acc_id" + belongs_to :accession_entity, class_name: "DRMDB::AccessionEntity", foreign_key: "acc_id", primary_key: "acc_id" +end diff --git a/api/app/models/drmdb/operation_history.rb b/api/app/models/drmdb/operation_history.rb index c7ba3e36..413c8804 100644 --- a/api/app/models/drmdb/operation_history.rb +++ b/api/app/models/drmdb/operation_history.rb @@ -1,3 +1,8 @@ class DRMDB::OperationHistory < DRMDB::Record - self.table_name = "operation_history" + self.table_name = "operation_history" + self.inheritance_column = nil + + enum :type, { + info: 3 + } end diff --git a/api/app/models/drmdb/status_history.rb b/api/app/models/drmdb/status_history.rb index 26dfd910..8e9d4c34 100644 --- a/api/app/models/drmdb/status_history.rb +++ b/api/app/models/drmdb/status_history.rb @@ -1,3 +1,20 @@ class DRMDB::StatusHistory < DRMDB::Record self.table_name = "status_history" + + belongs_to :submission, class_name: "DRMDB::Submission", foreign_key: "sub_id" + + enum :status, { + new: 100, + meta_validated: 300, + data_validating: 380, + data_error: 390, + data_validated: 400, + acc_issued: 500, + private_complete: 700, + release_notifed: 750, + public_complete: 800, + cancel: 1000, + suppress: 1100, + killed: 1200 + }, prefix: true end diff --git a/api/app/models/drmdb/submission.rb b/api/app/models/drmdb/submission.rb index 62c86d91..cd65c299 100644 --- a/api/app/models/drmdb/submission.rb +++ b/api/app/models/drmdb/submission.rb @@ -1,3 +1,6 @@ class DRMDB::Submission < DRMDB::Record self.table_name = "submission" + + has_one :submission_group, class_name: "DRMDB::SubmissionGroup", foreign_key: "sub_id" + has_many :status_histories, class_name: "DRMDB::StatusHistory", foreign_key: "sub_id" end diff --git a/api/app/models/drmdb/submission_component.rb b/api/app/models/drmdb/submission_component.rb new file mode 100644 index 00000000..ee735c32 --- /dev/null +++ b/api/app/models/drmdb/submission_component.rb @@ -0,0 +1,5 @@ +class DRMDB::SubmissionComponent < DRMDB::Record + self.table_name = 'submission_component' + + belongs_to :submission_group, class_name: 'DRMDB::SubmissionGroup', foreign_key: 'grp_id', primary_key: 'grp_id' +end diff --git a/api/app/models/drmdb/submission_group.rb b/api/app/models/drmdb/submission_group.rb new file mode 100644 index 00000000..1605c090 --- /dev/null +++ b/api/app/models/drmdb/submission_group.rb @@ -0,0 +1,21 @@ +class DRMDB::SubmissionGroup < DRMDB::Record + self.table_name = "submission_group" + + belongs_to :submission, class_name: "DRMDB::Submission", foreign_key: "sub_id" + + has_many :submission_components, class_name: "DRMDB::SubmissionComponent", foreign_key: "grp_id", primary_key: "grp_id" + has_many :accession_relations, class_name: "DRMDB::AccessionRelation", foreign_key: "grp_id", primary_key: "grp_id" + has_many :ext_relations, class_name: "DRMDB::ExtRelation", foreign_key: "grp_id", primary_key: "grp_id" + + has_many :accession_entities, through: :accession_relations + has_many :meta_entities, through: :accession_relations + has_many :ext_entities, through: :ext_relations + has_many :ext_permits, through: :ext_relations + + class << self + def instance_method_already_implemented?(method_name) + return true if method_name == "valid?" + super + end + end +end diff --git a/api/db/bioproject_migrate/20240827022556_bioproject_init.rb b/api/db/bioproject_migrate/20240827022556_bioproject_init.rb index 33306b27..c5d54ab8 100644 --- a/api/db/bioproject_migrate/20240827022556_bioproject_init.rb +++ b/api/db/bioproject_migrate/20240827022556_bioproject_init.rb @@ -1,4 +1,4 @@ -class BioProjectInit < ActiveRecord::Migration[7.2] +class BioProjectInit < ActiveRecord::Migration[8.0] def change execute 'CREATE SCHEMA mass' diff --git a/api/db/biosample_migrate/20240829001416_biosample_init.rb b/api/db/biosample_migrate/20240829001416_biosample_init.rb index 911cdc1e..459e3f3e 100644 --- a/api/db/biosample_migrate/20240829001416_biosample_init.rb +++ b/api/db/biosample_migrate/20240829001416_biosample_init.rb @@ -1,4 +1,4 @@ -class BioSampleInit < ActiveRecord::Migration[7.2] +class BioSampleInit < ActiveRecord::Migration[8.0] def change execute 'CREATE SCHEMA mass' diff --git a/api/db/drasearch_migrate/20241023004659_dra_search_init.rb b/api/db/drasearch_migrate/20241023004659_dra_search_init.rb index c4de40c0..82d021a7 100644 --- a/api/db/drasearch_migrate/20241023004659_dra_search_init.rb +++ b/api/db/drasearch_migrate/20241023004659_dra_search_init.rb @@ -1,4 +1,4 @@ -class DRASearchInit < ActiveRecord::Migration[7.2] +class DRASearchInit < ActiveRecord::Migration[8.0] def change execute 'CREATE SCHEMA sra' diff --git a/api/db/drmdb_migrate/20240827024216_drmdb_init.rb b/api/db/drmdb_migrate/20240827024216_drmdb_init.rb index 65a59e2e..59914a01 100644 --- a/api/db/drmdb_migrate/20240827024216_drmdb_init.rb +++ b/api/db/drmdb_migrate/20240827024216_drmdb_init.rb @@ -1,22 +1,74 @@ -class DRMDBInit < ActiveRecord::Migration[7.2] +class DRMDBInit < ActiveRecord::Migration[8.0] def change execute 'CREATE SCHEMA mass' + create_table 'mass.accession_entity', id: false do |t| + t.bigint :acc_id, primary_key: true + + t.text :alias, null: false + t.text :center_name + t.text :acc_type, null: false + t.integer :acc_no + t.boolean :is_delete, null: false, default: false + end + + create_table 'mass.accession_relation', id: false do |t| + t.bigint :rel_id, primary_key: true + + t.bigint :grp_id, null: false + t.bigint :acc_id, null: false + t.bigint :p_acc_id + end + + create_table 'mass.batch', id: false do |t| + t.bigint :bat_id, primary_key: true + + t.integer :status, null: false + t.timestamp :updated, null: false, default: -> { "DATE_TRUNC('second', NOW())" } + t.bigint :main_meta_id, null: false + t.bigint :sub_meta_id, null: false + t.bigint :usr_id, null: false + t.integer :serial, null: false + t.text :machine + t.integer :priority, null: false, default: 50 + end + create_table 'mass.ext_entity', id: false do |t| - t.bigint :ext_id, primary_key: true + t.bigint :ext_id, primary_key: true + t.text :acc_type, null: false t.text :ref_name, null: false t.integer :status, null: false end create_table 'mass.ext_permit', id: false do |t| - t.bigint :per_id, primary_key: true + t.bigint :per_id, primary_key: true + t.bigint :ext_id, null: false t.text :submitter_id, null: false end + create_table 'mass.ext_relation', id: false do |t| + t.bigint :rel_id, primary_key: true + + t.bigint :grp_id, null: false + t.bigint :acc_id + t.bigint :ext_id, null: false + end + + create_table 'mass.meta_entity', id: false do |t| + t.bigint :meta_id, primary_key: true + + t.bigint :acc_id, null: false + t.integer :meta_version, null: false + t.text :type, null: false + t.text :content, null: false + t.timestamp :date, null: false, default: -> { "DATE_TRUNC('second', NOW())" } + end + create_table 'mass.operation_history', id: false do |t| - t.bigint :his_id, primary_key: true + t.bigint :his_id, primary_key: true + t.integer :type, null: false t.text :summary, null: false t.text :file_name @@ -34,7 +86,8 @@ def change end create_table 'mass.submission', id: false do |t| - t.bigint :sub_id, primary_key: true + t.bigint :sub_id, primary_key: true + t.bigint :usr_id, null: false t.text :submitter_id, null: false t.integer :serial, null: false @@ -46,5 +99,23 @@ def change t.date :finish_date t.text :note end + + create_table 'mass.submission_component', id: false do |t| + t.bigint :det_id, primary_key: true + + t.bigint :grp_id, null: false + t.text :field_key, null: false + t.text :field_value, null: false + end + + create_table 'mass.submission_group', id: false do |t| + t.bigint :grp_id, primary_key: true + + t.bigint :sub_id, null: false + t.integer :submit_version, null: false + t.timestamp :date, null: false, default: -> { "DATE_TRUNC('second', NOW())" } + t.boolean :valid, null: false + t.integer :serial_version + end end end diff --git a/api/db/drmdb_schema.rb b/api/db/drmdb_schema.rb index 559e2260..38786d4c 100644 --- a/api/db/drmdb_schema.rb +++ b/api/db/drmdb_schema.rb @@ -16,6 +16,31 @@ # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" + create_table "accession_entity", primary_key: "acc_id", force: :cascade do |t| + t.text "alias", null: false + t.text "center_name" + t.text "acc_type", null: false + t.integer "acc_no" + t.boolean "is_delete", default: false, null: false + end + + create_table "accession_relation", primary_key: "rel_id", force: :cascade do |t| + t.bigint "grp_id", null: false + t.bigint "acc_id", null: false + t.bigint "p_acc_id" + end + + create_table "batch", primary_key: "bat_id", force: :cascade do |t| + t.integer "status", null: false + t.datetime "updated", precision: nil, default: -> { "date_trunc('second'::text, now())" }, null: false + t.bigint "main_meta_id", null: false + t.bigint "sub_meta_id", null: false + t.bigint "usr_id", null: false + t.integer "serial", null: false + t.text "machine" + t.integer "priority", default: 50, null: false + end + create_table "ext_entity", primary_key: "ext_id", force: :cascade do |t| t.text "acc_type", null: false t.text "ref_name", null: false @@ -27,6 +52,20 @@ t.text "submitter_id", null: false end + create_table "ext_relation", primary_key: "rel_id", force: :cascade do |t| + t.bigint "grp_id", null: false + t.bigint "acc_id" + t.bigint "ext_id", null: false + end + + create_table "meta_entity", primary_key: "meta_id", force: :cascade do |t| + t.bigint "acc_id", null: false + t.integer "meta_version", null: false + t.text "type", null: false + t.text "content", null: false + t.datetime "date", precision: nil, default: -> { "date_trunc('second'::text, now())" }, null: false + end + create_table "operation_history", primary_key: "his_id", force: :cascade do |t| t.integer "type", null: false t.text "summary", null: false @@ -56,4 +95,18 @@ t.date "finish_date" t.text "note" end + + create_table "submission_component", primary_key: "det_id", force: :cascade do |t| + t.bigint "grp_id", null: false + t.text "field_key", null: false + t.text "field_value", null: false + end + + create_table "submission_group", primary_key: "grp_id", force: :cascade do |t| + t.bigint "sub_id", null: false + t.integer "submit_version", null: false + t.datetime "date", precision: nil, default: -> { "date_trunc('second'::text, now())" }, null: false + t.boolean "valid", null: false + t.integer "serial_version" + end end diff --git a/api/db/submitterdb_migrate/20240827023903_submitterdb_init.rb b/api/db/submitterdb_migrate/20240827023903_submitterdb_init.rb index f301e39c..b4947a37 100644 --- a/api/db/submitterdb_migrate/20240827023903_submitterdb_init.rb +++ b/api/db/submitterdb_migrate/20240827023903_submitterdb_init.rb @@ -1,4 +1,4 @@ -class SubmitterDBInit < ActiveRecord::Migration[7.2] +class SubmitterDBInit < ActiveRecord::Migration[8.0] def change execute 'CREATE SCHEMA mass' diff --git a/api/spec/factories/submitterdb_logins.rb b/api/spec/factories/submitterdb_logins.rb new file mode 100644 index 00000000..06c57e51 --- /dev/null +++ b/api/spec/factories/submitterdb_logins.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :submitterdb_login, class: "SubmitterDB::Login" do + password { "password" } + end +end diff --git a/api/spec/factories/submitterdb_organizations.rb b/api/spec/factories/submitterdb_organizations.rb new file mode 100644 index 00000000..b44d33eb --- /dev/null +++ b/api/spec/factories/submitterdb_organizations.rb @@ -0,0 +1,4 @@ +FactoryBot.define do + factory :submitterdb_organization, class: "SubmitterDB::Organization" +end + diff --git a/api/spec/models/database/dra/submitter_spec.rb b/api/spec/models/database/dra/submitter_spec.rb new file mode 100644 index 00000000..6e797677 --- /dev/null +++ b/api/spec/models/database/dra/submitter_spec.rb @@ -0,0 +1,129 @@ +require "rails_helper" + +RSpec.describe Database::DRA::Submitter, type: :model do + example do + submission = create(:submission, { + validation: build(:validation, :valid, { + user: build(:user, uid: "alice") + }) + }) + + create :obj, validation: submission.validation, _id: "Submission", validity: "valid" + create :obj, validation: submission.validation, _id: "Experiment", validity: "valid" + create :obj, validation: submission.validation, _id: "Run", validity: "valid" + create :obj, validation: submission.validation, _id: "Analysis", validity: "valid" + + user_id = create(:submitterdb_login, **{ + submitter_id: "alice" + }).usr_id + + create :submitterdb_organization, **{ + submitter_id: "alice", + center_name: "Wonderland Inc." + } + + expect(Net::SSH).to receive(:start) + + Database::DRA::Submitter.new.submit submission + + submission = DRMDB::Submission.sole + + expect(submission).to have_attributes( + usr_id: user_id, + submitter_id: "alice", + serial: 1 + ) + + expect(submission.status_histories.sole).to have_attributes( + status: "data_validated" + ) + + submission_group = DRMDB::SubmissionGroup.sole + + expect(submission_group).to have_attributes( + submit_version: 1, + valid: true, + serial_version: 1 + ) + + expect(submission_group.accession_entities).to contain_exactly( + have_attributes( + alias: "alice-0001_Submission_0001", + center_name: "Wonderland Inc.", + acc_type: "submission" + ), + have_attributes( + alias: "alice-0001_Experiment_0001", + center_name: "Wonderland Inc.", + acc_type: "experiment" + ), + have_attributes( + alias: "alice-0001_Run_0001", + center_name: "Wonderland Inc.", + acc_type: "run" + ), + have_attributes( + alias: "alice-0001_Analysis_0001", + center_name: "Wonderland Inc.", + acc_type: "analysis" + ) + ) + + expect(submission_group.meta_entities).to contain_exactly( + have_attributes( + meta_version: 1, + type: "submission" + ), + have_attributes( + meta_version: 1, + type: "experiment" + ), + have_attributes( + meta_version: 1, + type: "run" + ), + have_attributes( + meta_version: 1, + type: "analysis" + ) + ) + + expect(submission_group.ext_entities).to contain_exactly( + have_attributes( + acc_type: "submission", + ref_name: "160053", + status: "valid" + ), + have_attributes( + acc_type: "submission", + ref_name: "160053", + status: "valid" + ), + have_attributes( + acc_type: "submission", + ref_name: "160053", + status: "valid" + ), + have_attributes( + acc_type: "submission", + ref_name: "160053", + status: "valid" + ) + ) + + expect(submission_group.ext_permits).to contain_exactly( + have_attributes( + submitter_id: "alice" + ), + have_attributes( + submitter_id: "alice" + ), + have_attributes( + submitter_id: "alice" + ), + have_attributes( + submitter_id: "alice" + ) + ) + end +end