Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit caac326

Browse files
author
Praful Makani
authored
docs(samples): add create ad manager transfer config (#530)
1 parent 8a8e174 commit caac326

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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_admanager_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 a ad manager(formerly DFP) transfer config
32+
public class CreateAdManagerTransfer {
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 networkCode = "MY_NETWORK_CODE";
40+
Map<String, Value> params = new HashMap<>();
41+
params.put("bucket", Value.newBuilder().setStringValue(bucket).build());
42+
params.put("network_code", Value.newBuilder().setStringValue(networkCode).build());
43+
TransferConfig transferConfig =
44+
TransferConfig.newBuilder()
45+
.setDestinationDatasetId(datasetId)
46+
.setDisplayName("Your Ad Manager Config Name")
47+
.setDataSourceId("dfp_dt")
48+
.setParams(Struct.newBuilder().putAllFields(params).build())
49+
.setSchedule("every 24 hours")
50+
.build();
51+
createAdManagerTransfer(projectId, transferConfig);
52+
}
53+
54+
public static void createAdManagerTransfer(String projectId, TransferConfig transferConfig)
55+
throws IOException {
56+
try (DataTransferServiceClient client = DataTransferServiceClient.create()) {
57+
ProjectName parent = ProjectName.of(projectId);
58+
CreateTransferConfigRequest request =
59+
CreateTransferConfigRequest.newBuilder()
60+
.setParent(parent.toString())
61+
.setTransferConfig(transferConfig)
62+
.build();
63+
TransferConfig config = client.createTransferConfig(request);
64+
System.out.println("Ad manager transfer created successfully :" + config.getName());
65+
} catch (ApiException ex) {
66+
System.out.print("Ad manager transfer was not created." + ex.toString());
67+
}
68+
}
69+
}
70+
// [END bigquerydatatransfer_create_admanager_transfer]

0 commit comments

Comments
 (0)