Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: talent solution v4 samples tests #2977

Merged
merged 7 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jobs/v4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</properties>

<prerequisites>
<maven>3.5</maven>
<maven>3.5.4</maven>
</prerequisites>

<dependencyManagement>
Expand Down
11 changes: 7 additions & 4 deletions jobs/v4/src/main/java/com/example/jobs/CommuteSearchJobs.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public static void searchJobs() throws IOException {

// Search Jobs with histogram queries.
public static void searchJobs(String projectId, String tenantId) 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 (JobServiceClient jobServiceClient = JobServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);
String domain = "www.example.com";
Expand Down Expand Up @@ -80,11 +83,11 @@ public static void searchJobs(String projectId, String tenantId) throws IOExcept

for (SearchJobsResponse.MatchingJob responseItem :
jobServiceClient.searchJobs(request).iterateAll()) {
System.out.printf("Job summary: %s\n", responseItem.getJobSummary());
System.out.printf("Job title snippet: %s\n", responseItem.getJobTitleSnippet());
System.out.format("Job summary: %s%n", responseItem.getJobSummary());
System.out.format("Job title snippet: %s%n", responseItem.getJobTitleSnippet());
Job job = responseItem.getJob();
System.out.printf("Job name: %s\n", job.getName());
System.out.printf("Job title: %s\n", job.getTitle());
System.out.format("Job name: %s%n", job.getName());
System.out.format("Job title: %s%n", job.getTitle());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public static void searchCustomRankingJobs() throws IOException {

// Search Jobs using custom rankings.
public static void searchCustomRankingJobs(String projectId, String tenantId) 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 (JobServiceClient jobServiceClient = JobServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);
String domain = "www.example.com";
Expand Down Expand Up @@ -66,11 +69,11 @@ public static void searchCustomRankingJobs(String projectId, String tenantId) th
.build();
for (SearchJobsResponse.MatchingJob responseItem :
jobServiceClient.searchJobs(request).iterateAll()) {
System.out.printf("Job summary: %s\n", responseItem.getJobSummary());
System.out.printf("Job title snippet: %s\n", responseItem.getJobTitleSnippet());
System.out.format("Job summary: %s%n", responseItem.getJobSummary());
System.out.format("Job title snippet: %s%n", responseItem.getJobTitleSnippet());
Job job = responseItem.getJob();
System.out.printf("Job name: %s\n", job.getName());
System.out.printf("Job title: %s\n", job.getTitle());
System.out.format("Job name: %s%n", job.getName());
System.out.format("Job title: %s%n", job.getTitle());
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions jobs/v4/src/main/java/com/example/jobs/HistogramSearchJobs.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public static void searchJobs() throws IOException {
// Search Jobs with histogram queries.
public static void searchJobs(String projectId, String tenantId, String query)
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 (JobServiceClient jobServiceClient = JobServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);

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

for (SearchJobsResponse.MatchingJob responseItem :
jobServiceClient.searchJobs(request).iterateAll()) {
System.out.printf("Job summary: %s\n", responseItem.getJobSummary());
System.out.printf("Job title snippet: %s\n", responseItem.getJobTitleSnippet());
System.out.format("Job summary: %s%n", responseItem.getJobSummary());
System.out.format("Job title snippet: %s%n", responseItem.getJobTitleSnippet());
Job job = responseItem.getJob();
System.out.printf("Job name: %s\n", job.getName());
System.out.printf("Job title: %s\n", job.getTitle());
System.out.format("Job name: %s%n", job.getName());
System.out.format("Job title: %s%n", job.getTitle());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public static void completeQuery() throws IOException {
// Complete job title given partial text (autocomplete).
public static void completeQuery(String projectId, String tenantId, String query)
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 (CompletionClient completionClient = CompletionClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);
CompleteQueryRequest request =
Expand All @@ -48,9 +51,9 @@ public static void completeQuery(String projectId, String tenantId, String query
.build();
CompleteQueryResponse response = completionClient.completeQuery(request);
for (CompleteQueryResponse.CompletionResult result : response.getCompletionResultsList()) {
System.out.printf("Suggested title: %s\n", result.getSuggestion());
System.out.format("Suggested title: %s%n", result.getSuggestion());
// Suggestion type is JOB_TITLE or COMPANY_TITLE
System.out.printf("Suggestion type: %s\n", result.getType());
System.out.format("Suggestion type: %s%n", result.getType());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public static void createClientEvent() throws IOException {
// Creates a client event.
public static void createClientEvent(
String projectId, String tenantId, String requestId, String eventId) 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 (EventServiceClient eventServiceClient = EventServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public static void createCompany() throws IOException {
// Create a company.
public static void createCompany(
String projectId, String tenantId, String displayName, String externalId) 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 (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);
Company company =
Expand All @@ -51,9 +54,9 @@ public static void createCompany(

Company response = companyServiceClient.createCompany(request);
System.out.println("Created Company");
System.out.printf("Name: %s\n", response.getName());
System.out.printf("Display Name: %s\n", response.getDisplayName());
System.out.printf("External ID: %s\n", response.getExternalId());
System.out.format("Name: %s%n", response.getName());
System.out.format("Display Name: %s%n", response.getDisplayName());
System.out.format("External ID: %s%n", response.getExternalId());
}
}
}
Expand Down
16 changes: 14 additions & 2 deletions jobs/v4/src/main/java/com/example/jobs/JobSearchCreateJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@
import com.google.cloud.talent.v4beta1.JobServiceClient;
import com.google.cloud.talent.v4beta1.TenantName;
import java.io.IOException;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;

public class JobSearchCreateJob {

Expand All @@ -46,14 +51,21 @@ public static void createJob(
String requisitionId,
String jobApplicationUrl)
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 (JobServiceClient jobServiceClient = JobServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);
Job.ApplicationInfo applicationInfo =
Job.ApplicationInfo.newBuilder().addUris(jobApplicationUrl).build();

List<String> addresses = Arrays.asList("1600 Amphitheatre Parkway, Mountain View, CA 94043",
List<String> addresses =
Arrays.asList(
"1600 Amphitheatre Parkway, Mountain View, CA 94043",
"111 8th Avenue, New York, NY 10011");

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

Job response = jobServiceClient.createJob(request);
System.out.printf("Created job: %s\n", response.getName());
System.out.format("Created job: %s%n", response.getName());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public static void createJob(
String companyId,
String requisitionId)
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 (JobServiceClient jobServiceClient = JobServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public static void createTenant() throws IOException {

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

Tenant response = tenantServiceClient.createTenant(request);
System.out.println("Created Tenant");
System.out.printf("Name: %s\n", response.getName());
System.out.printf("External ID: %s\n", response.getExternalId());
System.out.format("Name: %s%n", response.getName());
System.out.format("External ID: %s%n", response.getExternalId());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public static void deleteCompany() throws IOException {
// Delete Company.
public static void deleteCompany(String projectId, String tenantId, String companyId)
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 (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) {
CompanyName name = CompanyName.ofProjectTenantCompanyName(projectId, tenantId, companyId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public static void deleteJob() throws IOException {

// Delete Job.
public static void deleteJob(String projectId, String tenantId, String jobId) 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 (JobServiceClient jobServiceClient = JobServiceClient.create()) {
JobName name = JobName.ofProjectTenantJobName(projectId, tenantId, jobId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public static void deleteTenant() throws IOException {

// Delete Tenant.
public static void deleteTenant(String projectId, String tenantId) 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 (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
TenantName name = TenantName.of(projectId, tenantId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ public static void getCompany() throws IOException {
// Get Company.
public static void getCompany(String projectId, String tenantId, String companyId)
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 (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) {
CompanyName name = CompanyName.ofProjectTenantCompanyName(projectId, tenantId, companyId);

GetCompanyRequest request = GetCompanyRequest.newBuilder().setName(name.toString()).build();

Company response = companyServiceClient.getCompany(request);
System.out.printf("Company name: %s\n", response.getName());
System.out.printf("Display name: %s\n", response.getDisplayName());
System.out.format("Company name: %s%n", response.getName());
System.out.format("Display name: %s%n", response.getDisplayName());
}
}
}
Expand Down
19 changes: 11 additions & 8 deletions jobs/v4/src/main/java/com/example/jobs/JobSearchGetJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,28 @@ public static void getJob() throws IOException {

// Get Job.
public static void getJob(String projectId, String tenantId, String jobId) 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 (JobServiceClient jobServiceClient = JobServiceClient.create()) {
JobName name = JobName.ofProjectTenantJobName(projectId, tenantId, jobId);

GetJobRequest request = GetJobRequest.newBuilder().setName(name.toString()).build();

Job response = jobServiceClient.getJob(request);
System.out.printf("Job name: %s\n", response.getName());
System.out.printf("Requisition ID: %s\n", response.getRequisitionId());
System.out.printf("Title: %s\n", response.getTitle());
System.out.printf("Description: %s\n", response.getDescription());
System.out.printf("Posting language: %s\n", response.getLanguageCode());
System.out.format("Job name: %s%n", response.getName());
System.out.format("Requisition ID: %s%n", response.getRequisitionId());
System.out.format("Title: %s%n", response.getTitle());
System.out.format("Description: %s%n", response.getDescription());
System.out.format("Posting language: %s%n", response.getLanguageCode());
for (String address : response.getAddressesList()) {
System.out.printf("Address: %s\n", address);
System.out.format("Address: %s%n", address);
}
for (String email : response.getApplicationInfo().getEmailsList()) {
System.out.printf("Email: %s\n", email);
System.out.format("Email: %s%n", email);
}
for (String websiteUri : response.getApplicationInfo().getUrisList()) {
System.out.printf("Website: %s\n", websiteUri);
System.out.format("Website: %s%n", websiteUri);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ public static void getTenant() throws IOException {

// Get Tenant by name.
public static void getTenant(String projectId, String tenantId) 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 (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
TenantName name = TenantName.of(projectId, tenantId);

GetTenantRequest request = GetTenantRequest.newBuilder().setName(name.toString()).build();

Tenant response = tenantServiceClient.getTenant(request);
System.out.printf("Name: %s\n", response.getName());
System.out.printf("External ID: %s\n", response.getExternalId());
System.out.format("Name: %s%n", response.getName());
System.out.format("External ID: %s%n", response.getExternalId());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@ public static void listCompanies() throws IOException {

// List Companies.
public static void listCompanies(String projectId, String tenantId) 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 (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);

ListCompaniesRequest request =
ListCompaniesRequest.newBuilder().setParent(parent.toString()).build();

for (Company responseItem : companyServiceClient.listCompanies(request).iterateAll()) {
System.out.printf("Company Name: %s\n", responseItem.getName());
System.out.printf("Display Name: %s\n", responseItem.getDisplayName());
System.out.printf("External ID: %s\n", responseItem.getExternalId());
System.out.format("Company Name: %s%n", responseItem.getName());
System.out.format("Display Name: %s%n", responseItem.getDisplayName());
System.out.format("External ID: %s%n", responseItem.getExternalId());
}
}
}
Expand Down
Loading