static CustomerExtensionSettingReturnValue addCustomerExtensions(AdWordsSession session, List extensions) {
AdWordsServices adWordsServices = new AdWordsServices()
CustomerExtensionSettingServiceInterface customerExtensionSettingServiceInterface =
adWordsServices.get(session, CustomerExtensionSettingServiceInterface.class);
//First, we need to separate the extensions by type
Map lstExtensions = separateExtensions(extensions as List)
CustomerExtensionSettingOperation customerSiteLinkOperation = createSiteLinkExtensionOperation(lstExtensions.lstSiteLinkExtensions)
CustomerExtensionSettingOperation customerCalloutOperation = createCalloutExtensionOperation(lstExtensions.lstCalloutExtensions)
CustomerExtensionSettingOperation customerAppOperation = createAppExtensionOperation(lstExtensions.lstAppExtensions)
// Add the extensions.
List<CustomerExtensionSettingOperation> lstAllExtensions = new ArrayList<CustomerExtensionSettingOperation>();
if (lstExtensions.lstSiteLinkExtensions){
lstAllExtensions.addAll(customerSiteLinkOperation)
}
if (lstExtensions.lstCalloutExtensions){
lstAllExtensions.addAll(customerCalloutOperation)
}
if (lstExtensions.lstAppExtensions){
lstAllExtensions.addAll(customerAppOperation)
}
// Get existing extensions: remove them and add them again
List<CustomerExtensionSettingOperation> toRemoveExtensionsList = new ArrayList<CustomerExtensionSettingOperation>();
List<CustomerExtensionSetting> existingExtensionsList = getExtensions(session, "ALL")
if(existingExtensionsList.size() > 0) {
for (CustomerExtensionSetting customerExtensionSetting in existingExtensionsList) {
CustomerExtensionSettingOperation operationRemove = new CustomerExtensionSettingOperation()
operationRemove.operand = customerExtensionSetting
operationRemove.setOperator(Operator.REMOVE)
toRemoveExtensionsList.add(operationRemove)
CustomerExtensionSettingOperation operationAdd = new CustomerExtensionSettingOperation()
operationAdd.operand = customerExtensionSetting
operationAdd.setOperator(Operator.ADD)
lstAllExtensions.add(operationAdd)
}
customerExtensionSettingServiceInterface.mutate((CustomerExtensionSettingOperation[]) (toRemoveExtensionsList.toArray()));
}
return customerExtensionSettingServiceInterface.mutate((CustomerExtensionSettingOperation[]) (lstAllExtensions.toArray()));
}