Skip to content

Commit c871b63

Browse files
shubha-rajanchingor13
authored andcommitted
samples: Fixed Checkstyle Errors for DLP Samples (#2083)
1 parent 4417dd1 commit c871b63

24 files changed

+731
-714
lines changed

dlp/snippets/snippets/src/main/java/dlp/snippets/DeIdentifyWithDateShift.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package dlp.snippets;
218

319
// [START dlp_deidentify_date_shift]

dlp/snippets/snippets/src/main/java/dlp/snippets/DeIdentifyWithFpe.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package dlp.snippets;
218

319
// [START dlp_deidentify_fpe]

dlp/snippets/snippets/src/main/java/dlp/snippets/DeIdentifyWithMasking.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package dlp.snippets;
218

319
// [START dlp_deidentify_masking]

dlp/snippets/snippets/src/main/java/dlp/snippets/InfoTypesList.java

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,44 @@
1717
package dlp.snippets;
1818

1919
// [START dlp_list_info_types]
20+
2021
import com.google.cloud.dlp.v2.DlpServiceClient;
2122
import com.google.privacy.dlp.v2.InfoTypeDescription;
2223
import com.google.privacy.dlp.v2.ListInfoTypesRequest;
2324
import com.google.privacy.dlp.v2.ListInfoTypesResponse;
24-
2525
import java.io.IOException;
26-
import java.util.List;
27-
28-
public class InfoTypesList {
29-
30-
// Lists the types of sensitive information the DLP API supports.
31-
public static void listInfoTypes() throws IOException {
32-
// Initialize client that will be used to send requests. This client only needs to be created
33-
// once, and can be reused for multiple requests. After completing all of your requests, call
34-
// the "close" method on the client to safely clean up any remaining background resources.
35-
try (DlpServiceClient dlpClient = DlpServiceClient.create()) {
36-
37-
// Construct the request to be sent by the client
38-
ListInfoTypesRequest listInfoTypesRequest = ListInfoTypesRequest.newBuilder()
39-
// Only return infoTypes supported by certain parts of the API.
40-
// Supported filters are "supported_by=INSPECT" and "supported_by=RISK_ANALYSIS"
41-
// Defaults to "supported_by=INSPECT"
42-
.setFilter("supported_by=INSPECT")
43-
// BCP-47 language code for localized infoType friendly names.
44-
// Defaults to "en_US"
45-
.setLanguageCode("en-US").build();
46-
47-
// Use the client to send the API request.
48-
ListInfoTypesResponse response = dlpClient.listInfoTypes(listInfoTypesRequest);
49-
50-
// Parse the response and process the results
51-
System.out.println("Infotypes found:");
52-
for (InfoTypeDescription infoTypeDescription : response.getInfoTypesList()) {
53-
System.out.println("Name : " + infoTypeDescription.getName());
54-
System.out.println("Display name : " + infoTypeDescription.getDisplayName());
55-
}
56-
}
26+
27+
public class InfoTypesList {
28+
29+
// Lists the types of sensitive information the DLP API supports.
30+
public static void listInfoTypes() throws IOException {
31+
// Initialize client that will be used to send requests. This client only needs to be created
32+
// once, and can be reused for multiple requests. After completing all of your requests, call
33+
// the "close" method on the client to safely clean up any remaining background resources.
34+
try (DlpServiceClient dlpClient = DlpServiceClient.create()) {
35+
36+
// Construct the request to be sent by the client
37+
ListInfoTypesRequest listInfoTypesRequest =
38+
ListInfoTypesRequest.newBuilder()
39+
// Only return infoTypes supported by certain parts of the API.
40+
// Supported filters are "supported_by=INSPECT" and "supported_by=RISK_ANALYSIS"
41+
// Defaults to "supported_by=INSPECT"
42+
.setFilter("supported_by=INSPECT")
43+
// BCP-47 language code for localized infoType friendly names.
44+
// Defaults to "en_US"
45+
.setLanguageCode("en-US")
46+
.build();
47+
48+
// Use the client to send the API request.
49+
ListInfoTypesResponse response = dlpClient.listInfoTypes(listInfoTypesRequest);
50+
51+
// Parse the response and process the results
52+
System.out.println("Infotypes found:");
53+
for (InfoTypeDescription infoTypeDescription : response.getInfoTypesList()) {
54+
System.out.println("Name : " + infoTypeDescription.getName());
55+
System.out.println("Display name : " + infoTypeDescription.getDisplayName());
56+
}
5757
}
58+
}
5859
}
5960
// [END dlp_list_info_types]

dlp/snippets/snippets/src/main/java/dlp/snippets/JobsDelete.java

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,34 @@
2121
import com.google.cloud.dlp.v2.DlpServiceClient;
2222
import com.google.privacy.dlp.v2.DeleteDlpJobRequest;
2323
import com.google.privacy.dlp.v2.DlpJobName;
24-
2524
import java.io.IOException;
2625

27-
public class JobsDelete {
28-
public static void deleteJobs() throws IOException {
29-
// TODO(developer): Replace these variables before running the sample.
30-
String projectId = "your-project-id";
31-
String jobId = "your-job-id";
32-
deleteJobs(projectId,jobId);
33-
}
34-
35-
// Deletes a DLP Job with the given jobId
36-
public static void deleteJobs(String projectId, String jobId) throws IOException {
37-
// Initialize client that will be used to send requests. This client only needs to be created
38-
// once, and can be reused for multiple requests. After completing all of your requests, call
39-
// the "close" method on the client to safely clean up any remaining background resources.
40-
try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
41-
42-
// Construct the complete job name from the projectId and jobId
43-
DlpJobName jobName = DlpJobName.of(projectId, jobId);
44-
45-
// Construct the job deletion request to be sent by the client.
46-
DeleteDlpJobRequest deleteDlpJobRequest =
47-
DeleteDlpJobRequest.newBuilder().setName(jobName.toString()).build();
48-
49-
// Send the job deletion request
50-
dlpServiceClient.deleteDlpJob(deleteDlpJobRequest);
51-
System.out.println("Job deleted successfully.");
52-
}
26+
public class JobsDelete {
27+
public static void deleteJobs() throws IOException {
28+
// TODO(developer): Replace these variables before running the sample.
29+
String projectId = "your-project-id";
30+
String jobId = "your-job-id";
31+
deleteJobs(projectId, jobId);
32+
}
33+
34+
// Deletes a DLP Job with the given jobId
35+
public static void deleteJobs(String projectId, String jobId) throws IOException {
36+
// Initialize client that will be used to send requests. This client only needs to be created
37+
// once, and can be reused for multiple requests. After completing all of your requests, call
38+
// the "close" method on the client to safely clean up any remaining background resources.
39+
try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
40+
41+
// Construct the complete job name from the projectId and jobId
42+
DlpJobName jobName = DlpJobName.of(projectId, jobId);
43+
44+
// Construct the job deletion request to be sent by the client.
45+
DeleteDlpJobRequest deleteDlpJobRequest =
46+
DeleteDlpJobRequest.newBuilder().setName(jobName.toString()).build();
47+
48+
// Send the job deletion request
49+
dlpServiceClient.deleteDlpJob(deleteDlpJobRequest);
50+
System.out.println("Job deleted successfully.");
5351
}
52+
}
5453
}
55-
// [END dlp_delete_job]
54+
// [END dlp_delete_job]

dlp/snippets/snippets/src/main/java/dlp/snippets/JobsList.java

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,42 @@
2323
import com.google.privacy.dlp.v2.DlpJobType;
2424
import com.google.privacy.dlp.v2.ListDlpJobsRequest;
2525
import com.google.privacy.dlp.v2.ProjectName;
26-
2726
import java.io.IOException;
2827

2928
public class JobsList {
3029

31-
public static void listJobs() throws IOException {
32-
// TODO(developer): Replace these variables before running the sample.
33-
String projectId = "your-project-id";
34-
listJobs(projectId);
35-
}
30+
public static void listJobs() throws IOException {
31+
// TODO(developer): Replace these variables before running the sample.
32+
String projectId = "your-project-id";
33+
listJobs(projectId);
34+
}
3635

37-
// Lists DLP jobs
38-
public static void listJobs(String projectId) throws IOException {
39-
// Initialize client that will be used to send requests. This client only needs to be created
40-
// once, and can be reused for multiple requests. After completing all of your requests, call
41-
// the "close" method on the client to safely clean up any remaining background resources.
42-
try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
36+
// Lists DLP jobs
37+
public static void listJobs(String projectId) throws IOException {
38+
// Initialize client that will be used to send requests. This client only needs to be created
39+
// once, and can be reused for multiple requests. After completing all of your requests, call
40+
// the "close" method on the client to safely clean up any remaining background resources.
41+
try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
4342

44-
// Construct the request to be sent by the client.
45-
// For more info on filters and job types,
46-
// see https://cloud.google.com/dlp/docs/reference/rest/v2/projects.dlpJobs/list
47-
ListDlpJobsRequest listDlpJobsRequest =
48-
ListDlpJobsRequest.newBuilder()
49-
.setParent(ProjectName.of(projectId).toString())
50-
.setFilter("state=DONE")
51-
.setType(DlpJobType.valueOf("INSPECT_JOB"))
52-
.build();
43+
// Construct the request to be sent by the client.
44+
// For more info on filters and job types,
45+
// see https://cloud.google.com/dlp/docs/reference/rest/v2/projects.dlpJobs/list
46+
ListDlpJobsRequest listDlpJobsRequest =
47+
ListDlpJobsRequest.newBuilder()
48+
.setParent(ProjectName.of(projectId).toString())
49+
.setFilter("state=DONE")
50+
.setType(DlpJobType.valueOf("INSPECT_JOB"))
51+
.build();
5352

54-
// Send the request to list jobs and process the response
55-
DlpServiceClient.ListDlpJobsPagedResponse response =
56-
dlpServiceClient.listDlpJobs(listDlpJobsRequest);
53+
// Send the request to list jobs and process the response
54+
DlpServiceClient.ListDlpJobsPagedResponse response =
55+
dlpServiceClient.listDlpJobs(listDlpJobsRequest);
5756

58-
System.out.println("DLP jobs found:");
59-
for (DlpJob dlpJob : response.getPage().getValues()) {
60-
System.out.println(dlpJob.getName() + " -- " + dlpJob.getState());
61-
}
62-
}
57+
System.out.println("DLP jobs found:");
58+
for (DlpJob dlpJob : response.getPage().getValues()) {
59+
System.out.println(dlpJob.getName() + " -- " + dlpJob.getState());
60+
}
6361
}
62+
}
6463
}
65-
// [END dlp_list_jobs]
64+
// [END dlp_list_jobs]

dlp/snippets/snippets/src/main/java/dlp/snippets/ReIdentifyWithFpe.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package dlp.snippets;
218

319
// [START dlp_reidentify_fpe]

dlp/snippets/snippets/src/main/java/dlp/snippets/RiskAnalysisKMap.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ public static void calculateKMap(
193193
}
194194
}
195195
}
196+
196197
// handleMessage injects the job and settableFuture into the message reciever interface
197198
private static void handleMessage(
198199
DlpJob job,

dlp/snippets/snippets/src/main/java/dlp/snippets/RiskAnalysisLDiversity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ public static void calculateLDiversity(
173173
}
174174
}
175175
}
176+
176177
// handleMessage injects the job and settableFuture into the message reciever interface
177178
private static void handleMessage(
178179
DlpJob job,

dlp/snippets/snippets/src/main/java/dlp/snippets/RiskAnalysisNumericalStats.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ public static void numericalStatsAnalysis(
152152
}
153153
}
154154
}
155+
155156
// handleMessage injects the job and settableFuture into the message reciever interface
156157
private static void handleMessage(
157158
DlpJob job,

0 commit comments

Comments
 (0)