If you are unable to create a new account, please email support@bspsoftware.com

 

News:

MetaManager - Administrative Tools for IBM Cognos
Pricing starting at $2,100
Download Now    Learn More

Main Menu

Anyone have any SDK samples for querying the Content Store

Started by stark, 23 May 2007 01:09:30 PM

Previous topic - Next topic

stark

Hello all,

I am another newbie.  I need to get the status of a scheduled report( ie. "Succeeded" or "Failed" etc.) from an outside vb.net app.  I am trying to use queryEvents method.  Anyone have any samples?

Thanks in advance

lloydke

This is java but VB.net should be close.

first instantiate the object to connect to the event manager:

EventManagementService_ServiceLocator eventManagementServiceLocator=new EventManagementService_ServiceLocator();      
ContentManagerService_ServiceLocator cmServiceLocator = new ContentManagerService_ServiceLocator();

//Next connect to cognos
      
try
{
cmService = cmServiceLocator.getcontentManagerService(new java.net.URL(endPoint));
eventManagementService= eventManagementServiceLocator.geteventManagementService(new java.net.URL(endPoint));
}
catch (Exception e)
{
System.out.println(e);
}

//Then call the object passing the event your looking for

EventRecord queryEventsHelper[] = new EventRecord[] {};
try
{
queryEventsHelper = eventManagementService.queryEvents(myOptions);
if (queryEventsHelper != null)
for (int i = 0; i < queryEventsHelper.length; i++)
{
System.out.println("Event found: " + queryEventsHelper.getStatus());
System.out.println("       EventID = " + queryEventsHelper.getEventID());
}
else
System.out.println("No Scheduled Events found");
}
catch (java.rmi.RemoteException remoteEx)
{
System.out.println("Caught remote exception:\n");
remoteEx.printStackTrace();
}

Hope this helps.

--Kevin

stark

Thank you for the post Kevin.  In my 'rough' translation of the Java, it appears that I have everything that is in the sample.  However,  the 'myOptions' argument for the queryEvents method is causing issues.  I read in the SDK manual that you have to specify the startTime and endTime properties, and I have done so but I keep getting a Null Ref. Exception as though it is expecting something else..??
my search continues..

Anyway, thank you again for the post.

lloydke

It looks like the query class wants a SearchPathMultipleObject defined and passed (so it knows where to start looking) your creationTime etc put into a properties array using the PropEnum class and then pass in the array, sort options like ascending, etc. put into a PropEnum array and finally your queery options put into a QueryOptions array.

--Kevin

minotaur77

Below is the "hacked" version I put together in VB .net 2.0.  It is a console app that either traverses the content store or runs a report.  It is pulled from some examples I found here and interpreted from the SDK. 


Imports cognosdotnet_2_0

Module CubeVerify
    Public Class c8ConnectionHolder
        Public c8URL As String = "http://localhost:9300/p2pd/servlet/dispatch"
        Public c8AS As agentService
        Public c8CMS As contentManagerService1
        Public c8RS As reportService1
        Public Sub New()
            Me.c8RS = New reportService1
            Me.c8CMS = New contentManagerService1
            Me.c8AS = New agentService

            Me.c8AS.Url = c8URL
            Me.c8CMS.Url = c8URL
            Me.c8RS.Url = c8URL

            Dim credentialXML As System.Text.StringBuilder = New System.Text.StringBuilder("<credential>")
            credentialXML.AppendFormat("<namespace>{0}</namespace>", "xxxxxx")
            credentialXML.AppendFormat("<username>{0}</username>", "xxxxx")
            credentialXML.AppendFormat("<password>{0}</password>", "xxxxxx")
            credentialXML.Append("</credential>")
            Dim encodedCredentials As String = credentialXML.ToString
            Dim xmlEncodedCredentials As xmlEncodedXML = New xmlEncodedXML
            xmlEncodedCredentials.Value = encodedCredentials
            c8CMS.logon(xmlEncodedCredentials, Nothing)

            If c8AS.biBusHeaderValue Is Nothing Then
                c8AS.biBusHeaderValue = c8CMS.biBusHeaderValue
            End If

            If c8RS.biBusHeaderValue Is Nothing Then
                c8RS.biBusHeaderValue = c8CMS.biBusHeaderValue
            End If

        End Sub
    End Class


    Sub Main()

        Dim c8conn As New c8ConnectionHolder


        Try
           
            Console.WriteLine("connected to " + c8conn.c8AS.Url)
            doExecuteReport(c8conn, "/content/package[@name='Traffic']/report[@name='CM Click Ins for Today']")
            doTraverseFolders(c8conn)

        Catch ex As Exception
            Console.WriteLine("did not connect to " + c8conn.c8as.Url + " got error " + ex.ToString)

        End Try



    End Sub
    Public Sub doTraverseFolders(ByVal c8conn As c8ConnectionHolder)
        Dim strSearch As New searchPathMultipleObject
        strSearch.Value = "/content/folder"

        'Set the properties we wish to query for
        Dim properties(1) As propEnum
        'Dim properties(2) = propEnum
        properties(0) = propEnum.defaultName
        properties(1) = propEnum.searchPath

        'Set the sorting options
        Dim sortBy(0) As sort
        sortBy(0) = New sort
        sortBy(0).order = orderEnum.ascending
        sortBy(0).propName = propEnum.defaultName

       
        'Perform the Query
        Dim results As baseClass()
        results = c8conn.c8CMS.query(strSearch, properties, sortBy, New queryOptions)
        Dim i As Integer
        'Loop through the results
        Dim rLen As Integer = UBound(results)
        'Dim Jodi As Integer
        For i = 0 To rLen
            Dim curRes = results(i)
            Dim srchPath As String = curRes.searchPath.value
            Dim defName As String = curRes.defaultName.value

            'Display a list of the names - search paths
            Console.Write(defName & " - " & srchPath & "" & vbCrLf)
        Next

    End Sub


   



    Public Function doExecuteReport(ByVal c8Connection As c8ConnectionHolder, ByVal reportPath As String) As String
        If c8Connection Is Nothing Then
            Return Nothing
        End If
        Dim html As String = ""

        Dim ERR_MESG As String = "run() failed to return a valid report in this format"

        Dim executeReportResponse As cognosdotnet_2_0.asynchReply = Nothing
        Dim arrRunOpts(3) As [option]
        Dim arrParm() As parameterValue = Nothing

        Dim blnPromptOption As New runOptionBoolean()
        Dim outputFormat As New runOptionStringArray()
        Dim primaryWait As New asynchOptionInt() ' primary wait threshold
        Dim strarrFmt(0) As String
        Dim blnSaveOption As New runOptionBoolean()

        ' Specify do not save the output
        blnSaveOption.name = runOptionEnum.saveOutput
        blnSaveOption.value = False

        ' execute the report in HTML format
        strarrFmt(0) = "HTML"
        outputFormat.name = runOptionEnum.outputFormat
        outputFormat.value = strarrFmt

        ' Specify do not prompt for parameters (being passed)
        blnPromptOption.name = runOptionEnum.prompt
        blnPromptOption.value = False

        ' set the primary wait threshold to 0 seconds - wait indefinitely
        primaryWait.name = asynchOptionEnum.primaryWaitThreshold
        primaryWait.value = 0

        ' fill the array with the run options
        arrRunOpts(0) = blnPromptOption
        arrRunOpts(1) = outputFormat
        arrRunOpts(2) = primaryWait
        arrRunOpts(3) = blnSaveOption
        ' sn_dg_prm_smpl_runreport_P3_end_0
        Dim cmReportPath As New searchPathSingleObject()
        cmReportPath.Value = reportPath

        ' execute the report
        ' sn_dg_sdk_method_reportService_getOutput_start_0
        ' sn_dg_sdk_method_reportService_run_start_0
        ' sn_dg_prm_smpl_runreport_P4_start_0

        Dim asyRsr As asynchReply
        'Dim params As New ParameterValueC
        'frmURL.rptServ.biBusHeaderValue = frmURL.cmServ.biBusHeaderValue
        asyRsr = c8Connection.c8RS.getParameters(cmReportPath, arrParm, arrRunOpts)


        executeReportResponse = c8Connection.c8RS.run(cmReportPath, arrParm, arrRunOpts)
        ' sn_dg_sdk_method_reportService_run_end_0
        ' If response is not immediately complete, call wait until complete
        If Not executeReportResponse.status.Equals(asynchReplyStatusEnum.complete) Then
            ' sn_dg_sdk_method_reportService_getOutput_end_0
            While Not executeReportResponse.status.Equals(asynchReplyStatusEnum.complete)
                'before calling wait, double check that it is okay
                If Not hasSecondaryRequest(executeReportResponse, "wait") Then
                    Return ERR_MESG
                End If
                executeReportResponse = c8Connection.c8RS.wait(executeReportResponse.primaryRequest, New parameterValue() {}, New [option]() {})
            End While

            'After calling wait() it is necessary to check to make sure
            'the output is ready before retrieving it
            ' sn_dg_sdk_method_reportService_getOutput_start_1
            If outputIsReady(executeReportResponse) Then
                executeReportResponse = c8Connection.c8RS.getOutput(executeReportResponse.primaryRequest, New parameterValue() {}, New [option]() {})
                ' sn_dg_sdk_method_reportService_getOutput_end_1
                ' sn_dg_prm_smpl_runreport_P4_end_0
            Else
                Return ERR_MESG
            End If
        End If

        html = getOutputPage(executeReportResponse)


        Dim outputPath As New searchPathMultipleObject()
        outputPath.Value = "~~/output"

        'how to get charts/graphs/etc....
        'Dim bcOutput() As baseClass

        'bcOutput = c8Connection.c8CMS.query(outputPath, New propEnum() {propEnum.searchPath}, New sort() {}, New queryOptions())

        'If Not (bcOutput Is Nothing) And bcOutput.GetLength(0) > 0 Then
        '    Dim cf As New CommonFunctions()
        '    html = cf.setupGraphics(c8Connection.C8CMS, html)
        'End If
       


        Return html
    End Function



    'getOutputPage
    Public Function getOutputPage(ByVal executeReportResponse As asynchReply) As String
        ' sn_dg_sdk_method_reportService_getOutput_start_2
        Dim reportOutput As asynchDetailReportOutput = Nothing
        Dim i As Integer = 0
        Do While (i < executeReportResponse.details.Length)
            If (executeReportResponse.details(i).GetType Is GetType(asynchDetailReportOutput)) Then
                reportOutput = CType(executeReportResponse.details(i), asynchDetailReportOutput)
                'TODO: Warning!!! break;If
            End If
            i = (i + 1)
        Loop
        ' sn_dg_sdk_method_reportService_getOutput_end_2
        'text based output is split into pages -- return the current page
        Return reportOutput.outputPages(0).ToString
    End Function


    'outputIsReady


    Public Function outputIsReady(ByVal response As asynchReply) As Boolean
        Dim i As Integer = 0
        Do While (i < response.details.Length)
            If ((response.details(i).GetType Is GetType(asynchDetailReportStatus)) _
                        AndAlso ((CType(response.details(i), asynchDetailReportStatus).status = asynchDetailReportStatusEnum.responseReady) _
                        AndAlso hasSecondaryRequest(response, "getOutput"))) Then
                Return True
            End If
            i = (i + 1)
        Loop
        Return False
    End Function

    'hasSecondaryRequest
    Public Function hasSecondaryRequest(ByVal response As asynchReply, ByVal secondaryRequest As String) As Boolean
        Dim secondaryRequests() As asynchSecondaryRequest = response.secondaryRequests
        Dim i As Integer = 0
        Do While (i < secondaryRequests.Length)
            If (secondaryRequests(i).name.CompareTo(secondaryRequest) = 0) Then
                Return True
            End If
            i = (i + 1)
        Loop
        Return False
    End Function
End Module

stark

Thanks for the post minotaur77.  We have not upgraded to C8 yet, but I will see what I can crossref out of this.