Sha256: 1c6e1a9d3aa67ea02bd10d8904097ce97b2e879311551cdb2008f2dd55eb5383

Contents?: true

Size: 1.76 KB

Versions: 2

Compression:

Stored size: 1.76 KB

Contents

require 'bosdk/info_object'
require 'bosdk/webi_report_engine'

module BOSDK
  # Creates a wrapper around the Business Objects Java SDK.
  class EnterpriseSession
    # The underlying IEnterpriseSession
    attr_reader :session

    # The underlying IInfoStore
    attr_reader :infostore

    # Creates a new EnterpriseSession object, connecting to the specified CMS.
    #  EnterpriseSession.new('cms', 'Administrator', '')
    #
    # Automatically calls disconnect when cleaned up.
    def initialize(cms, username, password, options = Hash.new)
      @session = CrystalEnterprise.getSessionMgr.logon(username, password, cms, 'secEnterprise')
      @infostore = @session.getService('', 'InfoStore')
      @connected = true
      @locale = options[:locale] || 'en_US'

      at_exit { disconnect }
    end

    # Returns true/false if connected to the CMS.
    def connected?
      return @connected
    end

    # Disconnects from the CMS is connected.
    def disconnect
      @session.logoff if connected?
      @session = nil
      @connected = false
      nil
    end

    # Converts 'path://', 'query://' and 'cuid://' special forms to a SDK query
    def path_to_sql(path_stmt)
      @infostore.getStatelessPageInfo(path_stmt, PagingQueryOptions.new).getPageSQL
    end

    # Queries the InfoStore with the provided statement, returning an Array of
    # InfoObject(s).
    def query(stmt)
      sql = stmt.match(/^(path|query|cuid):\/\//i) ? path_to_sql(stmt) : stmt
      @infostore.query(sql).map{|o| InfoObject.new(o)}
    end

    # Open a Webi document from the provided docid
    def open_webi(docid)
      @webi_report_engine ||= WebiReportEngine.new(@session, @locale)
      @webi_report_engine.open(docid)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bosdk-1.0.3-universal-java-1.6 lib/bosdk/enterprise_session.rb
bosdk-1.0.2-universal-java-1.6 lib/bosdk/enterprise_session.rb