public static void runExample(
AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId, Long adId)
throws Exception {
// Get the AdGroupAdService.
AdGroupAdServiceInterface adGroupAdService =
adWordsServices.get(session, AdGroupAdServiceInterface.class);
// Create ad with updated status.
Ad ad = new Ad();
ad.setId(adId);
AdGroupAd adGroupAd = new AdGroupAd();
adGroupAd.setAdGroupId(adGroupId);
adGroupAd.setAd(ad);
adGroupAd.setStatus(AdGroupAdStatus.PAUSED);
// Create operations.
AdGroupAdOperation operation = new AdGroupAdOperation();
operation.setOperand(adGroupAd);
operation.setOperator(Operator.SET);
AdGroupAdOperation[] operations = new AdGroupAdOperation[] {operation};
// Update ad.
AdGroupAdReturnValue result = adGroupAdService.mutate(operations);
// Display ads.
for (AdGroupAd adGroupAdResult : result.getValue()) {
System.out.println("Ad with id \"" + adGroupAdResult.getAd().getId() + "\", type \""
+ adGroupAdResult.getAd().getAdType() + "\", and status \"" + adGroupAdResult.getStatus()