<< Masa.20101118-create-grant_download-command-de_oddb_org | 2010 | Masa.20101116-create-grant_download-command-de_oddb_org >>
Just for information in the furture development related to invoice system
Data preparation
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
Test a case in which there is no target file
module ODDB
module Html
module State
class Global < SBSM::State
...
def grant_download
Download.new(@session, '/home/masa/work/test.dat')
end
Result
Test downloading
def grant_download
_download(@session.user_input(:file))
end
Result
Next
Notes
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
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
Test bin/admin grant_download command
def grant_download
"WWW"
end
Run bin/adim
masa@masa ~/ywesee/de.oddb.org $ bin/admin de.oddb> grant_download -> WWW de.oddb>
Note
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
def grant_download
"WWW"
end
Question
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
require 'oddb/persistence/odba/business/grant_download'
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
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
require 'oddb/persistence/odba/business/grant_download'
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!!
Refer to