Class: Accessionable::Base

Inherits:
Object
  • Object
show all
Defined in:
app/models/accessionable/base.rb

Overview

Base class to control generating XML for accessioning with the ENA or EGA

See Also:

Direct Known Subclasses

Dac, Policy, Sample, Study, Submission

Defined Under Namespace

Classes: Tag

Constant Summary collapse

InvalidData =
Class.new(AccessionService::AccessionServiceError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(accession_number) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
# File 'app/models/accessionable/base.rb', line 8

def initialize(accession_number)
  @accession_number = accession_number

  time_now = Time.zone.now
  @date = time_now.strftime('%Y-%m-%dT%H:%M:%SZ')
  @date_short = time_now.strftime('%Y-%m-%d')
end

Instance Attribute Details

#accession_numberObject (readonly)

Returns the value of attribute accession_number.



6
7
8
# File 'app/models/accessionable/base.rb', line 6

def accession_number
  @accession_number
end

#dateObject (readonly)

Returns the value of attribute date.



6
7
8
# File 'app/models/accessionable/base.rb', line 6

def date
  @date
end

#date_shortObject (readonly)

Returns the value of attribute date_short.



6
7
8
# File 'app/models/accessionable/base.rb', line 6

def date_short
  @date_short
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'app/models/accessionable/base.rb', line 6

def name
  @name
end

Instance Method Details

#accessionable_idObject

Raises:

  • (NotImplementError)


58
59
60
# File 'app/models/accessionable/base.rb', line 58

def accessionable_id
  raise NotImplementError, 'abstract method'
end

#add_updated_event(user, classname, eventable) ⇒ Object



67
68
69
70
71
72
73
74
# File 'app/models/accessionable/base.rb', line 67

def add_updated_event(user, classname, eventable)
  eventable.events.create(
    created_by: user.,
    message: "#{classname} #{eventable.id} accession data has been updated by user #{user.}",
    content: 'accession number regenerated',
    of_interest_to: 'administrators'
  )
end

#aliasObject



33
34
35
# File 'app/models/accessionable/base.rb', line 33

def alias
  "#{name.gsub(/[^a-z\d]/i, '_')}-sc-#{accessionable_id}"
end

#center_nameObject



24
25
26
# File 'app/models/accessionable/base.rb', line 24

def center_name
  AccessionService::CenterName
end

#errorsObject



16
17
18
# File 'app/models/accessionable/base.rb', line 16

def errors
  []
end

#extract_accession_number(xmldoc) ⇒ Object



41
42
43
44
# File 'app/models/accessionable/base.rb', line 41

def extract_accession_number(xmldoc)
  element = xmldoc.root.elements["/RECEIPT/#{schema_type.upcase}"]
  accession_number = element && element.attributes['accession']
end

#extract_array_express_accession_number(xmldoc) ⇒ Object



46
47
48
49
# File 'app/models/accessionable/base.rb', line 46

def extract_array_express_accession_number(xmldoc)
  element = xmldoc.root.elements["/RECEIPT/#{schema_type.upcase}/EXT_ID[@type='ArrayExpress']"]
  accession_number = element && element.attributes['accession']
end

#file_nameObject



37
38
39
# File 'app/models/accessionable/base.rb', line 37

def file_name
  "#{self.alias}-#{date}.#{schema_type}.xml"
end

#label_scopeObject



76
77
78
# File 'app/models/accessionable/base.rb', line 76

def label_scope
  @label_scope ||= "metadata.#{self.class.name.split('::').last.downcase}.metadata"
end

#released?Boolean

Returns:

  • (Boolean)


62
63
64
65
# File 'app/models/accessionable/base.rb', line 62

def released?
  # Return false by default. Overidden by sample.
  false
end

#schema_typeObject



28
29
30
31
# File 'app/models/accessionable/base.rb', line 28

def schema_type
  # raise NotImplementedError, "abstract method"
  self.class.name.split('::').last.downcase
end

#update_accession_number!(_user, _accession_number) ⇒ Object

Raises:

  • (NotImplementedError)


51
52
53
# File 'app/models/accessionable/base.rb', line 51

def update_accession_number!(_user, _accession_number)
  raise NotImplementedError, 'abstract method'
end

#update_array_express_accession_number!(accession_number) ⇒ Object



55
56
# File 'app/models/accessionable/base.rb', line 55

def update_array_express_accession_number!(accession_number)
end

#xmlObject

Raises:

  • (NotImplementedError)


20
21
22
# File 'app/models/accessionable/base.rb', line 20

def xml
  raise NotImplementedError, 'abstract method'
end