Browse code

BM-13094 Chore: improve logs

David Phan authored on 12/04/2018 13:39:57
Showing 2 changed files
... ...
@@ -180,7 +180,7 @@ public class HSMJob implements IScheduledJob {
180 180
 		sched.info(rid, "en", "Processing user/group " + loginContext.login);
181 181
 		sched.info(rid, "fr", "Traitement de l'utilisateur/groupe " + loginContext.login);
182 182
 
183
-		logger.info("Processing user/group {}", loginContext.login);
183
+		logger.debug("Processing user/group {}", loginContext.login);
184 184
 
185 185
 		// Not sure about this
186 186
 		SecurityContext userContext = new SecurityContext(UUID.randomUUID().toString(), loginContext.uid,
... ...
@@ -199,6 +199,9 @@ public class HSMJob implements IScheduledJob {
199 199
 
200 200
 				logger.info("Demoted " + stats.getMovedMailsCount() + " mail(s) (" + stats.getMatchedMailsCount()
201 201
 						+ " checked) for " + loginContext.login);
202
+			} else {
203
+				sched.info(rid, "en", "No HSM policy for " + loginContext.login);
204
+				sched.info(rid, "fr", "Pas de politique d'archivage pour l'utilisateur " + loginContext.login);
202 205
 			}
203 206
 		} catch (Exception e) {
204 207
 			logger.warn("Fail to process user {}, check core logs for more informations", loginContext.login, e);
... ...
@@ -28,6 +28,7 @@ import net.bluemind.core.container.model.ItemValue;
28 28
 import net.bluemind.core.context.SecurityContext;
29 29
 import net.bluemind.core.rest.ServerSideServiceProvider;
30 30
 import net.bluemind.folder.api.Folder;
31
+import net.bluemind.folder.api.Folder.Type;
31 32
 import net.bluemind.hsm.api.IHSM;
32 33
 import net.bluemind.hsm.api.StoragePolicy;
33 34
 import net.bluemind.hsm.processor.HSMContext.HSMLoginContext;
... ...
@@ -52,27 +53,34 @@ public class MailboxProcessor {
52 52
 		StoragePolicy sp = getPolicy();
53 53
 
54 54
 		if (sp == null) {
55
-			logger.info("No HSM policy for {}", securityContext.getSubject());
56
-			return stats;
55
+			logger.debug("No HSM policy for {}", securityContext.getSubject());
56
+			return null;
57 57
 		}
58 58
 
59 59
 		HSMLoginContext loginContext = context.getLoginContext();
60 60
 
61
-		StoreClient sc = new StoreClient(loginContext.dataLocation, 1143,
62
-				loginContext.login + "@" + securityContext.getContainerUid(), securityContext.getSessionId());
61
+		try (StoreClient sc = new StoreClient(loginContext.dataLocation, 1143,
62
+				loginContext.login + "@" + securityContext.getContainerUid(), securityContext.getSessionId())) {
63 63
 
64
-		IMailboxFolderHierarchy mboxHierarchyService = ServerSideServiceProvider.getProvider(SecurityContext.SYSTEM)
65
-				.instance(IMailboxFolderHierarchy.class, context.getSecurityContext().getSubject());
64
+			if (!sc.login()) {
65
+				logger.error("{}@{} fails to login to IMAP", loginContext.login, securityContext.getContainerUid());
66
+				return stats;
67
+			}
66 68
 
67
-		List<ItemValue<Folder>> folders = mboxHierarchyService.multipleGet(mboxHierarchyService.allUids());
69
+			IMailboxFolderHierarchy mboxHierarchyService = ServerSideServiceProvider.getProvider(SecurityContext.SYSTEM)
70
+					.instance(IMailboxFolderHierarchy.class, context.getSecurityContext().getSubject());
68 71
 
69
-		if (sc.login()) {
72
+			List<ItemValue<Folder>> folders = mboxHierarchyService.multipleGet(mboxHierarchyService.allUids());
70 73
 
71 74
 			for (ItemValue<Folder> f : folders) {
75
+				if (f.value.type == Type.root) {
76
+					// skip Top Information Store
77
+					continue;
78
+				}
72 79
 				String folderName = f.value.path;
73 80
 
74 81
 				if (sp.excludedFolders.contains(folderName)) {
75
-					logger.info("Folder {} excluded by policy", folderName);
82
+					logger.info("[{}] Folder {} excluded by policy", loginContext.login, folderName);
76 83
 					continue;
77 84
 				}
78 85
 
... ...
@@ -81,18 +89,15 @@ public class MailboxProcessor {
81 81
 					fp.process(stats);
82 82
 					sc.expunge();
83 83
 				} else {
84
-					logger.info("Non selectable folder {}", folderName);
84
+					logger.info("[{}] Non selectable folder {}, type: {}", loginContext.login, folderName,
85
+							f.value.type);
85 86
 					continue;
86 87
 				}
87 88
 
88 89
 			}
89 90
 
90
-		} else {
91
-			logger.error("{}@{} fails to login to IMAP", loginContext.login, securityContext.getContainerUid());
92 91
 		}
93 92
 
94
-		sc.logout();
95
-
96 93
 		return stats;
97 94
 	}
98 95