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, verbose_output = false) ⇒ Object
- #get_direct_member_pids(pid, verbose_output = false) ⇒ Object
- #get_direct_member_results(pid, verbose_output = false, format = 'json') ⇒ Object
-
#get_pid_for_identifier(identifier) ⇒ 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
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/cul_hydra/risearch_members.rb', line 144 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, verbose_output = false) ⇒ Object
56 57 58 59 |
# File 'lib/cul_hydra/risearch_members.rb', line 56 def get_direct_member_count(pid, verbose_output=false) count = get_direct_member_results(pid,verbose_output,'count/json') return count.blank? ? 0 : count[0]['count'].to_i end |
#get_direct_member_pids(pid, verbose_output = false) ⇒ Object
51 52 53 54 |
# File 'lib/cul_hydra/risearch_members.rb', line 51 def get_direct_member_pids(pid, verbose_output=false) unique_pids = get_direct_member_results(pid,verbose_output,'json') unique_pids.map{|result| result['pid'].gsub('info:fedora/', '') }.uniq end |
#get_direct_member_results(pid, verbose_output = false, format = 'json') ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cul_hydra/risearch_members.rb', line 32 def get_direct_member_results(pid, 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' })) return search_response['results'] end |
#get_pid_for_identifier(identifier) ⇒ Object
Returns the pid of the first object found with the given identifier
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/cul_hydra/risearch_members.rb', line 124 def get_pid_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 => '1', :stream => 'on' })) 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
87 88 89 90 |
# File 'lib/cul_hydra/risearch_members.rb', line 87 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
82 83 84 85 |
# File 'lib/cul_hydra/risearch_members.rb', line 82 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
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/cul_hydra/risearch_members.rb', line 63 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
118 119 120 121 |
# File 'lib/cul_hydra/risearch_members.rb', line 118 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
113 114 115 116 |
# File 'lib/cul_hydra/risearch_members.rb', line 113 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
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/cul_hydra/risearch_members.rb', line 94 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 |