* @throws Exception
*/
private static void updateFeedItems(AdWordsServices adWordsServices, AdWordsSession session,
Long feedId, FeedAttribute line1Attribute, FeedAttribute line2Attribute,
Map<Long, String[]> feedItemDescriptions) throws Exception {
FeedItemServiceInterface feedItemService =
adWordsServices.get(session, FeedItemServiceInterface.class);
List<String> feedItemIds = Lists.newArrayList(
Iterables.transform(feedItemDescriptions.keySet(), Functions.toStringFunction()));
Selector itemSelector = new SelectorBuilder()
.fields("FeedId", "FeedItemId", "AttributeValues")
// Limit FeedItems to the feed.
.equalsId(feedId)
// Limit FeedItems to the items in the feedItemDescriptions map.
.in("FeedItemId", feedItemIds.toArray(new String[0])).build();
FeedItem[] feedItems = feedItemService.get(itemSelector).getEntries();
List<FeedItemOperation> itemOperations = Lists.newArrayListWithCapacity(feedItems.length);
for (FeedItem feedItem : feedItems) {
// Construct a FeedItemOperation that will set the line 1 and line 2
// attribute values for this FeedItem.
FeedItemAttributeValue[] itemAttributeValues = new FeedItemAttributeValue[2];
FeedItemAttributeValue line1AttributeValue = new FeedItemAttributeValue();
line1AttributeValue.setFeedAttributeId(line1Attribute.getId());
line1AttributeValue.setStringValue(feedItemDescriptions.get(feedItem.getFeedItemId())[0]);
itemAttributeValues[0] = line1AttributeValue;
FeedItemAttributeValue line2AttributeValue = new FeedItemAttributeValue();
line2AttributeValue.setFeedAttributeId(line2Attribute.getId());
line2AttributeValue.setStringValue(feedItemDescriptions.get(feedItem.getFeedItemId())[1]);
itemAttributeValues[1] = line2AttributeValue;
feedItem.setAttributeValues(itemAttributeValues);
FeedItemOperation operation = new FeedItemOperation();
operation.setOperator(Operator.SET);
operation.setOperand(feedItem);
itemOperations.add(operation);
}
FeedItemReturnValue itemsUpdateReturnValue =
feedItemService.mutate(itemOperations.toArray(new FeedItemOperation[0]));
System.out.printf("Updated %d items%n", itemsUpdateReturnValue.getValue().length);
}