Browse code

CGTG-227 Feat: add X-BM_HSM_DATETIME header

David Phan authored on 09/01/2018 11:39:26
Showing 5 changed files
... ...
@@ -55,7 +55,8 @@ public class Composer {
55 55
 		cfg.setClassForTemplateLoading(Composer.class, "/templates");
56 56
 	}
57 57
 
58
-	public InputStream render(Message orig, String lang, String hsmId) throws IOException, TemplateException {
58
+	public InputStream render(Message orig, String lang, String hsmId, String dateTime)
59
+			throws IOException, TemplateException {
59 60
 		Template tpl = null;
60 61
 		try {
61 62
 			tpl = cfg.getTemplate("demoted_" + lang + ".ftl");
... ...
@@ -71,6 +72,7 @@ public class Composer {
71 71
 		heads.setField(Fields.contentType("text/html", ImmutableMap.of("charset", "utf-8")));
72 72
 		heads.setField(Fields.contentTransferEncoding(MimeUtil.ENC_QUOTED_PRINTABLE));
73 73
 		heads.setField(new RawField(HSMHeaders.HSM_ID, hsmId));
74
+		heads.setField(new RawField(HSMHeaders.HSM_DATETIME, dateTime));
74 75
 
75 76
 		Header oh = orig.getHeader();
76 77
 		List<Field> origFields = oh.getFields();
... ...
@@ -20,5 +20,6 @@ package net.bluemind.hsm.processor;
20 20
 
21 21
 public class HSMHeaders {
22 22
 	public static final String HSM_ID = "X-BM_HSM_ID";
23
-	public static final String[] HSM_HEADERS = { HSM_ID };
23
+	public static final String HSM_DATETIME = "X-BM_HSM_DATETIME";
24
+	public static final String[] HSM_HEADERS = { HSM_ID, HSM_DATETIME };
24 25
 }
... ...
@@ -27,6 +27,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
27 27
 
28 28
 import org.apache.james.mime4j.dom.Message;
29 29
 import org.apache.james.mime4j.stream.RawField;
30
+import org.joda.time.DateTime;
30 31
 import org.slf4j.Logger;
31 32
 import org.slf4j.LoggerFactory;
32 33
 
... ...
@@ -127,8 +128,10 @@ public class DemoteCommand extends AbstractHSMCommand {
127 127
 			// Replace old mail
128 128
 			FlagsList fl = summary.getFlags();
129 129
 			fl.add(Flag.BMARCHIVED);
130
-			int newUid = replace(msg, fl, hsmId);
130
+			String dateTime = new DateTime().toString("EE, dd MMM YYYY HH:mm:ss");
131
+			int newUid = replace(msg, fl, hsmId, dateTime);
131 132
 			msg.getHeader().setField(new RawField(HSMHeaders.HSM_ID, hsmId));
133
+			msg.getHeader().setField(new RawField(HSMHeaders.HSM_DATETIME, dateTime));
132 134
 
133 135
 			mailIndexService.append(folder, newUid, msg, summary.getDate(), summary.getSize(), fl.asTags());
134 136
 
... ...
@@ -154,8 +157,9 @@ public class DemoteCommand extends AbstractHSMCommand {
154 154
 		}
155 155
 	}
156 156
 
157
-	private int replace(Message msg, FlagsList fl, String hsmId) throws IOException, TemplateException {
158
-		InputStream stream = composer.render(msg, lang, hsmId);
157
+	private int replace(Message msg, FlagsList fl, String hsmId, String dateTime)
158
+			throws IOException, TemplateException {
159
+		InputStream stream = composer.render(msg, lang, hsmId, dateTime);
159 160
 		int delivered = sc.append(folder.path, stream, fl, id);
160 161
 		return delivered;
161 162
 	}
... ...
@@ -74,6 +74,7 @@ import net.bluemind.hsm.api.IHSM;
74 74
 import net.bluemind.hsm.api.Promote;
75 75
 import net.bluemind.hsm.api.StoragePolicy;
76 76
 import net.bluemind.hsm.api.TierChangeResult;
77
+import net.bluemind.hsm.processor.HSMHeaders;
77 78
 import net.bluemind.imap.FlagsList;
78 79
 import net.bluemind.imap.IMAPByteSource;
79 80
 import net.bluemind.imap.IMAPException;
... ...
@@ -469,6 +470,7 @@ public class HSMServiceTests {
469 469
 			assertEquals(demote.imapId, summary.getUid());
470 470
 			assertEquals("mail de test", summary.getHeaders().getSubject());
471 471
 			assertEquals(demote.hsmId, summary.getHeaders().getRawHeader("X-BM_HSM_ID"));
472
+			assertNotNull(summary.getHeaders().getRawHeader(HSMHeaders.HSM_DATETIME));
472 473
 		}
473 474
 	}
474 475
 
... ...
@@ -41,8 +41,8 @@ public final class UIDFetchSummaryCommand extends Command<Collection<Summary>> {
41 41
 
42 42
 	static {
43 43
 		String[] headers = { "DATE", "FROM", "TO", "CC", "SUBJECT", "CONTENT-TYPE", "REPLY-TO", "LIST-POST",
44
-				"DISPOSITION-NOTIFICATION-TO", "X-PRIORITY", "X-BM_HSM_ID", "X-BM-EVENT", "X-BM-RESOURCEBOOKING",
45
-				"X-BM-FOLDERSHARING", "X-ASTERISK-CALLERID" };
44
+				"DISPOSITION-NOTIFICATION-TO", "X-PRIORITY", "X-BM_HSM_ID", "X-BM_HSM_DATETIME", "X-BM-EVENT",
45
+				"X-BM-RESOURCEBOOKING", "X-BM-FOLDERSHARING", "X-ASTERISK-CALLERID" };
46 46
 		StringBuilder sb = new StringBuilder(1024);
47 47
 		sb.append("BODY.PEEK[HEADER.FIELDS (");
48 48
 		for (int i = 0; i < headers.length; i++) {