use of com.google.cloud.talent.v4.ClientEvent in project java-talent by googleapis.
the class JobSearchCreateClientEvent method createClientEvent.
// Creates a client event.
public static void createClientEvent(String projectId, String tenantId, String requestId, String eventId) throws IOException {
// 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);
// The timestamp of the event as seconds of UTC time since Unix epoch
// For more information on how to create google.protobuf.Timestamps
// See:
// https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto
long seconds = 3L;
Timestamp createTime = Timestamp.newBuilder().setSeconds(seconds).build();
// The type of event attributed to the behavior of the end user
JobEvent.JobEventType type = JobEvent.JobEventType.VIEW;
// List of job names associated with this event
String jobsElement = "projects/[Project ID]/tenants/[Tenant ID]/jobs/[Job ID]";
String jobsElement2 = "projects/[Project ID]/tenants/[Tenant ID]/jobs/[Job ID]";
List<String> jobs = Arrays.asList(jobsElement, jobsElement2);
JobEvent jobEvent = JobEvent.newBuilder().setType(type).addAllJobs(jobs).build();
ClientEvent clientEvent = ClientEvent.newBuilder().setRequestId(requestId).setEventId(eventId).setCreateTime(createTime).setJobEvent(jobEvent).build();
CreateClientEventRequest request = CreateClientEventRequest.newBuilder().setParent(parent.toString()).setClientEvent(clientEvent).build();
ClientEvent response = eventServiceClient.createClientEvent(request);
System.out.println("Created client event. ");
System.out.println(response.toString());
}
}
use of com.google.cloud.talent.v4.ClientEvent in project java-docs-samples by GoogleCloudPlatform.
the class JobSearchCreateClientEvent method createClientEvent.
// Creates a client event.
public static void createClientEvent(String projectId, String tenantId, String requestId, String eventId) throws IOException {
// 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);
// The timestamp of the event as seconds of UTC time since Unix epoch
// For more information on how to create google.protobuf.Timestamps
// See:
// https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto
long seconds = 3L;
Timestamp createTime = Timestamp.newBuilder().setSeconds(seconds).build();
// The type of event attributed to the behavior of the end user
JobEvent.JobEventType type = JobEvent.JobEventType.VIEW;
// List of job names associated with this event
String jobsElement = "projects/[Project ID]/tenants/[Tenant ID]/jobs/[Job ID]";
String jobsElement2 = "projects/[Project ID]/tenants/[Tenant ID]/jobs/[Job ID]";
List<String> jobs = Arrays.asList(jobsElement, jobsElement2);
JobEvent jobEvent = JobEvent.newBuilder().setType(type).addAllJobs(jobs).build();
ClientEvent clientEvent = ClientEvent.newBuilder().setRequestId(requestId).setEventId(eventId).setCreateTime(createTime).setJobEvent(jobEvent).build();
CreateClientEventRequest request = CreateClientEventRequest.newBuilder().setParent(parent.toString()).setClientEvent(clientEvent).build();
ClientEvent response = eventServiceClient.createClientEvent(request);
System.out.println("Created client event. ");
System.out.println(response.toString());
}
}
use of com.google.cloud.talent.v4.ClientEvent in project java-talent by googleapis.
the class JobSearchCreateClientEvent method sampleCreateClientEvent.
/**
* Creates a client event
*
* @param projectId Your Google Cloud Project ID
* @param tenantId Identifier of the Tenant
* @param requestId A unique ID generated in the API responses. Value should be set to the
* request_id from an API response.
* @param eventId A unique identifier, generated by the client application
*/
public static void sampleCreateClientEvent(String projectId, String tenantId, String requestId, String eventId) {
try (EventServiceClient eventServiceClient = EventServiceClient.create()) {
TenantOrProjectName parent = TenantName.of(projectId, tenantId);
// The timestamp of the event as seconds of UTC time since Unix epoch
// For more information on how to create google.protobuf.Timestamps
// See:
// https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto
long seconds = 0L;
Timestamp createTime = Timestamp.newBuilder().setSeconds(seconds).build();
// The type of event attributed to the behavior of the end user
JobEvent.JobEventType type = JobEvent.JobEventType.VIEW;
// List of job names associated with this event
String jobsElement = "projects/[Project ID]/tenants/[Tenant ID]/jobs/[Job ID]";
String jobsElement2 = "projects/[Project ID]/tenants/[Tenant ID]/jobs/[Job ID]";
List<String> jobs = Arrays.asList(jobsElement, jobsElement2);
JobEvent jobEvent = JobEvent.newBuilder().setType(type).addAllJobs(jobs).build();
ClientEvent clientEvent = ClientEvent.newBuilder().setRequestId(requestId).setEventId(eventId).setCreateTime(createTime).setJobEvent(jobEvent).build();
CreateClientEventRequest request = CreateClientEventRequest.newBuilder().setParent(parent.toString()).setClientEvent(clientEvent).build();
ClientEvent response = eventServiceClient.createClientEvent(request);
System.out.println("Created client event");
} catch (Exception exception) {
System.err.println("Failed to create the client due to: " + exception);
}
}
use of com.google.cloud.talent.v4.ClientEvent in project java-talent by googleapis.
the class ITSystemTest method createEventTest.
@Test
public void createEventTest() {
String requestId = String.valueOf(Instant.now().getEpochSecond());
String eventId = String.valueOf(Instant.now().getEpochSecond());
Instant now = Instant.now();
Timestamp createTime = Timestamp.newBuilder().setSeconds(now.getEpochSecond()).setNanos(now.getNano()).build();
JobEvent jobEvent = JobEvent.newBuilder().setType(JobEvent.JobEventType.VIEW).addAllJobs(Arrays.asList(job.getName())).build();
ClientEvent clientEvent = ClientEvent.newBuilder().setRequestId(requestId).setEventId(eventId).setCreateTime(createTime).setJobEvent(jobEvent).build();
CreateClientEventRequest request = CreateClientEventRequest.newBuilder().setParent(tenantName.toString()).setClientEvent(clientEvent).build();
ClientEvent actual = eventServiceClient.createClientEvent(request);
assertEquals(requestId, actual.getRequestId());
assertEquals(eventId, actual.getEventId());
assertEquals(createTime, actual.getCreateTime());
assertEquals(jobEvent.getType(), actual.getJobEvent().getType());
}
Aggregations