Examples of MutateJobServiceInterface


Examples of com.google.api.ads.adwords.axis.v201306.cm.MutateJobServiceInterface

  }

  public static void runExample(
      AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId) throws Exception {
    // Get the MutateJobService.
    MutateJobServiceInterface mutateJobService =
        adWordsServices.get(session, MutateJobServiceInterface.class);

    Random r = new Random();
    List<AdGroupCriterionOperation> operations = new ArrayList<AdGroupCriterionOperation>();

    // Create AdGroupCriterionOperations to add keywords.
    for (int i = 0; i < KEYWORD_NUMBER; i++) {
      // Create Keyword.
      String text = String.format("mars%d", i);

      // Make 10% of keywords invalid to demonstrate error handling.
      if (r.nextInt() % 10 == 0) {
        text = text + "!!!";
      }
      Keyword keyword = new Keyword();
      keyword.setText(text);
      keyword.setMatchType(KeywordMatchType.BROAD);

      // Create BiddableAdGroupCriterion.
      BiddableAdGroupCriterion bagc = new BiddableAdGroupCriterion();
      bagc.setAdGroupId(adGroupId);
      bagc.setCriterion(keyword);

      // Create AdGroupCriterionOperation.
      AdGroupCriterionOperation agco = new AdGroupCriterionOperation();
      agco.setOperand(bagc);
      agco.setOperator(Operator.ADD);

      // Add to list.
      operations.add(agco);
    }

    // You can specify up to 3 job IDs that must successfully complete before
    // this job can be processed.
    BulkMutateJobPolicy policy = new BulkMutateJobPolicy();
    policy.setPrerequisiteJobIds(new long[] {});

    // Call mutate to create a new job.
    SimpleMutateJob response =
        mutateJobService.mutate(operations.toArray(new Operation[operations.size()]), policy);

    long jobId = response.getId();
    System.out.printf("Job with ID %d was successfully created.\n", jobId);

    // Create selector to retrieve job status and wait for it to complete.
    BulkMutateJobSelector selector = new BulkMutateJobSelector();
    selector.setJobIds(new long[] {jobId});

    // Poll for job status until it's finished.
    System.out.println("Retrieving job status...");
    SimpleMutateJob jobStatusResponse = null;
    BasicJobStatus status = null;
    for (int i = 0; i < RETRIES_COUNT; i++) {
      Job[] jobs = mutateJobService.get(selector);
      jobStatusResponse = (SimpleMutateJob) jobs[0];
      status = jobStatusResponse.getStatus();
      if (status == BasicJobStatus.COMPLETED || status == BasicJobStatus.FAILED) {
        break;
      }
      System.out.printf("[%d] Current status is '%s', waiting %d seconds to retry...\n", i,
          status.toString(), RETRY_INTERVAL);
      Thread.sleep(RETRY_INTERVAL * 1000);
    }

    // Handle unsuccessful results.
    if (status == BasicJobStatus.FAILED) {
      throw new IllegalStateException("Job failed with reason: "
          + jobStatusResponse.getFailureReason());
    }
    if (status == BasicJobStatus.PENDING || status == BasicJobStatus.PROCESSING) {
      throw new IllegalAccessException("Job did not complete within "
          + ((RETRIES_COUNT - 1) * RETRY_INTERVAL) + " seconds.");
    }

    // Status must be COMPLETED.
    // Get the job result. Here we re-use the same selector.
    JobResult result = mutateJobService.getResult(selector);

    // Output results.
    int i = 0;
    for (Operand operand : result.getSimpleMutateResult().getResults()) {
      String outcome = operand.getPlaceHolder() == null ? "SUCCESS" : "FAILED";
View Full Code Here

Examples of com.google.api.ads.adwords.axis.v201306.cm.MutateJobServiceInterface

  }

  public static void runExample(
      AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId) throws Exception {
    // Get the MutateJobService.
    MutateJobServiceInterface mutateJobService =
        adWordsServices.get(session, MutateJobServiceInterface.class);

    Random r = new Random();
    List<AdGroupCriterionOperation> operations = new ArrayList<AdGroupCriterionOperation>();

    // Create AdGroupCriterionOperations to add placements.
    for (int i = 0; i < PLACEMENT_NUMBER; i++) {
      // Create Placement.
      String url = String.format("example.com/mars%d", i);

      // Make 10% of placements invalid to demonstrate error handling.
      if (r.nextInt() % 10 == 0) {
        url = "NO_@_URL";
      }
      Placement placement = new Placement();
      placement.setUrl(url);

      // Create BiddableAdGroupCriterion.
      BiddableAdGroupCriterion bagc = new BiddableAdGroupCriterion();
      bagc.setAdGroupId(adGroupId);
      bagc.setCriterion(placement);

      // Create AdGroupCriterionOperation.
      AdGroupCriterionOperation agco = new AdGroupCriterionOperation();
      agco.setOperand(bagc);
      agco.setOperator(Operator.ADD);

      // Add to list.
      operations.add(agco);
    }

    // You can specify up to 3 job IDs that must successfully complete before
    // this job can be processed.
    BulkMutateJobPolicy policy = new BulkMutateJobPolicy();
    policy.setPrerequisiteJobIds(new long[] {});

    // Call mutate to create a new job.
    SimpleMutateJob response =
        mutateJobService.mutate(operations.toArray(new Operation[operations.size()]), policy);

    long jobId = response.getId();
    System.out.printf("Job with ID %d was successfully created.\n", jobId);

    // Create selector to retrieve job status and wait for it to complete.
    BulkMutateJobSelector selector = new BulkMutateJobSelector();
    selector.setJobIds(new long[] {jobId});

    // Poll for job status until it's finished.
    System.out.println("Retrieving job status...");
    SimpleMutateJob jobStatusResponse = null;
    BasicJobStatus status = null;
    for (int i = 0; i < RETRIES_COUNT; i++) {
      Job[] jobs = mutateJobService.get(selector);
      jobStatusResponse = (SimpleMutateJob) jobs[0];
      status = jobStatusResponse.getStatus();
      if (status == BasicJobStatus.COMPLETED || status == BasicJobStatus.FAILED) {
        break;
      }
      System.out.printf("[%d] Current status is '%s', waiting %d seconds to retry...\n", i,
          status.toString(), RETRY_INTERVAL);
      Thread.sleep(RETRY_INTERVAL * 1000);
    }

    // Handle unsuccessful results.
    if (status == BasicJobStatus.FAILED) {
      throw new IllegalStateException("Job failed with reason: "
          + jobStatusResponse.getFailureReason());
    }
    if (status == BasicJobStatus.PENDING || status == BasicJobStatus.PROCESSING) {
      throw new IllegalAccessException("Job did not complete within "
          + ((RETRIES_COUNT - 1) * RETRY_INTERVAL) + " seconds.");
    }

    // Status must be COMPLETED.
    // Get the job result. Here we re-use the same selector.
    JobResult result = mutateJobService.getResult(selector);

    // Output results.
    int i = 0;
    for (Operand operand : result.getSimpleMutateResult().getResults()) {
      String outcome = operand.getPlaceHolder() == null ? "SUCCESS" : "FAILED";
View Full Code Here

Examples of com.google.api.ads.adwords.axis.v201309.cm.MutateJobServiceInterface

  }

  public static void runExample(
      AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId) throws Exception {
    // Get the MutateJobService.
    MutateJobServiceInterface mutateJobService =
        adWordsServices.get(session, MutateJobServiceInterface.class);

    Random r = new Random();
    List<AdGroupCriterionOperation> operations = new ArrayList<AdGroupCriterionOperation>();

    // Create AdGroupCriterionOperations to add keywords.
    for (int i = 0; i < KEYWORD_NUMBER; i++) {
      // Create Keyword.
      String text = String.format("mars%d", i);

      // Make 10% of keywords invalid to demonstrate error handling.
      if (r.nextInt() % 10 == 0) {
        text = text + "!!!";
      }
      Keyword keyword = new Keyword();
      keyword.setText(text);
      keyword.setMatchType(KeywordMatchType.BROAD);

      // Create BiddableAdGroupCriterion.
      BiddableAdGroupCriterion bagc = new BiddableAdGroupCriterion();
      bagc.setAdGroupId(adGroupId);
      bagc.setCriterion(keyword);

      // Create AdGroupCriterionOperation.
      AdGroupCriterionOperation agco = new AdGroupCriterionOperation();
      agco.setOperand(bagc);
      agco.setOperator(Operator.ADD);

      // Add to list.
      operations.add(agco);
    }

    // You can specify up to 3 job IDs that must successfully complete before
    // this job can be processed.
    BulkMutateJobPolicy policy = new BulkMutateJobPolicy();
    policy.setPrerequisiteJobIds(new long[] {});

    // Call mutate to create a new job.
    SimpleMutateJob response =
        mutateJobService.mutate(operations.toArray(new Operation[operations.size()]), policy);

    long jobId = response.getId();
    System.out.printf("Job with ID %d was successfully created.\n", jobId);

    // Create selector to retrieve job status and wait for it to complete.
    BulkMutateJobSelector selector = new BulkMutateJobSelector();
    selector.setJobIds(new long[] {jobId});

    // Poll for job status until it's finished.
    System.out.println("Retrieving job status...");
    SimpleMutateJob jobStatusResponse = null;
    BasicJobStatus status = null;
    for (int i = 0; i < RETRIES_COUNT; i++) {
      Job[] jobs = mutateJobService.get(selector);
      jobStatusResponse = (SimpleMutateJob) jobs[0];
      status = jobStatusResponse.getStatus();
      if (status == BasicJobStatus.COMPLETED || status == BasicJobStatus.FAILED) {
        break;
      }
      System.out.printf("[%d] Current status is '%s', waiting %d seconds to retry...\n", i,
          status.toString(), RETRY_INTERVAL);
      Thread.sleep(RETRY_INTERVAL * 1000);
    }

    // Handle unsuccessful results.
    if (status == BasicJobStatus.FAILED) {
      throw new IllegalStateException("Job failed with reason: "
          + jobStatusResponse.getFailureReason());
    }
    if (status == BasicJobStatus.PENDING || status == BasicJobStatus.PROCESSING) {
      throw new IllegalAccessException("Job did not complete within "
          + ((RETRIES_COUNT - 1) * RETRY_INTERVAL) + " seconds.");
    }

    // Status must be COMPLETED.
    // Get the job result. Here we re-use the same selector.
    JobResult result = mutateJobService.getResult(selector);

    // Output results.
    int i = 0;
    for (Operand operand : result.getSimpleMutateResult().getResults()) {
      String outcome = operand.getPlaceHolder() == null ? "SUCCESS" : "FAILED";
View Full Code Here

Examples of com.google.api.ads.adwords.axis.v201309.cm.MutateJobServiceInterface

  }

  public static void runExample(
      AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId) throws Exception {
    // Get the MutateJobService.
    MutateJobServiceInterface mutateJobService =
        adWordsServices.get(session, MutateJobServiceInterface.class);

    Random r = new Random();
    List<AdGroupCriterionOperation> operations = new ArrayList<AdGroupCriterionOperation>();

    // Create AdGroupCriterionOperations to add placements.
    for (int i = 0; i < PLACEMENT_NUMBER; i++) {
      // Create Placement.
      String url = String.format("example.com/mars%d", i);

      // Make 10% of placements invalid to demonstrate error handling.
      if (r.nextInt() % 10 == 0) {
        url = "NO_@_URL";
      }
      Placement placement = new Placement();
      placement.setUrl(url);

      // Create BiddableAdGroupCriterion.
      BiddableAdGroupCriterion bagc = new BiddableAdGroupCriterion();
      bagc.setAdGroupId(adGroupId);
      bagc.setCriterion(placement);

      // Create AdGroupCriterionOperation.
      AdGroupCriterionOperation agco = new AdGroupCriterionOperation();
      agco.setOperand(bagc);
      agco.setOperator(Operator.ADD);

      // Add to list.
      operations.add(agco);
    }

    // You can specify up to 3 job IDs that must successfully complete before
    // this job can be processed.
    BulkMutateJobPolicy policy = new BulkMutateJobPolicy();
    policy.setPrerequisiteJobIds(new long[] {});

    // Call mutate to create a new job.
    SimpleMutateJob response =
        mutateJobService.mutate(operations.toArray(new Operation[operations.size()]), policy);

    long jobId = response.getId();
    System.out.printf("Job with ID %d was successfully created.\n", jobId);

    // Create selector to retrieve job status and wait for it to complete.
    BulkMutateJobSelector selector = new BulkMutateJobSelector();
    selector.setJobIds(new long[] {jobId});

    // Poll for job status until it's finished.
    System.out.println("Retrieving job status...");
    SimpleMutateJob jobStatusResponse = null;
    BasicJobStatus status = null;
    for (int i = 0; i < RETRIES_COUNT; i++) {
      Job[] jobs = mutateJobService.get(selector);
      jobStatusResponse = (SimpleMutateJob) jobs[0];
      status = jobStatusResponse.getStatus();
      if (status == BasicJobStatus.COMPLETED || status == BasicJobStatus.FAILED) {
        break;
      }
      System.out.printf("[%d] Current status is '%s', waiting %d seconds to retry...\n", i,
          status.toString(), RETRY_INTERVAL);
      Thread.sleep(RETRY_INTERVAL * 1000);
    }

    // Handle unsuccessful results.
    if (status == BasicJobStatus.FAILED) {
      throw new IllegalStateException("Job failed with reason: "
          + jobStatusResponse.getFailureReason());
    }
    if (status == BasicJobStatus.PENDING || status == BasicJobStatus.PROCESSING) {
      throw new IllegalAccessException("Job did not complete within "
          + ((RETRIES_COUNT - 1) * RETRY_INTERVAL) + " seconds.");
    }

    // Status must be COMPLETED.
    // Get the job result. Here we re-use the same selector.
    JobResult result = mutateJobService.getResult(selector);

    // Output results.
    int i = 0;
    for (Operand operand : result.getSimpleMutateResult().getResults()) {
      String outcome = operand.getPlaceHolder() == null ? "SUCCESS" : "FAILED";
View Full Code Here

Examples of com.google.api.ads.adwords.axis.v201402.cm.MutateJobServiceInterface

  }

  public static void runExample(
      AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId) throws Exception {
    // Get the MutateJobService.
    MutateJobServiceInterface mutateJobService =
        adWordsServices.get(session, MutateJobServiceInterface.class);

    Random r = new Random();
    List<AdGroupCriterionOperation> operations = new ArrayList<AdGroupCriterionOperation>();

    // Create AdGroupCriterionOperations to add keywords.
    for (int i = 0; i < KEYWORD_NUMBER; i++) {
      // Create Keyword.
      String text = String.format("mars%d", i);

      // Make 10% of keywords invalid to demonstrate error handling.
      if (r.nextInt() % 10 == 0) {
        text = text + "!!!";
      }
      Keyword keyword = new Keyword();
      keyword.setText(text);
      keyword.setMatchType(KeywordMatchType.BROAD);

      // Create BiddableAdGroupCriterion.
      BiddableAdGroupCriterion bagc = new BiddableAdGroupCriterion();
      bagc.setAdGroupId(adGroupId);
      bagc.setCriterion(keyword);

      // Create AdGroupCriterionOperation.
      AdGroupCriterionOperation agco = new AdGroupCriterionOperation();
      agco.setOperand(bagc);
      agco.setOperator(Operator.ADD);

      // Add to list.
      operations.add(agco);
    }

    // You can specify up to 3 job IDs that must successfully complete before
    // this job can be processed.
    BulkMutateJobPolicy policy = new BulkMutateJobPolicy();
    policy.setPrerequisiteJobIds(new long[] {});

    // Call mutate to create a new job.
    SimpleMutateJob response =
        mutateJobService.mutate(operations.toArray(new Operation[operations.size()]), policy);

    long jobId = response.getId();
    System.out.printf("Job with ID %d was successfully created.\n", jobId);

    // Create selector to retrieve job status and wait for it to complete.
    BulkMutateJobSelector selector = new BulkMutateJobSelector();
    selector.setJobIds(new long[] {jobId});

    // Poll for job status until it's finished.
    System.out.println("Retrieving job status...");
    SimpleMutateJob jobStatusResponse = null;
    BasicJobStatus status = null;
    for (int i = 0; i < RETRIES_COUNT; i++) {
      Job[] jobs = mutateJobService.get(selector);
      jobStatusResponse = (SimpleMutateJob) jobs[0];
      status = jobStatusResponse.getStatus();
      if (status == BasicJobStatus.COMPLETED || status == BasicJobStatus.FAILED) {
        break;
      }
      System.out.printf("[%d] Current status is '%s', waiting %d seconds to retry...\n", i,
          status.toString(), RETRY_INTERVAL);
      Thread.sleep(RETRY_INTERVAL * 1000);
    }

    // Handle unsuccessful results.
    if (status == BasicJobStatus.FAILED) {
      throw new IllegalStateException("Job failed with reason: "
          + jobStatusResponse.getFailureReason());
    }
    if (status == BasicJobStatus.PENDING || status == BasicJobStatus.PROCESSING) {
      throw new IllegalAccessException("Job did not complete within "
          + ((RETRIES_COUNT - 1) * RETRY_INTERVAL) + " seconds.");
    }

    // Status must be COMPLETED.
    // Get the job result. Here we re-use the same selector.
    JobResult result = mutateJobService.getResult(selector);

    // Output results.
    int i = 0;
    for (Operand operand : result.getSimpleMutateResult().getResults()) {
      String outcome = operand.getPlaceHolder() == null ? "SUCCESS" : "FAILED";
View Full Code Here

Examples of com.google.api.ads.adwords.axis.v201406.cm.MutateJobServiceInterface

  }

  public static void runExample(
      AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId) throws Exception {
    // Get the MutateJobService.
    MutateJobServiceInterface mutateJobService =
        adWordsServices.get(session, MutateJobServiceInterface.class);

    Random r = new Random();
    List<AdGroupCriterionOperation> operations = new ArrayList<AdGroupCriterionOperation>();

    // Create AdGroupCriterionOperations to add keywords.
    for (int i = 0; i < KEYWORD_NUMBER; i++) {
      // Create Keyword.
      String text = String.format("mars%d", i);

      // Make 10% of keywords invalid to demonstrate error handling.
      if (r.nextInt() % 10 == 0) {
        text = text + "!!!";
      }
      Keyword keyword = new Keyword();
      keyword.setText(text);
      keyword.setMatchType(KeywordMatchType.BROAD);

      // Create BiddableAdGroupCriterion.
      BiddableAdGroupCriterion bagc = new BiddableAdGroupCriterion();
      bagc.setAdGroupId(adGroupId);
      bagc.setCriterion(keyword);

      // Create AdGroupCriterionOperation.
      AdGroupCriterionOperation agco = new AdGroupCriterionOperation();
      agco.setOperand(bagc);
      agco.setOperator(Operator.ADD);

      // Add to list.
      operations.add(agco);
    }

    // You can specify up to 3 job IDs that must successfully complete before
    // this job can be processed.
    BulkMutateJobPolicy policy = new BulkMutateJobPolicy();
    policy.setPrerequisiteJobIds(new long[] {});

    // Call mutate to create a new job.
    SimpleMutateJob response =
        mutateJobService.mutate(operations.toArray(new Operation[operations.size()]), policy);

    long jobId = response.getId();
    System.out.printf("Job with ID %d was successfully created.\n", jobId);

    // Create selector to retrieve job status and wait for it to complete.
    BulkMutateJobSelector selector = new BulkMutateJobSelector();
    selector.setJobIds(new long[] {jobId});

    // Poll for job status until it's finished.
    System.out.println("Retrieving job status...");
    SimpleMutateJob jobStatusResponse = null;
    BasicJobStatus status = null;
    for (int i = 0; i < RETRIES_COUNT; i++) {
      Job[] jobs = mutateJobService.get(selector);
      jobStatusResponse = (SimpleMutateJob) jobs[0];
      status = jobStatusResponse.getStatus();
      if (status == BasicJobStatus.COMPLETED || status == BasicJobStatus.FAILED) {
        break;
      }
      System.out.printf("[%d] Current status is '%s', waiting %d seconds to retry...\n", i,
          status.toString(), RETRY_INTERVAL);
      Thread.sleep(RETRY_INTERVAL * 1000);
    }

    // Handle unsuccessful results.
    if (status == BasicJobStatus.FAILED) {
      throw new IllegalStateException("Job failed with reason: "
          + jobStatusResponse.getFailureReason());
    }
    if (status == BasicJobStatus.PENDING || status == BasicJobStatus.PROCESSING) {
      throw new IllegalAccessException("Job did not complete within "
          + ((RETRIES_COUNT - 1) * RETRY_INTERVAL) + " seconds.");
    }

    // Status must be COMPLETED.
    // Get the job result. Here we re-use the same selector.
    JobResult result = mutateJobService.getResult(selector);

    // Output results.
    int i = 0;
    for (Operand operand : result.getSimpleMutateResult().getResults()) {
      String outcome = operand.getPlaceHolder() == null ? "SUCCESS" : "FAILED";
View Full Code Here

Examples of com.google.api.adwords.v201306.cm.MutateJobServiceInterface

      // Get AdWordsUser from "~/adwords.properties".
      AdWordsUser user = new AdWordsUser();

      // Get the MutateJobService.
      MutateJobServiceInterface mutateJobService =
          user.getService(AdWordsService.V201306.MUTATE_JOB_SERVICE);

      long adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");

      Random r = new Random();
      List<AdGroupCriterionOperation> operations = new ArrayList<AdGroupCriterionOperation>();

      // Create AdGroupCriterionOperations to add keywords.
      for (int i = 0; i < KEYWORD_NUMBER; i++) {
        // Create Keyword.
        String text = String.format("mars%d", i);
        if (r.nextInt() % 10 == 0) {
          text = text + "!!!";
        }
        Keyword keyword = new Keyword();
        keyword.setText(text);
        keyword.setMatchType(KeywordMatchType.BROAD);
        // Create BiddableAdGroupCriterion.
        BiddableAdGroupCriterion bagc = new BiddableAdGroupCriterion();
        bagc.setAdGroupId(adGroupId);
        bagc.setCriterion(keyword);
        // Create AdGroupCriterionOperation.
        AdGroupCriterionOperation agco = new AdGroupCriterionOperation();
        agco.setOperand(bagc);
        agco.setOperator(Operator.ADD);
        // Add to list.
        operations.add(agco);
      }

      // You can specify up to 3 job IDs that must successfully complete before
      // this job can be processed.
      BulkMutateJobPolicy policy = new BulkMutateJobPolicy();
      policy.setPrerequisiteJobIds(new long[] {});

      // Call mutate to create a new job.
      SimpleMutateJob response =
          mutateJobService.mutate(operations.toArray(new Operation[operations.size()]), policy);

      long jobId = response.getId();
      System.out.printf("Job with ID %d was successfully created.\n", jobId);

      // Create selector to retrieve job status and wait for it to complete.
      BulkMutateJobSelector selector = new BulkMutateJobSelector();
      selector.setJobIds(new long[] {jobId});

      // Poll for job status until it's finished.
      System.out.println("Retrieving job status...");
      SimpleMutateJob jobStatusResponse = null;
      BasicJobStatus status = null;
      for (int i = 0; i < RETRIES_COUNT; i++) {
        Job[] jobs = mutateJobService.get(selector);
        jobStatusResponse = (SimpleMutateJob) jobs[0];
        status = jobStatusResponse.getStatus();
        if (status == BasicJobStatus.COMPLETED || status == BasicJobStatus.FAILED) {
          break;
        }
        System.out.printf("[%d] Current status is '%s', waiting %d seconds to retry...\n", i,
            status.toString(), RETRY_INTERVAL);
        Thread.sleep(RETRY_INTERVAL * 1000);
      }

      // Handle unsuccessful results.
      if (status == BasicJobStatus.FAILED) {
        throw new IllegalStateException("Job failed with reason: "
            + jobStatusResponse.getFailureReason());
      }
      if (status == BasicJobStatus.PENDING || status == BasicJobStatus.PROCESSING) {
        throw new IllegalAccessException("Job did not complete within "
            + ((RETRIES_COUNT - 1) * RETRY_INTERVAL) + " seconds.");
      }

      // Status must be COMPLETED.
      // Get the job result. Here we re-use the same selector.
      JobResult result = mutateJobService.getResult(selector);

      // Output results.
      int i = 0;
      for (Operand operand : result.getSimpleMutateResult().getResults()) {
        String outcome = operand.getPlaceHolder() == null ? "SUCCESS" : "FAILED";
View Full Code Here

Examples of com.google.api.adwords.v201306.cm.MutateJobServiceInterface

      // Get AdWordsUser from "~/adwords.properties".
      AdWordsUser user = new AdWordsUser();

      // Get the MutateJobService.
      MutateJobServiceInterface mutateJobService =
          user.getService(AdWordsService.V201306.MUTATE_JOB_SERVICE);

      long adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");

      Random r = new Random();
      List<AdGroupCriterionOperation> operations = new ArrayList<AdGroupCriterionOperation>();

      // Create AdGroupCriterionOperations to add Placements.
      for (int i = 0; i < PLACEMENT_NUMBER; i++) {
        // Create Placement.
        String url;
        if (r.nextInt() % 10 == 0) {
          url = "invalid-url/" + i;
        } else {
          url = "http://mars.google.com/" + i;
        }
        Placement placement = new Placement();
        placement.setUrl(url);
        // Create BiddableAdGroupCriterion.
        BiddableAdGroupCriterion bagc = new BiddableAdGroupCriterion();
        bagc.setAdGroupId(adGroupId);
        bagc.setCriterion(placement);
        // Create AdGroupCriterionOperation.
        AdGroupCriterionOperation agco = new AdGroupCriterionOperation();
        agco.setOperand(bagc);
        agco.setOperator(Operator.ADD);
        // Add to list.
        operations.add(agco);
      }

      // You can specify up to 3 job IDs that must successfully complete before
      // this job can be processed.
      BulkMutateJobPolicy policy = new BulkMutateJobPolicy();
      policy.setPrerequisiteJobIds(new long[] {});

      // Call mutate to create a new job.
      SimpleMutateJob response =
          mutateJobService.mutate(operations.toArray(new Operation[operations.size()]), policy);

      long jobId = response.getId();
      System.out.printf("Job with ID %d was successfully created.\n", jobId);

      // Create selector to retrieve job status and wait for it to complete.
      BulkMutateJobSelector selector = new BulkMutateJobSelector();
      selector.setJobIds(new long[] {jobId});

      // Poll for job status until it's finished.
      System.out.println("Retrieving job status...");
      SimpleMutateJob jobStatusResponse = null;
      BasicJobStatus status = null;
      for (int i = 0; i < RETRIES_COUNT; i++) {
        Job[] jobs = mutateJobService.get(selector);
        jobStatusResponse = (SimpleMutateJob) jobs[0];
        status = jobStatusResponse.getStatus();
        if (status == BasicJobStatus.COMPLETED || status == BasicJobStatus.FAILED) {
          break;
        }
        System.out.printf("[%d] Current status is '%s', waiting %d seconds to retry...\n", i,
            status.toString(), RETRY_INTERVAL);
        Thread.sleep(RETRY_INTERVAL * 1000);
      }

      // Handle unsuccessful results.
      if (status == BasicJobStatus.FAILED) {
        throw new IllegalStateException("Job failed with reason: "
            + jobStatusResponse.getFailureReason());
      }
      if (status == BasicJobStatus.PENDING || status == BasicJobStatus.PROCESSING) {
        throw new IllegalAccessException("Job did not complete within "
            + ((RETRIES_COUNT - 1) * RETRY_INTERVAL) + " seconds.");
      }

      // Status must be COMPLETED.
      // Get the job result. Here we re-use the same selector.
      JobResult result = mutateJobService.getResult(selector);

      // Output results.
      int i = 0;
      for (Operand operand : result.getSimpleMutateResult().getResults()) {
        String outcome = operand.getPlaceHolder() == null ? "SUCCESS" : "FAILED";
View Full Code Here

Examples of com.google.api.adwords.v201309.cm.MutateJobServiceInterface

      // Get AdWordsUser from "~/adwords.properties".
      AdWordsUser user = new AdWordsUser();

      // Get the MutateJobService.
      MutateJobServiceInterface mutateJobService =
          user.getService(AdWordsService.V201309.MUTATE_JOB_SERVICE);

      long adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");

      Random r = new Random();
      List<AdGroupCriterionOperation> operations = new ArrayList<AdGroupCriterionOperation>();

      // Create AdGroupCriterionOperations to add keywords.
      for (int i = 0; i < KEYWORD_NUMBER; i++) {
        // Create Keyword.
        String text = String.format("mars%d", i);
        if (r.nextInt() % 10 == 0) {
          text = text + "!!!";
        }
        Keyword keyword = new Keyword();
        keyword.setText(text);
        keyword.setMatchType(KeywordMatchType.BROAD);
        // Create BiddableAdGroupCriterion.
        BiddableAdGroupCriterion bagc = new BiddableAdGroupCriterion();
        bagc.setAdGroupId(adGroupId);
        bagc.setCriterion(keyword);
        // Create AdGroupCriterionOperation.
        AdGroupCriterionOperation agco = new AdGroupCriterionOperation();
        agco.setOperand(bagc);
        agco.setOperator(Operator.ADD);
        // Add to list.
        operations.add(agco);
      }

      // You can specify up to 3 job IDs that must successfully complete before
      // this job can be processed.
      BulkMutateJobPolicy policy = new BulkMutateJobPolicy();
      policy.setPrerequisiteJobIds(new long[] {});

      // Call mutate to create a new job.
      SimpleMutateJob response =
          mutateJobService.mutate(operations.toArray(new Operation[operations.size()]), policy);

      long jobId = response.getId();
      System.out.printf("Job with ID %d was successfully created.\n", jobId);

      // Create selector to retrieve job status and wait for it to complete.
      BulkMutateJobSelector selector = new BulkMutateJobSelector();
      selector.setJobIds(new long[] {jobId});

      // Poll for job status until it's finished.
      System.out.println("Retrieving job status...");
      SimpleMutateJob jobStatusResponse = null;
      BasicJobStatus status = null;
      for (int i = 0; i < RETRIES_COUNT; i++) {
        Job[] jobs = mutateJobService.get(selector);
        jobStatusResponse = (SimpleMutateJob) jobs[0];
        status = jobStatusResponse.getStatus();
        if (status == BasicJobStatus.COMPLETED || status == BasicJobStatus.FAILED) {
          break;
        }
        System.out.printf("[%d] Current status is '%s', waiting %d seconds to retry...\n", i,
            status.toString(), RETRY_INTERVAL);
        Thread.sleep(RETRY_INTERVAL * 1000);
      }

      // Handle unsuccessful results.
      if (status == BasicJobStatus.FAILED) {
        throw new IllegalStateException("Job failed with reason: "
            + jobStatusResponse.getFailureReason());
      }
      if (status == BasicJobStatus.PENDING || status == BasicJobStatus.PROCESSING) {
        throw new IllegalAccessException("Job did not complete within "
            + ((RETRIES_COUNT - 1) * RETRY_INTERVAL) + " seconds.");
      }

      // Status must be COMPLETED.
      // Get the job result. Here we re-use the same selector.
      JobResult result = mutateJobService.getResult(selector);

      // Output results.
      int i = 0;
      for (Operand operand : result.getSimpleMutateResult().getResults()) {
        String outcome = operand.getPlaceHolder() == null ? "SUCCESS" : "FAILED";
View Full Code Here

Examples of com.google.api.adwords.v201309.cm.MutateJobServiceInterface

      // Get AdWordsUser from "~/adwords.properties".
      AdWordsUser user = new AdWordsUser();

      // Get the MutateJobService.
      MutateJobServiceInterface mutateJobService =
          user.getService(AdWordsService.V201309.MUTATE_JOB_SERVICE);

      long adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");

      Random r = new Random();
      List<AdGroupCriterionOperation> operations = new ArrayList<AdGroupCriterionOperation>();

      // Create AdGroupCriterionOperations to add Placements.
      for (int i = 0; i < PLACEMENT_NUMBER; i++) {
        // Create Placement.
        String url;
        if (r.nextInt() % 10 == 0) {
          url = "invalid-url/" + i;
        } else {
          url = "http://mars.google.com/" + i;
        }
        Placement placement = new Placement();
        placement.setUrl(url);
        // Create BiddableAdGroupCriterion.
        BiddableAdGroupCriterion bagc = new BiddableAdGroupCriterion();
        bagc.setAdGroupId(adGroupId);
        bagc.setCriterion(placement);
        // Create AdGroupCriterionOperation.
        AdGroupCriterionOperation agco = new AdGroupCriterionOperation();
        agco.setOperand(bagc);
        agco.setOperator(Operator.ADD);
        // Add to list.
        operations.add(agco);
      }

      // You can specify up to 3 job IDs that must successfully complete before
      // this job can be processed.
      BulkMutateJobPolicy policy = new BulkMutateJobPolicy();
      policy.setPrerequisiteJobIds(new long[] {});

      // Call mutate to create a new job.
      SimpleMutateJob response =
          mutateJobService.mutate(operations.toArray(new Operation[operations.size()]), policy);

      long jobId = response.getId();
      System.out.printf("Job with ID %d was successfully created.\n", jobId);

      // Create selector to retrieve job status and wait for it to complete.
      BulkMutateJobSelector selector = new BulkMutateJobSelector();
      selector.setJobIds(new long[] {jobId});

      // Poll for job status until it's finished.
      System.out.println("Retrieving job status...");
      SimpleMutateJob jobStatusResponse = null;
      BasicJobStatus status = null;
      for (int i = 0; i < RETRIES_COUNT; i++) {
        Job[] jobs = mutateJobService.get(selector);
        jobStatusResponse = (SimpleMutateJob) jobs[0];
        status = jobStatusResponse.getStatus();
        if (status == BasicJobStatus.COMPLETED || status == BasicJobStatus.FAILED) {
          break;
        }
        System.out.printf("[%d] Current status is '%s', waiting %d seconds to retry...\n", i,
            status.toString(), RETRY_INTERVAL);
        Thread.sleep(RETRY_INTERVAL * 1000);
      }

      // Handle unsuccessful results.
      if (status == BasicJobStatus.FAILED) {
        throw new IllegalStateException("Job failed with reason: "
            + jobStatusResponse.getFailureReason());
      }
      if (status == BasicJobStatus.PENDING || status == BasicJobStatus.PROCESSING) {
        throw new IllegalAccessException("Job did not complete within "
            + ((RETRIES_COUNT - 1) * RETRY_INTERVAL) + " seconds.");
      }

      // Status must be COMPLETED.
      // Get the job result. Here we re-use the same selector.
      JobResult result = mutateJobService.getResult(selector);

      // Output results.
      int i = 0;
      for (Operand operand : result.getSimpleMutateResult().getResults()) {
        String outcome = operand.getPlaceHolder() == null ? "SUCCESS" : "FAILED";
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.