bea.com | products | dev2dev | support | askBEA

Download Docs | Site Map | Glossary
Search

Programming BPM Client Apps

Managing the Active Organization

This section explains how to manage the active organization, including the following topics:

- What Is an Active Organization?

- Getting the Active Organization

- Getting All Organizations

- Setting the Active Organization

- Example of Managing the Active Organization

For information about managing the active organization using the WebLogic Integration Worklist, see Working with Workflows in Using the WebLogic Integration Worklist.

Note: The Worklist client application is being deprecated as of this release of WebLogic Integration. For information about the features that are replacing it, see the BEA WebLogic Integration Release Notes.

What Is an Active Organization?

Organizations are defined, using either the WebLogic Integration Studio or a custom configuration client, to represent different business entities, geographical locations, or any other class of entities that is relevant to the particular business of the company. You can also define users and roles within organizations, to further fortify the permissions that provide security.

The current active organization is the default organization for both the Worklist and/or custom run-time management client requests in which an organization is not specified. The active organization is initially set to the default organization of the user who invoked the run-time management client. The default organization is specified when the user is initially created using the definition client.

You can get and set the active organization using the methods described in the following sections.

For more information about any of the methods described in the following sections, see the BEA WebLogic Integration Javadoc. For more information about maintaining organizations within a Studio client, see "Maintaining Organizations" in Administering Data in Using the WebLogic Integration Studio.

Getting the Active Organization

To get the currently active organization, use the following com.bea.wlpi.server.worklist.Worklist method:

>     public java.lang.String getActiveOrganization(
>     ) throws java.rmi.RemoteException,
>       com.bea.wlpi.common.WorkflowException

This method returns the ID of the active organization.

For example, the following code gets the active organization ID and saves it to the activeOrgId string variable:

>     String activeOrgId = worklist.getActiveOrganization();

In this example, worklist represents the EJBObject reference to the Worklist EJB. For more information about the getActiveOrganization() method, see the com.bea.wlpi.server.worklist.Worklist Javadoc.

Getting All Organizations

In order to set the active organization, you need to know the ID of the organization that you want to set as active. To get a list of all defined organization IDs, see Getting All Organizations.

Setting the Active Organization

To set the active organization, use the following com.bea.wlpi.server.worklist.Worklist method:

>     public void setActiveOrganization(
>       java.lang.String orgId
>     ) throws java.rmi.RemoteException,
>       com.bea.wlpi.common.WorkflowException

The following table describes the setActiveOrganization() method parameter for which you must specify a value.

Table 19-1 setActiveOrganization() Method Parameter

Parameter | Description | Valid Values
--- | --- | ---
orgId | ID of the organization that you want to set as active. | String specifying a valid organization ID. For information about getting a list of all organization IDs, see Getting All Organizations.

For example, the following code sets the active organization to ORG1. In this example, worklist represents the EJBObject reference to the Worklist EJB.

>     worklist.setActiveOrganization("ORG1");

For more information about the setActiveOrganization() method, see the com.bea.wlpi.server.worklist.Worklist Javadoc.

Example of Managing the Active Organization

This section provides excerpts from the command-line worklist example showing how to manage the active organization.

Note: For more information about the command-line worklist example, see Command-Line Worklist Example.

In this example, an input stream is defined to communicate with the user, and the user is prompted to specify one of the following actions to be performed:

- Getting the Active Organization

- Getting All Organizations

- Setting the Active Organization

Important lines of code are highlighted in bold. In this example, worklist represents the EJBObject reference to the Worklist EJB.

>     /* Create an input stream to communicate with the user */
>     stdIn = new BufferedReader( new InputStreamReader( System.in ) )

>     /* Display Tool Title */
>     System.out.print( "\n---  Command Line Worklist v1.2  ---" );

>     /* Display the main menu and interact with user */
>     while( true ) {
>        /* Display the menu */
>        System.out.println( "\n---           Main Menu          ---" );
>        System.out.println( "\nEnter choice:" );
>        System.out.println( "1) Organizations" );
>        System.out.println( "2) Workflows" );
>        System.out.println( "3) Tasks" );
>        System.out.println( "Q) Quit" );
>        System.out.print( ">> " );
>           .
>           .
>           .
>     public static void mngOrganization( ) {
>        String orgId;

>        /* Create an input stream to communicate with the user */
>        BufferedReader stdIn = new BufferedReader(
>           new InputStreamReader( System.in ) );

>        try {
>           /* Display the main menu and interact with user */
>           while( true ) {
>              /* Display the menu */
>              System.out.println( "\n\n---         Organizations        ---" );
>              System.out.println( "\nEnter choice:" );
>              System.out.println( "1) List active organization" );
>              System.out.println( "2) List all organizations" );
>              System.out.println( "3) Set active organization" );
>              System.out.println( "B) Back to previous menu" );
>              System.out.println( "Q) Quit" );
>              System.out.print( ">> " );

>              /* Get the user's selection */
>              String line = stdIn.readLine( );

>              /* User pressed enter without making a selection ? */
>              if( line.equals( "" ) )
>                 continue;
>              /* User entered more than one char ? */
>              else if( line.length( ) > 1 ) {
>                 System.out.println( "*** Invalid choice" );
>                 continue;
>              }

>              /* Convert to uppercase and to char */
>              char choice = line.toUpperCase( ).charAt( 0 );

>              /* Process user's selection */
>              switch( choice ) { ...

Getting the Active Organization

The following excerpt shows how to get the name of the active organization:

>              /* List active organization */
>              case '1' :
>                 /* WLPI Public API Method */
>                 /* NOTE: Would be nice to add code to capture any
>                  * thrown exceptions */
>                 String activeOrgId = worklist.getActiveOrganization( );
>                 System.out.println( "\nActive organization is " + activeOrgId );
>                 break; ...

Getting All Organizations

The following excerpt shows how to get a list of all organizations:

>              /* List all organizations */
>              case '2' :
>                 /* WLPI Public API Method */
>                 /* NOTE: Would be nice to add code to capture any thrown exceptions */
>                 List orgList = principal.getAllOrganizations( false );

>                 /* Any organizations defined ? */
>                 if( orgList.size( ) == 0 )
>                    System.out.println( "\nNo Organization defined" );
>                 else
>                    System.out.println( "\nDefined organizations:" );

>                 /* Process the list to display organization and attributes */
>                 for( int i = 0; i < orgList.size( ); i++ ) {
>                    /* Retrieve an element from the list */
>                    OrganizationInfo orgInfo = ( OrganizationInfo )orgList.get( i );
>                    /* Retrieve and display organization id */
>                    System.out.println( "- ID: " + orgInfo.getOrgId( ) );
>                 }
>                 break; ...

Setting the Active Organization

The following excerpt shows how to set the active organization:

>              /* Set active organization */
>              case '3' :
>                 /* Get Organization ID for the organization to set as active */
>                 if( ( orgId = askQuestion( "\nEnter Organization ID" ) ) == null ) {
>                    /* User cancelled the operation */
>                    System.out.println( "*** Cancelled" );
>                    break;
>                 }

>                 try {
>                    /* WLPI Public API Method */
>                    worklist.setActiveOrganization( orgId );

>                    /* Success (No exception trown) */
>                    System.out.println( "- Success" );

>                    /* WLPI Public API Method */
>                    /* Confirm that the operation was succesful */
>                    activeOrgId = worklist.getActiveOrganization( );
>                    System.out.println(
>                       "- The active organization is now " + activeOrgId );
>                 }
>                 catch( Exception e ) {
>                   System.out.println(
>                       "*** Failed to set the Active Organization (ID: " +
>                       orgId + ")" );
>                    System.err.println( e );
>                 }
>                 break;
>                    .
>                    .
>                    .