Class: ProjectMetadata

Inherits:
Object
  • Object
show all
Defined in:
app/models/project_metadata.rb

Constant Summary collapse

DOI_NOT_MINTED =
"DOI-NOT-MINTED"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProjectMetadata

Returns a new instance of ProjectMetadata.



9
10
11
12
13
# File 'app/models/project_metadata.rb', line 9

def initialize
  @departments = []
  @data_user_read_only = []
  @data_user_read_write = []
end

Instance Attribute Details

#approval_noteObject

Returns the value of attribute approval_note.



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

def approval_note
  @approval_note
end

#created_byObject

Returns the value of attribute created_by.



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

def created_by
  @created_by
end

#created_onObject

Returns the value of attribute created_on.



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

def created_on
  @created_on
end

#data_managerObject

Returns the value of attribute data_manager.



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

def data_manager
  @data_manager
end

#data_sponsorObject

Returns the value of attribute data_sponsor.



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

def data_sponsor
  @data_sponsor
end

#data_user_read_onlyObject

Returns the value of attribute data_user_read_only.



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

def data_user_read_only
  @data_user_read_only
end

#data_user_read_writeObject

Returns the value of attribute data_user_read_write.



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

def data_user_read_write
  @data_user_read_write
end

#departmentsObject

Returns the value of attribute departments.



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

def departments
  @departments
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#project_directoryObject

Returns the value of attribute project_directory.



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

def project_directory
  @project_directory
end

#project_idObject

Returns the value of attribute project_id.



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

def project_id
  @project_id
end

#project_purposeObject

Returns the value of attribute project_purpose.



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

def project_purpose
  @project_purpose
end

#schema_versionObject

Returns the value of attribute schema_version.



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

def schema_version
  @schema_version
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

#storage_capacityObject

Returns the value of attribute storage_capacity.



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

def storage_capacity
  @storage_capacity
end

#storage_performance_expectationsObject

Returns the value of attribute storage_performance_expectations.



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

def storage_performance_expectations
  @storage_performance_expectations
end

#submissionObject

Returns the value of attribute submission.



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

def submission
  @submission
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

#updated_byObject

Returns the value of attribute updated_by.



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

def updated_by
  @updated_by
end

#updated_onObject

Returns the value of attribute updated_on.



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

def updated_on
  @updated_on
end

Class Method Details

.new_from_hash(metadata_hash) ⇒ Object



15
16
17
18
19
# File 'app/models/project_metadata.rb', line 15

def self.new_from_hash()
  pm = ProjectMetadata.new
  pm.initialize_from_hash()
  pm
end

.new_from_params(metadata_params) ⇒ Object



21
22
23
24
25
# File 'app/models/project_metadata.rb', line 21

def self.new_from_params()
  pm = ProjectMetadata.new
  pm.initialize_from_params()
  pm
end

Instance Method Details

#initialize_from_hash(metadata_hash) ⇒ Object

rubocop:disable Metrics/MethodLength



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/project_metadata.rb', line 28

def initialize_from_hash()
  @title = [:title]
  @description = [:description]
  @status = [:status] if [:status]
  @data_sponsor = [:data_sponsor]
  @data_manager = [:data_manager]
  @departments = [:departments]
  @data_user_read_only = [:data_user_read_only] if [:data_user_read_only]
  @data_user_read_write = [:data_user_read_write] if [:data_user_read_write]

  @project_id = [:project_id] || ProjectMetadata::DOI_NOT_MINTED
  @project_purpose = [:project_purpose]
  @project_directory = [:project_directory]

  @storage_capacity = [:storage_capacity]
  @storage_performance_expectations = [:storage_performance_expectations]

  @created_by = [:created_by] if [:created_by]
  @created_on = [:created_on] if [:created_on]
  @updated_by = [:updated_by] if [:updated_by]
  @updated_on = [:updated_on] if [:updated_on]
  set_defaults
end

#initialize_from_params(params) ⇒ Object

Initializes the object with the values in the params (which is an ActionController::Parameters)



54
55
56
57
58
# File 'app/models/project_metadata.rb', line 54

def initialize_from_params(params)
  @data_user_read_only = ro_users_from_params(params)
  @data_user_read_write = rw_users_from_params(params)
  initialize_from_hash(params)
end

#ro_usersObject

Alias for ‘data_user_read_only`



92
93
94
# File 'app/models/project_metadata.rb', line 92

def ro_users
  @data_user_read_only
end

#rw_usersObject

Alias for ‘data_user_read_write`



97
98
99
# File 'app/models/project_metadata.rb', line 97

def rw_users
  @data_user_read_write
end

#update_with_params(params, current_user) ⇒ Object

Updates the object with the values in the params (which is an ActionController::Parameters) Notice how we only update values that come in the params and don’t change the values that don’t come as part of the params rubocop:disable Metrics/MethodLength



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/models/project_metadata.rb', line 64

def update_with_params(params, current_user)
  set_value(params, "title")
  set_value(params, "description")
  set_value(params, "status")
  set_value(params, "data_sponsor")
  set_value(params, "data_manager")
  set_value(params, "departments")
  set_value(params, "project_id")
  set_value(params, "project_purpose")
  calculate_project_directory(params)

  if params["data_user_counter"].present?
    @data_user_read_only = ro_users_from_params(params)
    @data_user_read_write = rw_users_from_params(params)
  end

  update_storage_capacity(params)
  update_storage_performance_expectations
  update_approval_note(params, current_user)
  @submission = params[:submission] if params[:submission]

  # Fields that come from the edit form
  @updated_by = current_user.uid
  @updated_on = Time.current.in_time_zone("America/New_York").iso8601
end