Exemple #1
0
  private boolean startReindexingMetadata(ArchivalUnit au, boolean force) {
    if (metadataMgr == null) {
      errMsg = "Metadata processing is not enabled.";
      return false;
    }

    if (!force) {
      if (!AuUtil.hasCrawled(au)) {
        errMsg = "Au has never crawled. Click again to reindex metadata";
        showForceReindexMetadata = true;
        return false;
      }

      AuState auState = AuUtil.getAuState(au);
      switch (auState.getSubstanceState()) {
        case No:
          errMsg = "Au has no substance. Click again to reindex metadata";
          showForceReindexMetadata = true;
          return false;
        case Unknown:
          errMsg = "Unknown substance for Au. Click again to reindex metadata.";
          showForceReindexMetadata = true;
          return false;
        case Yes:
          // fall through
      }
    }

    // Fully reindex metadata with the highest priority.
    Connection conn = null;
    PreparedStatement insertPendingAuBatchStatement = null;

    try {
      conn = dbMgr.getConnection();
      insertPendingAuBatchStatement = metadataMgr.getPrioritizedInsertPendingAuBatchStatement(conn);

      if (metadataMgr.enableAndAddAuToReindex(
          au, conn, insertPendingAuBatchStatement, false, true)) {
        statusMsg = "Reindexing metadata for " + au.getName();
        return true;
      }
    } catch (DbException dbe) {
      log.error("Cannot reindex metadata for " + au.getName(), dbe);
    } finally {
      DbManager.safeCloseStatement(insertPendingAuBatchStatement);
      DbManager.safeRollbackAndClose(conn);
    }

    if (force) {
      errMsg = "Still cannot reindex metadata for " + au.getName();
    } else {
      errMsg = "Cannot reindex metadata for " + au.getName();
    }
    return false;
  }
 /**
  * Returns a list of BibliographicItems from the metadata database.
  *
  * @return a list of BibliobraphicItems from the metadata database.
  */
 public static List<BibliographicItem> getBibliographicItems() {
   List<BibliographicItem> items = Collections.<BibliographicItem>emptyList();
   Connection conn = null;
   try {
     DbManager dbManager = getDaemon().getDbManager();
     conn = dbManager.getConnection();
     items = getBibliographicItems(dbManager, conn);
   } catch (DbException ex) {
     log.warning(ex.getMessage());
     log.warning("bibliographicItemsQuery = " + bibliographicItemsQuery);
   } finally {
     DbManager.safeRollbackAndClose(conn);
   }
   return items;
 }
  /**
   * Returns a list of BibliographicItems from the metadata database.
   *
   * @param dbManager the database manager
   * @param conn the database connection
   * @return a list of BibliobraphicItems from the metadata database.
   */
  public static List<BibliographicItem> getBibliographicItems(
      DbManager dbManager, Connection conn) {
    final String DEBUG_HEADER = "getBibliographicItems(): ";
    BibliographicItem previousItem = null;
    List<BibliographicItem> items = new ArrayList<BibliographicItem>();
    PreparedStatement statement = null;
    ResultSet resultSet = null;

    try {
      if (log.isDebug3())
        log.debug3(DEBUG_HEADER + "bibliographicItemsQuery = " + bibliographicItemsQuery);
      statement = dbManager.prepareStatement(conn, bibliographicItemsQuery);
      resultSet = dbManager.executeQuery(statement);

      while (resultSet.next()) {
        BibliographicItem item = new BibliographicDatabaseItem(resultSet);
        // Avoid adding items that differ only in some proprietary identifier.
        if (!item.sameInNonProprietaryIdProperties(previousItem)) {
          items.add(item);
        }
      }
    } catch (IllegalArgumentException ex) {
      log.warning(ex.getMessage());
      log.warning("bibliographicItemsQuery = " + bibliographicItemsQuery);
    } catch (SQLException ex) {
      log.warning(ex.getMessage());
      log.warning("bibliographicItemsQuery = " + bibliographicItemsQuery);
    } catch (DbException ex) {
      log.warning(ex.getMessage());
      log.warning("bibliographicItemsQuery = " + bibliographicItemsQuery);
    } finally {
      DbManager.safeCloseResultSet(resultSet);
      DbManager.safeCloseStatement(statement);
    }
    return items;
  }