The following example shows how to use substitution parts in your server side pipelines.

Source code


public class SubstitutionPart extends AFactoryPart
{
    protected Object executeRequestForPart(String requestName, Map inArgs)
            throws RequestExecutionException
    {
       try
       {
          String substString = 
           AppObjects.getValue(requestName + ".substitution");
         
          String newString = 
           SubstitutorUtils.generalSubstitute(
            substString,new MapDictionary(inArgs));
            
          return newString;
       }
       catch(ConfigException x)
       {
          throw new RequestExecutionException("Error:config errror",x);
       }
    }//eof-function
}//eof-class

How to use it


request.example.classname=com.ai.parts.SubstitutionPart
request.example.substitution=sometext {key} someother text {key2}
request.example.resultName=newkey1

The above code will introduce a key called "newkey1" in to the parameter list. You can use it in the downstream calls. here is a complete example

Using this part in a multi exec


request.MR.classname=com.ai.db.DBPreTranslateArgsMultiRequestExecutor
request.MR.db=some-database
request.MR.request.1=example
request.MR.request.2=R2

request.R2.classname=com.ai.db.DBRequestExecutor2
request.R2.stmt=select * from {newkey1}

Notice how the key "newkey1" is used.

Planning for a RecursiveSubstitutionPart

In the next release I will have the above part expanded to cover the recursion if needed. Under this scheme you can do this


request.example.classname=com.ai.parts.RecursiveSubstitutionPart
request.example.substitution=sometext {key} someother text {key2}
request.example.numberOfTimes=2
request.example.resultName=newkey1

The above code will run the substitution twice.

Source code for the part

Here is the source code for the part


package com.ai.parts;

import java.util.Map;

import com.ai.application.interfaces.AFactoryPart;
import com.ai.application.interfaces.ConfigException;
import com.ai.application.interfaces.RequestExecutionException;
import com.ai.application.utils.AppObjects;
import com.ai.common.MapDictionary;
import com.ai.common.SubstitutorUtils;

public class RecursiveSubstitutionPart  extends AFactoryPart
{

    protected Object executeRequestForPart(String requestName, Map inArgs)
    throws RequestExecutionException
   {
      try
      {
        String substString = AppObjects.getValue(requestName + ".substitution");
        String sNumberOfTimes = AppObjects.getValue(requestName + ".numberOfTimes","1");
        int numberOfTimes = Integer.parseInt(sNumberOfTimes);
        
        //If it is zero times, atleast do it once
        if (numberOfTimes == 0) numberOfTimes = 1;
            
        //Separate the more common case of 1 and do it right
        if (numberOfTimes == 1)
        {
            String newString = 
			SubstitutorUtils.generalSubstitute(substString,new MapDictionary(inArgs));
            return newString;
        }
        
        //more times expected
        String newString = substString;
        for(int i=0;i<numberOfTimes;i++)
        {
            newString = 
			SubstitutorUtils.generalSubstitute(newString,new MapDictionary(inArgs));
        }
        return newString;
      }
      catch(ConfigException x)
      {
        throw new RequestExecutionException("Error:config errror",x);
      }
   }//eof-function

}

Build information

The SubstitutionPart has been there for some time. The current build release is 22.2. The RecursiveSubstitutionPart will be there in the next release. For now if you would like to use just compile it against aspire and drop it in the web-inf/lib directory.