Search in sources :

Example 6 with AdminEmailAttributes

use of teammates.common.datatransfer.attributes.AdminEmailAttributes in project teammates by TEAMMATES.

the class AdminEmailsDb method deleteAllEmailsInTrashBin.

/**
 * Deletes all emails in trash bin, related group receiver text file will be removed from
 * Google Cloud Storage.
 */
public void deleteAllEmailsInTrashBin() {
    List<AdminEmailAttributes> emailsInTrashBin = getAdminEmailsInTrashBin();
    for (AdminEmailAttributes a : emailsInTrashBin) {
        if (a.getGroupReceiver() != null) {
            for (String key : a.getGroupReceiver()) {
                BlobKey blobKey = new BlobKey(key);
                deleteAdminEmailUploadedFile(blobKey);
            }
        }
    }
    deleteEntities(emailsInTrashBin);
}
Also used : BlobKey(com.google.appengine.api.blobstore.BlobKey) AdminEmailAttributes(teammates.common.datatransfer.attributes.AdminEmailAttributes)

Example 7 with AdminEmailAttributes

use of teammates.common.datatransfer.attributes.AdminEmailAttributes in project teammates by TEAMMATES.

the class AdminPrepareEmailAddressModeWorkerAction method execute.

@Override
public void execute() {
    log.info("Preparing admin email task queue in address mode...");
    String emailId = getRequestParamValue(ParamsNames.ADMIN_EMAIL_ID);
    Assumption.assertPostParamNotNull(ParamsNames.ADMIN_EMAIL_ID, emailId);
    String addressReceiverListString = getRequestParamValue(ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS);
    Assumption.assertPostParamNotNull(ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, addressReceiverListString);
    AdminEmailAttributes adminEmail = logic.getAdminEmailById(emailId);
    Assumption.assertNotNull(adminEmail);
    List<String> addressList = new ArrayList<>();
    if (addressReceiverListString.contains(",")) {
        addressList.addAll(Arrays.asList(addressReceiverListString.split(",")));
    } else {
        addressList.add(addressReceiverListString);
    }
    for (String emailAddress : addressList) {
        taskQueuer.scheduleAdminEmailForSending(emailId, emailAddress, adminEmail.getSubject(), adminEmail.getContentValue());
    }
}
Also used : ArrayList(java.util.ArrayList) AdminEmailAttributes(teammates.common.datatransfer.attributes.AdminEmailAttributes)

Example 8 with AdminEmailAttributes

use of teammates.common.datatransfer.attributes.AdminEmailAttributes in project teammates by TEAMMATES.

the class AdminSendEmailWorkerAction method execute.

@Override
public void execute() {
    String receiverEmail = getRequestParamValue(ParamsNames.ADMIN_EMAIL_RECEIVER);
    Assumption.assertPostParamNotNull(ParamsNames.ADMIN_EMAIL_RECEIVER, receiverEmail);
    String emailContent = getRequestParamValue(ParamsNames.ADMIN_EMAIL_CONTENT);
    String emailSubject = getRequestParamValue(ParamsNames.ADMIN_EMAIL_SUBJECT);
    if (emailContent == null || emailSubject == null) {
        String emailId = getRequestParamValue(ParamsNames.ADMIN_EMAIL_ID);
        Assumption.assertPostParamNotNull(ParamsNames.ADMIN_EMAIL_ID, emailId);
        log.info("Sending large email. Going to retrieve email content and subject from datastore.");
        AdminEmailAttributes adminEmail = logic.getAdminEmailById(emailId);
        Assumption.assertNotNull(adminEmail);
        emailContent = adminEmail.getContentValue();
        emailSubject = adminEmail.getSubject();
    }
    Assumption.assertNotNull(emailContent);
    Assumption.assertNotNull(emailSubject);
    try {
        EmailWrapper email = new EmailGenerator().generateAdminEmail(emailContent, emailSubject, receiverEmail);
        emailSender.sendEmail(email);
        log.info("Email sent to " + receiverEmail);
    } catch (Exception e) {
        log.severe("Unexpected error while sending admin emails: " + TeammatesException.toStringWithStackTrace(e));
    }
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) TeammatesException(teammates.common.exception.TeammatesException) AdminEmailAttributes(teammates.common.datatransfer.attributes.AdminEmailAttributes) EmailWrapper(teammates.common.util.EmailWrapper)

Example 9 with AdminEmailAttributes

use of teammates.common.datatransfer.attributes.AdminEmailAttributes in project teammates by TEAMMATES.

the class AdminEmailAttributesTest method testValidate.

@Test
public void testValidate() throws Exception {
    ______TS("valid admin email");
    assertTrue("Valid input", validAdminEmailAttributesObject.isValid());
    List<String> errorList = validAdminEmailAttributesObject.getInvalidityInfo();
    assertTrue("Valid input should return an empty list of errors", errorList.isEmpty());
    ______TS("success: subject max length");
    String subjectMaxLenString = StringHelperExtension.generateStringOfLength(FieldValidator.EMAIL_SUBJECT_MAX_LENGTH);
    AdminEmailAttributes validAttributesSubjectLength = AdminEmailAttributes.builder(subjectMaxLenString, addressReceiverListString, groupReceiverListFileKey, content).withSendDate(date).build();
    assertTrue("Valid input", validAttributesSubjectLength.isValid());
    List<String> emailErrorList = validAttributesSubjectLength.getInvalidityInfo();
    assertTrue("Valid input should return an empty list of errors", emailErrorList.isEmpty());
    ______TS("failure: content cannot be empty");
    AdminEmailAttributes invalidAttributesContentEmpty = AdminEmailAttributes.builder(subject, addressReceiverListString, groupReceiverListFileKey, new Text("")).withSendDate(date).build();
    String expectedContentEmptyError = getPopulatedErrorMessage(FieldValidator.EMAIL_CONTENT_ERROR_MESSAGE, invalidAttributesContentEmpty.getContentValue(), FieldValidator.EMAIL_CONTENT_FIELD_NAME, FieldValidator.REASON_EMPTY, 0);
    assertEquals("Invalid content input should return appropriate error string", expectedContentEmptyError, StringHelper.toString(invalidAttributesContentEmpty.getInvalidityInfo()));
    assertFalse("Invalid input", invalidAttributesContentEmpty.isValid());
    ______TS("failure: subject cannot exceeds max length");
    AdminEmailAttributes attributes = validAdminEmailAttributesObject;
    attributes.subject = StringHelperExtension.generateStringOfLength(FieldValidator.EMAIL_SUBJECT_MAX_LENGTH + 1);
    assertEquals(attributes.subject.length(), 201);
    String expectedEmptySubjectLengthError = getInvalidityInfoForSubject(attributes.subject);
    assertEquals("Invalid subject input should return appropriate error string", expectedEmptySubjectLengthError, StringHelper.toString(attributes.getInvalidityInfo()));
    assertFalse("Invalid input", attributes.isValid());
    ______TS("failure: subject must start with alphanumeric character");
    attributes.subject = "_InvalidSubject";
    assertTrue(attributes.subject.startsWith("_"));
    String expectedSubjectCharsError = getInvalidityInfoForSubject(attributes.subject);
    assertEquals("Invalid subject input should return appropriate error string", expectedSubjectCharsError, StringHelper.toString(attributes.getInvalidityInfo()));
    assertFalse("Invalid input", attributes.isValid());
    ______TS("failure: subject cannot contain vertical bar (|)");
    attributes.subject = "Invalid|Subject";
    assertTrue(attributes.subject.contains("|"));
    String expectedSubjectWithBarError = getInvalidityInfoForSubject(attributes.subject);
    assertEquals("Invalid subject input should return appropriate error string", expectedSubjectWithBarError, StringHelper.toString(attributes.getInvalidityInfo()));
    assertFalse("Invalid input", attributes.isValid());
    ______TS("failure: subject cannot contain percent sign(%)");
    attributes.subject = "Invalid%Subject";
    assertTrue(attributes.subject.contains("%"));
    String expectedSubjectWithPercentError = getInvalidityInfoForSubject(attributes.subject);
    assertEquals("Invalid subject input should return appropriate error string", expectedSubjectWithPercentError, StringHelper.toString(attributes.getInvalidityInfo()));
    assertFalse("Invalid input", attributes.isValid());
}
Also used : Text(com.google.appengine.api.datastore.Text) AdminEmailAttributes(teammates.common.datatransfer.attributes.AdminEmailAttributes) Test(org.testng.annotations.Test)

Example 10 with AdminEmailAttributes

use of teammates.common.datatransfer.attributes.AdminEmailAttributes in project teammates by TEAMMATES.

the class AdminEmailAttributesTest method testValueOf.

@Test
public void testValueOf() {
    AdminEmail adminEmail = new AdminEmail(groupReceiverListFileKey, addressReceiverListString, subject, content, date);
    AdminEmailAttributes adminEmailAttributes = AdminEmailAttributes.valueOf(adminEmail);
    assertEquals(adminEmail.getGroupReceiver(), adminEmailAttributes.groupReceiver);
    assertEquals(adminEmail.getAddressReceiver(), adminEmailAttributes.addressReceiver);
    assertEquals(adminEmail.getSubject(), adminEmailAttributes.subject);
    assertEquals(adminEmail.getContent(), adminEmailAttributes.content);
    assertEquals(adminEmail.getSendDate(), adminEmailAttributes.sendDate);
    assertTrue("Valid input", adminEmailAttributes.isValid());
}
Also used : AdminEmail(teammates.storage.entity.AdminEmail) AdminEmailAttributes(teammates.common.datatransfer.attributes.AdminEmailAttributes) Test(org.testng.annotations.Test)

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