Class: ServiceDispatcher

Inherits:
Object
  • Object
show all
Defined in:
app/models/service_dispatcher.rb

Overview

ServiceDispatcher provides a framework for sending off an openurl context object to a variety of services and getting back a standard response which can be rendered in views.

The services that can be added to the dispatcher are listed in the app/models/dispatch_services directory.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (ServiceDispatcher) initialize

A new instance of ServiceDispatcher



10
11
12
# File 'app/models/service_dispatcher.rb', line 10

def initialize
  @services = []
end

Instance Attribute Details

- (Object) services

Returns the value of attribute services



9
10
11
# File 'app/models/service_dispatcher.rb', line 9

def services
  @services
end

Instance Method Details

- (Object) <<(service)

alias for add_service



24
25
26
# File 'app/models/service_dispatcher.rb', line 24

def <<(service)
  add_service(service)
end

- (Object) add_identifier_lookups(context_object)



44
45
46
47
48
49
50
51
52
# File 'app/models/service_dispatcher.rb', line 44

def add_identifier_lookups(context_object)
  idlookup = []
  [context_object.referent, context_object.referrer, context_object.referringEntity].each { | ent |
   unless ent.identifier.nil?
    idlookup << IdentifierLookupService.new(ent)
   end
  }
@services << ServiceBundle.new(idlookup) 	
end

- (Object) add_search_engines



75
76
77
# File 'app/models/service_dispatcher.rb', line 75

def add_search_engines
	@services << ServiceBundle.new([AmazonService.new, GoogleService.new, YahooService.new])
end

- (Object) add_service(service)

pass in a service instance to add to the list of services to run when a context_object is dispatched



17
18
19
20
# File 'app/models/service_dispatcher.rb', line 17

def add_service(service)
  raise "not a valid service" if not service.kind_of? DispatchService
  @services << service
end

- (Object) add_social_bookmarkers



79
80
81
# File 'app/models/service_dispatcher.rb', line 79

def add_social_bookmarkers
	@services << ServiceBundle.new([ConnoteaService.new, YahooMyWebService.new, UnalogService.new])  
end

- (Object) dispatch(context_object)

runs a context object over a defined set of dispatch services and collects the data into a single response which is returned



31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/service_dispatcher.rb', line 31

def dispatch(context_object)
  # create a response to fill up
  response = DispatchResponse.new
  for service in @services
    service.handle context_object, response
  end
  unless service.kind_of? ServiceBundle
    puts service.class
    response.dispatched_services[service.identifier.to_sym] = service
  end
  return response
end


54
55
56
57
58
59
60
61
62
# File 'app/models/service_dispatcher.rb', line 54

def get_link_resolvers(collection)
	resolvers = []
	collection.institutions.each_key { | institution | 
    collection.institutions[institution].link_resolvers.each { | link_resolver |
      resolvers << LinkResolverService.new(link_resolver)      
    }
  }
  return resolvers
end

- (Object) get_opacs(collection)



64
65
66
67
68
69
70
71
72
73
# File 'app/models/service_dispatcher.rb', line 64

def get_opacs(collection)  
	opacs = []
	collection.institutions.each_key { | institution |   	
    collection.institutions[institution].catalogs.each { | catalog |
      opacs << OpacService.new(catalog)    
    }
  }
  opacs << WorldcatService.new
  return opacs
end