com.google.privacy.dlp.v2.Value Java Examples

The following examples show how to use com.google.privacy.dlp.v2.Value. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DLPTokenizationDoFnTest.java    From dlp-dataflow-deidentification with Apache License 2.0 6 votes vote down vote up
@Test
public void testConvertTableRowToRow() {
  DLPTokenizationDoFn dlp =
      new DLPTokenizationDoFn(
          "Project Name",
          ValueProvider.StaticValueProvider.of("DeidentifyTemplateName"),
          ValueProvider.StaticValueProvider.of("IdentifyTemplateName"));

  String[] header = {"header0", "header1"};
  String key = "Key name";
  Table.Row.Builder tableRowBuilder = Table.Row.newBuilder();
  tableRowBuilder.addValues(0, Value.newBuilder().setStringValue("value0"));
  tableRowBuilder.addValues(1, Value.newBuilder().setStringValue("value1"));
  Table.Row row = tableRowBuilder.build();

  Row result = dlp.convertTableRowToRow(header, key, row);
  assertEquals(result.getTableId(), key);
  assertEquals(result.getHeader()[0], "header0");
  assertEquals(result.getValue()[1], "value1");
}
 
Example #2
Source File: DeIdentifyTableRowSuppress.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
public static void deIdentifyTableRowSuppress() throws IOException {
  // TODO(developer): Replace these variables before running the sample.
  String projectId = "your-project-id";
  Table tableToDeIdentify = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("AGE").build())
      .addHeaders(FieldId.newBuilder().setName("PATIENT").build())
      .addHeaders(FieldId.newBuilder().setName("HAPPINESS SCORE").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("101").build())
          .addValues(Value.newBuilder().setStringValue("Charles Dickens").build())
          .addValues(Value.newBuilder().setStringValue("95").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("22").build())
          .addValues(Value.newBuilder().setStringValue("Jane Austen").build())
          .addValues(Value.newBuilder().setStringValue("21").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("55").build())
          .addValues(Value.newBuilder().setStringValue("Mark Twain").build())
          .addValues(Value.newBuilder().setStringValue("75").build())
          .build())
      .build();

  deIdentifyTableRowSuppress(projectId, tableToDeIdentify);
}
 
Example #3
Source File: MapStringToDlpRowTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void mapsDelimitedStringToRow() {
  PCollection<KV<String, Table.Row>> rowCollection =
      testPipeline
          .apply(Create.of(KV.of("key", "value,secondValue")))
          .apply(ParDo.of(new MapStringToDlpRow(",")));
  PAssert.that(rowCollection)
      .containsInAnyOrder(
          KV.of(
              "key",
              Table.Row.newBuilder()
                  .addValues(Value.newBuilder().setStringValue("value").build())
                  .addValues(Value.newBuilder().setStringValue("secondValue").build())
                  .build()));
  testPipeline.run().waitUntilFinish();
}
 
Example #4
Source File: DeIdentifyTableConditionMasking.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
public static void deIdentifyTableConditionMasking() throws IOException {
  // TODO(developer): Replace these variables before running the sample.
  String projectId = "your-project-id";
  Table tableToDeIdentify = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("AGE").build())
      .addHeaders(FieldId.newBuilder().setName("PATIENT").build())
      .addHeaders(FieldId.newBuilder().setName("HAPPINESS SCORE").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("101").build())
          .addValues(Value.newBuilder().setStringValue("Charles Dickens").build())
          .addValues(Value.newBuilder().setStringValue("95").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("22").build())
          .addValues(Value.newBuilder().setStringValue("Jane Austen").build())
          .addValues(Value.newBuilder().setStringValue("21").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("55").build())
          .addValues(Value.newBuilder().setStringValue("Mark Twain").build())
          .addValues(Value.newBuilder().setStringValue("75").build())
          .build())
      .build();

  deIdentifyTableConditionMasking(projectId, tableToDeIdentify);
}
 
Example #5
Source File: ReIdentifyTableWithFpe.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  // TODO(developer): Replace these variables before running the sample.
  String projectId = "your-project-id";
  String kmsKeyName =
      "projects/YOUR_PROJECT/"
          + "locations/YOUR_KEYRING_REGION/"
          + "keyRings/YOUR_KEYRING_NAME/"
          + "cryptoKeys/YOUR_KEY_NAME";
  String wrappedAesKey = "YOUR_ENCRYPTED_AES_256_KEY";
  Table tableToReIdentify = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("Employee ID").build())
      .addRows(
          Row.newBuilder().addValues(
              Value.newBuilder().setStringValue("28777").build())
              .build())
      .build();
  reIdentifyTableWithFpe(projectId, tableToReIdentify, kmsKeyName, wrappedAesKey);
}
 
Example #6
Source File: DeIdentifyTableBucketing.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
public static void deIdentifyTableBucketing() throws IOException {
  // TODO(developer): Replace these variables before running the sample.
  String projectId = "your-project-id";
  Table tableToDeIdentify = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("AGE").build())
      .addHeaders(FieldId.newBuilder().setName("PATIENT").build())
      .addHeaders(FieldId.newBuilder().setName("HAPPINESS SCORE").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("101").build())
          .addValues(Value.newBuilder().setStringValue("Charles Dickens").build())
          .addValues(Value.newBuilder().setStringValue("95").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("22").build())
          .addValues(Value.newBuilder().setStringValue("Jane Austen").build())
          .addValues(Value.newBuilder().setStringValue("21").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("55").build())
          .addValues(Value.newBuilder().setStringValue("Mark Twain").build())
          .addValues(Value.newBuilder().setStringValue("75").build())
          .build())
      .build();

  deIdentifyTableBucketing(projectId, tableToDeIdentify);
}
 
Example #7
Source File: DeIdentifyTableConditionInfoTypes.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
public static void deIdentifyTableConditionInfoTypes() throws IOException {
  // TODO(developer): Replace these variables before running the sample.
  String projectId = "your-project-id";
  Table tableToDeIdentify = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("AGE").build())
      .addHeaders(FieldId.newBuilder().setName("PATIENT").build())
      .addHeaders(FieldId.newBuilder().setName("HAPPINESS SCORE").build())
      .addHeaders(FieldId.newBuilder().setName("FACTOID").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("101").build())
          .addValues(Value.newBuilder().setStringValue("Charles Dickens").build())
          .addValues(Value.newBuilder().setStringValue("95").build())
          .addValues(Value.newBuilder().setStringValue(
              "Charles Dickens name was a curse, possibly invented by Shakespeare.").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("22").build())
          .addValues(Value.newBuilder().setStringValue("Jane Austen").build())
          .addValues(Value.newBuilder().setStringValue("21").build())
          .addValues(Value.newBuilder().setStringValue(
              "There are 14 kisses in Jane Austen's novels.").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("55").build())
          .addValues(Value.newBuilder().setStringValue("Mark Twain").build())
          .addValues(Value.newBuilder().setStringValue("75").build())
          .addValues(Value.newBuilder().setStringValue("Mark Twain loved cats.").build())
          .build())
      .build();

  deIdentifyTableConditionInfoTypes(projectId, tableToDeIdentify);
}
 
Example #8
Source File: InspectTests.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
@Test
public void testInspectTable() {
  Table tableToInspect = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("name").build())
      .addHeaders(FieldId.newBuilder().setName("phone").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("John Doe").build())
          .addValues(Value.newBuilder().setStringValue("(206) 555-0123").build()))
      .build();
  InspectTable.inspectTable(PROJECT_ID, tableToInspect);

  String output = bout.toString();
  assertThat(output).contains("Info type: PHONE_NUMBER");
}
 
Example #9
Source File: DeIdentificationTests.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
@Test
public void testReIdentifyTableWithFpe() throws IOException {
  Table tableToReIdentify = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("Employee ID").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("28777").build()).build())
      .build();

  ReIdentifyTableWithFpe.reIdentifyTableWithFpe(
      PROJECT_ID, tableToReIdentify, kmsKeyName, wrappedKey);

  String output = bout.toString();
  assertThat(output).contains("Table after re-identification:");
}
 
Example #10
Source File: DeIdentificationTests.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeIdentifyTableWithFpe() throws IOException {
  Table tableToDeIdentify = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("Employee ID").build())
      .addHeaders(FieldId.newBuilder().setName("Date").build())
      .addHeaders(FieldId.newBuilder().setName("Compensation").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("11111").build())
          .addValues(Value.newBuilder().setStringValue("2015").build())
          .addValues(Value.newBuilder().setStringValue("$10").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("11111").build())
          .addValues(Value.newBuilder().setStringValue("2016").build())
          .addValues(Value.newBuilder().setStringValue("$20").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("22222").build())
          .addValues(Value.newBuilder().setStringValue("2016").build())
          .addValues(Value.newBuilder().setStringValue("$15").build())
          .build())
      .build();

  DeIdentifyTableWithFpe.deIdentifyTableWithFpe(
      PROJECT_ID, tableToDeIdentify, kmsKeyName, wrappedKey);

  String output = bout.toString();
  assertThat(output).contains("Table after format-preserving encryption:");
}
 
Example #11
Source File: InspectTable.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  // TODO(developer): Replace these variables before running the sample.
  String projectId = "your-project-id";
  Table tableToInspect = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("name").build())
      .addHeaders(FieldId.newBuilder().setName("phone").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("John Doe").build())
          .addValues(Value.newBuilder().setStringValue("(206) 555-0123").build()))
      .build();

  inspectTable(projectId, tableToInspect);
}
 
Example #12
Source File: DLPTextToBigQueryStreaming.java    From dlp-dataflow-deidentification with Apache License 2.0 5 votes vote down vote up
private Table.Row convertCsvRowToTableRow(CSVRecord csvRow) {
  /** convert from CSV row to DLP Table Row */
  Iterator<String> valueIterator = csvRow.iterator();
  Table.Row.Builder tableRowBuilder = Table.Row.newBuilder();
  while (valueIterator.hasNext()) {
    String value = valueIterator.next();
    if (value != null) {
      tableRowBuilder.addValues(Value.newBuilder().setStringValue(value.toString()).build());
    } else {
      tableRowBuilder.addValues(Value.newBuilder().setStringValue("").build());
    }
  }

  return tableRowBuilder.build();
}
 
Example #13
Source File: DeIdentifyTableInfoTypes.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
public static void deIdentifyTableInfoTypes() throws IOException {
  // TODO(developer): Replace these variables before running the sample.
  String projectId = "your-project-id";
  Table tableToDeIdentify = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("AGE").build())
      .addHeaders(FieldId.newBuilder().setName("PATIENT").build())
      .addHeaders(FieldId.newBuilder().setName("HAPPINESS SCORE").build())
      .addHeaders(FieldId.newBuilder().setName("FACTOID").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("101").build())
          .addValues(Value.newBuilder().setStringValue("Charles Dickens").build())
          .addValues(Value.newBuilder().setStringValue("95").build())
          .addValues(Value.newBuilder().setStringValue(
              "Charles Dickens name was a curse, possibly invented by Shakespeare.").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("22").build())
          .addValues(Value.newBuilder().setStringValue("Jane Austen").build())
          .addValues(Value.newBuilder().setStringValue("21").build())
          .addValues(Value.newBuilder().setStringValue(
              "There are 14 kisses in Jane Austen's novels.").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("55").build())
          .addValues(Value.newBuilder().setStringValue("Mark Twain").build())
          .addValues(Value.newBuilder().setStringValue("75").build())
          .addValues(Value.newBuilder().setStringValue("Mark Twain loved cats.").build())
          .build())
      .build();

  deIdentifyTableInfoTypes(projectId, tableToDeIdentify);
}
 
Example #14
Source File: Util.java    From dlp-dataflow-deidentification with Apache License 2.0 5 votes vote down vote up
public static Table.Row convertCsvRowToTableRow(String row) {
  String[] values = row.split(",");
  Table.Row.Builder tableRowBuilder = Table.Row.newBuilder();
  for (String value : values) {
    tableRowBuilder.addValues(Value.newBuilder().setStringValue(value).build());
  }

  return tableRowBuilder.build();
}
 
Example #15
Source File: DeIdentifyWithDateShift.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
public static String joinRow(List<Value> values) {
  String name = values.get(0).getStringValue();
  String birthDate = formatDate(values.get(1).getDateValue());
  String creditCardNumber = values.get(2).getStringValue();
  String registerDate = formatDate(values.get(3).getDateValue());
  return String.join(",", name, birthDate, creditCardNumber, registerDate);
}
 
Example #16
Source File: DeIdentifyWithDateShift.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
public static Table.Row parseLineAsRow(String line) {
  List<String> values = Splitter.on(",").splitToList(line);
  Value name = Value.newBuilder().setStringValue(values.get(0)).build();
  Value birthDate = Value.newBuilder().setDateValue(parseAsDate(values.get(1))).build();
  Value creditCardNumber = Value.newBuilder().setStringValue(values.get(2)).build();
  Value registerDate = Value.newBuilder().setDateValue(parseAsDate(values.get(3))).build();
  return Table.Row.newBuilder()
      .addValues(name)
      .addValues(birthDate)
      .addValues(creditCardNumber)
      .addValues(registerDate)
      .build();
}
 
Example #17
Source File: DeIdentifyTableWithFpe.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  // TODO(developer): Replace these variables before running the sample.
  String projectId = "your-project-id";
  String kmsKeyName =
      "projects/YOUR_PROJECT/"
          + "locations/YOUR_KEYRING_REGION/"
          + "keyRings/YOUR_KEYRING_NAME/"
          + "cryptoKeys/YOUR_KEY_NAME";
  String wrappedAesKey = "YOUR_ENCRYPTED_AES_256_KEY";
  Table tableToDeIdentify = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("Employee ID").build())
      .addHeaders(FieldId.newBuilder().setName("Date").build())
      .addHeaders(FieldId.newBuilder().setName("Compensation").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("11111").build())
          .addValues(Value.newBuilder().setStringValue("2015").build())
          .addValues(Value.newBuilder().setStringValue("$10").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("11111").build())
          .addValues(Value.newBuilder().setStringValue("2016").build())
          .addValues(Value.newBuilder().setStringValue("$20").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("22222").build())
          .addValues(Value.newBuilder().setStringValue("2016").build())
          .addValues(Value.newBuilder().setStringValue("$15").build())
          .build())
      .build();
  deIdentifyTableWithFpe(projectId, tableToDeIdentify, kmsKeyName, wrappedAesKey);
}
 
Example #18
Source File: MapStringToDlpRowTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void mapsStringToRow() {
  PCollection<KV<String, Table.Row>> rowCollection =
      testPipeline
          .apply(Create.of(KV.of("key", "value")))
          .apply(ParDo.of(new MapStringToDlpRow(null)));
  PAssert.that(rowCollection)
      .containsInAnyOrder(
          KV.of(
              "key",
              Table.Row.newBuilder()
                  .addValues(Value.newBuilder().setStringValue("value").build())
                  .build()));
  testPipeline.run().waitUntilFinish();
}
 
Example #19
Source File: MapStringToDlpRow.java    From beam with Apache License 2.0 5 votes vote down vote up
@ProcessElement
public void processElement(ProcessContext context) {
  Table.Row.Builder rowBuilder = Table.Row.newBuilder();
  String line = Objects.requireNonNull(context.element().getValue());
  if (delimiter != null) {
    List<String> values = Arrays.asList(line.split(delimiter));
    values.forEach(
        value -> rowBuilder.addValues(Value.newBuilder().setStringValue(value).build()));
  } else {
    rowBuilder.addValues(Value.newBuilder().setStringValue(line).build());
  }
  context.output(KV.of(context.element().getKey(), rowBuilder.build()));
}
 
Example #20
Source File: DLPTextToBigQueryStreaming.java    From DataflowTemplates with Apache License 2.0 5 votes vote down vote up
private Table.Row convertCsvRowToTableRow(CSVRecord csvRow) {
  /** convert from CSV row to DLP Table Row */
  Iterator<String> valueIterator = csvRow.iterator();
  Table.Row.Builder tableRowBuilder = Table.Row.newBuilder();
  while (valueIterator.hasNext()) {
    String value = valueIterator.next();
    if (value != null) {
      tableRowBuilder.addValues(Value.newBuilder().setStringValue(value.toString()).build());
    } else {
      tableRowBuilder.addValues(Value.newBuilder().setStringValue("").build());
    }
  }

  return tableRowBuilder.build();
}
 
Example #21
Source File: DeIdentifyTableRowSuppress.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
public static Table deIdentifyTableRowSuppress(String projectId, Table tableToDeIdentify)
    throws IOException {
  // Initialize client that will be used to send requests. This client only needs to be created
  // once, and can be reused for multiple requests. After completing all of your requests, call
  // the "close" method on the client to safely clean up any remaining background resources.
  try (DlpServiceClient dlp = DlpServiceClient.create()) {
    // Specify what content you want the service to de-identify.
    ContentItem contentItem = ContentItem.newBuilder().setTable(tableToDeIdentify).build();

    // Specify when the content should be de-identified.
    Condition condition = Condition.newBuilder()
        .setField(FieldId.newBuilder().setName("AGE").build())
        .setOperator(RelationalOperator.GREATER_THAN)
        .setValue(Value.newBuilder().setIntegerValue(89).build()).build();
    // Apply the condition to record suppression.
    RecordSuppression recordSuppressions =
        RecordSuppression.newBuilder()
            .setCondition(RecordCondition.newBuilder()
                .setExpressions(Expressions.newBuilder()
                    .setConditions(Conditions.newBuilder().addConditions(condition).build())
                    .build())
                .build())
            .build();
    // Use record suppression as the only transformation
    RecordTransformations transformations =
        RecordTransformations.newBuilder()
            .addRecordSuppressions(recordSuppressions)
            .build();

    DeidentifyConfig deidentifyConfig =
        DeidentifyConfig.newBuilder().setRecordTransformations(transformations).build();

    // Combine configurations into a request for the service.
    DeidentifyContentRequest request =
        DeidentifyContentRequest.newBuilder()
            .setParent(LocationName.of(projectId, "global").toString())
            .setItem(contentItem)
            .setDeidentifyConfig(deidentifyConfig)
            .build();

    // Send the request and receive response from the service.
    DeidentifyContentResponse response = dlp.deidentifyContent(request);

    // Print the results.
    System.out.println(
        "Table after de-identification: " + response.getItem().getTable());

    return response.getItem().getTable();
  }
}
 
Example #22
Source File: DeIdentificationTests.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeIdentifyTableConditionsInfoTypes() throws IOException {
  // Transform findings only when specific conditions are met on another field
  Table tableToDeIdentify = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("AGE").build())
      .addHeaders(FieldId.newBuilder().setName("PATIENT").build())
      .addHeaders(FieldId.newBuilder().setName("HAPPINESS SCORE").build())
      .addHeaders(FieldId.newBuilder().setName("FACTOID").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("101").build())
          .addValues(Value.newBuilder().setStringValue("Charles Dickens").build())
          .addValues(Value.newBuilder().setStringValue("95").build())
          .addValues(Value.newBuilder().setStringValue(
              "Charles Dickens name was a curse, possibly invented by Shakespeare.").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("22").build())
          .addValues(Value.newBuilder().setStringValue("Jane Austen").build())
          .addValues(Value.newBuilder().setStringValue("21").build())
          .addValues(Value.newBuilder().setStringValue(
              "There are 14 kisses in Jane Austen's novels.").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("55").build())
          .addValues(Value.newBuilder().setStringValue("Mark Twain").build())
          .addValues(Value.newBuilder().setStringValue("75").build())
          .addValues(Value.newBuilder().setStringValue("Mark Twain loved cats.").build())
          .build())
      .build();
  Table expectedTable = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("AGE").build())
      .addHeaders(FieldId.newBuilder().setName("PATIENT").build())
      .addHeaders(FieldId.newBuilder().setName("HAPPINESS SCORE").build())
      .addHeaders(FieldId.newBuilder().setName("FACTOID").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("101").build())
          .addValues(Value.newBuilder().setStringValue("[PERSON_NAME]").build())
          .addValues(Value.newBuilder().setStringValue("95").build())
          .addValues(Value.newBuilder().setStringValue(
              "[PERSON_NAME] name was a curse, possibly invented by Shakespeare.").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("22").build())
          .addValues(Value.newBuilder().setStringValue("Jane Austen").build())
          .addValues(Value.newBuilder().setStringValue("21").build())
          .addValues(Value.newBuilder().setStringValue(
              "There are 14 kisses in Jane Austen's novels.").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("55").build())
          .addValues(Value.newBuilder().setStringValue("Mark Twain").build())
          .addValues(Value.newBuilder().setStringValue("75").build())
          .addValues(Value.newBuilder().setStringValue("Mark Twain loved cats.").build())
          .build())
      .build();

  Table table = DeIdentifyTableConditionInfoTypes.deIdentifyTableConditionInfoTypes(
      PROJECT_ID, tableToDeIdentify);

  String output = bout.toString();
  assertThat(output).contains("Table after de-identification:");
  assertThat(table).isEqualTo(expectedTable);
}
 
Example #23
Source File: DeIdentificationTests.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeIdentifyTableRowSuppress() throws IOException {
  // Suppress a row based on the content of a column
  Table tableToDeIdentify = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("AGE").build())
      .addHeaders(FieldId.newBuilder().setName("PATIENT").build())
      .addHeaders(FieldId.newBuilder().setName("HAPPINESS SCORE").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("101").build())
          .addValues(Value.newBuilder().setStringValue("Charles Dickens").build())
          .addValues(Value.newBuilder().setStringValue("95").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("22").build())
          .addValues(Value.newBuilder().setStringValue("Jane Austen").build())
          .addValues(Value.newBuilder().setStringValue("21").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("55").build())
          .addValues(Value.newBuilder().setStringValue("Mark Twain").build())
          .addValues(Value.newBuilder().setStringValue("75").build())
          .build())
      .build();
  Table expectedTable = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("AGE").build())
      .addHeaders(FieldId.newBuilder().setName("PATIENT").build())
      .addHeaders(FieldId.newBuilder().setName("HAPPINESS SCORE").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("22").build())
          .addValues(Value.newBuilder().setStringValue("Jane Austen").build())
          .addValues(Value.newBuilder().setStringValue("21").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("55").build())
          .addValues(Value.newBuilder().setStringValue("Mark Twain").build())
          .addValues(Value.newBuilder().setStringValue("75").build())
          .build())
      .build();

  Table table = DeIdentifyTableRowSuppress.deIdentifyTableRowSuppress(
      PROJECT_ID, tableToDeIdentify);

  String output = bout.toString();
  assertThat(output).contains("Table after de-identification:");
  assertThat(table).isEqualTo(expectedTable);
}
 
Example #24
Source File: DeIdentificationTests.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeIdentifyTableInfoTypes() throws IOException {
  // Transform findings found in column
  Table tableToDeIdentify = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("AGE").build())
      .addHeaders(FieldId.newBuilder().setName("PATIENT").build())
      .addHeaders(FieldId.newBuilder().setName("HAPPINESS SCORE").build())
      .addHeaders(FieldId.newBuilder().setName("FACTOID").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("101").build())
          .addValues(Value.newBuilder().setStringValue("Charles Dickens").build())
          .addValues(Value.newBuilder().setStringValue("95").build())
          .addValues(Value.newBuilder().setStringValue(
              "Charles Dickens name was a curse, possibly invented by Shakespeare.").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("22").build())
          .addValues(Value.newBuilder().setStringValue("Jane Austen").build())
          .addValues(Value.newBuilder().setStringValue("21").build())
          .addValues(Value.newBuilder().setStringValue(
              "There are 14 kisses in Jane Austen's novels.").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("55").build())
          .addValues(Value.newBuilder().setStringValue("Mark Twain").build())
          .addValues(Value.newBuilder().setStringValue("75").build())
          .addValues(Value.newBuilder().setStringValue("Mark Twain loved cats.").build())
          .build())
      .build();
  Table expectedTable = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("AGE").build())
      .addHeaders(FieldId.newBuilder().setName("PATIENT").build())
      .addHeaders(FieldId.newBuilder().setName("HAPPINESS SCORE").build())
      .addHeaders(FieldId.newBuilder().setName("FACTOID").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("101").build())
          .addValues(Value.newBuilder().setStringValue("[PERSON_NAME]").build())
          .addValues(Value.newBuilder().setStringValue("95").build())
          .addValues(Value.newBuilder().setStringValue(
              "[PERSON_NAME] name was a curse, possibly invented by Shakespeare.").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("22").build())
          .addValues(Value.newBuilder().setStringValue("[PERSON_NAME]").build())
          .addValues(Value.newBuilder().setStringValue("21").build())
          .addValues(Value.newBuilder().setStringValue(
              "There are 14 kisses in [PERSON_NAME] novels.").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("55").build())
          .addValues(Value.newBuilder().setStringValue("[PERSON_NAME]").build())
          .addValues(Value.newBuilder().setStringValue("75").build())
          .addValues(Value.newBuilder().setStringValue("[PERSON_NAME] loved cats.").build())
          .build())
      .build();

  Table table = DeIdentifyTableInfoTypes.deIdentifyTableInfoTypes(PROJECT_ID, tableToDeIdentify);

  String output = bout.toString();
  assertThat(output).contains("Table after de-identification:");
  assertThat(table).isEqualTo(expectedTable);
}
 
Example #25
Source File: DeIdentificationTests.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeIdentifyTableConditionMasking() throws IOException {
  // Transform a column based on the value of another column
  Table tableToDeIdentify = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("AGE").build())
      .addHeaders(FieldId.newBuilder().setName("PATIENT").build())
      .addHeaders(FieldId.newBuilder().setName("HAPPINESS SCORE").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("101").build())
          .addValues(Value.newBuilder().setStringValue("Charles Dickens").build())
          .addValues(Value.newBuilder().setStringValue("95").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("22").build())
          .addValues(Value.newBuilder().setStringValue("Jane Austen").build())
          .addValues(Value.newBuilder().setStringValue("21").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("55").build())
          .addValues(Value.newBuilder().setStringValue("Mark Twain").build())
          .addValues(Value.newBuilder().setStringValue("75").build())
          .build())
      .build();
  Table expectedTable = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("AGE").build())
      .addHeaders(FieldId.newBuilder().setName("PATIENT").build())
      .addHeaders(FieldId.newBuilder().setName("HAPPINESS SCORE").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("101").build())
          .addValues(Value.newBuilder().setStringValue("Charles Dickens").build())
          .addValues(Value.newBuilder().setStringValue("**").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("22").build())
          .addValues(Value.newBuilder().setStringValue("Jane Austen").build())
          .addValues(Value.newBuilder().setStringValue("21").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("55").build())
          .addValues(Value.newBuilder().setStringValue("Mark Twain").build())
          .addValues(Value.newBuilder().setStringValue("75").build())
          .build())
      .build();

  Table table = DeIdentifyTableConditionMasking.deIdentifyTableConditionMasking(
      PROJECT_ID, tableToDeIdentify);

  String output = bout.toString();
  assertThat(output).contains("Table after de-identification:");
  assertThat(table).isEqualTo(expectedTable);
}
 
Example #26
Source File: DeIdentificationTests.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeIdentifyTableBucketing() throws IOException {
  // Transform a column based on the value of another column
  Table tableToDeIdentify = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("AGE").build())
      .addHeaders(FieldId.newBuilder().setName("PATIENT").build())
      .addHeaders(FieldId.newBuilder().setName("HAPPINESS SCORE").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("101").build())
          .addValues(Value.newBuilder().setStringValue("Charles Dickens").build())
          .addValues(Value.newBuilder().setStringValue("95").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("22").build())
          .addValues(Value.newBuilder().setStringValue("Jane Austen").build())
          .addValues(Value.newBuilder().setStringValue("21").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("55").build())
          .addValues(Value.newBuilder().setStringValue("Mark Twain").build())
          .addValues(Value.newBuilder().setStringValue("75").build())
          .build())
      .build();
  Table expectedTable = Table.newBuilder()
      .addHeaders(FieldId.newBuilder().setName("AGE").build())
      .addHeaders(FieldId.newBuilder().setName("PATIENT").build())
      .addHeaders(FieldId.newBuilder().setName("HAPPINESS SCORE").build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("101").build())
          .addValues(Value.newBuilder().setStringValue("Charles Dickens").build())
          .addValues(Value.newBuilder().setStringValue("90:100").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("22").build())
          .addValues(Value.newBuilder().setStringValue("Jane Austen").build())
          .addValues(Value.newBuilder().setStringValue("20:30").build())
          .build())
      .addRows(Row.newBuilder()
          .addValues(Value.newBuilder().setStringValue("55").build())
          .addValues(Value.newBuilder().setStringValue("Mark Twain").build())
          .addValues(Value.newBuilder().setStringValue("70:80").build())
          .build())
      .build();

  Table table = DeIdentifyTableBucketing.deIdentifyTableBucketing(PROJECT_ID, tableToDeIdentify);

  String output = bout.toString();
  assertThat(output).contains("Table after de-identification:");
  assertThat(table).isEqualTo(expectedTable);
}
 
Example #27
Source File: RiskAnalysisNumericalStats.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
public static void numericalStatsAnalysis(
    String projectId, String datasetId, String tableId, String topicId, String subscriptionId)
    throws ExecutionException, InterruptedException, IOException {

  // Initialize client that will be used to send requests. This client only needs to be created
  // once, and can be reused for multiple requests. After completing all of your requests, call
  // the "close" method on the client to safely clean up any remaining background resources.
  try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {

    // Specify the BigQuery table to analyze
    BigQueryTable bigQueryTable =
        BigQueryTable.newBuilder()
            .setTableId(tableId)
            .setDatasetId(datasetId)
            .setProjectId(projectId)
            .build();

    // This represents the name of the column to analyze, which must contain numerical data
    String columnName = "Age";

    // Configure the privacy metric for the job
    FieldId fieldId = FieldId.newBuilder().setName(columnName).build();
    NumericalStatsConfig numericalStatsConfig =
        NumericalStatsConfig.newBuilder().setField(fieldId).build();
    PrivacyMetric privacyMetric =
        PrivacyMetric.newBuilder().setNumericalStatsConfig(numericalStatsConfig).build();

    // Create action to publish job status notifications over Google Cloud Pub/Sub
    ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId);
    PublishToPubSub publishToPubSub =
        PublishToPubSub.newBuilder().setTopic(topicName.toString()).build();
    Action action = Action.newBuilder().setPubSub(publishToPubSub).build();

    // Configure the risk analysis job to perform
    RiskAnalysisJobConfig riskAnalysisJobConfig =
        RiskAnalysisJobConfig.newBuilder()
            .setSourceTable(bigQueryTable)
            .setPrivacyMetric(privacyMetric)
            .addActions(action)
            .build();

    CreateDlpJobRequest createDlpJobRequest =
        CreateDlpJobRequest.newBuilder()
            .setParent(LocationName.of(projectId, "global").toString())
            .setRiskJob(riskAnalysisJobConfig)
            .build();

    // Send the request to the API using the client
    DlpJob dlpJob = dlpServiceClient.createDlpJob(createDlpJobRequest);

    // Set up a Pub/Sub subscriber to listen on the job completion status
    final SettableApiFuture<Boolean> done = SettableApiFuture.create();

    ProjectSubscriptionName subscriptionName =
        ProjectSubscriptionName.of(projectId, subscriptionId);

    MessageReceiver messageHandler =
        (PubsubMessage pubsubMessage, AckReplyConsumer ackReplyConsumer) -> {
          handleMessage(dlpJob, done, pubsubMessage, ackReplyConsumer);
        };
    Subscriber subscriber = Subscriber.newBuilder(subscriptionName, messageHandler).build();
    subscriber.startAsync();

    // Wait for job completion semi-synchronously
    // For long jobs, consider using a truly asynchronous execution model such as Cloud Functions
    try {
      done.get(15, TimeUnit.MINUTES);
    } catch (TimeoutException e) {
      System.out.println("Job was not completed after 15 minutes.");
      return;
    } finally {
      subscriber.stopAsync();
      subscriber.awaitTerminated();
    }

    // Build a request to get the completed job
    GetDlpJobRequest getDlpJobRequest =
        GetDlpJobRequest.newBuilder().setName(dlpJob.getName()).build();

    // Retrieve completed job status
    DlpJob completedJob = dlpServiceClient.getDlpJob(getDlpJobRequest);
    System.out.println("Job status: " + completedJob.getState());

    // Get the result and parse through and process the information
    NumericalStatsResult result = completedJob.getRiskDetails().getNumericalStatsResult();

    System.out.printf(
        "Value range : [%.3f, %.3f]\n",
        result.getMinValue().getFloatValue(), result.getMaxValue().getFloatValue());

    int percent = 1;
    Double lastValue = null;
    for (Value quantileValue : result.getQuantileValuesList()) {
      Double currentValue = quantileValue.getFloatValue();
      if (lastValue == null || !lastValue.equals(currentValue)) {
        System.out.printf("Value at %s %% quantile : %.3f", percent, currentValue);
      }
      lastValue = currentValue;
    }
  }
}
 
Example #28
Source File: DeIdentifyWithReplacement.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
public static void deIdentifyWithReplacement(String projectId, String textToRedact) {
  // Initialize client that will be used to send requests. This client only needs to be created
  // once, and can be reused for multiple requests. After completing all of your requests, call
  // the "close" method on the client to safely clean up any remaining background resources.
  try (DlpServiceClient dlp = DlpServiceClient.create()) {
    // Specify the content to be inspected.
    ContentItem item = ContentItem.newBuilder()
        .setValue(textToRedact).build();

    // Specify the type of info the inspection will look for.
    // See https://cloud.google.com/dlp/docs/infotypes-reference for complete list of info types
    InfoType infoType = InfoType.newBuilder().setName("EMAIL_ADDRESS").build();
    InspectConfig inspectConfig = InspectConfig.newBuilder().addInfoTypes(infoType).build();
    // Specify replacement string to be used for the finding.
    ReplaceValueConfig replaceValueConfig = ReplaceValueConfig.newBuilder()
        .setNewValue(Value.newBuilder().setStringValue("[email-address]").build())
        .build();
    // Define type of deidentification as replacement.
    PrimitiveTransformation primitiveTransformation = PrimitiveTransformation.newBuilder()
        .setReplaceConfig(replaceValueConfig)
        .build();
    // Associate deidentification type with info type.
    InfoTypeTransformation transformation = InfoTypeTransformation.newBuilder()
        .addInfoTypes(infoType)
        .setPrimitiveTransformation(primitiveTransformation)
        .build();
    // Construct the configuration for the Redact request and list all desired transformations.
    DeidentifyConfig redactConfig = DeidentifyConfig.newBuilder()
        .setInfoTypeTransformations(InfoTypeTransformations.newBuilder()
            .addTransformations(transformation))
        .build();

    // Construct the Redact request to be sent by the client.
    DeidentifyContentRequest request =
        DeidentifyContentRequest.newBuilder()
            .setParent(LocationName.of(projectId, "global").toString())
            .setItem(item)
            .setDeidentifyConfig(redactConfig)
            .setInspectConfig(inspectConfig)
            .build();

    // Use the client to send the API request.
    DeidentifyContentResponse response = dlp.deidentifyContent(request);

    // Parse the response and process results
    System.out.println("Text after redaction: " + response.getItem().getValue());
  } catch (Exception e) {
    System.out.println("Error during inspectString: \n" + e.toString());
  }
}
 
Example #29
Source File: DeIdentifyTableConditionMasking.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
public static Table deIdentifyTableConditionMasking(String projectId, Table tableToDeIdentify)
    throws IOException {
  // Initialize client that will be used to send requests. This client only needs to be created
  // once, and can be reused for multiple requests. After completing all of your requests, call
  // the "close" method on the client to safely clean up any remaining background resources.
  try (DlpServiceClient dlp = DlpServiceClient.create()) {
    // Specify what content you want the service to de-identify.
    ContentItem contentItem = ContentItem.newBuilder().setTable(tableToDeIdentify).build();

    // Specify how the content should be de-identified.
    CharacterMaskConfig characterMaskConfig =
        CharacterMaskConfig.newBuilder()
            .setMaskingCharacter("*")
            .build();
    PrimitiveTransformation primitiveTransformation =
        PrimitiveTransformation.newBuilder()
            .setCharacterMaskConfig(characterMaskConfig)
            .build();

    // Specify field to be de-identified.
    FieldId fieldId = FieldId.newBuilder().setName("HAPPINESS SCORE").build();

    // Specify when the above field should be de-identified.
    Condition condition = Condition.newBuilder()
        .setField(FieldId.newBuilder().setName("AGE").build())
        .setOperator(RelationalOperator.GREATER_THAN)
        .setValue(Value.newBuilder().setIntegerValue(89).build())
        .build();
    // Apply the condition to records
    RecordCondition recordCondition = RecordCondition.newBuilder()
        .setExpressions(Expressions.newBuilder()
            .setConditions(Conditions.newBuilder()
                .addConditions(condition)
                .build())
            .build())
        .build();

    // Associate the de-identification and conditions with the specified field.
    FieldTransformation fieldTransformation =
        FieldTransformation.newBuilder()
            .setPrimitiveTransformation(primitiveTransformation)
            .addFields(fieldId)
            .setCondition(recordCondition)
            .build();
    RecordTransformations transformations =
        RecordTransformations.newBuilder().addFieldTransformations(fieldTransformation).build();

    DeidentifyConfig deidentifyConfig =
        DeidentifyConfig.newBuilder().setRecordTransformations(transformations).build();

    // Combine configurations into a request for the service.
    DeidentifyContentRequest request =
        DeidentifyContentRequest.newBuilder()
            .setParent(LocationName.of(projectId, "global").toString())
            .setItem(contentItem)
            .setDeidentifyConfig(deidentifyConfig)
            .build();

    // Send the request and receive response from the service.
    DeidentifyContentResponse response = dlp.deidentifyContent(request);

    // Print the results.
    System.out.println(
        "Table after de-identification: " + response.getItem().getTable());

    return response.getItem().getTable();
  }
}
 
Example #30
Source File: DeIdentifyTableConditionInfoTypes.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
public static Table deIdentifyTableConditionInfoTypes(String projectId, Table tableToDeIdentify)
    throws IOException {
  // Initialize client that will be used to send requests. This client only needs to be created
  // once, and can be reused for multiple requests. After completing all of your requests, call
  // the "close" method on the client to safely clean up any remaining background resources.
  try (DlpServiceClient dlp = DlpServiceClient.create()) {
    // Specify what content you want the service to de-identify.
    ContentItem contentItem = ContentItem.newBuilder().setTable(tableToDeIdentify).build();

    // Specify how the content should be de-identified.
    // Select type of info to be replaced.
    InfoType infoType = InfoType.newBuilder().setName("PERSON_NAME").build();
    // Specify that findings should be replaced with corresponding info type name.
    ReplaceWithInfoTypeConfig replaceWithInfoTypeConfig =
        ReplaceWithInfoTypeConfig.getDefaultInstance();
    PrimitiveTransformation primitiveTransformation = PrimitiveTransformation.newBuilder()
        .setReplaceWithInfoTypeConfig(replaceWithInfoTypeConfig).build();
    // Associate info type with the replacement strategy
    InfoTypeTransformation infoTypeTransformation =
        InfoTypeTransformation.newBuilder()
            .addInfoTypes(infoType)
            .setPrimitiveTransformation(primitiveTransformation)
            .build();
    InfoTypeTransformations infoTypeTransformations =
        InfoTypeTransformations.newBuilder()
            .addTransformations(infoTypeTransformation)
            .build();

    // Specify fields to be de-identified.
    List<FieldId> fieldIds = Stream.of("PATIENT", "FACTOID")
        .map(id -> FieldId.newBuilder().setName(id).build())
        .collect(Collectors.toList());

    // Specify when the above fields should be de-identified.
    Condition condition = Condition.newBuilder()
        .setField(FieldId.newBuilder().setName("AGE").build())
        .setOperator(RelationalOperator.GREATER_THAN)
        .setValue(Value.newBuilder().setIntegerValue(89).build())
        .build();
    // Apply the condition to records
    RecordCondition recordCondition = RecordCondition.newBuilder()
        .setExpressions(Expressions.newBuilder()
            .setConditions(Conditions.newBuilder()
                .addConditions(condition)
                .build())
            .build())
        .build();

    // Associate the de-identification and conditions with the specified fields.
    FieldTransformation fieldTransformation =
        FieldTransformation.newBuilder()
            .setInfoTypeTransformations(infoTypeTransformations)
            .addAllFields(fieldIds)
            .setCondition(recordCondition)
            .build();
    RecordTransformations transformations =
        RecordTransformations.newBuilder().addFieldTransformations(fieldTransformation).build();

    DeidentifyConfig deidentifyConfig =
        DeidentifyConfig.newBuilder().setRecordTransformations(transformations).build();

    // Combine configurations into a request for the service.
    DeidentifyContentRequest request =
        DeidentifyContentRequest.newBuilder()
            .setParent(LocationName.of(projectId, "global").toString())
            .setItem(contentItem)
            .setDeidentifyConfig(deidentifyConfig)
            .build();

    // Send the request and receive response from the service.
    DeidentifyContentResponse response = dlp.deidentifyContent(request);

    // Print the results.
    System.out.println(
        "Table after de-identification: " + response.getItem().getTable());

    return response.getItem().getTable();
  }
}