use of teammates.common.util.AdminLogQuery in project teammates by TEAMMATES.
the class AdminEmailLogPageAction method searchEmailLogsWithTimeIncrement.
/**
* Searches enough email logs within MAX_SEARCH_PERIOD hours.
*/
private void searchEmailLogsWithTimeIncrement(AdminEmailLogPageData data) {
List<EmailLogEntry> emailLogs = new LinkedList<>();
List<String> versionToQuery = getVersionsForQuery(data.getVersions());
AdminLogQuery query = new AdminLogQuery(versionToQuery, null, data.getToDate());
int 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 (emailLogs.size() >= LOGS_PER_PAGE) {
break;
}
List<AppLogLine> searchResult = logApi.fetchLogs(query);
List<EmailLogEntry> filteredLogs = filterLogsForEmailLogPage(searchResult, data);
emailLogs.addAll(filteredLogs);
totalLogsSearched += searchResult.size();
query.moveTimePeriodBackward(SEARCH_TIME_INCREMENT);
}
data.setLogs(emailLogs);
long nextEndTimeToSearch = query.getEndTime();
String status = " Total Logs gone through in last search: " + totalLogsSearched + "<br>" + "<button class=\"btn-link\" id=\"button_older\" data-next-end-time-to-search=\"" + nextEndTimeToSearch + "\">Search More</button>";
data.setStatusForAjax(status);
statusToUser.add(new StatusMessage(status, StatusMessageColor.INFO));
}
use of teammates.common.util.AdminLogQuery in project teammates by TEAMMATES.
the class AdminLogQueryTest method testAdminLogQuery.
@Test
public void testAdminLogQuery() {
______TS("Test constructor with parameters");
List<String> versionList = new ArrayList<>();
versionList.add("5-44");
Calendar cal = new GregorianCalendar();
cal.set(1994, Calendar.MAY, 7, 15, 30, 12);
long startTime = cal.getTimeInMillis();
cal.add(Calendar.YEAR, 22);
long endTime = cal.getTimeInMillis();
AdminLogQuery query = new AdminLogQuery(versionList, startTime, endTime);
assertEquals(startTime, query.getStartTime());
assertEquals(endTime, query.getEndTime());
assertNotNull(query.getQuery());
______TS("Test setTimePeriod");
query = new AdminLogQuery(versionList, null, null);
assertEquals(0, query.getStartTime());
assertNotEquals(endTime, query.getStartTime());
query.setTimePeriod(startTime, endTime);
assertEquals(startTime, query.getStartTime());
assertEquals(endTime, query.getEndTime());
assertNotNull(query.getQuery());
}
use of teammates.common.util.AdminLogQuery in project teammates by TEAMMATES.
the class AdminLogQueryTest method testSetQueryWindowBackward.
@Test
public void testSetQueryWindowBackward() {
List<String> versionList = new ArrayList<>();
versionList.add("5-44");
Calendar cal = new GregorianCalendar();
cal.set(2016, 4, 7, 15, 30, 12);
long startTime = cal.getTimeInMillis();
cal.add(Calendar.DATE, 3);
long endTime = cal.getTimeInMillis();
AdminLogQuery query = new AdminLogQuery(versionList, startTime, endTime);
Long fourHours = Long.valueOf(4 * 60 * 60 * 1000);
// 4 hours before endTime
query.moveTimePeriodBackward(fourHours);
long expectedEndTime = startTime - 1;
long expectedStartTime = expectedEndTime - fourHours;
assertEquals(expectedStartTime, query.getStartTime());
assertEquals(expectedEndTime, query.getEndTime());
assertEquals(expectedStartTime, query.getQuery().getStartTimeMillis().longValue());
assertEquals(expectedEndTime, query.getQuery().getEndTimeMillis().longValue());
}
use of teammates.common.util.AdminLogQuery in project teammates by TEAMMATES.
the class AdminEmailLogPageAction method searchEmailLogsWithExactTimePeriod.
/**
* Searches all logs in the time period specified in the query.
*/
private void searchEmailLogsWithExactTimePeriod(AdminEmailLogPageData data) {
List<String> versionToQuery = getVersionsForQuery(data.getVersions());
AdminLogQuery query = new AdminLogQuery(versionToQuery, data.getFromDate(), data.getToDate());
List<AppLogLine> searchResult = new GaeLogApi().fetchLogs(query);
data.setLogs(filterLogsForEmailLogPage(searchResult, data));
long nextEndTimeToSearch = data.getFromDate() - 1;
int totalLogsSearched = searchResult.size();
String status = " Total Logs gone through in last search: " + totalLogsSearched + "<br>" + "<button class=\"btn-link\" id=\"button_older\" data-next-end-time-to-search=\"" + nextEndTimeToSearch + "\">Search More</button>";
data.setStatusForAjax(status);
statusToUser.add(new StatusMessage(status, StatusMessageColor.INFO));
}
use of teammates.common.util.AdminLogQuery 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);
}
Aggregations