view · edit · sidebar · attach · print · history

20101117-create-grant_download-command-de_oddb_org

<< Masa.20101118-create-grant_download-command-de_oddb_org | 2010 | Masa.20101116-create-grant_download-command-de_oddb_org >>


  1. Implementation of downloading process
  2. Define a GrantDownload class
  3. Implement GrantDownload class and grant_download method

Goal
  • Create grant_download / 80%
Milestones
  1. Check a test case in both oddb.org and de.oddb.org for downloading
  2. Implement small method and test
    • Check @session data
    • Downloading test 9:45
    • Define a class for a download user
    • Check a user expiry
    • Define a logging process
    • Define a grant_download method in util/server.rb
Summary
Commits
ToDo Tomorrow
  • Check the procedure of restore ODBA data on the cache
  • Implement grant_download in de.oddb.org
Keep in Mind
  1. A bug import_gkv Tue Nov 16 02:00:10 2010: de.oddb.org Zubef (PDF)
  2. On Ice
  3. emerge --sync

Implementation of downloading process in de.oddb.org

Just for information in the furture development related to invoice system

Data preparation

  • Run de.oddb.org/bin/oddbd
  • Run de.oddb.org/bin/exportd
masa@masa ~/ywesee/de.oddb.org $ jobs/export_csv
masa@masa ~/ywesee/de.oddb.org $ ls var/downloads -al
insgesamt 5552
drwxr-xr-x 2 masa masa      56 17. Nov 08:50 .
drwxr-xr-x 3 masa masa       8 17. Nov 08:42 ..
-rw-r--r-- 1 masa masa 4135471 17. Nov 08:50 de.oddb.csv
-rw-r--r-- 1 masa masa  771626 17. Nov 08:50 de.oddb.csv.gz
-rw-r--r-- 1 masa masa  771728 17. Nov 08:50 de.oddb.csv.zip

Test @session data

1. lib/oddb/html/util/validator.rb

  EVENTS = [ :ajax_autofill, :ajax_create_active_agent,
...
             #:sequence, :sort, :update ]
             :sequence, :sort, :update, :grant_download ]

2. lib/oddb/html/state/global.rb

module ODDB
  module Html
    module State
class Global < SBSM::State
...
  def grant_download
    p ODDB.config.export_dir
    p @session.user_input(:file)
  end

Result

"/home/masa/ywesee/de.oddb.org/var/downloads"
"de.oddb.csv"

Note

  • Good

Test a case in which there is no target file

lib/oddb/html/state/global.rb

module ODDB
  module Html
    module State
class Global < SBSM::State
...
  def grant_download
    Download.new(@session, '/home/masa/work/test.dat')
  end

Result

  • 'Es tut uns leid' on browser

Test downloading

lib/oddb/html/state/global.rb

  def grant_download
    _download(@session.user_input(:file))
  end

Result

  • Succeeded in downloading var/downloads/de.oddb.csv

Next

  • Check user 'exprired?'
  • Define a class somewhere for a download user

Define a GrantDownload class

Notes

  • Where should I define the class for the expiry check?, and class name.
  • I want to use 'save' and 'find_by_uid' methods, it should inherit Model class

Test defining a class

lib/oddb/business/grant_download.rb

#!/usr/bin/env ruby
# ODDB::Business::GrantDownload -- de.oddb.org -- 17.11.2011 -- mhatakeyama@ywesee.com

require 'oddb/model'

module ODDB
  module Business
    class GrantDownload < Model
    end
  end
end

lib/oddb/html/state/global.rb

  def grant_download
    if(user = ODDB::Business::GrantDownload.find_by_uid(1))
      p "AAA"
    else
      p "BBB"
    end
    #_download(@session.user_input(:file))
  end

Result

"BBB"

Note

  • The class is recognized

Test bin/admin grant_download command

lib/oddb/util/server.rb

      def grant_download
        "WWW"
      end

Run bin/adim

masa@masa ~/ywesee/de.oddb.org $ bin/admin
de.oddb> grant_download
-> WWW
de.oddb> 

Note

  • The method is recognized

Implement GrantDownload class and grant_download method

lib/oddb/business/grant_download.rb

#!/usr/bin/env ruby
# ODDB::Business::GrantDownload -- de.oddb.org -- 17.11.2011 -- mhatakeyama@ywesee.com

require 'oddb/model'

module ODDB
  module Business
    class GrantDownload < Model
    end
  end
end

lib/oddb/util/server.rb

      def grant_download
        "WWW"
      end

Question

  • How can I search the cache by the other data than odba_id?

Experiment

lib/oddb/business/grant_download.rb

#!/usr/bin/env ruby
# ODDB::Business::GrantDownload -- de.oddb.org -- 17.11.2011 -- mhatakeyama@ywesee.com

require 'oddb/model'

module ODDB
  module Business
    class GrantDownload < Model
      #multilingual :email
      #attr_reader :grant_list, :download_history
      attr_reader :email, :grant_list, :download_history
      def initialize(email)
        @email = email
        @grant_list = {}
        @download_history = []
      end
    end
  end
end

lib/oddb/persistence/odba/business/grant_download.rb

#!/usr/bin/env ruby
# ODDB::Business::GrantDownload -- de.oddb.org -- 17.11.2011 -- mhatakeyama@ywesee.com

require 'oddb/business/grant_download'
require 'oddb/persistence/odba/model'

module ODDB
  module Business
    class GrantDownload < Model
      odba_index :email, 'email.all'
    end
  end
end

lib/oddb/persistence/odba.rb

require 'oddb/persistence/odba/business/grant_download'

lib/oddb/util/server.rb

      def grant_download(arg1, arg2='')
        if arg1 == 1
          user = ODDB::Business::GrantDownload.new(arg2)
          user.save
          p user
          user.uid
        elsif arg1 == 2
          user = ODDB::Business::GrantDownload.find_by_uid(arg2)
          p user
          user
        elsif arg1 == 3
          user = ODDB::Business::GrantDownload.find_by_email(arg2)
          p user
          user
        elsif arg1 == 4
          user = ODDB::Business::GrantDownload.find_by_uid(arg2)
          p user
          user.delete
        end
      end

Reboot de.oddb.org/bin/oddbd

Result

masa@masa ~/ywesee/de.oddb.org $ bin/admin
de.oddb> grant_download 1, 'mhatakeyama@ywesee.com'
-> 3645278
de.oddb> grant_download 2, 3645278
-> #<ODDB::Business::GrantDownload:0x7f0508f2b4f8>
de.oddb> grant_download 3, 'mhatakeyama@ywesee.com'
-> 
de.oddb> grant_download 4, 3645278
-> #<ODDB::Business::GrantDownload:0x7f0508f2b4f8>

oddbd log

#<ODDB::Business::GrantDownload:0x7f0508f2b4f8 @odba_id=3645278, @odba_persistent=true, @grant_list={}, @email="mhatakeyama@ywesee.com", @odba_observers=[], @download_history=[]>
#<ODDB::Business::GrantDownload:0x7f0508f2b4f8 @odba_id=3645278, @odba_persistent=true, @grant_list={}, @email="mhatakeyama@ywesee.com", @odba_observers=[], @download_history=[]>
nil
#<ODDB::Business::GrantDownload:0x7f0508f2b4f8 @odba_id=3645278, @odba_persistent=true, @grant_list={}, @email="mhatakeyama@ywesee.com", @odba_observers=[], @download_history=[]>

Notes

  • find_by_email method is recognized but find_by_email method failed, does not find any object
  • Why?

Experiment

lib/oddb/business/grant_download.rb

#!/usr/bin/env ruby
# ODDB::Business::GrantDownload -- de.oddb.org -- 17.11.2011 -- mhatakeyama@ywesee.com

require 'oddb/model'

module ODDB
  module Business
    class GrantDownload < Model
      multilingual :email               #<= key point
      def initialize(email)
        self.email.de = email           #<= key point
      end
    end
  end
end

lib/oddb/persistence/odba/business/grant_download.rb

#!/usr/bin/env ruby
# ODDB::Business::GrantDownload -- de.oddb.org -- 17.11.2011 -- mhatakeyama@ywesee.com

require 'oddb/business/grant_download'
require 'oddb/persistence/odba/model'

module ODDB
  module Business
    class GrantDownload < Model
      odba_index :email
    end
  end
end

lib/oddb/persistence/odba.rb

require 'oddb/persistence/odba/business/grant_download'

lib/oddb/util/server.rb

      def grant_download(arg1, arg2='')
        if arg1 == 1
          user = ODDB::Business::GrantDownload.new(arg2)
          user.save
          p user
          user.uid
        elsif arg1 == 2
          user = ODDB::Business::GrantDownload.find_by_uid(arg2)
          p user
          user.uid
        elsif arg1 == 3
          user = ODDB::Business::GrantDownload.find_by_email(arg2)
          p user
          user.uid
        elsif arg1 == 4
          user = ODDB::Business::GrantDownload.find_by_uid(arg2)
          p user
          user.delete
          user.uid
        end
      end

Result

masa@masa ~/ywesee/de.oddb.org $ bin/admin 
de.oddb> grant_downloda 1, 'aa@bb.cc'
-> undefined method `grant_downloda' for nil:ODDB::Util::Server
de.oddb> grant_download 1, 'aa@bb.cc'
-> 3645287
de.oddb> grant_download 2, 3645287
-> 3645287
de.oddb> grant_download 3, 'aa@bb.cc'
-> 3645287
de.oddb> grant_download 1, 'aa@bb.cc'
-> 3645288
de.oddb> grant_download 3, 'aa@bb.cc'
-> 3645288

oddbd log

#<ODDB::Business::GrantDownload:0x7f612a1bdc20 @odba_id=3645287, @odba_persistent=true, @email=#<ODDB::Util::Multilingual:0x7f612a1bd838 @synonyms=[], @canonical={:de=>"aa@bb.cc"}>, @odba_observers=[]>
#<ODDB::Business::GrantDownload:0x7f612a1bdc20 @odba_id=3645287, @odba_persistent=true, @email=#<ODDB::Util::Multilingual:0x7f612a1bd838 @synonyms=[], @canonical={:de=>"aa@bb.cc"}>, @odba_observers=[]>
#<ODDB::Business::GrantDownload:0x7f612a1bdc20 @odba_id=3645287, @odba_persistent=true, @email=#<ODDB::Util::Multilingual:0x7f612a1bd838 @synonyms=[], @canonical={:de=>"aa@bb.cc"}>, @odba_observers=[]>
#<ODDB::Business::GrantDownload:0x7f612a15f6e8 @odba_id=3645288, @odba_persistent=true, @email=#<ODDB::Util::Multilingual:0x7f612a15f5a8 @synonyms=[], @canonical={:de=>"aa@bb.cc"}>, @odba_observers=[]>
#<ODDB::Business::GrantDownload:0x7f612a15f6e8 @odba_id=3645288, @odba_persistent=true, @email=#<ODDB::Util::Multilingual:0x7f612a15f5a8 @synonyms=[], @canonical={:de=>"aa@bb.cc"}>, @odba_observers=[]>

Notes

  • find_by_email method Works!!
  • find_by_* method finds the last entry record if there is the same index
  • key points are 'multilingual' attribute in lib/oddb/business/grant_download.rb
  • if only attr_* attribute is set for :email, find_by_email does not work. I do not know why.
  • in de.oddb.org, the class definition under lib/oddb/persistence/odba/ should be necessary

Refer to

view · edit · sidebar · attach · print · history
Page last modified on July 13, 2011, at 11:54 AM