Example usage for org.springframework.transaction TransactionDefinition PROPAGATION_REQUIRED

List of usage examples for org.springframework.transaction TransactionDefinition PROPAGATION_REQUIRED

Introduction

In this page you can find the example usage for org.springframework.transaction TransactionDefinition PROPAGATION_REQUIRED.

Prototype

int PROPAGATION_REQUIRED

To view the source code for org.springframework.transaction TransactionDefinition PROPAGATION_REQUIRED.

Click Source Link

Document

Support a current transaction; create a new one if none exists.

Usage

From source file:com.krawler.spring.crm.accountModule.crmAccountController.java

public ModelAndView updateMassAccounts(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    JSONObject myjobj = new JSONObject();
    KwlReturnObject kmsg = null;//from w  w w .  j a v a  2 s . c  o  m
    CrmAccount acc = 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 {
        boolean ownerChanged = false;
        JSONObject jobj = new JSONObject(request.getParameter("jsondata"));
        String userid = sessionHandlerImpl.getUserid(request);
        String accountIds = jobj.getString("accountid");
        String arrayId[] = accountIds.split(",");
        Integer operationCode = CrmPublisherHandler.UPDATERECORDCODE;
        String companyid = sessionHandlerImpl.getCompanyid(request);
        List<CrmAccount> ownerChangedAccounts = null;//new ArrayList<Object>();

        jobj.put("userid", userid);
        jobj.put("companyid", companyid);
        if (jobj.has("updatedon") && !StringUtil.isNullOrEmpty(jobj.getString("updatedon"))) {
            jobj.put("updatedon", jobj.getLong("updatedon"));
        } else {
            jobj.put("updatedon", new Date().getTime());
        }
        jobj.put("accountid", arrayId);
        jobj.put("tzdiff", sessionHandlerImpl.getTimeZoneDifference(request));
        JSONArray jcustomarray = null;
        if (jobj.has("customfield")) {
            jcustomarray = jobj.getJSONArray("customfield");
        }

        if (jobj.optString("accountownerid", null) != null) {
            String newOwnerId = jobj.getString("accountownerid");
            ownerChangedAccounts = crmAccountHandler.getOwnerChangedAccounts(crmAccountDAOObj, arrayId,
                    newOwnerId);
        }

        if (jobj.has("customfield")) {
            HashMap<String, Object> customrequestParams = new HashMap<String, Object>();
            customrequestParams.put("customarray", jcustomarray);
            customrequestParams.put("modulename", Constants.Crm_Account_modulename);
            customrequestParams.put("moduleprimarykey", Constants.Crm_Accountid);
            customrequestParams.put("companyid", companyid);
            customrequestParams.put("customdataclasspath", Constants.Crm_account_custom_data_classpath);
            KwlReturnObject customDataresult = null;
            for (String id : arrayId) {
                customrequestParams.put("modulerecid", id);
                customDataresult = fieldDataManagercntrl.setCustomData(customrequestParams);
            }
            if (customDataresult != null && customDataresult.getEntityList().size() > 0) {
                jobj.put("CrmAccountCustomDataobj", true);
            }
        }

        if (jobj.has("createdon")) {
            jobj.put("createdon", jobj.getLong("createdon"));
        }
        kmsg = crmAccountDAOObj.updateMassAccount(jobj);

        // TODO : How to insert audit log when mass update
        // acc = (CrmAccount) kmsg.getEntityList().get(0);
        // if (acc.getValidflag() == 1) {
        // auditTrailDAOObj.insertAuditLog(AuditAction.ACCOUNT_UPDATE,
        // jobj.getString("auditstr") + " Account - " +
        // ((acc.getAccountname() == null) ? "" : acc.getAccountname()) +
        // " ",
        // request, id);
        // }

        // }

        txnManager.commit(status);
        JSONObject cometObj = jobj;
        if (request.getParameter("massEdit") != null
                && Boolean.parseBoolean(request.getParameter("massEdit"))) {
            crmCommonService.validateMassupdate(arrayId, "Account", companyid);
            cometObj.put("accountid", accountIds);
            cometObj.put("ismassedit", true);
        }

        myjobj.put("success", true);
        myjobj.put("ID", accountIds);
        myjobj.put("createdon", jobj.has("createdon") ? jobj.getLong("createdon") : "");
        if (!StringUtil.isNullObject(acc)) {
            if (!StringUtil.isNullObject(acc.getCreatedon())) {
                cometObj.put("createdon", acc.getCreatedonGMT());
            }
        }

        publishAccountModuleInformation(request, cometObj, operationCode, companyid, userid);

        // TODO  : send Email when owner changed
        if (ownerChangedAccounts != null && ownerChangedAccounts.size() > 0) {// Send Notification if owner changed
            List<String> recepients = new ArrayList<String>();
            recepients.add(jobj.getString("accountownerid"));
            String loginURL = URLUtil.getRequestPageURL(request, Links.loginpageFull);
            HashMap<String, Object> extraParams = new HashMap<String, Object>();
            extraParams.put(NotificationConstants.LOGINURL, loginURL);
            extraParams.put(NotificationConstants.PARTNERNAME, sessionHandlerImpl.getPartnerName(request));
            StringBuffer variableData = new StringBuffer();
            String accname = "";
            String type = "";
            int srno = 0;
            Map refTypeMap = new HashMap();
            Map refIdMap = new HashMap();
            refIdMap.put("refid1", (ownerChangedAccounts.get(0)).getAccountid());
            refTypeMap.put("reftype1", Constants.Crm_account_classpath);
            refIdMap.put("refid2", userid);
            refTypeMap.put("reftype2", Constants.USERS_CLASSPATH);

            if (ownerChangedAccounts.size() > 1) {
                for (CrmAccount accountObj : ownerChangedAccounts) {
                    srno++;
                    accname = !StringUtil.isNullOrEmpty(accountObj.getAccountname())
                            ? accountObj.getAccountname()
                            : "";
                    type = (!StringUtil.isNullObject(accountObj.getCrmCombodataByAccounttypeid()))
                            ? accountObj.getCrmCombodataByAccounttypeid().getValue()
                            : "";
                    variableData.append("<tr>");
                    variableData.append("<td> " + srno + "</td>");
                    variableData.append("<td> " + accname + "</td>");
                    variableData.append("<td> " + type + "</td>");
                    variableData.append("</tr>");
                }
                extraParams.put(Constants.VARIABLEDATA, variableData);
                NotificationManagementServiceDAO.sendNotificationRequest(CHANNEL.EMAIL,
                        ACCOUNT_ASSIGNED_MASS_UPDATE, NOTIFICATIONSTATUS.REQUEST, userid, recepients, refIdMap,
                        refTypeMap, extraParams);
            } else {
                NotificationManagementServiceDAO.sendNotificationRequest(CHANNEL.EMAIL, ACCOUNT_ASSIGNED,
                        NOTIFICATIONSTATUS.REQUEST, userid, recepients, refIdMap, refTypeMap, extraParams);
            }

        }

    } catch (Exception e) {
        logger.warn("Exception while Accoount Mass Update:", e);
        txnManager.rollback(status);
    }
    return new ModelAndView("jsonView", "model", myjobj.toString());
}

From source file:com.krawler.spring.crm.activityModule.crmActivityController.java

public ModelAndView deleteActivity(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    JSONObject myjobj = null;//from  w  w w .j  av  a 2  s. co  m
    KwlReturnObject kmsg = null;
    CrmActivityMaster activity = 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 {
        String userid = sessionHandlerImpl.getUserid(request);
        ArrayList activityids = new ArrayList();
        String timeZoneDiff = sessionHandlerImpl.getTimeZoneDifference(request);
        myjobj = new JSONObject();
        myjobj.put("success", false);
        if (StringUtil.bNull(request.getParameter("jsondata"))) {
            String jsondata = request.getParameter("jsondata");
            JSONArray jarr = new JSONArray("[" + jsondata + "]");

            for (int i = 0; i < jarr.length(); i++) {
                JSONObject jobject = jarr.getJSONObject(i);
                activityids.add(jobject.getString("activityid").toString());
            }

            String[] arrayid = (String[]) activityids.toArray(new String[] {});
            JSONObject jobj = new JSONObject();
            jobj.put("deleteflag", 1);
            jobj.put("activityid", arrayid);
            jobj.put("userid", userid);
            jobj.put("updatedon", new Date());
            jobj.put("tzdiff", timeZoneDiff);

            kmsg = crmActivityDAOObj.updateMassActivity(jobj);

            List<CrmActivityMaster> ll = crmActivityDAOObj.getActivities(activityids);

            if (ll != null) {
                for (int i = 0; i < ll.size(); i++) {
                    CrmActivityMaster activityaudit = (CrmActivityMaster) ll.get(i);
                    if (activityaudit.getValidflag() == 1) {
                        auditTrailDAOObj.insertAuditLog(AuditAction.ACTIVITY_DELETE,
                                activityaudit.getFlag() + " - Activity deleted ", request,
                                activityaudit.getActivityid());
                    }
                }
            }

            JSONObject cometObj = new JSONObject();
            cometObj.put("ids", jarr);
            publishActivityModuleInformation(request, cometObj, CrmPublisherHandler.DELETERECORDCODE,
                    sessionHandlerImpl.getCompanyid(request), userid);
        }
        myjobj.put("success", true);
        myjobj.put("ID", activityids.toArray());
        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());
}

From source file:com.krawler.spring.crm.caseModule.crmCaseController.java

public ModelAndView saveCases(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    JSONObject myjobj = new JSONObject();
    KwlReturnObject kmsg = null;//from  w w  w. ja  v  a  2 s  .co m
    CrmCase cases = 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 {
        boolean caseClosed = false;
        boolean assignedUserChanged = false;
        JSONObject jobj = new JSONObject(request.getParameter("jsondata"));
        String companyid = sessionHandlerImpl.getCompanyid(request);
        String userid = sessionHandlerImpl.getUserid(request);
        Integer operationCode = CrmPublisherHandler.ADDRECORDCODE;
        String id = jobj.getString("caseid");
        String[] arrayId = new String[] { id };
        jobj.put("userid", userid);
        jobj.put("companyid", companyid);
        jobj.put("updatedon", new Date().getTime());
        JSONArray jcustomarray = null;
        if (jobj.has("customfield")) {
            jcustomarray = jobj.getJSONArray("customfield");
        }
        if (id.equals("0")) {
            id = java.util.UUID.randomUUID().toString();
            jobj.put("caseid", id);
            jobj.put("casecreatedby", userid);
            kmsg = crmCaseDAOObj.addCases(jobj);
            cases = (CrmCase) kmsg.getEntityList().get(0);
            if (cases.getValidflag() == 1) {
                auditTrailDAOObj.insertAuditLog(AuditAction.CASE_CREATE,
                        ((cases.getSubject() == null) ? "" : cases.getSubject()) + " - Case created ", request,
                        id);
            }
            HashMap<String, Object> customrequestParams = new HashMap<String, Object>();
            customrequestParams.put("customarray", jcustomarray);
            customrequestParams.put("modulename", Constants.Crm_Case_modulename);
            customrequestParams.put("moduleprimarykey", Constants.Crm_Caseid);
            customrequestParams.put("modulerecid", id);
            customrequestParams.put("companyid", companyid);
            customrequestParams.put("customdataclasspath", Constants.Crm_case_custom_data_classpath);
            if (jobj.has("customfield")) {
                KwlReturnObject customDataresult = fieldDataManagercntrl.setCustomData(customrequestParams);
                if (customDataresult != null && customDataresult.getEntityList().size() > 0) {
                    jobj.put("CrmCaseCustomDataobj", id);
                    kmsg = crmCaseDAOObj.editCases(jobj);
                }
            }
            // fetch auto-number columns only
            HashMap<String, Object> fieldrequestParams = new HashMap<String, Object>();
            fieldrequestParams.put("isexport", true);
            fieldrequestParams.put("filter_names", Arrays.asList("companyid", "moduleid", "fieldtype"));
            fieldrequestParams.put("filter_values",
                    Arrays.asList(companyid, Constants.Crm_case_moduleid, Constants.CUSTOM_FIELD_AUTONUMBER));
            KwlReturnObject AutoNoFieldMap = fieldManagerDAOobj.getFieldParams(fieldrequestParams);

            // increment auto number if exist
            if (AutoNoFieldMap.getEntityList().size() > 0) {
                JSONArray autoNoData = fieldDataManagercntrl.setAutoNumberCustomData(customrequestParams,
                        AutoNoFieldMap.getEntityList());
                jobj.put(com.krawler.common.util.Constants.AUTOCUSTOMFIELD, autoNoData);
            } // END logic - auto no
        } else {
            operationCode = CrmPublisherHandler.UPDATERECORDCODE;
            // using old and new record validflag, check record becames valid or not
            List<String> recordIds = new ArrayList<String>();
            recordIds.add(id);
            List<CrmCase> oldCaseRecord = crmCaseDAOObj.getCases(recordIds);
            String caseAssignedId = null;
            if (oldCaseRecord != null) {
                for (CrmCase caseObj : oldCaseRecord) {
                    caseAssignedId = (caseObj.getAssignedto() != null ? caseObj.getAssignedto().getUserID()
                            : "");
                    if (jobj.has("caseassignedtoid")) {
                        if (!caseAssignedId.equals(jobj.getString("caseassignedtoid"))) {
                            assignedUserChanged = true;
                        }
                    }
                    if (caseObj.getCrmCombodataByCasestatusid() != null && caseObj
                            .getCrmCombodataByCasestatusid().getMainID().equals(Constants.CASESTATUS_CLOSED)) {
                        caseClosed = true;
                    }
                }
            }
            if (jobj.has("customfield")) {

                HashMap<String, Object> customrequestParams = new HashMap<String, Object>();
                customrequestParams.put("customarray", jcustomarray);
                customrequestParams.put("modulename", Constants.Crm_Case_modulename);
                customrequestParams.put("moduleprimarykey", Constants.Crm_Caseid);
                customrequestParams.put("modulerecid", id);
                customrequestParams.put("companyid", companyid);
                customrequestParams.put("customdataclasspath", Constants.Crm_case_custom_data_classpath);
                KwlReturnObject customDataresult = fieldDataManagercntrl.setCustomData(customrequestParams);
                if (customDataresult != null && customDataresult.getEntityList().size() > 0) {
                    jobj.put("CrmCaseCustomDataobj", id);
                }
            }
            if (jobj.has("createdon")) {
                jobj.put("createdon", jobj.getLong("createdon"));
            }
            kmsg = crmCaseDAOObj.editCases(jobj);
            cases = (CrmCase) kmsg.getEntityList().get(0);
            if (cases.getValidflag() == 1) {
                auditTrailDAOObj.insertAuditLog(AuditAction.CASE_UPDATE, jobj.getString("auditstr") + " Case - "
                        + ((cases.getSubject() == null) ? "" : cases.getSubject()) + " ", request, id);

                String loginURL = URLUtil.getRequestPageURL(request, Links.loginpageFull);
                HashMap<String, Object> extraParams = new HashMap<String, Object>();
                extraParams.put(NotificationConstants.LOGINURL, loginURL);
                extraParams.put(NotificationConstants.PARTNERNAME, sessionHandlerImplObj.getPartnerName());
                if (jobj.has("casestatusid") && !caseClosed && cases.getCrmCombodataByCasestatusid() != null
                        && cases.getCrmCombodataByCasestatusid().getMainID()
                                .equals(Constants.CASESTATUS_CLOSED)) {
                    sendNotificationOnCaseClosed(cases, userid, companyid, extraParams,
                            sessionHandlerImplObj.getSystemEmailId());
                }
                if (assignedUserChanged && cases.getAssignedto() != null) {
                    sendNotificationOnCaseAssigned(cases, userid, extraParams);
                }
            }
        }
        if (request.getParameter("massEdit") != null
                && Boolean.parseBoolean(request.getParameter("massEdit"))) {
            if (arrayId[0].equals("0"))
                crmCommonService.validateMassupdate(new String[] { cases.getCaseid() }, "Case", companyid);
            else
                crmCommonService.validateMassupdate(arrayId, "Account", companyid);
        }
        myjobj.put("success", true);
        myjobj.put("ID", cases.getCaseid());
        myjobj.put("createdon", jobj.has("createdon") ? jobj.getLong("createdon") : "");
        myjobj.put(com.krawler.common.util.Constants.AUTOCUSTOMFIELD,
                jobj.has(com.krawler.common.util.Constants.AUTOCUSTOMFIELD)
                        ? jobj.getJSONArray(com.krawler.common.util.Constants.AUTOCUSTOMFIELD)
                        : "");
        txnManager.commit(status);

        JSONObject cometObj = jobj;
        if (!StringUtil.isNullObject(cases)) {
            if (!StringUtil.isNullObject(cases.getCreatedon())) {
                cometObj.put("createdon", cases.getCreatedonGMT());
            }
        }
        publishCasesModuleInformation(request, cometObj, operationCode, companyid, userid);
    } 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.caseModule.crmCaseController.java

public ModelAndView updateMassCases(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    JSONObject myjobj = new JSONObject();
    KwlReturnObject kmsg = null;/*ww w  .j  a v  a 2 s  .c  o m*/
    CrmCase cases = 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 {
        JSONObject jobj = new JSONObject(request.getParameter("jsondata"));
        String companyid = sessionHandlerImpl.getCompanyid(request);
        String userid = sessionHandlerImpl.getUserid(request);
        Integer operationCode = CrmPublisherHandler.UPDATERECORDCODE;
        String caseIds = jobj.getString("caseid");
        String arrayId[] = caseIds.split(",");
        jobj.put("userid", userid);
        jobj.put("companyid", companyid);
        if (jobj.has("updatedon") && !StringUtil.isNullOrEmpty(jobj.getString("updatedon"))) {
            jobj.put("updatedon", jobj.getLong("updatedon"));
        } else {
            jobj.put("updatedon", new Date().getTime());
        }
        jobj.put("caseid", arrayId);
        jobj.put("tzdiff", sessionHandlerImpl.getTimeZoneDifference(request));
        JSONArray jcustomarray = null;
        if (jobj.has("customfield")) {
            jcustomarray = jobj.getJSONArray("customfield");
        }

        if (jobj.has("customfield")) {
            HashMap<String, Object> customrequestParams = new HashMap<String, Object>();
            customrequestParams.put("customarray", jcustomarray);
            customrequestParams.put("modulename", Constants.Crm_Case_modulename);
            customrequestParams.put("moduleprimarykey", Constants.Crm_Caseid);
            customrequestParams.put("companyid", companyid);
            customrequestParams.put("customdataclasspath", Constants.Crm_case_custom_data_classpath);
            KwlReturnObject customDataresult = null;
            for (String id : arrayId) {
                customrequestParams.put("modulerecid", id);
                customDataresult = fieldDataManagercntrl.setCustomData(customrequestParams);
            }
            if (customDataresult != null && customDataresult.getEntityList().size() > 0) {
                jobj.put("CrmCaseCustomDataobj", true);

            }
        }
        if (jobj.has("createdon")) {
            jobj.put("createdon", jobj.getLong("createdon"));
        }
        kmsg = crmCaseDAOObj.updateMassCases(jobj);
        // TODO : How to insert audit log when mass update
        // cases = (CrmCase) kmsg.getEntityList().get(0);
        // if (cases.getValidflag() == 1) {
        // auditTrailDAOObj.insertAuditLog(AuditAction.CASE_UPDATE,
        // jobj.getString("auditstr") + " Case - " + ((acc.getCasename() ==
        // null) ? "" : acc.getCasename()) + " ",
        // request, id);
        // }

        // }

        JSONObject cometObj = jobj;
        if (request.getParameter("massEdit") != null
                && Boolean.parseBoolean(request.getParameter("massEdit"))) {
            crmCommonService.validateMassupdate(arrayId, "Case", companyid);
            cometObj.put("caseid", caseIds);
            cometObj.put("ismassedit", true);
        }

        myjobj.put("success", true);
        myjobj.put("ID", caseIds);
        myjobj.put("createdon", jobj.has("createdon") ? jobj.getLong("createdon") : "");

        if (!StringUtil.isNullObject(cases)) {
            if (cases.getCreatedOn() != null) {
                cometObj.put("createdon", cases.getCreatedonGMT());
            }
        }
        publishCasesModuleInformation(request, cometObj, operationCode, companyid, userid);
        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.caseModule.crmCaseController.java

public ModelAndView deleteCase(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    JSONObject myjobj = null;//  ww w  .  ja  v a  2 s  .  co m
    KwlReturnObject kmsg = null;
    CrmCase cases = 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);
    JSONArray jarr = null;
    try {
        String userid = sessionHandlerImpl.getUserid(request);
        ArrayList caseids = new ArrayList();
        myjobj = new JSONObject();
        myjobj.put("success", false);
        if (StringUtil.bNull(request.getParameter("jsondata"))) {
            String jsondata = request.getParameter("jsondata");
            jarr = new JSONArray("[" + jsondata + "]");

            for (int i = 0; i < jarr.length(); i++) {
                JSONObject jobject = jarr.getJSONObject(i);
                caseids.add(jobject.getString("caseid").toString());
            }
            String[] arrayid = (String[]) caseids.toArray(new String[] {});
            JSONObject jobj = new JSONObject();
            jobj.put("deleteflag", 1);
            jobj.put("caseid", arrayid);
            jobj.put("userid", userid);
            jobj.put("updatedon", new Date().getTime());
            kmsg = crmCaseDAOObj.updateMassCases(jobj);

            List<CrmCase> ll = crmCaseDAOObj.getCases(caseids);

            if (ll != null) {
                for (int i = 0; i < ll.size(); i++) {
                    CrmCase caseaudit = (CrmCase) ll.get(i);
                    if (caseaudit.getValidflag() == 1) {
                        auditTrailDAOObj.insertAuditLog(AuditAction.CASE_DELETE,
                                caseaudit.getSubject() + " - Case deleted ", request, caseaudit.getCaseid());
                    }
                }

            }
        }
        myjobj.put("success", true);
        myjobj.put("ID", caseids.toArray());
        txnManager.commit(status);

        if (jarr != null) {
            JSONObject cometObj = new JSONObject();
            cometObj.put("ids", jarr);
            publishCasesModuleInformation(request, cometObj, CrmPublisherHandler.DELETERECORDCODE,
                    sessionHandlerImpl.getCompanyid(request), userid);
        }

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

From source file:com.krawler.spring.crm.caseModule.CrmCustomerCaseController.java

public ModelAndView addComment(HttpServletRequest request, HttpServletResponse response) {
    Map model = new HashMap();
    String responseMessage = "";
    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  va  2  s .  c  o m*/
        if ((String) request.getSession().getAttribute(Constants.SESSION_CUSTOMER_ID) != null) {
            String caseId = request.getParameter("caseid");
            String userId = (String) request.getSession().getAttribute("contactid");
            String comment = request.getParameter("addcomment");
            crmCustomerCaseService.addComment(caseId, userId, comment);
            txnManager.commit(status);
            request.setAttribute("casedetails", "true");
            request.setAttribute("caseid", caseId);
        } else {
            request.setAttribute("logout", "true");
        }
        responseMessage = "usercases/redirect";
    }

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

From source file:com.krawler.spring.crm.caseModule.CrmCustomerCaseController.java

public ModelAndView saveCustomerCases(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, ServiceException {
    JSONObject myjobj = new JSONObject();
    KwlReturnObject kmsg = null;/*from  w ww  .ja v a  2s  .co  m*/
    CrmCase cases = null;
    String responseMessage = "";
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("JE_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
    TransactionStatus status = txnManager.getTransaction(def);
    FileUploadHandler uh = new FileUploadHandler();
    HashMap hm = uh.getItems(request);
    Map model = new HashMap();

    try {

        String companyid = sessionHandlerImpl.getCompanyid(request);
        String customerId = (String) request.getSession().getAttribute("customerid");
        String contactId = (String) request.getSession().getAttribute("contactid");
        String caseOwnerID = crmCustomerCaseService.getCompanyCaseDefaultOwnerID(companyid);
        Integer operationCode = CrmPublisherHandler.ADDRECORDCODE;
        JSONObject jobj = new JSONObject();
        JSONObject jobj1 = new JSONObject();
        String id = java.util.UUID.randomUUID().toString();

        jobj.put("caseid", id);
        jobj.put("contactnameid", contactId);
        jobj.put("userid", caseOwnerID);
        jobj.put("caseownerid", caseOwnerID);
        jobj.put("subject", hm.get("subject"));
        jobj.put("description", hm.get("description"));
        jobj.put("companyid", companyid);
        jobj.put("createdon", System.currentTimeMillis());
        jobj.put("updatedon", System.currentTimeMillis());
        jobj.put("casecreatedby", contactId);
        jobj.put("createdbyflag", "1");

        kmsg = crmCustomerCaseService.addCases(jobj);
        cases = (CrmCase) kmsg.getEntityList().get(0);

        try {
            FileItem fileItem = (FileItem) hm.get("attachment");
            String filename = fileItem.getName();
            String docID = "";
            if (filename != null && filename != "") {
                if (fileItem.getSize() <= 10485760) { //limit 10 mb
                    kmsg = crmCustomerCaseService.uploadFile(fileItem, null, companyid, getServletContext());//Since document is uploaded by customer ,userid is null for uploadfile function
                    Docs doc = (Docs) kmsg.getEntityList().get(0);
                    docID = doc.getDocid();
                    jobj1.put("docid", docID);
                    jobj1.put("companyid", companyid);
                    jobj1.put("id", id);
                    jobj1.put("map", "6");
                    jobj1.put("refid", id);
                    crmCustomerCaseService.saveDocumentMapping(jobj1);
                    crmCustomerCaseService.saveCustomerDocs(customerId, docID, id);
                }
            }
        } catch (Exception e) {
            logger.warn("Attachment upload failed with Customer case :" + e.getMessage());
        }

        myjobj.put("success", true);
        myjobj.put("ID", cases.getCaseid());
        myjobj.put("createdon", jobj.optLong("createdon"));
        txnManager.commit(status);

        JSONObject cometObj = jobj;
        if (!StringUtil.isNullObject(cases)) {
            if (!StringUtil.isNullObject(cases.getCreatedon())) {
                cometObj.put("createdon", cases.getCreatedonGMT());
            }
        }
        //publishCasesModuleInformation(request, cometObj, operationCode, companyid, caseOwnerID);
        request.setAttribute("caselist", "true");
        responseMessage = "usercases/redirect";

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

From source file:com.krawler.spring.crm.caseModule.CrmCustomerCaseController.java

public ModelAndView custPassword_Change(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {

    String newpass = request.getParameter("newpass");
    String currentpass = request.getParameter("curpass");
    String customerid = request.getParameter("customerid");
    String email = request.getParameter("email");
    Map model = new HashMap();
    // String replaceStr=request.getParameter("cdomain");
    String url = URLUtil.getRequestPageURL(request, Links.UnprotectedLoginPageFull);
    String loginurl = url.concat("caselogin.jsp");
    String name = request.getParameter("cname");
    boolean verify_pass = false;
    String responseMessage = "";
    if ((String) request.getSession().getAttribute(Constants.SESSION_CUSTOMER_ID) != null) {
        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. ja  v a  2s .co m*/

            verify_pass = contactManagementService.verifyCurrentPass(currentpass, customerid);
            if (verify_pass) {
                contactManagementService.custPassword_Change(newpass, customerid);
                txnManager.commit(status);
                request.setAttribute("homepage", "true");
                request.setAttribute("success", "true");
                responseMessage = "usercases/redirect";
                String partnerNames = sessionHandlerImplObj.getPartnerName();
                String sysEmailId = sessionHandlerImplObj.getSystemEmailId();
                String passwordString = "Username: " + email + " <br/><br/>Password: <b>" + newpass + "</b>";
                String htmlmsg = "Dear <b>" + name
                        + "</b>,<br/><br/> Your <b>password has been changed</b> for your account on "
                        + partnerNames + " CRM. <br/><br/>" + passwordString + "<br/><br/>You can log in at:\n"
                        + loginurl + "<br/><br/>See you on " + partnerNames + " CRM <br/><br/> -The "
                        + partnerNames + " CRM Team";
                try {
                    SendMailHandler.postMail(new String[] { email }, "[" + partnerNames + "] Password Changed",
                            htmlmsg, "", sysEmailId, partnerNames + " Admin");
                } catch (MessagingException e) {
                    e.printStackTrace();
                }

            } else {
                request.setAttribute("changepassword", "true");
                request.setAttribute("mis_pass", "true");
                txnManager.commit(status);
            }

        } catch (Exception e) {
            logger.warn("custPassword_change Error:", e);
            txnManager.rollback(status);
            responseMessage = "../../usercases/failure";
        }
    } else {
        request.setAttribute("logout", "true");
    }
    responseMessage = "usercases/redirect";
    return new ModelAndView(responseMessage, "model", model);
}

From source file:com.krawler.spring.crm.common.commentController.java

public ModelAndView addComments(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    JSONObject jobj = new JSONObject();
    JSONObject myjobj = new JSONObject();
    KwlReturnObject kmsg = null;/*from  www.j  av  a 2s .co m*/
    Object c;
    String details = "";
    String auditAction = "";
    String id = java.util.UUID.randomUUID().toString();
    String randomnumber = request.getParameter("randomnumber");
    String moduleName = request.getParameter("modulename");
    String jsondata = request.getParameter("jsondata");
    String map = "";
    String refid = "";
    //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 {
        String userid = sessionHandlerImpl.getUserid(request);
        String companyid = sessionHandlerImpl.getCompanyid(request);
        JSONArray jarr = new JSONArray("[" + jsondata + "]");
        for (int i = 0; i < jarr.length(); i++) {
            jobj = jarr.getJSONObject(i);
            map = jobj.getString("mapid");
            refid = jobj.getString("leadid");
            String commStrAudit = StringUtil.serverHTMLStripper(jobj.getString("comment"));
            commStrAudit = commStrAudit.replaceAll("&nbsp;", "");
            String cid = java.util.UUID.randomUUID().toString();
            String commentid = jobj.getString("commentid");
            jobj.put("userid", userid);
            jobj.put("companyid", companyid);
            jobj.put("cid", cid);
            jobj.put("refid", refid);
            if (StringUtil.isNullOrEmpty(commentid)) { // Add Mode
                jobj.put("id", id);
                if (moduleName.equals(Constants.Case)) {//Case                                      
                    crmCommentDAOObj.addCaseComments(jobj);
                } else {
                    kmsg = crmCommentDAOObj.addComments(jobj);
                }
            } else { // Edit Mode

                jobj.put("id", commentid.trim());
                if (moduleName.equals(Constants.Case)) {
                    kmsg = crmCommentDAOObj.editCaseComments(jobj);
                } else {
                    kmsg = crmCommentDAOObj.editComments(jobj);
                }
            }

            //@@@ - Need to restructure this code
            if (map.equals("0")) {
                c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmCampaign", refid);
                details = " Campaign - ";
                details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "campaignname")) ? ""
                        : BeanUtils.getProperty(c, "campaignname");
                auditAction = AuditAction.CAMPAIGN_ADD_COMMENTS;
            } else if (map.equals("1")) {
                c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmLead", refid);
                details = " Lead - ";
                details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "firstname")) ? ""
                        : BeanUtils.getProperty(c, "firstname") + " ";
                details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "lastname")) ? ""
                        : BeanUtils.getProperty(c, "lastname");
                auditAction = AuditAction.LEAD_ADD_COMMENTS;
            } else if (map.equals("2")) {
                c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmContact", refid);
                details = " Contact - ";
                details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "firstname")) ? ""
                        : BeanUtils.getProperty(c, "firstname");
                details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "lastname")) ? ""
                        : BeanUtils.getProperty(c, "lastname");
                auditAction = AuditAction.CONTACT_ADD_COMMENTS;
            } else if (map.equals("3")) {
                c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmProduct", refid);
                details = " Product - ";
                details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "productname")) ? ""
                        : BeanUtils.getProperty(c, "productname");
                auditAction = AuditAction.PRODUCT_ADD_COMMENTS;
            } else if (map.equals("4")) {
                c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmAccount", refid);
                details = " Account - ";
                details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "accountname")) ? ""
                        : BeanUtils.getProperty(c, "accountname");
                auditAction = AuditAction.ACCOUNT_ADD_COMMENTS;
            } else if (map.equals("5")) {
                c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmOpportunity", refid);
                details = " Opportunity - ";
                details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "oppname")) ? ""
                        : BeanUtils.getProperty(c, "oppname");
                auditAction = AuditAction.OPPORTUNITY_ADD_COMMENTS;
            } else if (map.equals("6")) {
                c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmCase", refid);
                details = " Case - ";
                details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "subject")) ? ""
                        : BeanUtils.getProperty(c, "subject");
                auditAction = AuditAction.CASE_ADD_COMMENTS;
            } else if (map.equals("7")) {
                c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmActivityMaster", refid);
                String subject = StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "subject")) ? ""
                        : "(" + BeanUtils.getProperty(c, "subject") + ")";
                //                      String aname = BeanUtils.getProperty(c,"crmCombodataByStatusid.aliasName");
                //                    if(!StringUtil.isNullOrEmpty(aname)){
                //                        comboStatus=aname;
                //                    }
                details = " Activity - " + BeanUtils.getProperty(c, "flag") + " " + subject;
                auditAction = AuditAction.ACTIVITY_ADD_COMMENTS;
            }
            auditTrailDAOObj.insertAuditLog(auditAction,
                    " Comment: '" + commStrAudit + "' , added for " + details, request, refid, id);
        }
        myjobj.put("ID", id);
        txnManager.commit(status);

        // add comment on other logins for same user
        try {
            JSONObject commetMap = new JSONObject();
            boolean isCommentAdded = kmsg.isSuccessFlag();
            int operationCode = CrmPublisherHandler.ADDCOMMENT;
            commetMap.put("isCommentAdded", isCommentAdded);
            commetMap.put("recid", refid);
            commetMap.put("modulename", moduleName);
            cometManagementService.publishModuleInformation(companyid, userid, randomnumber, moduleName, refid,
                    operationCode, commetMap, CometConstants.CRMUPDATES);
        } catch (Exception e) {
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
        txnManager.rollback(status);
    }
    return new ModelAndView("jsonView", "model", myjobj.toString());
}

From source file:com.krawler.spring.crm.common.documentController.java

public ModelAndView addDocuments(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    JSONObject jobj = new JSONObject();
    JSONObject myjobj = new JSONObject();
    List fileItems = null;/*w ww. j  a  v  a 2 s.co m*/
    String details = "";
    KwlReturnObject kmsg = null;
    String auditAction = "";
    String id = java.util.UUID.randomUUID().toString();
    // PrintWriter out = 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 {
        response.setContentType("text/html;charset=UTF-8");
        // out = response.getWriter();
        String userid = sessionHandlerImpl.getUserid(request);
        String companyID = sessionHandlerImpl.getCompanyid(request);
        String map = request.getParameter("mapid");
        HashMap<String, String> arrParam = new HashMap<String, String>();
        boolean fileUpload = false;
        ArrayList<FileItem> fi = new ArrayList<FileItem>();
        if (request.getParameter("fileAdd") != null) {
            DiskFileUpload fu = new DiskFileUpload();
            fileItems = fu.parseRequest(request);
            crmDocumentDAOObj.parseRequest(fileItems, arrParam, fi, fileUpload);
        }
        String docID = "";
        for (int cnt = 0; cnt < fi.size(); cnt++) {
            kmsg = crmDocumentDAOObj.uploadFile(fi.get(cnt), userid, companyID, getServletContext());
            Docs doc = (Docs) kmsg.getEntityList().get(0);
            docID = doc.getDocid();
            String refid = arrParam.get("refid");
            jobj.put("userid", userid);
            jobj.put("docid", docID);
            jobj.put("companyid", companyID);
            jobj.put("id", id);
            jobj.put("map", map);
            jobj.put("refid", refid);
            crmDocumentDAOObj.saveDocumentMapping(jobj);
            String randomid = java.util.UUID.randomUUID().toString();
            crmDocumentDAOObj.insertDocumentOwnerEntry(randomid, userid, docID);
            if (map.equals("0")) {
                CrmCampaign c = (CrmCampaign) hibernateTemplate.get(CrmCampaign.class, refid);
                details = " Campaign - ";
                details += StringUtil.isNullOrEmpty(c.getCampaignname()) ? "" : c.getCampaignname();
                auditAction = AuditAction.CAMPAIGN_DOC_UPLOAD;
            } else if (map.equals("1")) {
                CrmLead l = (CrmLead) hibernateTemplate.get(CrmLead.class, refid);
                details = " Lead - ";
                details += StringUtil.isNullOrEmpty(l.getFirstname()) ? "" : l.getFirstname() + " ";
                details += StringUtil.isNullOrEmpty(l.getLastname()) ? "" : l.getLastname();
                auditAction = AuditAction.LEAD_DOC_UPLOAD;
            } else if (map.equals("2")) {
                CrmContact c = (CrmContact) hibernateTemplate.get(CrmContact.class, refid);
                details = " Contact - ";
                details += StringUtil.isNullOrEmpty(c.getFirstname()) ? "" : c.getFirstname() + " ";
                details += StringUtil.isNullOrEmpty(c.getLastname()) ? "" : c.getLastname();
                auditAction = AuditAction.CONTACT_DOC_UPLOAD;
            } else if (map.equals("3")) {
                CrmProduct p = (CrmProduct) hibernateTemplate.get(CrmProduct.class, refid);
                details = " Product - ";
                details += StringUtil.isNullOrEmpty(p.getProductname()) ? "" : p.getProductname();
                auditAction = AuditAction.PRODUCT_DOC_UPLOAD;
            } else if (map.equals("4")) {
                CrmAccount a = (CrmAccount) hibernateTemplate.get(CrmAccount.class, refid);
                details = " Account - ";
                details += StringUtil.isNullOrEmpty(a.getAccountname()) ? "" : a.getAccountname();
                auditAction = AuditAction.ACCOUNT_DOC_UPLOAD;
            } else if (map.equals("5")) {
                CrmOpportunity o = (CrmOpportunity) hibernateTemplate.get(CrmOpportunity.class, refid);
                details = " Opportunity - ";
                details += StringUtil.isNullOrEmpty(o.getOppname()) ? "" : o.getOppname();
                auditAction = AuditAction.OPPORTUNITY_DOC_UPLOAD;
            } else if (map.equals("6")) {
                CrmCase c = (CrmCase) hibernateTemplate.get(CrmCase.class, refid);
                details = " Case - ";
                details += StringUtil.isNullOrEmpty(c.getSubject()) ? "" : c.getSubject();
                auditAction = AuditAction.CASE_DOC_UPLOAD;
            } else if (map.equals("7")) {
                CrmActivityMaster am = (CrmActivityMaster) hibernateTemplate.get(CrmActivityMaster.class,
                        refid);
                details = " Activity - ";
                details += StringUtil.isNullOrEmpty(am.getFlag()) ? "" : am.getFlag() + " ";
                details += StringUtil.isNullOrEmpty(am.getCrmCombodataByStatusid().getValue()) ? ""
                        : am.getCrmCombodataByStatusid().getValue();
                auditAction = AuditAction.ACTIVITY_DOC_UPLOAD;
            } else if (map.equals("-1")) {
                details = " My - Document ";
                auditAction = AuditAction.MY_DOC_UPLOAD;
            }
            auditTrailDAOObj.insertAuditLog(auditAction,
                    " Docment: '" + doc.getDocname() + "' , uploaded for " + details, request, refid, id);
        }
        myjobj.put("ID", docID);
        txnManager.commit(status);
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
        txnManager.rollback(status);
    } finally {
        // out.close();
    }
    return new ModelAndView("jsonView", "model", myjobj.toString());
}