Java源码示例:com.google.api.ads.adwords.jaxws.v201809.mcm.ManagedCustomerPage

示例1
@Before
public void setUp() throws ApiException {
  managedCustomer = new ManagedCustomer();
  managedCustomer.setCustomerId(123L);
  managedCustomer.setCanManageClients(false);
  ManagedCustomerPage managedCustomerPage 
    = new ManagedCustomerPage();
  managedCustomerPage.getEntries().add(managedCustomer);
  managedCustomerPage.setTotalNumEntries(1);

  MockitoAnnotations.initMocks(this);

  when(managedCustomerServiceInterfaceMock.get(
      Mockito.<Selector>anyObject())).thenReturn(managedCustomerPage);
      
  managedCustomerDelegate = new ManagedCustomerDelegate(null, false) {
    @Override
    ManagedCustomerServiceInterface getManagedCustomerServiceInterface(
        AdWordsSession adWordsSession){
      return managedCustomerServiceInterfaceMock;
    }
  };
}
 
示例2
/**
 * Gets all the client customer IDs for the {@link AdWordsSession}.
 *
 * <p>The accounts are read in complete, and after all accounts have been retrieved, their IDs
 * are extracted and returned in a {@code Set}.
 *
 * @return the {@link Set} with the IDs of the found accounts
 * @throws ApiException error from the API when retrieving the accounts
 */
public Set<Long> getClientCustomerIds() throws ApiException {
  Set<Long> clientCustomerIdsSet = new LinkedHashSet<Long>();
  ManagedCustomerPage managedCustomerPage;
  int offset = 0;

  SelectorBuilder builder = new SelectorBuilder();
  Selector selector =
      builder.fields(ManagedCustomerField.CustomerId)
          .offset(offset)
          .limit(NUMBER_OF_RESULTS)
          .equals(ManagedCustomerField.CanManageClients, String.valueOf(false))
          .build();

  do {
    LOGGER.info("Retrieving next {} accounts.", NUMBER_OF_RESULTS);

    try {
      managedCustomerPage = managedCustomerService.get(selector);
      addClientCustomerIds(managedCustomerPage, clientCustomerIdsSet);
    } catch (ApiException e) {
      // Retry once.
      managedCustomerPage = managedCustomerService.get(selector);
      addClientCustomerIds(managedCustomerPage, clientCustomerIdsSet);
    }

    LOGGER.info("{} accounts retrieved.", clientCustomerIdsSet.size());
    offset += NUMBER_OF_RESULTS;
    selector = builder.increaseOffsetBy(NUMBER_OF_RESULTS).build();
  } while (managedCustomerPage.getTotalNumEntries() > offset);

  return clientCustomerIdsSet;
}
 
示例3
/**
 * Add client customer IDs into the result set.
 *
 * @param managedCustomerPage the page of managed customers
 * @param clientCustomerIdsSet the result set of client customer IDs
 */
private static void addClientCustomerIds(
    @Nullable ManagedCustomerPage managedCustomerPage, Set<Long> clientCustomerIdsSet) {
  if (managedCustomerPage != null) {
    List<ManagedCustomer> managedCustomers = managedCustomerPage.getEntries();
    
    // ManagedCustomerPage.getEntries() could return null.
    if (managedCustomers != null) {
      for (ManagedCustomer managedCustomer : managedCustomers) {
        clientCustomerIdsSet.add(managedCustomer.getCustomerId());
      }
    }
  }
}
 
示例4
/**
 * Gets all the client customer IDs for the {@link AdWordsSession}.
 *
 * <p>The accounts are read in complete, and after all accounts have been retrieved, their IDs
 * are extracted and returned in a {@code Set}.
 *
 * @return the {@link Set} with the IDs of the found accounts
 * @throws ApiException error from the API when retrieving the accounts
 */
public Set<Long> getClientCustomerIds() throws ApiException {
  Set<Long> clientCustomerIdsSet = new LinkedHashSet<Long>();
  ManagedCustomerPage managedCustomerPage;
  int offset = 0;

  SelectorBuilder builder = new SelectorBuilder();
  Selector selector =
      builder.fields(ManagedCustomerField.CustomerId)
          .offset(offset)
          .limit(NUMBER_OF_RESULTS)
          .equals(ManagedCustomerField.CanManageClients, String.valueOf(false))
          .equals("ExcludeHiddenAccounts", String.valueOf(excludeHiddenAccounts))
          .build();

  do {
    LOGGER.info("Retrieving next {} accounts.", NUMBER_OF_RESULTS);

    managedCustomerPage = managedCustomerService.get(selector);
    addClientCustomerIds(managedCustomerPage, clientCustomerIdsSet);

    LOGGER.info("{} accounts retrieved.", clientCustomerIdsSet.size());
    offset += NUMBER_OF_RESULTS;
    selector = builder.increaseOffsetBy(NUMBER_OF_RESULTS).build();
  } while (managedCustomerPage.getTotalNumEntries() > offset);

  return clientCustomerIdsSet;
}
 
示例5
/**
 * Add client customer IDs into the result set.
 *
 * @param managedCustomerPage the page of managed customers
 * @param clientCustomerIdsSet the result set of client customer IDs
 */
private static void addClientCustomerIds(
    @Nullable ManagedCustomerPage managedCustomerPage, Set<Long> clientCustomerIdsSet) {
  if (managedCustomerPage != null) {
    List<ManagedCustomer> managedCustomers = managedCustomerPage.getEntries();

    // ManagedCustomerPage.getEntries() could return null.
    if (managedCustomers != null) {
      for (ManagedCustomer managedCustomer : managedCustomers) {
        clientCustomerIdsSet.add(managedCustomer.getCustomerId());
      }
    }
  }
}