Default language.

Create a New Java Routine


You must create a Java routine before you can create a new Data Privacy custom function. This topic will explain how to create a Java routine in the Eclipse environment. For details on how to use your newly created Java routine as a Data Privacy custom function, see Create-a-New-Custom-Function.

To create a new Java routine using Eclipse:

  1. Open the Eclipse IDE.
  2. Select the workspace where you want to define the Java routine. You can select an existing workspace or create a new one.
  3. If the Java Project Perspective and the Package Explorer view are not loaded automatically, switch to the Java Perspective by clicking Window > Open Perspective > Java Project (default).
  4. On the Package Explorer view, right-click and create a New Java Project in Eclipse. Provide a valid name, and leave the rest of the settings at the default.
  5. Right-click on the project and click Build Path > Add External Archives. Browse through the dialog box that appears to where the following jar files are located.

    • com.compuware.dataprivacy.userdefined
    • com.compuware.fileaid.common.expressionparser.extern

      Important

      These files are located in your Topaz Workbench installation directory. The default location is:

    <install directory>\Program Files\Compuware\Topaz Workbench\Data Privacy Samples\lib

  6. Select these two jar files and click OK.
  7. Right-click on the src folder within the project, and click New > Class.
  8. Provide a Class Name and the desired Package structure.
  9. For an expression builder function, your custom class should implement IUserDefinedFunction present in the userdefined.jar.

    In the class that gets generated, provide your implementation for the evaluate method. The object list in the function argument contains the input to your method from the expression in the exact same order as defined in the Data Privacy project. The object returned from this method would be available back to your expression (defined in the Data Privacy project) as the output of this custom method.

    The following is sample implementation code that pads the input value to the given size with the given pad value. 

    @Override
    public Object evaluate(List<Object> params) throws Exception {

    String dataElementValue = (String)params.get(0);
    Integer length = (Integer)params.get(1);
    String padValue = (String)params.get(2);

    if (dataElementValue == null ) dataElementValue="" ;

    StringBuffer paddedValue =
    new StringBuffer(dataElementValue);
    while (paddedValue.length() < length) {
    paddedValue.append(padValue);
    }

    return paddedValue.toString();
    }
  10. For an expression builder function that supports initialization and cleanup, your custom class should implement IUserDefinedFunctionExt present in the userdefined.jar.

    The implementation for the following two methods should be provided:

    public void initialize() throws Exception;
    public void cleanup() throws Exception;
    public Object evaluate(List<Object> params) throws Exception
  11. For a value conversion function, your custom class should implement the ICustomValueAdapter present in the userdefined.jar.

    The implementation for the following two methods should be provided:

    public String convert(byte[] bytes) throws Exception
    public byte[] convert(String source) throws Exception
  12. For a custom encryption function, your custom class should implement the IUserDefinedEncryption present in the userdefined.jar.

    The implementation for the following two methods should be provided:

    void encrypt(char[] sourceStr, String key);
    void decrypt(char[] sourceStr, String key);
  13. For a custom hash function, your custom class should implement the IUserDefinedHash present in the userdefined.jar.

    The implementation for the following method should be provided:

    public long getHashRow(String hashValue, long maxValue);
  14. After you complete your custom method, right-click on the project and select Export > Java > Jar file and click Next.
  15. Provide the path of the folder where you want to save the jar file using the Browse button under Select the export destination section.
  16. For instructions on using your Java routine as a custom function, see Create-a-New-Custom-Function.

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*