Google Cloud Talent Solution fetch a job by requis

2019-08-24 19:28发布

问题:

I am wondering if it is possible to fetch a job by requisitionId in Google Cloud Talent Solution. requisitionId has to be unique across jobs so it seems like a natural candidate for looking a job up.

When a job is created the api returns a job name that can be used to look the job up:

You can retrieve the details of a previously inserted job by sending a GET request to the Cloud Talent Solution. The URI should include the previously inserted job name returned by the original create request, as a URL parameter.

I'd like to avoid storing these names if possible. In my view storing them adds unnecessary complexity since I already have a unique requisitionId. To be clear the API does not let you add jobs with a duplicate requisitionId:

Job projects/{my_app_id}/jobs/{google_assigned_id} already exists. Request ID for tracking: ... Related Job requisition ID: ...

So can I look up jobs by requisitionId?

I could parse the error message that's returned to get the job name..but that seems pretty brittle.

回答1:

one can add it as custom attribute:

Map<String, CustomAttribute> attributes = new HashMap<>();

attributes
    .put("requisitionId", new CustomAttribute().setStringValue(requisitionId)
    .setFilterable(true));

Job job = new Job()
    ...
    .setCustomAttributes(attributes);

Job jobCreated = createJob(job);
String jobName = jobCreated.getName();

and then search for requisitionId with a custom attribute filter:

 JobQuery jobQuery = new JobQuery().setCustomAttributeFilter(filter);

this is a little redundant, but JobQuery has no method .setRequisitionId().

here's the documentation.



回答2:

It turns out the list method takes requisitionId so for a full, read-create-update cycle we can do:

const listRequest = {
  parent: `projects/${projectId}`,
  'filter': `companyName="${companyName}" AND requisitionId="${requisitionId}"`
}
const listResult = await jobService.projects.jobs.list(listRequest)
const existingJobs = listResult.data.jobs || [];

let existingJob = null
if (existingJobs && existingJobs.length > 0) {
  existingJob = existingJobs[0]
}

let googleJob
if (!existingJob) {
  const createRequest = {
    'parent': `projects/${projectId}`,
    'resource': {
      'job': {
        companyName,
        requisitionId,
        title,
        description,
        applicationInfo: {
          emails: ['email@example.com']
        }          
      }
    }
  }
  googleJob = await jobService.projects.jobs.create(createRequest)
  .then(result => result)
  .catch(resp => {
    console.error("ERROR")
    console.error(resp)
  })
} else {
  const patchRequest = {
    'name': existingJob.name,
    'resource': {
      'job': {
        companyName,
        requisitionId,
        title,
        description,
        applicationInfo: {
          emails: ['email@example.com']
        }          
      }
    }
  }
  googleJob = await jobService.projects.jobs.patch(patchRequest)
    .then(result => result)
    .catch(resp => {
      console.error("ERROR")
      console.error(resp)
    })
}

Docs: https://cloud.google.com/talent-solution/job-search/docs/reference/rest/v3/projects.jobs/list?authuser=0&hl=de

Notes:

  • The double quotes in the filter parameter are important. It will not accept single quotes and will give a cryptic error message.
  • The patch request cannot take a parent parameter even though everything else requires a parent parameter...