5 ユーザー通信プリファレンスJava APIの使用方法

この章では、UCP Java APIを使用して、アプリケーションでユーザー通信プリファレンス(UCP)サービスを消費する方法について説明します。

UCPサービス用のAPIとインタフェースの詳細は、ユーザー・メッセージング・サービスJava APIリファレンスを参照してください。

UCP Java APIの概要

ユーザー通信プリファレンス(UCP)サービスはアプリケーションから直接または間接的に消費できます。UCPサービスを間接的に消費するには、ユーザー宛てのメッセージを送信して、UMS APIをコールする必要があります。UMSはUCPサービスを使用して、ユーザーのメッセージ配信プリファレンスに基づいて、最適なチャネルを検出します。

詳細は、『Oracle® Fusion Middleware Oracle User Messaging Serviceによるアプリケーションの開発』を参照してください。UMS APIを使用する場合、デフォルトで、アプリケーションはデフォルトUCPプロファイルをターゲット指定しています。特定のプロファイルをターゲット指定するには、ユーザーにメッセージを送信する際に、oracle.sdp.messaging MessageInfo.setProfileId(String profileId)を使用してプロファイルを設定する必要があります。

UCPサービスを直接消費する場合、UCP Java APIをコールする必要があります。たとえば、ユーザーが好むチャネルの配信タイプに応じてメッセージ形式を制御する場合、UCPサービスを直接消費することが必要になります。また、たとえば、特定のイベントでアプリケーションのユーザーにメッセージを送信する新しいアプリケーションを構築する場合、まずアプリケーションのデプロイメント時に各ユーザーがメッセージを受信できるように、UCP APIを使用してプログラムにより各ユーザーのデフォルト電子メール・チャネルを作成できます。ユーザーがデフォルト・チャネルとして電子メールを希望しない場合、後で自分でプリファレンスを変更できます。

UCP Java APIは、アプリーションを実装してUCPサービスを消費するためのプログラム・インタフェースを提供します。また、UCPは、チャネルとフィルタを管理するためのJava APIも提供します。Javaインタフェースoracle.ucs.userprefs.UserCommunicationPreferenceは、クライアントがUCPサービスにアクセスするためのプライマリ・インタフェースです。oracle.ucs.userprefsパッケージには、ユーザー通信プリファレンスのAPIクラスが含まれています。詳細は、ユーザー・メッセージング・サービスJava APIリファレンスを参照してください。これは、アドレス、フィルタセットなどのユーザーのプリファレンス・オブジェクトを管理するためのルート・インタフェースです。UCPサービスのAPIとインタフェースの詳細は、ユーザー・メッセージング・サービスJava APIリファレンスを参照してください。

配信プリファレンスの取得

ユーザーの配信プリファレンスは、JavaメソッドgetDeliveryPreference(String guid, String profileID, Map>String,Object> facts)を呼び出すことにより取得できます。guidは大文字と小文字が区別されます。

12cで導入されたprofileIDパラメータは、特定プロファイルのユーザー・プリファレンスをターゲット設定するのに使用されます。各アプリケーションが特定のプロファイルをターゲットとすることをお薦めします。getDefaultProfileIdメソッドをコールしてアプリケーションにより取得できるデフォルトのプロファイルIDがあります。11g APIを呼び出す(プロファイルIDを使用しない)アプリケーションでは、デフォルト・プロファイルが自動的に使用されます。最終的に、このAPIをコールするアプリケーションは、ターゲット・プロファイルで一致するフィルタをUCPが選択できるように必要なファクトをすべて提供する必要があります。ファクトは、名前/値ペアのMap<String,Object>とします。ここで名前はビジネス条件とマップ内のキーです。このAPIの使用の詳細は、ユーザー・メッセージング・サービスJava APIリファレンスを参照してください。

次のコードの抜粋は、testUser1の配信プリファレンスを取得する方法を示しています。

// Obtain a UserCommunicationPreference object
UserCommunicationPreference ucp = UserPrefsServicesFactory.createUserCommunicationPreference();
 
// Set target user ID
String userId = “testUser1";
 
// Specify the Profile ID, or default id from ucp.getDefaultProfileId()
String profileId = “soa";
 
// Add all facts into Hashtable facts. Facts for Date and Time are not needed.
Map <String, String> facts = new HashMap<String, Object>();
facts.put(“Application", “BPEL"); 			// Add application name
facts.put(“Due Date", new Date()); 			// Use current date
facts.put(“Amount", new Double(“678.00")); 		// Set number for 678
 
 
// Invoke getDeliveryPreference() function with userId, profileId and and facts.
DeliveryPreference dp = ucp.getDeliveryPreference(userId, profileId, facts);
 
// Retrieve Action Type and delivery Channels from the returned DeliveryPreference object.
ActionType at = dp.getActionType();		//Get Action Type
Vector <DeviceAddress>  channels = dp.getDevices();	//Get delivery Channels

チャネルの管理

UCPには、UCPリポジトリをアイデンティティ・ストア(通常はLDAP)と同期する自動チャネル管理機能があります。

電子メール・アドレスがアイデンティティ・ストアに追加されると、その電子メール・アドレスに対応するEMAILチャネルがUCPリポジトリに自動的に作成されます。このチャネルは、対応する電子メール・アドレスがアイデンティティ・ストアから削除されると、リポジトリから削除されます。UCPは、電子メール、IM、勤務先電話、自宅電話および携帯電話のチャネルを自動的に作成します。これらのチャネルはIDMチャネルと呼ばれます。

これらのチャネルは自動的にUCPにより管理されるので、アプリケーション側でチャネルの作成または削除は行わないでください。アプリケーション側では、これらのチャネルをデフォルト・チャネルとして設定または設定解除することのみ可能です。ただし、アプリケーションは、createDeviceAddressgetDeviceAddressesなどのAPIを使用してUSERチャネルを作成、変更または削除できます。1つのチャネルを、setDefaultChannel APIを使用してデフォルト・チャネルとして設定できます。

次のコードの抜粋は、特定の電子メール・アドレスを持つユーザーtestUser1の通信チャネルを作成する方法を示しています。

// Create an email channel for testUser1
DeviceAddress channel = ucp.createDeviceAddress(“testUser1",		// User ID
					“myEmail",			// Channel name
					DeliveryType.EMAIL,		// Delivery Type for email
					“myemail@somecompany.com");	// Email address
ucp.save(channel);	// without this line, the Channel will not be persisted in UCP repository

チャネル名は各ユーザーで一意である必要があります。配信タイプと配信アドレスの組合せも、各ユーザーで一意である必要があります。次に、チャネルを管理する方法を示すサンプル・コードの抜粋をいくつか示します。

// Set the Channel as a default Channel
ucp.setDefaultAddress(“testUser1",		// User ID
			  “soa",			// Profile ID
			  channel);			// Channel to be flagged
 
// Unset a default Channel
ucp.removeDefaultAddress(“testUser1", 		// User ID
			         “soa",			// Profile ID
			         channel);		// Channel to be unset
 
// Modify the Channel's address
channel.setAddress(newemail@somecompany.com);
ucp.save(channel); 	// without this line, the change will not be persisted in UCP repository
 
// Remove the Channel
ucp.delete(channel);

フィルタの管理

フィルタは、プロファイルごとのセットで管理されます。

次のコードの抜粋は、ユーザーtestUser1soaプロファイルに対してメッセージング・フィルタを作成する方法を示しています。

// Get, or create if not exist, user's Filter Set for Profile “soa"
FilterSet  filterSet = ucp.getFilterSet(“testUser1"	// User ID
				    “soa");		// Profile ID
 
// Create a new Filter
Filter  filter = filterSet.createFilter(“Test Email Filter");	// Create a new Filter named “Test Email Filter"
filter.setConditionType(ConditionType.MATCH_ANY).	// Set the Condition Type to logical OR
 
// Create a new Condition
Condition  condition = filter.createCondition();		// Create a new Condition first
Map<String, BusinessRuleTerm> terms = ucp.getBusinessterms();
BusinessRuleTerm term = terms.get(“Subject");	// Business Term for “Subject"
condition.setFilterTerm(term);
condition.setTermOperation(TermOperationType.Contains);
condition.setOperandOne(“approved");		// Set value “approved"
ArrayList<Condition> conditions = new ArrayList<Condition>();
conditions.add(condition);
filter.setConditions(conditions);			// Add the Condition list to the Filter
 
// Set Action Type
filter.setActionType(ActionType.SERIAL);		// Set Action Type for SERIAL
 
// Get all the Channels for “soa" Profile
Set<DeviceAddress> allAddresses = ucp.getDeviceAddresses(“testUser1",	// User ID
						      “soa");		// Profile ID
ArrayList<DeviceAddress> channels = new ArrayList(allAddresses);	// Convert to a List
filter.setDeviceAddressList(channels);			// Add to the Filter as target Channels
 
// Add the Filter to the Filter Set
filterSet.addFilter(filter);
 
// Finally persist the FilterSet object
ucp.save(filterSet); 				// Required to persist the Filter

アプリケーションをデプロイするには、アプリケーションの開発ディスクリプタから共有ライブラリoracle.sdp.clientを参照する必要があります。アプリケーションは、UCPサービスと同じドメインにデプロイする必要があります。

UCPにはアプリケーションがチャネルとフィルタを管理するためのJava APIが用意されていますが、ユーザーが、UCPタスク・フロー・ライブラリを使用してWebアプリケーションに統合されたUCP Webインタフェースから、自分のプリファレンスを管理することをお薦めします。