Beispiel #1
0
    /**
     * @param projection Projection to use. If <code>null</code>, use the default projection.
     * @return Never <code>null</code>.
     * @throws InterruptedException
     */
    protected MatrixCursor getMessages(final String[] projection) throws InterruptedException {
      final BlockingQueue<List<MessageInfoHolder>> queue =
          new SynchronousQueue<List<MessageInfoHolder>>();

      // new code for integrated inbox, only execute this once as it will be processed afterwards
      // via the listener
      final SearchAccount integratedInboxAccount =
          SearchAccount.createUnifiedInboxAccount(getContext());
      final MessagingController msgController = MessagingController.getInstance(K9.app);

      msgController.searchLocalMessages(
          integratedInboxAccount, null, new MesssageInfoHolderRetrieverListener(queue));

      final List<MessageInfoHolder> holders = queue.take();

      // TODO add sort order parameter
      Collections.sort(
          holders,
          new MessageList.ReverseComparator<MessageInfoHolder>(new MessageList.DateComparator()));

      final String[] projectionToUse;
      if (projection == null) {
        projectionToUse = DEFAULT_MESSAGE_PROJECTION;
      } else {
        projectionToUse = projection;
      }

      final LinkedHashMap<String, FieldExtractor<MessageInfoHolder, ?>> extractors =
          resolveMessageExtractors(projectionToUse, holders.size());
      final int fieldCount = extractors.size();

      final String[] actualProjection = extractors.keySet().toArray(new String[fieldCount]);
      final MatrixCursor cursor = new MatrixCursor(actualProjection);

      for (final MessageInfoHolder holder : holders) {
        final Object[] o = new Object[fieldCount];

        int i = 0;
        for (final FieldExtractor<MessageInfoHolder, ?> extractor : extractors.values()) {
          o[i] = extractor.getField(holder);
          i += 1;
        }

        cursor.addRow(o);
      }

      return cursor;
    }
  @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;
    }
  }
 /**
  * calculate all the field indices in lineRay for all the desired fields
  *
  * @param lineRay the incoming line of entries from the CSV file
  */
 public static void setup(String[] lineRay) {
   for (String fieldname : lineRay) {
     FieldExtractor[] values = values();
     FieldExtractor extractor = null;
     for (int i = 0, length = values.length; i < length; i++) {
       extractor = values[i];
       if (extractor.fieldname.equals(fieldname)) {
         extractor.fieldindex = i;
         break;
       }
     }
     if (extractor.fieldindex == -1) {
       System.err.println("Header line contains spaces or invalid column name.");
       System.exit(1);
     }
   }
 }
  @Override
  public String toString() {
    if (lastFailingFieldExtractor != null) {
      return lastFailingFieldExtractor.toString();
    }

    return String.format("%s for fields [%s]", getClass().getSimpleName(), params.keySet());
  }
 @Override
 public void setup(String[] lineRay, LineProcessor parent) {
   lineProcessor = parent;
   FieldExtractor.setup(lineRay);
   operations = new CampaignOperation[MAX_OPERATIONS];
   operationsIterator = 0;
   opsPerLine = 1;
   idColumns = 1;
 }
 /**
  * Check the numeric fields from the CSV are in fact numeric
  *
  * @return did they all check out OK?
  */
 public boolean validate() {
   FieldExtractor[] numericValueCheck = {
     FieldExtractor.ClientAccountId, FieldExtractor.CampaignId
   };
   for (FieldExtractor numericField : numericValueCheck) {
     String value = FieldExtractor.getFieldValue(lineRay, numericField);
     try {
       Long.parseLong(value);
     } catch (Exception e) {
       lineProcessor.errorSummaryMessage =
           String.format(
               "Problem parsing data in row #%d. Field value was expected to be numeric",
               currentLineNumber);
       lineProcessor.errorCauseMessage =
           String.format("'%s' contains value of '%s'", numericField.getFieldName(), value);
       lineProcessor.handleFailure((int) currentLineNumber, lineProcessor.errorSummaryMessage);
       return false;
     }
   }
   return true;
 }