Skip to content

Commit ae4719e

Browse files
committed
WIP
1 parent 3c2a648 commit ae4719e

File tree

9 files changed

+135
-9
lines changed

9 files changed

+135
-9
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.0"
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
@@ -120,6 +120,8 @@ GEM
120120
aws-eventstream (~> 1, >= 1.0.2)
121121
base62-rb (0.3.1)
122122
base64 (0.2.0)
123+
bcrypt_pbkdf (1.1.1)
124+
bcrypt_pbkdf (1.1.1-arm64-darwin)
123125
bigdecimal (3.1.8)
124126
bindata (2.5.0)
125127
bootsnap (1.18.4)
@@ -141,6 +143,7 @@ GEM
141143
reline (>= 0.3.8)
142144
diff-lcs (1.5.1)
143145
drb (2.2.1)
146+
ed25519 (1.3.0)
144147
email_validator (2.2.4)
145148
activemodel
146149
erubi (1.13.0)
@@ -218,6 +221,7 @@ GEM
218221
timeout
219222
net-smtp (0.5.0)
220223
net-protocol
224+
net-ssh (7.2.3)
221225
nio4r (2.7.3)
222226
nokogiri (1.16.7-aarch64-linux)
223227
racc (~> 1.4)
@@ -428,15 +432,18 @@ PLATFORMS
428432
DEPENDENCIES
429433
aws-sdk-s3
430434
base62-rb
435+
bcrypt_pbkdf
431436
bootsnap
432437
brakeman
433438
climate_control
434439
debug
440+
ed25519
435441
factory_bot_rails
436442
fetch-api
437443
jb
438444
json
439445
metabobank_tools!
446+
net-ssh
440447
noodles_gff!
441448
openid_connect
442449
pagy
Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,46 @@
11
class Database::DRA::Submitter
22
def submit(submission)
3-
# do nothing
3+
submitter_id = submission.validation.user.uid
4+
user_id = SubmitterDB::Login.where(submitter_id:).pick(:usr_id)
5+
6+
DRMDB::Record.transaction isolation: Rails.env.test? ? nil : :serializable do
7+
serial = (DRMDB::Submission.where(submitter_id:).maximum(:serial) || 0) + 1
8+
submission_id = "#{submitter_id}-#{serial.to_s.rjust(4, '0')}"
9+
10+
submission = DRMDB::Submission.create!(
11+
usr_id: user_id,
12+
submitter_id:,
13+
serial:,
14+
create_date: Date.current
15+
)
16+
17+
submission.status_histories.create!(
18+
status: :new
19+
)
20+
21+
DRMDB::OperationHistory.create!(
22+
type: :info,
23+
summary: "Status update to new",
24+
usr_id: user_id,
25+
serial:,
26+
submitter_id:
27+
)
28+
29+
DRMDB::ExtEntity.create!(
30+
acc_type: :submission,
31+
ref_name: submission_id,
32+
status: :inputting
33+
) do |entity|
34+
entity.ext_permits.build(
35+
submitter_id:
36+
)
37+
end
38+
39+
host, user, key_data = ENV.values_at("DRA_SSH_HOST", "DRA_SSH_USER", "DRA_SSH_KEY_DATA")
40+
41+
Net::SSH.start host, user, key_data: [ key_data ] do |ssh|
42+
ssh.exec! "sudo /usr/local/sbin/chroot-createdir.sh #{submitter_id} #{submission_id}"
43+
end
44+
end
445
end
546
end

api/app/models/drmdb/ext_entity.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ class DRMDB::ExtEntity < DRMDB::Record
44
has_many :ext_permits, class_name: "DRMDB::ExtPermit", foreign_key: "ext_id"
55

66
enum :acc_type, {
7-
submission: "1",
8-
study: "2",
9-
sample: "3",
10-
experiment: "4",
11-
run: "5",
12-
analysis: "6"
7+
study: "PSUB",
8+
sample: "SSUB",
9+
submission: "DRA"
1310
}, prefix: true
1411

1512
enum :status, {
16-
valid: 100
13+
inputting: 0,
14+
valid: 100
1715
}, prefix: true
1816
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
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
class DRMDB::StatusHistory < DRMDB::Record
22
self.table_name = "status_history"
3+
4+
belongs_to :submission, class_name: "DRMDB::Submission", foreign_key: "sub_id"
5+
6+
enum :status, {
7+
new: 100
8+
}, prefix: true
39
end

api/app/models/drmdb/submission.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
class DRMDB::Submission < DRMDB::Record
22
self.table_name = "submission"
3+
4+
has_many :status_histories, class_name: "DRMDB::StatusHistory", foreign_key: "sub_id"
35
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FactoryBot.define do
2+
factory :submitterdb_login, class: 'SubmitterDB::Login' do
3+
password { 'password' }
4+
end
5+
end
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe Database::DRA::Submitter, type: :model do
4+
example do
5+
submission = create(:submission, {
6+
validation: build(:validation, :valid, {
7+
user: build(:user, uid: 'alice')
8+
})
9+
})
10+
11+
user_id = create(:submitterdb_login, **{
12+
submitter_id: 'alice'
13+
}).usr_id
14+
15+
expect(Net::SSH).to receive(:start)
16+
17+
Database::DRA::Submitter.new.submit submission
18+
19+
submission = DRMDB::Submission.sole
20+
21+
expect(submission).to have_attributes(
22+
usr_id: user_id,
23+
submitter_id: 'alice',
24+
serial: 1
25+
)
26+
27+
status_history = DRMDB::StatusHistory.sole
28+
29+
expect(status_history).to have_attributes(
30+
sub_id: submission[:sub_id],
31+
status: 'new'
32+
)
33+
34+
operation_history = DRMDB::OperationHistory.sole
35+
36+
expect(operation_history).to have_attributes(
37+
type: 'info',
38+
summary: 'Status update to new',
39+
usr_id: user_id,
40+
serial: 1,
41+
submitter_id: 'alice'
42+
)
43+
44+
ext_entity = DRMDB::ExtEntity.sole
45+
46+
expect(ext_entity).to have_attributes(
47+
acc_type: 'submission',
48+
ref_name: 'alice-0001',
49+
status: 'inputting'
50+
)
51+
52+
ext_permit = DRMDB::ExtPermit.sole
53+
54+
expect(ext_permit).to have_attributes(
55+
ext_id: ext_entity.ext_id,
56+
submitter_id: 'alice'
57+
)
58+
end
59+
end

0 commit comments

Comments
 (0)