Strategy ONE
Obtaining a List of Jobs, filtered by Project Name
The sample code below illustrates how to obtain a full list of jobs, instead of just a count, and how to filter that list by one of the fields of the job. In this example, the field used as a filter is the project name (for readability’s sake), but the project ID can also be used, as well as other fields of the job.
The sample code below returns a list of all jobs from the “MicroStrategy Tutorial” project.
// create a WebObjectsFactory instance
WebObjectsFactory factory = WebObjectsFactory.getInstance();
// Get the job source object
JobSource source = (JobSource) factory.getMonitorSource(EnumWebMonitorType.WebMonitorTypeJob);
// Set up the filter condition to only return jobs whose project name is "MicroStrategy Tutorial"
MonitorFilter filter = source.getFilter();
filter.add(EnumDSSXMLJobInfo.DssXmlJobInfoProjectName, EnumDSSXMLMonitorFilterOperator.DssXmlEqual, "MicroStrategy Tutorial");
// Set level flag to obtain browsing information
source.setLevel(EnumDSSXMLLevelFlags.DssXmlBrowsingLevel);
try {
// Sends the request to Intelligence Server to retrieve job information
JobResults results = source.getJobs();
// Loop through the results to print out browsing information, such as
// the job ID, the user that owns the job, and duration, in seconds, of the job
for (int i=0; i < results.getCount(); i++) {
Job singleJob = results.get(i);
System.out.print("job ID: " + singleJob.getJobID());
System.out.print(", user: " + singleJob.getUserName());
System.out.print(", duration: " + singleJob.getDuration() + " sec");
System.out.println();
}
} catch (WebObjectsAdminException woae) {
woae.printStackTrace();
}
Because of the filter in lines 3-4, information is printed only for jobs from the MicroStrategy Tutorial project.
