Oracle® Discussions Application Developer's Guide
10g Release 1(10.1.2) B28208-02 |
|
Previous |
Next |
The Category Service provides the following category-related operations:
Creating a category
Fetching category details, given the category ID
Listing containers under a given category
Updating the category definition
Deleting a category
Apart from the preceding operations, it also provides bulk operations to create and delete multiple categories in a single invocation. This chapter addresses the task of Creating a Category.
The following is an example for creating a category:
Example 8-1 Creating a Category
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.CategoryServiceSoapBindingStub;import oracle.discussions.ws.CategoryServiceServiceLocator;import oracle.discussions.ws.CategoryService; 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. CategoryServiceServiceLocator fssl = new CategoryServiceServiceLocator(); //Get a handle to the actual web service. CategoryService fs = fssl.getCategoryService(); //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. ((CategoryServiceSoapBindingStub)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. CategoryDefinition cDefn = new CategoryDefinition(); cDefn.setName("My Category"); cDefn.setDisplayName("My Category"); cDefn.setDescription("My Category"); cDefn.setWithAnnouncementBoard(true); //- 1 indicates that a root level category is created Category aContainer = fs.create(-1,cDefn); if(aContainer != null) { System.out.println("Container Type :" + aContainer.getContainerType()); System.out.println("Creation Date :" + aContainer.getCreationDate().getTime()); System.out.println("Creator :" + aContainer.getCreator()); System.out.println("Description :" + aContainer.getDescription()); System.out.println("Display Path :" + aContainer.getDisplayPath()); System.out.println("Display Name :" + aContainer.getDisplayName()); LastPost lp = aContainer.getLastPost(); if(lp != null) { System.out.println("Author :" + lp.getLastpostAuthor()); System.out.println("Date :" + lp.getLastpostDate()); System.out.println("Forum ID :" + lp.getLastpostForumId()); System.out.println("Topic id :" + lp.getLastpostTopicId()); System.out.println("Message Id :" + lp.getLastpostMessageId()); } System.out.println("Is Favorite :" + aContainer.isFavorite()); System.out.println("Is New :" + aContainer.isNewFolder()); System.out.println("Is New Since Last Visit :" + aContainer.isNewSinceLastVisit()); System.out.println("Is New Since Session :" + aContainer.isNewSinceSession()); System.out.println("Name :" + aContainer.getName()); System.out.println("Id :" + aContainer.getId()); System.out.println("is category type :" + aContainer.isCategoryType()); System.out.println("Web ui URL :" + aContainer.getWebuiURL()); System.out.println("Rss URL :" + aContainer.getRssURL()); System.out.println("Has ann forum :" + aContainer.isAnnouncementsBoardPresent()); System.out.println("Parent id :" + aContainer.getParentId()); } //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 create()
method of the categoryService
interface creates a new category in the repository. If the value of lParentId
is -1
then a root-level category is created. Otherwise, a category is created under the container represented by lParentId
. An exception is raised if lParentId
does not pertain to a valid category.
The properties of the category to be created are specified in the category definition bean (cDefn
in this example).
Note: The category name and the category display name are mandatory. They are unique arguments in the category definition bean and hence they cannot be null. |
The sample output for Example 8-1 is as follows:
Cookie : JSESSIONID=8c57046a22b8a4e4d7408338486da27bb6988d0322f2Container Type :1Creation Date :Sun Feb 26 20:44:53 PST 2006Creator :td_superuserDescription :My CategoryDisplay Path :/My CategoryDisplay Name :My CategoryIs Favorite :falseIs New :falseIs New Since Last Visit :falseIs New Since Session :falseName :My categoryId :85770is category type :trueWeb ui URL :http://stacx01:8888/discussions/app/mainAction.do?fid=85770Rss URL :http://stacx01:8888/discussions/rss/facility?fid=85770Has ann forum :trueParent id :-1User logout.Done