view · edit · sidebar · attach · print · history

20100916 understand-limitation-process

<< Masa.20100917-hack-limitationText-class | 2010 | Masa.20100915-update-limitation-text >>


  1. Trace again the code from the clicking of the search button
  2. Backtrace the code from the last commit

Goal
  • Understand limitation_text process / 50%
Milestones
  1. Trace the code from the start point step by step Suspend at HtmlGrid::Grid class
  2. Backtrace the code from src/view/dataformat.rb (the last commit)
Summary
Commits
ToDo Tomorrow
  1. Dimdi-Import-Error.
Keep in Mind
Attached Files

Trace again the code from the clicking of the search button

On the top page

<FORM ACCEPT-CHARSET="ISO-8859-1" NAME="stdform" METHOD="POST" ENCTYPE="application/x-www-form-urlencoded" 
 ACTION="http://oddb.masa.org/en/gcc" 
 onSubmit="
   if(search_query.value!='Enter Drug or Active Agent here'){
     var href = 'http://oddb.masa.org/en/gcc/search/zone/drugs/search_query/'+encodeURIComponent(search_query.value.replace(/\//, '%2F'));
     if(this.search_type)
       href += '/search_type/' + this.search_type.value;href += '#best_result';
     document.location.href=href;
   } 
   return false
 "
>

Alert check

  1. Copy the source code as test.html
  2. Modifiy it and experiment

Experiment

<FORM ACCEPT-CHARSET="ISO-8859-1" NAME="stdform" METHOD="POST" ENCTYPE="application/x-www-form-urlencoded" 
 ACTION="http://oddb.masa.org/en/gcc" 
 onSubmit="
   if(search_query.value!='Enter Drug or Active Agent here'){
     var href = 'http://oddb.masa.org/en/gcc/search/zone/drugs/search_query/'+encodeURIComponent(search_query.value.replace(/\//, '%2F'));
     if(this.search_type)
       href += '/search_type/' + this.search_type.value;href += '#best_result';

     alert(href);
     alert(this.search_type);

     document.location.href=href;
   } 
   return false
 "
>

Result

http://oddb.masa.org/en/gcc/search/zone/drugs/search_query/7680382940243/search_type/st_oddb#best_result
[object HTMLSelectElement]

BraSt

Experiment & Result & Consider

Experiment
/usr/lib64/ruby/site_ruby/1.8/sbsm/request.rb

    def process
      begin
        @cgi.params.store('default_flavor', ENV['DEFAULT_FLAVOR'])
        @request.notes.each { |key, val|
print "key=", key, " val=",val, "<br>"

Result (direct access to http://oddb.masa.org/en/gcc/search/zone/drugs/search_query/7680382940243)

key=language val=en
key=flavor val=gcc
key=event val=search
key=zone val=drugs
key=search_query val=7680382940243

Notes

  • SBSM::Request#process is called anyway
  • The url string is divided and saved in @request variable as hash data structure
  • Let's trace the next

Experiment
/usr/lib64/ruby/site_ruby/1.8/sbsm/request.rb

        begin
          headers = @proxy.http_headers
          unless(cookie_input.empty?)
            cookie = generate_cookie(cookie_input)
            headers.store('Set-Cookie', [cookie])
          end
          @cgi.out(headers) {

print res.include?("Lexotanil 1,5")

            (@cgi.params.has_key?("pretty")) ? CGI.pretty( res ) : res
          }
        rescue StandardError => e
          handle_exception(e)
        end

Result

true

Notes

  • 'res' is the whole html source, which includes the search result
  • The part where the limitation information is saved is before this part

Experiment
/usr/lib64/ruby/site_ruby/1.8/sbsm/session.rb

    def drb_process(request)
      start = Time.now
      html = @mutex.synchronize do
        process(request)
        to_html
      end
      (@@stats[@request_path] ||= []).push(Time.now - start)

open("/home/masa/work/test.dat","a"){|f| f.print html}

      html
    end

Result

  • The same result html source code

Notes

  • SBSM::Session#drb_process(request) is called in SBSM::Request#drb_process
  • The limitation saving point is also before this part
  • SBSM::Session#drb_process calls process and to_html methods and the resut becomes html source code
  • Next I should trace to_html method

Experiment
/usr/lib64/ruby/site_ruby/1.8/sbsm/session.rb

    def to_html
open("/home/masa/work/test.dat","a"){|f| f.print @state.class}
      @state.to_html(@@cgi)

Result

ODDB::State::Drugs::Result

Notes

  • Next ODDB::State::Drugs::Result#to_html

Search to_html method

  1. But there is no to_html method in src/state/drugs/result.rb
  2. class Result < State::Drugs::Global
  3. Check State::Drugs::Global class
  4. Also there is no to_html method in src/state/drugs/global.rb
  5. class Global < State::Global
  6. Check State::Global class
  7. Also there is no to_html method in src/state/global.rb
  8. class Global < SBSM::State
  9. Check SBSM::State class
  10. @@There is to_html method!! in /usr/lib64/ruby/site_ruby/1.8/sbsm/state.rb
  11. The to_html method calls view method, and view method returns some instance and a method or variable named to_html of the instance is called
  12. Check view class

Experiment
/usr/lib64/ruby/site_ruby/1.8/sbsm/state.rb

    def to_html(context)

open("/home/masa/work/test.dat","a"){|f| f.print view.class}

      view.to_html(context)
    end

Result

ODDB::View::Drugs::Result

Search ODDB::View::Drugs::Result#to_html

  1. But there is not to_html method in src/view/drugs/result.rb
  2. class Result < View::ResultTemplate
  3. Check ODDB::View::ResultTemplate
  4. There is neither to_html method in src/view/resulttemplate.rb
  5. class ResultTemplate < PublicTemplate
  6. Check ODDB::View::PublicTemplate
  7. There is neither to_html method in src/view/publictemplate.rb
  8. class PublicTemplate < HtmlGrid::Template
  9. Check HtmlGrid::Template
  10. There is to_html method in /usr/lib64/ruby/site_ruby/1.8/htmlgrid/template.rb
  11. HtmlGrid::Template#to_html calls super, which means the super class's to_html method
  12. class Template < Composite
  13. Check HtmlGrid::Composite class

/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb

    def to_html(context)
      @grid.set_attributes(@attributes)
      super << @grid.to_html(context)
    end

Experiment
/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb

    def to_html(context)
      @grid.set_attributes(@attributes)
open("/home/masa/work/test.dat","a"){|f| f.print @grid.to_html(context), "\n\n"}
      super << @grid.to_html(context)
    end

Result

  • The HtmlGrid::Template#to_html method is called several times
  • One of the outputs includes the html source code of search result
  • The saving point of limitation text is before this part

Experiment2
/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb

    def to_html(context)
      @grid.set_attributes(@attributes)
open("/home/masa/work/test.dat","a"){|f| f.print @grid.class, "\n"}
      super << @grid.to_html(context)
    end

Result

HtmlGrid::Grid
HtmlGrid::Grid
HtmlGrid::Grid
HtmlGrid::Grid
HtmlGrid::Grid
HtmlGrid::Grid
HtmlGrid::Grid
HtmlGrid::Grid
HtmlGrid::Grid
HtmlGrid::Grid
HtmlGrid::Grid
HtmlGrid::Grid
HtmlGrid::Grid
HtmlGrid::Grid
HtmlGrid::Grid
HtmlGrid::Grid
HtmlGrid::Grid

Notes

  • HtmlGrid::Template#to_html method is called in total 17 times
  • Next check Html::Grid#to_html method

Set-p experiment /usr/lib64/ruby/site_ruby/1.8/htmlgrid/grid.rb

  • But nothing is outputted
  • A method in a binary library, htmlgrid.so, may be called.
  • I cannot trace forward anymore
  • Let's start to find another entrance of code labyrinth

suspend

Backtrace the code from the last commit

The last commit

Experiment
src/view/dataformat.rb

        if (ean_code = model.barcode)
pp caller(0)

Result (the following is outputted 6 times => it is called for each package)

["/home/masa/ywesee/oddb.org/src/view/dataformat.rb:66:in `name_base'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:66:in `send'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:66:in `create'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:286:in `compose_component'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:209:in `_compose'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:203:in `each'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:203:in `_compose'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/list.rb:67:in `compose_list'",
 "/usr/lib64/ruby/1.8/delegate.rb:136:in `each_with_index'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/list.rb:65:in `each'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/list.rb:65:in `each_with_index'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/list.rb:65:in `compose_list'",
 "/home/masa/ywesee/oddb.org/src/view/drugs/resultlist.rb:222:in `compose_list'",
 "/home/masa/ywesee/oddb.org/src/model/search_result.rb:120:in `each'",
 "/home/masa/ywesee/oddb.org/src/model/search_result.rb:120:in `each'",
 "/home/masa/ywesee/oddb.org/src/view/drugs/resultlist.rb:217:in `compose_list'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/list.rb:54:in `compose'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:55:in `init'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/list.rb:129:in `init'",
 "/home/masa/ywesee/oddb.org/src/view/drugs/resultlist.rb:191:in `init'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/component.rb:138:in `initialize'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:59:in `new'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:59:in `create'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:286:in `compose_component'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:209:in `compose'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:203:in `each'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:203:in `compose'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:55:in `init'",
 "/home/masa/ywesee/oddb.org/src/view/drugs/result.rb:116:in `init'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/component.rb:138:in `initialize'",
 "/home/masa/ywesee/oddb.org/src/view/publictemplate.rb:53:in `new'",
 "/home/masa/ywesee/oddb.org/src/view/publictemplate.rb:53:in `content'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:66:in `send'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:66:in `create'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:286:in `compose_component'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:209:in `compose'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:203:in `each'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:203:in `compose'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:55:in `init'",
 "/home/masa/ywesee/oddb.org/src/view/publictemplate.rb:50:in `init'",
 "/home/masa/ywesee/oddb.org/src/view/resulttemplate.rb:28:in `init'",
 "/usr/lib64/ruby/site_ruby/1.8/htmlgrid/component.rb:138:in `initialize'",
 "/usr/lib64/ruby/site_ruby/1.8/sbsm/state.rb:271:in `new'",
 "/usr/lib64/ruby/site_ruby/1.8/sbsm/state.rb:271:in `view'",
 "/usr/lib64/ruby/site_ruby/1.8/sbsm/state.rb:191:in `to_html'",
 "/usr/lib64/ruby/site_ruby/1.8/sbsm/session.rb:496:in `to_html'",
 "/usr/lib64/ruby/site_ruby/1.8/sbsm/session.rb:174:in `drb_process'",
 "/usr/lib64/ruby/site_ruby/1.8/sbsm/session.rb:171:in `synchronize'",
 "/usr/lib64/ruby/site_ruby/1.8/sbsm/session.rb:171:in `drb_process'",
 "/usr/lib64/ruby/1.8/drb/drb.rb:1556:in `__send__'",
 "/usr/lib64/ruby/1.8/drb/drb.rb:1556:in `perform_without_block'",
 "/usr/lib64/ruby/1.8/drb/drb.rb:1516:in `perform'",
 "/usr/lib64/ruby/1.8/drb/drb.rb:1590:in `main_loop'",
 "/usr/lib64/ruby/1.8/drb/drb.rb:1586:in `loop'",
 "/usr/lib64/ruby/1.8/drb/drb.rb:1586:in `main_loop'",
 "/usr/lib64/ruby/1.8/drb/drb.rb:1582:in `start'",
 "/usr/lib64/ruby/1.8/drb/drb.rb:1582:in `main_loop'",
 "/usr/lib64/ruby/1.8/drb/drb.rb:1431:in `run'",
 "/usr/lib64/ruby/1.8/drb/drb.rb:1428:in `start'",
 "/usr/lib64/ruby/1.8/drb/drb.rb:1428:in `run'",
 "/usr/lib64/ruby/1.8/drb/drb.rb:1348:in `initialize'",
 "/usr/lib64/ruby/1.8/drb/drb.rb:1628:in `new'",
 "/usr/lib64/ruby/1.8/drb/drb.rb:1628:in `start_service'",
 "bin/oddbd:38"]

Experiment

        if (ean_code = model.barcode)
#pp caller(0)
pp model.limitation_text

Result

#<ODDB::LimitationText:0x7f9d3a9eef88
 @odba_class=nil,
 @odba_container=nil,
 @odba_id=10899115,
 @receiver=nil,
 @receiver_loaded=nil>
nil
#<ODDB::LimitationText:0x7f9d3a862e08
 @odba_class=nil,
 @odba_container=nil,
 @odba_id=23135746,
 @receiver=nil,
 @receiver_loaded=nil>
#<ODDB::LimitationText:0x7f9d3a7a4a70
 @odba_class=nil,
 @odba_container=nil,
 @odba_id=24323050,
 @receiver=nil,
 @receiver_loaded=nil>
#<ODDB::LimitationText:0x7f9d3a684d20
 @odba_class=nil,
 @odba_container=nil,
 @odba_id=10899116,
 @receiver=nil,
 @receiver_loaded=nil>
nil

Notes

  • This is also the same as yesterday

grep search

masa@masa ~/ywesee/oddb.org $ grep -r "class LimitationText" src
src/model/limitationtext.rb:    class LimitationText
src/state/drugs/limitationtext.rb:class LimitationText < State::Drugs::Global
src/state/drugs/limitationtexts.rb:class LimitationTexts < Global
src/state/migel/limitationtext.rb:class LimitationText < State::Migel::Global
src/view/drugs/limitationtext.rb:class LimitationTextInnerComposite < HtmlGrid::Composite
src/view/drugs/limitationtext.rb:class LimitationTextComposite < HtmlGrid::Composite
src/view/drugs/limitationtext.rb:class LimitationText < PrivateTemplate
src/view/drugs/limitationtexts.rb:class LimitationTextList < HtmlGrid::List
src/view/drugs/limitationtexts.rb:class LimitationTextsComposite < HtmlGrid::Composite
src/view/drugs/limitationtexts.rb:class LimitationTexts < ResultTemplate
src/view/migel/limitationtext.rb:class LimitationTextInnerComposite < View::Drugs::LimitationTextInnerComposite
src/view/migel/limitationtext.rb:class LimitationTextComposite < HtmlGrid::Composite
src/view/migel/limitationtext.rb:class LimitationText < View::PrivateTemplate

BraSt

  • ODDB::LimitationText class is definitely defined src/model/limitationtext.rb!!
view · edit · sidebar · attach · print · history
Page last modified on July 13, 2011, at 12:00 PM