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

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

Introduction

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

Prototype

public final void setPropagationBehavior(int propagationBehavior) 

Source Link

Document

Set the propagation behavior.

Usage

From source file:com.krawler.spring.profileHandler.profileHandlerController.java

public ModelAndView saveUser(HttpServletRequest request, HttpServletResponse response) {
    JSONObject jobj = new JSONObject();
    //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);
    KWLTimeZone timeZone = null;//from  w  w  w.ja  v a  2 s.  c  o m
    try {
        KwlReturnObject kmsg = null;
        HashMap hm = null;
        if (ServletFileUpload.isMultipartContent(request)) {
            hm = new FileUploadHandler().getItems(request);
        }
        if (hm == null)
            throw new Exception("Form does not support file upload");

        String id = (String) hm.get("userid");

        String auditDetails = "";
        User user = null;
        String pwd = null;

        if (id != null && id.length() > 0) {
            user = (User) KwlCommonTablesDAOObj.getClassObject("com.krawler.common.admin.User", id);
        }
        String companyid = sessionHandlerImpl.getCompanyid(request);
        HashMap<String, Object> requestParams = new HashMap<String, Object>();
        requestParams.put("userid", id);
        requestParams.put("companyid", companyid);

        ArrayList filter_names = new ArrayList();
        ArrayList filter_params = new ArrayList();
        filter_names.add("u.userLogin.userName");
        filter_names.add("u.company.companyID");
        filter_names.add("!u.userID");
        filter_params.add(hm.get("username"));
        filter_params.add(sessionHandlerImpl.getCompanyid(request));
        filter_params.add(id);

        kmsg = profileHandlerDAOObj.getUserDetails(requestParams, filter_names, filter_params);
        if (kmsg.getRecordTotalCount() > 0) {
            throw new Exception("User Name already exists");
        }

        String name = (String) hm.get("username");
        String oldname = user.getUserLogin().getUserName();
        if (!name.equals(oldname))
            auditDetails += "User Name '" + oldname + "' updated to '" + name + "',";

        name = (String) hm.get("fname");
        oldname = user.getFirstName();
        if (!name.equals(oldname))
            if (!StringUtil.isNullOrEmpty(oldname))
                auditDetails += " First Name '" + oldname + "' updated to '" + name + "',";
            else
                auditDetails += " First Name '" + name + "' added,";
        name = (String) hm.get("lname");
        oldname = user.getLastName();
        if (!name.equals(oldname))
            if (!StringUtil.isNullOrEmpty(oldname))
                auditDetails += " Last Name '" + oldname + "' updated to '" + name + "',";
            else
                auditDetails += " Last Name '" + name + "' added,";
        name = (String) hm.get("emailid");
        oldname = user.getEmailID();
        if (!name.equals(oldname))
            if (!StringUtil.isNullOrEmpty(oldname))
                auditDetails += " E-mail '" + oldname + "' updated to '" + name + "',";
            else
                auditDetails += " E-mail '" + name + "' added,";
        name = StringUtil.serverHTMLStripper((String) hm.get("address"));
        oldname = user.getAddress();
        if (!name.equals(oldname))
            if (!StringUtil.isNullOrEmpty(oldname))
                auditDetails += " Address '" + oldname + "' updated to '" + name + "',";
            else
                auditDetails += " Address '" + name + "' added,";

        if (hm.get("callwithid") != null) {
            int callid = Integer.parseInt(hm.get("callwithid").toString());
            if (callid != user.getCallwith())
                auditDetails += " Call With updated,";
        }
        if (hm.get("timeformat") != null) {
            int timeformat = Integer.parseInt(hm.get("timeformat").toString());
            if (timeformat != user.getTimeformat())
                auditDetails += " Time format updated,";
        }
        name = (String) hm.get("contactno");
        oldname = user.getContactNumber();
        if (!name.equals(oldname))
            if (!StringUtil.isNullOrEmpty(oldname))
                auditDetails += " Contact Number '" + oldname + "' updated to '" + name + "',";
            else
                auditDetails += " Contact Number '" + name + "' added,";

        if (StringUtil.isNullOrEmpty((String) hm.get("formatid")) == false) {
            KWLDateFormat kdf = (KWLDateFormat) KwlCommonTablesDAOObj
                    .getClassObject("com.krawler.common.admin.KWLDateFormat", (String) hm.get("formatid"));
            if (!kdf.equals(user.getDateFormat()))
                auditDetails += " Date format updated to '" + kdf.getJavaForm() + "',";
        }
        String diff = null, tzid = null;
        if (StringUtil.isNullOrEmpty((String) hm.get("tzid")) == false) {
            timeZone = (KWLTimeZone) KwlCommonTablesDAOObj
                    .getClassObject("com.krawler.common.admin.KWLTimeZone", (String) hm.get("tzid"));
            diff = timeZone.getDifference();
            tzid = timeZone.getTzID();
            if (!timeZone.equals(user.getTimeZone()))
                auditDetails += " Timezone updated to " + timeZone.getName() + ",";
        }
        if (StringUtil.isNullOrEmpty((String) hm.get("aboutuser")) == false) {
            name = (String) hm.get("aboutuser");
            oldname = user.getAboutUser();
            if (!name.equals(oldname))
                if (!StringUtil.isNullOrEmpty(oldname))
                    auditDetails += " About User '" + oldname + "' updated to '" + name + "',";
                else
                    auditDetails += " About User '" + name + "' added,";
        }

        requestParams.put("username", hm.get("username"));
        requestParams.put("firstName", hm.get("fname"));
        requestParams.put("lastName", hm.get("lname"));
        requestParams.put("emailID", hm.get("emailid"));
        requestParams.put("address", (String) hm.get("address"));
        requestParams.put("callwith", hm.get("callwithid"));
        requestParams.put("timeformat", hm.get("timeformat"));
        requestParams.put("contactNumber", hm.get("contactno"));
        requestParams.put("dateFormat", hm.get("formatid"));
        requestParams.put("timeZone", hm.get("tzid"));
        requestParams.put("aboutUser", hm.get("aboutuser"));
        requestParams.put("image", hm.get("userimage"));

        int notificationtype = 0;
        if (hm.containsKey("notificationtype") && hm.get("notificationtype").equals("on"))
            notificationtype = 1;
        requestParams.put("notificationtype", notificationtype);
        sessionHandlerImpl.updateNotifyOnFlag(request, notificationtype == 1 ? true : false);

        requestParams.put("addUser", false);

        sessionHandlerImpl.updatePreferences(request, null,
                (StringUtil.isNullOrEmpty((String) hm.get("formatid")) ? null : (String) hm.get("formatid")),
                (StringUtil.isNullOrEmpty((String) hm.get("tzid")) ? null : (String) hm.get("tzid")), diff,
                tzid, true);
        sessionHandlerImpl.updatePreferences(request, null,
                (StringUtil.isNullOrEmpty((String) hm.get("formatid")) ? null : (String) hm.get("formatid")),
                (StringUtil.isNullOrEmpty((String) hm.get("tzid")) ? null : (String) hm.get("tzid")), diff,
                (StringUtil.isNullOrEmpty((String) hm.get("timeformat")) ? null
                        : (String) hm.get("timeformat")));

        if (id == null || id.length() <= 0) {
            //permissionHandlerDAOObj.setDefaultPermissions(1,newuser.getUserID());
            HashMap<String, Object> userRoleParams = new HashMap<String, Object>();
            userRoleParams.put("userid", sessionHandlerImpl.getUserid(request));
            userRoleParams.put("roleid", 4);
            permissionHandlerDAOObj.saveRoleList(userRoleParams);
            User creater = (User) KwlCommonTablesDAOObj.getClassObject("com.krawler.common.admin.User",
                    sessionHandlerImpl.getUserid(request));
            //String fullnameCreator = (creater.getFirstName() + " " + creater.getLastName()).trim();
            String fullnameCreator = creater.getFirstName();
            if (fullnameCreator != null && creater.getLastName() != null)
                fullnameCreator += " " + creater.getLastName();

            if (StringUtil.isNullOrEmpty(creater.getFirstName())
                    && StringUtil.isNullOrEmpty(creater.getLastName())) {
                fullnameCreator = creater.getUserLogin().getUserName();
            }
            String uri = URLUtil.getPageURL(request, Links.loginpageFull);
            String pmsg = String.format(KWLErrorMsgs.msgMailInvite, user.getFirstName(), fullnameCreator,
                    user.getUserLogin().getUserName(), pwd, uri, fullnameCreator);
            String htmlmsg = String.format(KWLErrorMsgs.msgMailInviteUsernamePassword, user.getFirstName(),
                    fullnameCreator, sessionHandlerImplObj.getCompanyName(request),
                    user.getUserLogin().getUserName(), pwd, uri, uri, fullnameCreator);
            try {
                SendMailHandler.postMail(new String[] { user.getEmailID() }, "[Deskera] Welcome to Deskera CRM",
                        htmlmsg, pmsg, creater.getEmailID());
            } catch (MessagingException e) {
                e.printStackTrace();
            }
        }

        kmsg = profileHandlerDAOObj.saveUser(requestParams);
        if (kmsg.isSuccessFlag()) {
            jobj.put("msg", messageSource.getMessage("crm.userprofile.updateusersuccessmsg", null,
                    RequestContextUtils.getLocale(request)));//"Profile has been updated successfully.");
            if (!StringUtil.isNullObject(timeZone)) {
                jobj.put("tzdiff", timeZone.getDifference());
            }
            // create user entry for emails in krawlercrm database
            if (StringUtil.isNullOrEmpty(id)) {
                mailIntDAOObj.addUserEntryForEmails(sessionHandlerImpl.getUserid(request), user,
                        user.getUserLogin(), pwd, true);
            }
        } else {
            jobj.put("msg", messageSource.getMessage("crm.userprofile.updateuserfailuremsg", null,
                    RequestContextUtils.getLocale(request)));//"Sorry! User information could not be saved successfully. Please try again.");
        }

        if (auditDetails.length() > 0) {
            auditDetails = auditDetails.substring(0, auditDetails.length() - 1);
            if (!sessionHandlerImpl.getUserid(request).equals(id)) {
                auditDetails += " for user " + user.getFirstName() + " " + user.getLastName() + " ";
            }
            auditTrailDAOObj.insertAuditLog(AuditAction.User_Profile_update, auditDetails, request, id);
        }

        txnManager.commit(status);
    } catch (Exception e) {
        logger.warn("General exception in saveUser()", e);
        txnManager.rollback(status);
    }
    return new ModelAndView("jsonView", "model", jobj.toString());
}

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

public ModelAndView saveAccOwners(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    JSONObject myjobj = new JSONObject();
    KwlReturnObject kmsg = null;/*from   w  w w .j  a v a2  s  .  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 {
        String accid = request.getParameter("leadid");
        String owners = request.getParameter("owners");
        String mainowner = request.getParameter("mainOwner");
        HashMap<String, Object> requestParams = new HashMap<String, Object>();
        requestParams.put("accid", accid);
        requestParams.put("owners", owners);
        requestParams.put("mainOwner", mainowner);
        kmsg = crmAccountDAOObj.saveAccOwners(requestParams);
        // Fetch subowners name list
        List<String> idsList = new ArrayList<String>();
        idsList.add(accid);
        Map<String, List<AccountOwnerInfo>> ownersMap = crmAccountDAOObj.getAccountOwners(idsList);
        String[] ownerInfo = crmAccountHandler.getAllAccOwners(ownersMap.get(accid));
        myjobj.put("subowners", ownerInfo[1]);
        myjobj.put("success", kmsg.isSuccessFlag());
        txnManager.commit(status);
    } catch (SessionExpiredException e) {
        logger.warn("SessionExpiredException while saving account owner:", e);
        txnManager.rollback(status);
    } catch (JSONException e) {
        logger.warn("JSONException while saving account owner:", e);
        txnManager.rollback(status);
    } catch (ServiceException e) {
        logger.warn("ServiceException while saving account owner:", e);
        txnManager.rollback(status);
    } catch (Exception e) {
        logger.warn("Exception while saving account owner:", e);
        txnManager.rollback(status);
    }
    return new ModelAndView("jsonView", "model", myjobj.toString());
}

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

public ModelAndView newAccount(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    JSONObject myjobj = new JSONObject();
    JSONObject jobj = new JSONObject();
    KwlReturnObject kmsg = null;/*w  w w .  j  a  v a  2  s . co  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 {
        String userid = request.getParameter("userid");
        String accountname = request.getParameter("accountname");
        String website = request.getParameter("website");
        String description = request.getParameter("description");
        String contactno = request.getParameter("contactno");
        String revenue = request.getParameter("revenue");
        String id = java.util.UUID.randomUUID().toString();

        String companyid = sessionHandlerImpl.getCompanyid(request);
        jobj.put("accountid", id);
        jobj.put("accountownerid", userid);
        jobj.put("companyid", companyid);
        jobj.put("userid", userid);
        jobj.put("accountname", accountname);
        jobj.put("revenue", revenue);
        jobj.put("phone", contactno);
        jobj.put("description", description);
        jobj.put("website", website);
        jobj.put("validflag", 1);
        jobj.put("tzdiff", sessionHandlerImpl.getTimeZoneDifference(request));
        //            jobj.put("createdon", new Date());
        kmsg = crmAccountDAOObj.addAccounts(jobj);
        acc = (CrmAccount) kmsg.getEntityList().get(0);
        myjobj.put("success", true);
        myjobj.put("ID", acc.getAccountid());
        myjobj.put("validflag", acc.getValidflag());
        myjobj.put("accountname", acc.getAccountname());
        txnManager.commit(status);
    } catch (JSONException e) {
        System.out.println(e.getMessage());
        txnManager.rollback(status);
    } 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.accountModule.crmAccountController.java

public ModelAndView deleteAccount(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    JSONObject myjobj = null;//from   w  w  w .  jav  a  2  s  .com
    KwlReturnObject kmsg = null;
    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 {
        String userid = sessionHandlerImpl.getUserid(request);
        String timeZoneDiff = sessionHandlerImpl.getTimeZoneDifference(request);

        myjobj = new JSONObject();
        myjobj.put("success", false);
        JSONArray jarr = null;

        if (request.getAttribute("deletejarr") != null) {
            jarr = (JSONArray) request.getAttribute("deletejarr");
        } else {
            String jsondata = request.getParameter("jsondata");
            jarr = new JSONArray("[" + jsondata + "]");
        }

        ArrayList accountids = new ArrayList();
        for (int i = 0; i < jarr.length(); i++) {
            JSONObject jobject = jarr.getJSONObject(i);
            accountids.add(jobject.getString("accid").toString());
        }

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

        kmsg = crmAccountDAOObj.updateMassAccount(jobj);

        List<CrmAccount> ll = crmAccountDAOObj.getAccounts(accountids);

        if (ll != null) {
            for (int i = 0; i < ll.size(); i++) {
                CrmAccount accountaudit = (CrmAccount) ll.get(i);
                if (accountaudit.getValidflag() == 1) {
                    auditTrailDAOObj.insertAuditLog(AuditAction.ACCOUNT_DELETE,
                            accountaudit.getAccountname() + " - Account deleted ", request,
                            accountaudit.getAccountid());
                }
            }

        }

        if (request.getAttribute("failDelete") != null) {
            myjobj.put("failDelete", (JSONArray) request.getAttribute("failDelete"));
        }
        myjobj.put("successDeleteArr", jarr);
        myjobj.put("success", true);
        myjobj.put("ID", accountids.toArray());
        txnManager.commit(status);

        JSONObject cometObj = new JSONObject();
        cometObj.put("ids", jarr);
        publishAccountModuleInformation(request, cometObj, CrmPublisherHandler.DELETERECORDCODE,
                sessionHandlerImpl.getCompanyid(request), userid);
    } catch (JSONException e) {
        System.out.println(e.getMessage());
        txnManager.rollback(status);
    } 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.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  2s  . com
    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.accountModule.crmAccountController.java

public ModelAndView updateMassAccounts(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    JSONObject myjobj = new JSONObject();
    KwlReturnObject kmsg = null;//from  w ww.  j  ava  2  s . c om
    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.accountModule.crmAccountController.java

public ModelAndView saveAccounts(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    JSONObject myjobj = new JSONObject();
    KwlReturnObject kmsg = null;//from w  ww .  j  a  v  a2  s .  co 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.ADDRECORDCODE;
        String companyid = sessionHandlerImpl.getCompanyid(request);
        for (int i = 0; i < arrayId.length; i++) {
            String id = arrayId[i];
            jobj.put("userid", userid);
            jobj.put("companyid", companyid);
            jobj.put("updatedon", System.currentTimeMillis());
            jobj.put("accountid", id);
            JSONArray jcustomarray = null;
            if (jobj.has("customfield")) {
                jcustomarray = jobj.getJSONArray("customfield");
            }

            if (id.equals("0")) {
                if (jobj.has("accountownerid") && !jobj.getString("accountownerid").equals(userid)) {
                    ownerChanged = true;
                }

                id = java.util.UUID.randomUUID().toString();
                jobj.put("accountid", id);
                //                   if (jobj.has("customfield")) {
                //                       fieldManager.storeCustomFields(jcustomarray, "account", true, id);
                //                   }
                //                   jobj = StringUtil.setcreatedonDate(jobj, request);
                kmsg = crmAccountDAOObj.addAccounts(jobj);
                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("modulerecid", id);
                customrequestParams.put("companyid", companyid);
                customrequestParams.put("customdataclasspath", Constants.Crm_account_custom_data_classpath);
                acc = (CrmAccount) kmsg.getEntityList().get(0);
                if (jobj.has("customfield")) {
                    KwlReturnObject customDataresult = fieldDataManagercntrl.setCustomData(customrequestParams);
                    if (customDataresult != null && customDataresult.getEntityList().size() > 0) {
                        jobj.put("CrmAccountCustomDataobj", id);
                        kmsg = crmAccountDAOObj.editAccounts(jobj);
                    }

                    //                    fieldManager.storeCustomFields(jcustomarray,"account",true,id);
                }
                // 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_account_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(Constants.AUTOCUSTOMFIELD, autoNoData);
                } // END logic - auto no
                if (acc.getValidflag() == 1) {
                    auditTrailDAOObj.insertAuditLog(AuditAction.ACCOUNT_CREATE,
                            ((acc.getAccountname() == null) ? "" : acc.getAccountname())
                                    + " - Account created ",
                            request, id);
                }

            } else {
                // check if account owner changed
                String mainownerId = crmAccountHandler.getMainAccOwner(crmAccountDAOObj, id);
                if (!StringUtil.isNullOrEmpty(mainownerId)) {
                    if (!mainownerId.equals(jobj.optString("accountownerid", mainownerId))) {
                        ownerChanged = true;
                    }
                }

                operationCode = CrmPublisherHandler.UPDATERECORDCODE;
                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("modulerecid", id);
                    customrequestParams.put("companyid", companyid);
                    customrequestParams.put("customdataclasspath", Constants.Crm_account_custom_data_classpath);
                    KwlReturnObject customDataresult = fieldDataManagercntrl.setCustomData(customrequestParams);
                    if (customDataresult != null && customDataresult.getEntityList().size() > 0) {
                        jobj.put("CrmAccountCustomDataobj", id);
                    }
                }
                if (jobj.has("createdon")) {
                    jobj.put("createdon", jobj.getLong("createdon"));
                }
                kmsg = crmAccountDAOObj.editAccounts(jobj);
                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"))) {
            if (arrayId[0].equals("0"))
                crmCommonService.validateMassupdate(new String[] { acc.getAccountid() }, "Account", companyid);
            else
                crmCommonService.validateMassupdate(arrayId, "Account", companyid);
            cometObj.put("accountid", accountIds);
            cometObj.put("ismassedit", true);
        }

        myjobj.put("success", true);
        myjobj.put("ID", acc.getAccountid());
        myjobj.put("createdon", jobj.has("createdon") ? jobj.getLong("createdon") : "");
        cometObj.put("createdon", acc.getCreatedon());
        myjobj.put("updatedon", jobj.has("updatedon") ? jobj.getLong("updatedon") : "");
        myjobj.put(Constants.AUTOCUSTOMFIELD,
                jobj.has(Constants.AUTOCUSTOMFIELD) ? jobj.getJSONArray(Constants.AUTOCUSTOMFIELD) : "");
        cometObj.put("updatedon", acc.getUpdatedon());
        cometObj.put(Constants.AUTOCUSTOMFIELD,
                jobj.has(Constants.AUTOCUSTOMFIELD) ? jobj.getJSONArray(Constants.AUTOCUSTOMFIELD) : "");
        publishAccountModuleInformation(request, cometObj, operationCode, companyid, userid);

        if (sessionHandlerImpl.getCompanyNotifyOnFlag(request)) {// send Notification if set flag at company level
            if (ownerChanged) {// Send Notification if owner changed
                List<String> recepients = new ArrayList();
                recepients.add(jobj.getString("accountownerid"));
                Map refTypeMap = new HashMap();
                Map refIdMap = new HashMap();
                refIdMap.put("refid1", acc.getAccountid());
                refTypeMap.put("reftype1", Constants.Crm_account_classpath);
                refIdMap.put("refid2", userid);
                refTypeMap.put("reftype2", Constants.USERS_CLASSPATH);
                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));
                if (recepients.size() > 0) {
                    NotificationManagementServiceDAO.sendNotificationRequest(CHANNEL.EMAIL, ACCOUNT_ASSIGNED,
                            NOTIFICATIONSTATUS.REQUEST, userid, recepients, refIdMap, refTypeMap, extraParams);
                }
            }
        }
    } catch (Exception e) {
        logger.warn(e.getMessage());
        txnManager.rollback(status);
    }
    return new ModelAndView("jsonView", "model", myjobj.toString());
}

From source file:com.krawler.spring.importFunctionality.ImportUtil.java

/**
 * @param filename//from   w ww  . j  av  a 2 s. com
 * @param delimiterType
 * @param startindex
 * @param importDao
 * @return
 * @throws ServiceException
 */
public static void dumpCSVFileData(String filename, String delimiterType, int startindex, ImportDAO importDao,
        HibernateTransactionManager txnManager) throws ServiceException {
    boolean commitedEx = false;
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("import_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus status = txnManager.getTransaction(def);
    try {
        CsvReader csvReader = null;
        FileInputStream fstream = null;
        String destinationDirectory = storageHandlerImpl.GetDocStorePath() + "importplans";
        File csv = new File(destinationDirectory + "/" + filename);
        fstream = new FileInputStream(csv);
        csvReader = new CsvReader(new InputStreamReader(fstream), delimiterType);
        //            csvReader.readHeaders();
        String tableName = importDao.getTableName(filename);
        Session session = txnManager.getSessionFactory().getCurrentSession();
        int flushCounter = 0;
        while (csvReader.readRecord()) {
            ArrayList<String> dataArray = new ArrayList<String>();
            for (int i = 0; i < csvReader.getColumnCount(); i++) {
                dataArray.add(cleanHTML(csvReader.get(i)));
            }
            importDao.dumpFileRow(tableName, dataArray.toArray());
            if (flushCounter % 30 == 0) {
                session.flush();
                session.clear();
            }
            flushCounter++;
        }
        try {
            txnManager.commit(status);
        } catch (Exception ex) {
            commitedEx = true;
            throw ex;
        }
    } catch (IOException ex) {
        throw ServiceException.FAILURE("dumpCSVFileData: " + ex.getMessage(), ex);
    } catch (Exception ex) {
        if (!commitedEx) { //if exception occurs during commit then dont call rollback
            txnManager.rollback(status);
        }
        throw ServiceException.FAILURE("dumpCSVFileData: " + ex.getMessage(), ex);
    }
}

From source file:com.krawler.spring.importFunctionality.ImportUtil.java

/**
 * @param filename/*from www.  j a  va 2 s. co m*/
 * @param sheetNo
 * @param startindex
 * @param importDao
 * @return
 * @throws ServiceException
 */
public static void dumpXLSFileData(String filename, int sheetNo, int startindex, ImportDAO importDao,
        HibernateTransactionManager txnManager) throws ServiceException {
    boolean commitedEx = false;
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("import_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus status = txnManager.getTransaction(def);
    Session session = txnManager.getSessionFactory().getCurrentSession();
    try {
        String destinationDirectory = storageHandlerImpl.GetDocStorePath() + "xlsfiles";
        POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(destinationDirectory + "/" + filename));
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        HSSFSheet sheet = wb.getSheetAt(sheetNo);
        //DateFormat sdf = new SimpleDateFormat(df_full);
        int maxRow = sheet.getLastRowNum();
        int maxCol = 0;
        String tableName = importDao.getTableName(filename);
        int flushCounter = 0;
        for (int i = startindex; i <= maxRow; i++) {
            HSSFRow row = sheet.getRow(i);
            if (row == null) {
                continue;
            }
            if (i == startindex) {
                maxCol = row.getLastCellNum(); //Column Count
            }
            ArrayList<String> dataArray = new ArrayList<String>();
            JSONObject dataObj = new JSONObject();
            for (int j = 0; j < maxCol; j++) {
                HSSFCell cell = row.getCell(j);
                String val = null;
                if (cell == null) {
                    dataArray.add(val);
                    continue;
                }
                String colHeader = new CellReference(i, j).getCellRefParts()[2];
                switch (cell.getCellType()) {
                case HSSFCell.CELL_TYPE_NUMERIC:
                    if (HSSFDateUtil.isCellDateFormatted(cell)) {
                        val = Long.toString(cell.getDateCellValue().getTime());
                    } else {
                        val = dfmt.format(cell.getNumericCellValue());
                    }
                    break;
                case HSSFCell.CELL_TYPE_STRING:
                    val = ImportUtil.cleanHTML(cell.getRichStringCellValue().getString());
                    break;
                }
                dataObj.put(colHeader, val);
                dataArray.add(val); //Collect row data
            }
            //Insert Query
            if (dataObj.length() > 0) { // Empty row check (if lenght==0 then all columns are empty)
                importDao.dumpFileRow(tableName, dataArray.toArray());
                if (flushCounter % 30 == 0) {
                    session.flush();
                    session.clear();
                }
                flushCounter++;
            }

        }
        try {
            txnManager.commit(status);
        } catch (Exception ex) {
            commitedEx = true;
            throw ex;
        }
    } catch (IOException ex) {
        throw ServiceException.FAILURE("dumpXLSFileData: " + ex.getMessage(), ex);
    } catch (Exception ex) {
        if (!commitedEx) { //if exception occurs during commit then dont call rollback
            txnManager.rollback(status);
        }
        throw ServiceException.FAILURE("dumpXLSFileData: " + ex.getMessage(), ex);
    }
}

From source file:com.krawler.spring.importFunctionality.ImportUtil.java

/**
 * @param filename/*  w  ww.  ja  v  a  2 s  .com*/
 * @param sheetNo
 * @param startindex
 * @param importDao
 * @return
 * @throws ServiceException
 */
public static void dumpXLSXFileData(String filename, int sheetNo, int startindex, ImportDAO importDao,
        HibernateTransactionManager txnManager) throws ServiceException {
    boolean commitedEx = false;
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("import_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus status = txnManager.getTransaction(def);
    Session session = txnManager.getSessionFactory().getCurrentSession();
    try {
        String destinationDirectory = storageHandlerImpl.GetDocStorePath() + "xlsfiles";
        FileInputStream fs = new FileInputStream(destinationDirectory + "/" + filename);
        XSSFWorkbook wb = new XSSFWorkbook(fs);
        XSSFSheet sheet = wb.getSheetAt(sheetNo);
        //DateFormat sdf = new SimpleDateFormat(df_full);
        int maxRow = sheet.getLastRowNum();
        int maxCol = 0;
        String tableName = importDao.getTableName(filename);
        int flushCounter = 0;
        for (int i = startindex; i <= maxRow; i++) {
            XSSFRow row = sheet.getRow(i);
            if (row == null) {
                continue;
            }
            if (i == startindex) {
                maxCol = row.getLastCellNum(); //Column Count
            }
            ArrayList<String> dataArray = new ArrayList<String>();
            JSONObject dataObj = new JSONObject();
            for (int j = 0; j < maxCol; j++) {
                XSSFCell cell = row.getCell(j);
                String val = null;
                if (cell == null) {
                    dataArray.add(val);
                    continue;
                }
                String colHeader = new CellReference(i, j).getCellRefParts()[2];
                switch (cell.getCellType()) {
                case XSSFCell.CELL_TYPE_NUMERIC:
                    if (DateUtil.isCellDateFormatted(cell)) {
                        val = Long.toString(cell.getDateCellValue().getTime());
                    } else {
                        val = dfmt.format(cell.getNumericCellValue());
                    }
                    break;
                case XSSFCell.CELL_TYPE_STRING:
                    val = ImportUtil.cleanHTML(cell.getRichStringCellValue().getString());
                    break;
                }
                dataObj.put(colHeader, val);
                dataArray.add(val); //Collect row data
            }
            //Insert Query
            if (dataObj.length() > 0) { // Empty row check (if lenght==0 then all columns are empty)
                importDao.dumpFileRow(tableName, dataArray.toArray());
                if (flushCounter % 30 == 0) {
                    session.flush();
                    session.clear();
                }
                flushCounter++;
            }

        }
        try {
            txnManager.commit(status);
        } catch (Exception ex) {
            commitedEx = true;
            throw ex;
        }
    } catch (IOException ex) {
        throw ServiceException.FAILURE("dumpXLSXFileData: " + ex.getMessage(), ex);
    } catch (Exception ex) {
        if (!commitedEx) { //if exception occurs during commit then dont call rollback
            txnManager.rollback(status);
        }
        throw ServiceException.FAILURE("dumpXLSXFileData: " + ex.getMessage(), ex);
    }
}