HarvestCoordinatorImpl implements HarvestCoordinator { public Boolean reIndexHarvestResult(HarvestResult origHarvestResult) { TargetInstance ti = origHarvestResult.getTargetInstance(); Boolean reIndex = false; try { reIndex = !digitalAssetStoreFactory.getDAS().checkIndexing(origHarvestResult.getOid()); } catch (DigitalAssetStoreException ex) { log.error("Could not send checkIndexing message to the DAS", ex); } if (reIndex) { targetInstanceDao.save(ti); cleanHarvestResult(origHarvestResult); ti = targetInstanceDao.load(ti.getOid()); HarvestResult newHarvestResult = null; if (origHarvestResult instanceof ArcHarvestResult) { ArcHarvestResultDTO ahr = new ArcHarvestResultDTO(); ahr.setCreationDate(new Date()); ahr.setTargetInstanceOid(ti.getOid()); ahr.setProvenanceNote(origHarvestResult.getProvenanceNote()); ahr.setHarvestNumber(origHarvestResult.getHarvestNumber()); newHarvestResult = new ArcHarvestResult(ahr, ti); } else { HarvestResultDTO hr = new HarvestResultDTO(); hr.setCreationDate(new Date()); hr.setTargetInstanceOid(ti.getOid()); hr.setProvenanceNote(origHarvestResult.getProvenanceNote()); hr.setHarvestNumber(origHarvestResult.getHarvestNumber()); newHarvestResult = new HarvestResult(hr, ti); } origHarvestResult.setState(HarvestResult.STATE_ABORTED); newHarvestResult.setState(HarvestResult.STATE_INDEXING); List<HarvestResult> hrs = ti.getHarvestResults(); hrs.add(newHarvestResult); ti.setHarvestResults(hrs); ti.setState(TargetInstance.STATE_HARVESTED); targetInstanceDao.save(newHarvestResult); targetInstanceDao.save(ti); try { digitalAssetStoreFactory.getDAS().initiateIndexing( new ArcHarvestResultDTO(newHarvestResult.getOid(), newHarvestResult.getTargetInstance().getOid(), newHarvestResult.getCreationDate(), newHarvestResult.getHarvestNumber(), newHarvestResult .getProvenanceNote())); inTrayManager.generateNotification(ti.getOwner().getOid(), MessageType.CATEGORY_MISC, MessageType.TARGET_INSTANCE_COMPLETE, ti); inTrayManager.generateTask(Privilege.ENDORSE_HARVEST, MessageType.TARGET_INSTANCE_ENDORSE, ti); } catch (DigitalAssetStoreException ex) { log.error("Could not send initiateIndexing message to the DAS", ex); } } return reIndex; } HarvestCoordinatorImpl(); void heartbeat(HarvestAgentStatusDTO aStatus); void requestRecovery(String haHost, int port, String haService); void recoverHarvests(String haHost, int haPort, String haService); void harvestComplete(HarvestResultDTO aResult); Boolean reIndexHarvestResult(HarvestResult origHarvestResult); void notification(Long aTargetInstanceOid, int notificationCategory, String aMessageType); void notification(String aSubject, int notificationCategory, String aMessage); void harvest(TargetInstance aTargetInstance, HarvestAgentStatusDTO aHarvestAgent); synchronized void checkForBandwidthTransition(); long getCurrentGlobalMaxBandwidth(); HashMap<String, List<BandwidthRestriction>> getBandwidthRestrictions(); BandwidthRestriction getBandwidthRestriction(Long aOid); BandwidthRestriction getBandwidthRestriction(String aDay, Date aTime); void saveOrUpdate(BandwidthRestriction bandwidthRestriction); void delete(BandwidthRestriction bandwidthRestriction); void setMinimumBandwidth(int aMinimumBandwidth); void setTargetInstanceDao(TargetInstanceDAO targetInstanceDao); int getMaxBandwidthPercent(); void setMaxBandwidthPercent(int maxBandwidthPercent); void updateProfileOverrides(TargetInstance aTargetInstance); void pause(TargetInstance aTargetInstance); void resume(TargetInstance aTargetInstance); void abort(TargetInstance aTargetInstance); void stop(TargetInstance aTargetInstance); void pauseAll(); void resumeAll(); void pauseQueue(); void resumeQueue(); boolean isQueuePaused(); void processSchedule(); synchronized void harvestOrQueue(QueuedTargetInstanceDTO aTargetInstance); boolean isMiniumBandwidthAvailable(TargetInstance aTargetInstance); List<String> listLogFiles(TargetInstance aTargetInstance); LogFilePropertiesDTO[] listLogFileAttributes(TargetInstance aTargetInstance); String[] tailLog(TargetInstance aTargetInstance, String aFileName, int aNoOfLines); Integer countLogLines(TargetInstance aTargetInstance, String aFileName); String[] headLog(TargetInstance aTargetInstance, String aFileName, int aNoOfLines); String[] getLog(TargetInstance aTargetInstance, String aFileName, int aStartLine, int aNoOfLines); Integer getFirstLogLineBeginning(TargetInstance aTargetInstance, String aFileName, String match); Integer getFirstLogLineContaining(TargetInstance aTargetInstance, String aFileName, String match); Integer getFirstLogLineAfterTimeStamp(TargetInstance aTargetInstance, String aFileName, Long timestamp); String[] getLogLinesByRegex(TargetInstance aTargetInstance, String aFileName, int aNoOfLines, String aRegex,
			boolean prependLineNumbers); String[] getHopPath(TargetInstance aTargetInstance, String aFileName, String aUrl); File getLogfile(TargetInstance aTargetInstance, String aFilename); void purgeDigitalAssets(); void purgeAbortedTargetInstances(); void setDigitalAssetStoreFactory(DigitalAssetStoreFactory digitalAssetStoreFactory); void setTargetManager(TargetManager targetManager); void setInTrayManager(InTrayManager inTrayManager); void setDaysBeforeDASPurge(int daysBeforeDASPurge); void setDaysBeforeAbortedTargetInstancePurge(int daysBeforeAbortedTargetInstancePurge); void setSipBuilder(SipBuilder sipBuilder); void addToHarvestResult(Long harvestResultOid, ArcHarvestFileDTO ahf); void addHarvestResources(Long harvestResultOid, Collection<HarvestResourceDTO> dtos); Long createHarvestResult(HarvestResultDTO harvestResultDTO); void finaliseIndex(Long harvestResultOid); void runQaRecommentationService(TargetInstance ti); void notifyAQAComplete(String aqaId); void removeIndexes(TargetInstance ti); void removeIndexes(HarvestResult hr); void completeArchiving(Long targetInstanceOid, String archiveIID); void failedArchiving(Long targetInstanceOid, String message); void setTargetInstanceManager(TargetInstanceManager targetInstanceManager); @Override void pauseAgent(String agentName); @Override void resumeAgent(String agentName); @Override int getHarvestOptimizationLookAheadHours(); void setHarvestOptimizationLookAheadHours(int harvestOptimizeLookAheadHours); @Override void setHarvestOptimizationEnabled(boolean state); @Override boolean isHarvestOptimizationEnabled(); int getNumHarvestersExcludedFromOptimisation(); void setNumHarvestersExcludedFromOptimisation(int numHarvestersExcludedFromOptimisation); @Override HashMap<String, HarvestAgentStatusDTO> getHarvestAgents(); void setHarvestAgentManager(HarvestAgentManager harvestAgentManager); void setHarvestLogManager(HarvestLogManager harvestLogManager); void setHarvestBandwidthManager(HarvestBandwidthManager harvestBandwidthManager); void setHarvestQaManager(HarvestQaManager harvestQaManager);  }
@Test public final void testReIndexHarvestResult() { MockDigitalAssetStore store = new MockDigitalAssetStore(); testInstance.setDigitalAssetStoreFactory(new MockDigitalAssetStoreFactory(store)); { TargetInstance ti = tiDao.load(5000L); ti.setState(TargetInstance.STATE_HARVESTED); List<HarvestResult> results = ti.getHarvestResults(); int numResults = results.size(); assertTrue(numResults > 0); HarvestResult result = results.get(numResults - 1); assertNotNull(result); result.setState(HarvestResult.STATE_INDEXING); store.setCheckIndexingReturn(true); assertFalse(testInstance.reIndexHarvestResult(result)); assertEquals(ti.getState(), TargetInstance.STATE_HARVESTED); assertEquals(result.getState(), HarvestResult.STATE_INDEXING); assertEquals(results.size(), numResults); assertEquals(results.get(results.size() - 1).getState(), HarvestResult.STATE_INDEXING); } { TargetInstance ti = tiDao.load(5000L); ti.setState(TargetInstance.STATE_HARVESTED); List<HarvestResult> results = ti.getHarvestResults(); int numResults = results.size(); assertTrue(numResults > 0); HarvestResult result = results.get(numResults - 1); assertNotNull(result); result.setState(HarvestResult.STATE_INDEXING); store.setCheckIndexingReturn(false); assertTrue(testInstance.reIndexHarvestResult(result)); assertEquals(ti.getState(), TargetInstance.STATE_HARVESTED); assertEquals(result.getState(), HarvestResult.STATE_ABORTED); assertEquals(results.size(), numResults + 1); assertEquals(results.get(results.size() - 1).getState(), HarvestResult.STATE_INDEXING); } }