bosdk 1.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2010 Shane Emmons
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ BOSDK.gem
2
+ =========
3
+
4
+ Description
5
+ -----------
6
+
7
+ A JRuby wrapper for the Business Objects SDK
8
+
9
+ Requirements
10
+ ------------
11
+
12
+ - The Business Objects Java SDK
13
+ - An environment variable 'BOE_JAVA_LIB' pointing to the Business Objects Java
14
+ SDK directory
15
+ - JRuby >= 1.4.0
16
+
17
+ Usage
18
+ -----
19
+
20
+ require 'bosdk'
21
+ include BOSDK
22
+ session = EnterpriseSession.new('cms', 'Administrator', '')
23
+
24
+ stmt = "SELECT TOP 10 * FROM CI_SYSTEMOBJECTS WHERE SI_KIND='User'"
25
+ session.query(stmt).each do |obj|
26
+ puts obj.path
27
+ end
28
+
29
+ session.disconnect
30
+
31
+ Alternatively you can use the #connect closure.
32
+
33
+ require 'bosdk'
34
+ BOSDK.connect('cms', 'Administrator', '') do |session|
35
+ stmt = "SELECT TOP 10 * FROM CI_SYSTEMOBJECTS WHERE SI_KIND='User'"
36
+ session.query(stmt).each do |obj|
37
+ puts obj.path
38
+ end
39
+ end
40
+
41
+ BOIRB
42
+ -----
43
+
44
+ The library ships with an extension to the standard irb shell that connects you
45
+ to a cms and gives you a handful of helpful shortcuts.
46
+
47
+ connect(cms, username, password, options = Hash.new)
48
+ Creates a new EnterpriseSession and binds it to @boe.
49
+
50
+ connected?
51
+ Tests whether @boe is connected to a cms.
52
+
53
+ disconnect
54
+ Disconnects @boe from the cms.
55
+
56
+ query(stmt)
57
+ Runs the provided query on @boe and returns the resulting InfoObject array.
58
+
59
+ open_webi(docid)
60
+ Opens the specified InfoObject using a ReportEngine and returns a handle to the
61
+ WebiInstance. It also creates the following instance variables: @doc, @objs and
62
+ @vars. @doc is a handle to the WebiInstance, @objs is an alias for @doc.objects
63
+ and @vars is an alias for @doc.variables.
64
+
65
+ objects
66
+ Shortcut to @objs which is an alias for @doc.objects
67
+
68
+ variables
69
+ Shortcut to @vars which is an alias for @doc.variables
70
+
71
+ Resources
72
+ ---------
73
+
74
+ - [Website](http://semmons99.github.com/bosdk)
75
+ - [Git Repo](http://github.com/semmons99/bosdk)
76
+ - [Twitter](http://twitter.com/bosdk_gem)
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'rake/clean'
3
+
4
+ CLOBBER.include('doc', '.yardoc')
5
+
6
+ def gemspec
7
+ @gemspec ||= begin
8
+ file = File.expand_path("../bosdk.gemspec", __FILE__)
9
+ eval(File.read(file), binding, file)
10
+ end
11
+ end
12
+
13
+ require 'rspec/core/rake_task'
14
+ RSpec::Core::RakeTask.new
15
+ task :default => :spec
16
+ task :test => :spec
17
+
18
+ require 'yard'
19
+ YARD::Rake::YardocTask.new
20
+
21
+ require 'rake/gempackagetask'
22
+ Rake::GemPackageTask.new(gemspec) do |pkg|
23
+ pkg.gem_spec = gemspec
24
+ end
25
+ task :gem => :gemspec
26
+
27
+ desc "Validate the gemspec"
28
+ task :gemspec do
29
+ gemspec.validate
30
+ end
data/bin/boirb ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env jruby
2
+
3
+ require 'irb'
4
+
5
+ module IRB
6
+ def self.start_session(binding)
7
+ IRB.setup(nil)
8
+
9
+ workspace = WorkSpace.new(binding)
10
+
11
+ if @CONF[:SCRIPT]
12
+ irb = Irb.new(workspace, @CONF[:SCRIPT])
13
+ else
14
+ irb = Irb.new(workspace)
15
+ end
16
+
17
+ @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
18
+ @CONF[:MAIN_CONTEXT] = irb.context
19
+
20
+ trap("SIGINT") do
21
+ irb.signal_handle
22
+ end
23
+
24
+ catch(:IRB_EXIT) do
25
+ irb.eval_input
26
+ end
27
+ end
28
+ end
29
+
30
+ require 'bosdk'
31
+
32
+ def connect(cms, username, password, options = Hash.new)
33
+ @boe = BOSDK::EnterpriseSession.new(cms, username, password, options)
34
+ end
35
+
36
+ def connected?
37
+ @boe and @boe.connected?
38
+ end
39
+
40
+ def disconnect
41
+ @boe.disconnect if connected?
42
+ end
43
+
44
+ def query(stmt)
45
+ @boe.query(stmt) if connected?
46
+ end
47
+
48
+ def open_webi(docid)
49
+ @doc = @boe.open_webi(docid) if connected?
50
+ @objs = @doc.objects
51
+ @vars = @doc.variables
52
+ @doc
53
+ end
54
+
55
+ def objects
56
+ @objs
57
+ end
58
+
59
+ def variables
60
+ @vars
61
+ end
62
+
63
+ IRB.start_session(Kernel.binding)
data/bosdk.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "bosdk"
3
+ s.version = "1.2.0"
4
+ s.platform = "java"
5
+ s.authors = ["Shane Emmons"]
6
+ s.email = "semmons99@gmail.com"
7
+ s.homepage = "http://semmons99.github.com/bosdk"
8
+ s.summary = "JRuby Business Object Java SDK wrapper"
9
+ s.description = "A JRuby wrapper for the Business Objects Java SDK"
10
+
11
+ s.required_rubygems_version = ">= 1.3.6"
12
+
13
+ s.requirements = ["An environment variable 'BOE_JAVA_LIB' pointing to the Business Objects Java SDK directory"]
14
+
15
+ s.add_development_dependency "rspec", ">= 2.0.0"
16
+ s.add_development_dependency "yard"
17
+
18
+ s.files = Dir.glob("{bin,lib,spec}/**/*")
19
+ s.files += %w(README.md LICENSE)
20
+ s.files += %w(Rakefile .gemtest bosdk.gemspec)
21
+
22
+ s.executables = ["boirb"]
23
+ s.require_path = "lib"
24
+ end
25
+
@@ -0,0 +1,54 @@
1
+ module BOSDK
2
+ # Creates a wrapper around the Business Objects Java SDK.
3
+ class EnterpriseSession
4
+ # The underlying IEnterpriseSession
5
+ attr_reader :session
6
+
7
+ # The underlying IInfoStore
8
+ attr_reader :infostore
9
+
10
+ # Creates a new EnterpriseSession object, connecting to the specified CMS.
11
+ # EnterpriseSession.new('cms', 'Administrator', '')
12
+ #
13
+ # Automatically calls disconnect when cleaned up.
14
+ def initialize(cms, username, password, options = Hash.new)
15
+ @session = CrystalEnterprise.getSessionMgr.logon(username, password, cms, 'secEnterprise')
16
+ @infostore = @session.getService('', 'InfoStore')
17
+ @connected = true
18
+ @locale = options[:locale] || 'en_US'
19
+
20
+ at_exit { disconnect }
21
+ end
22
+
23
+ # Returns true/false if connected to the CMS.
24
+ def connected?
25
+ return @connected
26
+ end
27
+
28
+ # Disconnects from the CMS is connected.
29
+ def disconnect
30
+ @session.logoff if connected?
31
+ @session = nil
32
+ @connected = false
33
+ nil
34
+ end
35
+
36
+ # Converts 'path://', 'query://' and 'cuid://' special forms to a SDK query
37
+ def path_to_sql(path_stmt)
38
+ @infostore.getStatelessPageInfo(path_stmt, PagingQueryOptions.new).getPageSQL
39
+ end
40
+
41
+ # Queries the InfoStore with the provided statement, returning an Array of
42
+ # InfoObject(s).
43
+ def query(stmt)
44
+ sql = stmt.match(/^(path|query|cuid):\/\//i) ? path_to_sql(stmt) : stmt
45
+ @infostore.query(sql).map{|o| InfoObject.new(o)}
46
+ end
47
+
48
+ # Open a Webi document from the provided docid
49
+ def open_webi(docid)
50
+ @webi_report_engine ||= WebiReportEngine.new(@session, @locale)
51
+ WebiInstance.new(@webi_report_engine.open(docid))
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,53 @@
1
+ module BOSDK
2
+ # Creates a wrapper around an IInfoObject.
3
+ class InfoObject
4
+ # The underlying IInfoObject.
5
+ attr_reader :obj
6
+
7
+ # Creates a new InfoObject from the provided IInfoObject.
8
+ # InfoObject.new(obj)
9
+ def initialize(obj)
10
+ @obj = obj
11
+ end
12
+
13
+ # Returns the Business Objects ID (alias for #getID).
14
+ def docid
15
+ getID
16
+ end
17
+
18
+ # Returns true/false if #obj is a root node.
19
+ def is_root?
20
+ parent_id.nil? or parent_id == 0 or parent_id == docid
21
+ end
22
+
23
+ # Returns the parent of #obj as an InfoObject
24
+ def parent
25
+ return nil if is_root?
26
+ @parent ||= InfoObject.new(getParent)
27
+ end
28
+
29
+ # Returns the path of #obj as a String.
30
+ def path
31
+ @path ||= (is_root? ? '' : parent.path) + "/#{title}"
32
+ end
33
+
34
+ # Compares one InfoObject to another by #title.
35
+ def <=>(other_infoobject)
36
+ title <=> other_infoobject.title
37
+ end
38
+
39
+ # Forwards method to underlying IInfoObject and stores the results
40
+ def method_missing(method, *args)
41
+ eval "return @#{method.to_s}" if instance_variables.include?("@#{method.to_s}")
42
+ if @obj.respond_to?(method)
43
+ eval "return @#{method.to_s} = @obj.send(method, *args)"
44
+ end
45
+ super
46
+ end
47
+
48
+ # Returns true if underlying IInfoObject#respond_to? is true
49
+ def respond_to?(method)
50
+ @obj.respond_to?(method) || super
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,46 @@
1
+ module BOSDK
2
+ # Creates a wrapper around a DocumentInstance
3
+ class WebiInstance
4
+ # The underlying DocumentInstance
5
+ attr_reader :instance
6
+
7
+ # Create a new WebiInstance from the provided DocumentInstance
8
+ def initialize(instance)
9
+ @instance = instance
10
+ end
11
+
12
+ # Returns an array of hashes representing report objects.
13
+ def objects
14
+ return @objects unless @objects.nil?
15
+ objs = []
16
+ dict = @instance.getDictionary
17
+ (0 ... dict.getChildCount).each do |i|
18
+ obj = dict.getChildAt(i)
19
+ objs << {
20
+ :name => obj.getName,
21
+ :qual => obj.getQualification.toString.downcase.to_sym,
22
+ :type => obj.getType.toString.downcase.to_sym,
23
+ :object => obj,
24
+ }
25
+ end
26
+ @objects = objs
27
+ end
28
+
29
+ # Returns an array of hashes representing report variables.
30
+ def variables
31
+ return @variables unless @variables.nil?
32
+ vars = []
33
+ dict = @instance.getDictionary
34
+ dict.getVariables.each do |var|
35
+ vars << {
36
+ :name => var.getName,
37
+ :qual => var.getQualification.toString.downcase.to_sym,
38
+ :type => var.getType.toString.downcase.to_sym,
39
+ :formula => var.getFormula.getValue,
40
+ :variable => var,
41
+ }
42
+ end
43
+ @variables = vars
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,22 @@
1
+ module BOSDK
2
+ # Creates a wrapper around a Webi based ReportEngine.
3
+ class WebiReportEngine
4
+ # The underlying ReportEngine.
5
+ attr_reader :webi_report_engine
6
+
7
+ # Creates a new ReportEngine using the provided EnterpriseSession and an
8
+ # optional locale setting.
9
+ # WebiReportEngine.new(enterprise_session)
10
+ def initialize(enterprise_session, locale = "en_US")
11
+ report_engines = enterprise_session.getService("ReportEngines")
12
+ @webi_report_engine = report_engines.getService(ReportEngines::ReportEngineType::WI_REPORT_ENGINE)
13
+ @webi_report_engine.setLocale(locale)
14
+ #enterprise_session.setAttribute("widReportEngine", @webi_report_engine)
15
+ end
16
+
17
+ # Opens the webi document specified by the docid.
18
+ def open(docid)
19
+ @webi_report_engine.openDocument(docid)
20
+ end
21
+ end
22
+ end
data/lib/bosdk.rb ADDED
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2010 Shane Emmons
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person
4
+ # obtaining a copy of this software and associated documentation
5
+ # files (the "Software"), to deal in the Software without
6
+ # restriction, including without limitation the rights to use,
7
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the
9
+ # Software is furnished to do so, subject to the following
10
+ # conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ # OTHER DEALINGS IN THE SOFTWARE.
23
+ include Java
24
+ Dir.glob(ENV["BOE_JAVA_LIB"] + "/*.jar").each{|jar| require jar}
25
+ include_class "com.crystaldecisions.sdk.framework.CrystalEnterprise"
26
+ include_class "com.crystaldecisions.sdk.uri.PagingQueryOptions"
27
+ include_class "com.businessobjects.rebean.wi.ReportEngines"
28
+
29
+ require 'bosdk/enterprise_session'
30
+ require 'bosdk/info_object'
31
+ require 'bosdk/webi_report_engine'
32
+ require 'bosdk/webi_instance'
33
+
34
+ module BOSDK
35
+ # A closure over EnterpriseSession
36
+ def BOSDK.connect(cms, username, password, options = Hash.new, &block)
37
+ session = EnterpriseSession.new(cms, username, password, options)
38
+ yield session
39
+ session.disconnect
40
+ end
41
+ end
@@ -0,0 +1,21 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
2
+ require 'bosdk'
3
+
4
+ module BOSDK
5
+ describe BOSDK do
6
+ describe "#connect" do
7
+ before(:each) do
8
+ @es = mock("EnterpriseSession").as_null_object
9
+ class EnterpriseSession; end
10
+ EnterpriseSession.should_receive(:new).once.with('cms', 'Administrator', '', {:locale => "en_US"}).and_return(@es)
11
+ @es.should_receive(:disconnect).once.with.and_return
12
+ end
13
+
14
+ specify "wraps EnterpriseSession#new in a closure" do
15
+ BOSDK.connect('cms', 'Administrator', '', :locale => "en_US") do |session|
16
+ session.should == @es
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,170 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
2
+ require 'bosdk/enterprise_session'
3
+
4
+ module BOSDK
5
+ describe EnterpriseSession do
6
+ before(:each) do
7
+ @session_mgr = mock("ISessionMgr").as_null_object
8
+ @session = mock("IEnterpriseSession").as_null_object
9
+ @infostore = mock("IInfoStore").as_null_object
10
+ @infoobjects = mock("IInfoObjects").as_null_object
11
+
12
+ class CrystalEnterprise; end
13
+ CrystalEnterprise.should_receive(:getSessionMgr).at_least(1).with.and_return(@session_mgr)
14
+ @session_mgr.should_receive(:logon).at_least(1).with('Administrator', '', 'cms', 'secEnterprise').and_return(@session)
15
+ @session.should_receive(:getService).at_least(1).with('', 'InfoStore').and_return(@infostore)
16
+
17
+ @es = EnterpriseSession.new('cms', 'Administrator', '')
18
+ end
19
+
20
+ describe "#new" do
21
+ it "should accept an optional locale setting" do
22
+ EnterpriseSession.new('cms', 'Administrator', '', :locale => 'en_CA')
23
+ end
24
+ end
25
+
26
+ describe "#connected?" do
27
+ before(:each) do
28
+ @session.should_receive(:logoff).at_most(1).with.and_return
29
+ end
30
+
31
+ it "returns 'true' when connected to a CMS" do
32
+ @es.connected?.should be_true
33
+ end
34
+
35
+ it "returns 'false' when not connected to a CMS" do
36
+ @es.disconnect
37
+ @es.connected?.should be_false
38
+ end
39
+ end
40
+
41
+ describe "#disconnect" do
42
+ before(:each) do
43
+ @session.should_receive(:logoff).once.with.and_return
44
+ end
45
+
46
+ it "should disconnect from the CMS" do
47
+ @es.disconnect
48
+ @es.connected?.should be_false
49
+ end
50
+
51
+ it "shouldn't raise an error when not connected" do
52
+ lambda{2.times{ @es.disconnect }}.should_not raise_exception
53
+ end
54
+ end
55
+
56
+ describe "#path_to_sql" do
57
+ before(:each) do
58
+ @path_query = 'path://SystemObjects/Users/Administrator@SI_ID'
59
+ @stmt = "SELECT SI_ID FROM CI_SYSTEMOBJECTS WHERE SI_KIND='User' AND SI_NAME='Administrator'"
60
+
61
+ @stateless_page_info = mock("IStatelessPageInfo").as_null_object
62
+
63
+ class PagingQueryOptions; end
64
+ PagingQueryOptions.should_receive(:new).once.with
65
+ @infostore.should_receive(:getStatelessPageInfo).once.with(@path_query, nil).and_return(@stateless_page_info)
66
+ @stateless_page_info.should_receive(:getPageSQL).once.with.and_return(@stmt)
67
+ end
68
+
69
+ it "should convert a path query to an sql query" do
70
+ @es.path_to_sql(@path_query).should == @stmt
71
+ end
72
+ end
73
+
74
+ describe "#query" do
75
+ context "when :type => sql" do
76
+ before(:each) do
77
+ @stmt = 'SELECT * FROM CI_INFOOBJECTS'
78
+ @infostore.should_receive(:query).once.with(@stmt).and_return([])
79
+ end
80
+
81
+ it "should send the statement to the underlying InfoStore" do
82
+ @es.query(@stmt)
83
+ end
84
+ end
85
+
86
+ context "when :type => path://" do
87
+ before(:each) do
88
+ @path_query = 'path://SystemObjects/Users/Administrator@SI_ID'
89
+ @stmt = "SELECT * FROM CI_SYSTEMOBJECTS WHERE SI_KIND='User' AND SI_NAME='Administator'"
90
+
91
+ @es.should_receive(:path_to_sql).once.with(@path_query).and_return(@stmt)
92
+ @infostore.should_receive(:query).once.with(@stmt).and_return([])
93
+ end
94
+
95
+ it "should convert a path:// query to sql before execution" do
96
+ @es.query(@path_query)
97
+ end
98
+ end
99
+
100
+ context "when :type => query://" do
101
+ before(:each) do
102
+ @path_query = 'query://{SELECT * FROM CI_INFOOBJECTS}'
103
+ @stmt = 'SELECT * FROM CI_INFOOBJECTS'
104
+
105
+ @es.should_receive(:path_to_sql).once.with(@path_query).and_return(@stmt)
106
+ @infostore.should_receive(:query).once.with(@stmt).and_return([])
107
+ end
108
+
109
+ it "should convert a query:// query to sql before execution" do
110
+ @es.query(@path_query)
111
+ end
112
+ end
113
+
114
+ context "when :type => cuid://" do
115
+ before(:each) do
116
+ @path_query = 'cuid://ABC'
117
+ @stmt = "SELECT * FROM CI_INFOOBJECTS WHERE SI_CUID='ABC'"
118
+
119
+ @es.should_receive(:path_to_sql).once.with(@path_query).and_return(@stmt)
120
+ @infostore.should_receive(:query).once.with(@stmt).and_return([])
121
+ end
122
+
123
+ it "should convert a cuid:// query to sql before execution" do
124
+ @es.query(@path_query)
125
+ end
126
+ end
127
+ end
128
+
129
+ describe "#open_webi" do
130
+ before(:each) do
131
+ @webi_report_engine = mock("WebiReportEngine").as_null_object
132
+ @document_instance = mock("DocumentInstance").as_null_object
133
+ @webi_instance = mock("WebiInstance").as_null_object
134
+ class WebiReportEngine; end
135
+ class WebiInstance; end
136
+ WebiInstance.should_receive(:new).at_least(1).with(@document_instance).and_return(@webi_instance)
137
+ @webi_report_engine.should_receive(:open).at_least(1).with("1234").and_return(@document_instance)
138
+ end
139
+
140
+ context "when :locale => en_US" do
141
+ before(:each) do
142
+ WebiReportEngine.should_receive(:new).once.with(@session, 'en_US').and_return(@webi_report_engine)
143
+ end
144
+
145
+ it "should create a WebiReportEngine and call #open" do
146
+ @es.open_webi("1234")
147
+ end
148
+
149
+ it "should only create a WebiReportEngine once" do
150
+ 2.times{@es.open_webi("1234")}
151
+ end
152
+
153
+ it "should create a WebiInstance and return it" do
154
+ @es.open_webi("1234").should == @webi_instance
155
+ end
156
+ end
157
+
158
+ context "when :locale => en_CA" do
159
+ before(:each) do
160
+ WebiReportEngine.should_receive(:new).once.with(@session, 'en_CA').and_return(@webi_report_engine)
161
+ end
162
+
163
+ it "should pass any specified locale" do
164
+ es = EnterpriseSession.new('cms', 'Administrator', '', :locale => 'en_CA')
165
+ es.open_webi("1234")
166
+ end
167
+ end
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,149 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
2
+ require 'bosdk/info_object'
3
+
4
+ module BOSDK
5
+ describe InfoObject do
6
+ before(:each) do
7
+ @infoobject = mock("IInfoObject").as_null_object
8
+
9
+ @obj = InfoObject.new(@infoobject)
10
+ end
11
+
12
+ describe "#docid" do
13
+ before(:each) do
14
+ @infoobject.should_receive(:getID).once.with.and_return(1)
15
+ end
16
+
17
+ it "should call #getID and return the result" do
18
+ @obj.docid.should == 1
19
+ end
20
+
21
+ it "should only call #getID once" do
22
+ 2.times{@obj.docid.should == 1}
23
+ end
24
+ end
25
+
26
+ describe "#is_root?" do
27
+ context "when #parent_id == nil" do
28
+ before(:each) do
29
+ @infoobject.should_receive(:parent_id).once.with.and_return(nil)
30
+ end
31
+
32
+ it "should return true" do
33
+ @obj.is_root?.should be_true
34
+ end
35
+ end
36
+
37
+ context "when #parent_id == 0" do
38
+ before(:each) do
39
+ @infoobject.should_receive(:parent_id).once.with.and_return(0)
40
+ end
41
+
42
+ it "should return true" do
43
+ @obj.is_root?.should be_true
44
+ end
45
+ end
46
+
47
+ context "when #parent_id == #getID" do
48
+ before(:each) do
49
+ @infoobject.should_receive(:parent_id).once.with.and_return(1)
50
+ @infoobject.should_receive(:getID).once.with.and_return(1)
51
+ end
52
+
53
+ it "should return true" do
54
+ @obj.is_root?.should be_true
55
+ end
56
+ end
57
+
58
+ context "when #parent_id != nil, 0 or #getID" do
59
+ before(:each) do
60
+ @infoobject.should_receive(:parent_id).once.with.and_return(1)
61
+ @infoobject.should_receive(:getID).once.with.and_return(2)
62
+ end
63
+
64
+ it "should return false" do
65
+ @obj.is_root?.should be_false
66
+ end
67
+ end
68
+ end
69
+
70
+ describe "#parent" do
71
+ context "when #is_root? == true" do
72
+ before(:each) do
73
+ @infoobject.should_receive(:parent_id).once.with.and_return(nil)
74
+ end
75
+
76
+ it "should return nil" do
77
+ @obj.parent.should be_nil
78
+ end
79
+ end
80
+
81
+ context "when #is_root? == false" do
82
+ before(:each) do
83
+ @parent_obj = mock("IInfoObject").as_null_object
84
+ @infoobject.should_receive(:parent_id).once.with.and_return(1)
85
+ @infoobject.should_receive(:getID).once.with.and_return(2)
86
+ @infoobject.should_receive(:getParent).once.with.and_return(@parent_obj)
87
+ end
88
+
89
+ it "should return results of #getParent" do
90
+ parent = @obj.parent
91
+ parent.should be_instance_of InfoObject
92
+ parent.obj.should == @parent_obj
93
+ end
94
+
95
+ it "should only call the underlying #getParent once" do
96
+ 2.times{@obj.parent}
97
+ end
98
+ end
99
+ end
100
+
101
+ describe "#path" do
102
+ context "when #is_root? == true" do
103
+ before(:each) do
104
+ @infoobject.should_receive(:parent_id).once.with.and_return(nil)
105
+ @infoobject.should_receive(:title).once.with.and_return('test obj')
106
+ end
107
+
108
+ it "should return /#title" do
109
+ @obj.path.should == '/test obj'
110
+ end
111
+ end
112
+
113
+ context "when #is_root? == false" do
114
+ before(:each) do
115
+ @parent_obj = mock("IInfoObject").as_null_object
116
+ @parent_obj.should_receive(:parent_id).once.with.and_return(nil)
117
+ @parent_obj.should_receive(:title).once.with.and_return('test parent')
118
+
119
+ @infoobject.should_receive(:parent_id).once.with.and_return(1)
120
+ @infoobject.should_receive(:getID).once.with.and_return(2)
121
+ @infoobject.should_receive(:title).once.with.and_return('test obj')
122
+ @infoobject.should_receive(:getParent).once.with.and_return(@parent_obj)
123
+ end
124
+
125
+ it "should return #parent_title/../#title" do
126
+ @obj.path.should == '/test parent/test obj'
127
+ end
128
+
129
+ it "should only call the underlying #title, #parent#path, etc. once" do
130
+ 2.times{@obj.path}
131
+ end
132
+ end
133
+ end
134
+
135
+ describe "#<=>" do
136
+ it "should use #title" do
137
+ objs = []
138
+ ('a'..'c').to_a.reverse.each do |ltr|
139
+ obj = mock("IInfoObject").as_null_object
140
+ obj.should_receive(:title).once.with.and_return(ltr)
141
+ objs << InfoObject.new(obj)
142
+ end
143
+
144
+ sorted_objs = objs.sort
145
+ sorted_objs.should == objs.reverse
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,112 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
2
+ require 'bosdk/webi_instance'
3
+
4
+ module BOSDK
5
+ describe WebiInstance do
6
+ before(:each) do
7
+ @document_instance = mock("DocumentInstance").as_null_object
8
+
9
+ @webi = WebiInstance.new(@document_instance)
10
+ end
11
+
12
+ describe "#new" do
13
+ it "should store the passed DocumentInstance in @doc_instance" do
14
+ @webi.instance.should == @document_instance
15
+ end
16
+ end
17
+
18
+ describe "#objects" do
19
+ before(:each) do
20
+ @report_dictionary = mock("ReportDictionary").as_null_object
21
+ @report_expression_1 = mock("ReportExpression").as_null_object
22
+ @report_expression_2 = mock("ReportExpression").as_null_object
23
+ @object_qualification_1 = mock("ObjectQualification").as_null_object
24
+ @object_qualification_2 = mock("ObjectQualification").as_null_object
25
+ @object_type_1 = mock("ObjectType").as_null_object
26
+ @object_type_2 = mock("ObjectType").as_null_object
27
+
28
+ @document_instance.should_receive(:getDictionary).once.with.and_return(@report_dictionary)
29
+
30
+ @report_dictionary.should_receive(:getChildCount).once.with.and_return(2)
31
+ @report_dictionary.should_receive(:getChildAt).once.with(0).and_return(@report_expression_1)
32
+ @report_dictionary.should_receive(:getChildAt).once.with(1).and_return(@report_expression_2)
33
+
34
+ @report_expression_1.should_receive(:getName).once.with.and_return("Object1")
35
+ @report_expression_1.should_receive(:getQualification).once.with.and_return(@object_qualification_1)
36
+ @report_expression_1.should_receive(:getType).once.with.and_return(@object_type_1)
37
+
38
+ @report_expression_2.should_receive(:getName).once.with.and_return("Object2")
39
+ @report_expression_2.should_receive(:getQualification).once.with.and_return(@object_qualification_2)
40
+ @report_expression_2.should_receive(:getType).once.with.and_return(@object_type_2)
41
+
42
+ @object_qualification_1.should_receive(:toString).once.with.and_return("DIMENSION")
43
+ @object_qualification_2.should_receive(:toString).once.with.and_return("MEASURE")
44
+
45
+ @object_type_1.should_receive(:toString).once.with.and_return("TEXT")
46
+ @object_type_2.should_receive(:toString).once.with.and_return("NUMERIC")
47
+
48
+ @objects = [
49
+ {:name => 'Object1', :qual => :dimension, :type => :text, :object => @report_expression_1},
50
+ {:name => 'Object2', :qual => :measure, :type => :numeric, :object => @report_expression_2},
51
+ ]
52
+ end
53
+
54
+ it "should return an array of report objects" do
55
+ @webi.objects.should == @objects
56
+ end
57
+
58
+ it "should cache results" do
59
+ 2.times{@webi.objects}
60
+ end
61
+ end
62
+
63
+ describe "#variables" do
64
+ before(:each) do
65
+ @report_dictionary = mock("ReportDictionary").as_null_object
66
+ @variable_expression_1 = mock("VariableExpression").as_null_object
67
+ @variable_expression_2 = mock("VariableExpression").as_null_object
68
+ @object_qualification_1 = mock("ObjectQualification").as_null_object
69
+ @object_qualification_2 = mock("ObjectQualification").as_null_object
70
+ @object_type_1 = mock("ObjectType").as_null_object
71
+ @object_type_2 = mock("ObjectType").as_null_object
72
+ @formula_expression_1 = mock("FormulaExpression").as_null_object
73
+ @formula_expression_2 = mock("FormulaExpression").as_null_object
74
+
75
+ @document_instance.should_receive(:getDictionary).once.with.and_return(@report_dictionary)
76
+ @report_dictionary.should_receive(:getVariables).once.with.and_return([@variable_expression_1, @variable_expression_2])
77
+
78
+ @variable_expression_1.should_receive(:getName).once.with.and_return("Variable1")
79
+ @variable_expression_1.should_receive(:getQualification).once.with.and_return(@object_qualification_1)
80
+ @variable_expression_1.should_receive(:getType).once.with.and_return(@object_type_1)
81
+ @variable_expression_1.should_receive(:getFormula).once.with.and_return(@formula_expression_1)
82
+
83
+ @variable_expression_2.should_receive(:getName).once.with.and_return("Variable2")
84
+ @variable_expression_2.should_receive(:getQualification).once.with.and_return(@object_qualification_2)
85
+ @variable_expression_2.should_receive(:getType).once.with.and_return(@object_type_2)
86
+ @variable_expression_2.should_receive(:getFormula).once.with.and_return(@formula_expression_2)
87
+
88
+ @object_qualification_1.should_receive(:toString).once.with.and_return("DIMENSION")
89
+ @object_qualification_2.should_receive(:toString).once.with.and_return("MEASURE")
90
+
91
+ @object_type_1.should_receive(:toString).once.with.and_return("TEXT")
92
+ @object_type_2.should_receive(:toString).once.with.and_return("NUMERIC")
93
+
94
+ @formula_expression_1.should_receive(:getValue).once.with.and_return('If([Object1]="Object1";"Yes";"False")')
95
+ @formula_expression_2.should_receive(:getValue).once.with.and_return('Sum([Object2])')
96
+
97
+ @variables = [
98
+ {:name => 'Variable1', :qual => :dimension, :type => :text, :formula => 'If([Object1]="Object1";"Yes";"False")', :variable => @variable_expression_1},
99
+ {:name => 'Variable2', :qual => :measure, :type => :numeric, :formula => 'Sum([Object2])', :variable => @variable_expression_2},
100
+ ]
101
+ end
102
+
103
+ it "should return an array of variables" do
104
+ @webi.variables.should == @variables
105
+ end
106
+
107
+ it "should cache results" do
108
+ 2.times{@webi.variables}
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,39 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
2
+ require 'bosdk/webi_report_engine'
3
+
4
+ module BOSDK
5
+ describe WebiReportEngine do
6
+ before(:each) do
7
+ @enterprise_session = mock("EnterpriseSession").as_null_object
8
+ @report_engines = mock("ReportEngines").as_null_object
9
+ @webi_report_engine = mock("ReportEngine").as_null_object
10
+
11
+ @enterprise_session.should_receive(:getService).at_least(1).with("ReportEngines").and_return(@report_engines)
12
+ module ReportEngines; module ReportEngineType; module WI_REPORT_ENGINE; end; end; end
13
+ @report_engines.should_receive(:getService).at_least(1).with(ReportEngines::ReportEngineType::WI_REPORT_ENGINE).and_return(@webi_report_engine)
14
+ @webi_report_engine.should_receive(:setLocale).at_least(1).with("en_US")
15
+
16
+ @wre = WebiReportEngine.new(@enterprise_session)
17
+ end
18
+
19
+ describe "#new" do
20
+ before(:each) do
21
+ @webi_report_engine.should_receive(:setLocale).once.with("en_CA")
22
+ end
23
+
24
+ it "should allow you to set the locale" do
25
+ WebiReportEngine.new(@enterprise_session, "en_CA")
26
+ end
27
+ end
28
+
29
+ describe "#open" do
30
+ before(:each) do
31
+ @webi_report_engine.should_receive(:openDocument).once.with("1234")
32
+ end
33
+
34
+ it "should call the underlying #openDocument with the supplied docid" do
35
+ @wre.open("1234")
36
+ end
37
+ end
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bosdk
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.2.0
6
+ platform: java
7
+ authors:
8
+ - Shane Emmons
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-02-18 00:00:00 -05:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 2.0.0
25
+ type: :development
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: yard
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :development
37
+ version_requirements: *id002
38
+ description: A JRuby wrapper for the Business Objects Java SDK
39
+ email: semmons99@gmail.com
40
+ executables:
41
+ - boirb
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - bin/boirb
48
+ - lib/bosdk.rb
49
+ - lib/bosdk/enterprise_session.rb
50
+ - lib/bosdk/info_object.rb
51
+ - lib/bosdk/webi_instance.rb
52
+ - lib/bosdk/webi_report_engine.rb
53
+ - spec/bosdk_spec.rb
54
+ - spec/enterprise_session_spec.rb
55
+ - spec/info_object_spec.rb
56
+ - spec/webi_instance_spec.rb
57
+ - spec/webi_report_engine_spec.rb
58
+ - README.md
59
+ - LICENSE
60
+ - Rakefile
61
+ - .gemtest
62
+ - bosdk.gemspec
63
+ has_rdoc: true
64
+ homepage: http://semmons99.github.com/bosdk
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options: []
69
+
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 1.3.6
84
+ requirements:
85
+ - An environment variable 'BOE_JAVA_LIB' pointing to the Business Objects Java SDK directory
86
+ rubyforge_project:
87
+ rubygems_version: 1.5.0
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: JRuby Business Object Java SDK wrapper
91
+ test_files: []
92
+