ramaze.ch.oddb.org 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (286) hide show
  1. data/History.txt +6 -0
  2. data/LICENSE +339 -0
  3. data/Manifest.txt +285 -0
  4. data/README.txt +45 -0
  5. data/Rakefile +28 -0
  6. data/bin/admin +69 -0
  7. data/bin/exportd +63 -0
  8. data/bin/migrate +461 -0
  9. data/bin/oddbd +62 -0
  10. data/data/fulltext/data/dicts/french/fulltext.aff +1057 -0
  11. data/data/fulltext/data/dicts/french/fulltext.dict +91189 -0
  12. data/data/fulltext/data/dicts/french/fulltext.stop +135 -0
  13. data/data/fulltext/data/dicts/german/fulltext.aff +1233 -0
  14. data/data/fulltext/data/dicts/german/fulltext.dict +287574 -0
  15. data/data/fulltext/data/dicts/german/fulltext.stop +133 -0
  16. data/data/fulltext/data/german_compound/README +15 -0
  17. data/data/fulltext/data/german_compound/compound.pl +63 -0
  18. data/data/fulltext/data/german_compound/german.stop +20 -0
  19. data/data/fulltext/data/ispell-german-compound.tar.gz +0 -0
  20. data/data/fulltext/redist/dict_french/Makefile +12 -0
  21. data/data/fulltext/redist/dict_french/README.french +1 -0
  22. data/data/fulltext/redist/dict_french/dict_french.sql.in +7 -0
  23. data/data/fulltext/redist/dict_french/dict_snowball.c +56 -0
  24. data/data/fulltext/redist/dict_french/french_stem.c +1222 -0
  25. data/data/fulltext/redist/dict_french/french_stem.h +16 -0
  26. data/data/fulltext/redist/dict_french/subinclude.h +2 -0
  27. data/data/fulltext/redist/dict_german/Makefile +12 -0
  28. data/data/fulltext/redist/dict_german/README.german +1 -0
  29. data/data/fulltext/redist/dict_german/dict_german.sql.in +7 -0
  30. data/data/fulltext/redist/dict_german/dict_snowball.c +56 -0
  31. data/data/fulltext/redist/dict_german/german_stem.c +527 -0
  32. data/data/fulltext/redist/dict_german/german_stem.h +16 -0
  33. data/data/fulltext/redist/dict_german/subinclude.h +1 -0
  34. data/data/fulltext/redist/french_stem.c +1222 -0
  35. data/data/fulltext/redist/french_stem.h +16 -0
  36. data/data/fulltext/redist/german_stem.c +527 -0
  37. data/data/fulltext/redist/german_stem.h +16 -0
  38. data/lib/fixes/ruby19.rb +21 -0
  39. data/lib/fixes/selenium.rb +20 -0
  40. data/lib/fixes/singular.rb +8 -0
  41. data/lib/fixes/yaml.rb +13 -0
  42. data/lib/oddb.rb +11 -0
  43. data/lib/oddb/business/company.rb +18 -0
  44. data/lib/oddb/business/invoice.rb +75 -0
  45. data/lib/oddb/business/price.rb +60 -0
  46. data/lib/oddb/config.rb +73 -0
  47. data/lib/oddb/drugs.rb +16 -0
  48. data/lib/oddb/drugs/active_agent.rb +37 -0
  49. data/lib/oddb/drugs/atc.rb +53 -0
  50. data/lib/oddb/drugs/composition.rb +41 -0
  51. data/lib/oddb/drugs/ddd.rb +24 -0
  52. data/lib/oddb/drugs/dose.rb +107 -0
  53. data/lib/oddb/drugs/galenic_form.rb +21 -0
  54. data/lib/oddb/drugs/galenic_group.rb +17 -0
  55. data/lib/oddb/drugs/package.rb +87 -0
  56. data/lib/oddb/drugs/part.rb +56 -0
  57. data/lib/oddb/drugs/product.rb +25 -0
  58. data/lib/oddb/drugs/sequence.rb +61 -0
  59. data/lib/oddb/drugs/substance.rb +31 -0
  60. data/lib/oddb/drugs/substance_group.rb +13 -0
  61. data/lib/oddb/drugs/unit.rb +12 -0
  62. data/lib/oddb/export.rb +4 -0
  63. data/lib/oddb/export/csv.rb +89 -0
  64. data/lib/oddb/export/l10n_sessions.rb +30 -0
  65. data/lib/oddb/export/rss.rb +44 -0
  66. data/lib/oddb/export/server.rb +58 -0
  67. data/lib/oddb/export/xls.rb +119 -0
  68. data/lib/oddb/export/yaml.rb +123 -0
  69. data/lib/oddb/html/state/drugs/admin/package.rb +189 -0
  70. data/lib/oddb/html/state/drugs/admin/product.rb +56 -0
  71. data/lib/oddb/html/state/drugs/admin/sequence.rb +259 -0
  72. data/lib/oddb/html/state/drugs/ajax/explain_ddd_price.rb +19 -0
  73. data/lib/oddb/html/state/drugs/ajax/explain_price.rb +19 -0
  74. data/lib/oddb/html/state/drugs/ajax/global.rb +18 -0
  75. data/lib/oddb/html/state/drugs/ajax/package_infos.rb +19 -0
  76. data/lib/oddb/html/state/drugs/ajax/remote_infos.rb +19 -0
  77. data/lib/oddb/html/state/drugs/atc_browser.rb +39 -0
  78. data/lib/oddb/html/state/drugs/atc_guidelines.rb +21 -0
  79. data/lib/oddb/html/state/drugs/compare.rb +52 -0
  80. data/lib/oddb/html/state/drugs/download_export.rb +18 -0
  81. data/lib/oddb/html/state/drugs/fachinfo.rb +21 -0
  82. data/lib/oddb/html/state/drugs/feedback.rb +94 -0
  83. data/lib/oddb/html/state/drugs/global.rb +266 -0
  84. data/lib/oddb/html/state/drugs/init.rb +18 -0
  85. data/lib/oddb/html/state/drugs/login.rb +17 -0
  86. data/lib/oddb/html/state/drugs/package.rb +32 -0
  87. data/lib/oddb/html/state/drugs/patinfo.rb +21 -0
  88. data/lib/oddb/html/state/drugs/products.rb +51 -0
  89. data/lib/oddb/html/state/drugs/result.rb +125 -0
  90. data/lib/oddb/html/state/global.rb +165 -0
  91. data/lib/oddb/html/state/global_predefine.rb +17 -0
  92. data/lib/oddb/html/state/limit.rb +17 -0
  93. data/lib/oddb/html/state/login.rb +56 -0
  94. data/lib/oddb/html/state/paypal/checkout.rb +130 -0
  95. data/lib/oddb/html/state/paypal/collect.rb +46 -0
  96. data/lib/oddb/html/state/paypal/redirect.rb +18 -0
  97. data/lib/oddb/html/state/register_export.rb +38 -0
  98. data/lib/oddb/html/state/register_poweruser.rb +17 -0
  99. data/lib/oddb/html/state/viral/admin.rb +76 -0
  100. data/lib/oddb/html/state/viral/poweruser.rb +16 -0
  101. data/lib/oddb/html/util/annotated_list.rb +39 -0
  102. data/lib/oddb/html/util/know_it_all.rb +28 -0
  103. data/lib/oddb/html/util/known_user.rb +55 -0
  104. data/lib/oddb/html/util/lookandfeel.rb +554 -0
  105. data/lib/oddb/html/util/need_all_input.rb +29 -0
  106. data/lib/oddb/html/util/session.rb +88 -0
  107. data/lib/oddb/html/util/sort.rb +72 -0
  108. data/lib/oddb/html/util/unsaved_helper.rb +20 -0
  109. data/lib/oddb/html/util/validator.rb +54 -0
  110. data/lib/oddb/html/view/ajax/json.rb +22 -0
  111. data/lib/oddb/html/view/alpha_header.rb +28 -0
  112. data/lib/oddb/html/view/document.rb +126 -0
  113. data/lib/oddb/html/view/drugs/admin/package.rb +237 -0
  114. data/lib/oddb/html/view/drugs/admin/product.rb +104 -0
  115. data/lib/oddb/html/view/drugs/admin/sequence.rb +312 -0
  116. data/lib/oddb/html/view/drugs/ajax/explain_ddd_price.rb +87 -0
  117. data/lib/oddb/html/view/drugs/ajax/explain_price.rb +61 -0
  118. data/lib/oddb/html/view/drugs/ajax/package_infos.rb +105 -0
  119. data/lib/oddb/html/view/drugs/ajax/remote_infos.rb +44 -0
  120. data/lib/oddb/html/view/drugs/atc_browser.rb +68 -0
  121. data/lib/oddb/html/view/drugs/atc_guidelines.rb +94 -0
  122. data/lib/oddb/html/view/drugs/compare.rb +95 -0
  123. data/lib/oddb/html/view/drugs/download_export.rb +28 -0
  124. data/lib/oddb/html/view/drugs/fachinfo.rb +46 -0
  125. data/lib/oddb/html/view/drugs/feedback.rb +231 -0
  126. data/lib/oddb/html/view/drugs/init.rb +51 -0
  127. data/lib/oddb/html/view/drugs/legend.rb +24 -0
  128. data/lib/oddb/html/view/drugs/package.rb +398 -0
  129. data/lib/oddb/html/view/drugs/patinfo.rb +46 -0
  130. data/lib/oddb/html/view/drugs/products.rb +97 -0
  131. data/lib/oddb/html/view/drugs/result.rb +296 -0
  132. data/lib/oddb/html/view/drugs/search.rb +33 -0
  133. data/lib/oddb/html/view/drugs/template.rb +15 -0
  134. data/lib/oddb/html/view/foot.rb +52 -0
  135. data/lib/oddb/html/view/google.rb +23 -0
  136. data/lib/oddb/html/view/google_ads.rb +40 -0
  137. data/lib/oddb/html/view/head.rb +78 -0
  138. data/lib/oddb/html/view/limit.rb +109 -0
  139. data/lib/oddb/html/view/list.rb +59 -0
  140. data/lib/oddb/html/view/login.rb +38 -0
  141. data/lib/oddb/html/view/navigation.rb +67 -0
  142. data/lib/oddb/html/view/offset_header.rb +35 -0
  143. data/lib/oddb/html/view/paypal/collect.rb +84 -0
  144. data/lib/oddb/html/view/paypal/redirect.rb +51 -0
  145. data/lib/oddb/html/view/paypal/register_form.rb +106 -0
  146. data/lib/oddb/html/view/register_export.rb +29 -0
  147. data/lib/oddb/html/view/register_poweruser.rb +29 -0
  148. data/lib/oddb/html/view/rss/feedback.rb +64 -0
  149. data/lib/oddb/html/view/rss_preview.rb +54 -0
  150. data/lib/oddb/html/view/search.rb +104 -0
  151. data/lib/oddb/html/view/snapback.rb +24 -0
  152. data/lib/oddb/html/view/template.rb +56 -0
  153. data/lib/oddb/import/excel.rb +45 -0
  154. data/lib/oddb/import/import.rb +39 -0
  155. data/lib/oddb/import/rtf.rb +410 -0
  156. data/lib/oddb/import/whocc.rb +173 -0
  157. data/lib/oddb/import/xml.rb +15 -0
  158. data/lib/oddb/model.rb +179 -0
  159. data/lib/oddb/persistence/odba.rb +33 -0
  160. data/lib/oddb/persistence/odba/business/company.rb +13 -0
  161. data/lib/oddb/persistence/odba/business/invoice.rb +15 -0
  162. data/lib/oddb/persistence/odba/drugs/atc.rb +15 -0
  163. data/lib/oddb/persistence/odba/drugs/galenic_form.rb +18 -0
  164. data/lib/oddb/persistence/odba/drugs/galenic_group.rb +13 -0
  165. data/lib/oddb/persistence/odba/drugs/package.rb +25 -0
  166. data/lib/oddb/persistence/odba/drugs/product.rb +13 -0
  167. data/lib/oddb/persistence/odba/drugs/sequence.rb +21 -0
  168. data/lib/oddb/persistence/odba/drugs/substance.rb +21 -0
  169. data/lib/oddb/persistence/odba/drugs/substance_group.rb +13 -0
  170. data/lib/oddb/persistence/odba/drugs/unit.rb +13 -0
  171. data/lib/oddb/persistence/odba/export.rb +26 -0
  172. data/lib/oddb/persistence/odba/model.rb +68 -0
  173. data/lib/oddb/persistence/odba/regulatory/authority.rb +13 -0
  174. data/lib/oddb/persistence/odba/regulatory/registration.rb +13 -0
  175. data/lib/oddb/persistence/odba/text/document.rb +11 -0
  176. data/lib/oddb/persistence/odba/util/code.rb +11 -0
  177. data/lib/oddb/persistence/odba/util/m10l_document.rb +13 -0
  178. data/lib/oddb/persistence/og.rb +16 -0
  179. data/lib/oddb/persistence/og/drugs/composition.rb +14 -0
  180. data/lib/oddb/persistence/og/drugs/product.rb +14 -0
  181. data/lib/oddb/persistence/og/drugs/sequence.rb +15 -0
  182. data/lib/oddb/persistence/og/model.rb +25 -0
  183. data/lib/oddb/persistence/og/util/multilingual.rb +13 -0
  184. data/lib/oddb/redist/rtf_tools/reader.rb +139 -0
  185. data/lib/oddb/regulatory/authority.rb +14 -0
  186. data/lib/oddb/regulatory/registration.rb +15 -0
  187. data/lib/oddb/remote/business/company.rb +23 -0
  188. data/lib/oddb/remote/drugs/active_agent.rb +27 -0
  189. data/lib/oddb/remote/drugs/atc.rb +32 -0
  190. data/lib/oddb/remote/drugs/dose.rb +8 -0
  191. data/lib/oddb/remote/drugs/galenic_form.rb +25 -0
  192. data/lib/oddb/remote/drugs/package.rb +126 -0
  193. data/lib/oddb/remote/drugs/part.rb +30 -0
  194. data/lib/oddb/remote/drugs/product.rb +19 -0
  195. data/lib/oddb/remote/drugs/sequence.rb +46 -0
  196. data/lib/oddb/remote/drugs/substance.rb +20 -0
  197. data/lib/oddb/remote/drugs/unit.rb +19 -0
  198. data/lib/oddb/remote/object.rb +36 -0
  199. data/lib/oddb/remote/text/document.rb +20 -0
  200. data/lib/oddb/remote/util/m10l_document.rb +22 -0
  201. data/lib/oddb/text/chapter.rb +27 -0
  202. data/lib/oddb/text/document.rb +43 -0
  203. data/lib/oddb/text/format.rb +37 -0
  204. data/lib/oddb/text/paragraph.rb +58 -0
  205. data/lib/oddb/text/picture.rb +93 -0
  206. data/lib/oddb/text/table.rb +68 -0
  207. data/lib/oddb/util.rb +8 -0
  208. data/lib/oddb/util/annotated_list.rb +37 -0
  209. data/lib/oddb/util/code.rb +69 -0
  210. data/lib/oddb/util/comparison.rb +36 -0
  211. data/lib/oddb/util/exporter.rb +8 -0
  212. data/lib/oddb/util/feedback.rb +23 -0
  213. data/lib/oddb/util/ipn.rb +48 -0
  214. data/lib/oddb/util/m10l_document.rb +38 -0
  215. data/lib/oddb/util/mail.rb +73 -0
  216. data/lib/oddb/util/money.rb +60 -0
  217. data/lib/oddb/util/multilingual.rb +70 -0
  218. data/lib/oddb/util/quanty.rb +4 -0
  219. data/lib/oddb/util/quanty/fact.rb +229 -0
  220. data/lib/oddb/util/quanty/main.rb +160 -0
  221. data/lib/oddb/util/quanty/parse.rb +853 -0
  222. data/lib/oddb/util/quanty/units.dump +0 -0
  223. data/lib/oddb/util/server.rb +117 -0
  224. data/lib/oddb/util/updater.rb +41 -0
  225. data/lib/oddb/util/ydim.rb +110 -0
  226. data/lib/oddb/util/yus.rb +46 -0
  227. data/test/business/test_company.rb +29 -0
  228. data/test/business/test_price.rb +46 -0
  229. data/test/drugs/test_active_agent.rb +53 -0
  230. data/test/drugs/test_atc.rb +54 -0
  231. data/test/drugs/test_composition.rb +88 -0
  232. data/test/drugs/test_ddd.rb +22 -0
  233. data/test/drugs/test_dose.rb +190 -0
  234. data/test/drugs/test_galenic_form.rb +41 -0
  235. data/test/drugs/test_package.rb +173 -0
  236. data/test/drugs/test_part.rb +32 -0
  237. data/test/drugs/test_product.rb +31 -0
  238. data/test/drugs/test_sequence.rb +140 -0
  239. data/test/drugs/test_substance.rb +51 -0
  240. data/test/drugs/test_substance_group.rb +27 -0
  241. data/test/export/test_rss.rb +94 -0
  242. data/test/export/test_server.rb +117 -0
  243. data/test/export/test_xls.rb +152 -0
  244. data/test/export/test_yaml.rb +120 -0
  245. data/test/import/data/html/whocc/A.html +56 -0
  246. data/test/import/data/html/whocc/A03.html +48 -0
  247. data/test/import/data/html/whocc/A03AB.html +48 -0
  248. data/test/import/data/html/whocc/A06AA.html +47 -0
  249. data/test/import/data/html/whocc/C03.html +47 -0
  250. data/test/import/data/html/whocc/login.html +77 -0
  251. data/test/import/data/xml/ATC_2006.xml +47 -0
  252. data/test/import/data/xml/ATC_2006_ddd.xml +35 -0
  253. data/test/import/test_excel.rb +34 -0
  254. data/test/import/test_rtf.rb +40 -0
  255. data/test/import/test_whocc.rb +315 -0
  256. data/test/remote/drugs/test_active_agent.rb +36 -0
  257. data/test/selenium/selenium-server.jar +0 -0
  258. data/test/selenium/test_atc_browser.rb +122 -0
  259. data/test/selenium/test_atc_guidelines.rb +96 -0
  260. data/test/selenium/test_collect.rb +138 -0
  261. data/test/selenium/test_compare.rb +206 -0
  262. data/test/selenium/test_fachinfo.rb +130 -0
  263. data/test/selenium/test_feedback.rb +196 -0
  264. data/test/selenium/test_init.rb +52 -0
  265. data/test/selenium/test_limit.rb +305 -0
  266. data/test/selenium/test_login.rb +67 -0
  267. data/test/selenium/test_package.rb +512 -0
  268. data/test/selenium/test_patinfo.rb +131 -0
  269. data/test/selenium/test_product.rb +80 -0
  270. data/test/selenium/test_products.rb +142 -0
  271. data/test/selenium/test_search.rb +715 -0
  272. data/test/selenium/test_sequence.rb +543 -0
  273. data/test/selenium/unit.rb +185 -0
  274. data/test/stub/http_server.rb +169 -0
  275. data/test/stub/model.rb +173 -0
  276. data/test/suite.rb +15 -0
  277. data/test/test_model.rb +83 -0
  278. data/test/util/test_code.rb +74 -0
  279. data/test/util/test_ipn.rb +117 -0
  280. data/test/util/test_mail.rb +86 -0
  281. data/test/util/test_multilingual.rb +97 -0
  282. data/test/util/test_server.rb +48 -0
  283. data/test/util/test_updater.rb +353 -0
  284. data/test/util/test_ydim.rb +115 -0
  285. data/test/util/test_yus.rb +79 -0
  286. metadata +418 -0
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env ruby
2
+ # Util::Server -- de.oddb.org -- 01.09.2006 -- hwyss@ywesee.com
3
+
4
+ require 'oddb/html/util/known_user'
5
+ require 'oddb/html/util/session'
6
+ require 'oddb/html/util/validator'
7
+ require 'oddb/util/exporter'
8
+ require 'oddb/util/ipn'
9
+ require 'oddb/util/updater'
10
+ require 'oddb/export/rss'
11
+ require 'paypal'
12
+ require 'sbsm/drbserver'
13
+
14
+ module ODDB
15
+ module Util
16
+ class Server < SBSM::DRbServer
17
+ ENABLE_ADMIN = true
18
+ SESSION = Html::Util::Session
19
+ VALIDATOR = Html::Util::Validator
20
+ def initialize(*args)
21
+ super
22
+ @rss_mutex = Mutex.new
23
+ run_exporter if(ODDB.config.run_exporter)
24
+ run_updater if(ODDB.config.run_updater)
25
+ end
26
+ def _admin(src, result, priority=0)
27
+ raise "admin interface disabled" unless(self::class::ENABLE_ADMIN)
28
+ t = Thread.new {
29
+ Thread.current.abort_on_exception = false
30
+ begin
31
+ response = instance_eval(src)
32
+ str = response.to_s
33
+ result << if(str.length > 200)
34
+ response.class
35
+ else
36
+ str
37
+ end.to_s
38
+ rescue StandardError => error
39
+ result << error.message
40
+ require 'pp'
41
+ ODDB.logger.error('admin') { error.class }
42
+ ODDB.logger.error('admin') { error.message }
43
+ ODDB.logger.error('admin') { error.backtrace.pretty_inspect }
44
+ error
45
+ end
46
+ }
47
+ t[:source] = src
48
+ t.priority = priority
49
+ @admin_threads.add(t)
50
+ t
51
+ end
52
+ def create_product name
53
+ if prod = ODDB::Drugs::Product.find_by_name(name)
54
+ "The product already exists. You may edit it at http://de.oddb.org/de/drugs/product/uid/#{prod.uid}"
55
+ else
56
+ prod = ODDB::Drugs::Product.new
57
+ prod.name.de = name
58
+ prod.save
59
+ "Success! You may now edit the product at http://de.oddb.org/de/drugs/product/uid/#{prod.uid}"
60
+ end
61
+ end
62
+ def generate_dictionary(language, locale)
63
+ ODBA.storage.remove_dictionary(language)
64
+ base = File.join(ODDB.config.data_dir,
65
+ "fulltext", "data", "dicts", language)
66
+ ODBA.storage.generate_dictionary(language, locale, base)
67
+ end
68
+ def generate_dictionaries
69
+ generate_dictionary('german', 'de_DE@euro')
70
+ end
71
+ def ipn(notification)
72
+ Util::Ipn.process notification
73
+ nil # don't return the invoice back across drb - it's not defined in yipn
74
+ end
75
+ def login(email, pass)
76
+ session = ODDB.auth.login(email, pass, ODDB.config.auth_domain)
77
+ Html::Util::KnownUser.new(session)
78
+ end
79
+ def logout(session)
80
+ ODDB.auth.logout(session)
81
+ rescue DRb::DRbError, RangeError, NameError
82
+ end
83
+ def run_at(hour, &block)
84
+ Thread.new {
85
+ loop {
86
+ now = Time.now
87
+ run_at = Time.local(now.year, now.month, now.day, hour)
88
+ while(now > run_at)
89
+ run_at += 24*60*60
90
+ end
91
+ sleep(run_at - now)
92
+ block.call
93
+ }
94
+ }
95
+ end
96
+ def run_exporter
97
+ @exporter = run_at(ODDB.config.export_hour) { Exporter.run }
98
+ end
99
+ def run_updater
100
+ @updater = run_at(ODDB.config.update_hour) { Updater.run }
101
+ end
102
+ def update_feedback_rss_feed
103
+ async {
104
+ begin
105
+ @rss_mutex.synchronize {
106
+ Export::Rss::Feedback.new.export
107
+ }
108
+ rescue StandardError => error
109
+ ODDB.logger.error('rss_feed') { error.class }
110
+ ODDB.logger.error('rss_feed') { error.message }
111
+ ODDB.logger.error('rss_feed') { error.backtrace.pretty_inspect }
112
+ end
113
+ }
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # Util::Updater -- de.oddb.org -- 02.02.2007 -- hwyss@ywesee.com
4
+
5
+ require 'date'
6
+ require 'mechanize'
7
+ require 'oddb/import/whocc'
8
+ require 'oddb/util/mail'
9
+
10
+ module ODDB
11
+ module Util
12
+ module Updater
13
+ def Updater.import_whocc_guidelines
14
+ reported_import(Import::Whocc::Guidelines.new,
15
+ WWW::Mechanize.new)
16
+ end
17
+ def Updater.reported_import(importer, io, subject=nil)
18
+ _reported_import(importer, subject) { importer.import io }
19
+ end
20
+ def Updater._reported_import(importer, subject=nil, &block)
21
+ lines = [
22
+ sprintf("%s: %s#import", Time.now.strftime('%c'), importer.class)
23
+ ]
24
+ lines.concat block.call
25
+ rescue StandardError => err
26
+ lines.push(err.class.to_s, err.message, *err.backtrace)
27
+ if importer.respond_to?(:report)
28
+ lines.concat importer.report rescue [$!.message]
29
+ end
30
+ raise
31
+ ensure
32
+ subject = sprintf("%s: %s",
33
+ Time.now.strftime('%c'), subject || importer.class)
34
+ Mail.notify_admins(subject, lines)
35
+ end
36
+ def Updater.run(today = Date.today)
37
+ ## disabled until 2.0
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env ruby
2
+ # Util::Ydim -- de.oddb.org -- 30.01.2008 -- hwyss@ywesee.com
3
+
4
+ require 'ydim/config'
5
+ require 'ydim/client'
6
+ require 'oddb/config'
7
+ require 'oddb/util/yus'
8
+ require 'openssl'
9
+
10
+ module ODDB
11
+ module Util
12
+ module Ydim
13
+ DATE_FMT = "%d.%m.%Y"
14
+ SALUTATIONS = {
15
+ 'salutation_m' => 'Herr',
16
+ 'salutation_f' => 'Frau',
17
+ }
18
+ def Ydim.connect(&block)
19
+ config = YDIM::Client::CONFIG
20
+ server = DRbObject.new(nil, config.server_url)
21
+ client = YDIM::Client.new(config)
22
+ key = OpenSSL::PKey::DSA.new(File.read(config.private_key))
23
+ client.login(server, key)
24
+ block.call(client)
25
+ ensure
26
+ client.logout if(client)
27
+ end
28
+ def Ydim.create_debitor(email)
29
+ connect { |client|
30
+ keys = [ :salutation, :name_last, :name_first ]
31
+ info = Util::Yus.get_preferences(email, keys)
32
+ debitor = client.create_debitor
33
+ debitor.salutation = SALUTATIONS[info[:salutation]]
34
+ debitor.contact_firstname = info[:name_first]
35
+ debitor.contact = info[:name_last]
36
+ debitor.debitor_type = 'dt_info'
37
+ debitor.email = email
38
+ debitor.save
39
+ debitor
40
+ }
41
+ end
42
+ def Ydim.debitor_id(email)
43
+ if(id = Util::Yus.get_preference(email, :ydim_id))
44
+ id
45
+ elsif(debitor = identify_debitor(email))
46
+ debitor.unique_id
47
+ else
48
+ create_debitor(email).unique_id
49
+ end
50
+ end
51
+ def Ydim.identify_debitor(email)
52
+ connect { |client|
53
+ client.search_debitors(email).first
54
+ }
55
+ end
56
+ def Ydim.inject(invoice, opts = {:payment_received => false})
57
+ if(id = invoice.ydim_id)
58
+ Ydim.connect { |client| client.invoice(id) }
59
+ elsif(email = invoice.yus_name)
60
+ ydim_inv = inject_from_items(invoice_date(invoice), email, invoice.items,
61
+ invoice.currency || 'EUR')
62
+ ydim_inv.payment_received = opts[:payment_received]
63
+ ydim_inv.save
64
+ invoice.ydim_id = ydim_inv.unique_id
65
+ invoice.save
66
+ ydim_inv
67
+ end
68
+ end
69
+ def Ydim.inject_from_items(date, email, items, currency='EUR')
70
+ connect { |client|
71
+ debitor_id = debitor_id(email)
72
+ Util::Yus.set_preference(email, :ydim_id, debitor_id)
73
+ ydim_inv = client.create_invoice(debitor_id)
74
+ ydim_inv.description = invoice_description(items)
75
+ ydim_inv.date = date
76
+ ydim_inv.currency = currency
77
+ ydim_inv.payment_period = ODDB.config.payment_period
78
+ item_data = sort_items(items).collect { |item|
79
+ if(sprintf('%1.2f', item.quantity) == "0.00")
80
+ ydim_inv.precision = 3
81
+ end
82
+ item.ydim_data
83
+ }
84
+ client.add_items(ydim_inv.unique_id, item_data)
85
+ ydim_inv
86
+ }
87
+ end
88
+ def Ydim.invoice_date(invoice)
89
+ Date.new(invoice.time.year, invoice.time.month, invoice.time.day)
90
+ end
91
+ def Ydim.invoice_description(items)
92
+ types = []
93
+ items.each { |item| types.push(item.type) }
94
+ main = items.first
95
+ if(types.include?(:poweruser))
96
+ exp = main.expiry_time || main.time + (24 * 60 *60)
97
+ sprintf("PowerUser %s %s - %s", ODDB.config.server_name,
98
+ main.time.strftime(DATE_FMT), exp.strftime(DATE_FMT))
99
+ else
100
+ sprintf("%s %s", ODDB.config.server_name, main.time.strftime(DATE_FMT))
101
+ end
102
+ end
103
+ def Ydim.sort_items(items)
104
+ items.sort_by { |item|
105
+ [item.time.to_i / (24 * 60 * 60), item.text, item.type.to_s]
106
+ }
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+ # Yus -- de.oddb.org -- 30.01.2008 -- hwyss@ywesee.com
3
+
4
+ require 'drb'
5
+ require 'yus/session'
6
+
7
+ module ODDB
8
+ module Util
9
+ module Yus
10
+ def Yus.create_user(email, pass=nil)
11
+ Yus.server.autosession(ODDB.config.auth_domain) { |session|
12
+ session.create_entity(email, pass)
13
+ }
14
+ # if there is a password, we can log in
15
+ ODDB.server.login(email, pass) if(pass)
16
+ end
17
+ def Yus.get_preference(name, key)
18
+ Yus.server.autosession(ODDB.config.auth_domain) { |session|
19
+ session.get_entity_preference(name, key)
20
+ }
21
+ rescue ::Yus::YusError
22
+ nil # return nil
23
+ end
24
+ def Yus.get_preferences(name, *keys)
25
+ Yus.server.autosession(ODDB.config.auth_domain) { |session|
26
+ session.get_entity_preferences(name, keys.flatten)
27
+ }
28
+ rescue ::Yus::YusError
29
+ {} # return an empty hash
30
+ end
31
+ def Yus.grant(name, key, item, expires=nil)
32
+ Yus.server.autosession(ODDB.config.auth_domain) { |session|
33
+ session.grant(name, key, item, expires)
34
+ }
35
+ end
36
+ def Yus.server
37
+ DRb::DRbObject.new(nil, ODDB.config.auth_server)
38
+ end
39
+ def Yus.set_preference(name, key, value, domain=ODDB.config.auth_domain)
40
+ Yus.server.autosession(ODDB.config.auth_domain) { |session|
41
+ session.set_entity_preference(name, key, value, domain)
42
+ }
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # Business::TestCompany -- de.oddb.org -- 22.11.2006 -- hwyss@ywesee.com
3
+
4
+
5
+ $: << File.expand_path('../../lib', File.dirname(__FILE__))
6
+
7
+ require 'flexmock'
8
+ require 'test/unit'
9
+ require 'oddb/business/company'
10
+
11
+ module ODDB
12
+ module Business
13
+ class TestCompany < Test::Unit::TestCase
14
+ include FlexMock::TestCase
15
+ def setup
16
+ @company = Company.new
17
+ end
18
+ def test_packages
19
+ prod1 = flexmock('product')
20
+ prod2 = flexmock('product')
21
+ @company.add_product(prod1)
22
+ @company.add_product(prod2)
23
+ prod1.should_receive(:packages).and_return(['foo', 'bar'])
24
+ prod2.should_receive(:packages).and_return(['baz'])
25
+ assert_equal(['foo', 'bar', 'baz'], @company.packages)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+ # Business::TestPrice -- ch.oddb.org -- 24.07.2009 -- hwyss@ywesee.com
3
+
4
+ $: << File.expand_path('../../lib', File.dirname(__FILE__))
5
+
6
+ require 'test/unit'
7
+ require 'oddb/business/price'
8
+ require 'oddb/util/money'
9
+
10
+ module ODDB
11
+ module Business
12
+ class TestPrice < Test::Unit::TestCase
13
+ def setup
14
+ @price = Price.new
15
+ end
16
+ def test_empty
17
+ assert_nil @price.current
18
+ assert_equal 0.0, @price.to_f
19
+ assert_equal true, @price.is_for?(nil, nil)
20
+ assert_equal false, @price.is_for?(nil, 'CH')
21
+ assert_equal false, @price.is_for?(:public, nil)
22
+ end
23
+ def test_values
24
+ @price.value = Util::Money.new 12.5
25
+ assert_equal 12.5, @price
26
+ older = Util::Money.new 10.5
27
+ time = Time.now - 3600
28
+ older.valid_from = time
29
+ @price.value = older
30
+ assert_equal 12.5, @price
31
+ assert_equal 10.5, @price.at(time)
32
+ @price.value = 15
33
+ assert_equal 15, @price
34
+ assert_instance_of Util::Money, @price.current
35
+ time = Time.now - 1800
36
+ @price.value = 11, time
37
+ assert_equal 11, @price.at(time)
38
+ end
39
+ def test_argument_error
40
+ assert_raises(ArgumentError) do
41
+ @price.value = "foobar"
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+ # Drugs::TestActiveAgent -- de.oddb.org -- 22.11.2006 -- hwyss@ywesee.com
3
+
4
+ $: << File.expand_path('../../lib', File.dirname(__FILE__))
5
+
6
+ require 'flexmock'
7
+ require 'test/unit'
8
+ require 'oddb/drugs/active_agent'
9
+ require 'oddb/drugs/dose'
10
+
11
+ module ODDB
12
+ module Drugs
13
+ class TestActiveAgent < Test::Unit::TestCase
14
+ include FlexMock::TestCase
15
+ def test_create
16
+ substance = flexmock('substance')
17
+ dose = Dose.new(100, 'mg')
18
+ agent = ActiveAgent.new(substance, dose)
19
+ assert_equal(dose, agent.dose)
20
+ agent = ActiveAgent.new(substance, 100, 'mg')
21
+ assert_equal(dose, agent.dose)
22
+ end
23
+ def test_equality
24
+ substance = flexmock('substance')
25
+ dose = Dose.new(100, 'mg')
26
+ agent = ActiveAgent.new(substance, dose)
27
+ equal = ActiveAgent.new(substance, dose)
28
+ assert_equal(true, agent == equal)
29
+ assert_equal(true, equal == agent)
30
+
31
+ other = ActiveAgent.new(substance, Dose.new(200, 'mg'))
32
+ assert_equal(false, other == agent)
33
+ assert_equal(false, agent == other)
34
+
35
+ substance = flexmock('different substance')
36
+ other = ActiveAgent.new(substance, dose)
37
+ assert_equal(false, other == agent)
38
+ assert_equal(false, agent == other)
39
+
40
+ other.chemical_equivalence = equal
41
+ assert_equal(true, other == agent)
42
+ assert_equal(true, agent == other)
43
+ end
44
+ def test_equality__nil
45
+ substance = flexmock('substance')
46
+ dose = Dose.new(100, 'mg')
47
+ agent = ActiveAgent.new(substance, dose)
48
+
49
+ assert_equal(false, agent == nil)
50
+ end
51
+ end
52
+ end
53
+ end