Example usage for org.springframework.transaction.support DefaultTransactionDefinition setName

List of usage examples for org.springframework.transaction.support DefaultTransactionDefinition setName

Introduction

In this page you can find the example usage for org.springframework.transaction.support DefaultTransactionDefinition setName.

Prototype

public final void setName(String name) 

Source Link

Document

Set the name of this transaction.

Usage

From source file:com.krawler.spring.crm.leadModule.crmLeadCommonController.java

public ModelAndView acceptweblead(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    String result = "Problem while handling your request.";
    //Create transaction
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("JE_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
    TransactionStatus status = txnManager.getTransaction(def);
    try {/*  w ww .jav a2  s  .  c  o m*/
        String userid = request.getParameter("userid");
        String leadid = request.getParameter("leadid");
        boolean isAlreadyAssigned = crmLeadDAOObj.checkWebLeadAssignedOwner(leadid);
        String replaceStr = "<p id='unsubContent'><p>Lead has been successfully allocated to you and can be viewed in your lead list.</p>";
        String headerContent = "<head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'>"
                + "<title>New Web Lead</title>" + "<style type='text/css'>"
                + "body {font-family: 'trebuchet MS', tahoma, verdana, arial, helvetica, sans-serif;"
                + "background-color: #eee;margin: 0;} "
                + "#content {width: 100%;position:absolute;padding:20px;top:5%;}"
                + ".content {width: 600px;margin:auto;padding:20px;border:10px solid #ccc;background-color: white;}"
                + ".alert {font-size:20px;line-height:200%;font-family:Arial;font-weight:bold;}"
                + "p, label, .formText {line-height:150%;font-family:Arial;font-size: 14px;color: #333333;}"
                + "</style>" + "</head>";

        if (isAlreadyAssigned) {
            replaceStr = "<p id='unsubContent'><p>Sorry, lead cannot be allocated as it has been already allocated to a different team member.</p>";
        } else {
            String oldOwnerId = crmLeadDAOObj.confirmWebLeadOwner(leadid, userid);
            if (!StringUtil.isNullOrEmpty(oldOwnerId) && !oldOwnerId.equals(userid)) {
                User oldOwner = (User) kwlCommonTablesDAOObj.getClassObject("com.krawler.common.admin.User",
                        oldOwnerId);
                User newOwner = (User) kwlCommonTablesDAOObj.getClassObject("com.krawler.common.admin.User",
                        userid);
                CrmLead lead = (CrmLead) kwlCommonTablesDAOObj
                        .getClassObject("com.krawler.crm.database.tables.CrmLead", leadid);
                String recipients = oldOwner.getEmailID();
                String subject = oldOwner.getCompany().getCompanyName()
                        + " CRM - Web lead has been allocated to " + StringUtil.getFullName(newOwner);
                String mailbodyContent = "Hi %s,<p>Following web lead has been allocated to %s</p><p>Lead Name: %s</p><p>Phone Number: %s</p>"
                        + "<p>Email Address: %s</p><p>Please Note that lead will not be displayed in your list.</p>"
                        + "<p></p><p>- Thanks,</p><p>Administrator</p>";
                String mailbody = String.format(mailbodyContent, StringUtil.getFullName(oldOwner),
                        StringUtil.getFullName(newOwner),
                        (lead.getFirstname() + " " + lead.getLastname()).trim(), lead.getPhone(),
                        lead.getEmail());
                String htmlmsg = "<html><head><link rel='shortcut icon' href='../../images/deskera/deskera.png'/><title>New Web Lead</title></head><style type='text/css'>"
                        + "a:link, a:visited, a:active {\n" + "    color: #03C;" + "}\n" + "body {\n"
                        + "   font-family: Arial, Helvetica, sans-serif;" + "   color: #000;"
                        + "   font-size: 13px;" + "}\n" + "</style><body>" + "   <div>" + mailbody
                        + "   </div></body></html>";
                String pmsg = htmlmsg;
                String fromAddress = newOwner.getCompany().getCreator().getEmailID();
                SendMailHandler.postMail(new String[] { recipients }, subject, htmlmsg, pmsg, fromAddress, "");
            }
        }

        String bodyContent = "<body>" + "<div id='content'><div id=unsubThankYouPage class='content'>"
                + "<div class='alert' id='unsubTitle'>New Web Lead</div>" + replaceStr + "</p></div></div>"
                + "</div>" + "</body>";
        result = "<html><link rel='shortcut icon' href='../../images/deskera/deskera.png'/>" + headerContent
                + bodyContent + "</html>";
        txnManager.commit(status);
    } catch (Exception e) {
        txnManager.rollback(status);
        logger.warn(e.getMessage(), e);
        e.printStackTrace();
    }
    return new ModelAndView("chartView", "model", result);
}

From source file:com.krawler.spring.crm.leadModule.crmLeadCommonController.java

public ModelAndView storeLead(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    String result = "Problem while submitting your form.";
    HashMap model = new HashMap();
    Map paramMap1 = (java.util.Map) request.getParameterMap();
    HashMap paramMap = new HashMap();
    User user = null;//  w  ww.  ja va2  s .  c  om
    User sender = null;
    // Create transaction
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("JE_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
    TransactionStatus status = txnManager.getTransaction(def);
    try {
        model.put("successFlag", "1");
        model.put("redirectFlag", "0");
        String successMsg = "Thank you for submitting your information.";
        String val = "";
        int mtyfieldCntr = 0;
        Set arrayKeys = paramMap1.keySet();
        HashMap fieldMap = new HashMap();
        JSONObject fieldJSON = null;
        if (!StringUtil.isNullOrEmpty(request.getParameter("fieldJSON"))) {
            try {
                fieldJSON = new JSONObject(request.getParameter("fieldJSON"));
            } catch (JSONException je) {
                logger.warn("crmLeadCommonController.storeLead :- " + je.getMessage());
            } finally {
                fieldJSON = null;
            }
        }

        HashMap<String, Object> mailFieldsMap = new HashMap<String, Object>();
        HashMap<String, Object> mailValueMap = new HashMap<String, Object>();
        for (Object key : arrayKeys) {
            if (((String) key).startsWith("wl_")) {
                fieldMap.put(key, paramMap1.get((String) key) != null
                        ? new String[] {
                                StringUtil.serverHTMLStripper(((String[]) paramMap1.get((String) key))[0]) }
                        : null);
                if (paramMap1.get((String) key) != null) {
                    val = StringUtil.serverHTMLStripper(((String[]) paramMap1.get((String) key))[0]);
                    if (val.trim().equals("")) {
                        mtyfieldCntr++;
                    }
                }
            }
        }
        if (mtyfieldCntr != fieldMap.size()) {
            paramMap.putAll(paramMap1);
            paramMap.putAll(fieldMap);
            String subdomain = URLUtil.getDomainName(request);
            String companyid = companyDetailsDAOObj.getCompanyid(subdomain);
            Company company = (Company) kwlCommonTablesDAOObj.getClassObject("com.krawler.common.admin.Company",
                    companyid);
            sender = company.getCreator();
            String acceptURL = URLUtil.getRequestPageURL(request, Links.UnprotectedLoginPageFull)
                    + "crm/common/acceptweblead.do";
            int leadRoutingUser = 0;
            CompanyPreferences cmpPref = (CompanyPreferences) kwlCommonTablesDAOObj
                    .getClassObject("com.krawler.crm.database.tables.CompanyPreferences", companyid);
            JSONObject companyPrefObj = crmManagerCommon.getCompanyPreferencesJSON(cmpPref, new JSONObject());
            user = (User) kwlCommonTablesDAOObj.getClassObject("com.krawler.common.admin.User",
                    ((String[]) paramMap.get("leadOwner"))[0]);
            if (companyPrefObj.getInt(
                    com.krawler.common.util.Constants.SESSION_LEADROUTING) == LeadRoutingUsers.ROUNDROBIN) {
                user = crmManagerDAOObj.getNextLeadRoutingUsers(companyid).get(0);
                leadRoutingUser = LeadRoutingUsers.ROUNDROBIN;
            }
            if (companyPrefObj
                    .getInt(com.krawler.common.util.Constants.SESSION_LEADROUTING) == LeadRoutingUsers.FCFS) {
                leadRoutingUser = LeadRoutingUsers.FCFS;
            }

            JSONObject resultObj = webtoLeadFormHandlerObj.storeLead(paramMap, companyid, user.getUserID(),
                    acceptURL, leadRoutingUser);

            result = resultObj.optString("msg", result);
            if (!result.equals("Success")) {
                successMsg = result;
                model.put("successFlag", "0");
                txnManager.rollback(status);
            } else {
                CrmLead l = (CrmLead) hibernateTemplate.get(CrmLead.class, resultObj.getString("leadid"));
                if (fieldJSON != null) {
                    Iterator itr = fieldJSON.keys();
                    String keyStr = "";
                    String tmp = "";
                    String str = "";
                    String tmpAr = "";
                    int xtype = 999;
                    String[] valuesArr = null;
                    DefaultMasterItem defItem = null;
                    FieldComboData fieldCombodata = null;
                    Object invoker = null;
                    Class cl = null;
                    CrmLeadCustomData lcdata = null;
                    Method setter = null;
                    List<String> tmpProductlist = new ArrayList<String>();
                    while (itr.hasNext()) {
                        keyStr = (String) itr.next();
                        mailFieldsMap.put(keyStr, fieldJSON.get(keyStr));
                    }

                    for (String tmpStr : mailFieldsMap.keySet()) {
                        if (tmpStr.endsWith("_DROPDOWN#")) {
                            str = tmpStr;
                            str = str.replace("_DROPDOWN#", "");
                            if (tmpStr.startsWith("custom_field")) {
                                str = str.replace("custom_field", "");
                                if (paramMap.get("wl_custom_field" + str) != null) {
                                    fieldCombodata = (FieldComboData) kwlCommonTablesDAOObj.getClassObject(
                                            "com.krawler.common.admin.FieldComboData",
                                            ((String[]) paramMap.get("wl_custom_field" + str))[0]);
                                    if (fieldCombodata == null) { //Custom reference combo check- Since some   custom column may have reference of default combos.
                                        defItem = (DefaultMasterItem) kwlCommonTablesDAOObj.getClassObject(
                                                "com.krawler.crm.database.tables.DefaultMasterItem",
                                                ((String[]) paramMap.get("wl_custom_field" + str))[0]);
                                        if (defItem != null) {
                                            mailValueMap.put(tmpStr, defItem.getValue());
                                        }
                                    } else {
                                        FieldParams fieldParamObj = fieldCombodata.getField();
                                        xtype = fieldParamObj.getFieldtype();
                                        if (xtype == 7) { // for Multi select dropdown
                                            if (request.getParameterValues("wl_custom_field" + str) != null) {
                                                valuesArr = request.getParameterValues("wl_custom_field" + str);
                                                tmp = "";
                                                tmpAr = "";
                                                for (int i = 0; i < valuesArr.length; i++) {
                                                    fieldCombodata = (FieldComboData) kwlCommonTablesDAOObj
                                                            .getClassObject(
                                                                    "com.krawler.common.admin.FieldComboData",
                                                                    valuesArr[i]);
                                                    if (i == valuesArr.length - 1) {
                                                        tmp += fieldCombodata.getValue();
                                                        tmpAr += valuesArr[i];
                                                    } else {
                                                        tmp += fieldCombodata.getValue() + ",";
                                                        tmpAr += valuesArr[i] + ",";
                                                    }
                                                }
                                                mailValueMap.put(tmpStr, tmp);
                                                //Since multiselect combo list has not been saved becoz parammap contains only single value as there are multiple values selected
                                                if (((String[]) paramMap.get(
                                                        "wl_custom_field" + str)).length < valuesArr.length) {
                                                    try {
                                                        lcdata = l.getCrmLeadCustomDataobj();
                                                        cl = Class.forName(
                                                                "com.krawler.crm.database.tables.CrmCustomData");
                                                        invoker = (Object) lcdata;
                                                        setter = cl.getMethod(
                                                                "setCol" + fieldParamObj.getColnum(),
                                                                String.class);
                                                        setter.invoke(invoker, tmpAr);
                                                        l.setCrmLeadCustomDataobj((CrmLeadCustomData) invoker);
                                                    } catch (Exception e) {
                                                        logger.warn(e.getMessage());
                                                    }
                                                }
                                            } else
                                                mailValueMap.put(tmpStr, "");
                                        } else {
                                            fieldCombodata = (FieldComboData) kwlCommonTablesDAOObj
                                                    .getClassObject("com.krawler.common.admin.FieldComboData",
                                                            ((String[]) paramMap
                                                                    .get("wl_custom_field" + str))[0]);
                                            mailValueMap.put(tmpStr, fieldCombodata.getValue());
                                        }
                                    }
                                } else {
                                    mailValueMap.put(tmpStr, "");
                                }
                            } else if (tmpStr.startsWith("productid")) {
                                if (request.getParameterValues("wl_" + str) != null) {
                                    valuesArr = request.getParameterValues("wl_" + str);
                                    tmp = "";
                                    for (int n = 0; n < valuesArr.length; n++) {
                                        if (!tmpProductlist.isEmpty()) {
                                            tmpProductlist.remove(0);
                                        }
                                        tmpProductlist.add(valuesArr[n]);
                                        tmp += ((crmProductDAOObj.getProducts(tmpProductlist)).get(0))
                                                .getProductname() + ",";
                                    }
                                    tmp = tmp.substring(0, tmp.lastIndexOf(','));
                                    mailValueMap.put(tmpStr, tmp);
                                    if (((String[]) paramMap.get("wl_productid")).length < valuesArr.length) {
                                        //Since products list has not been saved becoz parammap contains only single value as there are multiple values selected
                                        try {
                                            crmLeadDAOObj.saveLeadProducts(new String[] { l.getLeadid() },
                                                    valuesArr);
                                        } catch (Exception ex) {
                                            logger.warn(ex.getMessage());
                                        }
                                    }
                                } else
                                    mailValueMap.put(tmpStr, "");
                            } else if (tmpStr.startsWith("type")) {
                                tmp = ((String[]) paramMap.get("wl_" + str))[0];
                                if (tmp == "1")
                                    mailValueMap.put(tmpStr, "Company");
                                else
                                    mailValueMap.put(tmpStr, "Individual");

                            } else {
                                defItem = (DefaultMasterItem) kwlCommonTablesDAOObj.getClassObject(
                                        "com.krawler.crm.database.tables.DefaultMasterItem",
                                        ((String[]) paramMap.get("wl_" + str))[0]);
                                if (defItem != null)
                                    mailValueMap.put(tmpStr, defItem.getValue());
                                else
                                    mailValueMap.put(tmpStr, "");
                            }
                        } else
                            mailValueMap.put(tmpStr,
                                    ((String[]) paramMap.get("wl_" + tmpStr))[0] != null
                                            ? ((String[]) paramMap.get("wl_" + tmpStr))[0]
                                            : "");
                    }
                }
                String id = java.util.UUID.randomUUID().toString();
                String ipaddr = null;
                if (StringUtil.isNullOrEmpty(request.getHeader("x-real-ip"))) {
                    ipaddr = request.getRemoteAddr();
                } else {
                    ipaddr = request.getHeader("x-real-ip");
                }
                auditTrailDAOObj
                        .insertAuditLog(AuditAction.LEAD_CREATE,
                                ((l.getLastname() == null) ? "" : l.getLastname())
                                        + " - Lead created through Web to Lead Form ",
                                ipaddr, user.getUserID(), id);

                crmCommonDAOObj.validaterecorsingledHB(Constants.MODULE_LEAD, l.getLeadid(), companyid);

                txnManager.commit(status);
                if (resultObj.has("leadid")) {
                    String leadid = resultObj.getString("leadid");
                    if (leadRoutingUser == LeadRoutingUsers.ROUNDROBIN) {
                        crmManagerDAOObj.setLastUsedFlagForLeadRouting(user.getUserID(), companyid);
                        if (fieldJSON != null)
                            sendMailToLeadOwner(user, leadid, mailFieldsMap, mailValueMap);
                        else
                            sendMailToLeadOwner(user, leadid, null, null);
                    } else if (leadRoutingUser == LeadRoutingUsers.FCFS) {
                        List<String> recepients = new ArrayList();
                        KwlReturnObject kmsg = crmManagerDAOObj.getAssignedLeadRoutingUsers(companyid,
                                new HashMap<String, Object>());
                        List<User> userlist = kmsg.getEntityList();
                        for (User userObj : userlist) {
                            recepients.add(userObj.getUserID());
                        }
                        Map refTypeMap = new HashMap();
                        Map refIdMap = new HashMap();
                        refIdMap.put("refid1", leadid);
                        refTypeMap.put("reftype1", Constants.Crm_lead_classpath);
                        HashMap<String, Object> extraParams = new HashMap<String, Object>();
                        extraParams.put(NotificationConstants.LOGINURL, acceptURL);
                        if (recepients.size() > 0) {
                            String platformUrl = ConfigReader.getinstance().get("platformURL");
                            if (platformUrl != null) {
                                getPartnerURL(platformUrl, company, CHANNEL.EMAIL, NOTIFICATIONSTATUS.REQUEST,
                                        company.getCreator().getUserID(), recepients, refIdMap, refTypeMap,
                                        extraParams);
                            } else {
                                extraParams.put(NotificationConstants.PARTNERNAME, company.getCompanyName());
                                sendMailToAssignedLeadRoutingUsers(CHANNEL.EMAIL, NOTIFICATIONSTATUS.REQUEST,
                                        company.getCreator().getUserID(), recepients, refIdMap, refTypeMap,
                                        extraParams);
                            }
                        }
                    } else {
                        if (fieldJSON != null)
                            sendMailToLeadOwner(user, leadid, mailFieldsMap, mailValueMap);
                        else
                            sendMailToLeadOwner(user, leadid, null, null);
                    }
                }
            }
            model.put("successMsg", successMsg);
            String returnurl = request.getParameter("returnurl");
            if (!StringUtil.isNullOrEmpty(returnurl)) {
                model.put("redirectFlag", "1");
                model.put("returnurl", returnurl);
            }
        } else {
            model.put("successMsg", "Form should not be empty");
            model.put("successFlag", "0");
            txnManager.rollback(status);
        }

    } catch (Exception e) {
        txnManager.rollback(status);
        logger.warn(e.getMessage(), e);
        if (user != null) {
            sender = user;
        }
        if (sender != null) {
            sendMailToLeadOwner(sender, paramMap1);
        }
    }
    return new ModelAndView("captureLead", "model", model);
}

From source file:com.krawler.spring.crm.leadModule.crmLeadCommonController.java

public ModelAndView convertLeads(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    JSONObject myjobj = null;// w  ww.ja  v  a 2s  . co  m
    boolean refNotFoundFlag = false;
    String refNotFoundStr = "";
    KwlReturnObject kmsg = null;
    CrmLead lead = null;
    CrmAccount acc = null;
    CrmOpportunity opp = null;
    String contactid = null;
    boolean b = false;
    //Create transaction
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("JE_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
    TransactionStatus status = txnManager.getTransaction(def);
    JSONObject accModulejObj = new JSONObject();
    JSONObject oppModulejObj = new JSONObject();
    JSONObject contactModulejObj = new JSONObject();
    JSONObject resJson = new JSONObject();
    try {
        Map<String, Object> moduleFields = new HashMap<String, Object>();
        Map<String, Object> columnMappedList = new HashMap<String, Object>();
        JSONArray moduleCustomfieldArray;
        myjobj = new JSONObject();
        myjobj.put("success", false);
        String timeZoneDiff = sessionHandlerImpl.getTimeZoneDifference(request);
        String timeFormatId = sessionHandlerImpl.getUserTimeFormat(request);
        boolean convertedflag = true;
        boolean companyNotifyFlag = sessionHandlerImpl.getCompanyNotifyOnFlag(request);

        // extract ip address
        String ipAddress = SystemUtil.getIpAddress(request);
        String companyid = sessionHandlerImpl.getCompanyid(request);
        if (StringUtil.bNull(request.getParameter("jsondata"))) {
            String userid = sessionHandlerImpl.getUserid(request);
            String conversiontype = " ";
            String jsondata = request.getParameter("jsondata");
            JSONArray jarr = new JSONArray("[" + jsondata + "]");
            JSONObject jobj = jarr.getJSONObject(0);
            String leadid = jobj.getString("leadid");
            CrmLead CrmLeadObj = crmLeadDAOObj.getLead(leadid);
            if (CrmLeadObj == null || CrmLeadObj.getIsconverted().equals("1")) {
                convertedflag = false;
                refNotFoundStr = " Selected lead already converted successfully.";
            }
            if (convertedflag) {

                String accflag = jobj.getString("accflag");
                String conflag = jobj.optString("conflag");
                String oppflag = jobj.getString("oppflag");
                String taskflag = jobj.getString("taskflag");

                Long closingdate = jobj.getLong("closingdate");
                String lastname = jobj.getString("lastname");
                String accountname = jobj.getString("accountname");
                String oppParentaccountid = jobj.getString("oppparentaccountid");
                String oppname = jobj.getString("oppname");
                String oppstageid = jobj.getString("oppstageid");
                String validflag = jobj.getString("validflag");
                String leadType = jobj.getString("type");
                boolean transfer = false;
                String details = "";
                String accid = java.util.UUID.randomUUID().toString();

                // check all mandatory column mapped
                resJson.put("success", true);
                if (accflag.equals("1")) {
                    accModulejObj = getModuleRecord(request, Constants.MODULE_ACCOUNT, companyid, jobj,
                            moduleFields, columnMappedList);
                    checkManadatoryColumnMapped(resJson, Constants.MODULE_ACCOUNT, companyid, moduleFields,
                            columnMappedList);
                }
                if (oppflag.equals("1")) {
                    oppModulejObj = getModuleRecord(request, Constants.MODULE_OPPORTUNITY, companyid, jobj,
                            moduleFields, columnMappedList);
                    // check all mandatory column mapped
                    checkManadatoryColumnMapped(resJson, Constants.MODULE_OPPORTUNITY, companyid, moduleFields,
                            columnMappedList);
                }
                if (conflag.equals("1")) {
                    contactModulejObj = getModuleRecord(request, Constants.MODULE_CONTACT, companyid, jobj,
                            moduleFields, columnMappedList);
                    // check all mandatory column mapped
                    checkManadatoryColumnMapped(resJson, Constants.MODULE_CONTACT, companyid, moduleFields,
                            columnMappedList);
                }
                if (!resJson.getBoolean("success")) {
                    refNotFoundFlag = true;
                    refNotFoundStr = resJson.getString("msg");
                }
                if (!refNotFoundFlag) {
                    // Convert into Account
                    if (accflag.equals("1")) {
                        conversiontype = "1";
                        refNotFoundStr = "";
                        if (accModulejObj.getBoolean("success")) {
                            accModulejObj.put("accountname", accountname);
                            accModulejObj.put("leadid", leadid);
                            accModulejObj.put("companyid", companyid);
                            accModulejObj.put("userid", userid);
                            accModulejObj.put("updatedon", new Date());
                            accModulejObj.put("accountid", accid);
                            accModulejObj.put("validflag", "0");
                            accModulejObj.put("tzdiff", timeZoneDiff);
                            kmsg = crmAccountDAOObj.addAccounts(accModulejObj);

                            moduleCustomfieldArray = accModulejObj.getJSONArray("customfield");
                            if (moduleCustomfieldArray.length() > 0) {
                                KwlReturnObject customDataresult = fieldDataManagercntrl.setcustomdata(
                                        moduleCustomfieldArray, Constants.Crm_account_moduleid, accid,
                                        companyid, true);
                                if (customDataresult != null && customDataresult.getEntityList().size() > 0) {
                                    JSONObject accJObj = new JSONObject();
                                    accJObj.put("accountid", accid);
                                    accJObj.put("CrmAccountCustomDataobj", accid);
                                    accJObj.put("tzdiff", timeZoneDiff);
                                    kmsg = crmAccountDAOObj.editAccounts(accJObj);
                                }
                                //                            fieldManager.storeCustomFields(moduleCustomfieldArray,"account",true,accid,"1");
                            }
                            crmCommentDAOObj.CreateDuplicateComments(leadid, accid);

                            documentConversion(leadid, accid, "4");

                            auditTrailDAOObj.insertAuditLog(AuditAction.ACCOUNT_CREATE,
                                    accountname + " - Account created from Lead - " + lastname, request, accid);
                            acc = (CrmAccount) kmsg.getEntityList().get(0);
                            //Save Account Owner
                            saveAccOwnersFromLead(leadid, accid);
                            details += " Account - [ " + accountname + " ], ";
                            if (oppflag.equals("1")) {
                                transfer = false;
                            } else {
                                transfer = true;
                            }

                            if (leadType.equals("1")) { // checked for Lead Type - if Company then associated contacts must be linked with newly added Account
                                linkLeadsContactsToAccount(leadid, accid, userid, companyid, timeZoneDiff,
                                        ipAddress);
                            }

                        } else {
                            myjobj.put("success", false);
                            refNotFoundStr += "Data not found in Account module for following fields - <BR /> "
                                    + accModulejObj.getString("msg") + "<BR /><BR />";
                            refNotFoundFlag = true;
                        }

                        // Add Activity
                        if (taskflag.equals("1")) {
                            if (StringUtil.bNull(request.getParameter("activitydata"))) {
                                String activityjson = request.getParameter("activitydata");
                                JSONObject activityJSON = new JSONObject(activityjson);
                                activityJSON.put("relatedtoid", Constants.MODULE_ACCOUNT);
                                activityJSON.put("relatedtonameid", accid);
                                String loginURL = URLUtil.getRequestPageURL(request, Links.loginpageFull);
                                String partnerName = sessionHandlerImpl.getPartnerName(request);
                                activityManagementService.saveActivity(companyid, userid, timeFormatId,
                                        timeZoneDiff, ipAddress, activityJSON, companyNotifyFlag, loginURL,
                                        partnerName);
                            }
                        }
                    }

                    String oppid = java.util.UUID.randomUUID().toString();

                    // Convert into Opportunity
                    if (oppflag.equals("1")) {
                        conversiontype = "2";
                        if (oppModulejObj.getBoolean("success")) {
                            oppModulejObj.put("oppid", oppid);
                            oppModulejObj.put("companyid", companyid);
                            oppModulejObj.put("userid", userid);
                            oppModulejObj.put("updatedon", new Date().getTime());
                            oppModulejObj.put("tzdiff", timeZoneDiff);
                            //                    oppJObj.put("createdon", new Date());
                            oppModulejObj.put("leadid", leadid);
                            if (accflag.equals("1")) {
                                oppModulejObj.put("accountnameid", accid);
                            } else {
                                oppModulejObj.put("accountnameid", oppParentaccountid);
                            }
                            //                        String timeFormatId = sessionHandlerImpl.getUserTimeFormat(request);
                            //                        String timeZoneDiff = sessionHandlerImpl.getTimeZoneDifference(request);
                            if (jobj.has("closingdate")) {
                                oppModulejObj.put("closingdate", jobj.getLong("closingdate"));
                            }
                            oppModulejObj.put("validflag", "0");
                            oppModulejObj.put("oppstageid", oppstageid);
                            oppModulejObj.put("currencyid", "0");
                            oppModulejObj.put("oppname", oppname);
                            kmsg = crmOpportunityDAOObj.addOpportunities(oppModulejObj);

                            moduleCustomfieldArray = oppModulejObj.getJSONArray("customfield");
                            if (moduleCustomfieldArray.length() > 0) {
                                //                            fieldManager.storeCustomFields(moduleCustomfieldArray,"opportunity",true,oppid,"5");
                                KwlReturnObject customDataresult = fieldDataManagercntrl.setcustomdata(
                                        moduleCustomfieldArray, Constants.Crm_opportunity_moduleid, oppid,
                                        companyid, true);
                                if (customDataresult != null && customDataresult.getEntityList().size() > 0) {
                                    JSONObject oppJObj = new JSONObject();
                                    oppJObj.put("oppid", oppid);
                                    oppJObj.put("CrmOpportunityCustomDataobj", oppid);
                                    oppJObj.put("tzdiff", timeZoneDiff);
                                    kmsg = crmOpportunityDAOObj.editOpportunities(oppJObj);
                                }
                            }
                            opp = (CrmOpportunity) kmsg.getEntityList().get(0);
                            //Save Opportunity Owner
                            saveOppOwnersFromLead(leadid, oppid);
                            crmCommentDAOObj.CreateDuplicateComments(leadid, oppid);

                            documentConversion(leadid, oppid, "5");

                            auditTrailDAOObj.insertAuditLog(AuditAction.OPPORTUNITY_CREATE,
                                    oppname + " - Opportunity created from Lead - " + lastname, request, oppid);
                            details += "Opportunity [ " + oppname + " ], ";

                            if (accflag.equals("1")) {
                                //  transfer = true;
                            }
                            b = true;
                        } else {
                            myjobj.put("success", false);
                            refNotFoundStr += "Data not found in Opportunity module for following fields - <BR /> "
                                    + oppModulejObj.getString("msg") + "<BR /><BR />";
                            refNotFoundFlag = true;
                        }
                    }

                    // Convert into Contact
                    if (conflag.equals("1")) {
                        if (leadType.equals("0")) { // checked for Lead Type - if Company then don't convert to contact
                            if (contactModulejObj.getBoolean("success")) {
                                //   conversiontype="3";
                                contactModulejObj.put("leadid", leadid);
                                if (accflag.equals("1")) {
                                    contactModulejObj.put("accountid", accid);
                                } else if (oppflag.equals("1")) {
                                    contactModulejObj.put("accountid", oppParentaccountid);
                                }
                                contactModulejObj.put("validflag", "0");

                                // add new contact
                                JSONObject contactJson = contactManagementService.saveContact(companyid, userid,
                                        timeZoneDiff, ipAddress, contactModulejObj);
                                contactid = contactJson.getString("ID");

                                moduleCustomfieldArray = contactModulejObj.getJSONArray("customfield");
                                if (moduleCustomfieldArray.length() > 0) {
                                    //                                fieldManager.storeCustomFields(moduleCustomfieldArray,"contact",true,conid,"6");
                                    KwlReturnObject customDataresult = fieldDataManagercntrl.setcustomdata(
                                            moduleCustomfieldArray, Constants.Crm_contact_moduleid, contactid,
                                            companyid, true);
                                    if (customDataresult != null
                                            && customDataresult.getEntityList().size() > 0) {
                                        JSONObject contactJObj = new JSONObject();
                                        contactJObj.put("contactid", contactid);
                                        contactJObj.put("CrmContactCustomDataobj", contactid);
                                        contactJObj.put("tzdiff", timeZoneDiff);
                                        contactJson = contactManagementService.saveContact(companyid, userid,
                                                timeZoneDiff, ipAddress, contactJObj);
                                    }
                                }

                                //Save Contact Owner
                                saveContactOwnersFromLead(leadid, contactid);
                                //                    auditTrailDAOObj.insertAuditLog(AuditAction.CONTACT_CREATE,
                                //                                    firstname + " " + lastname + " - Contact created from Lead - "+kmsg.getEntityList().getFirstname()+" "+leadd.getLastname(),
                                //                                    request, conid);
                                String firstname = "";
                                String contactName = "";
                                String lName = "";
                                if (contactModulejObj.has("firstname")) {
                                    firstname = contactModulejObj.get("firstname").toString().trim();
                                }
                                if (contactModulejObj.has("lastname")) {
                                    lName = contactModulejObj.get("lastname").toString().trim();
                                }
                                contactName = (firstname + " " + lName).trim();

                                crmCommentDAOObj.CreateDuplicateComments(leadid, contactid);
                                documentConversion(leadid, contactid, "2");

                                auditTrailDAOObj.insertAuditLog(AuditAction.CONTACT_CREATE,
                                        contactName + " - Contact created from Lead - " + lastname, request,
                                        contactid);
                                if (oppflag.equals("1")) {
                                    transfer = false;
                                } else {
                                    transfer = true;
                                }
                                b = true;

                            } else {
                                myjobj.put("success", false);
                                refNotFoundStr += "Data not found in Contact module for following fields - <BR /> "
                                        + contactModulejObj.getString("msg") + "<BR /><BR />";
                                refNotFoundFlag = true;
                            }
                        } else {
                            if (accflag.equals("1")) {
                                accid = acc.getAccountid();
                            } else if (oppflag.equals("1")) {
                                if (opp.getCrmAccount() != null)
                                    accid = opp.getCrmAccount().getAccountid();
                                else
                                    accid = "";
                            } else {
                                accid = "";
                            }
                            updateContacts(leadid, accid, timeZoneDiff, ipAddress);
                        }
                    }

                }
                if (!refNotFoundFlag) {
                    kmsg = crmManagerDAOObj.getMasterIDCompany(companyid, Constants.LEADSTATUSID_QUALIFIED);
                    DefaultMasterItem obj = (DefaultMasterItem) kmsg.getEntityList().get(0);
                    JSONObject leadJObj = new JSONObject();
                    if (transfer) {
                        leadJObj.put("istransfered", "1");
                    }

                    leadJObj.put("leadid", leadid);
                    leadJObj.put("leadstatusid", obj.getID());
                    leadJObj.put("conversiontype", conversiontype);
                    leadJObj.put("leadconversiondate", conversiontype);
                    leadJObj.put("isconverted", "1");
                    leadJObj.put("updatedon", new Date());
                    leadJObj.put("tzdiff", timeZoneDiff);
                    kmsg = crmLeadDAOObj.editLeads(leadJObj);
                    lead = (CrmLead) kmsg.getEntityList().get(0);
                    auditTrailDAOObj.insertAuditLog(AuditAction.LEAD_CONVERT,
                            details + " created by converting Lead - " + lead.getLastname(), request, leadid);
                    b = true;
                    myjobj.put("success", b);
                }
            } // end of if
        }

        if (!refNotFoundFlag && convertedflag) {
            txnManager.commit(status);
            if (acc != null)
                crmCommonDAOObj.validaterecorsingledHB("Account", acc.getAccountid(), companyid);
            if (opp != null)
                crmCommonDAOObj.validaterecorsingledHB("Opportunity", opp.getOppid(), companyid);
            if (contactid != null)
                crmCommonDAOObj.validaterecorsingledHB("Contact", contactid, companyid);
        } else {
            myjobj.put("msg", refNotFoundStr);

            txnManager.rollback(status);
        }
    } catch (JSONException e) {
        txnManager.rollback(status);
        logger.warn(e.getMessage(), e);
    } catch (Exception e) {
        txnManager.rollback(status);
        logger.warn(e.getMessage(), e);
    }
    return new ModelAndView(successView, "model", myjobj.toString());
}

From source file:com.krawler.spring.crm.emailMarketing.crmEmailMarketingController.java

public RedirectView trackUrl(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    String origUrl = request.getParameter("origurl");
    String trackid = request.getParameter("trackid");
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("JE_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
    TransactionStatus status = txnManager.getTransaction(def);
    try {/*from w  ww.j a v  a  2 s .  c o  m*/
        crmEmailMarketingDAOObj.trackUrl(trackid, origUrl, new Date());
        txnManager.commit(status);
    } catch (ServiceException e) {
        logger.warn(e.getMessage(), e);
        txnManager.rollback(status);
    }
    return new RedirectView(origUrl);
}

From source file:com.krawler.spring.crm.emailMarketing.crmEmailMarketingController.java

public ModelAndView checkBounceStatus(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    JSONObject myjobj = new JSONObject();
    KwlReturnObject kmsg = null;/*  www.j a va  2s  . co  m*/
    //Create transaction
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("JE_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
    TransactionStatus status = txnManager.getTransaction(def);
    try {
        myjobj.put("success", false);
        kmsg = bounceHandlerImplObj.checkBounceStatus();
        myjobj.put("success", kmsg.isSuccessFlag());
        txnManager.commit(status);
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
        txnManager.rollback(status);
    }
    return new ModelAndView("jsonView", "model", myjobj.toString());
}

From source file:com.krawler.spring.crm.emailMarketing.crmEmailMarketingController.java

public ModelAndView viewedEmailMarketMail(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    String htmlString = "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\"><head><link rel=\"shortcut icon\" href=\"../../images/deskera/deskera.png\"/></head>";
    //Create transaction
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("JE_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
    TransactionStatus status = txnManager.getTransaction(def);
    try {/* w w w . j  a v a  2  s  .  c  o m*/
        HashMap<String, Object> requestParams = new HashMap<String, Object>();
        requestParams.put("trackid", request.getParameter("trackid"));

        KwlReturnObject kmsg = crmEmailMarketingDAOObj.viewedEmailMarketMail(requestParams);
        txnManager.commit(status);
    } catch (ServiceException e) {
        logger.warn(e.getMessage(), e);
        htmlString = "<div style='font-color:red;'><b>Failed to process request</b></div>";
        txnManager.rollback(status);
    } finally {
        htmlString += "</html>";
    }
    return new ModelAndView("chartView", "model", htmlString);
}

From source file:com.krawler.spring.crm.emailMarketing.crmEmailMarketingController.java

public ModelAndView unsubscribeUserMarketMail(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    String htmlString = "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\"><head><link rel=\"shortcut icon\" href=\"../../images/deskera/deskera.png\"/></head>";
    //Create transaction
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("JE_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
    TransactionStatus status = txnManager.getTransaction(def);
    try {/*from w  w  w .j  a v a 2 s  . co  m*/
        HashMap<String, Object> requestParams = new HashMap<String, Object>();
        requestParams.put("trackid", request.getParameter("trackid"));

        KwlReturnObject kmsg = crmEmailMarketingDAOObj.unsubscribeUserMarketMail(requestParams);
        htmlString += kmsg.getEntityList().get(0).toString();
        txnManager.commit(status);
    } catch (ServiceException e) {
        logger.warn(e.getMessage(), e);
        htmlString = "<div style='font-color:red;'><b>Failed to process request</b></div>";
        txnManager.rollback(status);
    } finally {
        htmlString += "</html>";
    }
    return new ModelAndView("chartView", "model", htmlString);
}

From source file:com.krawler.spring.crm.emailMarketing.crmEmailMarketingController.java

public ModelAndView subscribeUserMarketMail(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    String htmlString = "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\"><head><link rel=\"shortcut icon\" href=\"../../images/deskera/deskera.png\"/></head>";
    //Create transaction
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("JE_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
    TransactionStatus status = txnManager.getTransaction(def);
    try {/*from  w w w.  ja  v a 2s.  c  o  m*/
        HashMap<String, Object> requestParams = new HashMap<String, Object>();
        requestParams.put("trackid", request.getParameter("trackid"));

        KwlReturnObject kmsg = crmEmailMarketingDAOObj.subscribeUserMarketMail(requestParams);
        htmlString += kmsg.getEntityList().get(0).toString();
        txnManager.commit(status);
    } catch (ServiceException e) {
        logger.warn(e.getMessage(), e);
        htmlString = "<div style='font-color:red;'><b>Failed to process request</b></div>";
        txnManager.rollback(status);
    } finally {
        htmlString += "</html>";
    }
    return new ModelAndView("chartView", "model", htmlString);
}

From source file:com.krawler.spring.crm.emailMarketing.crmEmailMarketingController.java

public ModelAndView confirmSubscribeUserMarketMail(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    String htmlString = "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\"><head><link rel=\"shortcut icon\" href=\"../../images/deskera/deskera.png\"/></head>";
    //Create transaction
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("JE_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
    TransactionStatus status = txnManager.getTransaction(def);
    try {/*from   w  w w.j  a  v a2 s  .  c  om*/
        HashMap<String, Object> requestParams = new HashMap<String, Object>();
        requestParams.put("trackid", request.getParameter("trackid"));

        KwlReturnObject kmsg = crmEmailMarketingDAOObj.confirmsubscribeUserMarketMail(requestParams);
        htmlString += kmsg.getEntityList().get(0).toString();
        txnManager.commit(status);
    } catch (ServiceException e) {
        logger.warn(e.getMessage(), e);
        htmlString = "<div style='font-color:red;'><b>Failed to process request</b></div>";
        txnManager.rollback(status);
    } finally {
        htmlString += "</html>";
    }
    return new ModelAndView("chartView", "model", htmlString);
}

From source file:com.krawler.spring.crm.emailMarketing.crmEmailMarketingController.java

public ModelAndView deleteBouncedTargets(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    JSONObject myjobj = null;// ww  w  .j a va2  s . c  o m
    KwlReturnObject kmsg = null;
    //Create transaction
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("JE_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
    TransactionStatus status = txnManager.getTransaction(def);
    try {
        myjobj = new JSONObject();
        myjobj.put("success", false);
        String[] targets = request.getParameter("targets").split(",");
        kmsg = bounceHandlerImplObj.deleteBouncedTargets(targets);
        myjobj.put("success", kmsg.isSuccessFlag());
        txnManager.commit(status);
    } catch (JSONException e) {
        logger.warn(e.getMessage(), e);
        txnManager.rollback(status);
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
        txnManager.rollback(status);
    }
    return new ModelAndView("jsonView", "model", myjobj.toString());
}