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 IDK Remote APIs

To query for ALI objects from a remote application, use the IObjectManager interface in the PRC.

The IObjectManager interface in the PRC allows you to query for objects using a range of methods, including location, class, and custom filters. To query for portal objects, follow the steps below. You can also use the PRC Search API to query for portal objects; for details, see Querying ALI Objects Using the IDK Remote Search API.
  1. Create a session with the portal. For details, see Initiating a PRC Session to Use IDK Remote APIs.
  2. Retrieve an Object Manager for the type of object you are querying. For details, see Retrieving ALI Object Managers Using IDK Remote APIs.
  3. Execute the query, as shown in the sample code below. This example demonstrates how to query for portal users matching specific criteria within the portal, using the following process:
    1. Declare and prepare all parameters to be passed to the query method. This example uses the most flexible query call, with the following parameters. If any of these parameters is omitted, the default value will be used. (There are simpler calls with fewer parameters; for details, see the IDK API documentation.)
      Parameter Description Default
      folderID The folder to search. all folders (folderID = -1)
      startRow The row on which to start the search. the initial row (startRow = 0)
      maxRows The maximum number of rows to search. unlimited (maxRow = -1)
      sortProperty The object property on which to sort results. object ID (sortProperty = ObjectProperty.ObjectID)
      ascending The sort order for results (ascending or descending). ascending (ascending = true)
      propsToReturn The properties to return. all properties
      filters The values on which to filter results. no filters
    2. Execute the query to retrieve an IObjectQuery instance.
    3. Enumerate through the query, displaying interesting information.

Java:

public static voidqueryObjects(String loginToken)
{
 IObjectManager objectManager = getSession(loginToken).getObjectManager(ObjectClass.User);

 int folderID = -1;  //search all folders
 int startRow = 0;  //start at the first found
 int maxRows = -1;  //return unlimited results
 ObjectProperty sortProperty = UserProperty.UniqueName;  //sort on the unique name
 boolean ascending = true;  //sort ascending

 ObjectProperty[] propsToReturn = new ObjectProperty[4];  //return specific properties
 propsToReturn[0] = UserProperty.SimpleName;
 propsToReturn[1] = UserProperty.UniqueName;
 propsToReturn[2] = UserProperty.AuthName;
 propsToReturn[3] = ObjectProperty.Created;

 QueryFilter[] filters = new QueryFilter[2];  //filter the results
 //simple name contains "user" 
 filters[0] = new StringQueryFilter(UserProperty.SimpleName, Operator.Contains,"user");  
 //created at most a day ago
 GregorianCalendar filterDate = new GregorianCalendar();
 filterDate.add(Calendar.DATE, -1);
 Date yesterday = filterDate.getTime();
 filters[1] = new DateQueryFilter(ObjectProperty.Created, Operator.GreaterThan, yesterday);
 try
 {
 IObjectQuery queryResults = objectManager.queryObjects(
 folderID,
 startRow,
 maxRows,
 sortProperty,
 ascending,
 propsToReturn,
 filters);

 for(int i = 0; i < queryResults.getRowCount(); i++)
 {
 IObjectQueryRow queryObject = queryResults.getRow(i);
 System.out.println(
 "User: " + queryObject.getStringValue(UserProperty.SimpleName) +
 ", Created:" + queryObject.getCreated());
 }
 }
 catch(Exception e)
 {
 System.err.println(e.getMessage());
 e.printStackTrace(System.err);
 }
}

.NET (C#):

public static voidQueryObjects(stringloginToken)
{
 IObjectManager objectManager = GetSession(loginToken).GetObjectManager(ObjectClass.User);

 int folderID = -1;  //search all folders
 int startRow = 0;  //start at the first found
 int maxRows = -1;  //return unlimited results
 ObjectProperty sortProperty = UserProperty.UniqueName;  //sort on the unique name
 bool ascending = true;  //sort ascending

 ObjectProperty[] propsToReturn = new ObjectProperty[4];  //return specific properties
 propsToReturn[0] = UserProperty.SimpleName;
 propsToReturn[1] = UserProperty.UniqueName;
 propsToReturn[2] = UserProperty.AuthName;
 propsToReturn[3] = ObjectProperty.Created;

 DateTime yesterday =  new DateTime();
 yesterday = DateTime.Now.AddDays(-1); 

 QueryFilter[] filters = new QueryFilter[2];  //filter the results
 //simple name contains "user"
 filters[0] = new StringQueryFilter(UserProperty.SimpleName, Operator.Contains, "user");
 //created at most a day ago
 filters[1] = new DateQueryFilter(ObjectProperty.Created, Operator.GreaterThan, yesterday);

 try
 {
 IObjectQuery queryResults = objectManager.QueryObjects(
 folderID,
 startRow,
 maxRows,
 sortProperty,
 ascending,
 propsToReturn,
 filters);

 for(int i = 0; i < queryResults.GetRowCount(); i++)
 {
 IObjectQueryRow queryObject = queryResults.GetRow(i);
 Console.Out.WriteLine(
 "User: " + queryObject.GetStringValue(UserProperty.SimpleName) +
 ", Created:" + queryObject.GetCreated());
 }
 }
 catch(Exception e)
 {
 Response.Write(e.Message + "<br>");
 Response.Write(e.StackTrace + "<br><br>");
 }
}

.NET (VB):

Public Shared SubQueryObjects(ByVal loginToken As String)

 Dim objectManager As IObjectManager
 Dim session As IRemoteSession = portletContext.GetRemotePortalSession

 objectManager = session.GetObjectManager(ObjectClass.User)

 Dim folderID As Integer
 folderID = -1 'search all folders

 Dim startRow As Integer
 startRow = 0 'start at the first found

 Dim maxRows As Integer
 maxRows = -1 'return unlimited results

 Dim sortProperty As ObjectProperty
 sortProperty = UserProperty.UniqueName 'sort on the unique name

 Dim ascending As Boolean
 ascending = True 'sort ascending

 Dim propsToReturn(4) As ObjectProperty 'return specific properties
 propsToReturn(0) = UserProperty.SimpleName
 propsToReturn(1) = UserProperty.UniqueName
 propsToReturn(2) = UserProperty.AuthName
 propsToReturn(3) = ObjectProperty.Created

 Dim yesterday As DateTime
 yesterday = DateTime.Now.AddDays(-1)

 Dim filters(2) As QueryFilter 'filter the results
 'simple name contains "user"
 filters(0) = New StringQueryFilter(UserProperty.SimpleName, _Operator.Contains, _"user") 
 'created at most a day ago
 filters(1) = New DateQueryFilter(ObjectProperty.Created, _Operator.GreaterThan, yesterday) 

 Try

 Dim queryResults As IObjectQuery
 queryResults = objectManager.QueryObjects(folderID, startRow, maxRows, sortProperty,
ascending, propsToReturn, filters)

 Dim i As Integer
 Dim queryObject As IObjectQueryRow
 For i = 0 To queryResults.GetRowCount()-1

 queryObject = queryResults.GetRow(i)
 Response.Write(_ "User: " & queryObject.GetStringValue(UserProperty.SimpleName)& _
 ", Created:" & queryObject.GetCreated() + "<br>")
 Next 

 Catch e As Exception
 Response.Write(e.Message + "<br>")
 Response.Write(e.StackTrace)

 End Try
EndSub

  Back to Top      Previous Next