Class: LD4L::OreRDF::FindProxies
- Inherits:
-
Object
- Object
- LD4L::OreRDF::FindProxies
- Defined in:
- lib/ld4l/ore_rdf/services/proxy/find.rb
Class Method Summary collapse
-
.call(options = {}) ⇒ Object
Find proxies matching the specified criteria.
Class Method Details
.call(options = {}) ⇒ Object
Find proxies matching the specified criteria.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 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 88 89 90 91 92 |
# File 'lib/ld4l/ore_rdf/services/proxy/find.rb', line 29 def self.call( ={} ) aggregation = [:aggregation] || nil raise ArgumentError, 'aggregation must be one of string uri, RDF::URI, LD4L::OreRDF::AggregationResource' unless !aggregation.nil? && ( aggregation.kind_of?(String) || aggregation.kind_of?(RDF::URI) || aggregation.kind_of?(LD4L::OreRDF::AggregationResource) ) aggregation = RDF::URI(aggregation) if aggregation.kind_of?(String) aggregation = aggregation.rdf_subject if aggregation.kind_of?(LD4L::OreRDF::AggregationResource) # aggregation = aggregation.to_s if aggregation.kind_of?(RDF::URI) # aggregation = aggregation.rdf_subject.to_s if aggregation.kind_of?(LD4L::OreRDF::AggregationResource) repository = [:repository] || :default raise ArgumentError, 'repository must be a symbol' unless repository.kind_of?(Symbol) raise ArgumentError, 'repository must be a registered repository' unless ActiveTriples::Repositories.repositories.has_key?(repository) resume = [:resume] || false raise ArgumentError, 'resume must be true or false' unless resume.kind_of?(TrueClass) || resume.kind_of?(FalseClass) criteria = [:criteria] || nil raise ArgumentError, 'criteria must be a hash of attribute-value pairs for searching for proxies' unless criteria.nil? || criteria.kind_of?(Hash) criteria = criteria ? criteria.dup : {} criteria[RDF.type] = RDFVocabularies::ORE.Proxy criteria[RDFVocabularies::ORE.proxyIn] = aggregation # properties are ignored when resume==true because all properties are returned as part of the resumed proxies properties = [:properties] || nil raise ArgumentError, 'properties must be an array of predicates' unless properties.nil? || properties.kind_of?(Hash) || resume properties.each_key { |k| criteria[properties[k]] = k unless criteria.has_key?(properties[k]) } unless properties.nil? || resume process_properties = properties.nil? || resume ? false : true graph = ActiveTriples::Repositories.repositories[repository] query = RDF::Query.new({ :proxy => criteria }) process_properties || resume ? proxies = {} : proxies = [] results = query.execute(graph) results.each do |r| h = r.to_hash uri = h[:proxy] if resume # if resume, return Hash of proxy uri => resumed proxy for each found if aggregation.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8 proxies[uri] = LD4L::OreRDF::ProxyResource.new(uri,aggregation.list_info) else # < ActiveTriples 0.8 proxies[uri] = LD4L::OreRDF::ProxyResource.new(uri) end elsif process_properties # if properties, return Hash of proxy uri => Hash of property => value for each found properties = h properties.delete(:proxy) proxies[uri] = properties else # if no properties && not resumed, return array of proxy uris proxies << uri end end proxies end |