Search in sources :

Example 1 with ActivityLogEntry

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);
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) ActivityLogEntry(teammates.common.util.ActivityLogEntry) AdminActivityLogPageAction(teammates.ui.controller.AdminActivityLogPageAction) AdminActivityLogPageData(teammates.ui.pagedata.AdminActivityLogPageData)

Example 2 with ActivityLogEntry

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());
}
Also used : ActivityLogEntry(teammates.common.util.ActivityLogEntry) Builder(teammates.common.util.ActivityLogEntry.Builder) Test(org.testng.annotations.Test)

Example 3 with ActivityLogEntry

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));
}
Also used : ActivityLogEntry(teammates.common.util.ActivityLogEntry) AppLogLine(com.google.appengine.api.log.AppLogLine) Test(org.testng.annotations.Test)

Example 4 with ActivityLogEntry

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));
}
Also used : ActivityLogEntry(teammates.common.util.ActivityLogEntry) ZoneId(java.time.ZoneId) Version(teammates.common.util.Version) GaeVersionApi(teammates.common.util.GaeVersionApi) StatusMessage(teammates.common.util.StatusMessage)

Example 5 with ActivityLogEntry

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;
}
Also used : ActivityLogEntry(teammates.common.util.ActivityLogEntry) AppLogLine(com.google.appengine.api.log.AppLogLine) LinkedList(java.util.LinkedList) GaeLogApi(teammates.common.util.GaeLogApi)

Aggregations

ActivityLogEntry (teammates.common.util.ActivityLogEntry)10 AppLogLine (com.google.appengine.api.log.AppLogLine)4 Test (org.testng.annotations.Test)4 LinkedList (java.util.LinkedList)2 Builder (teammates.common.util.ActivityLogEntry.Builder)2 AdminActivityLogPageData (teammates.ui.pagedata.AdminActivityLogPageData)2 ZoneId (java.time.ZoneId)1 AdminLogQuery (teammates.common.util.AdminLogQuery)1 GaeLogApi (teammates.common.util.GaeLogApi)1 GaeVersionApi (teammates.common.util.GaeVersionApi)1 StatusMessage (teammates.common.util.StatusMessage)1 Version (teammates.common.util.Version)1 AdminActivityLogPageAction (teammates.ui.controller.AdminActivityLogPageAction)1 ShowPageResult (teammates.ui.controller.ShowPageResult)1 AdminActivityLogTableRow (teammates.ui.template.AdminActivityLogTableRow)1