Module: Cul::Hydra::RisearchMembers::ClassMethods

Included in:
Cul::Hydra::RisearchMembers
Defined in:
lib/cul_hydra/risearch_members.rb

Instance Method Summary collapse

Instance Method Details

#get_all_pids_for_identifier(identifier) ⇒ Object

Returns the pids of ALL objects found with the given identifier



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/cul_hydra/risearch_members.rb', line 178

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_direct_members_with_datastream_pids(pid, dsid, flush_resource_index_before_query = false, verbose_output = false) ⇒ Object



89
90
91
92
# File 'lib/cul_hydra/risearch_members.rb', line 89

def get_direct_members_with_datastream_pids(pid, dsid, flush_resource_index_before_query=false, verbose_output=false)
  unique_pids = get_direct_members_with_datastream_results(pid, dsid, flush_resource_index_before_query, verbose_output, 'json')
  unique_pids.map{|result| result['pid'].gsub('info:fedora/', '') }.uniq
end

#get_direct_members_with_datastream_results(pid, dsid, flush_resource_index_before_query = false, verbose_output = false, format = 'json') ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/cul_hydra/risearch_members.rb', line 62

def get_direct_members_with_datastream_results(pid, dsid, flush_resource_index_before_query=false, verbose_output=false, format='json')
  # Note: The query we're using below is a faster version of this query:
  #   "select $pid from <#ri>
  #   where $pid <http://purl.oclc.org/NET/CUL/memberOf> <fedora:#{pid}>
  #   and $pid <fedora-view:disseminates> $ds
  #   and $ds <fedora-view:disseminationType> <info:fedora/*/#{dsid}>"

  direct_members_with_ds_query = "select $pid
    count( select $ds from <#ri> where  $pid <fedora-view:disseminates> $ds and $ds <fedora-view:disseminationType> <info:fedora/*/#{dsid}>)
    from <#ri>
    where $pid <http://purl.oclc.org/NET/CUL/memberOf> <info:fedora/#{pid}>
    having $k0 <http://mulgara.org/mulgara#occursMoreThan> '0.0'^^<http://www.w3.org/2001/XMLSchema#double>;"

    puts 'Performing query:' if verbose_output
    puts direct_members_with_ds_query if verbose_output

    search_response = JSON.parse(Cul::Hydra::Fedora.repository.find_by_itql(direct_members_with_ds_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



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/cul_hydra/risearch_members.rb', line 157

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



120
121
122
123
# File 'lib/cul_hydra/risearch_members.rb', line 120

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



115
116
117
118
# File 'lib/cul_hydra/risearch_members.rb', line 115

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



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/cul_hydra/risearch_members.rb', line 96

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



151
152
153
154
# File 'lib/cul_hydra/risearch_members.rb', line 151

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



146
147
148
149
# File 'lib/cul_hydra/risearch_members.rb', line 146

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



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/cul_hydra/risearch_members.rb', line 127

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