TopicSubscriptionUtilOOB: スコープ指定
TopicSubscriptionUtilOOB スクリプトインクルードは、トピックサブスクリプション [sn_api_notif_mgmt_topic_subscription] テーブルのレコードを照会および操作するためのメソッドを提供します。このクラスはサービス レイヤーで動作し、データ アクセス オブジェクト (DAO) クラスと対話します。
これらの関数は、[トピックのサブスクリプション] フォームで [登録 ] ボタンが選択されたときに呼び出されます。このスクリプトインクルードのデフォルト機能を変更する場合は、このスクリプトインクルードに含まれる関数を TopicSubscriptionUtil スクリプトインクルードで上書きする必要があります。
どちらのスクリプトインクルードも sn_api_notif_mgmt 名前空間で実行されます。
トピックのサブスクリプションの詳細については、「 Handling the external events using Telecommunications API notification」を参照してください。
TopicSubscriptionUtilOOB:executeRegistrationSubflow(文字列 topicSubID)
スポークサブフローをトリガーして、渡されたトピックサブスクリプションを外部システムに登録します。
登録フローをトリガーする前に、この関数は、渡されたトピックサブスクリプションレコードにコールバック URL が含まれているかどうか、およびトピックが既に登録されているかどうかを確認します。これらのチェックに合格すると、デモサブフローがトリガーされます。このデモサブフローは、スポークセレクターでアダプターとして定義され、「モック」送信登録呼び出しを実行します。
この関数は、ユーザーが [トピックのサブスクリプション] フォームで [ 登録 ] ボタンを選択すると呼び出されます。デモサブフローの名前は、 Constants.INITIATE_REGISTRATION_PROCESS = "sn_ind_tmf642.initiate_registration_process";
トピックサブスクリプションを登録する独自のカスタムサブフローを定義するには、 TopicSubscriptionUtil スクリプトインクルードでこの関数を上書きする必要があります。
この登録サブフロー内で、外部システムの登録エンドポイントを呼び出してトピックを登録する REST ステップ、接続エイリアス、またはその他の実装を作成する必要があります。このエンドポイントは、登録するトピック名とコールバック URL を渡す必要があります。その代わり、外部システムエンドポイントは、サブスクリプション ID、登録が成功したかどうか、およびトピックサブスクリプションテーブルに格納する登録情報を返す必要があります。この情報には通常、登録ステータス、登録メッセージ、およびサブスクリプション ID フィールドが含まれます。登録サブフローは、 updateRegistrationResponse() メソッドを呼び出して、応答ペイロードをトピックサブスクリプションテーブルに保存する必要があります。
| 名前 | タイプ | 説明 |
|---|---|---|
| topicSubID | 文字列 | 登録するトピックサブスクリプションレコードのSys_id。 |
| タイプ | 説明 |
|---|---|
| なし |
次のコード例は、この関数をオーバーライドする方法を示しています。
var TopicSubscriptionUtil= Class.create();
TopicSubscriptionUtil.prototype =
Object.extendsObject(TopicSubscriptionUtilOOB, {
// Define overriding functions here. Pass the topicSubID of the record to be registered for subscription
executeRegistrationSubflow: function(topicSubID){
var topicSubGr = new TopicSubscriptionUtil(topicSubID).topicSubscriptionDAO.getGlideRecord();
// Customer extensible function to call their defined subflows. Here one can call their own subflow that
// will perform registration by giving an endpoint of the external env and parsing and updating the topic Sub
// record with Registered information.
var registrationFlow = ''; // Pass the subflow name that you want to override here.
var inputs = {};
inputs['topic_subscription_rec'] = topicSubGr;
try {
var flowOp = sn_fd.FlowAPI.getRunner().subflow(registrationFlow).inBackground().withInputs(inputs).run();
} catch (ex) {
gs.addErrorMessage(gs.getMessage(ex + ' Please check the subflow and inputs defined.'));
}
}
type: TopicSubscriptionUtil
});
TopicSubscriptionUtilOOB:getSubFlowName()
トピックサブスクリプションを登録するスポークセレクターサブフロートリガーに使用するサブフローを返します。
通常、この関数は executeRegistrationSubflow() 関数から呼び出されます。このサブフローは、外部システムへの接続とトピックサブスクリプションの登録を行います。使用するサブフローの名前は Constants.INITIATE_REGISTRATION_PROCESSで定義されます。
この機能を変更して、sn_api_notif_mgmtで実行するサブフローの名前を上書きすることで、独自のサブフローの名前を含めることができます 。定数 スクリプトインクルード。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 使用するサブフローの名前。デモ実装では、このサブフローは Constants.INITIATE_REGISTRATION_PROCESS = "sn_ind_tmf642.initiate_registration_process"; として定義されます。 |
次のコード例は、この関数をオーバーライドする方法を示しています。
var TopicSubscriptionUtil= Class.create();
TopicSubscriptionUtil.prototype =
Object.extendsObject(TopicSubscriptionUtilOOB, {
// Define overriding functions here. Define a constants and return.
// That is your subflow that has the registration process. In current OOB implementation
// it’s a spoke selector implementation.
getSubFlowName: function(){
var subflowName = '' // Pass your subflow name here
return subflowName;
}
type: TopicSubscriptionUtil
});
TopicSubscriptionUtilOOB:getTopicName(topicSubRefID)
トピックサブスクリプション [sn_api_notif_mgmt_topic_subscription] テーブル内のレコードの渡されたsys_idに関連付けられたトピックの名前を返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| topicSubRefID | 文字列 | トピック名を返すトピックサブスクリプションレコードのSys_id。 テーブル:トピックサブスクリプション [sn_api_notif_mgmt_topic_subscription] |
| タイプ | 説明 |
|---|---|
| 文字列 | トピック名。 |
次のコード例は、この関数をオーバーライドする方法を示しています。
var TopicSubscriptionUtil = Class.create();
TopicSubscriptionUtil.prototype =
Object.extendsObject(TopicSubscriptionUtilOOB, {
// Define overriding functions here. Pass topicSubId or topicId and get topicname from there.
getTopicName: function(topicSubRefID){
var topicSubGr = new TopicSubscriptionUtil(topicSubRefID).topicSubscriptionDAO.getGlideRecord();
var topicRefID = topicSubGr.getValue('topic');
var topicGr = new TopicUtil(topicRefID).topicDAO.getGlideRecord();
return topicGr.getValue('topic_name');
}
type: TopicSubscriptionUtil
});
TopicSubscriptionUtilOOB:getUnregisteredTopicIds()
未登録のトピックのsys_idsを返します。未登録のトピックは、トピック [sn_api_notif_mgmt_topic] テーブルにはあるが、トピックサブスクリプション [sn_api_notif_mgmt_topic_subscription] テーブルにはないトピックです。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| アレイ | まだ登録されていないトピックレコードのsys_idsのリスト。 |
次のコード例は、この関数の更新を示しています。
var TopicSubscriptionUtil= Class.create();
TopicSubscriptionUtil.prototype =
Object.extendsObject(TopicSubscriptionUtilOOB, {
// Define overriding functions here. This method is returning all topic IDs
// that are not in the Topic Subscription table. Modify queries here to
// return other topics in Topic Subscription table to return either 'Error' or
// 'UnRegistered' status topics.
getUnregisteredTopicIds: function(){
var topicIds = [];
var topicSubscriptionGr = TopicSubscriptionDAO.getInSubscriptionTopic();
if (!gs.nil(topicSubscriptionGr)) {
while (topicSubscriptionGr.next()) {
topicIds.push(topicSubscriptionGr.getValue('topic'));
}
}
var unregisteredTopicGr = TopicDAO.getUnregisteredTopic(topicIds);
if (!gs.nil(unregisteredTopicGr)) {
var unregisterTopicIds = [];
while (unregisteredTopicGr.next()) {
unregisterTopicIds.push(unregisteredTopicGr.getValue('sys_id'));
}
}
return unregisterTopicIds;
}
type: TopicSubscriptionUtil
});
TopicSubscriptionUtilOOB:updateRegistrationResponse(オブジェクト registrationDetails)
トピックサブスクリプション [sn_api_notif_mgmt_topic_subscription] テーブルのトピックサブスクリプションレコードを送信トピック登録エンドポイント呼び出しのモック登録応答の値で更新します。
TopicSubscriptionUtil スクリプトインクルードでこの関数を上書きして、関連するトピックサブスクリプションレコードに保存されている情報を変更できます。登録の詳細を返すサブフローの実行の詳細については、 executeRegistrationSubflow() を参照してください。
| 名前 | タイプ | 説明 |
|---|---|---|
| 登録の詳細 | オブジェクト | デモ実装の場合、これはデモ登録 API 呼び出しによって返されるモック応答です。 この関数を上書きする場合、応答ペイロードには少なくとも次のトピックサブスクリプションフィールドが含まれている必要があります。
|
| タイプ | 説明 |
|---|---|
| エラー | コールが成功しても、何も返されません。エラーが発生した場合は、以下が返されます。
|
次のコード例は、この関数を更新する方法を示しています。
var TopicSubscriptionUtil= Class.create();
TopicSubscriptionUtil.prototype =
Object.extendsObject(TopicSubscriptionUtilOOB, {
// Define overriding functions here. Modify this method to parse the registration details
// output from a spoke selector flow. You can pass different parameters from the registration response
// and map them to the fields in the Topic Subscription table.
updateRegistrationResponse: function(registrationDetails){
var reqTypeId = Constants.TOPIC_SUB_REQUEST_TYPE;
var outputMap = new sn_appss.IntegrationRequestConfigAPI().outputJSONToMap(reqTypeId, registrationDetails.result);
var updateTopicSubObj = new sn_tmt_core.BaseObject();
if (Constants.REGISTRATION_RESPONSE_SUCCESS_CODES.indexOf(responseCode) != -1) {
updateTopicSubObj.setValue('registration_status', Constants.REGISTRATION_STATUS.REGISTERED);
updateTopicSubObj.setValue('registration_message', outputMap.response_body.message);
updateTopicSubObj.setValue('subscription_id', outputMap.response_body.result.id);
}
}
type: TopicSubscriptionUtil
});
TopicSubscriptionUtilOOB:updateTopicSubscriptionRec(オブジェクト topicSubObj)
DAO 挿入を使用して、現在のトピックサブスクリプションレコードをトピックサブスクリプション [sn_api_notif_mgmt_topic_subscription] テーブルに保存します。
通常、この関数は updateRegistrationResponse() 関数内で呼び出します。
| 名前 | タイプ | 説明 |
|---|---|---|
| topicSubObj | オブジェクト | 関連するトピックサブスクリプションレコードで更新するフィールド。これは登録サブフローによって返されるペイロードです。 例: 詳細については、 executeRegistrationSubflow() を参照してください。 |
| タイプ | 説明 |
|---|---|
| 文字列 | 更新されたトピックサブスクリプションレコードのSys_id。 |
次のコード例は、この関数を更新する方法を示しています。
var TopicSubscriptionUtil= Class.create();
TopicSubscriptionUtil.prototype =
Object.extendsObject(TopicSubscriptionUtilOOB, {
// Define overriding functions here. Pass a topic subscription record object that contains
// the values to update in a record.
updateTopicSubRec: function(topicSubObj){
return this.topicSubscriptionDAO.updateTopicSubscription(topicSubObj);
}
type: TopicSubscriptionUtil
});
次のコード例は、この関数を呼び出す方法を示しています。
if (!gs.nil(outputMap) && outputMap.status_code == '1') {
var responseCode = outputMap.response_body.code;
var topicSubID = registrationDetails.topicSubID;
var topicSubGr = new TopicSubscriptionUtil(topicSubID).topicSubscriptionDAO.getGlideRecord();
var updateTopicSubObj = new sn_tmt_core.BaseObject();
if (Constants.REGISTRATION_RESPONSE_SUCCESS_CODES.indexOf(responseCode) != -1) {
updateTopicSubObj.setValue('registration_status', Constants.REGISTRATION_STATUS.REGISTERED);
updateTopicSubObj.setValue('registration_message', outputMap.response_body.message);
updateTopicSubObj.setValue('subscription_id', outputMap.response_body.result.id);
} else {
updateTopicSubObj.setValue('registration_status', Constants.REGISTRATION_STATUS.ERROR);
updateTopicSubObj.setValue('registration_message', outputMap.response_body.message);
}
new TopicSubscriptionUtil(topicSubGr).updateTopicSubscriptionRec(updateTopicSubObj);
return '';
} else if (!gs.nil(outputMap) && outputMap.status_code == '0') {
return outputMap.status_reason;
} else {
var errorMsg = 'Spoke Request Type output not set, please check request adapter flow';
return errorMsg;
}