List of usage examples for org.springframework.transaction.support DefaultTransactionDefinition setName
public final void setName(String name)
From source file:com.krawler.spring.profileHandler.profileHandlerController.java
public ModelAndView changePassword(HttpServletRequest request, HttpServletResponse response) throws ServletException { JSONObject jobj = new JSONObject(); KwlReturnObject kmsg = null;/* www .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 platformURL = this.getServletContext().getInitParameter("platformURL"); String platformURL = ConfigReader.getinstance().get("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("platformURL", platformURL); requestParams.put("userid", sessionHandlerImpl.getUserid(request)); requestParams.put("companyid", sessionHandlerImpl.getCompanyid(request)); kmsg = profileHandlerDAOObj.changePassword(requestParams); jobj = (JSONObject) kmsg.getEntityList().get(0); jobj.put("success", kmsg.isSuccessFlag()); txnManager.commit(status); } catch (Exception e) { logger.warn("General exception in changePassword()", e); txnManager.rollback(status); } return new ModelAndView("jsonView", "model", jobj.toString()); }
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//from w ww . j a va 2 s. com * @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:org.ohmage.query.impl.UserMobilityQueries.java
/** * Creates a new Mobility point.//from w w w .j a v a2s .c o m * * @param username The username of the user to which this point belongs. * * @param client The client value given on upload. * * @param mobilityPoint The Mobility point to be created. * * @throws DataAccessException Thrown if there is an error. */ @Override public void createMobilityPoint(final String username, final String client, final MobilityPoint mobilityPoint) throws DataAccessException { // Create the transaction. DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("Creating a Mobility data point."); try { // Begin the transaction. PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource()); TransactionStatus status = transactionManager.getTransaction(def); JSONObject location = null; try { Location tLocation = mobilityPoint.getLocation(); if (tLocation != null) { try { location = tLocation.toJson(false, LocationColumnKey.ALL_COLUMNS); } catch (DomainException e) { throw new DataAccessException(e); } } } catch (JSONException e) { throw new DataAccessException(e); } try { KeyHolder mobilityPointDatabaseKeyHolder = new GeneratedKeyHolder(); getJdbcTemplate().update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement(SQL_INSERT, new String[] { "id" }); ps.setString(1, mobilityPoint.getId().toString()); ps.setString(2, username); ps.setString(3, client); ps.setLong(4, mobilityPoint.getTime()); ps.setString(5, mobilityPoint.getTimezone().getID()); ps.setString(6, mobilityPoint.getLocationStatus().toString().toLowerCase()); try { Location location = mobilityPoint.getLocation(); ps.setString(7, ((location == null) ? null : location.toJson(false, LocationColumnKey.ALL_COLUMNS).toString())); } catch (JSONException e) { throw new SQLException("Could not create a JSONObject for the location.", e); } catch (DomainException e) { throw new SQLException("Could not create a JSONObject for the location.", e); } ps.setString(8, mobilityPoint.getMode().toString().toLowerCase()); ps.setString(9, mobilityPoint.getPrivacyState().toString()); return ps; } }, mobilityPointDatabaseKeyHolder); // If it's an extended entry, add the sensor data. if (SubType.SENSOR_DATA.equals(mobilityPoint.getSubType())) { JSONObject sensorData; try { sensorData = mobilityPoint.getSensorData().toJson(false, SensorDataColumnKey.ALL_COLUMNS); } catch (JSONException e) { throw new DataAccessException(e); } catch (DomainException e) { throw new DataAccessException(e); } JSONObject classifierData; try { ClassifierData tClassifierData = mobilityPoint.getClassifierData(); if (tClassifierData == null) { classifierData = null; } else { classifierData = tClassifierData.toJson(false, ClassifierDataColumnKey.ALL_COLUMNS); } } catch (JSONException e) { throw new DataAccessException(e); } catch (DomainException e) { throw new DataAccessException(e); } try { getJdbcTemplate().update(SQL_INSERT_EXTENDED, mobilityPointDatabaseKeyHolder.getKey().longValue(), sensorData.toString(), (classifierData == null) ? (new JSONObject()).toString() : classifierData.toString(), MobilityClassifier.getVersion()); } catch (org.springframework.dao.DataAccessException e) { transactionManager.rollback(status); throw new DataAccessException( "Error executing SQL '" + SQL_INSERT_EXTENDED + "' with parameters: " + mobilityPointDatabaseKeyHolder.getKey().longValue() + ", " + sensorData.toString() + ", " + ((classifierData == null) ? (new JSONObject()).toString() : classifierData.toString()) + ", " + MobilityClassifier.getVersion(), e); } } } // If this is a duplicate upload, we will ignore it by rolling back // to where we were before we started and return. catch (org.springframework.dao.DataIntegrityViolationException e) { // FIXME: Now that we use UUIDs, the client should not be // submitting duplicates. We probably want to, at the very // least make a warning message and at most fail the request. if (!isDuplicate(e)) { transactionManager.rollback(status); throw new DataAccessException("Error executing SQL '" + SQL_INSERT + "' with parameters: " + mobilityPoint.getId().toString() + ", " + username + ", " + client + ", " + mobilityPoint.getTime() + ", " + mobilityPoint.getTimezone().getID() + ", " + mobilityPoint.getLocationStatus().toString().toLowerCase() + ", " + ((location == null) ? "null" : location.toString()) + ", " + mobilityPoint.getMode().toString().toLowerCase() + ", " + mobilityPoint.getPrivacyState(), e); } } catch (org.springframework.dao.DataAccessException e) { transactionManager.rollback(status); throw new DataAccessException("Error executing SQL '" + SQL_INSERT + "' with parameters: " + mobilityPoint.getId().toString() + ", " + username + ", " + client + ", " + mobilityPoint.getTime() + ", " + mobilityPoint.getTimezone().getID() + ", " + mobilityPoint.getLocationStatus().toString().toLowerCase() + ", " + ((location == null) ? "null" : location.toString()) + ", " + mobilityPoint.getMode().toString().toLowerCase() + ", " + mobilityPoint.getPrivacyState(), e); } // Commit the transaction. try { transactionManager.commit(status); } catch (TransactionException e) { transactionManager.rollback(status); throw new DataAccessException("Error while committing the transaction.", e); } } catch (TransactionException e) { throw new DataAccessException("Error while attempting to rollback the transaction.", e); } }
From source file:com.krawler.esp.handlers.zohoRequestHandler.java
public String saveUpdateZohoAccounts(String username, String password, String authToken, String userid, String companyid) {/* ww w . j a v a2s . co m*/ // 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 CrmAccount c where c.accountid= ?"; JSONObject jobj = getRecordJson("Accounts", 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 existingContact = zohoRequestDAO.executeQuery(Hql, new Object[] { recObj.get("ACCOUNTID") }); JSONObject accJObj = new JSONObject(); accJObj.put("accountid", recObj.get("ACCOUNTID")); accJObj.put("companyid", companyid); accJObj.put("userid", userid); accJObj.put("updatedon", new Date()); accJObj.put("accountname", recObj.getString("Account Name").equals("null") ? "" : recObj.getString("Account Name")); accJObj.put("description", ""); accJObj.put("email", recObj.getString("Website").equals("null") ? "" : recObj.getString("Website")); accJObj.put("phone", recObj.getString("Phone").equals("null") ? "" : recObj.getString("Phone")); accJObj.put("revenue", recObj.getString("Annual Revenue").equals("null") ? "" : recObj.getString("Annual Revenue")); accJObj.put("validflag", 1); accJObj.put("accountownerid", userid); accJObj.put("isarchive", false); accJObj.put("deleteflag", 0); if (existingContact.size() > 0) { KwlReturnObject kmsg = crmAccountDAOObj.editAccounts(accJObj); } else { // accJObj.put("createdon", new Date()); KwlReturnObject kmsg = crmAccountDAOObj.addAccounts(accJObj); } 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 e) { logger.warn(e.getMessage(), e); } finally { // s.close(); return result; } }
From source file:com.krawler.esp.handlers.zohoRequestHandler.java
public String saveUpdateZohoLeads(String username, String password, String authToken, String userid, String companyid) {/*from ww w . ja v a 2 s. c o m*/ // 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 CrmLead c where c.leadid= ?"; JSONObject jobj = getRecordJson("Leads", 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) hibernateTemplate.beginTransaction(); JSONObject recObj = dataArray.getJSONObject(cnt); List existingContact = zohoRequestDAO.executeQuery(Hql, new Object[] { recObj.get("LEADID") }); JSONObject jobjret = new JSONObject(); String fname = recObj.getString("First Name"); String lname = recObj.getString("Last Name"); lname = fname.equalsIgnoreCase("null") ? lname : fname + " " + lname; lname = lname.trim(); jobjret.put("lastname", recObj.getString("Last Name").equals("null") ? "" : lname); jobjret.put("email", recObj.getString("Email").equals("null") ? "" : recObj.getString("Email")); jobjret.put("phone", recObj.getString("Phone").equals("null") ? "" : recObj.getString("Phone")); jobjret.put("validflag", 1); jobjret.put("userid", userid); jobjret.put("companyid", companyid); jobjret.put("isconverted", "0"); jobjret.put("istransfered", "0"); jobjret.put("type", "0"); jobjret.put("updatedon", new Date()); jobjret.put("leadid", recObj.getString("LEADID")); jobjret.put("leadownerid", userid); jobjret.put("isarchive", false); jobjret.put("deleteflag", 0); if (existingContact.size() > 0) { KwlReturnObject kmsg = crmLeadDAOObj.editLeads(jobjret); } else { KwlReturnObject kmsg = crmLeadDAOObj.addLeads(jobjret); } 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); txnManager.rollback(status); } finally { // s.close(); return result; } }
From source file:com.krawler.esp.handlers.zohoRequestHandler.java
public String saveUpdateZohoContact(String username, String password, String authToken, String userid, String companyid, String ipAddress, String tzdiff) { // 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 {/*from ww w . j a v a 2s . c o m*/ String Hql = "from CrmContact c where c.contactid= ?"; JSONObject jobj = getRecordJson("Contacts", 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 existingContact = zohoRequestDAO.executeQuery(Hql, new Object[] { recObj.get("CONTACTID") }); JSONObject conJObj = new JSONObject(); String conid = recObj.get("CONTACTID").toString(); conJObj.put("contactid", conid); conJObj.put("companyid", companyid); conJObj.put("userid", userid); conJObj.put("contactownerid", userid); conJObj.put("updatedon", new Date()); conJObj.put("description", ""); conJObj.put("phone", recObj.getString("Phone").equals("null") ? "" : recObj.getString("Phone")); conJObj.put("isarchive", false); conJObj.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) { conJObj.put("accountid", recObj.get("ACCOUNTID")); } conJObj.put("email", recObj.getString("Email").equals("null") ? "" : recObj.getString("Email")); conJObj.put("firstname", recObj.getString("First Name").equals("null") ? "" : recObj.getString("First Name")); conJObj.put("lastname", recObj.getString("Last Name").equals("null") ? "" : recObj.getString("Last Name")); conJObj.put("validflag", 1); if (existingContact.size() == 0) { conJObj.put("contactid", "0"); } contactManagementService.saveContact(companyid, userid, tzdiff, ipAddress, conJObj); // 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 e) { logger.warn(e.getMessage(), e); } finally { // s.close(); return result; } }
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. j a v a 2 s. c o m*/ // 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:org.ohmage.query.impl.ClassQueries.java
@Override public void deleteClass(String classId) throws DataAccessException { // Create the transaction. DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("Deleting a class."); try {//from ww w.j a v a 2s . co m // Begin the transaction. PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource()); TransactionStatus status = transactionManager.getTransaction(def); try { getJdbcTemplate().update(SQL_DELETE_CLASS, new Object[] { classId }); } catch (org.springframework.dao.DataAccessException e) { transactionManager.rollback(status); throw new DataAccessException( "Error while executing SQL '" + SQL_DELETE_CLASS + "' with parameter: " + classId, e); } // Commit the transaction. try { transactionManager.commit(status); } catch (TransactionException e) { transactionManager.rollback(status); throw new DataAccessException("Error while committing the transaction.", e); } } catch (TransactionException e) { throw new DataAccessException("Error while attempting to rollback the transaction.", e); } }
From source file:org.ohmage.query.impl.ClassQueries.java
@Override public void createClass(String classId, String className, String classDescription) throws DataAccessException { // Create the transaction. DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("Creating a new class."); try {/*from ww w .ja v a 2s.co m*/ // Begin the transaction. PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource()); TransactionStatus status = transactionManager.getTransaction(def); // Insert the class. try { getJdbcTemplate().update(SQL_INSERT_CLASS, new Object[] { classId, className, classDescription }); } catch (org.springframework.dao.DataAccessException e) { transactionManager.rollback(status); throw new DataAccessException("Error while executing SQL '" + SQL_INSERT_CLASS + "' with parameters: " + classId + ", " + className + ", " + classDescription, e); } // Commit the transaction. try { transactionManager.commit(status); } catch (TransactionException e) { transactionManager.rollback(status); throw new DataAccessException("Error while committing the transaction.", e); } } catch (TransactionException e) { throw new DataAccessException("Error while attempting to rollback the transaction.", e); } }
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 {/* ww w . j a v a 2 s.c o 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; } }