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);
}
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());
}
}
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));
}
}
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());
}
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());
}
Aggregations