Create a New Standalone Java Program to Apply Privacy Rules


The Data Privacy API provides support to apply dynamic privacy rules from any Java application so that the data can be disguised using the rules defined to File-AID Data Privacy. The javadoc for the Data Privacy API can be found in your Topaz Workbench installation directory. The default location is:

<install directory>\Enterprise Data\Data Privacy Samples\doc\api

Important

<install directory> is equivalent to the default installation path of C:\Users\<Windows ID>\Compuware Topaz, where <Windows ID> is the Windows login ID that was used to install the product.  Note that the product may be installed in a non-default location and thus the file paths may differ.

This topic explains how to create a Java program in the Eclipse environment and how to call the Data Privacy API from the Java program.

To create a new Java program using Eclipse

Perform the following steps. You might want to refer to the  sample code for assistance.

  1. Open the Eclipse IDE.
  2. Select the workspace where you want to define the Java program. 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 > Perspective > Java.
  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 > Configure Build Path> Add External JARs. Browse through the dialog box that appears to where the following jar files are located.
    • com.compuware.dataprivacy.api
    • com.compuware.dataprivacy.api.impl

      Important

      These files are located in your Topaz Workbench installation directory. The default location is: <install directory>\Enterprise Data\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. Right-click on package > Refactor > Rename. This is applicable in Standard Eclipse only.
  9. In the class that gets generated, provide your implementation for calling the Data Privacy API. 
  10. Create a new Data Privacy Rules Provider by specifying your Data Privacy Server Host and Port Number.

    The following is sample code that creates a new Data Privacy Rules Provider that connects to a Data Privacy Server Host 10.30.10.29 and Port Number 4180: 

    Important

    IFieldMetadata can have the following classes as parameters:

    1. NumericFieldMetadata: This class represents a numeric field in the Metadata. See the following example:
      JavaAPI_1.png
    2. TextFieldMetadata: This class represents a text field in the Metadata. See the following example:
      JavaAPI2.png


    IDataPrivacyRulesProvider provider = new
    DataPrivacyRulesProvider("10.30.10.29", "4180");
  11. Create a List of Field Metadata and add the required fields.

    The following is sample code that creates a list of one numeric field (SSN) and one text (LAST_NAME) field: 

    List<IFieldMetadata> fldMetadata = new ArrayList<IFieldMetadata>();
    fldMetadata.add(new NumericFieldMetadata(0, "SSN"));
    fldMetadata.add(new TextFieldMetadata(1, "LAST_NAME"));
  12. Get the Data Privacy Rules from the Data Privacy Rules Provider that was created in step 10 by specifying the Data Privacy Repository Name and Project ID and passing the field metadata that was created in step 11.

    The following is a sample code that gets the rules from Project ID
    "8a9e8a9d509485ae0150b02c960804f3" present in the Data Privacy Repository named FBTEST_REPOTRUNK:

    Important

    You can supply the following parameters to the getDataPrivacyRules method:

    Parameters

    Details

    getDataPrivacyRules(String repositoryName, String projectID, IFieldMetadata fldMetadata)
    • repositoryName: The name of the repository where the data privacy project is present.
    • projectID: The project ID where the rules are present.
    • fldMetadata: The field metadata for which the rules need to be fetched.
    getDataPrivacyRules(String repositoryName, String projectID, List<IFieldMetadata> fldMetadata)


    IDataPrivacyRules privacyRules =
    provider.getDataPrivacyRules("FBTEST_REPOTRUNK",
    "8a9e8a9d509485ae0150b3af216b058e", fldMetadata);
  13. Create a list of fields for the source data that you want to disguise, then set the source data to the fields.

    The following is sample code that creates a list of one numeric field (ssnField) and one text field (lNameField), then sets the source data to those fields (SSN value to 123574698 and Last Name value to White): 

    List<IField> fields = new ArrayList<IField>();
    INumericField ssnField = new NumericField(0);
    ITextField lNameField = new TextField(1);
    fields.add(ssnField);
    fields.add(lNameField);
    ssnField.setValue(123574698);
    lNameField.setValue("White");

    The setValue method inside NumericField takes Integer as an argument. The setValue method inside TextField takes String as an argument.

    You can add the following parameters to apply a method:

    Parameter

    Details

    apply (IField field)

    field:  A data privacy field that needs to be disguised

    apply (List<IField> fields)

    fields: A list of data privacy fields that needs to be disguised.

  14. Apply the rules by passing the fields created and added in step 13.

    The following is sample code that applies the rules by passing the fields: 

    int retcode = privacyRules.apply(fields);
  15. Get the results after the successful disguise (retcode is zero).

    The following is sample code that gets the disguised results: 

    Number disguisedSSN = ssnField.getValue();
    String disguisedLastName = lNameField.getValue();

    The following are the return codes that the apply method can return pertaining to the mentioned scenarios:

    1. SUCCESS = 0; 
    2. INFO = 1; 
    3. WARN = 4; 
    4. ERROR = 8; 
    5. FATAL = 16;
  16. After you complete your Java program, right-click on the project and select Export > Java > Jar file, then click Next.
  17. Provide the path of the folder where you want to save the jar file using the Browse button under Select the export destination section.

    Important

    The full source code for the example described above can be found in the Topaz Workbench installation directory. The default location is: <install directory>\Enterprise Data\Data Privacy Samples\src\com\compuware\dataprivacy\samples\api\APISample.java

  18. To execute the Java program, you need to include the File-AID Rules Engine jars to the classpath. The following is an example command to execute the Java program from the command line: 

    java -cp <Path to your File-AID Rules Engine jars> <your java program>

    You need to include four jars (slf4j-api-1.7.32.jar, log4j-slf4j-impl-2.17.1.jar, log4j-api-2.17.1.jar & log4j-core-2.17.1.jar) located in the dme folder of the installed File-AID Execution Server, or under <install directory>\eclipse\plugins\com.compuware.fileaid.ex.standalone.product.executionserver.x64_<versioninfo>\lib\thirdparty. <versioninfo> is an alphanumeric string representing the product version that is installed.
    Also, you need to include the database drivers in the classpath if you are using translation for disguise.

    If using JDK 11, add jaxb-runtime-2.3.1.jar located under <Remote Execution Server Install Directory>\Dme\hibernate or under <install directory>\eclipse\plugins \ com.compuware.fileaid.ex.standalone.product.executionserver.x64_<versioninfo>\lib\thirdparty\hibernate.

    Important

    • <Remote Execution Server Install Directory> is the location of the remote execution server installation.  By default, it is installed to C:\Program Files\Compuware\File-AID_EX.
    • <versioninfo> is an alphanumeric string representing the product version that is installed.
  19. To execute the Java program from Eclipse:

    1. Right-click on the project and select Build Path > Add External Archives.
    2. Browse through the dialog box that appears to where the Common Disguise Engine jar files are located (the Common Disguise Engine install directory). Add the four jar files (slf4j-api-1.7.32.jar, log4j-slf4j-impl-2.17.1.jar, log4j-api-2.17.1.jar & log4j-core-2.17.1.jar) located in the dme folder of the installed File-AID Execution Server. Be sure to also include database drivers if you are using translation for disguise.

      If using JDK 11, add jaxb-runtime-2.3.1.jar located under <Remote Execution Server Install Directory>\Dme\hibernate or under

      <install directory>\eclipse\plugins \ com.compuware.fileaid.ex.standalone.product.executionserver.x64_<versioninfo>\lib\thirdparty\hibernate.

      Important

      • <Remote Execution Server Install Directory> is the location of the Remote Execution Server installation.  By default, it is installed to: C:\Program Files\Compuware\File-AID_EX.
      • <versioninfo> is an alphanumeric string representing the product version that is installed.
    3. Right-click on the project, select Run as, then select Java Application.

    The following exceptions might occur when you call the methods that are mentioned in this procedure:

    Exception

    Details

    DataPrivacyAPIException

    Occurs when there is any issue while fetching the rules from the Data Privacy Repository for the metadata fields.

    NullPointerException

    Occurs if a variable does not have any value but is used and operated upon.

    NoClassDefFoundError

    Occurs if the .class file for a particular class is not found at the runtime.

    IllegalArgumentException

    Occurs if any method is called with an invalid argument. For example, calling the method that uses String as a parameter with an Integer argument.

Sample code

You can refer to the following example while creating a Java program:

public Object evaluate(List<Object> params) throws Exception {
       // Get the parameters passed into custom function.
       // The following gets the SSN and Last Name values.
       String ssn = (String) params.get(0);
       String lName = (String) params.get(1);
       IDataPrivacyRules privacyRules = null;
       Properties resourceProps = new Properties();
       List<IFieldMetadata> fldMetadata = new ArrayList<IFieldMetadata>();
       if (ssn != null && lName != null) {
           // Create a list of fields and add the fields required to the list.
           // The following creates a list of one numeric field and one text fields.
           List<IField> fields = new ArrayList<IField>();
           INumericField ssnField = new NumericField(0);
           fields.add(ssnField);
           ITextField lNameField = new TextField(1);
           fields.add(lNameField);
           // Set the field values.
           // The following sets the SSN and Last Name field values.
           ssnField.setValue(Integer.parseInt(ssn));
           lNameField.setValue(lName);
           IDataPrivacyRulesProvider provider = new DataPrivacyRulesProvider(
                   resourceProps.getProperty("REGRESSION_DP_SERVER_IP"),
                   resourceProps.getProperty("REGRESSION_DP_SERVER_PORT"));

           privacyRules = provider.getDataPrivacyRules(resourceProps.getProperty("REGRESSION_REPO_NAME"),
                   resourceProps.getProperty("REGRESSION_MF_TT_PROJECT_ID"), fldMetadata);
           // Apply the rules.
           privacyRules.apply(fields);

           // Get the results after disguise.
           Number disguisedSsn = ssnField.getValue();
           String disguisedLastName = lNameField.getValue();

           // Create a list of results and add the disguised results to the list.
           List<String> results = new ArrayList<String>();
           results.add(disguisedSsn.toString());
           results.add(disguisedLastName);

           return results;
        }
       return null;

public void initialize() throws Exception {

       //Specify the Data Privacy Server Host and Port Number.
       //The following connects to a Data Privacy Server Host 10.30.10.29 and Port
       //Number 4180.
       IDataPrivacyRulesProvider provider = new
       DataPrivacyRulesProvider("10.30.10.29", "4180");

       //Create a List of Field Metadata and add the required fields.
       //The following creates a list of one numeric field (SSN) and one text field
       //(LAST_NAME).
       List<IFieldMetadata> fldMetadata = new ArrayList<IFieldMetadata>();
       fldMetadata.add(new NumericFieldMetadata(0, "SSN"));
       fldMetadata.add(new TextFieldMetadata(1, "LAST_NAME"));

       Properties resourceProps = new Properties();
       IDataPrivacyRules    privacyRules = provider.getDataPrivacyRules(resourceProps.getProperty("REGRESSION_REPO_NAME"),
               resourceProps.getProperty("REGRESSION_MF_TT_PROJECT_ID"), fldMetadata);
    
       //Specify the Data Privacy Repository name and Project ID to get the rules.
       //The following gets the rules from Project ID
       //"8a9e8a9d509485ae0150b02c960804f3"
       //present in the Data Privacy Repository named "FBTEST_REPOTRUNK".
       privacyRules = provider.getDataPrivacyRules("FBTEST_REPOTRUNK",
       "8a9e8a9d509485ae0150b02c960804f3", fldMetadata);
    }    
}

 

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