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>\Program Files\Compuware\Topaz Workbench\Data Privacy Samples\doc\api
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:
- Open the Eclipse IDE.
- Select the workspace where you want to define the Java program. You can select an existing workspace or create a new one.
- 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).
- 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.
- 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.api
com.compuware.dataprivacy.api.impl
- Select these two jar files and click OK.
- Right-click on the src folder within the project, and click New > Class.
- Provide a Class Name and the desired Package structure.
- In the class that gets generated, provide your implementation for calling the Data Privacy API.
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:
IDataPrivacyRulesProvider provider = new
DataPrivacyRulesProvider("10.30.10.29", "4180");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"));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 sample code that gets the rules from Project ID "8a9e8a9d509485ae0150b02c960804f3" present in the Data Privacy Repository named FBTEST_REPOTRUNK:
IDataPrivacyRules privacyRules =
provider.getDataPrivacyRules("FBTEST_REPOTRUNK",
"8a9e8a9d509485ae0150b3af216b058e", fldMetadata);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");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);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();- After you complete your Java program, right-click on the project and select Export > Java > Jar file, then click Next.
Provide the path of the folder where you want to save the jar file using the Browse button under Select the export destination section.
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 three jars (org.apache.log4j.jar, slf4j-api-1.7.30.jar & slf4j-log4j12-1.7.30.jar) located in the dme folder of the installed File-AID Execution Server, or under the <Topaz_Install>\eclipse\plugins\com.compuware.fileaid.ex.standalone.product.executionserver.x64_versioninfo\lib\thirdparty. 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 the <Execution Server Install Folder>\dme\hibernate or under the <Topaz_Install>\eclipse\plugins\com.compuware.fileaid.ex.standalone.product.executionserver.x64_versioninfo\lib\thirdparty\hibernate.
- To execute the Java program from Eclipse:
- Right-click on the project and select Build Path > Add External Archives.
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 three jar files (org.apache.log4j.jar, slf4j-api-1.7.30.jar & slf4j-log4j12-1.7.30.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 the <Execution Server Install Folder>\dme\hibernate or under the <Topaz_Install>\eclipse\plugins\com.compuware.fileaid.ex.standalone.product.executionserver.x64_versioninfo\lib\thirdparty\hibernate.
Right-click on the project, select Run as, then select Java Application.