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.


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

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


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

def accession_number
  @accession_number
end

#dateObject (readonly)

Returns the value of attribute date


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

def date
  @date
end

#date_shortObject (readonly)

Returns the value of attribute date_short


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

def date_short
  @date_short
end

#nameObject (readonly)

Returns the value of attribute name


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

def name
  @name
end

Instance Method Details

#accessionable_idObject

Raises:

  • (NotImplementError)

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

def accessionable_id
  raise NotImplementError, 'abstract method'
end

#add_updated_event(user, classname, eventable) ⇒ Object


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

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


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

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

#center_nameObject


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

def center_name
  AccessionService::CenterName
end

#errorsObject


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

def errors
  []
end

#extract_accession_number(xmldoc) ⇒ Object


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

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


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

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


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

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

#label_scopeObject


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

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

#released?Boolean

Returns:

  • (Boolean)

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

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

#schema_typeObject


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

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

#update_accession_number!(_user, _accession_number) ⇒ Object

Raises:

  • (NotImplementedError)

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

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

#update_array_express_accession_number!(accession_number) ⇒ Object


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

def update_array_express_accession_number!(accession_number)
end

#xmlObject

Raises:

  • (NotImplementedError)

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

def xml
  raise NotImplementedError, 'abstract method'
end