Browse code

FEATBL-664 Fix: cleanup synckey

David Phan authored on 05/12/2018 14:34:50
Showing 6 changed files
... ...
@@ -107,8 +107,6 @@ public enum FilterType {
107 107
 
108 108
 			st.date = new DateTime(fromFilter);
109 109
 			st.version = 0;
110
-			st.highestUid = 0;
111
-			st.lowestUid = 0;
112 110
 		}
113 111
 
114 112
 	}
... ...
@@ -31,10 +31,6 @@ public class SyncState {
31 31
 	public ItemDataType type;
32 32
 	public long version;
33 33
 
34
-	// mail only
35
-	public long highestUid;
36
-	public long lowestUid;
37
-
38 34
 	public SyncState() {
39 35
 		date = new DateTime(0);
40 36
 	}
... ...
@@ -23,8 +23,6 @@ import java.util.LinkedHashSet;
23 23
 public class Changes {
24 24
 
25 25
 	public long version = 0;
26
-	public long highestUid = 0;
27
-	public long lowestUid = 0;
28 26
 	public LinkedHashSet<ItemChangeReference> items = new LinkedHashSet<ItemChangeReference>();
29 27
 
30 28
 }
... ...
@@ -114,7 +114,7 @@ public class FolderSyncProtocol implements IEasProtocol<FolderSyncRequest, Folde
114 114
 				}
115 115
 			}
116 116
 
117
-			response.syncKey = sm.generateSyncKey(ItemDataType.FOLDER, changes);
117
+			response.syncKey = sm.generateSyncKey(ItemDataType.FOLDER, changes.version);
118 118
 
119 119
 			response.changes.count = response.changes.add.size() + response.changes.update.size()
120 120
 					+ response.changes.delete.size();
... ...
@@ -433,8 +433,6 @@ public class SyncProtocol implements IEasProtocol<SyncRequest, SyncResponse> {
433 433
 			changes = contentExporter.getChanged(bs, state, c.options.filterType, c.getCollectionId());
434 434
 		} else {
435 435
 			changes.version = state.version;
436
-			changes.highestUid = state.highestUid;
437
-			changes.lowestUid = state.lowestUid;
438 436
 		}
439 437
 
440 438
 		if (!clientAddedServerIds.isEmpty()) {
... ...
@@ -726,10 +724,10 @@ public class SyncProtocol implements IEasProtocol<SyncRequest, SyncResponse> {
726 726
 						ServerChange srvChange = asServerChange(cr);
727 727
 						cmds.add(srvChange);
728 728
 					}
729
-					cc.syncKey = sm.generateSyncKey(st.type, changes);
729
+					cc.syncKey = sm.generateSyncKey(st.type, changes.version);
730 730
 				} else {
731 731
 					c.forceResponse = true;
732
-					cc.syncKey = sm.generateSyncKey(st);
732
+					cc.syncKey = sm.generateSyncKey(st.type, st.version);
733 733
 
734 734
 				}
735 735
 				bs.addLastClientSyncState(c.getCollectionId(), st);
... ...
@@ -27,8 +27,6 @@ import org.slf4j.LoggerFactory;
27 27
 import com.google.common.base.Splitter;
28 28
 
29 29
 import net.bluemind.eas.backend.BackendSession;
30
-import net.bluemind.eas.backend.Changes;
31
-import net.bluemind.eas.backend.FolderChanges;
32 30
 import net.bluemind.eas.backend.HierarchyNode;
33 31
 import net.bluemind.eas.dto.sync.SyncState;
34 32
 import net.bluemind.eas.dto.type.ItemDataType;
... ...
@@ -56,27 +54,19 @@ public class StateMachine {
56 56
 			ret.type = ItemDataType.FOLDER;
57 57
 			return ret;
58 58
 		}
59
-		if (!store.needReset(bs)) {
60
-			Iterator<String> sss = Splitter.on("-").split(syncKey).iterator();
61
-			SyncState ret = new SyncState();
62
-			try {
63
-				ret.date = new DateTime(Long.parseLong(sss.next()));
64
-				ret.type = ItemDataType.valueOf(sss.next());
65
-				ret.version = Long.parseLong(sss.next());
66
-				ret.highestUid = 0;
67
-				ret.lowestUid = 0;
68
-			} catch (Exception e) {
69
-				// we might have received a sync key in our old format
70
-				logger.error(e.getMessage(), e);
71
-				ret = null;
72
-			}
73
-			return ret;
59
+		if (store.needReset(bs)) {
60
+			logger.info("reset folder hierarchy for {}'s device {}", bs.getLoginAtDomain(),
61
+					bs.getDeviceId().getIdentifier());
62
+			return null;
74 63
 		}
75 64
 
76
-		logger.info("reset folder hierarchy for {}'s device {}", bs.getLoginAtDomain(),
77
-				bs.getDeviceId().getIdentifier());
65
+		Iterator<String> sss = Splitter.on("-").split(syncKey).iterator();
66
+		SyncState ret = new SyncState();
67
+		ret.date = new DateTime(Long.parseLong(sss.next()));
68
+		ret.type = ItemDataType.valueOf(sss.next());
69
+		ret.version = Long.parseLong(sss.next());
70
+		return ret;
78 71
 
79
-		return null;
80 72
 	}
81 73
 
82 74
 	/**
... ...
@@ -98,32 +88,12 @@ public class StateMachine {
98 98
 			return ret;
99 99
 		}
100 100
 
101
-		try {
102
-			Iterator<String> sss = Splitter.on("-").split(syncKey).iterator();
103
-			SyncState ret = new SyncState();
104
-			ret.date = new DateTime(Long.parseLong(sss.next()));
105
-			ret.type = ItemDataType.valueOf(sss.next());
106
-			ret.version = Long.parseLong(sss.next());
107
-
108
-			if (ret.type == ItemDataType.EMAIL) {
109
-				if (sss.hasNext()) {
110
-					ret.highestUid = Long.parseLong(sss.next());
111
-				}
112
-				if (sss.hasNext()) {
113
-					ret.lowestUid = Long.parseLong(sss.next());
114
-				}
115
-			}
116
-
117
-			return ret;
118
-		} catch (Exception e) {
119
-			// we might have received a sync key in our old format
120
-			logger.error("Invalid sync key {} ?", syncKey, e);
121
-		}
122
-
123
-		logger.info("reset folder {} for {}'s device {}", folderId, bs.getLoginAtDomain(),
124
-				bs.getDeviceId().getIdentifier());
125
-
126
-		return null;
101
+		Iterator<String> sss = Splitter.on("-").split(syncKey).iterator();
102
+		SyncState ret = new SyncState();
103
+		ret.date = new DateTime(Long.parseLong(sss.next()));
104
+		ret.type = ItemDataType.valueOf(sss.next());
105
+		ret.version = Long.parseLong(sss.next());
106
+		return ret;
127 107
 	}
128 108
 
129 109
 	/**
... ...
@@ -131,10 +101,10 @@ public class StateMachine {
131 131
 	 * @return
132 132
 	 */
133 133
 	public String generateSyncKey(ItemDataType type) {
134
-		return generateSyncKey(type, new Changes());
134
+		return generateSyncKey(type, 0);
135 135
 	}
136 136
 
137
-	public String generateSyncKey(ItemDataType type, Changes changes) {
137
+	public String generateSyncKey(ItemDataType type, long version) {
138 138
 
139 139
 		StringBuilder sk = new StringBuilder(64);
140 140
 
... ...
@@ -142,48 +112,8 @@ public class StateMachine {
142 142
 		sk.append("-");
143 143
 		sk.append(type.asXmlValue());
144 144
 		sk.append("-");
145
-		sk.append(changes.version);
146
-
147
-		if (type == ItemDataType.EMAIL) {
148
-			sk.append("-");
149
-			sk.append(changes.highestUid);
150
-			sk.append("-");
151
-			sk.append(changes.lowestUid);
152
-		}
145
+		sk.append(version);
153 146
 
154 147
 		return sk.toString();
155 148
 	}
156
-
157
-	public String generateSyncKey(ItemDataType type, FolderChanges changes) {
158
-
159
-		StringBuilder sk = new StringBuilder(64);
160
-
161
-		sk.append(System.currentTimeMillis());
162
-		sk.append("-");
163
-		sk.append(type.asXmlValue());
164
-		sk.append("-");
165
-		sk.append(changes.version);
166
-
167
-		return sk.toString();
168
-	}
169
-
170
-	public String generateSyncKey(SyncState st) {
171
-		StringBuilder sk = new StringBuilder(64);
172
-
173
-		sk.append(System.currentTimeMillis());
174
-		sk.append("-");
175
-		sk.append(st.type.asXmlValue());
176
-		sk.append("-");
177
-		sk.append(st.version);
178
-
179
-		if (st.type == ItemDataType.EMAIL) {
180
-			sk.append("-");
181
-			sk.append(st.highestUid);
182
-			sk.append("-");
183
-			sk.append(st.lowestUid);
184
-		}
185
-
186
-		return sk.toString();
187
-	}
188
-
189 149
 }