List of usage examples for org.springframework.transaction TransactionDefinition PROPAGATION_REQUIRED
int PROPAGATION_REQUIRED
To view the source code for org.springframework.transaction TransactionDefinition PROPAGATION_REQUIRED.
Click Source Link
From source file:com.krawler.esp.handlers.zohoRequestHandler.java
public String saveUpdateZohoPotentials(String username, String password, String authToken, String userid, String companyid) {/*w w w . ja va 2 s . c om*/ // Session s = zohoRequestDAO.getCurrentSession(); String result = "{success:false,recCount:0,totalRecords:0}"; int recCount = 0; 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 Hql = "from CrmOpportunity c where c.oppid= ?"; JSONObject jobj = getRecordJson("Potentials", username, password, authToken); //Potential , Leads, Accounts if (jobj.get("success").equals(true)) { JSONArray dataArray = jobj.getJSONArray("data"); for (int cnt = 0; cnt < dataArray.length(); cnt++) { // Transaction tx = (Transaction) s.beginTransaction(); JSONObject recObj = dataArray.getJSONObject(cnt); List existingPotential = zohoRequestDAO.executeQuery(Hql, new Object[] { recObj.get("POTENTIALID") }); String masterData = "FROM CrmCombodata c where c.crmCombomaster.masterid=?"; List masterdata = zohoRequestDAO.executeQuery(masterData, new Object[] { "d49609c2-0abc-47ce-8d5a-5850c03b7291" }); Iterator itr = masterdata.iterator(); HashMap combodata = new HashMap(); while (itr.hasNext()) { CrmCombodata cdata = (CrmCombodata) itr.next(); combodata.put(cdata.getRawvalue().toLowerCase(), cdata.getValueid()); } Object stagevalue = combodata.get(recObj.getString("Stage").toLowerCase()); DefaultMasterItem dmasterItem = null; if (stagevalue == null) { stagevalue = combodata.get("prospecting"); Company companyObj = (Company) zohoRequestDAO.get(Company.class, companyid); CrmCombomaster crmComboMasterObj = (CrmCombomaster) zohoRequestDAO.get(CrmCombomaster.class, "d49609c2-0abc-47ce-8d5a-5850c03b7291"); dmasterItem = new DefaultMasterItem(); dmasterItem.setMainID(""); dmasterItem.setCompany(companyObj); dmasterItem.setID(UUID.randomUUID().toString()); dmasterItem.setCrmCombomaster(crmComboMasterObj); dmasterItem.setValue(recObj.getString("Stage")); } else { String dmasteritemid = "from DefaultMasterItem d where d.crmCombodata.valueid = ? and d.company.companyID=?"; List templist = zohoRequestDAO.executeQuery(dmasteritemid, new Object[] { stagevalue, companyid }); itr = templist.iterator(); while (itr.hasNext()) { dmasterItem = (DefaultMasterItem) itr.next(); } } JSONObject oppJObj = new JSONObject(); oppJObj.put("oppid", recObj.get("POTENTIALID")); oppJObj.put("companyid", companyid); oppJObj.put("userid", userid); oppJObj.put("updatedon", new Date()); oppJObj.put("oppname", recObj.getString("Potential Name").equals("null") ? "" : recObj.getString("Potential Name")); oppJObj.put("oppownerid", userid); oppJObj.put("opptypeid", "0"); oppJObj.put("currencyid", "0"); oppJObj.put("oppstageid", dmasterItem.getID()); oppJObj.put("isarchive", false); oppJObj.put("deleteflag", 0); CrmAccount ca = null; try { ca = (CrmAccount) zohoRequestDAO.get(CrmAccount.class, recObj.get("ACCOUNTID").toString()); } catch (Exception e) { logger.warn(e.getMessage(), e); } if (ca != null) { oppJObj.put("accountnameid", recObj.get("ACCOUNTID")); } // String timeFormatId = sessionHandlerImpl.getUserTimeFormat(request); // String timeZoneDiff = sessionHandlerImpl.getTimeZoneDifference(request); // if(recObj.has("closedate") && ! recObj.getString("Closing Date").equals("")){ // oppJObj.put("closedate",authHandler.getDateFormatter(timeFormatId, timeZoneDiff).parse(recObj.getString("Closing Date").toString())); // } java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd"); java.util.Date closingdate = null; if (!StringUtil.isNullOrEmpty(recObj.getString("Closing Date"))) { closingdate = sdf.parse(recObj.getString("Closing Date").toString()); oppJObj.put("closingdate", closingdate.getTime()); } oppJObj.put("validflag", 1); if (existingPotential.size() > 0) { KwlReturnObject kmsg = crmOpportunityDAOObj.editOpportunities(oppJObj); } else { // oppJObj.put("createdon", new Date()); KwlReturnObject kmsg = crmOpportunityDAOObj.addOpportunities(oppJObj); } // tx.commit(); recCount++; } txnManager.commit(status); result = "{success:true,recCount:" + recCount + ",totalRecords:" + jobj.get("recordCount") + "}"; } } catch (ServiceException ex) { logger.warn(ex.getMessage(), ex); txnManager.rollback(status); } catch (JSONException ex) { logger.warn(ex.getMessage(), ex); txnManager.rollback(status); } catch (Exception ex) { logger.warn(ex.getMessage(), ex); } finally { // s.close(); return result; } }
From source file:com.krawler.esp.handlers.zohoRequestHandler.java
@Override public void run() { // new TransactionTemplate(transactionManager) // .execute(new TransactionCallbackWithoutResult() { // @Override // public void doInTransactionWithoutResult(TransactionStatus status) { // dao.lock(client, NONE); // dao.save(new Report(client, client.getTotal())); // client.setLastCreated(new Date()); // } // }); // Session session = null; try {/*from www . j a va2 s. co m*/ while (!processQueue.isEmpty()) { JSONObject tempObj = (JSONObject) processQueue.get(0); try { this.isWorking = true; String username = tempObj.getString("username"); String password = tempObj.getString("password"); //String apiKey = tempObj.getString("apikey"); String authToken = tempObj.getString("authtoken"); String userid = tempObj.getString("userid"); String companyid = tempObj.getString("companyid"); String ipAddress = tempObj.getString("ipaddress"); String tzDiff = tempObj.getString("tzdiff"); String parterName = tempObj.getString(Constants.SESSION_PARTNERNAME); String sysEmailId = tempObj.getString("sysemailid"); JSONObject accountResult = null; JSONObject leadResult = null; JSONObject potentialResult = null; JSONObject contactResult = null; String result = ""; if (tempObj.getBoolean("accounts")) { result = saveUpdateZohoAccounts(username, password, authToken, userid, companyid); accountResult = new JSONObject(result); } if (tempObj.getBoolean("leads")) { result = saveUpdateZohoLeads(username, password, authToken, userid, companyid); leadResult = new JSONObject(result); } if (tempObj.getBoolean("potentials")) { result = saveUpdateZohoPotentials(username, password, authToken, userid, companyid); potentialResult = new JSONObject(result); } if (tempObj.getBoolean("contacts")) { result = saveUpdateZohoContact(username, password, authToken, userid, companyid, ipAddress, tzDiff); contactResult = new JSONObject(result); } String htmltxt = "Report for data imported from zoho.<br/>"; String plainMsg = "Report for data imported from zoho.\n"; zohoImportLog zlog = new zohoImportLog(); if (accountResult != null) { zlog.setAccounts(Integer.parseInt(accountResult.getString("recCount"))); zlog.setFailedAccounts( (accountResult.getInt("totalRecords") - accountResult.getInt("recCount"))); htmltxt += "<br/><br/>Accounts:<br/>"; htmltxt += "Total Records Imported: " + accountResult.getString("recCount"); htmltxt += "<br/>Failed Records: " + (accountResult.getInt("totalRecords") - accountResult.getInt("recCount")); plainMsg += "\nAccounts:\n"; plainMsg += "Total Records Imported: " + accountResult.getString("recCount"); plainMsg += "\nFailed Records: " + (accountResult.getInt("totalRecords") - accountResult.getInt("recCount")); } if (leadResult != null) { zlog.setLeads(Integer.parseInt(leadResult.getString("recCount"))); zlog.setFailedLeads((leadResult.getInt("totalRecords") - leadResult.getInt("recCount"))); htmltxt += "<br/><br/>Leads:<br/>"; htmltxt += "Total Records Imported: " + leadResult.getString("recCount"); htmltxt += "<br/>Failed Records: " + (leadResult.getInt("totalRecords") - leadResult.getInt("recCount")); plainMsg += "\nLeads:\n"; plainMsg += "Total Records Imported: " + leadResult.getString("recCount"); plainMsg += "\nFailed Records: " + (leadResult.getInt("totalRecords") - leadResult.getInt("recCount")); } if (potentialResult != null) { zlog.setPotentials(Integer.parseInt(potentialResult.getString("recCount"))); zlog.setFailedPotentials( (potentialResult.getInt("totalRecords") - potentialResult.getInt("recCount"))); htmltxt += "<br/><br/>Potentials:<br/>"; htmltxt += "Total Records Imported: " + potentialResult.getString("recCount"); htmltxt += "<br/>Failed Records: " + (potentialResult.getInt("totalRecords") - potentialResult.getInt("recCount")); plainMsg += "\nPotentials:\n"; plainMsg += "Total Records Imported: " + potentialResult.getString("recCount"); plainMsg += "\nFailed Records: " + (potentialResult.getInt("totalRecords") - potentialResult.getInt("recCount")); } if (contactResult != null) { zlog.setContacts(Integer.parseInt(contactResult.getString("recCount"))); zlog.setFailedContacts( (contactResult.getInt("totalRecords") - contactResult.getInt("recCount"))); htmltxt += "<br/><br/>Contacts:<br/>"; htmltxt += "Total Records Imported: " + contactResult.getString("recCount"); htmltxt += "<br/>Failed Records: " + (contactResult.getInt("totalRecords") - contactResult.getInt("recCount")); plainMsg += "\nContacts:\n"; plainMsg += "Total Records Imported: " + contactResult.getString("recCount"); plainMsg += "\nFailed Records: " + (contactResult.getInt("totalRecords") - contactResult.getInt("recCount")); } htmltxt += "<br/><br/>For queries, email us at support@deskera.com<br/>"; htmltxt += parterName + " Team"; plainMsg += "\nFor queries, email us at support@deskera.com\n"; plainMsg += parterName + " Team"; // session = zohoRequestDAO.getCurrentSession(); // Transaction tx = session.beginTransaction(); DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("JE_Tx"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED); TransactionStatus status = txnManager.getTransaction(def); User u = (User) zohoRequestDAO.get(User.class, userid); zlog.setUserid(userid); zlog.setCompanyid(companyid); zlog.setDate(new java.util.Date()); zlog.setZusername(username); zohoRequestDAO.save(zlog); txnManager.commit(status); // tx.commit(); SendMailHandler.postMail(new String[] { u.getEmailID() }, parterName + " CRM - Report for data imported from zoho", htmltxt, plainMsg, parterName + " Admin<" + sysEmailId + ">"); } catch (MessagingException ex) { logger.warn(ex.getMessage(), ex); } catch (JSONException ex) { logger.warn(ex.getMessage(), ex); } finally { // session.close(); processQueue.remove(tempObj); } } } catch (Exception e) { logger.warn(e.getMessage(), e); } finally { this.isWorking = false; } }
From source file:com.krawler.formbuilder.servlet.ModuleBuilderController.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request/* ww w.ja v a2 s . c o m*/ * @param response servlet response */ public ModelAndView form(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException { String result = ""; boolean isFormSubmit = false; boolean commit = false; //Create transaction DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("JE_Tx"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED); TransactionStatus status = txnManager.getTransaction(def); try { int action = Integer.parseInt(request.getParameter("action")); switch (action) { case 0: commit = true; String formid = request.getParameter("formid"); String moduleid = request.getParameter("moduleid"); String formjson = request.getParameter("formjson"); String parentmodule = request.getParameter("parentmodule"); String jsondata = request.getParameter("jsondata"); String tbar = request.getParameter("tbar"); String bbar = request.getParameter("bbar"); // TODO add company id in param result = moduleDao.saveForm(formid, moduleid, formjson, parentmodule, jsondata, tbar, bbar); break; case 1: isFormSubmit = true; result = moduleDao.getAllForms(request.getParameter("moduleid")); break; // case 2: // result = getForm(session, request.getParameter("formid"),request); // break; case 3: commit = true; isFormSubmit = true; result = moduleDao.deleteForm(request.getParameter("id")); break; case 4: // TODO add company check int start = Integer.parseInt(request.getParameter("start")); int limit = Integer.parseInt(request.getParameter("limit")); result = moduleDao.getAllModules(request.getParameter("ss"), request.getParameter("sort"), request.getParameter("dir"), start, limit); break; case 5: isFormSubmit = true; commit = true; // TODO add company check result = moduleDao.createModule(request); break; /*case 6: // result = moduleBuilderGenerateTable.deleteFields(conn,request); break; */case 7: // TODO add company check result = moduleDao.getAllModulesForCombo(request); break; case 8: isFormSubmit = true; result = moduleDao.moduleData(request.getParameter("moduleid")); break; case 9: commit = true; isFormSubmit = true; result = moduleDao.deleteModule(request.getParameter("moduleid")); break; case 10: //result = moduleDao.getGridData(request); String tname = request.getParameter("tablename"); moduleid = request.getParameter("moduleid"); Object modObj = Class.forName("com.krawler.esp.hibernate.impl." + tname).newInstance(); result = moduleDao.getModuleRecords(moduleid, modObj, prepareClauses(request), DATE_FORMAT); break; case 11: result = moduleDao.getModuleConfig(request.getParameter("moduleid")); break; /*case 12: result = getSearchFieldSet(session,request); break;*/ case 13: commit = true; result = moduleDao.saveModuleGridConfig(request.getParameter("jsondata")); break; /*case 14: result = setSearchField(session,request); break;*/ case 15: result = moduleDao.getComboField(request.getParameter("moduleid")); break; case 21: result = moduleDao.getComboData(request.getParameter("moduleid"), request.getParameter("name")); break; case 22: commit = true; isFormSubmit = true; result = "{'success':false, 'msg':'Error occured at server.'}"; //this function will not be called (Parto of old modulebuilder) List fileItems = new ArrayList(); Map arrParams = prepareData(request, fileItems); List modInfo = moduleDao.getModuleInfo((String) arrParams.get("moduleid")); result = moduleDao.createNewRecord(filterData(arrParams, modInfo), fileItems, (String) arrParams.get("moduleid"));//moduleBuilderMethods.createNewRecord(session,request); break; case 23: commit = true; isFormSubmit = true; result = "{'success':false, 'msg':'Error occured at server.'}"; List fileItems1 = new ArrayList(); Map arrParams1 = prepareData(request, fileItems1); List modInfo1 = moduleDao.getModuleInfo((String) arrParams1.get("moduleid")); result = moduleDao.editRecord(filterData(arrParams1, modInfo1), fileItems1, "id", (String) arrParams1.get("moduleid"));//moduleBuilderMethods.editRecord(session,request); break; case 24: commit = true; // isFormSubmit=true; result = moduleDao.deleteRecord("id", request.getParameter("id"), request.getParameter("moduleid"));//moduleBuilderMethods.deleteRecord(session,request); break; case 25: String basemode = request.getParameter("basemode"); String mdlid = request.getParameter("moduleid"); String reportid = request.getParameter("reportid"); String taskid = request.getParameter("taskid"); result = moduleDao.openSubModules(basemode, mdlid, reportid, taskid); break; case 26: result = moduleDao.getOtherModules(request.getParameter("moduleid"), request.getParameter("mode")); break; case 27: commit = true; result = moduleDao.configSubtabModules(request.getParameter("basemodule"), request.getParameter("submodule"), request.getParameter("mode"), request.getParameter("columnname")); break; case 29: commit = true; isFormSubmit = true; result = moduleDao.uploadFile(request);//moduleBuilderMethods.uploadFile(session,request); break; case 30: result = moduleDao.getAttachment(request);//moduleBuilderMethods.getAttachment(session, request); break; case 31: result = moduleDao.getStdCongifType(request.getParameter("reportid")); break; case 32: commit = true; int configid = 0; try { configid = Integer.parseInt(request.getParameter("configid")); } catch (Exception ex) { logger.warn(ex.getMessage(), ex); } result = moduleDao.getModuleCongifType(configid, request.getParameter("add"), request.getParameter("reportid"), request.getParameter("deleteconfig")); break; case 33: String comboValueId = request.getParameter("comboValueId"); List<ModuleClause> clauses = new ArrayList<ModuleClause>(); clauses.add(new ModuleClause("id", "=", comboValueId)); result = moduleDao.getReadOnlyFields(request.getParameter("moduleid"), request.getParameterValues("appenid"), clauses, DATE_FORMAT); break; case 34: result = moduleDao.getModuleForCombo(request); break; case 35: commit = true; result = deployProject(); break; case 36: commit = true; isFormSubmit = true; result = moduleDao.editModule(request); break; case 37: // isFormSubmit=true; result = moduleDao.getAllModules1(request.getParameter("moduleid")); break; case 38: result = moduleDao.getTableColumn(request.getParameter("moduleid")); break; case 39: isFormSubmit = true; result = moduleDao.getformWithParentvalue(request.getParameter("parentmodule"), request.getParameter("childmodule"), request.getParameter("modulevar")); break; case 40: commit = true; String moduleidParam = request.getParameter("moduleid"); String tablename1 = request.getParameter(PARAM_TABLE_NAME); result = moduleDao.buildModule(moduleidParam, tablename1); break; case 45:// Not find any reference String tablename = request.getParameter(PARAM_TABLE_NAME); Object moduleObj = Class.forName("com.krawler.esp.hibernate.impl." + tablename).newInstance(); result = moduleDao.getModuleRecords(moduleObj, DATE_FORMAT); break; case 46: moduleid = request.getParameter("moduleid"); result = moduleDao.getModuleRecords(moduleid, request.getParameter("tablename"), prepareClauses(request), DATE_FORMAT); break; case 47: moduleid = request.getParameter("moduleid"); result = moduleDao.getModuleRecords(moduleid, request.getParameter("tablename"), prepareClauses(request), DATE_FORMAT); break; case 48: isFormSubmit = true; result = moduleDao.getPortletData(request); break; } if (commit) { txnManager.commit(status); } else { txnManager.rollback(status); } } catch (NumberFormatException e) { logger.warn(e.getMessage(), e); txnManager.rollback(status); } catch (ServiceException ex) { logger.warn(ex.getMessage(), ex); txnManager.rollback(status); } catch (Exception ex) { logger.warn(ex.getMessage(), ex); txnManager.rollback(status); } if (isFormSubmit) { return new ModelAndView("jsonView-ex", "model", result); } return new ModelAndView("jsonView", "model", result); }
From source file:com.krawler.spring.common.CommonFnController.java
public ModelAndView saveUsers(HttpServletRequest request, HttpServletResponse response) { HashMap hm = null;//w w w. j a v a 2 s . co m String msg = ""; Boolean success = false; JSONObject jobj = new JSONObject(); DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("CF_Tx"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status = txnManager.getTransaction(def); try { hm = new FileUploadHandler().getItems(request); HashMap<String, Object> requestMap = generateMap(hm); KwlReturnObject rtObj = profileHandlerDAOObj.saveUser(requestMap); User usr = (User) rtObj.getEntityList().get(0); String imageName = ((FileItem) (hm.get("userimage"))).getName(); if (StringUtil.isNullOrEmpty(imageName) == false) { String fileName = usr.getUserID() + FileUploadHandler.getImageExt(); usr.setImage(ProfileImageServlet.ImgBasePath + fileName); new FileUploadHandler().uploadImage((FileItem) hm.get("userimage"), fileName, StorageHandler.GetProfileImgStorePath(), 100, 100, false, false); } success = true; msg = messageSource.getMessage("acc.rem.189", null, RequestContextUtils.getLocale(request)); txnManager.commit(status); } catch (ServiceException ex) { success = false; msg = ex.getMessage(); txnManager.rollback(status); Logger.getLogger(CommonFnController.class.getName()).log(Level.SEVERE, "saveUsers", ex); } catch (Exception ex) { msg = "" + ex.getMessage(); success = false; txnManager.rollback(status); Logger.getLogger(CommonFnController.class.getName()).log(Level.SEVERE, "saveUsers", ex); } finally { try { jobj.put("success", success); jobj.put("msg", msg); } catch (com.krawler.utils.json.base.JSONException ex) { Logger.getLogger(CommonFnController.class.getName()).log(Level.SEVERE, null, ex); } } // } return new ModelAndView("jsonView_ex", "model", jobj.toString()); }
From source file:com.krawler.spring.common.CommonFnController.java
public ModelAndView changeUserPassword(HttpServletRequest request, HttpServletResponse response) { JSONObject jobj = new JSONObject(); KwlReturnObject kmsg = null;//from www. j a v a 2 s . c o m //Create transaction DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("CF_Tx"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status = txnManager.getTransaction(def); try { String platformURL = this.getServletContext().getInitParameter("platformURL"); HashMap<String, Object> requestParams = new HashMap<String, Object>(); requestParams.put("currentpassword", StringUtil.checkForNull(request.getParameter("currentpassword"))); requestParams.put("changepassword", StringUtil.checkForNull(request.getParameter("changepassword"))); requestParams.put("userid", sessionHandlerImpl.getUserid(request)); requestParams.put("companyid", sessionHandlerImpl.getCompanyid(request)); requestParams.put("remoteapikey", ConfigReader.getinstance().get("remoteapikey")); kmsg = profileHandlerDAOObj.changeUserPassword(platformURL, requestParams); jobj = (JSONObject) kmsg.getEntityList().get(0); txnManager.commit(status); jobj.put("success", true); } catch (Exception e) { System.out.println(e.getMessage()); txnManager.rollback(status); } return new ModelAndView("jsonView", "model", jobj.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 ww w . j a va 2s .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.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.crm.accountModule.crmAccountController.java
public ModelAndView newAccount(HttpServletRequest request, HttpServletResponse response) throws ServletException { JSONObject myjobj = new JSONObject(); JSONObject jobj = new JSONObject(); KwlReturnObject kmsg = null;/* ww w. ja v a 2s.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 { 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 repAccount(HttpServletRequest request, HttpServletResponse response) throws ServletException { JSONObject myjobj = new JSONObject(); String jsondata = request.getParameter("val"); KwlReturnObject kmsg = null;// ww w . ja v a 2 s . co m CrmAccount acc = null; JSONObject jobj; //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 { jobj = new JSONObject(jsondata); JSONArray jarr = new JSONArray(); jarr = jobj.getJSONArray("userdata"); for (int ctr = 0; ctr < jarr.length(); ctr++) { jobj = jarr.getJSONObject(ctr); String contactno = jobj.getString("contactno"); jobj.put("phone", contactno); jobj.put("tzdiff", sessionHandlerImpl.getTimeZoneDifference(request)); kmsg = crmAccountDAOObj.editAccounts(jobj); acc = (CrmAccount) kmsg.getEntityList().get(0); } myjobj.put("success", true); myjobj.put("ID", acc.getAccountid()); 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 . j a v a2 s . c o m*/ 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.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 a 2 s. c om //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()); }