List of usage examples for org.springframework.transaction.support DefaultTransactionDefinition setName
public final void setName(String name)
From source file:com.krawler.spring.crm.caseModule.crmCaseController.java
public ModelAndView deleteCase(HttpServletRequest request, HttpServletResponse response) throws ServletException { JSONObject myjobj = null;/* ww w .j a v a 2s . co m*/ KwlReturnObject kmsg = null; CrmCase cases = null; //Create transaction DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("JE_Tx"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED); TransactionStatus status = txnManager.getTransaction(def); JSONArray jarr = null; try { String userid = sessionHandlerImpl.getUserid(request); ArrayList caseids = new ArrayList(); myjobj = new JSONObject(); myjobj.put("success", false); if (StringUtil.bNull(request.getParameter("jsondata"))) { String jsondata = request.getParameter("jsondata"); jarr = new JSONArray("[" + jsondata + "]"); for (int i = 0; i < jarr.length(); i++) { JSONObject jobject = jarr.getJSONObject(i); caseids.add(jobject.getString("caseid").toString()); } String[] arrayid = (String[]) caseids.toArray(new String[] {}); JSONObject jobj = new JSONObject(); jobj.put("deleteflag", 1); jobj.put("caseid", arrayid); jobj.put("userid", userid); jobj.put("updatedon", new Date().getTime()); kmsg = crmCaseDAOObj.updateMassCases(jobj); List<CrmCase> ll = crmCaseDAOObj.getCases(caseids); if (ll != null) { for (int i = 0; i < ll.size(); i++) { CrmCase caseaudit = (CrmCase) ll.get(i); if (caseaudit.getValidflag() == 1) { auditTrailDAOObj.insertAuditLog(AuditAction.CASE_DELETE, caseaudit.getSubject() + " - Case deleted ", request, caseaudit.getCaseid()); } } } } myjobj.put("success", true); myjobj.put("ID", caseids.toArray()); txnManager.commit(status); if (jarr != null) { JSONObject cometObj = new JSONObject(); cometObj.put("ids", jarr); publishCasesModuleInformation(request, cometObj, CrmPublisherHandler.DELETERECORDCODE, sessionHandlerImpl.getCompanyid(request), userid); } } catch (JSONException e) { LOGGER.warn(e.getMessage(), e); txnManager.rollback(status); } catch (Exception e) { LOGGER.warn(e.getMessage(), e); txnManager.rollback(status); } return new ModelAndView("jsonView", "model", myjobj.toString()); }
From source file:com.krawler.spring.crm.caseModule.crmCaseController.java
public ModelAndView updateMassCases(HttpServletRequest request, HttpServletResponse response) throws ServletException { JSONObject myjobj = new JSONObject(); KwlReturnObject kmsg = null;/*from w w w. j a v a 2 s .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 { JSONObject jobj = new JSONObject(request.getParameter("jsondata")); String companyid = sessionHandlerImpl.getCompanyid(request); String userid = sessionHandlerImpl.getUserid(request); Integer operationCode = CrmPublisherHandler.UPDATERECORDCODE; String caseIds = jobj.getString("caseid"); String arrayId[] = caseIds.split(","); jobj.put("userid", userid); jobj.put("companyid", companyid); if (jobj.has("updatedon") && !StringUtil.isNullOrEmpty(jobj.getString("updatedon"))) { jobj.put("updatedon", jobj.getLong("updatedon")); } else { jobj.put("updatedon", new Date().getTime()); } jobj.put("caseid", arrayId); jobj.put("tzdiff", sessionHandlerImpl.getTimeZoneDifference(request)); JSONArray jcustomarray = null; if (jobj.has("customfield")) { jcustomarray = jobj.getJSONArray("customfield"); } if (jobj.has("customfield")) { HashMap<String, Object> customrequestParams = new HashMap<String, Object>(); customrequestParams.put("customarray", jcustomarray); customrequestParams.put("modulename", Constants.Crm_Case_modulename); customrequestParams.put("moduleprimarykey", Constants.Crm_Caseid); customrequestParams.put("companyid", companyid); customrequestParams.put("customdataclasspath", Constants.Crm_case_custom_data_classpath); KwlReturnObject customDataresult = null; for (String id : arrayId) { customrequestParams.put("modulerecid", id); customDataresult = fieldDataManagercntrl.setCustomData(customrequestParams); } if (customDataresult != null && customDataresult.getEntityList().size() > 0) { jobj.put("CrmCaseCustomDataobj", true); } } if (jobj.has("createdon")) { jobj.put("createdon", jobj.getLong("createdon")); } kmsg = crmCaseDAOObj.updateMassCases(jobj); // TODO : How to insert audit log when mass update // cases = (CrmCase) kmsg.getEntityList().get(0); // if (cases.getValidflag() == 1) { // auditTrailDAOObj.insertAuditLog(AuditAction.CASE_UPDATE, // jobj.getString("auditstr") + " Case - " + ((acc.getCasename() == // null) ? "" : acc.getCasename()) + " ", // request, id); // } // } JSONObject cometObj = jobj; if (request.getParameter("massEdit") != null && Boolean.parseBoolean(request.getParameter("massEdit"))) { crmCommonService.validateMassupdate(arrayId, "Case", companyid); cometObj.put("caseid", caseIds); cometObj.put("ismassedit", true); } myjobj.put("success", true); myjobj.put("ID", caseIds); myjobj.put("createdon", jobj.has("createdon") ? jobj.getLong("createdon") : ""); if (!StringUtil.isNullObject(cases)) { if (cases.getCreatedOn() != null) { cometObj.put("createdon", cases.getCreatedonGMT()); } } publishCasesModuleInformation(request, cometObj, operationCode, companyid, userid); txnManager.commit(status); } catch (Exception e) { LOGGER.warn(e.getMessage(), e); txnManager.rollback(status); } return new ModelAndView("jsonView", "model", myjobj.toString()); }
From source file:com.krawler.spring.crm.accountModule.crmAccountController.java
public ModelAndView repAccount(HttpServletRequest request, HttpServletResponse response) throws ServletException { JSONObject myjobj = new JSONObject(); String jsondata = request.getParameter("val"); KwlReturnObject kmsg = null;// w w w . j a v a 2 s. c o 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.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. jav a2 s . c om*/ 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;/* w ww . ja 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()); }
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;//from w ww.j a v a 2 s . com 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:org.ohmage.query.impl.SurveyResponseQueries.java
public void deleteSurveyResponse(final UUID surveyResponseId) throws DataAccessException { // Create the transaction. DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("Deleting a survey response."); try {/*w ww . ja v a 2s . co m*/ // Begin the transaction. PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource()); TransactionStatus status = transactionManager.getTransaction(def); try { getJdbcTemplate().update(SQL_DELETE_SURVEY_RESPONSE, new Object[] { surveyResponseId.toString() }); } catch (org.springframework.dao.DataAccessException e) { transactionManager.rollback(status); throw new DataAccessException("Error executing SQL '" + SQL_DELETE_SURVEY_RESPONSE + "' with parameter: " + surveyResponseId.toString(), 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.spring.crm.accountModule.crmAccountController.java
public ModelAndView deleteAccount(HttpServletRequest request, HttpServletResponse response) throws ServletException { JSONObject myjobj = null;//from w w w . ja 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:org.ohmage.query.impl.SurveyResponseQueries.java
public void updateSurveyResponsesPrivacyState(final Set<UUID> surveyResponseIds, final SurveyResponse.PrivacyState newPrivacyState) throws DataAccessException { StringBuilder sqlBuilder = new StringBuilder(SQL_UPDATE_SURVEY_RESPONSES_PRIVACY_STATE); sqlBuilder.append(StringUtils.generateStatementPList(surveyResponseIds.size())); List<Object> parameters = new ArrayList<Object>(surveyResponseIds.size() + 1); parameters.add(newPrivacyState.toString()); for (UUID surveyResponseId : surveyResponseIds) { parameters.add(surveyResponseId.toString()); }// w ww. j a va 2 s . c o m // Create the transaction. DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("Updating a survey response."); try { // Begin the transaction. PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource()); TransactionStatus status = transactionManager.getTransaction(def); try { getJdbcTemplate().update(sqlBuilder.toString(), parameters.toArray()); } catch (org.springframework.dao.DataAccessException e) { transactionManager.rollback(status); throw new DataAccessException("Error executing SQL '" + sqlBuilder.toString() + "' with parameters: " + parameters.toArray(), 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.spring.crm.caseModule.crmCaseController.java
public ModelAndView saveCases(HttpServletRequest request, HttpServletResponse response) throws ServletException { JSONObject myjobj = new JSONObject(); KwlReturnObject kmsg = null;/*from w ww . j a va 2 s .c om*/ 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()); }