Skip to content

Commit

Permalink
Moves method to remove system profiles to data import helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
shelleydoljack committed Feb 13, 2024
1 parent 9d519cd commit 48ca18c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
32 changes: 18 additions & 14 deletions tasks/helpers/data_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,25 +128,29 @@ def profile_associations_put(payload, master, detail)

def pull_action_profiles
hash = @@folio_request.get('/data-import-profiles/actionProfiles?withRelations=true&limit=999')
trim_default_data(hash, 'actionProfiles')
trim_hash(hash, 'actionProfiles')
remove_system_profiles(hash, 'actionProfiles')
hash.to_json
end

def pull_job_profiles
hash = @@folio_request.get('/data-import-profiles/jobProfiles?limit=999')
trim_default_data(hash, 'jobProfiles')
trim_hash(hash, 'jobProfiles')
remove_system_profiles(hash, 'jobProfiles')
hash.to_json
end

def pull_mapping_profiles
hash = @@folio_request.get('/data-import-profiles/mappingProfiles?withRelations=true&limit=999')
trim_default_data(hash, 'mappingProfiles')
trim_hash(hash, 'mappingProfiles')
remove_system_profiles(hash, 'mappingProfiles')
hash.to_json
end

def pull_match_profiles
hash = @@folio_request.get('/data-import-profiles/matchProfiles?withRelations=true&limit=999')
trim_default_data(hash, 'matchProfiles')
trim_hash(hash, 'matchProfiles')
remove_system_profiles(hash, 'matchProfiles')
hash.to_json
end

Expand Down Expand Up @@ -214,16 +218,16 @@ def profile_associations_load(payload, master, detail)
end
end

def remove_values(hash, key_name)
hash.each do |k, v|
if k == key_name
hash.delete(k)
elsif v.is_a?(Hash)
remove_values(v, key_name)
elsif v.is_a?(Array)
v.flatten.each { |x| remove_values(x, key_name) if x.is_a?(Hash) }
end
def remove_system_profiles(hash, name)
new_hash = []
hash[name].each do |obj|
next if obj['userInfo']['userName'] == 'System'

obj.delete('parentProfiles')
obj.delete('childProfiles')
obj.delete('userInfo')
new_hash.append(obj)
end
hash
hash[name] = new_hash
end
end
19 changes: 0 additions & 19 deletions tasks/helpers/folio_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,4 @@ def trim_hash(hash, name)
hash.delete('resultInfo')
hash
end

def trim_default_data(hash, name)
new_hash = []
hash[name].each do |obj|
next if obj['userInfo']['userName'] == 'System'

obj.delete('childOf')
obj.delete('grantedTo')
obj.delete('dummy')
obj.delete('deprecated')
obj.delete('authentication')
obj.delete('parentProfiles')
obj.delete('childProfiles')
new_hash.append(obj)
end
hash.delete('totalRecords')
hash.delete('resultInfo')
hash[name] = new_hash
end
end

0 comments on commit 48ca18c

Please sign in to comment.