Search in sources :

Example 6 with ActivityLogEntry

use of teammates.common.util.ActivityLogEntry in project teammates by TEAMMATES.

the class ActivityLogEntryTest method logEntry_withAppLogLine_constructSuccessfully.

@Test
public void logEntry_withAppLogLine_constructSuccessfully() {
    ______TS("Success: Generate activityLog from appLogLine (with TimeTaken)");
    String logMessageWithoutTimeTaken = "TEAMMATESLOG|||instructorHome|||Pageload|||true|||Instructor" + "|||UserName|||UserId|||UserEmail|||Message|||URL|||UserId20151019143729608";
    AppLogLine appLog = new AppLogLine();
    appLog.setLogMessage(logMessageWithoutTimeTaken + Const.ActivityLog.FIELD_SEPARATOR + "20");
    ActivityLogEntry entry = ActivityLogEntry.buildFromAppLog(appLog);
    assertEquals(logMessageWithoutTimeTaken, entry.generateLogMessage());
    assertEquals(20, entry.getActionTimeTaken());
    ______TS("Success: Generate activityLog from appLogLine (without TimeTaken)");
    appLog.setLogMessage(logMessageWithoutTimeTaken);
    entry = ActivityLogEntry.buildFromAppLog(appLog);
    assertEquals(logMessageWithoutTimeTaken, entry.generateLogMessage());
    assertEquals(0, entry.getActionTimeTaken());
    ______TS("Success with severe log: timeTaken not in correct format");
    appLog.setLogMessage(logMessageWithoutTimeTaken + Const.ActivityLog.FIELD_SEPARATOR + "random");
    entry = ActivityLogEntry.buildFromAppLog(appLog);
    assertEquals(logMessageWithoutTimeTaken, entry.generateLogMessage());
    assertEquals(0, entry.getActionTimeTaken());
}
Also used : ActivityLogEntry(teammates.common.util.ActivityLogEntry) AppLogLine(com.google.appengine.api.log.AppLogLine) Test(org.testng.annotations.Test)

Example 7 with ActivityLogEntry

use of teammates.common.util.ActivityLogEntry in project teammates by TEAMMATES.

the class ActivityLogEntryTest method builder_validInputs.

@Test
public void builder_validInputs() {
    ______TS("Test generateLogMessage");
    String statusToAdmin = "<span class=\"text-danger\">Error. ActivityLogEntry object is not created " + "for this servlet action.</span><br>Message";
    String logMessage = "TEAMMATESLOG|||instructorHome|||Servlet Action Failure|||true" + "|||Instructor(M)|||Joe|||GoogleIdA|||instructor@email.tmt" + "|||" + statusToAdmin + "|||url.com";
    Builder builder = new Builder("instructorHome", "url.com", 10);
    builder.withActionResponse(Const.ACTION_RESULT_FAILURE).withUserRole(Const.ActivityLog.ROLE_INSTRUCTOR).withUserName("Joe").withUserGoogleId("GoogleIdA").withUserEmail("instructor@email.tmt").withLogMessage(statusToAdmin).withLogId("GoogleIdA@10").withActionTimeTaken(20).withMasqueradeUserRole(true);
    ActivityLogEntry entry = builder.build();
    AssertHelper.assertLogMessageEquals(logMessage, entry.generateLogMessage());
    ______TS("Test getters");
    assertEquals("instructorHome", entry.getActionName());
    assertEquals(Const.ACTION_RESULT_FAILURE, entry.getActionResponse());
    assertEquals(10, entry.getLogTime());
    assertEquals("url.com", entry.getActionUrl());
    assertEquals("Instructor", entry.getUserRole());
    assertTrue(entry.isMasqueradeUserRole());
    assertEquals("GoogleIdA", entry.getUserGoogleId());
    assertEquals("instructor@email.tmt", entry.getUserEmail());
    assertEquals("Joe", entry.getUserName());
    assertEquals("GoogleIdA@10", entry.getLogId());
    assertEquals(20, entry.getActionTimeTaken());
    assertEquals(statusToAdmin, entry.getLogMessage());
    assertTrue(entry.isTestingData());
    assertTrue(entry.getShouldShowLog());
}
Also used : ActivityLogEntry(teammates.common.util.ActivityLogEntry) Builder(teammates.common.util.ActivityLogEntry.Builder) Test(org.testng.annotations.Test)

Example 8 with ActivityLogEntry

use of teammates.common.util.ActivityLogEntry in project teammates by TEAMMATES.

the class AdminActivityLogPageAction method execute.

@Override
protected ActionResult execute() {
    gateKeeper.verifyAdminPrivileges(account);
    AdminActivityLogPageData data = new AdminActivityLogPageData(account, sessionToken);
    String searchTimeOffset = getRequestParamValue("searchTimeOffset");
    if (searchTimeOffset == null) {
        searchTimeOffset = "";
    }
    String logRoleFromAjax = getRequestParamValue("logRole");
    String logGoogleIdFromAjax = getRequestParamValue("logGoogleId");
    // logUnixTimeMillis is the number of milliseconds from the Unix epoch, i.e. independent of time zone
    String logUnixTimeMillis = getRequestParamValue("logUnixTimeMillis");
    boolean isLoadingLocalTimeAjax = logRoleFromAjax != null && logGoogleIdFromAjax != null && logUnixTimeMillis != null;
    if (isLoadingLocalTimeAjax) {
        data.setLogLocalTime(getLocalTimeInfo(logGoogleIdFromAjax, logRoleFromAjax, logUnixTimeMillis));
        return createAjaxResult(data);
    }
    // This parameter determines whether the logs with requests contained in "excludedLogRequestURIs"
    // in AdminActivityLogPageData should be shown. Use "?all=true" in URL to show all logs.
    // This will keep showing all logs despite any action or change in the page unless
    // the page is reloaded with "?all=false" or simply reloaded with this parameter omitted.
    boolean shouldShowAllLogs = getRequestParamAsBoolean("all");
    data.setShowAllLogs(shouldShowAllLogs);
    // This determines whether the logs related to testing data should be shown. Use "testdata=true" in URL
    // to show all testing logs. This will keep showing all logs from testing data despite any action
    // or change in the page unless the page is reloaded with "?testdata=false"
    // or simply reloaded with this parameter omitted.
    boolean shouldShowTestData = getRequestParamAsBoolean("testdata");
    data.setShowTestData(shouldShowTestData);
    String filterQuery = getRequestParamValue("filterQuery");
    if (filterQuery == null) {
        filterQuery = "";
    }
    // This is used to parse the filterQuery. If the query is not parsed, the filter function would ignore the query
    data.generateQueryParameters(filterQuery);
    boolean isContinueFromPreviousSearch = !data.isFromDateSpecifiedInQuery() && !searchTimeOffset.isEmpty();
    if (isContinueFromPreviousSearch) {
        data.setToDate(Long.parseLong(searchTimeOffset));
    }
    List<String> versionToQuery = getVersionsForQuery(data.getVersions());
    AdminLogQuery query = new AdminLogQuery(versionToQuery, data.getFromDate(), data.getToDate());
    List<ActivityLogEntry> logs = null;
    if (data.isFromDateSpecifiedInQuery()) {
        logs = searchLogsWithExactTimePeriod(query, data);
    } else {
        logs = searchLogsWithTimeIncrement(query, data);
    }
    String courseIdFromSearchPage = getRequestParamValue("courseId");
    generateStatusMessage(versionToQuery, data, logs, courseIdFromSearchPage);
    data.init(logs);
    if (searchTimeOffset.isEmpty()) {
        return createShowPageResult(Const.ViewURIs.ADMIN_ACTIVITY_LOG, data);
    }
    return createShowPageResult(Const.ViewURIs.ADMIN_ACTIVITY_LOG_AJAX, data);
}
Also used : ActivityLogEntry(teammates.common.util.ActivityLogEntry) AdminActivityLogPageData(teammates.ui.pagedata.AdminActivityLogPageData) AdminLogQuery(teammates.common.util.AdminLogQuery)

Example 9 with ActivityLogEntry

use of teammates.common.util.ActivityLogEntry in project teammates by TEAMMATES.

the class AdminActivityLogPageAction method filterLogsForActivityLogPage.

/**
 * Filters logs that should be shown on Admin Activity Log Page.
 */
private List<ActivityLogEntry> filterLogsForActivityLogPage(List<AppLogLine> appLogLines, AdminActivityLogPageData data) {
    List<ActivityLogEntry> appLogs = new LinkedList<>();
    for (AppLogLine appLog : appLogLines) {
        String logMsg = appLog.getLogMessage();
        boolean isNotTeammatesLog = !logMsg.contains("TEAMMATESLOG");
        boolean isLogFromAdminActivityLogPage = logMsg.contains("adminActivityLogPage");
        if (isNotTeammatesLog || isLogFromAdminActivityLogPage) {
            continue;
        }
        ActivityLogEntry activityLogEntry = ActivityLogEntry.buildFromAppLog(appLog);
        boolean isToShow = data.filterLog(activityLogEntry) && (!activityLogEntry.isTestingData() || data.getShouldShowTestData());
        if (!isToShow) {
            continue;
        }
        appLogs.add(activityLogEntry);
    }
    return appLogs;
}
Also used : ActivityLogEntry(teammates.common.util.ActivityLogEntry) AppLogLine(com.google.appengine.api.log.AppLogLine) LinkedList(java.util.LinkedList)

Example 10 with ActivityLogEntry

use of teammates.common.util.ActivityLogEntry in project teammates by TEAMMATES.

the class AdminActivityLogPageData method initLogsAsTemplateRows.

private void initLogsAsTemplateRows(List<ActivityLogEntry> entries) {
    logs = new ArrayList<>();
    for (ActivityLogEntry entry : entries) {
        AdminActivityLogTableRow row = new AdminActivityLogTableRow(entry);
        logs.add(row);
    }
}
Also used : ActivityLogEntry(teammates.common.util.ActivityLogEntry) AdminActivityLogTableRow(teammates.ui.template.AdminActivityLogTableRow)

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