Oracle® Discussions Application Developer's Guide
10g Release 1(10.1.2) B28208-02 |
|
Previous |
Next |
The Container Service interface provides methods common to both Category and Forum Services. It acts as a logical parent service to both the services.
The Container Service interface consists of methods for the following operations:
Retrieving parent category of a container
Retrieving the information on the last post in a container
Searching a container
Retrieving announcements forum in a container
Listing or updating roles of users on a container
This chapter addresses the following tasks:
The following is an example to search Oracle Discussions Containers by using a search term as the search criterion:
Example 7-1 Searching Oracle Discussion Containers
import java.util.Date; import java.io.*; import java.util.*; import javax.mail.*; import javax.mail.internet.*; import org.apache.axis.transport.http.HTTPConstants;import oracle.discussions.ws.exceptions.TdWSException;import oracle.discussions.ws.beans.*;import oracle.discussions.ws.AuthenticationServiceServiceLocator;import oracle.discussions.ws.AuthenticationServiceSoapBindingStub;import oracle.discussions.ws.AuthenticationService;import oracle.discussions.ws.ContainerServiceSoapBindingStub;import oracle.discussions.ws.ContainerServiceServiceLocator;import oracle.discussions.ws.ContainerService; public class WSClient{ private static AuthenticationService as = null; public static String getCookie() throws Exception { //STEP - 0: User Login //Create the service locator for authentication service. The locator //contains information about the web Services endpoint AuthenticationServiceServiceLocator assl = new AuthenticationServiceServiceLocator(); //Get the handle to the actual webservices interface. as = assl.getAuthenticationService(); //Indicate to the server that the client is interested in maintaining //session. //HTTP is stateless and the user state is maintained in the session. //Unless the user is willing to participate in a session, user state //cannot be preserved. ((AuthenticationServiceSoapBindingStub)as).setMaintainSession(true); //Invoke the actual login webservices call. as.login("td_superuser","welcome1"); //Retrieve the cookie. The cookie is set on successful authentication. String cookie = (String)((AuthenticationServiceSoapBindingStub)as) ._getCall().getMessageContext() .getProperty(HTTPConstants.HEADER_COOKIE); System.out.println("Cookie : " + cookie); return cookie; } public static void main(String args[]) { try { //STEP - 0: User Login String cookie = getCookie(); //STEP - 1: Locate the Web Services end point. //The Web Services locator contains the webservices end point address. //Hence instantiate the service locator. ContainerServiceServiceLocator fssl = new ContainerServiceServiceLocator(); //Get a handle to the actual web service. ContainerService fs = fssl.getContainerService(); //Indicate to the server that the user is willing to participate in the //session. //Since HTTP is stateless, all the client data is maintained in the //session. ((ContainerServiceSoapBindingStub)fs).setMaintainSession(true); //Set the cookie retrieved in the call to login webservice. //The cookie asserts user's identity to the server. ((javax.xml.rpc.Stub)fs)._setProperty(HTTPConstants.HEADER_ COOKIE,cookie); //Invoke the actual web services call. SearchTerm st = new SearchTerm(); st.setAuthor("td_superuser"); //The container ID needs to be changed accordingly ForumMessage sr[] = fs.search(new long[]{15524},st,true); if(sr != null) { for(int i = 0; i < sr.length; i++) { System.out.println("Subject :" + sr[i].getSubject()); System.out.println("Plain Text :" + sr[i].getBodyPlainText()); String[] frmAdd = sr[i].getFromAddresses(); if(frmAdd != null) { for(int j = 0 ; j < frmAdd.length ; j++) System.out.println("From Address :" + frmAdd[j]); } System.out.println("Level :" + sr[i].getLevel()); System.out.println("No of replies :" + sr[i].getNumberOfReplies()); System.out.println("Oracle Msg Id :" + sr[i].getMessageId()); System.out.println("is new since session :" + sr[i].isNewSinceSession()); System.out.println("is new since last visit :" + sr[i].isNewSinceLastVisit()); System.out.println("is new " + sr[i].isNewMessage()); System.out.println("Has Attachments :" + sr[i].isHasAttachments()); System.out.println("X Priority :" + sr[i].getXPriority()); System.out.println("Sent date :" + sr[i].getSentDate()); System.out.println("Size :" + sr[i].getSize()); System.out.println("HTML ? :" + sr[i].isHTMLContentType()); System.out.println("WebUI URL :" + sr[i].getWebUIUrl()); } } //STEP - 2: User Logout logout(); } catch(TdWSException ex) { System.out.println("Error Code :" + ex.getErrorCode()); System.out.println("Error Message :" + ex.getErrorMessage()); String[] trace = ex.getServerStackTrace(); if(trace != null) { for(int i = 0 ; i < trace.length ; i++) System.out.println("trace[" + i + "]" + trace[i]); } } catch(Exception ex) { System.out.println("Never went into tdex :" + ex.getMessage()); ex.printStackTrace(); } } public static void logout() throws Exception { System.out.println("User logout."); //Once all the webservices operations are done, invoke logout //operation. //On logout, user state is destroyed and the cookie is invalidated. as.logout(); System.out.println("Done"); }}
The search()
method in the ContainerService
interface searches the containers specified by lContainerId
for search term st
. If no container IDs are supplied then all the Oracle Discussions containers, for which the user has access, are searched. If a container ID array is supplied, then only those containers are searched.
The method also accepts a boolean parameter that indicates if the announcements are also to be searched. Wild-card searches can also be performed. This method has the following three attributes:
lContainerId
is the array of container IDs specifying search scope.
st
is the search term specifying search context.
bSearchAnnouncements
is the boolean value indicating if announcements are also to be searched.
The ContainerService.search()
returns sr
which is an array of forum message beans that represents search results.
The sample output for Example 7-1 is as follows:
Subject :Topic-1Plain Text :Topic-1From Address :Admin <td_superuser@stacx01.us.oracle.com>Level :0No of replies :0Oracle Msg Id :161673is new since session :falseis new since last visit :falseis new falseHas Attachments :falseX Priority :1Sent date: Sun Feb 26 19:54:18 PST 2006Size :404HTML ? :falseWebUI URL :http://stacx01:8888/discussions/app/mainAction.do?fid=15524&tid=161673&mid=161673#161673User logout.Done
The following is an example for updating and listing grantee roles:
Example 7-2 Updating and Listing Grantee Roles
import java.util.Date; import java.io.*; import java.util.*; import javax.mail.*; import javax.mail.internet.*; import org.apache.axis.transport.http.HTTPConstants;import oracle.discussions.ws.exceptions.TdWSException;import oracle.discussions.ws.beans.*;import oracle.discussions.ws.AuthenticationServiceServiceLocator;import oracle.discussions.ws.AuthenticationServiceSoapBindingStub;import oracle.discussions.ws.AuthenticationService;import oracle.discussions.ws.ContainerServiceSoapBindingStub;import oracle.discussions.ws.ContainerServiceServiceLocator;import oracle.discussions.ws.ContainerService; public class WSClient{ private static AuthenticationService as = null; public static String getCookie() throws Exception { //STEP - 0: User Login //Create the service locator for authentication service. The locator //contains information about the Web Services endpoint AuthenticationServiceServiceLocator assl = new AuthenticationServiceServiceLocator(); //Get the handle to the actual webservices interface. as = assl.getAuthenticationService(); //Indicate to the server that the client is interested in maintaining //session. //HTTP is stateless and the user state is maintained in the session. //Unless the user is willing to participate in a session, user state cannot //be preserved. ((AuthenticationServiceSoapBindingStub)as).setMaintainSession(true); //Invoke the actual login webservices call. as.login("td_superuser","welcome1"); //Retrieve the cookie. The cookie is set on successful authentication. String cookie = (String)((AuthenticationServiceSoapBindingStub)as) ._getCall().getMessageContext() .getProperty(HTTPConstants.HEADER_COOKIE); System.out.println("Cookie : " + cookie); return cookie; } public static void main(String args[]) { try { //STEP - 0: User Login String cookie = getCookie(); //STEP - 1: Locate the Web Services end point. //The web services locator contains the webservices end point address. //Hence instantiate the service locator. ContainerServiceServiceLocator fssl = new ContainerServiceServiceLocator(); //Get a handle to the actual web service. ContainerService fs = fssl.getContainerService(); //Indicate to the server that the user is willing to participate in the //session. //Since HTTP is stateless, all the client data is maintained in the //session. ((ContainerServiceSoapBindingStub)fs).setMaintainSession(true); //Set the cookie retrieved in the call to login webservice. //The cookie asserts user's identity to the server. ((javax.xml.rpc.Stub)fs)._setProperty(HTTPConstants.HEADER_COOKIE,cookie); //Invoke the actual web services call. Role role1 = new Role(); role1.setId(1); role1.setName("oracle.discussions.roles.board_reader"); GranteeRole[] grArray = new GranteeRole[3]; GranteeRole gr1 = new GranteeRole(); //The user ID and the email ID neeeds to be changed accordingly gr1.setEmail("tduser1@stacx01.us.oracle.com"); gr1.setRole(role1); Role role2 = new Role(); role2.setId(8); role2.setName("oracle.discussions.roles.board_moderator"); GranteeRole gr2 = new GranteeRole(); gr2.setEmail("tduser@stacx01.us.oracle.com"); gr2.setRole(role2); Role role3 = new Role(); role3.setId(8); role3.setName("oracle.discussions.roles.board_moderator"); GranteeRole gr3 = new GranteeRole(); gr3.setEmail("td_superuser@stacx01.us.oracle.com"); gr3.setRole(role3); grArray[0] = gr1; grArray[1] = gr2; grArray[2] = gr3; GranteeRole[] gr = fs.updateGranteeRoles(6732,grArray); if(gr != null) { for(int i = 0 ; i < gr.length ; i++) { System.out.println(gr[i].getRole().getName()); System.out.println(gr[i].getEmail()); } } //STEP - 2: User Logout logout(); } catch(TdWSException ex) { System.out.println("Error Code :" + ex.getErrorCode()); System.out.println("Error Message :" + ex.getErrorMessage()); String[] trace = ex.getServerStackTrace(); if(trace != null) { for(int i = 0 ; i < trace.length ; i++) System.out.println("trace[" + i + "]" + trace[i]); } } catch(Exception ex) { System.out.println("Never went into tdex :" + ex.getMessage()); ex.printStackTrace(); } } public static void logout() throws Exception { System.out.println("User logout."); //Once all the webservices operations are done, invoke logout //operation. //On logout, user state is destroyed and the cookie is invalidated. as.logout(); System.out.println("Done"); }}
The GranteeRole
class represents the role of a Oracle Discussions user in the container.
The updateGranteeRoles()
method edits the roles of users in the container specified by lContainerId
. While invoking the operation, it is important that the grantee role information of the user invoking the action is also specified. The roles inherited from the parent container cannot be edited at this container level. An exception is raised if a user tries to edit his own role. This method has the following two attributes:
lContainerId
is the ID that specifies the container on which the roles are to be edited.
grRoleArray
is an array of beans that represents grantee roles.
This method returns grArrayRes
which is an array of beans representing updated grantee roles.
The listGranteeRoles()
method returns the roles of all the users on the container specified by the lContainerId
.
The sample output for Example 7-2 is as follows:
Cookie : JSESSIONID=8c57046a22b8ed03c740184043cca9fb9c7877bee658Updating the grantee role information.Updated grantee role information successfully.