Search in sources :

Example 1 with AdminEmailAttributes

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());
}
Also used : AdminEmailAttributes(teammates.common.datatransfer.attributes.AdminEmailAttributes) Test(org.testng.annotations.Test)

Example 2 with AdminEmailAttributes

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(&#34;Hello World&#34;);</code>", adminEmailAttributes.getContentValue());
    ______TS("success: sanitized superscript");
    adminEmailAttributes.content = new Text("f(x) = x<sup>2</sup>");
    adminEmailAttributes.sanitizeForSaving();
    assertEquals("f(x) &#61; 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());
}
Also used : Text(com.google.appengine.api.datastore.Text) AdminEmailAttributes(teammates.common.datatransfer.attributes.AdminEmailAttributes) Test(org.testng.annotations.Test)

Example 3 with AdminEmailAttributes

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());
}
Also used : AdminEmailAttributes(teammates.common.datatransfer.attributes.AdminEmailAttributes) Test(org.testng.annotations.Test)

Example 4 with AdminEmailAttributes

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();
}
Also used : Instant(java.time.Instant) Text(com.google.appengine.api.datastore.Text) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) InvalidParametersException(teammates.common.exception.InvalidParametersException) AdminEmailAttributes(teammates.common.datatransfer.attributes.AdminEmailAttributes)

Example 5 with AdminEmailAttributes

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);
    }
}
Also used : AdminEmailAttributes(teammates.common.datatransfer.attributes.AdminEmailAttributes)

Aggregations

AdminEmailAttributes (teammates.common.datatransfer.attributes.AdminEmailAttributes)17 Test (org.testng.annotations.Test)7 Text (com.google.appengine.api.datastore.Text)5 AdminEmailComposePageData (teammates.ui.pagedata.AdminEmailComposePageData)3 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)2 InvalidParametersException (teammates.common.exception.InvalidParametersException)2 ShowPageResult (teammates.ui.controller.ShowPageResult)2 BlobKey (com.google.appengine.api.blobstore.BlobKey)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 TeammatesException (teammates.common.exception.TeammatesException)1 EmailWrapper (teammates.common.util.EmailWrapper)1 StatusMessage (teammates.common.util.StatusMessage)1 EmailGenerator (teammates.logic.api.EmailGenerator)1 AdminEmail (teammates.storage.entity.AdminEmail)1 AdminEmailComposePageAction (teammates.ui.controller.AdminEmailComposePageAction)1 AdminEmailComposeSaveAction (teammates.ui.controller.AdminEmailComposeSaveAction)1