private void checkSubstance(ArchivalUnit au) { SubstanceChecker subChecker = new SubstanceChecker(au); if (!subChecker.isEnabled()) { errMsg = "No substance patterns defined for plugin."; return; } AuState auState = AuUtil.getAuState(au); SubstanceChecker.State oldState = auState.getSubstanceState(); SubstanceChecker.State newState = subChecker.findSubstance(); String chtxt = (newState == oldState ? "(unchanged)" : "(was " + oldState.toString() + ")"); switch (newState) { case Unknown: log.error("Shouldn't happen: SubstanceChecker returned Unknown"); errMsg = "Error in SubstanceChecker; see log."; break; case Yes: statusMsg = "AU has substance " + chtxt + ": " + au.getName(); auState.setSubstanceState(SubstanceChecker.State.Yes); break; case No: statusMsg = "AU has no substance " + chtxt + ": " + au.getName(); auState.setSubstanceState(SubstanceChecker.State.No); break; } }
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; }
public void testSubstanceState() { AuState aus = new AuState(mau, historyRepo); assertEquals(SubstanceChecker.State.Unknown, aus.getSubstanceState()); assertFalse(aus.hasNoSubstance()); aus.setSubstanceState(SubstanceChecker.State.Yes); assertEquals(1, historyRepo.getAuStateStoreCount()); assertEquals(SubstanceChecker.State.Yes, aus.getSubstanceState()); assertFalse(aus.hasNoSubstance()); aus.setSubstanceState(SubstanceChecker.State.No); assertEquals(2, historyRepo.getAuStateStoreCount()); assertEquals(SubstanceChecker.State.No, aus.getSubstanceState()); assertTrue(aus.hasNoSubstance()); assertNotEquals("2", aus.getFeatureVersion(Plugin.Feature.Substance)); mplug.setFeatureVersionMap(MapUtil.map(Plugin.Feature.Substance, "2")); aus.setSubstanceState(SubstanceChecker.State.Yes); // changing both the substance state and feature version should store // only once assertEquals(3, historyRepo.getAuStateStoreCount()); assertEquals(SubstanceChecker.State.Yes, aus.getSubstanceState()); assertEquals("2", aus.getFeatureVersion(Plugin.Feature.Substance)); }