List of usage examples for org.springframework.transaction.support DefaultTransactionDefinition setPropagationBehavior
public final void setPropagationBehavior(int propagationBehavior)
From source file:org.bitsofinfo.util.address.usps.ais.store.jpa.JPAStore.java
private Copyright processCopyright(Copyright copyright) throws StoreException { Copyright c = this.entityMgr.find(Copyright.class, copyright.getIdentifier()); if (c == null) { DefaultTransactionDefinition td = new DefaultTransactionDefinition(); td.setName("Process copyright"); td.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus txs = this.transactionManager.getTransaction(td); try {/*from ww w .ja v a 2s.co m*/ this.saveRecord(copyright); this.transactionManager.commit(txs); } catch (DataIntegrityViolationException e) { if (!txs.isCompleted()) { this.transactionManager.rollback(txs); } // ignore this, it is fine, some other load beat us to it c = this.entityMgr.find(Copyright.class, copyright.getIdentifier()); } c = copyright; } return c; }
From source file:es.tid.fiware.rss.expenditureLimit.processing.test.ProcessingLimitServiceTest.java
/** * Check that the acummulated is set to 0 and added a negative value (refund) *///from w w w . j a v a2 s .co m @Test public void updateResetControls() { try { DbeTransaction tx = ProcessingLimitServiceTest.generateTransaction(); // Set user for testing tx.setTxEndUserId("userIdUpdate"); tx.setTcTransactionType(Constants.REFUND_TYPE); tx.setFtChargedTotalAmount(new BigDecimal(2)); List<DbeExpendControl> controls = controlService.getExpendDataForUserAppProvCurrencyObCountry( tx.getTxEndUserId(), tx.getBmService(), tx.getTxAppProvider(), tx.getBmCurrency(), tx.getBmObMop().getBmObCountry()); DbeExpendControl control = controls.get(0); // Reset period Date date = new Date(); date.setTime((new Date()).getTime() - 100000000); control.setDtNextPeriodStart(date); DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus status = transactionManager.getTransaction(def); controlService.createOrUpdate(control); transactionManager.commit(status); limitService.updateLimit(tx); List<DbeExpendControl> controls2 = controlService.getExpendDataForUserAppProvCurrencyObCountry( tx.getTxEndUserId(), tx.getBmService(), tx.getTxAppProvider(), tx.getBmCurrency(), tx.getBmObMop().getBmObCountry()); for (DbeExpendControl controlAux : controls2) { if (control.getId().getTxElType().equalsIgnoreCase(controlAux.getId().getTxElType())) { Assert.assertTrue(controlAux.getFtExpensedAmount().compareTo(new BigDecimal(-2)) == 0); } } } catch (RSSException e) { Assert.fail("Exception not expected" + e.getMessage()); } }
From source file:org.bitsofinfo.util.address.usps.ais.store.jpa.JPAStore.java
private void processNonCopyrightRecords(List<USPSRecord> records, Copyright copyright) throws StoreException { DefaultTransactionDefinition td = new DefaultTransactionDefinition(); td.setName("Process copyright"); td.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus txs = this.transactionManager.getTransaction(td); try {// ww w . j av a2 s. co m //copyright = this.entityMgr.merge(copyright); for (USPSRecord r : records) { // skip copyrights if it is the same one passed in above if (r instanceof Copyright) { if (r.getIdentifier().equals(copyright.getIdentifier())) { // chuck it as it has already been processed continue; } } // ensure the copyright is linked r.setCopyright(copyright); // if we use the action code, use that to // determine to save or delete. if (r.getActionCode() == ActionCode.D) { this.deleteRecord(r); } else { this.saveRecord(r); } } this.transactionManager.commit(txs); } catch (Exception e) { this.transactionManager.rollback(txs); } }
From source file:com.krawler.spring.crm.caseModule.CrmCustomerCaseController.java
public ModelAndView addComment(HttpServletRequest request, HttpServletResponse response) { Map model = new HashMap(); String responseMessage = ""; DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("JE_Tx"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED); TransactionStatus status = txnManager.getTransaction(def); try {//from w w w. j a va 2 s. c o m if ((String) request.getSession().getAttribute(Constants.SESSION_CUSTOMER_ID) != null) { String caseId = request.getParameter("caseid"); String userId = (String) request.getSession().getAttribute("contactid"); String comment = request.getParameter("addcomment"); crmCustomerCaseService.addComment(caseId, userId, comment); txnManager.commit(status); request.setAttribute("casedetails", "true"); request.setAttribute("caseid", caseId); } else { request.setAttribute("logout", "true"); } responseMessage = "usercases/redirect"; } catch (Exception e) { logger.warn(e.getMessage(), e); txnManager.rollback(status); } return new ModelAndView(responseMessage, "model", model); }
From source file:es.tid.fiware.rss.expenditureLimit.processing.test.ProcessingLimitServiceTest.java
/** * Update periods and check amounts./*w ww . j a va 2 s . c o m*/ */ @Test @Transactional(propagation = Propagation.SUPPORTS) public void checkControls() { DbeTransaction tx = ProcessingLimitServiceTest.generateTransaction(); tx.setTxEndUserId("userIdUpdate"); try { List<DbeExpendControl> controlsBefore = controlService.getExpendDataForUserAppProvCurrencyObCountry( tx.getTxEndUserId(), tx.getBmService(), tx.getTxAppProvider(), tx.getBmCurrency(), tx.getBmObMop().getBmObCountry()); Assert.assertNotNull(controlsBefore); // Reset dates to current date--> if not test fail GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.DAY_OF_MONTH, 1); DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus status = transactionManager.getTransaction(def); for (DbeExpendControl control : controlsBefore) { control.setDtNextPeriodStart(cal.getTime()); controlService.createOrUpdate(control); } transactionManager.commit(status); limitService.proccesLimit(tx); List<DbeExpendControl> controlsAfter = controlService.getExpendDataForUserAppProvCurrencyObCountry( tx.getTxEndUserId(), tx.getBmService(), tx.getTxAppProvider(), tx.getBmCurrency(), tx.getBmObMop().getBmObCountry()); ProcessingLimitServiceTest.logger.debug("Controls:" + controlsAfter.size()); for (DbeExpendControl controlInit : controlsBefore) { for (DbeExpendControl controlEnd : controlsAfter) { if (controlInit.getId().getTxElType().equalsIgnoreCase(controlEnd.getId().getTxElType())) { // All the values without modification Assert.assertTrue( controlInit.getFtExpensedAmount().compareTo(controlEnd.getFtExpensedAmount()) == 0); break; } } } } catch (RSSException e) { ProcessingLimitServiceTest.logger.debug("Error: " + e.getMessage()); Assert.fail("Exception not expected"); } // check error try { tx.setFtChargedTotalAmount(null); tx.setFtInternalTotalAmount(new BigDecimal(1000)); limitService.proccesLimit(tx); Assert.fail("Exception expected"); } catch (RSSException e) { ProcessingLimitServiceTest.logger.debug("Exception received: " + e.getMessage()); // "SVC3705", Assert.assertTrue(e.getMessage().contains("Insufficient payment method balance")); } // check that try { tx.setFtChargedTotalAmount(null); tx.setFtInternalTotalAmount(new BigDecimal(30)); List<DbeExpendControl> controlsBefore = controlService.getExpendDataForUserAppProvCurrencyObCountry( tx.getTxEndUserId(), tx.getBmService(), tx.getTxAppProvider(), tx.getBmCurrency(), tx.getBmObMop().getBmObCountry()); // Reset period DbeExpendControl control = controlsBefore.get(0); GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.MONTH, -1); control.setDtNextPeriodStart(cal.getTime()); DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus status = transactionManager.getTransaction(def); controlService.update(control); transactionManager.commit(status); limitService.proccesLimit(tx); List<DbeExpendControl> controlsAfter = controlService.getExpendDataForUserAppProvCurrencyObCountry( tx.getTxEndUserId(), tx.getBmService(), tx.getTxAppProvider(), tx.getBmCurrency(), tx.getBmObMop().getBmObCountry()); boolean finded = false; for (DbeExpendControl checkControl : controlsAfter) { if (checkControl.getFtExpensedAmount().compareTo(new BigDecimal(0)) == 0) { finded = true; break; } } // reset control found Assert.assertTrue(finded); } catch (RSSException e) { ProcessingLimitServiceTest.logger.debug("Exception received: " + e.getMessage()); Assert.fail("Exception expected"); } }
From source file:com.krawler.spring.crm.common.commentController.java
public ModelAndView addComments(HttpServletRequest request, HttpServletResponse response) throws ServletException { JSONObject jobj = new JSONObject(); JSONObject myjobj = new JSONObject(); KwlReturnObject kmsg = null;/* ww w .j a v a2s .co m*/ Object c; String details = ""; String auditAction = ""; String id = java.util.UUID.randomUUID().toString(); String randomnumber = request.getParameter("randomnumber"); String moduleName = request.getParameter("modulename"); String jsondata = request.getParameter("jsondata"); String map = ""; String refid = ""; //Create transaction DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("JE_Tx"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED); TransactionStatus status = txnManager.getTransaction(def); try { String userid = sessionHandlerImpl.getUserid(request); String companyid = sessionHandlerImpl.getCompanyid(request); JSONArray jarr = new JSONArray("[" + jsondata + "]"); for (int i = 0; i < jarr.length(); i++) { jobj = jarr.getJSONObject(i); map = jobj.getString("mapid"); refid = jobj.getString("leadid"); String commStrAudit = StringUtil.serverHTMLStripper(jobj.getString("comment")); commStrAudit = commStrAudit.replaceAll(" ", ""); String cid = java.util.UUID.randomUUID().toString(); String commentid = jobj.getString("commentid"); jobj.put("userid", userid); jobj.put("companyid", companyid); jobj.put("cid", cid); jobj.put("refid", refid); if (StringUtil.isNullOrEmpty(commentid)) { // Add Mode jobj.put("id", id); if (moduleName.equals(Constants.Case)) {//Case crmCommentDAOObj.addCaseComments(jobj); } else { kmsg = crmCommentDAOObj.addComments(jobj); } } else { // Edit Mode jobj.put("id", commentid.trim()); if (moduleName.equals(Constants.Case)) { kmsg = crmCommentDAOObj.editCaseComments(jobj); } else { kmsg = crmCommentDAOObj.editComments(jobj); } } //@@@ - Need to restructure this code if (map.equals("0")) { c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmCampaign", refid); details = " Campaign - "; details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "campaignname")) ? "" : BeanUtils.getProperty(c, "campaignname"); auditAction = AuditAction.CAMPAIGN_ADD_COMMENTS; } else if (map.equals("1")) { c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmLead", refid); details = " Lead - "; details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "firstname")) ? "" : BeanUtils.getProperty(c, "firstname") + " "; details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "lastname")) ? "" : BeanUtils.getProperty(c, "lastname"); auditAction = AuditAction.LEAD_ADD_COMMENTS; } else if (map.equals("2")) { c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmContact", refid); details = " Contact - "; details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "firstname")) ? "" : BeanUtils.getProperty(c, "firstname"); details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "lastname")) ? "" : BeanUtils.getProperty(c, "lastname"); auditAction = AuditAction.CONTACT_ADD_COMMENTS; } else if (map.equals("3")) { c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmProduct", refid); details = " Product - "; details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "productname")) ? "" : BeanUtils.getProperty(c, "productname"); auditAction = AuditAction.PRODUCT_ADD_COMMENTS; } else if (map.equals("4")) { c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmAccount", refid); details = " Account - "; details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "accountname")) ? "" : BeanUtils.getProperty(c, "accountname"); auditAction = AuditAction.ACCOUNT_ADD_COMMENTS; } else if (map.equals("5")) { c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmOpportunity", refid); details = " Opportunity - "; details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "oppname")) ? "" : BeanUtils.getProperty(c, "oppname"); auditAction = AuditAction.OPPORTUNITY_ADD_COMMENTS; } else if (map.equals("6")) { c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmCase", refid); details = " Case - "; details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "subject")) ? "" : BeanUtils.getProperty(c, "subject"); auditAction = AuditAction.CASE_ADD_COMMENTS; } else if (map.equals("7")) { c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmActivityMaster", refid); String subject = StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "subject")) ? "" : "(" + BeanUtils.getProperty(c, "subject") + ")"; // String aname = BeanUtils.getProperty(c,"crmCombodataByStatusid.aliasName"); // if(!StringUtil.isNullOrEmpty(aname)){ // comboStatus=aname; // } details = " Activity - " + BeanUtils.getProperty(c, "flag") + " " + subject; auditAction = AuditAction.ACTIVITY_ADD_COMMENTS; } auditTrailDAOObj.insertAuditLog(auditAction, " Comment: '" + commStrAudit + "' , added for " + details, request, refid, id); } myjobj.put("ID", id); txnManager.commit(status); // add comment on other logins for same user try { JSONObject commetMap = new JSONObject(); boolean isCommentAdded = kmsg.isSuccessFlag(); int operationCode = CrmPublisherHandler.ADDCOMMENT; commetMap.put("isCommentAdded", isCommentAdded); commetMap.put("recid", refid); commetMap.put("modulename", moduleName); cometManagementService.publishModuleInformation(companyid, userid, randomnumber, moduleName, refid, operationCode, commetMap, CometConstants.CRMUPDATES); } catch (Exception e) { } } catch (Exception e) { System.out.println(e.getMessage()); txnManager.rollback(status); } return new ModelAndView("jsonView", "model", myjobj.toString()); }
From source file:es.upm.fiware.rss.expenditureLimit.processing.test.ProcessingLimitServiceTest.java
/** * /*from w w w. j a v a2 s . c o m*/ * Check that not existing control are created. */ @Transactional(propagation = Propagation.SUPPORTS) public void creationControls() { try { DbeTransaction tx = ProcessingLimitServiceTest.generateTransaction(); // Set user for testing tx.setTxEndUserId("userForCreation"); List<DbeExpendControl> controls = controlService.getExpendDataForUserAppProvCurrency( tx.getTxEndUserId(), tx.getAppProvider().getId().getAggregator().getTxEmail(), tx.getAppProvider().getId().getTxAppProviderId(), tx.getBmCurrency()); Assert.assertTrue(controls.isEmpty()); // Update limits. DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus status = transactionManager.getTransaction(def); limitService.proccesLimit(tx); transactionManager.commit(status); controls = controlService.getExpendDataForUserAppProvCurrency(tx.getTxEndUserId(), tx.getAppProvider().getId().getAggregator().getTxEmail(), tx.getAppProvider().getId().getTxAppProviderId(), tx.getBmCurrency()); Assert.assertNotNull(controls); Assert.assertTrue(controls.size() == 3); // All the new control have to be set to 0 for (DbeExpendControl control : controls) { Assert.assertTrue(control.getFtExpensedAmount().compareTo(new BigDecimal(0)) == 0); } ProcessingLimitServiceTest.logger.debug("Controls:" + controls.size()); } catch (RSSException e) { ProcessingLimitServiceTest.logger.debug("Error: " + e.getMessage()); } }
From source file:es.upm.fiware.rss.expenditureLimit.processing.test.ProcessingLimitServiceTest.java
/** * Check that the acummulated is set to 0 and added a negative value (refund) *//*from w w w. ja v a 2 s. c om*/ @Transactional public void updateResetControls() { try { DbeTransaction tx = ProcessingLimitServiceTest.generateTransaction(); // Set user for testing tx.setTxEndUserId("userIdUpdate"); tx.setTcTransactionType(Constants.REFUND_TYPE); tx.setFtChargedAmount(new BigDecimal(2)); List<DbeExpendControl> controls = this.getExpenditureControls(tx); DbeExpendControl control = controls.get(0); // Reset period Date date = new Date(); date.setTime((new Date()).getTime() - 100000000); control.setDtNextPeriodStart(date); DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus status = transactionManager.getTransaction(def); controlService.createOrUpdate(control); transactionManager.commit(status); limitService.updateLimit(tx); List<DbeExpendControl> controls2 = this.getExpenditureControls(tx); for (DbeExpendControl controlAux : controls2) { if (control.getId().getTxElType().equalsIgnoreCase(controlAux.getId().getTxElType())) { Assert.assertTrue("Expensed amount: " + controlAux.getFtExpensedAmount(), controlAux.getFtExpensedAmount().compareTo(new BigDecimal(-2)) == 0); } } } catch (RSSException e) { Assert.fail("Exception not expected" + e.getMessage()); } }
From source file:com.krawler.spring.crm.caseModule.CrmCustomerCaseController.java
public ModelAndView custPassword_Change(HttpServletRequest request, HttpServletResponse response) throws ServletException { String newpass = request.getParameter("newpass"); String currentpass = request.getParameter("curpass"); String customerid = request.getParameter("customerid"); String email = request.getParameter("email"); Map model = new HashMap(); // String replaceStr=request.getParameter("cdomain"); String url = URLUtil.getRequestPageURL(request, Links.UnprotectedLoginPageFull); String loginurl = url.concat("caselogin.jsp"); String name = request.getParameter("cname"); boolean verify_pass = false; String responseMessage = ""; if ((String) request.getSession().getAttribute(Constants.SESSION_CUSTOMER_ID) != null) { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("JE_Tx"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED); TransactionStatus status = txnManager.getTransaction(def); try {/*from w w w . j a v a 2s .c o m*/ verify_pass = contactManagementService.verifyCurrentPass(currentpass, customerid); if (verify_pass) { contactManagementService.custPassword_Change(newpass, customerid); txnManager.commit(status); request.setAttribute("homepage", "true"); request.setAttribute("success", "true"); responseMessage = "usercases/redirect"; String partnerNames = sessionHandlerImplObj.getPartnerName(); String sysEmailId = sessionHandlerImplObj.getSystemEmailId(); String passwordString = "Username: " + email + " <br/><br/>Password: <b>" + newpass + "</b>"; String htmlmsg = "Dear <b>" + name + "</b>,<br/><br/> Your <b>password has been changed</b> for your account on " + partnerNames + " CRM. <br/><br/>" + passwordString + "<br/><br/>You can log in at:\n" + loginurl + "<br/><br/>See you on " + partnerNames + " CRM <br/><br/> -The " + partnerNames + " CRM Team"; try { SendMailHandler.postMail(new String[] { email }, "[" + partnerNames + "] Password Changed", htmlmsg, "", sysEmailId, partnerNames + " Admin"); } catch (MessagingException e) { e.printStackTrace(); } } else { request.setAttribute("changepassword", "true"); request.setAttribute("mis_pass", "true"); txnManager.commit(status); } } catch (Exception e) { logger.warn("custPassword_change Error:", e); txnManager.rollback(status); responseMessage = "../../usercases/failure"; } } else { request.setAttribute("logout", "true"); } responseMessage = "usercases/redirect"; return new ModelAndView(responseMessage, "model", model); }