use of com.google.privacy.dlp.v2.CreateInspectTemplateRequest in project java-docs-samples by GoogleCloudPlatform.
the class Templates method createInspectTemplate.
// [START dlp_create_inspect_template]
/**
* Create a new DLP inspection configuration template.
*
* @param displayName (Optional) The human-readable name to give the template
* @param projectId Google Cloud Project ID to call the API under
* @param templateId (Optional) The name of the template to be created
* @param infoTypeList The infoTypes of information to match
* @param minLikelihood The minimum likelihood required before returning a match
* @param maxFindings The maximum number of findings to report per request (0 = server maximum)
*/
private static void createInspectTemplate(String displayName, String templateId, String description, String projectId, List<InfoType> infoTypeList, Likelihood minLikelihood, int maxFindings) {
try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
FindingLimits findingLimits = FindingLimits.newBuilder().setMaxFindingsPerRequest(maxFindings).build();
// Construct the inspection configuration for the template
InspectConfig inspectConfig = InspectConfig.newBuilder().addAllInfoTypes(infoTypeList).setMinLikelihood(minLikelihood).setLimits(findingLimits).build();
InspectTemplate inspectTemplate = InspectTemplate.newBuilder().setInspectConfig(inspectConfig).setDisplayName(displayName).setDescription(description).build();
CreateInspectTemplateRequest createInspectTemplateRequest = CreateInspectTemplateRequest.newBuilder().setParent(ProjectName.of(projectId).toString()).setInspectTemplate(inspectTemplate).setTemplateId(templateId).build();
InspectTemplate response = dlpServiceClient.createInspectTemplate(createInspectTemplateRequest);
System.out.printf("Template created: %s", response.getName());
} catch (Exception e) {
System.out.printf("Error creating template: %s", e.getMessage());
}
}
Aggregations