use of com.google.api.ads.admanager.axis.v202205.ResultSet in project googleads-java-lib by googleads.
the class PqlTest method testCombineResultSet_badColumns.
@Test
public void testCombineResultSet_badColumns() {
Row row1 = new Row();
row1.getValues().addAll(Lists.newArrayList(textValue1, booleanValue1, numberValue1));
Row row2 = new Row();
row2.getValues().addAll(Lists.newArrayList(textValue2, booleanValue2, numberValue2));
Row row3 = new Row();
row3.getValues().addAll(Lists.newArrayList(textValue3, booleanValue3));
ResultSet resultSet1 = new ResultSet();
resultSet1.getColumnTypes().addAll(Lists.newArrayList(column1, column2, column3));
resultSet1.getRows().addAll(Lists.newArrayList(row1, row2));
ResultSet resultSet2 = new ResultSet();
resultSet2.getColumnTypes().addAll(Lists.newArrayList(column1, column2));
resultSet2.getRows().addAll(Lists.newArrayList(row3));
thrown.expect(IllegalArgumentException.class);
Pql.combineResultSets(resultSet1, resultSet2);
}
use of com.google.api.ads.admanager.axis.v202205.ResultSet in project googleads-java-lib by googleads.
the class PqlTest method testGetColumnLabels.
@Test
public void testGetColumnLabels() {
ResultSet resultSet = new ResultSet();
resultSet.getColumnTypes().addAll(Lists.newArrayList(column1, column2, column3));
assertEquals(Lists.newArrayList("column1", "column2", "column3"), Pql.getColumnLabels(resultSet));
}
use of com.google.api.ads.admanager.axis.v202205.ResultSet in project googleads-java-lib by googleads.
the class PqlTest method testCombineResultSet_badColumns.
@Test
public void testCombineResultSet_badColumns() {
Row row1 = new Row();
row1.getValues().addAll(Lists.newArrayList(textValue1, booleanValue1, numberValue1));
Row row2 = new Row();
row2.getValues().addAll(Lists.newArrayList(textValue2, booleanValue2, numberValue2));
Row row3 = new Row();
row3.getValues().addAll(Lists.newArrayList(textValue3, booleanValue3));
ResultSet resultSet1 = new ResultSet();
resultSet1.getColumnTypes().addAll(Lists.newArrayList(column1, column2, column3));
resultSet1.getRows().addAll(Lists.newArrayList(row1, row2));
ResultSet resultSet2 = new ResultSet();
resultSet2.getColumnTypes().addAll(Lists.newArrayList(column1, column2));
resultSet2.getRows().addAll(Lists.newArrayList(row3));
thrown.expect(IllegalArgumentException.class);
Pql.combineResultSets(resultSet1, resultSet2);
}
use of com.google.api.ads.admanager.axis.v202205.ResultSet in project googleads-java-lib by googleads.
the class Pql method combineResultSets.
/**
* Combines the first and second result sets, if and only if, the columns of both result sets
* match.
*
* @throws IllegalArgumentException if the columns of the first result set don't match the second
*/
public static ResultSet combineResultSets(ResultSet first, ResultSet second) {
Function<ColumnType, String> columnTypeToString = new Function<ColumnType, String>() {
public String apply(ColumnType input) {
return input.getLabelName();
}
};
List<String> firstColumns = Lists.transform(Lists.newArrayList(first.getColumnTypes()), columnTypeToString);
List<String> secondColumns = Lists.transform(Lists.newArrayList(second.getColumnTypes()), columnTypeToString);
if (!firstColumns.equals(secondColumns)) {
throw new IllegalArgumentException(String.format("First result set columns [%s] do not match second columns [%s]", Joiner.on(",").join(firstColumns), Joiner.on(",").join(secondColumns)));
}
List<Row> combinedRows = Lists.newArrayList(first.getRows());
if (second.getRows() != null) {
combinedRows.addAll(Lists.newArrayList(second.getRows()));
}
ResultSet combinedResultSet = new ResultSet();
combinedResultSet.getColumnTypes().addAll(first.getColumnTypes());
combinedResultSet.getRows().addAll(combinedRows);
return combinedResultSet;
}
use of com.google.api.ads.admanager.axis.v202205.ResultSet in project googleads-java-lib by googleads.
the class GetDefaultThirdPartyDataDeclaration method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
*/
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws Exception {
// Get the NetworkService.
NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
// Get the PublisherQueryLanguageService.
PublisherQueryLanguageServiceInterface pqlService = adManagerServices.get(session, PublisherQueryLanguageServiceInterface.class);
// Get the current network's default third party data declaration.
ThirdPartyDataDeclaration declaration = networkService.getDefaultThirdPartyDataDeclaration();
if (declaration == null) {
System.out.println("No default ad technology partners have been set on this network.");
} else if (DeclarationType.NONE.equals(declaration.getDeclarationType()) || declaration.getThirdPartyCompanyIds().length == 0) {
System.out.println("This network has specified that there are no ad technology providers " + " associated with its reservation creatives by default.");
} else {
System.out.printf("This network has specified %d ad technology provider(s) associated with its reservation" + " creatives by default:%n", declaration.getThirdPartyCompanyIds().length);
ResultSet companies = pqlService.select(new StatementBuilder().select("name, id").from("rich_media_ad_company").where("id in (:ids)").withBindVariableValue("ids", ImmutableSet.copyOf(Longs.asList(declaration.getThirdPartyCompanyIds()))).toStatement());
System.out.println(Pql.resultSetToString(companies));
}
}
Aggregations