Browse code

BM-15556 Fix: don't try to send reminder to archived users

Thomas Fricker authored on 08/01/2020 11:17:33
Showing 1 changed files
... ...
@@ -47,6 +47,7 @@ import net.bluemind.deferredaction.api.DeferredAction;
47 47
 import net.bluemind.deferredaction.api.IDeferredAction;
48 48
 import net.bluemind.deferredaction.api.IDeferredActionContainerUids;
49 49
 import net.bluemind.deferredaction.registry.IDeferredActionExecutor;
50
+import net.bluemind.directory.api.IDirectory;
50 51
 import net.bluemind.domain.api.Domain;
51 52
 import net.bluemind.domain.api.IDomains;
52 53
 import net.bluemind.icalendar.api.ICalendarElement.VAlarm;
... ...
@@ -81,6 +82,7 @@ public class EventDeferredActionExecutor implements IDeferredActionExecutor {
81 82
 			IDeferredAction deferredActionService = provider.instance(IDeferredAction.class, deferredActionUid);
82 83
 			IMailboxes mailboxesService = provider.instance(IMailboxes.class, domain.uid);
83 84
 			IUserSettings userSettingsService = provider.instance(IUserSettings.class, domain.uid);
85
+			IDirectory directoryService = provider.instance(IDirectory.class, domain.uid);
84 86
 
85 87
 			List<ItemValue<DeferredAction>> deferredActions = deferredActionService
86 88
 					.getByActionId(EventDeferredAction.ACTION_ID, executionDate.toInstant().toEpochMilli());
... ...
@@ -92,30 +94,32 @@ public class EventDeferredActionExecutor implements IDeferredActionExecutor {
92 94
 						VertxPlatform.getVertx().setTimer(
93 95
 								Math.max(1, action.value.executionDate.getTime() - new Date().getTime()),
94 96
 								(timerId) -> executeAction(deferredActionService, action, mailboxesService,
95
-										userSettingsService));
97
+										userSettingsService, directoryService));
96 98
 					});
97 99
 		};
98 100
 	}
99 101
 
100 102
 	private void executeAction(IDeferredAction deferredActionService, ItemValue<EventDeferredAction> deferredAction,
101
-			IMailboxes mailboxesService, IUserSettings userSettingsService) {
103
+			IMailboxes mailboxesService, IUserSettings userSettingsService, IDirectory directoryService) {
102 104
 		try {
103
-			ItemValue<net.bluemind.mailbox.api.Mailbox> userMailbox = mailboxesService
104
-					.getComplete(deferredAction.value.ownerUid);
105
-
106
-			VEvent event = deferredAction.value.vevent;
107
-			VAlarm alarm = deferredAction.value.valarm;
108
-
109
-			Map<String, String> userSettings = userSettingsService.get(userMailbox.uid);
110
-			Map<String, Object> data = buildData(event, alarm, userSettings);
111
-			logger.info("Send deferred action to {} for entity {}", userMailbox.displayName, deferredAction.uid);
112
-			CompletableFuture.runAsync(() -> {
113
-				try {
114
-					sendNotificationEmail(data, userMailbox, userSettings);
115
-				} catch (Exception e) {
116
-					logger.error("Impossible to send deferred action for entity: {}", deferredAction.uid, e);
117
-				}
118
-			});
105
+			if (userIsNotArchived(directoryService, deferredAction.value.ownerUid)) {
106
+				ItemValue<net.bluemind.mailbox.api.Mailbox> userMailbox = mailboxesService
107
+						.getComplete(deferredAction.value.ownerUid);
108
+
109
+				VEvent event = deferredAction.value.vevent;
110
+				VAlarm alarm = deferredAction.value.valarm;
111
+
112
+				Map<String, String> userSettings = userSettingsService.get(userMailbox.uid);
113
+				Map<String, Object> data = buildData(event, alarm, userSettings);
114
+				logger.info("Send deferred action to {} for entity {}", userMailbox.displayName, deferredAction.uid);
115
+				CompletableFuture.runAsync(() -> {
116
+					try {
117
+						sendNotificationEmail(data, userMailbox, userSettings);
118
+					} catch (Exception e) {
119
+						logger.error("Impossible to send deferred action for entity: {}", deferredAction.uid, e);
120
+					}
121
+				});
122
+			}
119 123
 		} catch (Exception e) {
120 124
 			logger.error("Impossible to send deferred action for entity: {}", deferredAction.uid, e);
121 125
 		} finally {
... ...
@@ -133,6 +137,10 @@ public class EventDeferredActionExecutor implements IDeferredActionExecutor {
133 137
 		}
134 138
 	}
135 139
 
140
+	private boolean userIsNotArchived(IDirectory directoryService, String ownerUid) {
141
+		return !directoryService.findByEntryUid(ownerUid).archived;
142
+	}
143
+
136 144
 	private void storeTrigger(EventDeferredAction deferredAction, IDeferredAction service) {
137 145
 		deferredAction.nextExecutionDate()
138 146
 				.map(executionDate -> deferredAction.copy(Date.from(executionDate.toInstant())))