Skip to content

Commit bc85669

Browse files
chitara-01Shabirmean
authored andcommitted
Correction in DeIdentifyWithExceptionList class to follow exception rule in InspectConfig
1 parent eb7f5f0 commit bc85669

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

dlp/snippets/src/main/java/dlp/snippets/DeIdentifyWithExceptionList.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@
2626
import com.google.privacy.dlp.v2.DeidentifyConfig;
2727
import com.google.privacy.dlp.v2.DeidentifyContentRequest;
2828
import com.google.privacy.dlp.v2.DeidentifyContentResponse;
29+
import com.google.privacy.dlp.v2.ExclusionRule;
2930
import com.google.privacy.dlp.v2.InfoType;
3031
import com.google.privacy.dlp.v2.InfoTypeTransformations;
3132
import com.google.privacy.dlp.v2.InfoTypeTransformations.InfoTypeTransformation;
3233
import com.google.privacy.dlp.v2.InspectConfig;
34+
import com.google.privacy.dlp.v2.InspectionRule;
35+
import com.google.privacy.dlp.v2.InspectionRuleSet;
3336
import com.google.privacy.dlp.v2.LocationName;
37+
import com.google.privacy.dlp.v2.MatchingType;
3438
import com.google.privacy.dlp.v2.PrimitiveTransformation;
3539
import com.google.privacy.dlp.v2.ReplaceWithInfoTypeConfig;
3640
import java.io.IOException;
@@ -69,12 +73,31 @@ public static void deIdentifyWithExceptionList(String projectId, String textToDe
6973
CustomInfoType customInfoType =
7074
CustomInfoType.newBuilder().setInfoType(developerEmail).setDictionary(wordList).build();
7175

76+
ExclusionRule exclusionRule =
77+
ExclusionRule.newBuilder()
78+
.setDictionary(wordList)
79+
.setMatchingType(MatchingType.MATCHING_TYPE_FULL_MATCH)
80+
.build();
81+
82+
InspectionRule inspectionRule =
83+
InspectionRule.newBuilder()
84+
.setExclusionRule(exclusionRule)
85+
.build();
86+
7287
// Specify the word list custom info type and build-in info type the inspection will look for.
7388
InfoType emailAddress = InfoType.newBuilder().setName("EMAIL_ADDRESS").build();
89+
90+
InspectionRuleSet inspectionRuleSet =
91+
InspectionRuleSet.newBuilder()
92+
.addInfoTypes(emailAddress)
93+
.addRules(inspectionRule)
94+
.build();
95+
7496
InspectConfig inspectConfig =
7597
InspectConfig.newBuilder()
7698
.addInfoTypes(emailAddress)
7799
.addCustomInfoTypes(customInfoType)
100+
.addRuleSet(inspectionRuleSet)
78101
.build();
79102

80103
// Define type of deidentification as replacement.

0 commit comments

Comments
 (0)