use of teammates.common.util.ActivityLogEntry.Builder in project teammates by TEAMMATES.
the class LogMessageGenerator method generateActionFailureLogMessage.
/**
* Generates log message for servlet action failure.
*
* @param url URL of the request
* @param params parameterMap of the request
* @param e Exception thrown in the failure
* @param currUser login information generated by {@link teammates.logic.api.GateKeeper}
* @return log message in the form specified in {@link ActivityLogEntry}
*/
public String generateActionFailureLogMessage(String url, Map<String, String[]> params, Exception e, UserType currUser) {
Builder builder = generateBasicLogEntryBuilder(url, params, currUser);
String message = "<span class=\"text-danger\">Servlet Action failure in " + builder.getActionName() + "<br>" + e.getClass() + ": " + TeammatesException.toStringWithStackTrace(e) + "<br>" + JsonUtils.toJson(params, Map.class) + "</span>";
builder.withLogMessage(message);
builder.withActionResponse(Const.ACTION_RESULT_FAILURE);
return builder.build().generateLogMessage();
}
use of teammates.common.util.ActivityLogEntry.Builder 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.Builder in project teammates by TEAMMATES.
the class ActivityLogEntryTest method builder_defaultValues.
@Test
public void builder_defaultValues() {
Builder builder = new Builder("instructorHome", "URL", 10);
String logMessage = "TEAMMATESLOG|||instructorHome|||instructorHome|||true|||Unknown|||Unknown|||Unknown" + "|||Unknown|||Unknown|||URL";
AssertHelper.assertLogMessageEquals(logMessage, builder.build().generateLogMessage());
}
use of teammates.common.util.ActivityLogEntry.Builder 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());
}
use of teammates.common.util.ActivityLogEntry.Builder in project teammates by TEAMMATES.
the class LogMessageGenerator method generateBasicActivityLogMessage.
/**
* Generates log message with basic information.
*
* @param url URL of the request
* @param params parameterMap of the request
* @param message log message to show to admin
* @param currUser login information generated by {@link teammates.logic.api.GateKeeper}
* @return log message in form specified in {@link ActivityLogEntry}
*/
public String generateBasicActivityLogMessage(String url, Map<String, String[]> params, String message, UserType currUser) {
Builder builder = generateBasicLogEntryBuilder(url, params, currUser);
builder.withLogMessage(message);
return builder.build().generateLogMessage();
}
Aggregations