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.
-
#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.
76 77 78 79 80 |
# File 'app/models/project_metadata.rb', line 76 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.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def approval_note @approval_note end |
#created_by ⇒ Object
Returns the value of attribute created_by.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def created_by @created_by end |
#created_on ⇒ Object
Returns the value of attribute created_on.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def created_on @created_on end |
#data_manager ⇒ Object
Returns the value of attribute data_manager.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def data_manager @data_manager end |
#data_sponsor ⇒ Object
Returns the value of attribute data_sponsor.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def data_sponsor @data_sponsor end |
#data_use_agreement ⇒ Object
Returns the value of attribute data_use_agreement.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def data_use_agreement @data_use_agreement end |
#data_user_read_only ⇒ Object
Returns the value of attribute data_user_read_only.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def data_user_read_only @data_user_read_only end |
#data_user_read_write ⇒ Object
Returns the value of attribute data_user_read_write.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def data_user_read_write @data_user_read_write end |
#departments ⇒ Object
Returns the value of attribute departments.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def departments @departments end |
#description ⇒ Object
Returns the value of attribute description.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def description @description end |
#globus_request ⇒ Object
Returns the value of attribute globus_request.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def globus_request @globus_request end |
#hpc ⇒ Object
Returns the value of attribute hpc.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def hpc @hpc end |
#project_directory ⇒ Object
Returns the value of attribute project_directory.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def project_directory @project_directory end |
#project_directory_protocol ⇒ Object
Returns the value of attribute project_directory_protocol.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def project_directory_protocol @project_directory_protocol end |
#project_id ⇒ Object
Returns the value of attribute project_id.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def project_id @project_id end |
#project_purpose ⇒ Object
Returns the value of attribute project_purpose.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def project_purpose @project_purpose end |
#project_visibility ⇒ Object
Returns the value of attribute project_visibility.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def project_visibility @project_visibility end |
#provisional ⇒ Object
Returns the value of attribute provisional.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def provisional @provisional end |
#resource_type ⇒ Object
Returns the value of attribute resource_type.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def resource_type @resource_type end |
#schema_version ⇒ Object
Returns the value of attribute schema_version.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def schema_version @schema_version end |
#smb_request ⇒ Object
Returns the value of attribute smb_request.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def smb_request @smb_request end |
#status ⇒ Object
Returns the value of attribute status.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def status @status end |
#storage_capacity ⇒ Object
Returns the value of attribute storage_capacity.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def storage_capacity @storage_capacity end |
#storage_performance_expectations ⇒ Object
Returns the value of attribute storage_performance_expectations.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def storage_performance_expectations @storage_performance_expectations end |
#submission ⇒ Object
Returns the value of attribute submission.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def submission @submission end |
#title ⇒ Object
Returns the value of attribute title.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def title @title end |
#updated_by ⇒ Object
Returns the value of attribute updated_by.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 def updated_by @updated_by end |
#updated_on ⇒ Object
Returns the value of attribute updated_on.
61 62 63 |
# File 'app/models/project_metadata.rb', line 61 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 36 37 38 |
# File 'app/models/project_metadata.rb', line 33 def self.default_globus_request { requested: false, approved: false } 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.
49 50 51 |
# File 'app/models/project_metadata.rb', line 49 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.
41 42 43 44 45 46 |
# File 'app/models/project_metadata.rb', line 41 def self.default_smb_request { requested: false, approved: false } end |
.new_from_hash(metadata_hash) ⇒ Object
82 83 84 85 86 |
# File 'app/models/project_metadata.rb', line 82 def self.new_from_hash() pm = ProjectMetadata.new pm.initialize_from_hash() pm end |
.new_from_params(metadata_params) ⇒ Object
88 89 90 91 92 |
# File 'app/models/project_metadata.rb', line 88 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
54 55 56 57 58 59 |
# File 'app/models/project_metadata.rb', line 54 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
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 130 131 132 133 134 |
# File 'app/models/project_metadata.rb', line 98 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 @hpc = [:hpc] || self.class.default_hpc @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 @globus_request = [:globus_request] || self.class.default_globus_request @smb_request = [:smb_request] || self.class.default_smb_request @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)
141 142 143 144 145 |
# File 'app/models/project_metadata.rb', line 141 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`
179 180 181 |
# File 'app/models/project_metadata.rb', line 179 def ro_users @data_user_read_only end |
#rw_users ⇒ Object
Alias for ‘data_user_read_write`
184 185 186 |
# File 'app/models/project_metadata.rb', line 184 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
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'app/models/project_metadata.rb', line 151 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 |