Skip to content

Commit

Permalink
Custom IMAP events generator can not be applied #83
Browse files Browse the repository at this point in the history
  • Loading branch information
zaharchenko committed Aug 21, 2019
1 parent 0cded6b commit 4f00736
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ public class ImapEvents {
@Inject
private Authentication authentication;

@Inject
private ImapEventsGenerator standardEventsGenerator;

@Inject
private ImapDao imapDao;

Expand All @@ -62,15 +59,15 @@ public void shutdown(ImapMailBox mailBox) {
}

public void handleNewMessages(ImapFolder cubaFolder) {
fireEvents( cubaFolder, getEventsGeneratorImplementation(cubaFolder.getMailBox()).generateForNewMessages(cubaFolder) );
fireEvents(cubaFolder, getEventsGeneratorImplementation(cubaFolder.getMailBox()).generateForNewMessages(cubaFolder));
}

public void handleChangedMessages(ImapFolder cubaFolder) {
fireEvents( cubaFolder, getEventsGeneratorImplementation(cubaFolder.getMailBox()).generateForChangedMessages(cubaFolder) );
fireEvents(cubaFolder, getEventsGeneratorImplementation(cubaFolder.getMailBox()).generateForChangedMessages(cubaFolder));
}

public void handleMissedMessages(ImapFolder cubaFolder) {
fireEvents( cubaFolder, getEventsGeneratorImplementation(cubaFolder.getMailBox()).generateForMissedMessages(cubaFolder) );
fireEvents(cubaFolder, getEventsGeneratorImplementation(cubaFolder.getMailBox()).generateForMissedMessages(cubaFolder));
}

private ImapEventsGenerator getEventsGeneratorImplementation(ImapMailBox mailBox) {
Expand All @@ -80,16 +77,20 @@ private ImapEventsGenerator getEventsGeneratorImplementation(ImapMailBox mailBox
Map<String, ?> beans = AppContext.getApplicationContext()
.getBeansOfType(eventsGeneratorClass);
if (beans.isEmpty()) {
return standardEventsGenerator;
return getStandartEventsGenerator();
}
Map.Entry<String, ?> bean = beans.entrySet().iterator().next();
if (!(bean.getValue() instanceof ImapEventsGenerator)) {
log.warn("Bean {} is not implementation of ImapEventsGenerator interface", bean.getKey());
return standardEventsGenerator;
return getStandartEventsGenerator();
}
return (ImapEventsGenerator) bean.getValue();
}
return standardEventsGenerator;
return getStandartEventsGenerator();
}

private ImapEventsGenerator getStandartEventsGenerator() {
return AppBeans.get(ImapStandardEventsGenerator.NAME);
}

private void fireEvents(ImapFolder cubaFolder, Collection<? extends BaseImapEvent> imapEvents) {
Expand Down

0 comments on commit 4f00736

Please sign in to comment.