/**
   * Returns the list of feed item IDs that are used by a campaign through a given campaign feed.
   */
  private static Set<Long> getFeedItemIdsForCampaign(CampaignFeed campaignFeed) throws Exception {
    Set<Long> feedItemIds = Sets.newHashSet();

    FunctionOperator functionOperator = campaignFeed.getMatchingFunction().getOperator();

    if (FunctionOperator.IN.equals(functionOperator)) {
      // Check if matchingFunction is of the form IN(FEED_ITEM_ID,{xxx,xxx}).
      // Extract feed items if applicable.
      feedItemIds.addAll(getFeedItemIdsFromArgument(campaignFeed.getMatchingFunction()));
    } else if (FunctionOperator.AND.equals(functionOperator)) {
      for (FunctionArgumentOperand argument : campaignFeed.getMatchingFunction().getLhsOperand()) {
        // Check if matchingFunction is of the form IN(FEED_ITEM_ID,{xxx,xxx}).
        // Extract feed items if applicable.
        if (argument instanceof FunctionOperand) {
          FunctionOperand operand = (FunctionOperand) argument;
          if (FunctionOperator.IN.equals(operand.getValue().getOperator())) {
            feedItemIds.addAll(getFeedItemIdsFromArgument(operand.getValue()));
          }
        }
      }

    } else {
      // There are no other matching functions involving feed item IDs.
    }

    return feedItemIds;
  }
  /** Gets the platform restrictions for sitelinks in a campaign. */
  private static ExtensionSettingPlatform getPlatformRestictionsForCampaign(
      CampaignFeed campaignFeed) {
    String platformRestrictions = ExtensionSettingPlatform.NONE.getValue();

    if (FunctionOperator.AND.equals(campaignFeed.getMatchingFunction().getOperator())) {
      for (FunctionArgumentOperand argument : campaignFeed.getMatchingFunction().getLhsOperand()) {
        if (argument instanceof FunctionOperand) {
          FunctionOperand operand = (FunctionOperand) argument;
          if (FunctionOperator.EQUALS.equals(operand.getValue().getOperator())
              && (operand.getValue().getLhsOperand(0) instanceof RequestContextOperand)) {
            RequestContextOperand requestContextOperand =
                (RequestContextOperand) operand.getValue().getLhsOperand(0);
            if (RequestContextOperandContextType.DEVICE_PLATFORM.equals(
                requestContextOperand.getContextType())) {
              platformRestrictions =
                  ((ConstantOperand) operand.getValue().getRhsOperand(0)).getStringValue();
            }
          }
        }
      }
    }
    return ExtensionSettingPlatform.fromString(platformRestrictions.toUpperCase());
  }