Class: Accessionable::Dac

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

Overview

Represents a Data Access Committee who co-ordinate access to managed (EGA) studies. Should ideally be a completely separate record from Study but currently just a group of attributes in the Study::Metadata

Constant Summary

Constants inherited from Base

Base::InvalidData

Instance Attribute Summary collapse

Attributes inherited from Base

#accession_number, #date, #date_short, #name

Instance Method Summary collapse

Methods inherited from Base

#add_updated_event, #alias, #center_name, #extract_accession_number, #extract_array_express_accession_number, #file_name, #label_scope, #released?, #schema_type, #update_array_express_accession_number!

Constructor Details

#initialize(study) ⇒ Dac

Returns a new instance of Dac


6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/models/accessionable/dac.rb', line 6

def initialize(study)
  @study = study
  @name = study.dac_refname
  @contacts = study.data_access_contacts.map do |contact|
    {
      email: contact.email,
      name: contact.name,
      organisation: AccessionService::CenterName
    }
  end

  super(study.dac_accession_number)
end

Instance Attribute Details

#contactsObject (readonly)

Returns the value of attribute contacts


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

def contacts
  @contacts
end

Instance Method Details

#accessionable_idObject


56
57
58
# File 'app/models/accessionable/dac.rb', line 56

def accessionable_id
  @study.id
end

#errorsObject


20
21
22
23
24
25
26
# File 'app/models/accessionable/dac.rb', line 20

def errors
  [].tap do |errors|
    if @contacts.empty?
      errors << 'Data Access Contacts Empty. Please add a contact'
    end
  end
end

#protect?(service) ⇒ Boolean

Returns:

  • (Boolean)

52
53
54
# File 'app/models/accessionable/dac.rb', line 52

def protect?(service)
  service.dac_visibility(@study) == AccessionService::Protect
end

#update_accession_number!(user, accession_number) ⇒ Object


45
46
47
48
49
50
# File 'app/models/accessionable/dac.rb', line 45

def update_accession_number!(user, accession_number)
  @accession_number = accession_number
  add_updated_event(user, "DAC for Study #{@study.id}", @study) if @accession_number
  @study..ega_dac_accession_number = accession_number
  @study.save!
end

#xmlObject


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/accessionable/dac.rb', line 28

def xml
  xml = Builder::XmlMarkup.new
  xml.instruct!
  xml.DAC_SET('xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance') {
    xml.DAC(alias: self.alias, accession: accession_number, center_name: center_name) {
      xml.CONTACTS {
        contacts.each do |contact|
          xml.CONTACT(name: contact[:name],
                      email: contact[:email],
                      organisation: contact[:organisation])
        end
      }
    }
  }
  xml.target!
end