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


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

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


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

def contact
  @contact
end

#responseObject (readonly)

Returns the value of attribute response


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

def response
  @response
end

#sampleObject (readonly)

Returns the value of attribute sample


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

def sample
  @sample
end

#serviceObject (readonly)

Returns the value of attribute service


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

def service
  @service
end

#userObject (readonly)

Returns the value of attribute user


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

def user
  @user
end

Instance Method Details

#payloadObject


64
65
66
# File 'lib/accession/accession/submission.rb', line 64

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

#postObject


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

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

#to_xmlObject


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

def to_xml
  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
  ) {
    xml.CONTACTS {
      xml.CONTACT(contact.to_h)
    }

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

#update_accession_numberObject


58
59
60
61
62
# File 'lib/accession/accession/submission.rb', line 58

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