Skip to content

Commit 86cea4d

Browse files
authored
fix: talent solution v4 samples tests (#2977)
* fix: talent solution v4 samples tests * deleted unnecessary text file * updated exp date * fixed the lint * updated code according to new checkstyle * removed setExpireDate mthd * added helpful link to job exp
1 parent db7dc84 commit 86cea4d

19 files changed

+106
-43
lines changed

jobs/v4/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</properties>
2525

2626
<prerequisites>
27-
<maven>3.5</maven>
27+
<maven>3.5.4</maven>
2828
</prerequisites>
2929

3030
<dependencyManagement>

jobs/v4/src/main/java/com/example/jobs/CommuteSearchJobs.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public static void searchJobs() throws IOException {
4242

4343
// Search Jobs with histogram queries.
4444
public static void searchJobs(String projectId, String tenantId) throws IOException {
45+
// Initialize client that will be used to send requests. This client only needs to be created
46+
// once, and can be reused for multiple requests. After completing all of your requests, call
47+
// the "close" method on the client to safely clean up any remaining background resources.
4548
try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
4649
TenantName parent = TenantName.of(projectId, tenantId);
4750
String domain = "www.example.com";
@@ -80,11 +83,11 @@ public static void searchJobs(String projectId, String tenantId) throws IOExcept
8083

8184
for (SearchJobsResponse.MatchingJob responseItem :
8285
jobServiceClient.searchJobs(request).iterateAll()) {
83-
System.out.printf("Job summary: %s\n", responseItem.getJobSummary());
84-
System.out.printf("Job title snippet: %s\n", responseItem.getJobTitleSnippet());
86+
System.out.format("Job summary: %s%n", responseItem.getJobSummary());
87+
System.out.format("Job title snippet: %s%n", responseItem.getJobTitleSnippet());
8588
Job job = responseItem.getJob();
86-
System.out.printf("Job name: %s\n", job.getName());
87-
System.out.printf("Job title: %s\n", job.getTitle());
89+
System.out.format("Job name: %s%n", job.getName());
90+
System.out.format("Job title: %s%n", job.getTitle());
8891
}
8992
}
9093
}

jobs/v4/src/main/java/com/example/jobs/CustomRankingSearchJobs.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public static void searchCustomRankingJobs() throws IOException {
3737

3838
// Search Jobs using custom rankings.
3939
public static void searchCustomRankingJobs(String projectId, String tenantId) throws IOException {
40+
// Initialize client that will be used to send requests. This client only needs to be created
41+
// once, and can be reused for multiple requests. After completing all of your requests, call
42+
// the "close" method on the client to safely clean up any remaining background resources.
4043
try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
4144
TenantName parent = TenantName.of(projectId, tenantId);
4245
String domain = "www.example.com";
@@ -66,11 +69,11 @@ public static void searchCustomRankingJobs(String projectId, String tenantId) th
6669
.build();
6770
for (SearchJobsResponse.MatchingJob responseItem :
6871
jobServiceClient.searchJobs(request).iterateAll()) {
69-
System.out.printf("Job summary: %s\n", responseItem.getJobSummary());
70-
System.out.printf("Job title snippet: %s\n", responseItem.getJobTitleSnippet());
72+
System.out.format("Job summary: %s%n", responseItem.getJobSummary());
73+
System.out.format("Job title snippet: %s%n", responseItem.getJobTitleSnippet());
7174
Job job = responseItem.getJob();
72-
System.out.printf("Job name: %s\n", job.getName());
73-
System.out.printf("Job title: %s\n", job.getTitle());
75+
System.out.format("Job name: %s%n", job.getName());
76+
System.out.format("Job title: %s%n", job.getTitle());
7477
}
7578
}
7679
}

jobs/v4/src/main/java/com/example/jobs/HistogramSearchJobs.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public static void searchJobs() throws IOException {
4040
// Search Jobs with histogram queries.
4141
public static void searchJobs(String projectId, String tenantId, String query)
4242
throws IOException {
43+
// Initialize client that will be used to send requests. This client only needs to be created
44+
// once, and can be reused for multiple requests. After completing all of your requests, call
45+
// the "close" method on the client to safely clean up any remaining background resources.
4346
try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
4447
TenantName parent = TenantName.of(projectId, tenantId);
4548

@@ -63,11 +66,11 @@ public static void searchJobs(String projectId, String tenantId, String query)
6366

6467
for (SearchJobsResponse.MatchingJob responseItem :
6568
jobServiceClient.searchJobs(request).iterateAll()) {
66-
System.out.printf("Job summary: %s\n", responseItem.getJobSummary());
67-
System.out.printf("Job title snippet: %s\n", responseItem.getJobTitleSnippet());
69+
System.out.format("Job summary: %s%n", responseItem.getJobSummary());
70+
System.out.format("Job title snippet: %s%n", responseItem.getJobTitleSnippet());
6871
Job job = responseItem.getJob();
69-
System.out.printf("Job name: %s\n", job.getName());
70-
System.out.printf("Job title: %s\n", job.getTitle());
72+
System.out.format("Job name: %s%n", job.getName());
73+
System.out.format("Job title: %s%n", job.getTitle());
7174
}
7275
}
7376
}

jobs/v4/src/main/java/com/example/jobs/JobSearchAutoCompleteJobTitle.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public static void completeQuery() throws IOException {
3737
// Complete job title given partial text (autocomplete).
3838
public static void completeQuery(String projectId, String tenantId, String query)
3939
throws IOException {
40+
// Initialize client that will be used to send requests. This client only needs to be created
41+
// once, and can be reused for multiple requests. After completing all of your requests, call
42+
// the "close" method on the client to safely clean up any remaining background resources.
4043
try (CompletionClient completionClient = CompletionClient.create()) {
4144
TenantName parent = TenantName.of(projectId, tenantId);
4245
CompleteQueryRequest request =
@@ -48,9 +51,9 @@ public static void completeQuery(String projectId, String tenantId, String query
4851
.build();
4952
CompleteQueryResponse response = completionClient.completeQuery(request);
5053
for (CompleteQueryResponse.CompletionResult result : response.getCompletionResultsList()) {
51-
System.out.printf("Suggested title: %s\n", result.getSuggestion());
54+
System.out.format("Suggested title: %s%n", result.getSuggestion());
5255
// Suggestion type is JOB_TITLE or COMPANY_TITLE
53-
System.out.printf("Suggestion type: %s\n", result.getType());
56+
System.out.format("Suggestion type: %s%n", result.getType());
5457
}
5558
}
5659
}

jobs/v4/src/main/java/com/example/jobs/JobSearchCreateClientEvent.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public static void createClientEvent() throws IOException {
4242
// Creates a client event.
4343
public static void createClientEvent(
4444
String projectId, String tenantId, String requestId, String eventId) throws IOException {
45+
// Initialize client that will be used to send requests. This client only needs to be created
46+
// once, and can be reused for multiple requests. After completing all of your requests, call
47+
// the "close" method on the client to safely clean up any remaining background resources.
4548
try (EventServiceClient eventServiceClient = EventServiceClient.create()) {
4649
TenantName parent = TenantName.of(projectId, tenantId);
4750

jobs/v4/src/main/java/com/example/jobs/JobSearchCreateCompany.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public static void createCompany() throws IOException {
3838
// Create a company.
3939
public static void createCompany(
4040
String projectId, String tenantId, String displayName, String externalId) throws IOException {
41+
// Initialize client that will be used to send requests. This client only needs to be created
42+
// once, and can be reused for multiple requests. After completing all of your requests, call
43+
// the "close" method on the client to safely clean up any remaining background resources.
4144
try (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) {
4245
TenantName parent = TenantName.of(projectId, tenantId);
4346
Company company =
@@ -51,9 +54,9 @@ public static void createCompany(
5154

5255
Company response = companyServiceClient.createCompany(request);
5356
System.out.println("Created Company");
54-
System.out.printf("Name: %s\n", response.getName());
55-
System.out.printf("Display Name: %s\n", response.getDisplayName());
56-
System.out.printf("External ID: %s\n", response.getExternalId());
57+
System.out.format("Name: %s%n", response.getName());
58+
System.out.format("Display Name: %s%n", response.getDisplayName());
59+
System.out.format("External ID: %s%n", response.getExternalId());
5760
}
5861
}
5962
}

jobs/v4/src/main/java/com/example/jobs/JobSearchCreateJob.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@
2323
import com.google.cloud.talent.v4beta1.JobServiceClient;
2424
import com.google.cloud.talent.v4beta1.TenantName;
2525
import java.io.IOException;
26+
import java.sql.Timestamp;
27+
import java.time.LocalDate;
28+
import java.time.LocalDateTime;
2629
import java.util.Arrays;
30+
import java.util.Calendar;
2731
import java.util.List;
32+
import java.util.Locale;
2833

2934
public class JobSearchCreateJob {
3035

@@ -46,14 +51,21 @@ public static void createJob(
4651
String requisitionId,
4752
String jobApplicationUrl)
4853
throws IOException {
54+
// Initialize client that will be used to send requests. This client only needs to be created
55+
// once, and can be reused for multiple requests. After completing all of your requests, call
56+
// the "close" method on the client to safely clean up any remaining background resources.
4957
try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
5058
TenantName parent = TenantName.of(projectId, tenantId);
5159
Job.ApplicationInfo applicationInfo =
5260
Job.ApplicationInfo.newBuilder().addUris(jobApplicationUrl).build();
5361

54-
List<String> addresses = Arrays.asList("1600 Amphitheatre Parkway, Mountain View, CA 94043",
62+
List<String> addresses =
63+
Arrays.asList(
64+
"1600 Amphitheatre Parkway, Mountain View, CA 94043",
5565
"111 8th Avenue, New York, NY 10011");
5666

67+
// By default, job will expire in 30 days.
68+
// https://cloud.google.com/talent-solution/job-search/docs/jobs
5769
Job job =
5870
Job.newBuilder()
5971
.setCompany(companyId)
@@ -69,7 +81,7 @@ public static void createJob(
6981
CreateJobRequest.newBuilder().setParent(parent.toString()).setJob(job).build();
7082

7183
Job response = jobServiceClient.createJob(request);
72-
System.out.printf("Created job: %s\n", response.getName());
84+
System.out.format("Created job: %s%n", response.getName());
7385
}
7486
}
7587
}

jobs/v4/src/main/java/com/example/jobs/JobSearchCreateJobCustomAttributes.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public static void createJob(
4343
String companyId,
4444
String requisitionId)
4545
throws IOException {
46+
// Initialize client that will be used to send requests. This client only needs to be created
47+
// once, and can be reused for multiple requests. After completing all of your requests, call
48+
// the "close" method on the client to safely clean up any remaining background resources.
4649
try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
4750
TenantName parent = TenantName.of(projectId, tenantId);
4851

jobs/v4/src/main/java/com/example/jobs/JobSearchCreateTenant.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public static void createTenant() throws IOException {
3535

3636
// Create Tenant for scoping resources, e.g. companies and jobs.
3737
public static void createTenant(String projectId, String externalId) 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.
3841
try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
3942
ProjectName parent = ProjectName.of(projectId);
4043
Tenant tenant = Tenant.newBuilder().setExternalId(externalId).build();
@@ -44,8 +47,8 @@ public static void createTenant(String projectId, String externalId) throws IOEx
4447

4548
Tenant response = tenantServiceClient.createTenant(request);
4649
System.out.println("Created Tenant");
47-
System.out.printf("Name: %s\n", response.getName());
48-
System.out.printf("External ID: %s\n", response.getExternalId());
50+
System.out.format("Name: %s%n", response.getName());
51+
System.out.format("External ID: %s%n", response.getExternalId());
4952
}
5053
}
5154
}

0 commit comments

Comments
 (0)