com.etcc.csc.presentation.action.ContactUsSubmitAction.java Source code

Java tutorial

Introduction

Here is the source code for com.etcc.csc.presentation.action.ContactUsSubmitAction.java

Source

package com.etcc.csc.presentation.action;

import com.etcc.csc.common.Constants;
import com.etcc.csc.common.DelegateEnum;
import com.etcc.csc.common.DelegateFactory;
import com.etcc.csc.dto.AccountLoginDTO;
import com.etcc.csc.service.AppInterface;
import com.etcc.csc.util.SessionUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.validator.DynaValidatorForm;

public class ContactUsSubmitAction extends Action {

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        DynaValidatorForm dynaForm = (DynaValidatorForm) form;
        String driversLicense = null;
        String licensePlate = null;
        String accountNumber = null;
        String replyAddress = dynaForm.getString("replyAddress");
        String topic = StringUtils.trimToEmpty(dynaForm.getString("topic"));
        Boolean is121Comment = (Boolean) dynaForm.get("is121Comment");
        Boolean updateEmail = (Boolean) dynaForm.get("updateEmail");
        String localeStr = SessionUtil.getStrutsLocaleLang(request);
        if (StringUtils.isBlank(topic)) {
            topic = "General";
        }
        String comment = dynaForm.getString("comment");
        if (topic.equals("Account") || topic.equals("Violation") || topic.equals("ZipCash")) {
            driversLicense = dynaForm.getString("driversLicense");
            licensePlate = dynaForm.getString("licensePlate");
            accountNumber = dynaForm.getString("accountNumber");
            if (driversLicense != null && driversLicense.length() > 0) {
                comment = comment + "   Drivers License:" + driversLicense;
            } else {
                comment = comment + "   Drivers License:Not Provided.";
            }
            if (licensePlate != null && licensePlate.length() > 0) {
                comment = comment + "  License Plate:" + licensePlate;
            } else {
                comment = comment + "  License Plate:Not Provided.";
            }
            if (accountNumber != null && accountNumber.length() > 0) {
                comment = comment + "  Account Number:" + accountNumber;
            } else {
                comment = comment + "  Account Number:Not Provided.";
            }
        }

        AccountLoginDTO accountLogin = SessionUtil.getSessionAccountLogin(request.getSession());
        long docId = -1;
        String docType = null;
        String licState = null;
        String licPlate = null;
        String dbSessionId = null;
        if (accountLogin != null) {
            docType = accountLogin.getLoginType();
            if (docType != null) {
                if (docType.equalsIgnoreCase(Constants.LOGIN_TYPE_INVOICE)) {
                    docId = accountLogin.getInvoiceId();
                } else if ((docType.equalsIgnoreCase(Constants.LOGIN_TYPE_ACCOUNT) || docType == null)
                        && accountLogin.getAcctId() > 0) {
                    docId = accountLogin.getAcctId();
                    docType = Constants.LOGIN_TYPE_ACCOUNT;
                }
                licState = accountLogin.getLicState();
                if (topic.equals("Account") || topic.equals("Violation") || topic.equals("ZipCash")) {
                    if (licensePlate != null && licensePlate.length() > 0) {
                        licPlate = licensePlate;
                    }
                } else {
                    if (accountLogin.getLicPlate() != null && accountLogin.getLicPlate().length() > 0)
                        licPlate = accountLogin.getLicPlate();
                }
            }

            dbSessionId = accountLogin.getDbSessionId();
        }
        AppInterface ai = (AppInterface) DelegateFactory.create(DelegateEnum.APP_DELEGATE);
        boolean submitted = ai.contactUs(docId, docType, licState, licPlate, replyAddress, topic, comment,
                dbSessionId, is121Comment, updateEmail, localeStr);

        if (submitted) {
            request.setAttribute("contactUsResult", "true");
            return mapping.findForward("success");
        } else

            return mapping.findForward("failure");
    }
}