app/models/service_response.rb in umlaut-3.0.5 vs app/models/service_response.rb in umlaut-3.1.0.pre1

- old
+ new

@@ -9,10 +9,14 @@ [The legacy columns response_key, value_string, value_alt_string and value_text are deprecated and should not be used, but some legacy Services still use them, so they're still there for now]. In addition, there's a Hash (automatically serialized by ActiveRecord) that's stored in service_data, for arbitrary additional data that a Service can store--whatever you want, just put it in. However, there are conventions that Views expect, see below. You can access ALL the arbitrary key/values in a ServiceResponse, built-in in attributes or from the serialized Hash, by the proxy object returned from #data_values. +You can create a ServiceResponse object with ServiceResponse.create_from_hash, +where the hash keys may be direct iVar columns, or serialized in the +service_data hash, you don't have to care. + ServiceResponse is connected to a Request via the ServiceType join table. The data architecture allows a ServiceResponse to be tied to multiple requests, perhaps to support some kind of cacheing re-use in the future. But at present, the code doesn't do this, a ServiceResponse will really only be related to one request. However, a ServiceResponse can be related to a single Request more than once--once per each type of service response. ServiceType is really a three way join, representing a ServiceResponse, attached to a particular Request, with a particular ServiceTypeValue. == View Display of ServiceResponse @@ -40,10 +44,16 @@ == Full text specific These are applicable only when the incoming OpenURL is an article-level citation. Umlaut uses Request#title_level_citation? to estimate this. [:coverage_checked] boolean, default true. False for links from, eg, the catalog, where we weren't able to pre-check if the particular citation is included at this link. [:can_link_to_article] boolean, default true. False if the links is _known_ not to deliver user to actual article requested, but just to a title-level page. Even though SFX links sometimes incorrectly do this, they are still not set to false here. + +== Coverage dates +Generally only for fulltext. Right now only supplied by SFX. + + [:coverage_begin_date] Ruby Date object representing start of coverage + [:coverage_end_date] Ruby Date object representing end of coverage == highlighted_link (see also) [:source] (optional, otherwise service's display_name is used) == Holdings set adds: @@ -78,11 +88,11 @@ ActionView::Helpers::SanitizeHelper's #sanitize method can convenient. =end class ServiceResponse < ActiveRecord::Base - @@built_in_fields = [:display_text, :url, :notes, :response_key, :value_string, :value_alt_string, :value_text] + @@built_in_fields = [:display_text, :url, :notes, :response_key, :value_string, :value_alt_string, :value_text, :id] belongs_to :request serialize :service_data # This value is not stored in db, but is set temporarily so # the http request params can easily be passed around with a response # object. @@ -96,10 +106,19 @@ def initialize(params = nil) super(params) self.service_data = {} unless self.service_data end + + # Create from a hash of key/values, where some keys + # may be direct iVars, some may end up serialized in service_data, + # you don't have to care, it will do the right thing. + def self.create_from_hash(hash) + r = ServiceResponse.new + r.take_key_values(hash) + return r + end # Instantiates and returns a new Service associated with this response. def service @service ||= ServiceStore.instantiate_service!( self.service_id, nil ) end @@ -133,12 +152,14 @@ def take_key_values(hash) # copy it, cause we're gonna modify it hash = hash.clone + hash.each_pair do |key, value| - if ( self.class.built_in_fields.include?(key)) - self.send(key.to_s + '=', value) + setter = "#{key.to_s}=" + if ( self.respond_to?(setter)) + self.send(setter, value) hash.delete(key) end end # What's left is arbitrary key/values that go in service_data init_service_data(hash)