下面列出了org.apache.commons.io.monitor.FileAlterationListenerAdaptor#org.apache.wicket.request.cycle.IRequestCycleListener 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@BeforeEach
public void setUp() throws Exception {
log.info("Going to perform setup for TestInstall");
AbstractSpringTest.setOmHome();
setWicketApplicationName(DEFAULT_APP_NAME);
tempFolder = Files.createTempDirectory("omtempdb").toFile();
setH2Home(tempFolder);
tester = getWicketTester((Application)ensureApplication(-1L));
RequestCycleListenerCollection listeners = tester.getApplication().getRequestCycleListeners();
for (Iterator<IRequestCycleListener> iter = listeners.iterator(); iter.hasNext();) {
IRequestCycleListener l = iter.next();
if (l instanceof WebSocketAwareCsrfPreventionRequestCycleListener) {
listeners.remove(l);
break;
}
}
assertNotNull(WebSession.get(), "Web session should not be null");
Locale[] locales = Locale.getAvailableLocales();
tester.getSession().setLocale(locales[rnd.nextInt(locales.length)]);
log.info("Setup complete");
}
@Override
protected void onAttach()
{
if (autoDetach) {
RequestCycle.get().getListeners().add(new IRequestCycleListener() {
@Override
public void onDetach(RequestCycle aCycle)
{
LambdaModel.this.detach();
}
});
}
}
@EventListener
public void onAfterCasWritten(AfterCasWrittenEvent aEvent)
{
RequestCycle requestCycle = RequestCycle.get();
if (requestCycle == null) {
return;
}
Set<RecommendationStateKey> committed = requestCycle.getMetaData(COMMITTED);
if (committed == null) {
committed = new HashSet<>();
requestCycle.setMetaData(COMMITTED, committed);
}
committed.add(new RecommendationStateKey(aEvent.getDocument().getUser(),
aEvent.getDocument().getProject()));
boolean containsTrainingTrigger = false;
for (IRequestCycleListener listener : requestCycle.getListeners()) {
if (listener instanceof TriggerTrainingTaskListener) {
containsTrainingTrigger = true;
}
}
if (!containsTrainingTrigger) {
// Hack to figure out which annotations the user is viewing. This obviously works only
// if the user is viewing annotations through an AnnotationPageBase ... still not a
// bad guess
IPageRequestHandler handler = PageRequestHandlerTracker
.getLastHandler(requestCycle);
Page page = (Page) handler.getPage();
if (page instanceof AnnotationPageBase) {
AnnotatorState state = ((AnnotationPageBase) page).getModelObject();
requestCycle.getListeners()
.add(new TriggerTrainingTaskListener(state.getDocument()));
}
else {
// Otherwise use the document from the event... mind that if there are multiple
// events, we consider only the first one since after that the trigger listener
// will be in the cycle and we do not add another one.
// FIXME: This works as long as the user is working on a single document, but not if
// the user is doing a bulk operation. If a bulk-operation is done, we get multiple
// AfterCasWrittenEvent and we do not know which of them belongs to the document
// which the user is currently viewing.
requestCycle.getListeners()
.add(new TriggerTrainingTaskListener(aEvent.getDocument().getDocument()));
}
}
}