Search in sources :

Example 6 with AdminEmailComposePageData

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);
}
Also used : Text(com.google.appengine.api.datastore.Text) AdminEmailComposePageData(teammates.ui.pagedata.AdminEmailComposePageData) AdminEmailAttributes(teammates.common.datatransfer.attributes.AdminEmailAttributes) StatusMessage(teammates.common.util.StatusMessage)

Example 7 with AdminEmailComposePageData

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);
}
Also used : BlobKey(com.google.appengine.api.blobstore.BlobKey) InvalidParametersException(teammates.common.exception.InvalidParametersException) Text(com.google.appengine.api.datastore.Text) AdminEmailComposePageData(teammates.ui.pagedata.AdminEmailComposePageData) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) InvalidParametersException(teammates.common.exception.InvalidParametersException) StatusMessage(teammates.common.util.StatusMessage)

Aggregations

AdminEmailComposePageData (teammates.ui.pagedata.AdminEmailComposePageData)7 AdminEmailAttributes (teammates.common.datatransfer.attributes.AdminEmailAttributes)3 StatusMessage (teammates.common.util.StatusMessage)3 BlobKey (com.google.appengine.api.blobstore.BlobKey)2 Text (com.google.appengine.api.datastore.Text)2 Test (org.testng.annotations.Test)2 ShowPageResult (teammates.ui.controller.ShowPageResult)2 BlobInfo (com.google.appengine.api.blobstore.BlobInfo)1 IOException (java.io.IOException)1 List (java.util.List)1 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)1 InvalidParametersException (teammates.common.exception.InvalidParametersException)1 AdminEmailComposePageAction (teammates.ui.controller.AdminEmailComposePageAction)1 AdminEmailComposeSaveAction (teammates.ui.controller.AdminEmailComposeSaveAction)1 FileUploadPageData (teammates.ui.pagedata.FileUploadPageData)1