|
| 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 | + * http://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 | + |
| 17 | +package com.example.bigquerydatatransfer; |
| 18 | + |
| 19 | +// [START bigquerydatatransfer_create_campaignmanager_transfer] |
| 20 | +import com.google.api.gax.rpc.ApiException; |
| 21 | +import com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest; |
| 22 | +import com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient; |
| 23 | +import com.google.cloud.bigquery.datatransfer.v1.ProjectName; |
| 24 | +import com.google.cloud.bigquery.datatransfer.v1.TransferConfig; |
| 25 | +import com.google.protobuf.Struct; |
| 26 | +import com.google.protobuf.Value; |
| 27 | +import java.io.IOException; |
| 28 | +import java.util.HashMap; |
| 29 | +import java.util.Map; |
| 30 | + |
| 31 | +// Sample to create campaign manager transfer config |
| 32 | +public class CreateCampaignmanagerTransfer { |
| 33 | + |
| 34 | + public static void main(String[] args) throws IOException { |
| 35 | + // TODO(developer): Replace these variables before running the sample. |
| 36 | + final String projectId = "MY_PROJECT_ID"; |
| 37 | + String datasetId = "MY_DATASET_ID"; |
| 38 | + String bucket = "gs://cloud-sample-data"; |
| 39 | + String networkId = "MY_DOUBLE_CLICK_ID"; |
| 40 | + String fileNamePrefix = "test_"; |
| 41 | + Map<String, Value> params = new HashMap<>(); |
| 42 | + params.put("bucket", Value.newBuilder().setStringValue(bucket).build()); |
| 43 | + params.put("network_id", Value.newBuilder().setStringValue(networkId).build()); |
| 44 | + params.put("file_name_prefix", Value.newBuilder().setStringValue(fileNamePrefix).build()); |
| 45 | + TransferConfig transferConfig = |
| 46 | + TransferConfig.newBuilder() |
| 47 | + .setDestinationDatasetId(datasetId) |
| 48 | + .setDisplayName("Your Campaignmanager Config Name") |
| 49 | + .setDataSourceId("dcm_dt") |
| 50 | + .setParams(Struct.newBuilder().putAllFields(params).build()) |
| 51 | + .setSchedule("every 24 hours") |
| 52 | + .build(); |
| 53 | + createCampaignmanagerTransfer(projectId, transferConfig); |
| 54 | + } |
| 55 | + |
| 56 | + public static void createCampaignmanagerTransfer(String projectId, TransferConfig transferConfig) |
| 57 | + throws IOException { |
| 58 | + try (DataTransferServiceClient client = DataTransferServiceClient.create()) { |
| 59 | + ProjectName parent = ProjectName.of(projectId); |
| 60 | + CreateTransferConfigRequest request = |
| 61 | + CreateTransferConfigRequest.newBuilder() |
| 62 | + .setParent(parent.toString()) |
| 63 | + .setTransferConfig(transferConfig) |
| 64 | + .build(); |
| 65 | + TransferConfig config = client.createTransferConfig(request); |
| 66 | + System.out.println("Campaignmanager transfer created successfully :" + config.getName()); |
| 67 | + } catch (ApiException ex) { |
| 68 | + System.out.print("Campaignmanager transfer was not created." + ex.toString()); |
| 69 | + } |
| 70 | + } |
| 71 | +} |
| 72 | +// [END bigquerydatatransfer_create_campaignmanager_transfer] |
0 commit comments