Created On:  09 October 2012

Problem:

How do you list all requirement trace information using CaliberRM SDK using Java?

Resolution:

Below is sample Java code used to retrieve a list of requirement trace information. Please replace the Caliber server name and login credentials below with those relevant to your environment.

import com.starbase.caliber.*;
import com.starbase.caliber.external.*;
import com.starbase.caliber.external.xgeneric.XGenericObject;
import com.starbase.caliber.server.*;

public class FindTrace {
 public static void main(String[] args) {
  //Caliber server
  String host = "localhost";
  //Username
  String login = "admin";
  //Password
  String password = "admin";
  //Requirement ID
  int reqID = 905;

  CaliberServer server = new CaliberServer(host);
  Session session = null;

  try {
   session = server.login(login, password);

   Requirement r = session.getRequirement(reqID);
   Trace[] traces = r.getTracesTo();
   System.out.println("To "+traces.length);

   Trace[] tracesF = r.getTracesFrom();
   System.out.println("From "+tracesF.length);

   for (int i = 0; i < traces.length; i++) {
    CaliberObject to = traces.getToObject();
    CaliberObject from = traces.getFromObject();

    if (to instanceof IntegrationObject) {
     IntegrationObject extObject = (IntegrationObject) to;
     System.out.println("Int Object "+extObject.getIntegrationName());
     System.out.println(extObject.getIntegrationContextID());

    }
    if (to instanceof XGenericObject) {
     XGenericObject extObject = (XGenericObject) to;
     System.out.println("XGen Object "+extObject.getName());     

    }
    if (to instanceof ExternalObject) {
     ExternalObject extObject = (ExternalObject) to;
     System.out.println("Ext Object "+extObject.getName());
     
    }
   }
  } catch (Exception e) {
   e.printStackTrace();
  } finally {
   if (session != null) {
    session.logout();
   }
  }
 }
}

Incident #2595645