Skip to content

Commit 6857404

Browse files
committed
WIP
1 parent 3cc967d commit 6857404

File tree

17 files changed

+285
-7
lines changed

17 files changed

+285
-7
lines changed

api/Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ gem "rails", "~> 7.2.2"
66

77
gem "aws-sdk-s3"
88
gem "base62-rb"
9+
gem "bcrypt_pbkdf"
910
gem "bootsnap", require: false
11+
gem "ed25519"
1012
gem "fetch-api"
1113
gem "jb"
1214
gem "json"
1315
gem "metabobank_tools", github: "ddbj/metabobank_tools"
16+
gem "net-ssh"
1417
gem "noodles_gff", path: "../noodles_gff-rb"
1518
gem "openid_connect"
1619
gem "pagy"

api/Gemfile.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ GEM
121121
aws-eventstream (~> 1, >= 1.0.2)
122122
base62-rb (0.3.1)
123123
base64 (0.2.0)
124+
bcrypt_pbkdf (1.1.1)
125+
bcrypt_pbkdf (1.1.1-arm64-darwin)
124126
benchmark (0.3.0)
125127
bigdecimal (3.1.8)
126128
bindata (2.5.0)
@@ -143,6 +145,7 @@ GEM
143145
reline (>= 0.3.8)
144146
diff-lcs (1.5.1)
145147
drb (2.2.1)
148+
ed25519 (1.3.0)
146149
email_validator (2.2.4)
147150
activemodel
148151
erubi (1.13.0)
@@ -221,6 +224,7 @@ GEM
221224
timeout
222225
net-smtp (0.5.0)
223226
net-protocol
227+
net-ssh (7.3.0)
224228
nio4r (2.7.4)
225229
nokogiri (1.16.7-aarch64-linux)
226230
racc (~> 1.4)
@@ -430,15 +434,18 @@ PLATFORMS
430434
DEPENDENCIES
431435
aws-sdk-s3
432436
base62-rb
437+
bcrypt_pbkdf
433438
bootsnap
434439
brakeman
435440
climate_control
436441
debug
442+
ed25519
437443
factory_bot_rails
438444
fetch-api
439445
jb
440446
json
441447
metabobank_tools!
448+
net-ssh
442449
noodles_gff!
443450
openid_connect
444451
pagy
Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,72 @@
11
class Database::DRA::Submitter
2+
ACC_TYPES = {
3+
"Submission" => "DRA",
4+
"Experiment" => "DRX",
5+
"Run" => "DRR",
6+
"Analysis" => "DRZ"
7+
}
8+
29
def submit(submission)
3-
# do nothing
10+
submitter_id = submission.validation.user.uid
11+
user_id = SubmitterDB::Login.where(submitter_id:).pick(:usr_id)
12+
13+
DRMDB::Record.transaction isolation: Rails.env.test? ? nil : :serializable do
14+
serial = (DRMDB::Submission.where(submitter_id:).maximum(:serial) || 0) + 1
15+
16+
submission = DRMDB::Submission.create!(
17+
usr_id: user_id,
18+
submitter_id:,
19+
serial:,
20+
create_date: Date.current
21+
)
22+
23+
submission.status_histories.create!(
24+
status: :new
25+
)
26+
27+
DRMDB::OperationHistory.create!(
28+
type: :info,
29+
summary: "Status update to new",
30+
usr_id: user_id,
31+
serial:,
32+
submitter_id:
33+
)
34+
35+
submission_id = "#{submitter_id}-#{serial.to_s.rjust(4, '0')}"
36+
37+
DRMDB::ExtEntity.create!(
38+
acc_type: :submission,
39+
ref_name: submission_id,
40+
status: :inputting
41+
) do |entity|
42+
entity.ext_permits.build(
43+
submitter_id:
44+
)
45+
end
46+
47+
host, user, key_data = ENV.values_at("DRA_SSH_HOST", "DRA_SSH_USER", "DRA_SSH_KEY_DATA")
48+
49+
Net::SSH.start host, user, key_data: [ key_data ] do |ssh|
50+
ssh.exec! "sudo /usr/local/sbin/chroot-createdir.sh #{submitter_id} #{submission_id}"
51+
end
52+
53+
submission.validation.objs.where(_id: ACC_TYPES.keys).each do |obj|
54+
DRMDB::AccessionEntity.create!(
55+
alias: "#{submission_id}_#{obj._id}_0001",
56+
center_name: "National Institute of Genetics",
57+
acc_type: ACC_TYPES.fetch(obj._id),
58+
) do |accession|
59+
accession.create_accession_relation!(
60+
grp_id: 42
61+
) do |relation|
62+
relation.meta_entities.create!(
63+
meta_version: 0,
64+
type: obj._id.downcase,
65+
content: obj.file.download
66+
)
67+
end
68+
end
69+
end
70+
end
471
end
572
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class DRMDB::AccessionEntity < DRMDB::Record
2+
self.table_name = "accession_entity"
3+
self.inheritance_column = nil
4+
5+
belongs_to :accession_relation, class_name: "DRMDB::AccessionRelation", foreign_key: "acc_id"
6+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class DRMDB::AccessionRelation < DRMDB::Record
2+
self.table_name = "accession_relation"
3+
4+
belongs_to :submission_group, class_name: "DRMDB::SubmissionGroup", foreign_key: "grp_id"
5+
6+
has_one :meta_entity, class_name: "DRMDB::MetaEntity", foreign_key: "acc_id"
7+
has_many :accession_entities, class_name: "DRMDB::AccessionEntity", foreign_key: "acc_id"
8+
end

api/app/models/drmdb/ext_entity.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class DRMDB::ExtEntity < DRMDB::Record
22
self.table_name = "ext_entity"
33

4-
has_many :ext_permits, class_name: "DRMDB::ExtPermit", foreign_key: "ext_id"
4+
belongs_to :ext_relation, class_name: "DRMDB::ExtRelation", foreign_key: "ext_id"
55

66
enum :acc_type, {
77
study: "PSUB",

api/app/models/drmdb/ext_permit.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
class DRMDB::ExtPermit < DRMDB::Record
22
self.table_name = "ext_permit"
3+
4+
belongs_to :ext_relation, class_name: "DRMDB::ExtRelation", foreign_key: "ext_id"
35
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class DRMDB::ExtRelation < DRMDB::Record
2+
self.table_name = "ext_relation"
3+
4+
belongs_to :submission_group, class_name: "DRMDB::SubmissionGroup", foreign_key: "grp_id"
5+
6+
has_many :ext_entities, class_name: "DRMDB::ExtEntity", foreign_key: "ext_id"
7+
has_one :ext_permit, class_name: "DRMDB::ExtPermit", foreign_key: "ext_id"
8+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class DRMDB::MetaEntity < DRMDB::Record
2+
self.table_name = "meta_entity"
3+
4+
belongs_to :accession_relation, class_name: "DRMDB::AccessionRelation", foreign_key: "acc_id"
5+
end
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
class DRMDB::OperationHistory < DRMDB::Record
2-
self.table_name = "operation_history"
2+
self.table_name = "operation_history"
3+
self.inheritance_column = nil
4+
5+
enum :type, {
6+
info: 3
7+
}
38
end

0 commit comments

Comments
 (0)