use of teammates.common.datatransfer.attributes.AdminEmailAttributes in project teammates by TEAMMATES.
the class AdminEmailAttributesTest method testBuilderWithNullOptionalArguments.
@Test
public void testBuilderWithNullOptionalArguments() {
AdminEmailAttributes attributesWithNullOptionalArguments = AdminEmailAttributes.builder(subject, addressReceiverListString, groupReceiverListFileKey, content).withSendDate(null).withCreateDate(null).withEmailId(null).build();
______TS("valid admin email");
assertTrue("Valid input", attributesWithNullOptionalArguments.isValid());
______TS("success: default values for optional params");
assertEquals(Const.ParamsNames.ADMIN_EMAIL_ID, attributesWithNullOptionalArguments.getEmailId());
assertFalse("Default false for isInTrashBin", attributesWithNullOptionalArguments.isInTrashBin);
assertEquals(Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP, attributesWithNullOptionalArguments.getCreateDate());
assertEquals(null, attributesWithNullOptionalArguments.getSendDate());
}
use of teammates.common.datatransfer.attributes.AdminEmailAttributes in project teammates by TEAMMATES.
the class AdminEmailAttributesTest method testSanitizeForSaving.
@Test
public void testSanitizeForSaving() {
String subjectWithWhitespaces = " subject to be sanitized by removing leading/trailing whitespace ";
Text contentWithWhitespaces = new Text(" content to be sanitized by removing leading/trailing whitespace ");
______TS("valid sanitation of admin email");
AdminEmailAttributes adminEmailAttributes = AdminEmailAttributes.builder(subjectWithWhitespaces, addressReceiverListString, groupReceiverListFileKey, contentWithWhitespaces).withSendDate(date).build();
______TS("success: sanitized whitespace");
adminEmailAttributes.sanitizeForSaving();
assertEquals("subject to be sanitized by removing leading/trailing whitespace", adminEmailAttributes.getSubject());
assertEquals("content to be sanitized by removing leading/trailing whitespace", adminEmailAttributes.getContentValue());
______TS("success: sanitized code block");
adminEmailAttributes.content = new Text("<code>System.out.println(\"Hello World\");</code>");
adminEmailAttributes.sanitizeForSaving();
assertEquals("<code>System.out.println("Hello World");</code>", adminEmailAttributes.getContentValue());
______TS("success: sanitized superscript");
adminEmailAttributes.content = new Text("f(x) = x<sup>2</sup>");
adminEmailAttributes.sanitizeForSaving();
assertEquals("f(x) = x<sup>2</sup>", adminEmailAttributes.getContentValue());
______TS("success: sanitized chemical formula");
adminEmailAttributes.content = new Text("<p>Chemical formula: C<sub>6</sub>H<sub>12</sub>O<sub>6</sub></p>");
adminEmailAttributes.sanitizeForSaving();
assertEquals("<p>Chemical formula: C<sub>6</sub>H<sub>12</sub>O<sub>6</sub></p>", adminEmailAttributes.getContentValue());
______TS("success: sanitized invalid closing tag");
adminEmailAttributes.content = new Text("</td></option></div> invalid closing tags");
adminEmailAttributes.sanitizeForSaving();
assertEquals(" invalid closing tags", adminEmailAttributes.getContentValue());
}
use of teammates.common.datatransfer.attributes.AdminEmailAttributes in project teammates by TEAMMATES.
the class AdminEmailAttributesTest method testBuilderWithDefaultValues.
@Test
public void testBuilderWithDefaultValues() {
______TS("valid admin email");
AdminEmailAttributes attributesWithDefaultValues = AdminEmailAttributes.builder(subject, addressReceiverListString, groupReceiverListFileKey, content).build();
______TS("success: default values for optional params");
assertEquals(Const.ParamsNames.ADMIN_EMAIL_ID, attributesWithDefaultValues.getEmailId());
assertFalse("Default false for isInTrashBin", attributesWithDefaultValues.isInTrashBin);
assertEquals(Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP, attributesWithDefaultValues.getCreateDate());
assertTrue("Valid input", attributesWithDefaultValues.isValid());
}
use of teammates.common.datatransfer.attributes.AdminEmailAttributes in project teammates by TEAMMATES.
the class AdminEmailComposeSendAction method recordNewSentEmail.
private void recordNewSentEmail(String subject, List<String> addressReceiver, List<String> groupReceiver, String content) {
AdminEmailAttributes newDraft = AdminEmailAttributes.builder(subject, addressReceiver, groupReceiver, new Text(content)).withSendDate(Instant.now()).build();
try {
Instant createDate = logic.createAdminEmail(newDraft);
emailId = logic.getAdminEmail(subject, createDate).getEmailId();
} catch (Exception e) {
isError = true;
setStatusForException(e, e.getMessage());
return;
}
statusToAdmin = "Email queued for sending.";
moveJobToGroupModeTaskQueue();
moveJobToAddressModeTaskQueue();
}
use of teammates.common.datatransfer.attributes.AdminEmailAttributes in project teammates by TEAMMATES.
the class BackDoorLogic method removeDataBundle.
public void removeDataBundle(DataBundle dataBundle) {
// Questions and responses will be deleted automatically.
// We don't attempt to delete them again, to save time.
deleteCourses(dataBundle.courses.values());
populateNullStudentProfiles(dataBundle.accounts.values());
accountsDb.deleteAccounts(dataBundle.accounts.values());
for (AdminEmailAttributes email : dataBundle.adminEmails.values()) {
// Retrieve email by subject as fields emailId, createDate cannot be specified by dataBundle.
AdminEmailAttributes emailInDb = adminEmailsDb.getAdminEmailBySubject(email.subject);
// It is expected that email may not be in datastore yet, should fail silently.
if (emailInDb == null) {
continue;
}
adminEmailsDb.deleteEntity(emailInDb);
}
}
Aggregations