Browse code

BM-14829 Fix: add error message to failed events

Thomas Fricker authored on 27/05/2019 15:57:14
Showing 1 changed files
... ...
@@ -106,9 +106,13 @@ public class AuditLogCommand implements ICmdLet, Runnable {
106 106
 
107 107
 	private String process(List<String> content) {
108 108
 		List<Tblrow> tblData = new ArrayList<>();
109
-		for (String line : content) {
109
+		boolean lastLineFailed = false;
110
+
111
+		for (int i = 0; i < content.size(); i++) {
112
+			String line = content.get(i);
113
+			String next = content.size() > (i + 1) ? content.get(i + 1) : "";
110 114
 			if (!line.trim().isEmpty()) {
111
-				processLine(tblData, line);
115
+				lastLineFailed = processLine(tblData, line, next, lastLineFailed);
112 116
 			}
113 117
 		}
114 118
 
... ...
@@ -121,43 +125,47 @@ public class AuditLogCommand implements ICmdLet, Runnable {
121 125
 		return table;
122 126
 	}
123 127
 
124
-	private void processLine(List<Tblrow> tblData, String line) {
128
+	private boolean processLine(List<Tblrow> tblData, String line, String nextLine, boolean lastLineFailed) {
125 129
 		// replace encoded \" and \\" in the json structure
126 130
 		line = line.replace("\\\\\\\"", "");
127 131
 		line = line.replace("\\\"", "\"");
128 132
 		line = replaceMemberGroup(line);
129 133
 		Matcher m = pattern.matcher(line);
134
+		boolean success = true;
130 135
 		if (!m.matches()) {
131
-			tblData.add(new Tblrow("", "", "", "", "", "Line does not match audit pattern: " + line, "", "",
132
-					Collections.emptyList()));
136
+			if (!lastLineFailed) {
137
+				tblData.add(new Tblrow("", "", "", "", "", "Line does not match audit pattern: " + line, "", "",
138
+						Collections.emptyList()));
139
+			}
140
+			return true;
133 141
 		} else {
134 142
 			List<String> additionalData = new ArrayList<>();
135 143
 			String actionPart = m.group(5);
144
+			String type = m.group(3);
136 145
 			String itemUid = "";
137 146
 			Optional<String> itemParam = getParam(actionPart, "item-uid");
138 147
 			if (itemParam.isPresent()) {
139 148
 				itemUid = itemParam.get();
140 149
 				if (!StringUtil.isNullOrEmpty(eventUid) && !itemUid.equals(eventUid)) {
141
-					return;
150
+					return success(type);
142 151
 				}
143 152
 			} else {
144 153
 				if (!StringUtil.isNullOrEmpty(eventUid)) {
145
-					return;
154
+					return success(type);
146 155
 				}
147 156
 			}
148 157
 			if (!readOnly && actionPart.contains("ro:true")) {
149
-				return;
158
+				return !success(type);
150 159
 			}
151 160
 			String action = getAction(actionPart);
152 161
 			if (filteredActionSet.contains(action)) {
153
-				return;
162
+				return !success(type);
154 163
 			}
155 164
 			if (action.equals("send-mail")) {
156 165
 				additionalData.add("mailto:" + getParam(actionPart, "mailTo").get());
157 166
 			}
158 167
 			getParam(actionPart, "sendNotif").ifPresent(n -> additionalData.add("Send-Notification:" + n));
159 168
 			String date = formatDate(m.group(1) + " " + m.group(2));
160
-			String type = m.group(3);
161 169
 			String actor = formatActor(m.group(4));
162 170
 			String actionData = "";
163 171
 			boolean showData = data;
... ...
@@ -167,18 +175,23 @@ public class AuditLogCommand implements ICmdLet, Runnable {
167 175
 			}
168 176
 			actionData = formatAction(action, actionPart);
169 177
 			if (!StringUtil.isNullOrEmpty(eventQuery) && !((actionPart + actionData).contains(eventQuery))) {
170
-				return;
178
+				return !success(type);
171 179
 			}
172 180
 
173 181
 			String result = m.group(7);
174 182
 			String entity = formatEntity(m.group(6));
175 183
 			if (!StringUtil.isNullOrEmpty(calendarQuery) && !entity.contains(calendarQuery)) {
176
-				return;
184
+				return !success(type);
185
+			}
186
+			success = success(type);
187
+			if (!success) {
188
+				actionData = nextLine;
189
+				showData = true;
177 190
 			}
178 191
 			tblData.add(new Tblrow(date, type, actor, itemUid, action, showData ? actionData : "", result, entity,
179 192
 					additionalData));
180 193
 		}
181
-
194
+		return !success;
182 195
 	}
183 196
 
184 197
 	private String formatAction(String action, String actionPart) {
... ...
@@ -194,6 +207,10 @@ public class AuditLogCommand implements ICmdLet, Runnable {
194 207
 
195 208
 	}
196 209
 
210
+	private boolean success(String type) {
211
+		return type.equals("INFO");
212
+	}
213
+
197 214
 	private String extractChangesValue(String actionPart) {
198 215
 		return jsonPart(actionPart, "changes", 8, null, 0);
199 216
 	}