use of com.google.api.ads.adwords.jaxws.v201809.cm.AdGroup in project googleads-java-lib by googleads.
the class ProductPartitionTreeImpl method getAdGroupBiddingStrategyConfiguration.
/**
* Retrieves the {@link BiddingStrategyConfiguration} of an ad group.
*
* @param services the AdWordsServices
* @param session the session to use for the request
* @param adGroupId the ad group ID
* @return the non-null BiddingStrategyConfiguration of the ad group
*/
private static BiddingStrategyConfiguration getAdGroupBiddingStrategyConfiguration(AdWordsServicesInterface services, AdWordsSession session, Long adGroupId) throws ApiException, RemoteException {
AdGroupServiceInterface adGroupService = services.get(session, AdGroupServiceInterface.class);
Selector selector = new SelectorBuilder().fields(AdGroupField.Id, AdGroupField.BiddingStrategyType, AdGroupField.BiddingStrategyId, AdGroupField.BiddingStrategyName).equalsId(adGroupId).build();
AdGroupPage adGroupPage = adGroupService.get(selector);
if (adGroupPage.getEntries() == null || adGroupPage.getEntries().length == 0) {
throw new IllegalArgumentException("No ad group found with ID " + adGroupId);
}
AdGroup adGroup = adGroupPage.getEntries(0);
Preconditions.checkState(adGroup.getBiddingStrategyConfiguration() != null, "Unexpected state - ad group ID %s has a null BiddingStrategyConfiguration", adGroupId);
return adGroup.getBiddingStrategyConfiguration();
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.AdGroup in project googleads-java-lib by googleads.
the class AddDynamicSearchAdsCampaign method runExample.
/**
* Runs the example.
*
* @param adWordsServices 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(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
Budget budget = createBudget(adWordsServices, session);
Campaign campaign = createCampaign(adWordsServices, session, budget);
AdGroup adGroup = createAdGroup(adWordsServices, session, campaign);
createExpandedDSA(adWordsServices, session, adGroup);
addWebPageCriteria(adWordsServices, session, adGroup);
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.AdGroup in project googleads-java-lib by googleads.
the class JaxWsBatchJobResponseDeserializerTest method testDeserializeBatchJobMutateResponseWithErrors.
@Test
public void testDeserializeBatchJobMutateResponseWithErrors() throws Exception {
BatchJobMutateResponse response = deserializer.deserializeBatchJobMutateResults(BatchJobMutateResponse.class, JaxWsBatchJobResponseDeserializerTest.class.getResource("resources/BatchJobMutate.responseWithErrors.xml"));
assertNotNull("Null deserialized request returned", response);
// Expect: Campaign, AdGroup, BiddableAdGroupCriterion, BiddableAdGroupCriterion,
// CriterionError, CriterionError, CriterionError
assertEquals(7, response.getMutateResults().length);
assertNotNull(response.getMutateResults()[0].getOperand().getCampaign());
assertNotNull(response.getMutateResults()[1].getOperand().getAdGroup());
assertNotNull(response.getMutateResults()[2].getOperand().getAdGroupCriterion());
assertThat(response.getMutateResults()[2].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
assertNotNull(response.getMutateResults()[3].getOperand().getAdGroupCriterion());
assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
assertThat(response.getMutateResults()[4].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
assertThat(response.getMutateResults()[5].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
assertThat(response.getMutateResults()[6].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.AdGroup in project googleads-java-lib by googleads.
the class JaxWsDeserializationTest method testDeserializeBatchJobMutateRequest.
@Test
public void testDeserializeBatchJobMutateRequest() {
Source source = new StreamSource(JaxWsDeserializationTest.class.getResourceAsStream("resources/BatchJobMutate.responseWithErrors.xml"));
BatchJobMutateResponse response = deserializer.deserialize(source);
assertNotNull("Null deserialized request returned", response);
// Expect: Campaign, AdGroup, BiddableAdGroupCriterion, BiddableAdGroupCriterion,
// CriterionError, CriterionError, CriterionError
assertEquals(7, response.getMutateResults().length);
assertNotNull(response.getMutateResults()[0].getOperand().getCampaign());
assertNotNull(response.getMutateResults()[1].getOperand().getAdGroup());
assertNotNull(response.getMutateResults()[2].getOperand().getAdGroupCriterion());
assertThat(response.getMutateResults()[2].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
assertNotNull(response.getMutateResults()[3].getOperand().getAdGroupCriterion());
assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
assertThat(response.getMutateResults()[4].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
assertThat(response.getMutateResults()[5].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
assertThat(response.getMutateResults()[6].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.AdGroup in project googleads-java-lib by googleads.
the class JaxWsDeserializationTest method testDeserializeBatchJobResponseWithoutErrors.
/**
* Tests that a response without errors will be properly deserialized.
*/
@Test
public void testDeserializeBatchJobResponseWithoutErrors() throws Exception {
Source source = new StreamSource(JaxWsDeserializationTest.class.getResourceAsStream("resources/BatchJobMutate.responseWithoutErrors.xml"));
BatchJobMutateResponse response = deserializer.deserialize(source);
assertNotNull(response);
// Expect: Campaign, AdGroup, BiddableAdGroupCriterion, BiddableAdGroupCriterion
assertEquals(4, response.getMutateResults().length);
assertNotNull(response.getMutateResults()[0].getOperand().getCampaign());
assertNotNull(response.getMutateResults()[1].getOperand().getAdGroup());
assertNotNull(response.getMutateResults()[2].getOperand().getAdGroupCriterion());
assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
assertNotNull(response.getMutateResults()[3].getOperand().getAdGroupCriterion());
assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
}
Aggregations