Skip to content

Commit 6ca77c0

Browse files
committed
WIP
1 parent 3cc967d commit 6ca77c0

File tree

9 files changed

+148
-6
lines changed

9 files changed

+148
-6
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: 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
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

api/db/drmdb_migrate/20240827024216_drmdb_init.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,33 @@ def change
33
execute 'CREATE SCHEMA mass'
44

55
create_table 'mass.ext_entity', id: false do |t|
6-
t.bigint :ext_id, primary_key: true
6+
t.bigint :ext_id, primary_key: true
7+
78
t.text :acc_type, null: false
89
t.text :ref_name, null: false
910
t.integer :status, null: false
1011
end
1112

1213
create_table 'mass.ext_permit', id: false do |t|
13-
t.bigint :per_id, primary_key: true
14+
t.bigint :per_id, primary_key: true
15+
1416
t.bigint :ext_id, null: false
1517
t.text :submitter_id, null: false
1618
end
1719

20+
create_table 'mass.meta_entity', id: false do |t|
21+
t.bigint :meta_id, primary_key: true
22+
23+
t.bigint :acc_id, null: false
24+
t.integer :meta_version, null: false
25+
t.text :type, null: false
26+
t.text :content, null: false
27+
t.timestamp :date, null: false, default: -> { "DATE_TRUNC('second', NOW())" }
28+
end
29+
1830
create_table 'mass.operation_history', id: false do |t|
19-
t.bigint :his_id, primary_key: true
31+
t.bigint :his_id, primary_key: true
32+
2033
t.integer :type, null: false
2134
t.text :summary, null: false
2235
t.text :file_name
@@ -34,7 +47,8 @@ def change
3447
end
3548

3649
create_table 'mass.submission', id: false do |t|
37-
t.bigint :sub_id, primary_key: true
50+
t.bigint :sub_id, primary_key: true
51+
3852
t.bigint :usr_id, null: false
3953
t.text :submitter_id, null: false
4054
t.integer :serial, null: false
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)