Class: Accessionable::Study

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

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

Constructor Details

#initialize(study) ⇒ Study

rubocop:todo Metrics/MethodLength



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/accessionable/study.rb', line 13

def initialize(study) # rubocop:todo Metrics/AbcSize
  @study = study
  data = {}

  study_title = study..study_study_title
  @name = study_title.blank? ? '' : study_title.gsub(/[^a-z\d]/i, '_')

  study_type = study..study_type.name
  @existing_study_type = study_type # the study type if validated is exactly the one submission need

  @study_title = @name
  @center_study_name = @study_title

  pid = study..study_project_id
  @study_id = pid.presence || '0'

  study_abstract = study..study_abstract
  @study_abstract = study_abstract if study_abstract.present?

  study_desc = study..study_description
  @description = study_desc if study_desc.present?

  @tags = []
  @tags << Tag.new(label_scope, 'ArrayExpress', nil) if study.for_array_express?
  super(study..study_ebi_accession_number)
end

Instance Attribute Details

#center_study_nameObject (readonly)

Returns the value of attribute center_study_name.



10
11
12
# File 'app/models/accessionable/study.rb', line 10

def center_study_name
  @center_study_name
end

#descriptionObject (readonly)

Returns the value of attribute description.



10
11
12
# File 'app/models/accessionable/study.rb', line 10

def description
  @description
end

#existing_study_typeObject (readonly)

Returns the value of attribute existing_study_type.



10
11
12
# File 'app/models/accessionable/study.rb', line 10

def existing_study_type
  @existing_study_type
end

#study_abstractObject (readonly)

Returns the value of attribute study_abstract.



10
11
12
# File 'app/models/accessionable/study.rb', line 10

def study_abstract
  @study_abstract
end

#study_titleObject (readonly)

Returns the value of attribute study_title.



10
11
12
# File 'app/models/accessionable/study.rb', line 10

def study_title
  @study_title
end

#tagsObject (readonly)

Returns the value of attribute tags.



10
11
12
# File 'app/models/accessionable/study.rb', line 10

def tags
  @tags
end

Instance Method Details

#accessionable_idObject

rubocop:enable Metrics/MethodLength



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

def accessionable_id
  @study.id
end

#errorsObject

rubocop:enable Metrics/MethodLength



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

def errors
  error_list = []
end

#protect?(service) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'app/models/accessionable/study.rb', line 79

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

#update_accession_number!(user, accession_number) ⇒ Object



83
84
85
86
87
88
# File 'app/models/accessionable/study.rb', line 83

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

#update_array_express_accession_number!(number) ⇒ Object



90
91
92
93
# File 'app/models/accessionable/study.rb', line 90

def update_array_express_accession_number!(number)
  @study..array_express_accession_number = number
  @study.save!
end

#xmlObject

rubocop:todo Metrics/MethodLength



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/models/accessionable/study.rb', line 47

def xml # rubocop:todo Metrics/AbcSize
  xml = Builder::XmlMarkup.new
  xml.instruct!
  xml.STUDY_SET('xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance') do
    xml.STUDY(alias: self.alias, accession: accession_number) do
      xml.DESCRIPTOR do
        xml.STUDY_TITLE study_title
        xml.STUDY_DESCRIPTION description
        xml.CENTER_PROJECT_NAME center_study_name
        xml.CENTER_NAME center_name
        xml.STUDY_ABSTRACT study_abstract

        xml.PROJECT_ID(accessionable_id || '0')
        study_type = existing_study_type
        if StudyType.include?(study_type)
          xml.STUDY_TYPE(existing_study_type: study_type)
        else
          xml.STUDY_TYPE(existing_study_type: ::Study::Other_type, new_study_type: study_type)
        end
      end
      xml.STUDY_ATTRIBUTES { tags.each { |tag| xml.STUDY_ATTRIBUTE { tag.build(xml) } } } if tags.present?
    end
  end
  xml.target!
end