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


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

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


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

def dac_accession_number
  @dac_accession_number
end

#policy_urlObject (readonly)

Returns the value of attribute policy_url


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

def policy_url
  @policy_url
end

#titleObject (readonly)

Returns the value of attribute title


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

def title
  @title
end

Instance Method Details

#accessionable_idObject


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

def accessionable_id
  @study.id
end

#errorsObject


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

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

#protect?(service) ⇒ Boolean

Returns:

  • (Boolean)

48
49
50
# File 'app/models/accessionable/policy.rb', line 48

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

#update_accession_number!(user, accession_number) ⇒ Object


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

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


26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/accessionable/policy.rb', line 26

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