Class: ProjectMetadata
- Inherits:
-
Object
- Object
- ProjectMetadata
- Defined in:
- app/models/project_metadata.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- DOI_NOT_MINTED =
"DOI-NOT-MINTED"
Instance Attribute Summary collapse
-
#approval_note ⇒ Object
Returns the value of attribute approval_note.
-
#created_by ⇒ Object
Returns the value of attribute created_by.
-
#created_on ⇒ Object
Returns the value of attribute created_on.
-
#data_manager ⇒ Object
Returns the value of attribute data_manager.
-
#data_sponsor ⇒ Object
Returns the value of attribute data_sponsor.
-
#data_use_agreement ⇒ Object
Returns the value of attribute data_use_agreement.
-
#data_user_read_only ⇒ Object
Returns the value of attribute data_user_read_only.
-
#data_user_read_write ⇒ Object
Returns the value of attribute data_user_read_write.
-
#departments ⇒ Object
Returns the value of attribute departments.
-
#description ⇒ Object
Returns the value of attribute description.
-
#globus_request ⇒ Object
Returns the value of attribute globus_request.
-
#hpc ⇒ Object
Returns the value of attribute hpc.
-
#number_of_files ⇒ Object
Returns the value of attribute number_of_files.
-
#project_directory ⇒ Object
Returns the value of attribute project_directory.
-
#project_directory_protocol ⇒ Object
Returns the value of attribute project_directory_protocol.
-
#project_id ⇒ Object
Returns the value of attribute project_id.
-
#project_purpose ⇒ Object
Returns the value of attribute project_purpose.
-
#project_visibility ⇒ Object
Returns the value of attribute project_visibility.
-
#provisional ⇒ Object
Returns the value of attribute provisional.
-
#resource_type ⇒ Object
Returns the value of attribute resource_type.
-
#schema_version ⇒ Object
Returns the value of attribute schema_version.
-
#smb_request ⇒ Object
Returns the value of attribute smb_request.
-
#status ⇒ Object
Returns the value of attribute status.
-
#storage_capacity ⇒ Object
Returns the value of attribute storage_capacity.
-
#storage_performance_expectations ⇒ Object
Returns the value of attribute storage_performance_expectations.
-
#submission ⇒ Object
Returns the value of attribute submission.
-
#title ⇒ Object
Returns the value of attribute title.
-
#updated_by ⇒ Object
Returns the value of attribute updated_by.
-
#updated_on ⇒ Object
Returns the value of attribute updated_on.
Class Method Summary collapse
-
.default_data_use_agreement ⇒ String
The default data use agreement.
-
.default_directory_protocol ⇒ String
The default directory protocol.
-
.default_globus_request ⇒ Hash
The default globus request Hash entries.
-
.default_hpc ⇒ String
The default HPC value.
-
.default_project_visibility ⇒ String
The default project visibility.
-
.default_provisionality ⇒ Boolean
The default value for whether a project is provisional.
-
.default_resource_type ⇒ String
The default project resource type.
-
.default_smb_request ⇒ Hash
The default Samba/SMB request Hash entries.
- .new_from_hash(metadata_hash) ⇒ Object
- .new_from_params(metadata_params) ⇒ Object
-
.safe_directory(directory) ⇒ Object
Ensure that the project directory is a valid path.
Instance Method Summary collapse
-
#initialize ⇒ ProjectMetadata
constructor
A new instance of ProjectMetadata.
-
#initialize_from_hash(metadata_hash) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/MethodLength rubocop:disable Metrics/PerceivedComplexity.
-
#initialize_from_params(params) ⇒ Object
Initializes the object with the values in the params (which is an ActionController::Parameters).
-
#ro_users ⇒ Object
Alias for ‘data_user_read_only`.
-
#rw_users ⇒ Object
Alias for ‘data_user_read_write`.
-
#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.
Constructor Details
#initialize ⇒ ProjectMetadata
Returns a new instance of ProjectMetadata.
71 72 73 74 75 |
# File 'app/models/project_metadata.rb', line 71 def initialize @departments = [] @data_user_read_only = [] @data_user_read_write = [] end |
Instance Attribute Details
#approval_note ⇒ Object
Returns the value of attribute approval_note.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def approval_note @approval_note end |
#created_by ⇒ Object
Returns the value of attribute created_by.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def created_by @created_by end |
#created_on ⇒ Object
Returns the value of attribute created_on.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def created_on @created_on end |
#data_manager ⇒ Object
Returns the value of attribute data_manager.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def data_manager @data_manager end |
#data_sponsor ⇒ Object
Returns the value of attribute data_sponsor.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def data_sponsor @data_sponsor end |
#data_use_agreement ⇒ Object
Returns the value of attribute data_use_agreement.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def data_use_agreement @data_use_agreement end |
#data_user_read_only ⇒ Object
Returns the value of attribute data_user_read_only.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def data_user_read_only @data_user_read_only end |
#data_user_read_write ⇒ Object
Returns the value of attribute data_user_read_write.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def data_user_read_write @data_user_read_write end |
#departments ⇒ Object
Returns the value of attribute departments.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def departments @departments end |
#description ⇒ Object
Returns the value of attribute description.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def description @description end |
#globus_request ⇒ Object
Returns the value of attribute globus_request.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def globus_request @globus_request end |
#hpc ⇒ Object
Returns the value of attribute hpc.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def hpc @hpc end |
#number_of_files ⇒ Object
Returns the value of attribute number_of_files.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def number_of_files @number_of_files end |
#project_directory ⇒ Object
Returns the value of attribute project_directory.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def project_directory @project_directory end |
#project_directory_protocol ⇒ Object
Returns the value of attribute project_directory_protocol.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def project_directory_protocol @project_directory_protocol end |
#project_id ⇒ Object
Returns the value of attribute project_id.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def project_id @project_id end |
#project_purpose ⇒ Object
Returns the value of attribute project_purpose.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def project_purpose @project_purpose end |
#project_visibility ⇒ Object
Returns the value of attribute project_visibility.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def project_visibility @project_visibility end |
#provisional ⇒ Object
Returns the value of attribute provisional.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def provisional @provisional end |
#resource_type ⇒ Object
Returns the value of attribute resource_type.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def resource_type @resource_type end |
#schema_version ⇒ Object
Returns the value of attribute schema_version.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def schema_version @schema_version end |
#smb_request ⇒ Object
Returns the value of attribute smb_request.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def smb_request @smb_request end |
#status ⇒ Object
Returns the value of attribute status.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def status @status end |
#storage_capacity ⇒ Object
Returns the value of attribute storage_capacity.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def storage_capacity @storage_capacity end |
#storage_performance_expectations ⇒ Object
Returns the value of attribute storage_performance_expectations.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def storage_performance_expectations @storage_performance_expectations end |
#submission ⇒ Object
Returns the value of attribute submission.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def submission @submission end |
#title ⇒ Object
Returns the value of attribute title.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def title @title end |
#updated_by ⇒ Object
Returns the value of attribute updated_by.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def updated_by @updated_by end |
#updated_on ⇒ Object
Returns the value of attribute updated_on.
55 56 57 |
# File 'app/models/project_metadata.rb', line 55 def updated_on @updated_on end |
Class Method Details
.default_data_use_agreement ⇒ String
Returns The default data use agreement.
28 29 30 |
# File 'app/models/project_metadata.rb', line 28 def self.default_data_use_agreement "No" end |
.default_directory_protocol ⇒ String
Returns The default directory protocol.
8 9 10 |
# File 'app/models/project_metadata.rb', line 8 def self.default_directory_protocol "NFS" end |
.default_globus_request ⇒ Hash
Returns The default globus request Hash entries.
33 34 35 |
# File 'app/models/project_metadata.rb', line 33 def self.default_globus_request "No" end |
.default_hpc ⇒ String
Returns The default HPC value.
18 19 20 |
# File 'app/models/project_metadata.rb', line 18 def self.default_hpc "No" end |
.default_project_visibility ⇒ String
Returns The default project visibility.
23 24 25 |
# File 'app/models/project_metadata.rb', line 23 def self.default_project_visibility "Restricted" end |
.default_provisionality ⇒ Boolean
Returns The default value for whether a project is provisional.
43 44 45 |
# File 'app/models/project_metadata.rb', line 43 def self.default_provisionality false end |
.default_resource_type ⇒ String
Returns The default project resource type.
13 14 15 |
# File 'app/models/project_metadata.rb', line 13 def self.default_resource_type "TigerData Project" end |
.default_smb_request ⇒ Hash
Returns The default Samba/SMB request Hash entries.
38 39 40 |
# File 'app/models/project_metadata.rb', line 38 def self.default_smb_request "No" end |
.new_from_hash(metadata_hash) ⇒ Object
77 78 79 80 81 |
# File 'app/models/project_metadata.rb', line 77 def self.new_from_hash() pm = ProjectMetadata.new pm.initialize_from_hash() pm end |
.new_from_params(metadata_params) ⇒ Object
83 84 85 86 87 |
# File 'app/models/project_metadata.rb', line 83 def self.new_from_params() pm = ProjectMetadata.new pm.initialize_from_params() pm end |
.safe_directory(directory) ⇒ Object
Ensure that the project directory is a valid path
48 49 50 51 52 53 |
# File 'app/models/project_metadata.rb', line 48 def self.safe_directory(directory) return "" if directory.nil? # only alphanumeric characters and / directory.strip.gsub(/[^A-Za-z\d\/]/, "-") end |
Instance Method Details
#initialize_from_hash(metadata_hash) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/MethodLength rubocop:disable Metrics/PerceivedComplexity
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/models/project_metadata.rb', line 93 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 = ProjectMetadata.safe_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] # NOTE: The following attributes are required by the 0.8 XML schema @number_of_files = [:number_of_files] || "Less than 10,000" @hpc = [:hpc] || self.class.default_hpc @globus_request = [:globus] || self.class.default_globus_request @smb_request = [:smb] || self.class.default_smb_request @data_use_agreement = [:data_use_agreement] || self.class.default_data_use_agreement @project_visibility = [:project_visibility] || self.class.default_project_visibility @resource_type = [:resource_type] || self.class.default_resource_type @provisional = [:provisional] || self.class.default_provisionality set_defaults end |
#initialize_from_params(params) ⇒ Object
Initializes the object with the values in the params (which is an ActionController::Parameters)
136 137 138 139 140 |
# File 'app/models/project_metadata.rb', line 136 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_users ⇒ Object
Alias for ‘data_user_read_only`
174 175 176 |
# File 'app/models/project_metadata.rb', line 174 def ro_users @data_user_read_only end |
#rw_users ⇒ Object
Alias for ‘data_user_read_write`
179 180 181 |
# File 'app/models/project_metadata.rb', line 179 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
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'app/models/project_metadata.rb', line 146 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 |