AquaLogic User Interaction Development Guide

     Previous Next  Open TOC in new window   View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Querying ALI Objects Using the IDK Remote Search API

To search for ALI objects and documents from a remote application, use the IPortalSearchRequest interface in the IDK.

To construct a query, follow the steps below.
  1. Create a session with the portal. For details, see Initiating a PRC Session to Use IDK Remote APIs.
  2. Retrieve an ISearchFactory from the session by calling IRemoteSession.getSearchFactory.
  3. Create a new IPortalSearchRequest to represent your query.
  4. Create a new method and construct the query, as shown in the sample code that follows.

The sample code below demonstrates how to query for a folder ID by folder name. The folder ID is required to execute other PRC functionality, including creating portlets, documents and groups. This example uses query constraints; for more information, see Using Query Constraints with the IDK Remote Search API.

Java

//set the endpoint to the value of web services server
String endpoint = "http://IP-GW-AS08:9080/ptapi/services/QueryInterfaceAPI";
URL url = new URL(endpoint);

//set username and password to log in
//hard-coding the values is only for demo purposes
String username = "Administrator";
String password = "";
IRemoteSession prcSession = RemoteSessionFactory.getExplicitLoginContext(url, username, password);
ISearchFactory searchFactory = prcSession.getSearchFactory();
IPortalSearchRequest searchRequest = searchFactory.createPortalSearchRequest();
public static int getFolderId(IPortalSearchRequest searchRequest, String folderName)
 throws Exception
{
	int folderId = -1;

	//search for the given folder name
	searchRequest.setQuery(folderName);

	// only search for folders
	ObjectClass[] objectTypes = {ObjectClass.DocumentFolder};
	searchRequest.setObjectTypesToSearch(objectTypes);

	ISearchResponse searchResponse = searchRequest.execute();
	ISearchResultSet resultSet = searchResponse.getResultSet();
	int numResults = searchResponse.getReturnedCount();

	if(numResults > 0)
		{
		Enumeration results = resultSet.getResults(); //just get the first element
		IPortalSearchResult result = (IPortalSearchResult) results.nextElement();
		folderId = result.getObjectID();
		}

	returnfolderId;
}

.NET (C#)

//set the endpoint to the value of web services server
String endpoint = "http://IP-GW-AS08:9080/ptapi/services/QueryInterfaceAPI";

//set username and password to log in
//hard-coding the values is only for demo purposes
String username = "Administrator";
String password = "";
IRemoteSession session = RemoteSessionFactory.GetExplicitLoginContext(new System.Uri(endpoint), username, password);
ISearchFactory searchFactory = session.GetSearchFactory();
IPortalSearchRequest searchRequest = searchFactory.CreatePortalSearchRequest();

public static int GetFolderId(IPortalSearchRequest searchRequest, String folderName)
{
	int folderId = -1;

	//search for the given folder name
	searchRequest.SetQuery(folderName);

	// only search for folders
	ObjectClass[] objectTypes = {ObjectClass.DocumentFolder};
	searchRequest.SetObjectTypesToSearch(objectTypes);

	ISearchResponse searchResponse = searchRequest.Execute();
	ISearchResultSet resultSet = searchResponse.GetResultSet();
	int numResults = searchResponse.GetReturnedCount();

	if(numResults > 0)
		{
		Enumeration results = resultSet.GetResults(); //just get the first element
		IPortalSearchResult result = (IPortalSearchResult) results.Current;
		folderId = result.GetObjectID();
		}

	returnfolderId;
}

.NET (VB)

//set the endpoint to the value of web services server
String endpoint = "http://IP-GW-AS08:9080/ptapi/services/QueryInterfaceAPI"

//set username and password to log in
//hard-coding the values is only for demo purposes
String username = "Administrator"
String password = ""

Dim session As IRemoteSession = RemoteSessionFactory.GetExplicitLoginContext(New
System.Uri(endpoint), username, password)
Dim searchFactory As ISearchFactory = session.GetSearchFactory()
Dim searchRequest As IPortalSearchRequest = searchFactory.CreatePortalSearchRequest()

Public Shared Function GetFolderID(ByVal searchRequest As IPortalSearchRequest, ByVal
folderName As String)

	Dim folderID As Int32 = -1
	searchRequest.SetQuery(folderName)

	Dim objectTypes() As ObjectClass = {ObjectClass.DocumentFolder}
	searchRequest.SetObjectTypesToSearch(objectTypes)

	Dim searchResponse As ISearchResponse = searchRequest.Execute()
	Dim resultSet As ISearchResultSet = searchResponse.GetResultSet()
	Dim numResults As Int32 = searchResponse.GetReturnedCount()

	If (numResults > 0) Then

		Dim results As IEnumerator = resultSet.GetResults()
		results.MoveNext()
		Dim result As IPortalSearchResult = DirectCast(results.Current, IPortalSearchResult)
		folderId = result.GetObjectID()

	End If

	Return folderId

End Function

  Back to Top      Previous Next