コード例 #1
0
  @Override
  public boolean setOperations(String[] lineRay, long currentLineNumber) {
    this.lineRay = lineRay;
    this.currentLineNumber = currentLineNumber;

    if (validate()) {
      // extract all the required fields from the row/line
      String clientAccountId =
          FieldExtractor.getFieldValue(lineRay, FieldExtractor.ClientAccountId);
      String campaignId = FieldExtractor.getFieldValue(lineRay, FieldExtractor.CampaignId);
      String advertisingChannelType =
          FieldExtractor.getFieldValue(lineRay, FieldExtractor.ChannelType);
      String googleSearch = FieldExtractor.getFieldValue(lineRay, FieldExtractor.GoogleSearch);
      String searchNetwork = FieldExtractor.getFieldValue(lineRay, FieldExtractor.SearchNetwork);
      String contentNetwork = FieldExtractor.getFieldValue(lineRay, FieldExtractor.ContentNetwork);
      String partnerSearchNetwork =
          FieldExtractor.getFieldValue(lineRay, FieldExtractor.PartnerSearchNetwork);
      String displaySelect = FieldExtractor.getFieldValue(lineRay, FieldExtractor.DisplaySelect);

      try {

        lineProcessor.awapi.addSession(clientAccountId);
        Campaign campaign = new Campaign();
        campaign.setId(Long.decode(campaignId));
        campaign.setAdvertisingChannelType(
            AdvertisingChannelType.fromString(advertisingChannelType));
        // Set the campaign network options to Search and Search Network.
        NetworkSetting networkSetting = new NetworkSetting();
        networkSetting.setTargetGoogleSearch(Boolean.valueOf(googleSearch));
        networkSetting.setTargetSearchNetwork(Boolean.valueOf(searchNetwork));
        networkSetting.setTargetContentNetwork(Boolean.valueOf(contentNetwork));
        networkSetting.setTargetPartnerSearchNetwork(Boolean.valueOf(partnerSearchNetwork));
        campaign.setNetworkSetting(networkSetting);
        if (displaySelect.equalsIgnoreCase("TRUE")) {
          campaign.setDisplaySelect(true);
        } else if (displaySelect.equalsIgnoreCase("FALSE")) {
          campaign.setDisplaySelect(false);
        }

        // Create operations.
        CampaignOperation operation = new CampaignOperation();
        operation.setOperand(campaign);
        operation.setOperator(Operator.SET);

        operations[operationsIterator++] = operation;

        return true;

      } catch (Exception generalException) {
        // catch general failures...
        reportError(campaignId, generalException);
        return false;
      }
    } else {
      return false;
    }
  }
コード例 #2
0
  @Override
  public boolean mutate() {
    boolean state = true;
    int line = 0;
    ApiError partialFailures[] = new ApiError[MAX_OPERATIONS];
    ApiError returnedFailures[] = null;

    // Get the CampaignService.
    campaignService = lineProcessor.awapi.campaignService;

    if (campaignService == null) {
      System.err.println("Error fetching CampaignService.");
      throw new NullPointerException();
    }

    if (!ConstantsIF.DEBUG_MODE) {
      try {
        // Add campaign.
        CampaignReturnValue result = campaignService.mutate(operations);
        lineProcessor.voluntaryWaitLogic();

        if (result != null) {
          returnedFailures = result.getPartialFailureErrors();
          if (returnedFailures != null) {
            for (ApiError apiError : returnedFailures) {
              Matcher matcher = operationIndexPattern.matcher(apiError.getFieldPath());
              if (matcher.matches()) {
                int operationIndex = Integer.parseInt(matcher.group(1));
                partialFailures[operationIndex] = apiError;
              }
            }
          }
          for (Campaign campaignResult : result.getValue()) {
            String message =
                String.format(
                    "Campaign with id '%d' and name '%s' ",
                    campaignResult.getId(), campaignResult.getName());

            if (partialFailures[line] == null) {
              // successfully processed a row of data!
              lineProcessor.handleSuccess(line, message + "was migrated.");
            } else if (partialFailures[line] instanceof PolicyViolationError) {
              lineProcessor.handlePolicyViolation(
                  line, "Campaign", (PolicyViolationError) partialFailures[line]);
            } else {
              lineProcessor.handleFailure(
                  line, message + "failed with: " + partialFailures[line].getErrorString());
              state = false;
            }
            line++;
          }
        } else {
          lineProcessor.handleFailure(line, "No Campaigns were migrated.");
          lineProcessor.errorCauseMessage = "Campaign Migration failed.";
          state = false;
        }
      } catch (ApiException apiException) {
        // catch specific API errors... eg: RateLimitError...
        ApiError[] errorRay = apiException.getErrors();
        for (ApiError apiError : errorRay) {
          if (apiError instanceof RateExceededError) {
            // RateExceededError
            lineProcessor.processRateExceededError(apiException);
            state = false;
          } else if (apiError instanceof PolicyViolationError) {
            lineProcessor.handlePolicyViolation(line, "Campaign", (PolicyViolationError) apiError);
          } else {
            System.err.println(apiError.getErrorString());
            lineProcessor.handleFailure(line++, apiError.getErrorString());
            state = false;
          }
        }
      } catch (Exception generalException) {
        // catch general failures...
        reportError("Failed to migrate Campaigns", generalException);
        state = false;
        generalException.printStackTrace();
      }
    }
    return state;
  }