Class: Accessionable::Policy

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

Overview

Represents policy information about who will have access to information associatied with manages (EGA) studies Comprised of a DAC and a URL. 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) ⇒ Policy

Returns a new instance of Policy.



10
11
12
13
14
15
16
17
18
19
20
# File 'app/models/accessionable/policy.rb', line 10

def initialize(study)
  @study = study

  @name = "Policy for study - #{study.name} - ##{study.id}"
  @policy_url = study..dac_policy
  @title = study..dac_policy_title

  # @dac_refname = study.dac_refname
  @dac_accession_number = study.dac_accession_number
  super(study.policy_accession_number)
end

Instance Attribute Details

#dac_accession_numberObject (readonly)

Returns the value of attribute dac_accession_number.



8
9
10
# File 'app/models/accessionable/policy.rb', line 8

def dac_accession_number
  @dac_accession_number
end

#policy_urlObject (readonly)

Returns the value of attribute policy_url.



8
9
10
# File 'app/models/accessionable/policy.rb', line 8

def policy_url
  @policy_url
end

#titleObject (readonly)

Returns the value of attribute title.



8
9
10
# File 'app/models/accessionable/policy.rb', line 8

def title
  @title
end

Instance Method Details

#accessionable_idObject



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

def accessionable_id
  @study.id
end

#errorsObject



22
23
24
25
26
27
28
# File 'app/models/accessionable/policy.rb', line 22

def errors
  [].tap do |errors|
    unless @dac_accession_number
      errors << 'DAC Accession number not found. Please get an accession number for the DAC.'
    end
  end
end

#protect?(service) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#update_accession_number!(user, accession_number) ⇒ Object



43
44
45
46
47
48
# File 'app/models/accessionable/policy.rb', line 43

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

#xmlObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/accessionable/policy.rb', line 30

def xml
  xml = Builder::XmlMarkup.new
  xml.instruct!
  xml.POLICY_SET('xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance') do
    xml.POLICY(alias: self.alias, accession: accession_number, center_name: center_name) do
      xml.TITLE title
      xml.DAC_REF(accession: dac_accession_number)
      xml.POLICY_FILE policy_url
    end
  end
  xml.target!
end