Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search with ApplyQuery problems

Status
Not open for further replies.

huTorres

Programmer
Jan 22, 2007
6
NL
Hello.
I am trying to use the JAVA LAPI method ApplyQuery to search for an object in livelink.

I am doing:

LLValue selectList = (new LLValue()).setList();
selectList.add("ID");

status = this.search.ApplyQuery(topicId, selectList, "", LAPI_SEARCH.SORTBYNOTHING, "OTName" , 0, 1, "None", topic);

I get an exception back, with no desc..

Can anyone help on how to use this 'ApplyQuery' in JAVA? Any examples?

Thanks in advance.
 
This works for me
Code:
//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());
	}



}

Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
 
Also if you do not want to go cuckoo,please use XMLsearchAPI being advocated even by opentext than lapi search.there is an intereting thread probably David Templeton commented on in this forum about pros and cons of lapi search.

Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
 
appnair, thanks for your reply.
Currently I am doing the following (see code above) and I get the exception:
- get(name) not implemented for this datatype


LLValue vQueryResults = new LLValue();
LLValue objectInfo = new LLValue().setAssocNotSet();
LLValue createInfo = new LLValue().setAssoc();
LLValue aRequest = new LLValue().setAssoc();
LLValue selectList = new LLValue().setList();

aRequest.add("Content", topicBody);
createInfo.add("Request", aRequest);

selectList.add( "OTName" ); //Object Name
//selectList.add( "OTDataID" ); //The objects ID
selectList.add( "OTObject" );
selectList.add( "OTOwnerID" ); //The objects VolumeID

//LAPI_SEARCH vSearch = new LAPI_SEARCH (connector.getSession());


try {
// Where clause which searches on the OTName region for the word "Livelink"
//String where = "(OTData :\"Discussion2\")";
//To find all discussions that contain the word 'Discussion' either in their body or in an attribute
String where = "(OTSubType : 215) AND Discussion";


log.debug("topic ID: " + topicId);
status = this.search.ApplyQuery(topicId, selectList, where,
LAPI_SEARCH.SORTBYDEFAULT, "OTName" , 0, 1, "LivelinkQueryLanguage", vQueryResults );


I have seen this problem beeng reported before and it seams that the solution was installing some patches.. Any other ideas?

Thanks
 
I would first try to search the instance thru the livelink GUI and verify the results.get(name) not implemented just means that your api call did not get a success,but somwhere in the code you are trying to get something out like a system.out println

As an example to illustrate.if you say
doc.accessEnterpriseWS(wsinfo)

If the call does not execute to be zero and you had a statement like
parentVol = pwsInfo.toInteger( "VolumeID" );
parentID = pwsInfo.toInteger( "ID" );

the get(name) error will happen.

So rather than assuming patches and the system at fault I would first test the livelink search server by issuing a GUI
search command along the same lines as your query.If livelink search works and your lapi query does not then it might be worth looking into.


Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
 
appnair, thanks for your time.
I understand what you say, but the exception (get(name)..) I get is throwed from the search.ApplyQuery, not from any of my code. The status code (status = this.search.ApplyQuery()) returned is 0. So it seams that the search goes ok, but the execption is trowed.
I think that debugging the LAPI would be the best solution for my problem. Any documentation that explains how to do this?

Unfortnatly I am not experienced with GUI searching. I will try to check that.

My code is:

public int createTopicReply(LLValue folder, int topicId, String topicSubject,
String topicBody) throws Exception
{
int result;
int status;
LLValue vQueryResults = new LLValue();
LLValue objectInfo = new LLValue().setAssocNotSet();
LLValue createInfo = new LLValue().setAssoc();
LLValue aRequest = new LLValue().setAssoc();
LLValue selectList = new LLValue().setList();

aRequest.add("Content", topicBody);
createInfo.add("Request", aRequest);

selectList.add( "OTName" ); //Object Name
//selectList.add( "OTDataID" ); //The objects ID
selectList.add( "OTObject" );
selectList.add( "OTOwnerID" ); //The objects VolumeID

try {
//Example of search

//To find all discussions that contain the word 'Discussion' either in their body or in an attribute
String where = "(OTSubType : 215) AND Discussion";


log.debug("topic ID: " + topicId);
//search that returns exception
status = this.search.ApplyQuery(topicId, selectList, where,
LAPI_SEARCH.SORTBYDEFAULT, "OTName" , 0, 1, "LivelinkQueryLanguage", vQueryResults );

log.debug("topic ID1: " + topicId);
status = this.doc.CreateObjectEx(topicId, -topicId,
LAPI_DOCUMENTS.REPLYSUBTYPE, LAPI_DOCUMENTS.REPLYSUBTYPE, topicSubject,
createInfo, objectInfo);

if (status != 0) {
//error occurred
throw new Exception((connector.getSession().getErrMsg()) + " " +
(connector.getSession().getStatusMessage()));
}
log.debug("Created object ID: " + objectInfo.toInteger("ID"));
result = objectInfo.toInteger("ID");
}
catch (Exception e) {
//search.ApplyQuery ends up here!!
connector.getStatus();
//log.debug(e.getMessage());
log.debug(ExceptionHelper.create(e, e.getMessage()));
throw new Exception((connector.getSession().getErrMsg()) + " " +
(connector.getSession().getStatusMessage()));
}
return result;
}
 
Assuming you are doing it right and in your livelink system you can search the discussion subtypes,I would probably log a call with OT.I am assuming you have the documentation and
topicid is the searchbroker object.There is also a a mentioning of "Note: You must specify the OTObject region in order to satisfy Livelink's data retrieval and validation code" .Does this lapi user have powers to search ?Can you confirm the basics,like opening up a livelink http page and using the livelink search bar as this lapi user...In working with lapi and livelink for several years the first thing I do is try if it is possible with the livelink GUI,then it should be possible with lapi.

Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
 
appnair,

Some time ago I solved (with Opentext support) my issues with this search method.
Thanks for your useful tips ;)

Hugo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top