Approach To The Cognos 8 SDK: Proven Practice
Approach To The Cognos 8 SDK: Proven Practice
Copyright
Copyright © 2008 Cognos ULC (formerly Cognos Incorporated). Cognos ULC
is an IBM Company. While every attempt has been made to ensure that the
information in this document is accurate and complete, some typographical
errors or technical inaccuracies may exist. Cognos does not accept
responsibility for any kind of loss resulting from the use of information
contained in this document. This document shows the publication date. The
information contained in this document is subject to change without notice.
Any improvements or changes to the information contained in this document
will be documented in subsequent editions. This document contains
proprietary information of Cognos. All rights are reserved. No part of this
document may be copied, photocopied, reproduced, stored in a retrieval
system, transmitted in any form or by any means, or translated into another
language without the prior written consent of Cognos. Cognos and the
Cognos logo are trademarks of Cognos ULC (formerly Cognos Incorporated)
in the United States and/or other countries. IBM and the IBM logo are
trademarks of International Business Machines Corporation in the United
States, or other countries, or both. All other names are trademarks or
registered trademarks of their respective companies. Information about
Cognos products can be found at www.cognos.com
This document is maintained by the Best Practices, Product and Technology
team. You can send comments, suggestions, and additions to
[email protected] .
Contents
1 INTRODUCTION ............................................................................................ 4
1.1 PURPOSE .............................................................................................................. 4
1.2 APPLICABILITY ....................................................................................................... 5
1.3 EXCLUSIONS AND EXCEPTIONS .................................................................................... 5
2 GET THE RIGHT TOOLS FOR THE JOB ........................................................... 5
3 ABOUT COGNOS 8 WEB SERVICES................................................................ 6
4 DEPLOY A STANDALONE COGNOS 8 INSTALLATION.................................... 6
5 GO SALES AND RETAILERS ........................................................................... 7
6 CONTENT STORE LAYOUT AND SEARCH PATHS ........................................... 7
7 ENUMERATION SETS..................................................................................... 9
8 ALL THOSE CLASSES ................................................................................... 10
8.1 CLASSES THAT REPRESENT CONTENT STORE OBJECTS ...................................................... 10
8.2 CLASSES THAT IMPLEMENT PROPERTIES OF CONTENT STORE OBJECTS .................................. 11
9 THE COGNOS 8 SERVICES........................................................................... 11
10 LOGGING ON AND LOGGING OFF ............................................................... 12
10.1 LOGGING ON ....................................................................................................... 13
10.2 SHARING THE CAM PASSPORT BETWEEN SERVICES ........................................................ 14
10.2.1 Java Samples ................................................................................................ 14
10.2.2 C# Samples .................................................................................................. 15
10.3 LOGGING OFF ...................................................................................................... 15
10.4 FOR MORE INFORMATION........................................................................................ 15
11 QUERY THE CONTENT STORE ..................................................................... 15
11.1 THE CONTENTMANAGERSERVICE.QUERY () METHOD ....................................................... 16
11.2 HOW CONTENT STORE OBJECTS ARE RETURNED ........................................................... 16
11.3 FOR MORE INFORMATION........................................................................................ 17
12 RUNNING A SIMPLE REPORT...................................................................... 17
12.1 THE REPORTSERVICE.RUN () METHOD ........................................................................ 18
12.2 THE ASYNCHRONOUS CONVERSATION ......................................................................... 20
12.3 HOW THE CONTENTS OF A REPORT ARE RETURNED ........................................................ 21
12.4 FOR MORE INFORMATION........................................................................................ 23
13 CONCLUSION .............................................................................................. 23
1 Introduction
1.1 Purpose
The Cognos 8 Software Development Kit (SDK) can be used to create
anything from simple utility applications to full-scale, highly complex
applications. Indeed, most of the functionality provided through Cognos
Connection can be re-created using the Cognos 8 SDK.
The Cognos 8 SDK documentation contains over 1700 pages in PDF form. In
addition to the documentation, there are code samples that are installed with
the SDK and a considerable number of Knowledge Base and SupportLink
articles related to the Cognos 8 SDK. For someone just starting out with the
Cognos 8 SDK, all of this information can be overwhelming and finding a
place to get started can be difficult.
Topics that will not be covered in this document but will be mentioned here
to alert the reader about what is possible with the Cognos 8 SDK are,
• Adding, deleting, modifying objects in the Content Store
• Running complex reports that require prompting
• Scheduling reports and running jobs
• Cognos 8 services other than the Content Manager Service and the
Report Service
In the Cognos 8 SDK documentation set, there are separate manuals for
developing Framework Manager metadata models and developing Custom
Authentication Providers. These are topics that require advanced knowledge
and are outside the scope of this document.
1.2 Applicability
This document applies to the Cognos 8 SDK. The Cognos ReportNet SDK will
not be covered in this document. While much of the material in this
document does apply, there are differences between the Cognos 8 SDK and
the Cognos ReportNet SDK. The Cognos Proven Practices document titled
Approaching The CRN SDK has been created to address the specific topics of
the Cognos ReportNet SDK.
The .NET Languages (C# and VB.NET) use Microsoft’s Visual Studio (VS) as
the IDE. As of January 2006, VS 2005 was the latest release and either the
“Standard” or “Professional” editions can be used.
A default installation on a single server will allow Anonymous access and will
give the Everyone group in the Cognos namespace the permissions of the
built in System Administrators role. The Cognos 8 SDK application will not
need to logon as it will be treated as the Anonymous user.
• Populates the Content Store with sample reports with various styles
and complexities
• Referred to in the Cognos 8 SDK documentation
• Used by most code samples
• Is a “well-known” reporting environment with which many people are
already familiar
• Allows for easier replication of the reporting environment within
Cognos Support should assistance be required.
The layout of the Content Store defines the search path. The search path is a
key component in developing Cognos 8 SDK applications as it is used to
identify which Content Store object(s) to retrieve. The Appendix titled Search
Path Syntax in the Cognos 8 SDK Developer’s guide provides detailed
information on search paths, including how to obtain a search path to an
individual object using Cognos Connection. In this section there is also a
short table that contains various search path samples. From this table, pay
particular attention to the meaning of “~”, “/” (single slash), “//” (double
slash) and”//*” (double slash and asterisk).
• A “~” (single tilde) is a shortcut to the search path that represents the
Account object of the user that the Cognos 8 SDK application is using
for authentication. More information on logging in a Cognos 8 SDK
application is covered later in this document.
• A “/” (single slash) in the search path means “return direct children”
of the specified type from the current location.
• A “//” (double slash) in the search means “return everything of the
specified type” from the current location
• A “//*” (double slash and asterisk) in the search path means “return
everything of any type” from the current location
A search path is similar to an XPath statement and the details on this topic
can be found in Appendix G of the Cognos 8 SDK Developer’s Guide. If
unfamiliar with XPath, it may be useful to review the basic concepts and an
introductory tutorial can be found at http://www.w3schools.com/xpath. There
is no need to be an expert in XPath to use the Cognos 8 SDK but it is worth
pointing out that using XPath to parse and process any XML document can
greatly simplify development by reducing the amount of code required within
an application.
In the Content Store hierarchy of Cognos 8, there are 7 top level folders.
They are,
• adminFolder
• capability
• configuration
• content
• directory
• portal
• transientStateFolder
The most widely used top level folders of a Cognos 8 SDK application will be
content and directory. In particular, the following sub-folders.
• /content/package will contain all of the reports and report views
created against a particular package.
• /directory/namespace will contain the external security information
such as users, groups and roles for a particular namespace. It is
important to note that with the exception of the built-in Cognos
namespace, the information contained here is not the actual data
stored in the external security provider. It is a representation of the
associated data that is specific to the Cognos Content Store.
In the documentation for the Content Store layout, there are sections for
each top level folder that contain useful search paths. The section for the top
level folder directory contains search paths for the built-in objects of the
Cognos namespace.
7 Enumeration Sets
In the context of the Cognos 8 SDK, an enumeration set can be considered as
a list of read-only constants. As standalone entities, enumeration sets don’t
have much value. Their sole purpose is to act as an identifier without having
to know the actual contents. The values in an enumeration set are typically
used to provide input to a method although there are situations where they
are useful to determine an output type.
For example,
• To specify the defaultName member in the propEnum enumeration
set, use propEnum.defaultName.
• To specify the account member in the classEnum enumeration set,
use classEnum.account.
There are over 80 enumeration sets in the Cognos 8 SDK but familiarity with
only 7 of them are required at this point. They are,
• General Use
o classEnum
• Query The Content Store
o propEnum
• Running Reports
o runOptionEnum
o outputEncapsulationEnum
o outputFormatEnum
o asynchReplyStatusEnum
o asynchDetailReportStatusEnum
The complete list of enumeration sets can be found in the Cognos 8 SDK
Developer’s Guide under the chapter titled Enumeration Sets.
In the next section, it will be seen that classEnum and propEnum are also
useful as a reference in identifying the purpose of the many classes that
make up the Cognos 8 SDK.
The Cognos 8 class list can be categorized into two distinct groups,
• Classes that represent Content Store objects
• Classes that implement properties of Content Store objects
In addition to the classes listed in classEnum, there are several other classes
whose sole purpose is to define common properties for other classes. These
classes are known as abstract classes. There are several abstract classes in
the Cognos 8 SDK but at this point the most relevant ones are,
• baseClass – defines properties that apply to every class in classEnum
and the classes listed below.
The terms object and class are often used interchangeably. In this document,
the term class will be used as a definition and the term object will be used to
represent a physical instance of this definition. For example, the term report
object will refer to an actual Content Store object of class report. An object
can be accessed with a search path.
Each Cognos 8 service has associated methods and each one of these
methods are part of a method set. It is possible for several services to
contain the same method. For example, both the ReportService and
JobService contain the run() method. The ReportService will run reports and
the JobService will run jobs.
The remainder of this document will focus on the following two services,
• ContentManagerService
• ReportService
These two services are the most widely used services in a typical Cognos 8
installation and are used by an SDK application to logon and logoff, make
queries to the Content Store and run reports. Once familiar with them,
making use of other services such as the JobService should be reasonably
straightforward.
One Cognos 8 service that does need a specific mention at this point is the
CognosReportNetService. This service is provided as a compatibility mode for
SDK applications originally written for Cognos ReportNet and should not be
used to develop new Cognos 8 SDK applications.
10.1 Logging On
The logon() method of the ContentManagerService takes 2 parameters,
credentials and roles.
The roles parameter is used to specify search paths to role objects in the
Cognos namespace. The permissions of these role objects will be applied to
the user specified in the credentials. If no additional roles are required, this
parameter must be an empty array instead of null.
Why is the CAM Passport important? In an SDK application, the CAM Passport
does not automatically propagate to other services that might be used within
the application. Since the ContentManagerService is the only service than can
logon and logoff, there needs to be ability to assign the CAM Passport to
other services that the SDK application might require (such as the
ReportService). This assignment is done simply by copying the BIBusHeader
of the ContentManagerService to the BIBusHeader of the other service,
thereby making that service an authenticated service.
The samples that are installed with the Cognos 8 SDK contain code that
demonstrate how to connect to a Cognos 8 service, how to logon using the
ContentManagerService and how to copy a BIBusHeader from the
ContentManagerService to another service.
Once the service has been connected, the method quickLogon() in the file
Logon.java shows how to build the credentials in XML and call the logon()
method of the ContentManagerService.
10.2.2 C# Samples
The C# sample files that show how to logon and share a CAM Passport are,
• <install_location/sdk/csharp/SamplesCommon/SamplesConnect.cs
• <install_location/sdk/csharp/SamplesCommon/SamplesLogon.cs
When the logoff() method is called, the CAM passport will be invalidated
by the Cognos 8 server. This means any other authenticated Cognos 8
service that was established by the SDK application is automatically logged
off. Any subsequent use of the CAM Passport from a saved BIBusHeader will
return a fault.
If an SDK application does not explicitly logoff, the session will remain active
until it is timed out. SDK applications should log out when processing is done.
In many sample code fragments, you will see the query() method called as
follows,
Note that the sortBy and options parameters are not null. They are empty
instances of an object. If null values are supplied, an error (exception) will
occur.
This is essentially all there is to retrieving objects from the Content Store.
Most of the code in the Cognos 8 SDK application will involve processing the
properties of the retrieved Content Store object(s).
The first technique is to use a language specific operator that will perform an
object level comparison. In Java, use the “instanceof” operator, for C# use
the “is” operator and for VB.NET use the “TypeOf” and “Is” combination.
if (baseClassObj.getObjectClass().getValue()== ClassEnum.Report)
{
<code to process a Report object>
}
if (baseClassObj.getObjectClass().getValue()== ClassEnum.ReportView)
{
<code to process a ReportView object>
}
if (baseClassObj.getObjectClass().getValue()== ClassEnum.Account)
{
<code to process an Account object>
}
When discussing Cognos 8 and reports, the term report specification (often
shortened to report spec) will be used often. A report specification is simply
an XML document that can be interpreted by Cognos 8 to generate a report.
The XML document has no meaning outside of Cognos 8. A report
specification contains a large amount of information and can be very
complex. The details of report specifications are beyond the scope of this
document but more information can be found in of the Cognos 8 SDK
Developer’s Guide under the chapters titled Using Report Specifications and
Report Specification Reference.
The parameterValues and options parameters are the same for both the
run() and runSpecification() methods. Both of these parameters
must be actual objects regardless of whether they are being used. A value of
null (or nothing) will generate an error (exception).
As one might expect, the run() method will wait for the report to finish
running but it is important to point out it will not wait forever. The run option
primaryWaitThreshold specifies the maximum amount of time spent waiting
in the run() method. The default value is 7 seconds. If the report output is
not ready after this amount time, the run() method will complete and the
Cognos 8 SDK application will continue on with processing. Additional blocks
of code after the run() method may be required to handle long running
reports. This will be discussed in the next section on the asynchronous
conversation.
When first starting out with the Cognos 8 SDK, the asynchronous
conversation may be more confusing than any other topic but a thorough
understanding of the asynchronous conversation will likely be required for
production quality applications. It is also important to realize that the
asynchronous conversation does not just apply to running reports. It applies
to all of the other Cognos 8 services that implement the run() method.
Even simple reports that have no prompts may take a long time to run. This
is often the case when large amounts of data are present in the report. As
mentioned in the previous section, the primaryWaitThreshold is used to
determine the amount of time the run() method will wait for report output.
If this time expires and the report output is still not ready, then the Cognos 8
SDK application must wait and remain synchronized with the Cognos 8 server
until the output is ready. This is accomplished using the wait() method of
the ReportService. The Cognos 8 SDK application will remain in the wait()
method until the report output is ready or the amount of time specified by
the run option secondaryWaitThreshold has passed. The default value for the
secondaryWaitThreshold is 30 seconds. A Cognos 8 SDK application will
generally just loop around the wait() method until the report output is
ready.
The Cognos 8 SDK Developer’s Guide states that it is possible to set either of
the wait thresholds to 0. This means that there will be no asynchronous
conversation and the Cognos 8 SDK application will wait until report data is
returned or an error occurred. Waiting an indeterminate time is generally
considered to be a bad technique for production quality applications. This is a
passive approach and is difficult, if not impossible, to react to errors. In
addition, the application will usually require additional code to manage other
time-sensitive resources such as communications sockets. It is far better to
learn about and use the asynchronous conversation to actively manage the
processing of the report.
If the report is complete, the details property of the asynchReply object will
contain an asynchDetailReportOutput object. Depending on the some of the
run options, the asynchDetailReportOutput object will either contain the
actual report output or a search path to where the output has been saved in
the Content Store.
13 Conclusion
The information in this document should provide a basic foundation for the
Cognos 8 SDK. Using this foundation, there should be little problem in
navigating the entire Cognos 8 SDK documentation set and making use of
other Cognos 8 services to build robust SDK applications.