Package com.ikanow.infinit.e.data_model.store.config.source

Examples of com.ikanow.infinit.e.data_model.store.config.source.SourceHarvestStatusPojo


        _numMessages++;
      }
    }//TOTEST
   
    if (null == sourceToUpdate.getHarvestStatus()) {
      sourceToUpdate.setHarvestStatus(new SourceHarvestStatusPojo());
    }
   
    BasicDBObject update = new BasicDBObject();
      // (annoyingly need to do this in raw format because otherwise overwrite any existing fields eg synced,doccount)
    if ((null == sourceToUpdate.getDistributionFactor()) || (HarvestEnum.in_progress != harvestStatus)) {
View Full Code Here


      if (HarvestEnum.error == harvestStatus) {
        _numMessages++;
      }
    }//TOTEST 
   
    SourceHarvestStatusPojo hp = new SourceHarvestStatusPojo();
    hp.setHarvested(harvestDate);
    hp.setHarvest_status(harvestStatus);
    sourceToUpdate.setHarvestStatus(hp);
    sourceToUpdate.getHarvestStatus().setRealHarvested(harvestDate);
   
    // Display message
    if (null == _currMessage) { 
View Full Code Here

      if (password != null && password.length() > 0) rdbms.setPassword(new TextEncryption().decrypt(password));
    }
   
    // Some horrible logic to handle a DB cycle being >max records
    int nNumRecordsToSkip = 0;
    SourceHarvestStatusPojo lastHarvestInfo = source.getHarvestStatus();
    if (null != lastHarvestInfo) { // either in delta query mode, or truncation mode of initial query
      if (null != lastHarvestInfo.getHarvest_message()) {
        if (lastHarvestInfo.getHarvest_message().startsWith("query:")) { // Initial query
          try {
            int nEndOfNum = lastHarvestInfo.getHarvest_message().indexOf('.', 6);
            if (nEndOfNum > 0) {
              nNumRecordsToSkip = Integer.parseInt(lastHarvestInfo.getHarvest_message().substring(6, nEndOfNum));
            }
          }
          catch (Exception e) {} // Do nothing, just default to 0
          lastHarvestInfo = null; // (go through initial query branch below)
        }
        else { // Delta query or error!
          if (lastHarvestInfo.getHarvest_message().startsWith("deltaquery:")) { // Delta query, phew
            try {
              int nEndOfNum = lastHarvestInfo.getHarvest_message().indexOf('.', 11);
              if (nEndOfNum > 0) {
                nNumRecordsToSkip = Integer.parseInt(lastHarvestInfo.getHarvest_message().substring(11, nEndOfNum));
              }
            }
            catch (Exception e) {} // Do nothing, just default to 0             
          }         
        }
View Full Code Here

            boolean bReset = false;
            if ((null == fullSource.getHarvestStatus()) || (null == fullSource.getHarvestStatus().getDistributionTokensFree())) {
              distributionToken = fullSource.getDistributionFactor();
              // (also set up some parameters so don't need to worry about null checks later)
              if (null == fullSource.getHarvestStatus()) {
                fullSource.setHarvestStatus(new SourceHarvestStatusPojo());
              }
              fullSource.getHarvestStatus().setDistributionTokensFree(distributionToken);
              fullSource.getHarvestStatus().setDistributionTokensComplete(0);
            }
            else {
View Full Code Here

    }
   
    // Some horrible logic to handle a DB cycle being >max records
    int nNumRecordsToSkip = 0;
    Integer distributionToken = null;
    SourceHarvestStatusPojo lastHarvestInfo = source.getHarvestStatus();
      // (this is never null when called from the harvester by construction)
   
    if ((null != lastHarvestInfo) && (null != lastHarvestInfo.getHarvest_message())) { // either in delta query mode, or truncation mode of initial query
      String harvestMessage = null;
      if ((null == source.getDistributionTokens()) || source.getDistributionTokens().isEmpty()) {
        harvestMessage = lastHarvestInfo.getHarvest_message();
      }
      else { // (currently only support one slice per harvester)
        distributionToken = source.getDistributionTokens().iterator().next();
        if (null != lastHarvestInfo.getDistributedStatus()) {
          harvestMessage = lastHarvestInfo.getDistributedStatus().get(distributionToken.toString());
        }
      }//TODO (INF-2120): TOTEST
     
      if (null != harvestMessage) {
        harvestMessage = harvestMessage.replaceAll("\\[[0-9T:-]+\\]", "").trim();
       
        if (harvestMessage.startsWith("query:")) { // Initial query
          try {
            int nEndOfNum = harvestMessage.indexOf('.', 6);
            if (nEndOfNum > 0) {
              nNumRecordsToSkip = Integer.parseInt(harvestMessage.substring(6, nEndOfNum));
            }
          }
          catch (Exception e) {} // Do nothing, just default to 0
          lastHarvestInfo = null; // (go through initial query branch below)
        }
        else { // Delta query or error!
          if (harvestMessage.startsWith("deltaquery:")) { // Delta query, phew
            try {
              int nEndOfNum = harvestMessage.indexOf('.', 11);
              if (nEndOfNum > 0) {
                nNumRecordsToSkip = Integer.parseInt(harvestMessage.substring(11, nEndOfNum));
              }
            }
            catch (Exception e) {} // Do nothing, just default to 0             
          }         
        }
      }
    }//TESTED ("query:" by eye, "deltaquery:" implicitly as cut and paste) //TOTEST with "." and with other fields added
   
    // If the query has been performed before run delta and delete queries
    if ((null != lastHarvestInfo) && (null != lastHarvestInfo.getHarvest_message()))  
    {
      String deltaQuery = null;
      String deleteQuery = null;
      String deltaDate = null;
     
      // Get the date last harvested from the harvest object and then convert the date
      // to the proper format for the database being queried
      if (source.getHarvestStatus().getHarvested() != null)
      {
        if (null != source.getHarvestStatus().getRealHarvested()) { // (this is more accurate)
          deltaDate = getDatabaseDateString(dt, source.getHarvestStatus().getRealHarvested());         
        }
        else {
          deltaDate = getDatabaseDateString(dt, source.getHarvestStatus().getHarvested());
        }
      }
           
      // Delta Query - get new data that has appeared in our source since the harvest last run
      // Important Note: The query should be against a "last modified" field not publishedDate unless they are
      // equal to ensure new records get added properly and not ignored by the harvester
      if ((source.getDatabaseConfig().getDeltaQuery() != null) && !source.getDatabaseConfig().getDeltaQuery().isEmpty())
      {
        deltaQuery = source.getDatabaseConfig().getDeltaQuery();
        // Replace '?' in the delta query with the date value retrieved via getHarvested()
        if ((source.getHarvestStatus().getHarvested() != null) && (deltaQuery.contains("?")))
        {
          deltaQuery = deltaQuery.replace("?", "'" + deltaDate + "'").toString();
        }
      }
      // Skip logic:
      if (deltaQuery.contains("!SKIP!")) {
        deltaQuery = deltaQuery.replace("!SKIP!", new Integer(nNumRecordsToSkip).toString());
      }
      else {
        rdbms.setRecordsToSkip(nNumRecordsToSkip);       
      }
     
      // Distribution logic, currently manual:
      if ((null != distributionToken) && deltaQuery.contains("!TOKEN!")) {
        deltaQuery = deltaQuery.replace("!TOKEN!", distributionToken.toString());       
      }//TODO (INF-2120): TOTEST   
      if ((null != source.getDistributionFactor()) && deltaQuery.contains("!NTOKENS!")) {
        deltaQuery = deltaQuery.replace("!NTOKENS!", source.getDistributionFactor().toString());       
      }//TODO (INF-2120): TOTEST   
     
      // Delete docs from the index if they have been deleted from the source
      // database. Designed to check a "deleted" table to get records that have been
      // deleted to identify the records to remove form the index.
      if ((source.getDatabaseConfig().getDeleteQuery() != null) && !source.getDatabaseConfig().getDeleteQuery().isEmpty())
      {
        deleteQuery = source.getDatabaseConfig().getDeleteQuery();
       
        // Distribution logic, currently manual:
        if ((null != distributionToken) && deleteQuery.contains("!TOKEN!")) {
          deleteQuery = deltaQuery.replace("!TOKEN!", distributionToken.toString());       
        }//TODO (INF-2120): TOTEST   
        if ((null != source.getDistributionFactor()) && deleteQuery.contains("!NTOKENS!")) {
          deleteQuery = deleteQuery.replace("!NTOKENS!", source.getDistributionFactor().toString());       
        }//TODO (INF-2120): TOTEST   
       
        // Replace '?' in the delete query with the date value retrieved via getHarvested()
        if ((source.getHarvestStatus().getHarvested() != null) && (deleteQuery.contains("?")))
        {
          deleteQuery = deleteQuery.replace("?", "'" + deltaDate + "'").toString();
        }
        rdbms.setQuery(deleteQuery, deltaDate);
        String errMessage = rdbms.executeQuery();
        if (null == errMessage) {
          deleteRecords(rdbms.getResultSet(), source);
        }
        else {
          _context.getHarvestStatus().update(source, new Date(), HarvestEnum.error, "Error when harvesting DB: " + errMessage, false, true);
          // Close the connection
          try {
            rdbms.closeConnection();
            rdbms = null;
          }
          catch (Exception e) {
            // Do nothing, we've already updated the harvest
          }
          return;
        }//TOTEST (INF-2349)
      }
     
      // Set the rdbms query = deltaQuery
      if ((deltaQuery != null) && (deltaDate != null))
      {
        rdbms.setQuery(deltaQuery, deltaDate);
      }
      else
      {
        rdbms.setQuery(source.getDatabaseConfig().getQuery());
      }
    }
    else // Very first import (though might be in horrible initial query mode)
    {
      String query = source.getDatabaseConfig().getQuery();
      if (query.contains("!SKIP!")) {
        query = query.replace("!SKIP!", new Integer(nNumRecordsToSkip).toString());
      }
      else {
        rdbms.setRecordsToSkip(nNumRecordsToSkip);       
      }
     
      // Distribution logic, currently manual:
      if ((null != distributionToken) && query.contains("!TOKEN!")) {
        query = query.replace("!TOKEN!", distributionToken.toString());       
      }//TODO (INF-2120): TOTEST         
      if ((null != source.getDistributionFactor()) && query.contains("!NTOKENS!")) {
        query = query.replace("!NTOKENS!", source.getDistributionFactor().toString());       
      }//TODO (INF-2120): TOTEST   
     
      // Set rdbs query = default source.database.query value
      rdbms.setQuery(query);
    }
   
    // Execute the specified query
    String sErr = rdbms.executeQuery();
   
    if (null != sErr) {
      _context.getHarvestStatus().update(source, new Date(), HarvestEnum.error, "Error when harvesting DB: " + sErr, false, true);
    }
    else {
      // Build the list of docs using the result set from the query
      try {
        boolean bTruncated = addRecords(rdbms.getResultSet(), rdbms.getMetaData(), source);
       
        // Update source document with harvest success message
        String truncationMode = null;
        if (bTruncated) {
          source.setReachedMaxDocs();
          if ((null != lastHarvestInfo) && (null != lastHarvestInfo.getHarvest_message())) {
            // Was a delta query
            truncationMode = new StringBuffer("deltaquery:").append(nNumRecordsToSkip + this.docsToAdd.size()).append('.').toString();         
          }
          else { // Was an initial import           
            truncationMode = new StringBuffer("query:").append(nNumRecordsToSkip + this.docsToAdd.size()).append('.').toString();
View Full Code Here

          // - If harvest specified, and there exists an existing harvest block then ignore
          // - If harvest specified, and the harvest has previously been deleted, then copy (except num records)
          // - Extra ... if new status object has harvested unset, then unset that
          if ((null == source.getHarvestStatus()) && (null != oldSource.getHarvestStatus())) {
            // request to unset the harvest status altogether
            source.setHarvestStatus(new SourceHarvestStatusPojo()); // new harvest status
            source.getHarvestStatus().setDoccount(oldSource.getHarvestStatus().getDoccount());
              // but keep number of records
          }
          else if ((null != oldSource.getHarvestStatus()) && (null == oldSource.getHarvestStatus().getHarvest_status())) {
            // Has previously been unset with the logic from the above clause
View Full Code Here

      harvester.setStandaloneMode(nNumDocsToReturn, bRealDedup);
      List<DocumentPojo> toAdd = new LinkedList<DocumentPojo>();
      List<DocumentPojo> toUpdate = new LinkedList<DocumentPojo>();
      List<DocumentPojo> toRemove = new LinkedList<DocumentPojo>();
      if (null == source.getHarvestStatus()) {
        source.setHarvestStatus(new SourceHarvestStatusPojo());
      }
      String oldMessage = source.getHarvestStatus().getHarvest_message();
      // SPECIAL CASE: FOR FEDERATED QUERIES
      if ((null != source.getExtractType()) && source.getExtractType().equals("Federated")) {
        int federatedQueryEnts = 0;
View Full Code Here

TOP

Related Classes of com.ikanow.infinit.e.data_model.store.config.source.SourceHarvestStatusPojo

Copyright © 2018 www.massapicom. 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.