Oracle® Fusion Middleware Oracle Enterprise Repository統合ガイド 11g リリース1 (11.1.1.7) B72433-02 |
|
前 |
次 |
この章では、サブスクリプションAPIのユースケースについて説明します。このユースケースで、Oracle Enterprise Repositoryにおいてアセットに対するサブスクリプションの作成、読込みまたは削除を行う方法、およびアセットに対してサブスクライブされたユーザーを読み込む方法について解説します。
この章では、次の項目について説明します。
サブスクリプションAPIでは、サブスクライブされているアセットをユーザーが管理するメカニズムを提供します。この場合、サブスクリプションは、具体的には電子メール・サブスクリプションを示します。このAPIを介して作成されるサブスクリプションは、アセットの詳細ページで「サブスクライブ」ボタンをクリックするユーザーに相当します。ユーザーがアセットに対してサブスクライブした後、アセットに発生しているイベントについて電子メールで通知されます。サブスクライブ済のユーザーが通知されるイベントのリストは、『Oracle Fusion Middleware Oracle Enterprise Repositoryユーザーズ・ガイド』を参照してください。
REXのサブスクリプションAPIを使用すると、開発者はアセットのリストに対するサブスクリプションを作成、削除および検査できます。この操作は、常に、様々なサブスクリプション・メソッドに引数として渡された認証トークンで識別されたユーザーに対して実行されます。
この項では、サブスクリプションAPIを使用するユースケースについて説明します。含まれる内容は、次のとおりです。
説明
REXで認証します。
問合せを介してアセットのサマリーのリストを読み込みます。
一致したアセットに対してサブスクライブします。
サンプル・コード
例29-1 ユースケース: アセットに対するサブスクリプションの作成
package com.flashline.sample.subscriptionapi; import java.net.MalformedURLException; import java.net.URL; import java.rmi.RemoteException; import javax.xml.rpc.ServiceException; import com.flashline.registry.openapi.base.OpenAPIException; import com.flashline.registry.openapi.entity.AssetSummary; import com.flashline.registry.openapi.entity.AuthToken; import com.flashline.registry.openapi.query.AssetCriteria; import com.flashline.registry.openapi.service.v300.FlashlineRegistry; import com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator; public class CreateSubscription { public static void main(String pArgs[]) throws OpenAPIException, RemoteException, ServiceException { try { // ///////////////////////////////////////////////////////// // Connect to Oracle Enterprise Repository // ///////////////////////////////////////////////////////// URL lURL = null; lURL = new URL(pArgs[0]); FlashlineRegistry repository = new FlashlineRegistryServiceLocator() .getFlashlineRegistry(lURL); // ///////////////////////////////////////////////////////// // Login to OER // ///////////////////////////////////////////////////////// AuthToken authToken = repository.authTokenCreate(pArgs[1], pArgs[2]); // ///////////////////////////////////////////////////////// // find the assets to which to subscribe // ///////////////////////////////////////////////////////// AssetCriteria criteria = new AssetCriteria(); criteria.setNameCriteria("%"); AssetSummary[] lAssetSummaries = repository.assetQuerySummary(authToken, criteria); // ///////////////////////////////////////////////////////// // Iterate through assets, pulling out the ids and adding // to the array of longs // ///////////////////////////////////////////////////////// long[] lAssetIDs = new long[lAssetSummaries.length]; for (int i = 0; i < lAssetSummaries.length; i++) { lAssetIDs[i] = lAssetSummaries[i].getID(); } // ///////////////////////////////////////////////////////// // Create the subscriptions. The value of "false" for the // parameter pFailOnAnyError, causes the operation to NOT // fail for any asset to which the user does not have VIEW // privileges, or for which the asset is not subscribable. // // If this value is not "false", the operation throws // an exception if any asset in the array of asset IDs is // not subscribable or viewable by the user, and NONE of the // subscriptions are recorded in the repository. // ///////////////////////////////////////////////////////// repository.subscriptionCreate(authToken, lAssetIDs, false); } catch (OpenAPIException lEx) { System.out.println("ServerCode = " + lEx.getServerErrorCode()); System.out.println("Message = " + lEx.getMessage()); System.out.println("StackTrace:"); lEx.printStackTrace(); } catch (RemoteException lEx) { lEx.printStackTrace(); } catch (ServiceException lEx) { lEx.printStackTrace(); } catch (MalformedURLException lEx) { lEx.printStackTrace(); } } }
説明
REXで認証します。
問合せを介してアセットのサマリーのリストを読み込みます。
一致したアセットに対して存在するサブスクリプションを削除します。
サンプル・コード
例29-2 ユースケース: アセットに対するサブスクリプションの削除
package com.flashline.sample.subscriptionapi; import java.net.MalformedURLException; import java.net.URL; import java.rmi.RemoteException; import javax.xml.rpc.ServiceException; import com.flashline.registry.openapi.base.OpenAPIException; import com.flashline.registry.openapi.entity.AssetSummary; import com.flashline.registry.openapi.entity.AuthToken; import com.flashline.registry.openapi.query.AssetCriteria; import com.flashline.registry.openapi.service.v300.FlashlineRegistry; import com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator; public class DeleteSubscription { public static void main(String pArgs[]) throws OpenAPIException, RemoteException, ServiceException { try { /////////////////////////////////////////////////////////// // Connect to Oracle Enterprise Repository /////////////////////////////////////////////////////////// URL lURL = null; lURL = new URL(pArgs[0]); FlashlineRegistry repository = new FlashlineRegistryServiceLocator() .getFlashlineRegistry(lURL); /////////////////////////////////////////////////////////// // Login to OER /////////////////////////////////////////////////////////// AuthToken authToken = repository.authTokenCreate( pArgs[1],pArgs[2]); /////////////////////////////////////////////////////////// // find the assets for which to delete subscriptions /////////////////////////////////////////////////////////// AssetCriteria criteria = new AssetCriteria(); criteria.setNameCriteria("%"); AssetSummary[] lAssetSummaries = repository.assetQuerySummary(authToken, criteria); /////////////////////////////////////////////////////////// // Iterate through assets, pulling out the ids and adding // to the array of longs /////////////////////////////////////////////////////////// long[] lAssetIDs = new long[lAssetSummaries.length]; for (int i = 0; i < lAssetSummaries.length; i++) { lAssetIDs[i] = lAssetSummaries[i].getID(); } /////////////////////////////////////////////////////////// // Delete the subscriptions on the list of assets. /////////////////////////////////////////////////////////// repository.subscriptionDelete(authToken, lAssetIDs); } catch (OpenAPIException lEx) { System.out.println("ServerCode = " + lEx.getServerErrorCode()); System.out.println("Message = " + lEx.getMessage()); System.out.println("StackTrace:"); lEx.printStackTrace(); } catch (RemoteException lEx) { lEx.printStackTrace(); } catch (ServiceException lEx) { lEx.printStackTrace(); } catch (MalformedURLException lEx) { lEx.printStackTrace(); } } }
説明
REXで認証します。
認証済のユーザーに対してサブスクライブされたアセットのリストを読み込みます。
サンプル・コード
例29-3 ユースケース: アセットに対するサブスクリプションの読込み
package com.flashline.sample.subscriptionapi; import java.net.MalformedURLException; import java.net.URL; import java.rmi.RemoteException; import javax.xml.rpc.ServiceException; import com.flashline.registry.openapi.base.OpenAPIException; import com.flashline.registry.openapi.entity.Asset; import com.flashline.registry.openapi.entity.AuthToken; import com.flashline.registry.openapi.service.v300.FlashlineRegistry; import com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator; public class ReadSubscriptions { public static void main(String pArgs[]) throws OpenAPIException, RemoteException, ServiceException { try { /////////////////////////////////////////////////////////// // Connect to Oracle Enterprise Repository /////////////////////////////////////////////////////////// URL lURL = null; lURL = new URL(pArgs[0]); FlashlineRegistry repository = new FlashlineRegistryServiceLocator() .getFlashlineRegistry(lURL); /////////////////////////////////////////////////////////// // Login to OER /////////////////////////////////////////////////////////// AuthToken authToken = repository.authTokenCreate( pArgs[1],pArgs[2]); ////////////////////////////////////////////////////////// // Read all of the assets to which the user is subscribed. ////////////////////////////////////////////////////////// long[] lSubscribedAssets = repository.subscriptionReadSubscribedAssets(authToken); ////////////////////////////////////////////////////////// // Print out the assets to which the user is subscribed ////////////////////////////////////////////////////////// Asset[] lAssets = repository.assetReadArray(authToken, lSubscribedAssets); System.out.println("Subscribed Assets for user "+pArgs[1]); for(int i=0; i<lAssets.length; i++){ System.out.println(" -> "+lAssets[i].getLongName()); } } catch (OpenAPIException lEx) { System.out.println("ServerCode = " + lEx.getServerErrorCode()); System.out.println("Message = " + lEx.getMessage()); System.out.println("StackTrace:"); lEx.printStackTrace(); } catch (RemoteException lEx) { lEx.printStackTrace(); } catch (ServiceException lEx) { lEx.printStackTrace(); } catch (MalformedURLException lEx) { lEx.printStackTrace(); } } }
説明
REXで認証します。
特定のユーザーに対してサブスクライブされたアセットのリストを読み込みます。
サンプル・コード
例29-4 ユースケース: アセットに対してサブスクライブされたユーザーの読込み
package com.flashline.sample.subscriptionapi; import java.net.MalformedURLException; import java.net.URL; import java.rmi.RemoteException; import javax.xml.rpc.ServiceException; import com.flashline.registry.openapi.base.OpenAPIException; import com.flashline.registry.openapi.entity.AssetSummary; import com.flashline.registry.openapi.entity.AuthToken; import com.flashline.registry.openapi.entity.RegistryUser; import com.flashline.registry.openapi.query.AssetCriteria; import com.flashline.registry.openapi.service.v300.FlashlineRegistry; import com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator; public class ReadSubscribersToAsset { public static void main(String pArgs[]) throws OpenAPIException, RemoteException, ServiceException { try { /////////////////////////////////////////////////////////// // Connect to Oracle Enterprise Repository /////////////////////////////////////////////////////////// URL lURL = null; lURL = new URL(pArgs[0]); FlashlineRegistry repository = new FlashlineRegistryServiceLocator() .getFlashlineRegistry(lURL); /////////////////////////////////////////////////////////// // Login to OER /////////////////////////////////////////////////////////// AuthToken authToken = repository.authTokenCreate( pArgs[1],pArgs[2]); ////////////////////////////////////////////////////////// // Assume that this query returns some number of assets... ////////////////////////////////////////////////////////// AssetCriteria lCriteria = new AssetCriteria(); lCriteria.setNameCriteria("%"); AssetSummary[] lAssetSummaries = repository.assetQuerySummary(authToken, lCriteria); ////////////////////////////////////////////////////////// // Read the users that are subscribed to the first asset ////////////////////////////////////////////////////////// RegistryUser[] lSubscribedUsers = repository.subscriptionReadUsersSubscribedToAsset(authToken, lAssetSummaries[0].getID()); for (int i=0; i<lSubscribedUsers.length; i++){ System.out.println("Subscribed Users: "+lSubscribedUsers[i].getUserName()); } } catch (OpenAPIException lEx) { System.out.println("ServerCode = " + lEx.getServerErrorCode()); System.out.println("Message = " + lEx.getMessage()); System.out.println("StackTrace:"); lEx.printStackTrace(); } catch (RemoteException lEx) { lEx.printStackTrace(); } catch (ServiceException lEx) { lEx.printStackTrace(); } catch (MalformedURLException lEx) { lEx.printStackTrace(); } } }