Get Cognos report Owner name, Report creation and modification time and schedule frequency via Cognos Java SDK

Hi All,
I am exploring Cognos SDK and I am unable to get Report Owner Name and Report Creation and Modification Time along with schedule frequency.
Do someone provide some info, how to get these details via Cognos Java SDK?
Thanks,

Hi @sjain135,

Unfortunately, schedules don’t provide a really clean interface for determining their frequency, probably because there are just so many different scheduling possibilities. But here is an example of querying for hopefully useful schedule and report information.

First, I created the following schedule in Cognos:

Then I wrote the following Java code that simply prints the details of the report and schedule you requested:

import com.cognos.developer.schemas.bibus._3.*;
import org.apache.axis.client.Stub;
import org.apache.axis.message.SOAPHeaderElement;

import javax.xml.rpc.ServiceException;
import java.rmi.RemoteException;
import java.util.Arrays;

public class ScheduleQuery {

   public static void main( String[] args ) {

      try {

         ContentManagerService_PortType contentManagerService = getContentManagerService();

         String reportSearchPath =
               "/content/folder[@name='Samples']/folder[@name='Reports']/folder[@name='Standard reports']/report[@name='Employee expenses']";
         SearchPathMultipleObject reportSearchPathObject = new SearchPathMultipleObject( reportSearchPath );

         System.out.println("================");
         System.out.println( "Querying for report with search path : " + reportSearchPath );
         PropEnum[] reportProps = {PropEnum.searchPath, PropEnum.owner, PropEnum.creationTime, PropEnum.modificationTime};
         BaseClass[] reportResults = contentManagerService.query( reportSearchPathObject, reportProps, new Sort[0], new QueryOptions() );
         Arrays.stream( reportResults ).forEach( baseClass -> {
            System.out.println( "Search path: " + baseClass.getSearchPath().getValue() );
            System.out.println( "Owner: " + baseClass.getOwner().getValue()[0].getSearchPath().getValue() );
            System.out.println( "Creation Date: " + baseClass.getCreationTime().getValue().getTime() );
            System.out.println( "Modification Date: " + baseClass.getModificationTime().getValue().getTime() );
         } );

         System.out.println("================");
         System.out.println( "Querying for schedule with search path : " + reportSearchPath );
         PropEnum[] scheduleProps =
               {
                     PropEnum.searchPath,
                     PropEnum.timeZoneID,
                     PropEnum.triggerName,
                     PropEnum.active,
                     PropEnum.dailyPeriod,
                     PropEnum.endDate,
                     PropEnum.endType,
                     PropEnum.everyNPeriods,
                     PropEnum.monthlyAbsoluteDay,
                     PropEnum.monthlyRelativeDay,
                     PropEnum.monthlyRelativeWeek,
                     PropEnum.startDate,
                     PropEnum.type,
                     PropEnum.weeklyMonday,
                     PropEnum.weeklyTuesday,
                     PropEnum.weeklyWednesday,
                     PropEnum.weeklyThursday,
                     PropEnum.weeklyFriday,
                     PropEnum.weeklySaturday,
                     PropEnum.weeklySunday,
                     PropEnum.yearlyAbsoluteDay,
                     PropEnum.yearlyAbsoluteMonth,
                     PropEnum.yearlyRelativeDay,
                     PropEnum.yearlyRelativeMonth,
                     PropEnum.yearlyRelativeWeek,
                     PropEnum.intradayRecurrenceStart,
                     PropEnum.intradayRecurrenceEnd,
                     PropEnum.intradayRecurrenceInterval
               };
         SearchPathMultipleObject scheduleSearchPathObject = new SearchPathMultipleObject( reportSearchPath + "/schedule" );
         BaseClass[] scheduleResults =
               contentManagerService.query( scheduleSearchPathObject, scheduleProps, new Sort[0], new QueryOptions() );
         Arrays.stream( scheduleResults ).forEach( baseClass -> {
            System.out.println( "Search path: " + baseClass.getSearchPath().getValue() );
            if( baseClass instanceof Schedule ) {
               Schedule schedule = ((Schedule) baseClass);
               System.out.println( "timeZoneID: " + schedule.getTimeZoneID().getValue() );
               System.out.println( "triggerName: " + schedule.getTriggerName().getValue() );
               System.out.println( "active: " + schedule.getActive().isValue() );
               System.out.println( "dailyPeriod: " + schedule.getDailyPeriod().getValue() );
               System.out.println( "endDate: " + schedule.getEndDate().getValue().getTime() );
               System.out.println( "endType: " + schedule.getEndType().getValue() );
               System.out.println( "everyNPeriods: " + schedule.getEveryNPeriods().getValue() );
               System.out.println( "monthlyAbsoluteDay: " + schedule.getMonthlyAbsoluteDay().getValue() );
               System.out.println( "monthlyRelativeDay: " + schedule.getMonthlyRelativeDay().getValue() );
               System.out.println( "monthlyRelativeWeek: " + schedule.getMonthlyRelativeWeek().getValue() );
               System.out.println( "startDate: " + schedule.getStartDate().getValue().getTime() );
               System.out.println( "type: " + schedule.getType().getValue() );
               System.out.println( "weeklyMonday: " + schedule.getWeeklyMonday().isValue() );
               System.out.println( "weeklyTuesday: " + schedule.getWeeklyTuesday().isValue() );
               System.out.println( "weeklyWednesday: " + schedule.getWeeklyWednesday().isValue() );
               System.out.println( "weeklyThursday: " + schedule.getWeeklyThursday().isValue() );
               System.out.println( "weeklyFriday: " + schedule.getWeeklyFriday().isValue() );
               System.out.println( "weeklySaturday: " + schedule.getWeeklySaturday().isValue() );
               System.out.println( "weeklySunday: " + schedule.getWeeklySunday().isValue() );
               System.out.println( "yearlyAbsoluteDay: " + schedule.getYearlyAbsoluteDay().getValue() );
               System.out.println( "yearlyAbsoluteMonth: " + schedule.getYearlyAbsoluteMonth().getValue() );
               System.out.println( "yearlyRelativeDay: " + schedule.getYearlyRelativeDay().getValue() );
               System.out.println( "yearlyRelativeMonth: " + schedule.getYearlyRelativeMonth().getValue() );
               System.out.println( "yearlyRelativeWeek: " + schedule.getYearlyRelativeWeek().getValue() );
               System.out.println( "intradayRecurrenceStart: " + schedule.getIntradayRecurrenceStart().getValue() );
               System.out.println( "intradayRecurrenceEnd: " + schedule.getIntradayRecurrenceEnd().getValue() );
               System.out.println( "intradayRecurrenceInterval: " + schedule.getIntradayRecurrenceInterval().getValue() );
            }
         } );


         contentManagerService.logoff();
      } catch( ServiceException | RemoteException aException ) {
         throw new RuntimeException( "Error communicating with Cognos. ", aException );
      }

   }

   private static ContentManagerService_PortType getContentManagerService() throws ServiceException, RemoteException {
      ContentManagerService_ServiceLocator cmLocator = new ContentManagerService_ServiceLocator();
      cmLocator.setcontentManagerServiceEndpointAddress( SoapConfig.url );
      ContentManagerService_PortType cm = cmLocator.getcontentManagerService();
      cm.logon( new XmlEncodedXML( getCredentialsXml( SoapConfig.namespace, SoapConfig.username, SoapConfig.password ) ),
            null );
      SOAPHeaderElement
            biBusHeader = ((Stub) cm).getResponseHeader( "http://developer.cognos.com/schemas/bibus/3/", "biBusHeader" );
      ((Stub) cm).setHeader( biBusHeader );
      return cm;
   }

   private static String getCredentialsXml( String aNamespace, String aUser, String aPassword ) {

      return "<credential>" +
            "<namespace>" + aNamespace + "</namespace>" +
            "<username>" + aUser + "</username>" +
            "<password>" + aPassword + "</password>" +
            "</credential>";
   }

   public static class SoapConfig {
      public static final String url = "http://cognosServer:9300/p2pd/servlet/dispatch";
      public static final String namespace = "namespaceId";
      public static final String username = "user";
      public static final String password = "password";
   }
}

The output of the code was the following:

================
Querying for report with search path : /content/folder[@name='Samples']/folder[@name='Reports']/folder[@name='Standard reports']/report[@name='Employee expenses']
Search path: /content/folder[@name='Samples']/folder[@name='Reports']/folder[@name='Standard reports']/report[@name='Employee expenses']
Owner: CAMID("MyLDAP:u:uid=user,ou=people")
Creation Date: Thu Nov 26 09:46:27 CST 2015
Modification Date: Wed Nov 03 16:27:40 CDT 2021
================
Querying for schedule with search path : /content/folder[@name='Samples']/folder[@name='Reports']/folder[@name='Standard reports']/report[@name='Employee expenses']
Search path: /content/folder[@name='Samples']/folder[@name='Reports']/folder[@name='Standard reports']/report[@name='Employee expenses']/schedule[@name='2021-11-03T19:28:17.414Z']
timeZoneID: null
triggerName: null
active: true
dailyPeriod: day
endDate: Fri Nov 05 14:28:11 CDT 2021
endType: onDate
everyNPeriods: 1
monthlyAbsoluteDay: null
monthlyRelativeDay: null
monthlyRelativeWeek: null
startDate: Wed Nov 03 14:27:24 CDT 2021
type: weeklyWithIntradayRecurrence
weeklyMonday: false
weeklyTuesday: false
weeklyWednesday: true
weeklyThursday: false
weeklyFriday: false
weeklySaturday: false
weeklySunday: false
yearlyAbsoluteDay: null
yearlyAbsoluteMonth: null
yearlyRelativeDay: null
yearlyRelativeMonth: null
yearlyRelativeWeek: null
intradayRecurrenceStart: 19:27:51.000Z
intradayRecurrenceEnd: 03:27:51.000Z
intradayRecurrenceInterval: PT1H

To run this, you will need to fill in your Cognos server and authentication information in the SoapConfig class as well as ensure that the Cognos SDK JARs are on the classpath.