Module: Cul::Hydra::RisearchMembers::ClassMethods
- Included in:
- Cul::Hydra::RisearchMembers
- Defined in:
- lib/cul_hydra/risearch_members.rb
Instance Method Summary collapse
-
#get_all_pids_for_identifier(identifier) ⇒ Object
Returns the pids of ALL objects found with the given identifier.
- #get_direct_member_count(pid, flush_resource_index_before_query = false, verbose_output = false) ⇒ Object
- #get_direct_member_pids(pid, flush_resource_index_before_query = false, verbose_output = false) ⇒ Object
- #get_direct_member_results(pid, flush_resource_index_before_query = false, verbose_output = false, format = 'json') ⇒ Object
-
#get_pid_for_identifier(identifier, flush_resource_index_before_query = false) ⇒ Object
Returns the pid of the first object found with the given identifier.
- #get_project_constituent_count(pid, verbose_output = false) ⇒ Object
- #get_project_constituent_pids(pid, verbose_output = false) ⇒ Object
-
#get_project_constituent_results(pid, verbose_output = false, format = 'json') ⇒ Object
Project constituents.
- #get_publish_target_member_count(pid, verbose_output = false) ⇒ Object
- #get_publish_target_member_pids(pid, verbose_output = false) ⇒ Object
-
#get_publish_target_member_results(pid, verbose_output = false, format = 'json') ⇒ Object
Publish target members.
- #get_recursive_member_pids(pid, verbose_output = false, cmodel_type = 'all') ⇒ Object
Instance Method Details
#get_all_pids_for_identifier(identifier) ⇒ Object
Returns the pids of ALL objects found with the given identifier
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/cul_hydra/risearch_members.rb', line 146 def get_all_pids_for_identifier(identifier) find_by_identifier_query = "select $pid from <#ri> where $pid <http://purl.org/dc/elements/1.1/identifier> $identifier and $identifier <mulgara:is> '#{identifier}'" search_response = JSON(Cul::Hydra::Fedora.repository.find_by_itql(find_by_identifier_query, { :type => 'tuples', :format => 'json', :limit => '', :stream => 'on' })) pids_to_return = [] if search_response['results'].present? search_response['results'].each do |result| pids_to_return << result['pid'].gsub('info:fedora/', '') end end return pids_to_return end |
#get_direct_member_count(pid, flush_resource_index_before_query = false, verbose_output = false) ⇒ Object
57 58 59 60 |
# File 'lib/cul_hydra/risearch_members.rb', line 57 def get_direct_member_count(pid, flush_resource_index_before_query=false, verbose_output=false) count = get_direct_member_results(pid,flush_resource_index_before_query,verbose_output,'count/json') return count.blank? ? 0 : count[0]['count'].to_i end |
#get_direct_member_pids(pid, flush_resource_index_before_query = false, verbose_output = false) ⇒ Object
52 53 54 55 |
# File 'lib/cul_hydra/risearch_members.rb', line 52 def get_direct_member_pids(pid, flush_resource_index_before_query=false, verbose_output=false) unique_pids = get_direct_member_results(pid,flush_resource_index_before_query,verbose_output,'json') unique_pids.map{|result| result['pid'].gsub('info:fedora/', '') }.uniq end |
#get_direct_member_results(pid, flush_resource_index_before_query = false, verbose_output = false, format = 'json') ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cul_hydra/risearch_members.rb', line 32 def get_direct_member_results(pid, flush_resource_index_before_query=false, verbose_output=false, format='json') direct_member_query = 'select $pid from <#ri> where $pid <http://purl.oclc.org/NET/CUL/memberOf> <fedora:' + pid + '>' puts 'Performing query:' if verbose_output puts direct_member_query if verbose_output search_response = JSON(Cul::Hydra::Fedora.repository.find_by_itql(direct_member_query, { :type => 'tuples', :format => format, :limit => '', :stream => 'on', :flush => flush_resource_index_before_query.to_s })) return search_response['results'] end |
#get_pid_for_identifier(identifier, flush_resource_index_before_query = false) ⇒ Object
Returns the pid of the first object found with the given identifier
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/cul_hydra/risearch_members.rb', line 125 def get_pid_for_identifier(identifier, flush_resource_index_before_query=false) find_by_identifier_query = "select $pid from <#ri> where $pid <http://purl.org/dc/elements/1.1/identifier> $identifier and $identifier <mulgara:is> '#{identifier}'" search_response = JSON(Cul::Hydra::Fedora.repository.find_by_itql(find_by_identifier_query, { :type => 'tuples', :format => 'json', :limit => '1', :stream => 'on', :flush => flush_resource_index_before_query.to_s })) if search_response['results'].present? return search_response['results'].first['pid'].gsub('info:fedora/', '') else return nil end end |
#get_project_constituent_count(pid, verbose_output = false) ⇒ Object
88 89 90 91 |
# File 'lib/cul_hydra/risearch_members.rb', line 88 def get_project_constituent_count(pid, verbose_output=false) count = get_project_constituent_results(pid,verbose_output,'count/json') return count.blank? ? 0 : count[0]['count'].to_i end |
#get_project_constituent_pids(pid, verbose_output = false) ⇒ Object
83 84 85 86 |
# File 'lib/cul_hydra/risearch_members.rb', line 83 def get_project_constituent_pids(pid, verbose_output=false) unique_pids = get_project_constituent_results(pid,verbose_output,'json') unique_pids.map{|result| result['pid'].gsub('info:fedora/', '') }.uniq end |
#get_project_constituent_results(pid, verbose_output = false, format = 'json') ⇒ Object
Project constituents
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/cul_hydra/risearch_members.rb', line 64 def get_project_constituent_results(pid, verbose_output=false, format='json') project_constituent_query = 'select $pid from <#ri> where $pid <info:fedora/fedora-system:def/relations-external#isConstituentOf> <fedora:' + pid + '>' puts 'Performing query:' if verbose_output puts project_constituent_query if verbose_output search_response = JSON(Cul::Hydra::Fedora.repository.find_by_itql(project_constituent_query, { :type => 'tuples', :format => format, :limit => '', :stream => 'on' })) return search_response['results'] end |
#get_publish_target_member_count(pid, verbose_output = false) ⇒ Object
119 120 121 122 |
# File 'lib/cul_hydra/risearch_members.rb', line 119 def get_publish_target_member_count(pid, verbose_output=false) count = get_publish_target_member_results(pid,verbose_output,'count/json') return count.blank? ? 0 : count[0]['count'].to_i end |
#get_publish_target_member_pids(pid, verbose_output = false) ⇒ Object
114 115 116 117 |
# File 'lib/cul_hydra/risearch_members.rb', line 114 def get_publish_target_member_pids(pid, verbose_output=false) unique_pids = get_publish_target_member_results(pid,verbose_output,'json') unique_pids.map{|result| result['pid'].gsub('info:fedora/', '') }.uniq end |
#get_publish_target_member_results(pid, verbose_output = false, format = 'json') ⇒ Object
Publish target members
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/cul_hydra/risearch_members.rb', line 95 def get_publish_target_member_results(pid, verbose_output=false, format='json') project_constituent_query = 'select $pid from <#ri> where $pid <http://purl.org/dc/terms/publisher> <fedora:' + pid + '>' puts 'Performing query:' if verbose_output puts project_constituent_query if verbose_output search_response = JSON(Cul::Hydra::Fedora.repository.find_by_itql(project_constituent_query, { :type => 'tuples', :format => format, :limit => '', :stream => 'on' })) return search_response['results'] end |
#get_recursive_member_pids(pid, verbose_output = false, cmodel_type = 'all') ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cul_hydra/risearch_members.rb', line 4 def get_recursive_member_pids(pid, verbose_output=false, cmodel_type='all') recursive_member_query = 'select $child $parent from <#ri> where walk($child <http://purl.oclc.org/NET/CUL/memberOf> <fedora:' + pid + '> and $child <http://purl.oclc.org/NET/CUL/memberOf> $parent)' unless cmodel_type == 'all' recursive_member_query += ' and $child <fedora-model:hasModel> $cmodel' recursive_member_query += ' and $cmodel <mulgara:is> <info:fedora/ldpd:' + cmodel_type + '>' end puts 'Performing query:' if verbose_output puts recursive_member_query if verbose_output search_response = JSON(Cul::Hydra::Fedora.repository.find_by_itql(recursive_member_query, { :type => 'tuples', :format => 'json', :limit => '', :stream => 'on' })) unique_pids = search_response['results'].map{|result| result['child'].gsub('info:fedora/', '') }.uniq return unique_pids end |