Class: Accession::Submission

Inherits:
Object
  • Object
show all
Includes:
Accessionable, ActiveModel::Model
Defined in:
lib/accession/accession/submission.rb

Overview

Made up of a sample, user and service Used by Request to extract relevant information to send to appropriate accessioning service

Defined Under Namespace

Classes: Payload

Instance Attribute Summary collapse

Attributes included from Accessionable

#ebi_alias

Instance Method Summary collapse

Methods included from Accessionable

#date, #ebi_alias_datestamped, #filename, #schema_type, #to_file

Constructor Details

#initialize(user, sample) ⇒ Submission

Returns a new instance of Submission.



18
19
20
21
22
23
24
25
26
27
# File 'lib/accession/accession/submission.rb', line 18

def initialize(user, sample)
  @user = user
  @sample = sample
  @response = Accession::NullResponse.new

  if valid?
    @service = sample.service
    @contact = Contact.new(user)
  end
end

Instance Attribute Details

#contactObject (readonly)

Returns the value of attribute contact.



9
10
11
# File 'lib/accession/accession/submission.rb', line 9

def contact
  @contact
end

#responseObject (readonly)

Returns the value of attribute response.



9
10
11
# File 'lib/accession/accession/submission.rb', line 9

def response
  @response
end

#sampleObject (readonly)

Returns the value of attribute sample.



9
10
11
# File 'lib/accession/accession/submission.rb', line 9

def sample
  @sample
end

#serviceObject (readonly)

Returns the value of attribute service.



9
10
11
# File 'lib/accession/accession/submission.rb', line 9

def service
  @service
end

#userObject (readonly)

Returns the value of attribute user.



9
10
11
# File 'lib/accession/accession/submission.rb', line 9

def user
  @user
end

Instance Method Details

#payloadObject



57
58
59
# File 'lib/accession/accession/submission.rb', line 57

def payload
  @payload ||= Payload.new([self, sample])
end

#postObject



49
50
51
# File 'lib/accession/accession/submission.rb', line 49

def post
  @response = Accession::Request.post(self) if valid?
end

#to_xmlObject

rubocop:todo Metrics/AbcSize, Metrics/MethodLength



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/accession/accession/submission.rb', line 29

def to_xml # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
  xml = Builder::XmlMarkup.new
  xml.instruct!
  xml.SUBMISSION(
    XML_NAMESPACE,
    center_name: CENTER_NAME,
    broker_name: service.broker,
    alias: sample.ebi_alias_datestamped,
    submission_date: date
  ) do
    xml.CONTACTS { xml.CONTACT(contact.to_h) }

    xml.ACTIONS do
      xml.ACTION { xml.ADD(source: sample.filename, schema: sample.schema_type) }
      xml.ACTION { xml.tag!(service.visibility) }
    end
  end
  xml.target!
end

#update_accession_numberObject



53
54
55
# File 'lib/accession/accession/submission.rb', line 53

def update_accession_number
  sample.update_accession_number(response.accession_number) if accessioned?
end