@@ -114,14 +114,7 @@ def translate_roles(hash:)
114114 def process_org ( hash :)
115115 return hash unless hash . present? && hash [ :org_id ] . present?
116116
117- # Check if org already exists in the DB
118- existing_org = existing_org_from_hash ( hash )
119-
120- return finalize_org_hash ( hash , existing_org , false ) if existing_org . present?
121-
122- # Check if entered org has a valid ROR
123- # If so, allow creation
124- allow = validate_ror ( hash )
117+ hash , allow = OrgSelection ::HashToOrgService . process_org ( hash : hash )
125118
126119 # If org ROR cannot be validated, then contributor org is invalid
127120 # Only trigger flash during a real request (tests calling this method directly have no request object)
@@ -137,25 +130,6 @@ def process_org(hash:)
137130 finalize_org_hash ( hash , org , allow )
138131 end
139132
140- def parse_org_json ( hash )
141- JSON . parse ( hash [ :org_id ] ) rescue nil # rubocop:disable Style/RescueModifier
142- end
143-
144- def existing_org_from_hash ( hash )
145- # hash[:org_id] is a JSON string like:
146- # "{\"id\":1200,\"name\":\"Some Org\",\"ror\":\"https://ror.org/123\"}"
147- # So it must be parsed into a Ruby hash for HashToOrgService
148- parsed = parse_org_json ( hash )
149-
150- return nil unless parsed . present?
151-
152- # Returns org in DB if it exists
153- OrgSelection ::HashToOrgService . to_org (
154- hash : parsed . to_h ,
155- allow_create : false
156- )
157- end
158-
159133 def finalize_org_hash ( hash , org , allow )
160134 hash = remove_org_selection_params ( params_in : hash )
161135
@@ -166,20 +140,6 @@ def finalize_org_hash(hash, org, allow)
166140 hash
167141 end
168142
169- def validate_ror ( hash )
170- # Make external API call to ROR to find org with entered name
171- ror_result = ExternalApis ::RorService . search ( term : hash [ :org_name ] ) . first
172-
173- # Find ROR value in org hash
174- parsed_ror = parse_org_json ( hash ) [ 'ror' ]
175-
176- # If org hash ROR and external ROR values are the same
177- # The org is valid and has the correct ROR
178- return ror_result [ :ror ] == parsed_ror if ror_result . present? && parsed_ror . present?
179-
180- false
181- end
182-
183143 # When creating, just remove the ORCID if it was left blank
184144 def process_orcid_for_create ( hash :)
185145 return hash unless hash [ :identifiers_attributes ] . present?
0 commit comments