in services/library/src/main/java/com/google/cloud/pso/bq_pii_classifier/services/findings/FindingsReaderStandardDlp.java [77:132]
public TablePolicyTags getFieldsToPolicyTagsMap(String dlpJobName) throws InterruptedException, NonRetryableApplicationException, IOException {
String formattedQuery = generateQuery(dlpJobName);
// Create a job ID so that we can safely retry.
Job queryJob = bqService.submitJob(formattedQuery);
TableResult result = bqService.waitAndGetJobResults(queryJob);
// Construct a mapping between field names and DLP infotypes
Map<String, PolicyTagInfo> fieldsToPolicyTagMap = new HashMap<>();
String tableSpecStr = "";
for (FieldValueList row : result.iterateAll()) {
if (row.get("field_name").isNull()) {
throw new NonRetryableApplicationException("getFieldsToPolicyTagsMap query returned rows with null field_name");
}
String column_name = row.get("field_name").getStringValue();
if (row.get("info_type").isNull()) {
throw new NonRetryableApplicationException(
String.format(
"getFieldsToPolicyTagsMap query returned rows with null info_type for column '%s'",
column_name));
}
String infoType = row.get("info_type").getStringValue();
if (row.get("policy_tag").isNull()) {
throw new NonRetryableApplicationException(
String.format(
"getFieldsToPolicyTagsMap query returned rows with null policy_tag for column '%s' of info_type '%s'. Checkout the classification taxonomy configuration and the DLP inspection template. All InfoTypes defined in the inspection template must have corresponding entries in the classification taxonomies.",
column_name, infoType));
}
String policyTag = row.get("policy_tag").getStringValue();
if (row.get("classification").isNull()) {
throw new NonRetryableApplicationException(
String.format(
"getFieldsToPolicyTagsMap query returned rows with null classification for column '%s' of info_type '%s'. Checkout the classification taxonomy configuration and the DLP inspection template. All InfoTypes defined in the inspection template must have corresponding entries in the classification taxonomies.",
column_name, infoType));
}
String classification = row.get("classification").getStringValue();
if (row.get("table_spec").isNull()) {
throw new NonRetryableApplicationException("getFieldsToPolicyTagsMap query returned rows with null table_spec");
}
tableSpecStr = row.get("table_spec").getStringValue();
fieldsToPolicyTagMap.put(column_name, new PolicyTagInfo(infoType, policyTag, classification));
}
if (fieldsToPolicyTagMap.isEmpty())
return null;
else
return new TablePolicyTags(TableSpec.fromSqlString(tableSpecStr), fieldsToPolicyTagMap);
}