use of teammates.ui.pagedata.AdminEmailComposePageData in project teammates by TEAMMATES.
the class AdminEmailComposeSaveAction method execute.
@Override
protected ActionResult execute() {
gateKeeper.verifyAdminPrivileges(account);
AdminEmailComposePageData data = new AdminEmailComposePageData(account, sessionToken);
String emailContent = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_CONTENT);
String subject = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_SUBJECT);
String addressReceiverListString = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS);
String groupReceiverListFileKey = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_GROUP_RECEIVER_LIST_FILE_KEY);
String emailId = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_ID);
addressReceiver.add(addressReceiverListString);
if (groupReceiverListFileKey != null && !groupReceiverListFileKey.isEmpty()) {
groupReceiver.add(groupReceiverListFileKey);
}
boolean isNewDraft = emailId == null;
if (isNewDraft) {
// this is a new email draft, so create a new admin email entity
createAndSaveNewDraft(subject, addressReceiver, groupReceiver, emailContent);
} else {
// currently editing a previous email draft, so we need to update the previous draft
// instead of creating a new admin email entity
// retrieve the previous draft email
AdminEmailAttributes previousDraft = logic.getAdminEmailById(emailId);
if (previousDraft == null) {
// the previous draft is not found (eg. deleted by accident when editing)
createAndSaveNewDraft(subject, addressReceiver, groupReceiver, emailContent);
} else {
// the previous draft exists so simply update it with the latest email info
updatePreviousEmailDraft(previousDraft.getEmailId(), subject, addressReceiver, groupReceiver, emailContent);
}
}
if (isError) {
data.emailToEdit = AdminEmailAttributes.builder(subject, addressReceiver, groupReceiver, new Text(emailContent)).withEmailId(emailId).build();
} else {
statusToAdmin = Const.StatusMessages.EMAIL_DRAFT_SAVED + ": <br>" + "Subject: " + SanitizationHelper.sanitizeForHtml(subject);
statusToUser.add(new StatusMessage(Const.StatusMessages.EMAIL_DRAFT_SAVED, StatusMessageColor.SUCCESS));
}
return createShowPageResult(Const.ViewURIs.ADMIN_EMAIL, data);
}
use of teammates.ui.pagedata.AdminEmailComposePageData in project teammates by TEAMMATES.
the class AdminEmailComposeSendAction method execute.
@Override
protected ActionResult execute() {
gateKeeper.verifyAdminPrivileges(account);
AdminEmailComposePageData data = new AdminEmailComposePageData(account, sessionToken);
String emailContent = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_CONTENT);
String subject = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_SUBJECT);
addressReceiverListString = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS);
isAddressModeOn = addressReceiverListString != null && !addressReceiverListString.isEmpty();
emailId = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_ID);
groupReceiverListFileKey = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_GROUP_RECEIVER_LIST_FILE_KEY);
isGroupModeOn = groupReceiverListFileKey != null && !groupReceiverListFileKey.isEmpty();
if (isGroupModeOn) {
try {
groupReceiver.add(groupReceiverListFileKey);
GoogleCloudStorageHelper.getGroupReceiverList(new BlobKey(groupReceiverListFileKey));
} catch (Exception e) {
isError = true;
setStatusForException(e, "An error occurred when retrieving receiver list, please try again");
}
}
if (isAddressModeOn) {
addressReceiver.add(addressReceiverListString);
try {
checkAddressReceiverString(addressReceiverListString);
} catch (InvalidParametersException e) {
isError = true;
setStatusForException(e);
}
}
if (!isAddressModeOn && !isGroupModeOn) {
isError = true;
statusToAdmin = "Error : No receiver address or file given";
statusToUser.add(new StatusMessage("Error : No receiver address or file given", StatusMessageColor.DANGER));
}
if (isError) {
data.emailToEdit = AdminEmailAttributes.builder(subject, addressReceiver, groupReceiver, new Text(emailContent)).withEmailId(emailId).build();
return createShowPageResult(Const.ViewURIs.ADMIN_EMAIL, data);
}
boolean isEmailDraft = emailId != null && !emailId.isEmpty();
if (isEmailDraft) {
updateDraftEmailToSent(emailId, subject, addressReceiver, groupReceiver, emailContent);
} else {
recordNewSentEmail(subject, addressReceiver, groupReceiver, emailContent);
}
if (isError) {
data.emailToEdit = AdminEmailAttributes.builder(subject, addressReceiver, groupReceiver, new Text(emailContent)).withEmailId(emailId).build();
}
return createShowPageResult(Const.ViewURIs.ADMIN_EMAIL, data);
}
Aggregations