use of teammates.common.util.ActivityLogEntry in project teammates by TEAMMATES.
the class AdminActivityLogPageActionTest method verifyActionResult.
private void verifyActionResult(int[][] expectedLogs, String... params) {
AdminActivityLogPageAction action = getAction(params);
ShowPageResult result = getShowPageResult(action);
AdminActivityLogPageData pageData = (AdminActivityLogPageData) result.data;
List<ActivityLogEntry> actualLogs = getLogsFromLogTemplateRows(pageData.getLogs());
verifyLogs(expectedLogs, actualLogs);
}
use of teammates.common.util.ActivityLogEntry in project teammates by TEAMMATES.
the class ActivityLogEntryTest method builder_withNullValues_ignoreNullValues.
@Test
public void builder_withNullValues_ignoreNullValues() {
Builder builder = new Builder(null, null, 10);
builder.withActionResponse(null).withLogId(null).withLogMessage(null).withUserEmail(null).withUserGoogleId(null).withUserName(null).withUserRole(null);
String logMessage = "TEAMMATESLOG|||Unknown|||Unknown|||true|||Unknown|||Unknown|||Unknown" + "|||Unknown|||Unknown|||Unknown";
ActivityLogEntry entry = builder.build();
AssertHelper.assertLogMessageEquals(logMessage, entry.generateLogMessage());
assertEquals(Const.ActivityLog.UNKNOWN, entry.getLogId());
}
use of teammates.common.util.ActivityLogEntry in project teammates by TEAMMATES.
the class ActivityLogEntryTest method logEntry_withMalformationAppLogLine_constructionFail.
@Test
public void logEntry_withMalformationAppLogLine_constructionFail() {
______TS("Fail: log message not in correct format");
AppLogLine appLog = new AppLogLine();
appLog.setLogMessage("TEAMMATESLOG||RANDOM");
ActivityLogEntry entry = ActivityLogEntry.buildFromAppLog(appLog);
assertTrue(entry.generateLogMessage().contains(Const.ActivityLog.MESSAGE_ERROR_LOG_MESSAGE_FORMAT));
String logMessageMalformation = "TEAMMATESLOG|||instructorHome|||Pageload|||true|||Instructor" + "|||UserName|||UserId|||UserEmail|||Message|||URL";
appLog.setLogMessage(logMessageMalformation);
entry = ActivityLogEntry.buildFromAppLog(appLog);
assertTrue(entry.generateLogMessage().contains(Const.ActivityLog.MESSAGE_ERROR_LOG_MESSAGE_FORMAT));
}
use of teammates.common.util.ActivityLogEntry in project teammates by TEAMMATES.
the class AdminActivityLogPageAction method generateStatusMessage.
private void generateStatusMessage(List<String> versionToQuery, AdminActivityLogPageData data, List<ActivityLogEntry> logs, String courseId) {
StringBuilder status = new StringBuilder(500);
status.append("Total Logs gone through in last search: " + totalLogsSearched + "<br>Total Relevant Logs found in last search: " + String.format("%s<br>", logs.size()));
long earliestSearchTime = data.getFromDate();
ActivityLogEntry earliestLogChecked = null;
if (!logs.isEmpty()) {
earliestLogChecked = logs.get(logs.size() - 1);
}
// if the search space is limited to a certain log
if (logs.size() >= RELEVANT_LOGS_PER_PAGE && earliestLogChecked != null) {
earliestSearchTime = earliestLogChecked.getLogTime();
}
ZoneId targetTimeZone = null;
if (data.isPersonSpecified()) {
String targetUserGoogleId = data.getPersonSpecified();
targetTimeZone = getLocalTimeZoneForRequest(targetUserGoogleId, "");
if (targetTimeZone == null && courseId != null && !courseId.isEmpty()) {
// if the user is unregistered, try finding the timezone by course id passed from Search page
targetTimeZone = getLocalTimeZoneForUnregisteredUserRequest(courseId);
}
} else {
targetTimeZone = Const.SystemParams.ADMIN_TIME_ZONE_ID;
}
String timeInAdminTimeZone = TimeHelper.formatActivityLogTime(Instant.ofEpochMilli(earliestSearchTime), Const.SystemParams.ADMIN_TIME_ZONE_ID);
String timeInUserTimeZone = TimeHelper.formatActivityLogTime(Instant.ofEpochMilli(earliestSearchTime), targetTimeZone);
status.append("The earliest log entry checked on <b>" + timeInAdminTimeZone + "</b> in Admin Time Zone (" + Const.SystemParams.ADMIN_TIME_ZONE_ID.getId() + ") and ");
if (targetTimeZone == null) {
status.append(timeInUserTimeZone).append(".<br>");
} else {
status.append("on <b>" + timeInUserTimeZone + "</b> in Local Time Zone (" + targetTimeZone + ").<br>");
}
status.append("Logs are from following version(s): ");
for (int i = 0; i < versionToQuery.size(); i++) {
String version = versionToQuery.get(i).replace('-', '.');
if (i < versionToQuery.size() - 1) {
status.append(version).append(", ");
} else {
status.append(version).append("<br>");
}
}
status.append("All available version(s): ");
GaeVersionApi versionApi = new GaeVersionApi();
List<Version> versionList = versionApi.getAvailableVersions();
for (int i = 0; i < versionList.size(); i++) {
String version = versionList.get(i).toString();
if (i < versionList.size() - 1) {
status.append(version).append(", ");
} else {
status.append(version).append("<br>");
}
}
// the "Search More" button to continue searching from the previous fromDate
status.append("<button class=\"btn-link\" id=\"button_older\" data-next-end-time-to-search=\"" + nextEndTimeToSearch + "\">Search More</button><input id=\"ifShowAll\" type=\"hidden\" value=\"" + data.getShouldShowAllLogs() + "\"/><input id=\"ifShowTestData\" type=\"hidden\" value=\"" + data.getShouldShowTestData() + "\"/>");
String statusString = status.toString();
data.setStatusForAjax(statusString);
statusToUser.add(new StatusMessage(statusString, StatusMessageColor.INFO));
}
use of teammates.common.util.ActivityLogEntry in project teammates by TEAMMATES.
the class AdminActivityLogPageAction method searchLogsWithTimeIncrement.
/**
* Retrieves enough logs within MAX_SEARCH_PERIOD hours.
*/
private List<ActivityLogEntry> searchLogsWithTimeIncrement(AdminLogQuery query, AdminActivityLogPageData data) {
List<ActivityLogEntry> appLogs = new LinkedList<>();
totalLogsSearched = 0;
GaeLogApi logApi = new GaeLogApi();
long startTime = query.getEndTime() - SEARCH_TIME_INCREMENT;
query.setTimePeriod(startTime, query.getEndTime());
for (int i = 0; i < MAX_SEARCH_TIMES; i++) {
if (appLogs.size() >= RELEVANT_LOGS_PER_PAGE) {
break;
}
List<AppLogLine> searchResult = logApi.fetchLogs(query);
List<ActivityLogEntry> filteredLogs = filterLogsForActivityLogPage(searchResult, data);
appLogs.addAll(filteredLogs);
totalLogsSearched += searchResult.size();
query.moveTimePeriodBackward(SEARCH_TIME_INCREMENT);
}
data.setFromDate(query.getStartTime() + SEARCH_TIME_INCREMENT);
nextEndTimeToSearch = query.getEndTime();
return appLogs;
}
Aggregations