ExternalCallout API の例

この例では、クレジット・スコアを取得する外部コールアウトを作成します。

クレジット・スコアを取得する外部コールアウトの作成:

  1. 以下の内容を含む GetCreditScore.java というファイルを作成します。このファイルでは、モデリング・アプリケーションからスコアを取り出す ScoreQueryUtility というクラスがあることを前提とします。

    import java.util.Map;
    import com.unicacorp.interact.session.AudienceId;
    import com.unicacorp.interact.flowchart.macrolang.storedobjs.IAffiniumExternalCallout;
    import com.unicacorp.interact.flowchart.macrolang.storedobjs.CalloutException;
    import java.util.Random;
    
    public class GetCreditScore implements IAffiniumExternalCallout
    {
     // the class that has the logic to query an external system for a customer's credit score
     private static ScoreQueryUtility scoreQueryUtility;
     public void initialize(Map<String, String> configurationData) throws CalloutException
     {
      // configurationData has the key- value pairs specific to the environment the server is running in
      // initialize scoreQueryUtility here
     }
    
    	public void shutdown(Map<String, String> configurationData) throws CalloutException
    	{
     // shutdown scoreQueryUtility here
     }
    
    	public int getNumberOfArguments()
    	{
      // do not expect any additional arguments other than the customer's id
      return 0;
     }
    
    	public List<String> getValue(AudienceId audienceId, Map<String, String> configurationData, 
    		Object... arguments) throws CalloutException
    	{
      Long customerId = (Long) audienceId.getComponentValue("Customer");
      // now query scoreQueryUtility for the credit score of customerId
      Double score = scoreQueryUtility.query(customerId);
      String str = Double.toString(score);
      List<String> list = new LinkedList<String>();
      list.add(str);
      return list;
     }
    }
  2. GetCreditScore.javaGetCreditScore.class にコンパイルします。

  3. GetCreditScore.class およびこのファイルで使用する他のクラス・ファイルを含む creditscore.jar という JAR ファイルを作成します。

  4. ランタイム・サーバー上の任意の場所 (/data/interact/creditscore.jar など) に JAR ファイルをコピーします。

  5. 「構成管理」ページで、externalCallouts カテゴリーに名前が GetCreditScore でクラスパスが /data/interact/creditscore.jar の外部コールアウトを作成します。

  6. 対話式フローチャートで、コールアウトを EXTERNALCALLOUT('GetCreditScore') として使用できます。