|
| 1 | +/* |
| 2 | + * Copyright 2020 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 | + * https://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 | +// DO NOT EDIT! This is a generated sample ("LongRunningRequestAsync", |
| 17 | +// "job_search_batch_create_jobs") |
| 18 | +// sample-metadata: |
| 19 | +// title: |
| 20 | +// description: Batch Create Jobs |
| 21 | +// usage: gradle run -PmainClass=com.google.cloud.examples.talent.v4beta1.JobSearchBatchCreateJobs |
| 22 | +// [--args='[--project_id "Your Google Cloud Project ID"] [--tenant_id "Your Tenant ID (using |
| 23 | +// tenancy is optional)"] [--company_name_one "Company name, e.g. |
| 24 | +// projects/your-project/companies/company-id"] [--requisition_id_one "Job requisition ID, aka |
| 25 | +// Posting ID. Unique per job."] [--title_one "Software Engineer"] [--description_one "This is a |
| 26 | +// description of this <i>wonderful</i> job!"] [--job_application_url_one |
| 27 | +// "https://www.example.org/job-posting/123"] [--address_one "1600 Amphitheatre Parkway, Mountain |
| 28 | +// View, CA 94043"] [--language_code_one "en-US"] [--company_name_two "Company name, e.g. |
| 29 | +// projects/your-project/companies/company-id"] [--requisition_id_two "Job requisition ID, aka |
| 30 | +// Posting ID. Unique per job."] [--title_two "Quality Assurance"] [--description_two "This is a |
| 31 | +// description of this <i>wonderful</i> job!"] [--job_application_url_two |
| 32 | +// "https://www.example.org/job-posting/123"] [--address_two "111 8th Avenue, New York, NY 10011"] |
| 33 | +// [--language_code_two "en-US"]'] |
| 34 | + |
| 35 | +package com.google.cloud.examples.talent.v4beta1; |
| 36 | + |
| 37 | +import com.google.api.gax.longrunning.OperationFuture; |
| 38 | +import com.google.cloud.talent.v4beta1.BatchCreateJobsRequest; |
| 39 | +import com.google.cloud.talent.v4beta1.BatchOperationMetadata; |
| 40 | +import com.google.cloud.talent.v4beta1.Job; |
| 41 | +import com.google.cloud.talent.v4beta1.JobOperationResult; |
| 42 | +import com.google.cloud.talent.v4beta1.JobServiceClient; |
| 43 | +import com.google.cloud.talent.v4beta1.TenantName; |
| 44 | +import java.util.Arrays; |
| 45 | +import java.util.List; |
| 46 | +import org.apache.commons.cli.CommandLine; |
| 47 | +import org.apache.commons.cli.DefaultParser; |
| 48 | +import org.apache.commons.cli.Option; |
| 49 | +import org.apache.commons.cli.Options; |
| 50 | + |
| 51 | +public class JobSearchBatchCreateJobs { |
| 52 | + // [START job_search_batch_create_jobs] |
| 53 | + /* |
| 54 | + * Please include the following imports to run this sample. |
| 55 | + * |
| 56 | + * import com.google.api.gax.longrunning.OperationFuture; |
| 57 | + * import com.google.cloud.talent.v4beta1.BatchCreateJobsRequest; |
| 58 | + * import com.google.cloud.talent.v4beta1.BatchOperationMetadata; |
| 59 | + * import com.google.cloud.talent.v4beta1.Job; |
| 60 | + * import com.google.cloud.talent.v4beta1.Job.ApplicationInfo; |
| 61 | + * import com.google.cloud.talent.v4beta1.JobOperationResult; |
| 62 | + * import com.google.cloud.talent.v4beta1.JobServiceClient; |
| 63 | + * import com.google.cloud.talent.v4beta1.TenantName; |
| 64 | + * import java.util.Arrays; |
| 65 | + * import java.util.List; |
| 66 | + */ |
| 67 | + |
| 68 | + public static void sampleBatchCreateJobs() { |
| 69 | + // TODO(developer): Replace these variables before running the sample. |
| 70 | + String projectId = "Your Google Cloud Project ID"; |
| 71 | + String tenantId = "Your Tenant ID (using tenancy is optional)"; |
| 72 | + String companyNameOne = "Company name, e.g. projects/your-project/companies/company-id"; |
| 73 | + String requisitionIdOne = "Job requisition ID, aka Posting ID. Unique per job."; |
| 74 | + String titleOne = "Software Engineer"; |
| 75 | + String descriptionOne = "This is a description of this <i>wonderful</i> job!"; |
| 76 | + String jobApplicationUrlOne = "https://www.example.org/job-posting/123"; |
| 77 | + String addressOne = "1600 Amphitheatre Parkway, Mountain View, CA 94043"; |
| 78 | + String languageCodeOne = "en-US"; |
| 79 | + String companyNameTwo = "Company name, e.g. projects/your-project/companies/company-id"; |
| 80 | + String requisitionIdTwo = "Job requisition ID, aka Posting ID. Unique per job."; |
| 81 | + String titleTwo = "Quality Assurance"; |
| 82 | + String descriptionTwo = "This is a description of this <i>wonderful</i> job!"; |
| 83 | + String jobApplicationUrlTwo = "https://www.example.org/job-posting/123"; |
| 84 | + String addressTwo = "111 8th Avenue, New York, NY 10011"; |
| 85 | + String languageCodeTwo = "en-US"; |
| 86 | + sampleBatchCreateJobs( |
| 87 | + projectId, |
| 88 | + tenantId, |
| 89 | + companyNameOne, |
| 90 | + requisitionIdOne, |
| 91 | + titleOne, |
| 92 | + descriptionOne, |
| 93 | + jobApplicationUrlOne, |
| 94 | + addressOne, |
| 95 | + languageCodeOne, |
| 96 | + companyNameTwo, |
| 97 | + requisitionIdTwo, |
| 98 | + titleTwo, |
| 99 | + descriptionTwo, |
| 100 | + jobApplicationUrlTwo, |
| 101 | + addressTwo, |
| 102 | + languageCodeTwo); |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Batch Create Jobs |
| 107 | + * |
| 108 | + * @param projectId Your Google Cloud Project ID |
| 109 | + * @param tenantId Identifier of the Tenant |
| 110 | + */ |
| 111 | + public static void sampleBatchCreateJobs( |
| 112 | + String projectId, |
| 113 | + String tenantId, |
| 114 | + String companyNameOne, |
| 115 | + String requisitionIdOne, |
| 116 | + String titleOne, |
| 117 | + String descriptionOne, |
| 118 | + String jobApplicationUrlOne, |
| 119 | + String addressOne, |
| 120 | + String languageCodeOne, |
| 121 | + String companyNameTwo, |
| 122 | + String requisitionIdTwo, |
| 123 | + String titleTwo, |
| 124 | + String descriptionTwo, |
| 125 | + String jobApplicationUrlTwo, |
| 126 | + String addressTwo, |
| 127 | + String languageCodeTwo) { |
| 128 | + try (JobServiceClient jobServiceClient = JobServiceClient.create()) { |
| 129 | + String formattedParent = TenantName.format(projectId, tenantId); |
| 130 | + List<String> uris = Arrays.asList(jobApplicationUrlOne); |
| 131 | + Job.ApplicationInfo applicationInfo = |
| 132 | + Job.ApplicationInfo.newBuilder().addAllUris(uris).build(); |
| 133 | + List<String> addresses = Arrays.asList(addressOne); |
| 134 | + Job jobsElement = |
| 135 | + Job.newBuilder() |
| 136 | + .setCompany(companyNameOne) |
| 137 | + .setRequisitionId(requisitionIdOne) |
| 138 | + .setTitle(titleOne) |
| 139 | + .setDescription(descriptionOne) |
| 140 | + .setApplicationInfo(applicationInfo) |
| 141 | + .addAllAddresses(addresses) |
| 142 | + .setLanguageCode(languageCodeOne) |
| 143 | + .build(); |
| 144 | + List<String> uris2 = Arrays.asList(jobApplicationUrlTwo); |
| 145 | + Job.ApplicationInfo applicationInfo2 = |
| 146 | + Job.ApplicationInfo.newBuilder().addAllUris(uris2).build(); |
| 147 | + List<String> addresses2 = Arrays.asList(addressTwo); |
| 148 | + Job jobsElement2 = |
| 149 | + Job.newBuilder() |
| 150 | + .setCompany(companyNameTwo) |
| 151 | + .setRequisitionId(requisitionIdTwo) |
| 152 | + .setTitle(titleTwo) |
| 153 | + .setDescription(descriptionTwo) |
| 154 | + .setApplicationInfo(applicationInfo2) |
| 155 | + .addAllAddresses(addresses2) |
| 156 | + .setLanguageCode(languageCodeTwo) |
| 157 | + .build(); |
| 158 | + List<Job> jobs = Arrays.asList(jobsElement, jobsElement2); |
| 159 | + BatchCreateJobsRequest request = |
| 160 | + BatchCreateJobsRequest.newBuilder().setParent(formattedParent).addAllJobs(jobs).build(); |
| 161 | + OperationFuture<JobOperationResult, BatchOperationMetadata> future = |
| 162 | + jobServiceClient.batchCreateJobsAsync(request); |
| 163 | + |
| 164 | + System.out.println("Waiting for operation to complete..."); |
| 165 | + JobOperationResult response = future.get(); |
| 166 | + System.out.printf("Batch response: %s\n", response); |
| 167 | + } catch (Exception exception) { |
| 168 | + System.err.println("Failed to create the client due to: " + exception); |
| 169 | + } |
| 170 | + } |
| 171 | + // [END job_search_batch_create_jobs] |
| 172 | + |
| 173 | + public static void main(String[] args) throws Exception { |
| 174 | + Options options = new Options(); |
| 175 | + options.addOption( |
| 176 | + Option.builder("").required(false).hasArg(true).longOpt("project_id").build()); |
| 177 | + options.addOption(Option.builder("").required(false).hasArg(true).longOpt("tenant_id").build()); |
| 178 | + options.addOption( |
| 179 | + Option.builder("").required(false).hasArg(true).longOpt("company_name_one").build()); |
| 180 | + options.addOption( |
| 181 | + Option.builder("").required(false).hasArg(true).longOpt("requisition_id_one").build()); |
| 182 | + options.addOption(Option.builder("").required(false).hasArg(true).longOpt("title_one").build()); |
| 183 | + options.addOption( |
| 184 | + Option.builder("").required(false).hasArg(true).longOpt("description_one").build()); |
| 185 | + options.addOption( |
| 186 | + Option.builder("").required(false).hasArg(true).longOpt("job_application_url_one").build()); |
| 187 | + options.addOption( |
| 188 | + Option.builder("").required(false).hasArg(true).longOpt("address_one").build()); |
| 189 | + options.addOption( |
| 190 | + Option.builder("").required(false).hasArg(true).longOpt("language_code_one").build()); |
| 191 | + options.addOption( |
| 192 | + Option.builder("").required(false).hasArg(true).longOpt("company_name_two").build()); |
| 193 | + options.addOption( |
| 194 | + Option.builder("").required(false).hasArg(true).longOpt("requisition_id_two").build()); |
| 195 | + options.addOption(Option.builder("").required(false).hasArg(true).longOpt("title_two").build()); |
| 196 | + options.addOption( |
| 197 | + Option.builder("").required(false).hasArg(true).longOpt("description_two").build()); |
| 198 | + options.addOption( |
| 199 | + Option.builder("").required(false).hasArg(true).longOpt("job_application_url_two").build()); |
| 200 | + options.addOption( |
| 201 | + Option.builder("").required(false).hasArg(true).longOpt("address_two").build()); |
| 202 | + options.addOption( |
| 203 | + Option.builder("").required(false).hasArg(true).longOpt("language_code_two").build()); |
| 204 | + |
| 205 | + CommandLine cl = (new DefaultParser()).parse(options, args); |
| 206 | + String projectId = cl.getOptionValue("project_id", "Your Google Cloud Project ID"); |
| 207 | + String tenantId = cl.getOptionValue("tenant_id", "Your Tenant ID (using tenancy is optional)"); |
| 208 | + String companyNameOne = |
| 209 | + cl.getOptionValue( |
| 210 | + "company_name_one", "Company name, e.g. projects/your-project/companies/company-id"); |
| 211 | + String requisitionIdOne = |
| 212 | + cl.getOptionValue( |
| 213 | + "requisition_id_one", "Job requisition ID, aka Posting ID. Unique per job."); |
| 214 | + String titleOne = cl.getOptionValue("title_one", "Software Engineer"); |
| 215 | + String descriptionOne = |
| 216 | + cl.getOptionValue("description_one", "This is a description of this <i>wonderful</i> job!"); |
| 217 | + String jobApplicationUrlOne = |
| 218 | + cl.getOptionValue("job_application_url_one", "https://www.example.org/job-posting/123"); |
| 219 | + String addressOne = |
| 220 | + cl.getOptionValue("address_one", "1600 Amphitheatre Parkway, Mountain View, CA 94043"); |
| 221 | + String languageCodeOne = cl.getOptionValue("language_code_one", "en-US"); |
| 222 | + String companyNameTwo = |
| 223 | + cl.getOptionValue( |
| 224 | + "company_name_two", "Company name, e.g. projects/your-project/companies/company-id"); |
| 225 | + String requisitionIdTwo = |
| 226 | + cl.getOptionValue( |
| 227 | + "requisition_id_two", "Job requisition ID, aka Posting ID. Unique per job."); |
| 228 | + String titleTwo = cl.getOptionValue("title_two", "Quality Assurance"); |
| 229 | + String descriptionTwo = |
| 230 | + cl.getOptionValue("description_two", "This is a description of this <i>wonderful</i> job!"); |
| 231 | + String jobApplicationUrlTwo = |
| 232 | + cl.getOptionValue("job_application_url_two", "https://www.example.org/job-posting/123"); |
| 233 | + String addressTwo = cl.getOptionValue("address_two", "111 8th Avenue, New York, NY 10011"); |
| 234 | + String languageCodeTwo = cl.getOptionValue("language_code_two", "en-US"); |
| 235 | + |
| 236 | + sampleBatchCreateJobs( |
| 237 | + projectId, |
| 238 | + tenantId, |
| 239 | + companyNameOne, |
| 240 | + requisitionIdOne, |
| 241 | + titleOne, |
| 242 | + descriptionOne, |
| 243 | + jobApplicationUrlOne, |
| 244 | + addressOne, |
| 245 | + languageCodeOne, |
| 246 | + companyNameTwo, |
| 247 | + requisitionIdTwo, |
| 248 | + titleTwo, |
| 249 | + descriptionTwo, |
| 250 | + jobApplicationUrlTwo, |
| 251 | + addressTwo, |
| 252 | + languageCodeTwo); |
| 253 | + } |
| 254 | +} |
0 commit comments