Chinaunix首页 | 论坛 | 博客
  • 博客访问: 8686
  • 博文数量: 4
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 50
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-31 16:57
文章分类
文章存档

2010年(1)

2009年(3)

我的朋友
最近访客

分类: Java

2009-09-08 11:39:29

凑合看,不想翻译了.

Static Variables

There are a few static application parameters that you will use in the sample code.

FILENET_USERNAME
The Login ID for the user that you want to connect to FileNet with. Any content or workflows updated will be attributed to this user.

FILENET_PASSWORD
The password for the user

A simple test to see whether a user has sufficient rights to do certain functions via the API is to log in to Workplace and attempt to do the functionality that you are trying through the API. An example is, if you are trying to get a list of Document Classes through the API, you should be able to do the same in Workplace.

FILENET_URI
The URI that the application should use to connect to FileNet. This URI is used by both the CE and PE, and should point to the CE server. Because I'm using WebSphere with the EJB transport, the URI is in the format of "iiop://[server]:[port]/FileNet/Engine". Adjust the URI according to your platforms EJB syntax.

CE_DOMAIN
The Domain represents a logical grouping of physical resources. A single Domain may contain multiple Object Stores.

CE_OBJECTSTORE
An Object Store represents a location in which CE folders and content are managed on the server. The Object Store name can be found in FEM or by logging into Workplace and looking at the list of Object Stores on the left side.

Each Object Store has its own set of Document Classes that can be defined. There is a default Document Class called 'Document' that serves as the base Document Class.

PE_CONNECTION_POINT
Connection Points have replaced the Routers from FileNet 3.5 and enables connection to a PE Isolated Region. The PE Isolated Region is like the CE Object Store in that it holds PE queues, rosters, and other workflow configurations. Connection Points can be managed through FEM.

Main Code

In this section, I'll break down the main test method in the sample code and explain the API calls being made. The sample code starts off by logging into the CE first.

Connection ceConnection =
   Factory.Connection.getConnection(FILENET_URI);

The CE API contains Factory.* classes to create CE objects. To establish a Connection object, call the Factory.Connection class to create one by passing in the URI. This Connection object represents a logical connection to a FileNet Domain.

Subject ceSubject =
   UserContext.createSubject(ceConnection, FILENET_USERNAME,
      FILENET_PASSWORD, null);

Next, to use JAAS, you create a Subject object. You pass in the username and password you want to use. The third parameter is for the JAAS stanza. Passing in 'null' means you want to use the default FileNet JAAS stanza, which is called 'FileNetP8'. The server authenticates the user and returns the JAAS subject.

UserContext.get().pushSubject(ceSubject);

Before running any further CE API calls, it is necessary to push a Subject object onto the UserContext stack. This sets the user pushed as the active user for subsequent CE API calls.

Domain ceDomain =
   Factory.Domain.fetchInstance(ceConnection, CE_DOMAIN, null);

Now that you have a valid Subject on the stack, you can retrieve objects from the FileNet server. In this case, you call a fetch* to retrieve a Domain from the FileNet server by passing in the Connection object you created earlier and the Domain name that you want to retrieve. The third parameter represents a PropertyFilter object; it controls what properties should be returned. For the sample, I've left this as null so that all non-object properties are returned by default.

ObjectStore ceObjectStore =
   Factory.ObjectStore.fetchInstance(ceDomain, CE_OBJECTSTORE,
                                     null);

Because the Domain is a container for CE resources, you now can retrieve your Object Store. You use the same type of call as retrieving the Domain, but instead you pass in the Domain object and the Object Store name. Once again, you pass in a 'null' for the PropertyFilter.

Once you get a valid Object Store object, you are now logged in and ready to use the rest of the CE API.

The next couple lines show how you would retrieve the properties of a Document Class.

ClassDefinition classDef =
   Factory.ClassDefinition.fetchInstance(ceObjectStore,
                                         "Document", null);

A Document Class is represented by the ClassDefinition interface. To retrieve a specific instance of a Document Class, you fetch it by passing in the Object Store object and the Document Class name you want. The "Document" document class is provided by default and serves as the base class for other document classes.

PropertyDefinitionList properties =
   classDef.get_PropertyDefinitions();

Now that you've fetched the Document Class, you can call a get* to retrieve the properties on the Document Class. It returns a PropertyDefinitionList, which is an iterable collection of PropertyDefinition objects.

for (Iterator propertyIter =
   properties.iterator(); propertyIter.hasNext();) {
      PropertyDefinition property =
         (PropertyDefinition) propertyIter.next();

   System.out.println("Property: " + property.get_DisplayName());
}

For each PropertyDefinition you can get a lot of metadata, including the display name and symbolic name. Here, you iterate the properties and output the display name to the console.

UserContext.get().popSubject();

Lastly, you pop the Subject off because you are done making CE API calls. This makes the next Subject on the stack the active user.

VWSession peSession = new VWSession();
peSession.setBootstrapCEURI(FILENET_URI);

The FileNet PE login starts by creating a VWSession object. The VWSession object is the starting point for most of the PE API calls. With the VWSession object, you can query rosters and queues, and process any items found. In this test code, you'll log in to the PE and retrieve a list of all Process Queues that are configured.

peSession.logon(FILENET_USERNAME,
                FILENET_PASSWORD,
                PE_CONNECTION_POINT);

Once you have the VWSession object, you set the CE URI onto the object so that it can perform the login and authentication. Once this method executes successfully, you will be logged into the PE.

String[] queueNames =
   peSession.fetchQueueNames(VWSession.QUEUE_PROCESS);

From here, you can call fetchQueueNames to retrieve the Queues. The static value you pass in says that you want only the Queues that will be processing Workflow items. There are also other options, such as only system queues or user queues.

for (String queue : queueNames) {
   System.out.println("Queue: " + queue);
}

The fetchQueueNames method returns an array of Strings for the name of the Queues. You simply print out the names of the Queues for verification.

Although you've covered the basic API calls to login to CE and PE and perform simple queries, this serves as the basis for more complicated API calls. The full API and developers guide are documented within the FileNet ECM Help site, whose link can be found off of Workplace.

 


import java.util.Iterator;

import javax.security.auth.Subject;

import junit.framework.TestCase;

import com.filenet.api.admin.ClassDefinition;
import com.filenet.api.admin.PropertyDefinition;
import com.filenet.api.collection.PropertyDefinitionList;
import com.filenet.api.core.Connection;
import com.filenet.api.core.Domain;
import com.filenet.api.core.Factory;
import com.filenet.api.core.ObjectStore;
import com.filenet.api.util.UserContext;

import filenet.vw.api.VWException;
import filenet.vw.api.VWSession;

public class FileNetConnectionTest extends TestCase {

   /**
   * Replace these variables with your settings
   */

   public String FILENET_USERNAME         = "";
   public String FILENET_PASSWORD        = "";
   public String FILENET_URI             = "";

   public String CE_DOMAIN             = "";
   public String CE_OBJECTSTORE            = "";
    
   public String PE_CONNECTION_POINT     = "";
    
   public void testFileNetConnection() throws VWException {
        
      /*
      * Connect to Content Engine and retrieve a list of
      * properties for the base 'Document' document class
       */

      Connection ceConnection =
         Factory.Connection.getConnection(FILENET_URI);
      
      Subject ceSubject =
         UserContext.createSubject(ceConnection, FILENET_USERNAME, FILENET_PASSWORD, null);
      
      UserContext.get().pushSubject(ceSubject);
      
      Domain ceDomain = Factory.Domain.fetchInstance(ceConnection, CE_DOMAIN, null);
      
      ObjectStore ceObjectStore = Factory.ObjectStore.fetchInstance(ceDomain, CE_OBJECTSTORE, null);
        
      ClassDefinition classDef =
         Factory.ClassDefinition.fetchInstance(ceObjectStore, "Document", null);
        
      PropertyDefinitionList properties = classDef.get_PropertyDefinitions();
      
      for (Iterator propertyIter = properties.iterator(); propertyIter.hasNext();) {
         PropertyDefinition property = (PropertyDefinition) propertyIter.next();
         
         System.out.println("Property: " + property.get_DisplayName());
      }
        
      UserContext.get().popSubject();
        
      /*
       * Connect to Process Engine and retrieve a list of
       * Queues for this Connection Point
       */

      VWSession peSession = new VWSession();
      peSession.setBootstrapCEURI(FILENET_URI);
        
      peSession.logon(FILENET_USERNAME,
                        FILENET_PASSWORD,
                        PE_CONNECTION_POINT);
            
      String[] queueNames =
         peSession.fetchQueueNames(VWSession.QUEUE_PROCESS);

      for (String queue : queueNames) {
         System.out.println("Queue: " + queue);
      }
   }    
}

阅读(1554) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:IBM---FileNet---javaAPI实现封闭报销流程(一)

给主人留下些什么吧!~~