Search in sources :

Example 1 with FeedMappingPage

use of com.google.api.ads.adwords.axis.v201809.cm.FeedMappingPage in project googleads-java-lib by googleads.

the class MigrateToExtensionSettings method getFeedMapping.

/**
 * Gets the feed mapping for a feed.
 *
 * @return a multimap from feed attribute ID to the set of field IDs mapped to the attribute
 */
private static Multimap<Long, Integer> getFeedMapping(AdWordsServicesInterface adWordsServices, AdWordsSession session, Feed feed, long placeholderType) throws RemoteException {
    // Get the FeedMappingService.
    FeedMappingServiceInterface feedMappingService = adWordsServices.get(session, FeedMappingServiceInterface.class);
    String query = String.format("SELECT FeedMappingId, AttributeFieldMappings WHERE FeedId = %d and PlaceholderType = %d " + "AND Status = 'ENABLED'", feed.getId(), placeholderType);
    Multimap<Long, Integer> attributeMappings = HashMultimap.create();
    int offset = 0;
    FeedMappingPage feedMappingPage;
    do {
        String pageQuery = String.format(query + " LIMIT %d, %d", offset, PAGE_SIZE);
        feedMappingPage = feedMappingService.query(pageQuery);
        if (feedMappingPage.getEntries() != null) {
            // than one field if needed.
            for (FeedMapping feedMapping : feedMappingPage.getEntries()) {
                for (AttributeFieldMapping attributeMapping : feedMapping.getAttributeFieldMappings()) {
                    attributeMappings.put(attributeMapping.getFeedAttributeId(), attributeMapping.getFieldId());
                }
            }
        }
        offset += PAGE_SIZE;
    } while (offset < feedMappingPage.getTotalNumEntries());
    return attributeMappings;
}
Also used : FeedMappingPage(com.google.api.ads.adwords.axis.v201809.cm.FeedMappingPage) AttributeFieldMapping(com.google.api.ads.adwords.axis.v201809.cm.AttributeFieldMapping) FeedMappingServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.FeedMappingServiceInterface) FeedMapping(com.google.api.ads.adwords.axis.v201809.cm.FeedMapping)

Aggregations

AttributeFieldMapping (com.google.api.ads.adwords.axis.v201809.cm.AttributeFieldMapping)1 FeedMapping (com.google.api.ads.adwords.axis.v201809.cm.FeedMapping)1 FeedMappingPage (com.google.api.ads.adwords.axis.v201809.cm.FeedMappingPage)1 FeedMappingServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.FeedMappingServiceInterface)1