use of com.google.cloud.talent.v4.TenantName in project java-docs-samples by GoogleCloudPlatform.
the class CustomRankingSearchJobs method searchCustomRankingJobs.
// Search Jobs using custom rankings.
public static void searchCustomRankingJobs(String projectId, String tenantId) throws IOException {
// 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";
String sessionId = "Hashed session identifier";
String userId = "Hashed user identifier";
RequestMetadata requestMetadata = RequestMetadata.newBuilder().setDomain(domain).setSessionId(sessionId).setUserId(userId).build();
SearchJobsRequest.CustomRankingInfo.ImportanceLevel importanceLevel = SearchJobsRequest.CustomRankingInfo.ImportanceLevel.EXTREME;
String rankingExpression = "(someFieldLong + 25) * 0.25";
SearchJobsRequest.CustomRankingInfo customRankingInfo = SearchJobsRequest.CustomRankingInfo.newBuilder().setImportanceLevel(importanceLevel).setRankingExpression(rankingExpression).build();
String orderBy = "custom_ranking desc";
SearchJobsRequest request = SearchJobsRequest.newBuilder().setParent(parent.toString()).setRequestMetadata(requestMetadata).setCustomRankingInfo(customRankingInfo).setOrderBy(orderBy).build();
for (SearchJobsResponse.MatchingJob responseItem : jobServiceClient.searchJobs(request).iterateAll()) {
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.format("Job name: %s%n", job.getName());
System.out.format("Job title: %s%n", job.getTitle());
}
}
}
use of com.google.cloud.talent.v4.TenantName in project java-docs-samples by GoogleCloudPlatform.
the class JobSearchAutoCompleteJobTitle method completeQuery.
// Complete job title given partial text (autocomplete).
public static void completeQuery(String projectId, String tenantId, String query) throws IOException {
// 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 = CompleteQueryRequest.newBuilder().setParent(parent.toString()).setQuery(query).setPageSize(// limit for number of results
5).addLanguageCodes(// language code
"en-US").build();
CompleteQueryResponse response = completionClient.completeQuery(request);
for (CompleteQueryResponse.CompletionResult result : response.getCompletionResultsList()) {
System.out.format("Suggested title: %s%n", result.getSuggestion());
// Suggestion type is JOB_TITLE or COMPANY_TITLE
System.out.format("Suggestion type: %s%n", result.getType());
}
}
}
use of com.google.cloud.talent.v4.TenantName in project java-docs-samples by GoogleCloudPlatform.
the class JobSearchCreateJobCustomAttributes method createJob.
// Create Job with Custom Attributes.
public static void createJob(String projectId, String tenantId, String companyId, String requisitionId) throws IOException {
// 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);
// Custom attribute can be string or numeric value, and can be filtered in search queries.
// https://cloud.google.com/talent-solution/job-search/docs/custom-attributes
CustomAttribute customAttribute = CustomAttribute.newBuilder().addStringValues("Internship").addStringValues("Apprenticeship").setFilterable(true).build();
Job job = Job.newBuilder().setCompany(companyId).setTitle("Software Developer I").setDescription("This is a description of this <i>wonderful</i> job!").putCustomAttributes("FOR_STUDENTS", customAttribute).setRequisitionId(requisitionId).setLanguageCode("en-US").build();
CreateJobRequest request = CreateJobRequest.newBuilder().setParent(parent.toString()).setJob(job).build();
Job response = jobServiceClient.createJob(request);
System.out.printf("Created job: %s\n", response.getName());
}
}
use of com.google.cloud.talent.v4.TenantName in project java-docs-samples by GoogleCloudPlatform.
the class JobSearchListCompanies method listCompanies.
// List Companies.
public static void listCompanies(String projectId, String tenantId) throws IOException {
// 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.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());
}
}
}
use of com.google.cloud.talent.v4.TenantName in project java-talent by googleapis.
the class JobServiceClientTest method listJobsTest.
@Test
public void listJobsTest() throws Exception {
Job responsesElement = Job.newBuilder().build();
ListJobsResponse expectedResponse = ListJobsResponse.newBuilder().setNextPageToken("").addAllJobs(Arrays.asList(responsesElement)).build();
mockJobService.addResponse(expectedResponse);
TenantName parent = TenantName.of("[PROJECT]", "[TENANT]");
String filter = "filter-1274492040";
ListJobsPagedResponse pagedListResponse = client.listJobs(parent, filter);
List<Job> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getJobsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockJobService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListJobsRequest actualRequest = ((ListJobsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(filter, actualRequest.getFilter());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations