//Java Sample using ApplyQuery
import com.opentext.api.*;
public class ApplyQuery
{
//For Connection
private static String Server = "houlnkdev1";
private static int Port = 2099;
private static String DFT = "";
private static String User = "llapi";
private static String Pass = "llapi";
public static void main( String[] args )
{
try
{
//variables
LLSession session;
LAPI_DOCUMENTS doc;
LAPI_SEARCH search;
int brokerID;
//Constructors for session and search objects
session = new LLSession (Server, Port, DFT, User, Pass);
search = new LAPI_SEARCH (session);
brokerID = GetSearchBroker(search, session);
Search(brokerID, session, search);
}
catch ( Throwable e )
{
System.err.println( e.getMessage() );
e.printStackTrace( System.err );
}
}
public static int GetSearchBroker(LAPI_SEARCH search, LLSession session)
{
//Returns the BrokerID for the Enterprise Slice
LLValue vListBrokers, tmpAssoc;
int length, brokerID;
String nodeName, broker;
broker = "Enterprise";
brokerID = -1;
//Define the value objects
vListBrokers = new LLValue(); //List of available brokers
tmpAssoc = new LLValue(); //Temp Assoc
// Retrieve the Search Brokers
if (search.GetSearchBrokers(vListBrokers) != 0)
{
System.out.println("Failed to get Search Brokers");
sError(session);
}
else
{
//Find the Enterpise BrokerID
length = vListBrokers.size();
for (int i=0; i<length; i++)
{
tmpAssoc = vListBrokers.toValue(i);
nodeName = tmpAssoc.toString("NodeName");
System.out.println("Got this Broker"+nodeName );
if (nodeName.equals(broker))
{
brokerID = tmpAssoc.toInteger("NodeID");
}
}
}
return (brokerID);
}
public static void Search(int brokerID, LLSession session, LAPI_SEARCH search)
{
//Use Apply query to Search for a specified term
//Variables
LLValue vSelectList, vQueryResults, value;
String where, fName;
int length;
//Define value objects
vSelectList = new LLValue().setList();
vQueryResults = new LLValue();
value = new LLValue();
//Set up the list of fields for ApplyQuery to return
//Note: OTObject must be in this list for ApplyQuery to work
vSelectList.add( "OTName" ); //Object Name
//vSelectList.add( "OTDataID" ); //The objects ID
vSelectList.add( "OTObject" );
vSelectList.add( "OTOwnerID" ); //The objects VolumeID
//Where clause which searches on the OTName region for the word "Livelink"
where = "(OTData :\"Livelink\")";
//Search Livelink
if ( search.ApplyQuery( brokerID, vSelectList, where, search.SORTBYDEFAULT, "OTName", 0, 100, "LivelinkQueryLanguage", vQueryResults) != 0)
{
System.out.println("Apply query failed");
sError(session);
}
else
{
//Displays the results of the search
length = vQueryResults.size();
if (length > 0)
{
System.out.println("The query returned "+ length+" results");
for (int i=0; i<length; i++)
{
value = vQueryResults.toValue(i);
fName = value.toString("OTName");
System.out.println(fName);
}
}
}
}
private static void sError(LLSession session)
{
//Error Checking
System.out.println("Status Code: " + session.getStatus());
System.out.println("Api Error: " + session.getApiError());
System.out.println("Error Message: " + session.getErrMsg());
System.out.println("Status Message: " + session.getStatusMessage());
}
}