app/helpers/cornell_catalog_helper.rb
# when all items on holding have the same item perm location,
# and it is different from the holding perm location
# rejigger the item perm location to be the
# perm location
# use the temp location from the response though, not from the item record, as that
# might be out of date.
when all items on holding have the same item perm location,
and it is different from the holding perm location
rejigger the item perm location to be the
perm location
use the temp location from the response though, not from the item record, as that
might be out of date.
when all items on holding have the same item perm location and it is different from the holding perm location rejigger the item perm location to be the perm location use the temp location from the response though not from the item record as that might be out of date .
def fix_permtemps(bibid,con_full,response)
	    if @document.nil?
	      iarray = nil
	    else
	      iarray = @document['item_record_display']
	    end
	    items = []
	    if iarray.nil?
	      return con_full
	    end
	    iarray.each do |ite|
	      items << JSON.parse(ite)
	    end
	    items_db = []
	    if response[bibid] and response[bibid][bibid] and response[bibid][bibid][:records]
	     response[bibid][bibid][:records].each do |record|
	      if record[:bibid].to_s == bibid
		record[:holdings].each do |hdb|
		      hso = {}
		      hso['mfhd_id'] = hdb['MFHD_ID'].to_s
		      hso['item_id'] = hdb['ITEM_ID'].to_s
		      hso['perm_location'] = {}
		      hso['perm_location']['number'] = hdb['PERM_LOCATION']
		      hso['perm_location']['code'] = hdb['PERM_LOCATION_CODE']
		      hso['perm_location']['name'] = hdb['PERM_LOCATION_DISPLAY_NAME']
		      hso['perm_location']['library'] = hdb['PERM_LOCATION_DISPLAY_NAME']
		if hdb['TEMP_LOCATION_ID'] != 0
			   hso['temp_location'] = {}
			   hso['temp_location']['code'] = hdb['TEMP_LOCATION_CODE']
			   hso['temp_location']['number'] = hdb['TEMP_LOCATION_ID']
			   hso['temp_location']['name'] = hdb['TEMP_LOCATION_DISPLAY_NAME']
			   hso['temp_location']['library'] = hdb['TEMP_LOCATION_DISPLAY_NAME']
		      end
		      items_db << hso
		end
	      end
	     end
	    end
	    cond2 = []
	    items2 = Marshal.load( Marshal.dump(items) )
	    con_full.each do |loc|
	      loc2 = loc
	      im = items_db.select {|i| i['mfhd_id'] == loc['holding_id'][0] }
	      imc = im.count
	      im2 = items2.select {|i| i['mfhd_id'] == loc['holding_id'][0] }
	      imc2 = im2.count
	      tm = im.select {|i| i['temp_location'] && !i['temp_location']['code'].blank? }
	      pm = im2.select {|i| !i['perm_location']['code'].blank? }
	      pl = (pm.select {|i| !i['perm_location']['code'].blank?  }).each{|x| x.keep_if{|k,v| k== 'perm_location'}}
              pl.uniq!
	      tl = (tm.select {|i| !i['temp_location']['code'].blank?  }).each{|x| x.keep_if{|k,v| k== 'temp_location'}}
	      if pm.count > 0 and pm.count == imc2 and tm.count == 0
                if pl.size == 1
		  loc2['location_name'] = pl[0]['perm_location']['name']
		  loc2['location_code'] = pl[0]['perm_location']['code']
		  loc2['copies'][0].delete('temp_locations')
                end
	      end
	      if tm.count > 0 and tm.count == imc
		loc2['location_name'] = tl[0]['temp_location']['name']
		loc2['location_code'] = tl[0]['temp_location']['code']
		loc2['copies'][0].delete('temp_locations')
	      end
	      cond2 << loc2
	    end
	    cond2
	  end
def fix_permtemps ( bibid , con_full , response ) if @document . nil? iarray = nil else iarray = @document [ 'item_record_display' ] end items = [ ] if iarray . nil? return con_full end iarray . each do | ite | items << JSON . parse ( ite ) end items_db = [ ] if response [ bibid ] and response [ bibid ] [ bibid ] and response [ bibid ] [ bibid ] [ :records ] response [ bibid ] [ bibid ] [ :records ] . each do | record | if record [ :bibid ] . to_s == bibid record [ :holdings ] . each do | hdb | hso = { } hso [ 'mfhd_id' ] = hdb [ 'MFHD_ID' ] . to_s hso [ 'item_id' ] = hdb [ 'ITEM_ID' ] . to_s hso [ 'perm_location' ] = { } hso [ 'perm_location' ] [ 'number' ] = hdb [ 'PERM_LOCATION' ] hso [ 'perm_location' ] [ 'code' ] = hdb [ 'PERM_LOCATION_CODE' ] hso [ 'perm_location' ] [ 'name' ] = hdb [ 'PERM_LOCATION_DISPLAY_NAME' ] hso [ 'perm_location' ] [ 'library' ] = hdb [ 'PERM_LOCATION_DISPLAY_NAME' ] if hdb [ 'TEMP_LOCATION_ID' ] != 0 hso [ 'temp_location' ] = { } hso [ 'temp_location' ] [ 'code' ] = hdb [ 'TEMP_LOCATION_CODE' ] hso [ 'temp_location' ] [ 'number' ] = hdb [ 'TEMP_LOCATION_ID' ] hso [ 'temp_location' ] [ 'name' ] = hdb [ 'TEMP_LOCATION_DISPLAY_NAME' ] hso [ 'temp_location' ] [ 'library' ] = hdb [ 'TEMP_LOCATION_DISPLAY_NAME' ] end items_db << hso end end end end cond2 = [ ] items2 = Marshal . load ( Marshal . dump ( items ) ) con_full . each do | loc | loc2 = loc im = items_db . select { | i | i [ 'mfhd_id' ] == loc [ 'holding_id' ] [ 0 ] } imc = im . count im2 = items2 . select { | i | i [ 'mfhd_id' ] == loc [ 'holding_id' ] [ 0 ] } imc2 = im2 . count tm = im . select { | i | i [ 'temp_location' ] && ! i [ 'temp_location' ] [ 'code' ] . blank? } pm = im2 . select { | i | ! i [ 'perm_location' ] [ 'code' ] . blank? } pl = ( pm . select { | i | ! i [ 'perm_location' ] [ 'code' ] . blank? } ) . each { | x | x . keep_if { | k , v | k == 'perm_location' } } pl . uniq! tl = ( tm . select { | i | ! i [ 'temp_location' ] [ 'code' ] . blank? } ) . each { | x | x . keep_if { | k , v | k == 'temp_location' } } if pm . count > 0 and pm . count == imc2 and tm . count == 0 if pl . size == 1 loc2 [ 'location_name' ] = pl [ 0 ] [ 'perm_location' ] [ 'name' ] loc2 [ 'location_code' ] = pl [ 0 ] [ 'perm_location' ] [ 'code' ] loc2 [ 'copies' ] [ 0 ] . delete ( 'temp_locations' ) end end if tm . count > 0 and tm . count == imc loc2 [ 'location_name' ] = tl [ 0 ] [ 'temp_location' ] [ 'name' ] loc2 [ 'location_code' ] = tl [ 0 ] [ 'temp_location' ] [ 'code' ] loc2 [ 'copies' ] [ 0 ] . delete ( 'temp_locations' ) end cond2 << loc2 end cond2 end
when all items on holding have the same item perm location,
and it is different from the holding perm location
rejigger the item perm location to be the
perm location
use the temp location from the response though, not from the item record, as that
might be out of date.
when all items on holding have the same item perm location and it is different from the holding perm location rejigger the item perm location to be the perm location use the temp location from the response though not from the item record as that might be out of date .
##Rails.logger.debug "\nes287_debug #{__method__.to_s}: #{__FILE__} line(#{__LINE__}) con_full=#{con_full.inspect}\n" ##Rails.logger.debug "\nes287_debug #{__method__.to_s}: #{__FILE__} line(#{__LINE__}) response=#{response.inspect}\n" ##Rails.logger.debug "\nes287_debug fix_perm: #{__FILE__} line(#{__LINE__}) @document.item_record_display=#{@document['item_record_display'].inspect}\n" ##Rails.logger.debug "\nes287_debug fix_perm: #{__FILE__} line(#{__LINE__}) iarray=#{iarray.inspect}\n" ##Rails.logger.debug "\nes287_debug fix_perm: #{__FILE__} line(#{__LINE__}) items=#{items.pretty_inspect}\n" ##Rails.logger.debug "\nes287_debug fix_perm: #{__FILE__} line(#{__LINE__}) items=#{items}\n" # from response create an array of items similar to that of solr ##Rails.logger.debug "\nes287_debug #{__method__.to_s}: #{__FILE__} line(#{__LINE__}) items_db=#{items_db.inspect}\n" # for each holding record, count the items #select from items array those with matching mfhd_id, and count them. how many items on this mfhd? # we have to check against data directly from the db as solr might be out of date. #select from items array those with matching mfhd_id and a temp loc, and count them. how many items on this mfhd with a temp location?
bibid
<not_specific>
con_full
<not_specific>
response
<not_specific>