Search in sources :

Example 1 with CreateClientEventRequest

use of com.google.cloud.talent.v4.CreateClientEventRequest 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());
    }
}
Also used : JobEvent(com.google.cloud.talent.v4.JobEvent) CreateClientEventRequest(com.google.cloud.talent.v4.CreateClientEventRequest) TenantName(com.google.cloud.talent.v4.TenantName) Timestamp(com.google.protobuf.Timestamp) EventServiceClient(com.google.cloud.talent.v4.EventServiceClient) ClientEvent(com.google.cloud.talent.v4.ClientEvent)

Example 2 with CreateClientEventRequest

use of com.google.cloud.talent.v4.CreateClientEventRequest 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());
    }
}
Also used : JobEvent(com.google.cloud.talent.v4beta1.JobEvent) CreateClientEventRequest(com.google.cloud.talent.v4beta1.CreateClientEventRequest) TenantName(com.google.cloud.talent.v4beta1.TenantName) Timestamp(com.google.protobuf.Timestamp) EventServiceClient(com.google.cloud.talent.v4beta1.EventServiceClient) ClientEvent(com.google.cloud.talent.v4beta1.ClientEvent)

Example 3 with CreateClientEventRequest

use of com.google.cloud.talent.v4.CreateClientEventRequest 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);
    }
}
Also used : JobEvent(com.google.cloud.talent.v4beta1.JobEvent) CreateClientEventRequest(com.google.cloud.talent.v4beta1.CreateClientEventRequest) TenantOrProjectName(com.google.cloud.talent.v4beta1.TenantOrProjectName) Timestamp(com.google.protobuf.Timestamp) EventServiceClient(com.google.cloud.talent.v4beta1.EventServiceClient) ClientEvent(com.google.cloud.talent.v4beta1.ClientEvent)

Example 4 with CreateClientEventRequest

use of com.google.cloud.talent.v4.CreateClientEventRequest 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());
}
Also used : JobEvent(com.google.cloud.talent.v4beta1.JobEvent) CreateClientEventRequest(com.google.cloud.talent.v4beta1.CreateClientEventRequest) Instant(org.threeten.bp.Instant) Timestamp(com.google.protobuf.Timestamp) ClientEvent(com.google.cloud.talent.v4beta1.ClientEvent) Test(org.junit.Test)

Aggregations

Timestamp (com.google.protobuf.Timestamp)4 ClientEvent (com.google.cloud.talent.v4beta1.ClientEvent)3 CreateClientEventRequest (com.google.cloud.talent.v4beta1.CreateClientEventRequest)3 JobEvent (com.google.cloud.talent.v4beta1.JobEvent)3 EventServiceClient (com.google.cloud.talent.v4beta1.EventServiceClient)2 ClientEvent (com.google.cloud.talent.v4.ClientEvent)1 CreateClientEventRequest (com.google.cloud.talent.v4.CreateClientEventRequest)1 EventServiceClient (com.google.cloud.talent.v4.EventServiceClient)1 JobEvent (com.google.cloud.talent.v4.JobEvent)1 TenantName (com.google.cloud.talent.v4.TenantName)1 TenantName (com.google.cloud.talent.v4beta1.TenantName)1 TenantOrProjectName (com.google.cloud.talent.v4beta1.TenantOrProjectName)1 Test (org.junit.Test)1 Instant (org.threeten.bp.Instant)1