TopicSubscriptionUtilOOB :スコープ指定

  • リリースバージョン: Xanadu
  • 更新日 2024年08月01日
  • 所要時間:17分
  • 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() メソッドを呼び出して、応答ペイロードをトピックサブスクリプションテーブルに保存する必要があります。

    表 : 1. パラメーター
    名前 タイプ 説明
    topicSubID 文字列 登録するトピックサブスクリプションレコードのSys_id。
    表 : 2. 返される内容
    タイプ 説明
    なし

    次のコード例は、この関数をオーバーライドする方法を示しています。

    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で実行するサブフローの名前を上書きすることで、この機能を変更して独自のサブフローの名前を含めることができます 。定数スクリプト インクルード。

    表 : 3. パラメーター
    名前 タイプ 説明
    なし
    表 : 4. 返される内容
    タイプ 説明
    文字列 使用するサブフローの名前。デモの実装では、このサブフローは 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に関連付けられたトピックの名前を返します。

    表 : 5. パラメーター
    名前 タイプ 説明
    topicSubRefID 文字列 トピック名を返すトピックサブスクリプションレコードのSys_id。トピックサブスクリプション [sn_api_notif_mgmt_topic_subscription] テーブルにあります。
    表 : 6. 返される内容
    タイプ 説明
    文字列 トピック名。

    次のコード例は、この関数をオーバーライドする方法を示しています。

    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] テーブルにはないトピックです。

    表 : 7. パラメーター
    名前 タイプ 説明
    なし
    表 : 8. 返される内容
    タイプ 説明
    アレイ まだ登録されていないトピックレコードの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()」を参照してください。

    表 : 9. パラメーター
    名前 タイプ 説明
    registration詳細 オブジェクト デモ実装の場合、これはデモ登録 API 呼び出しによって返されるモック応答です。

    この関数を上書きする場合、応答ペイロードには少なくとも次のトピックサブスクリプションフィールドが含まれている必要があります。

    • registration_status
    • registration_message
    • subscription_id
    表 : 10. 返される内容
    タイプ 説明
    エラー 呼び出しが成功した場合、何も返されません。エラーが発生した場合は、以下が返されます。
    • status_reason: status_code = 0 の場合に失敗の理由を明確にするスポーク呼び出しから返されます。
    • errormessage:「 スポーク要求タイプの出力が設定されていません。要求アダプタフローを確認してください」など、status_code が 0 または 1 でない場合のエラーを説明するエラーメッセージ。

    次のコード例は、この関数を更新する方法を示しています。

    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() 関数内で呼び出します。

    表 : 11. パラメーター
    名前 タイプ 説明
    topicSubObj オブジェクト 関連するトピックサブスクリプションレコードで更新するフィールド。これは、登録サブフローによって返されるペイロードです。

    例:

    "topicSubObj": {
      "registration_message": "String",
      "registration_status": "String",
      "subscription_id": "String"
    }

    詳細については、「 executeRegistrationSubflow()」を参照してください。

    表 : 12. 返される内容
    タイプ 説明
    文字列 更新されたトピックサブスクリプションレコードの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;
    }