budget.setAmount(new Money(null, 50000000L));
budget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD);
goodCampaign.setBudget(budget);
// Create operations.
CampaignOperation operation = new CampaignOperation();
operation.setOperand(goodCampaign);
operation.setOperator(Operator.ADD);
CampaignOperation[] operations = new CampaignOperation[] {operation};
// Validate campaign add operation.
CampaignReturnValue result = campaignValidationService.mutate(operations);
// Display new campaigns, which should be none if the service was a
// validation service.
if (result != null) {
for (Campaign campaignResult : result.getValue()) {
System.out.println("New campaign with name \"" + campaignResult.getName()
+ "\" and id \"" + campaignResult.getId() + "\" was created.");
}
} else {
System.out.println("No campaigns created.");
}
// Provide an invalid bidding strategy that will cause an exception
// during validation.
Campaign badCampaign = new Campaign();
badCampaign.setName("Campaign #" + System.currentTimeMillis());
badCampaign.setStatus(CampaignStatus.PAUSED);
badCampaign.setBudget(budget);
// Throws RequiredError.REQUIRED @ operations[0].operand.biddingStrategy.
badCampaign.setBiddingStrategyConfiguration(null);
// Create operations.
operation = new CampaignOperation();
operation.setOperand(badCampaign);
operation.setOperator(Operator.ADD);
operations = new CampaignOperation[] {operation};
try {
// Validate campaign add operation.