List of usage examples for org.springframework.validation BindingResult reject
void reject(String errorCode, String defaultMessage);
From source file:org.egov.works.contractorbill.service.ContractorBillRegisterService.java
public void validateTotalDebitAndCreditAmount(final ContractorBillRegister contractorBillRegister, final BindingResult resultBinder) { BigDecimal totalDebitAmount = BigDecimal.ZERO; BigDecimal totalCreditAmount = BigDecimal.ZERO; for (final EgBilldetails egBilldetails : contractorBillRegister.getEgBilldetailes()) { if (egBilldetails.getDebitamount() != null && !(BigDecimal.ZERO.compareTo(egBilldetails.getDebitamount()) == 0)) totalDebitAmount = totalDebitAmount.add(egBilldetails.getDebitamount()); if (egBilldetails.getCreditamount() != null && !(BigDecimal.ZERO.compareTo(egBilldetails.getCreditamount()) == 0)) totalCreditAmount = totalCreditAmount.add(egBilldetails.getCreditamount()); }/*from w ww . j a va 2 s . c om*/ if (!(totalDebitAmount.compareTo(totalCreditAmount) == 0)) resultBinder.reject("error.total.debitamount.creditamount.notequal", "error.total.debitamount.creditamount.notequal"); }
From source file:org.egov.works.contractorbill.service.ContractorBillRegisterService.java
public EgBilldetails getBillDetails(final ContractorBillRegister billregister, final EgBilldetails egBilldetails, final LineEstimateDetails lineEstimateDetails, final BindingResult resultBinder, final HttpServletRequest request) { egBilldetails.setFunctionid(new BigDecimal(lineEstimateDetails.getLineEstimate().getFunction().getId())); boolean isDebit = false; CChartOfAccounts coa = null;//from w w w .j a va 2 s. com if (!(BigDecimal.ZERO.compareTo(egBilldetails.getGlcodeid()) == 0)) coa = chartOfAccountsHibernateDAO.findById(egBilldetails.getGlcodeid().longValue(), false); if (coa != null && coa.getId() != null) egBilldetails.setGlcodeid(BigDecimal.valueOf(coa.getId())); if (egBilldetails.getDebitamount() != null && !(BigDecimal.ZERO.compareTo(egBilldetails.getDebitamount()) == 0)) { egBilldetails.setDebitamount(egBilldetails.getDebitamount()); isDebit = true; } else if (egBilldetails.getCreditamount() != null && !(BigDecimal.ZERO.compareTo(egBilldetails.getCreditamount()) == 0)) egBilldetails.setCreditamount(egBilldetails.getCreditamount()); else if (!org.apache.commons.lang.StringUtils.isBlank(request.getParameter("netPayableAccountCode")) && request.getParameter("netPayableAccountCode").toString().equals(egBilldetails.getGlcodeid())) resultBinder.reject("error.contractorbill.accountdetails.amount.required", "error.contractorbill.accountdetails.amount.required"); egBilldetails.setEgBillregister(billregister); final List<CChartOfAccounts> contractorRefundAccountList = chartOfAccountsHibernateDAO .getAccountCodeByListOfPurposeName(WorksConstants.CONTRACTOR_REFUND_PURPOSE); if (coa != null && coa.getGlcode() != null) { Accountdetailtype projectCodeAccountDetailType = null; Accountdetailtype contractorAccountDetailType = null; if (isDebit && !contractorRefundAccountList.isEmpty() && !contractorRefundAccountList.contains(coa)) { projectCodeAccountDetailType = chartOfAccountsHibernateDAO .getAccountDetailTypeIdByName(coa.getGlcode(), WorksConstants.PROJECTCODE); if (projectCodeAccountDetailType == null) resultBinder.reject("error.contractorBill.validate.glcode.for.projectcode.subledger", new String[] { coa.getGlcode() }, null); } final List<Accountdetailtype> detailCode = chartOfAccountsHibernateDAO .getAccountdetailtypeListByGLCode(coa.getGlcode()); if (detailCode != null && !detailCode.isEmpty()) { if (isDebit && !contractorRefundAccountList.isEmpty() && !contractorRefundAccountList.contains(coa)) { if (projectCodeAccountDetailType != null) egBilldetails.addEgBillPayeedetail(getEgPayeeDetails(egBilldetails, projectCodeAccountDetailType.getId(), egBilldetails.getDebitamount(), isDebit, Integer.valueOf(lineEstimateDetails.getProjectCode().getId().toString()))); } else { contractorAccountDetailType = chartOfAccountsHibernateDAO.getAccountDetailTypeIdByName( coa.getGlcode(), WorksConstants.ACCOUNTDETAIL_TYPE_CONTRACTOR); if (contractorAccountDetailType != null) egBilldetails.getEgBillPaydetailes().add(getEgPayeeDetails(egBilldetails, contractorAccountDetailType.getId(), isDebit ? egBilldetails.getDebitamount() : egBilldetails.getCreditamount(), isDebit, Integer.valueOf(billregister.getWorkOrder().getContractor().getId().toString()))); } if (projectCodeAccountDetailType == null && contractorAccountDetailType == null) resultBinder.reject("error.contractorbill.validate.glcode.for.subledger", new String[] { coa.getGlcode() }, null); } } egBilldetails.setLastupdatedtime(new Date()); return egBilldetails; }
From source file:org.egov.works.contractorbill.service.ContractorBillRegisterService.java
public void validateMileStonePercentage(final ContractorBillRegister contractorBillRegister, final BindingResult resultBinder) { TrackMilestone trackMileStone = null; if (contractorBillRegister.getBilltype().equalsIgnoreCase(BillTypes.Final_Bill.toString())) { trackMileStone = trackMilestoneService.getCompletionPercentageToCreateContractorFinalBill( contractorBillRegister.getWorkOrderEstimate().getId()); if (trackMileStone == null) resultBinder.reject("error.contractor.finalbill.milestonepercentage", "error.contractor.finalbill.milestonepercentage"); } else {/*from ww w . j a v a2 s . c om*/ trackMileStone = trackMilestoneService.getMinimumPercentageToCreateContractorBill( contractorBillRegister.getWorkOrderEstimate().getId()); if (trackMileStone == null) resultBinder.reject("error.contractorbil.milestone.percentage", "error.contractorbil.milestone.percentage"); } }
From source file:org.egov.works.contractorbill.service.ContractorBillRegisterService.java
public void validateZeroCreditAndDebitAmount(final ContractorBillRegister contractorBillRegister, final BindingResult resultBinder) { for (final EgBilldetails egBillDetail : contractorBillRegister.getEgBilldetailes()) if (egBillDetail.getCreditamount() != null && BigDecimal.ZERO.compareTo(egBillDetail.getCreditamount()) == 0 || egBillDetail.getDebitamount() != null && BigDecimal.ZERO.compareTo(egBillDetail.getDebitamount()) == 0) { resultBinder.reject("error.creditordebitamount.zero", "error.creditordebitamount.zero"); break; }//from w ww . j a v a 2 s. c o m }
From source file:org.egov.works.web.controller.contractorbill.CreateContractorBillController.java
@RequestMapping(value = "/contractorbill-save", method = RequestMethod.POST) public String create(@ModelAttribute("contractorBillRegister") ContractorBillRegister contractorBillRegister, final Model model, final BindingResult resultBinder, final HttpServletRequest request, @RequestParam String workFlowAction, @RequestParam("file") final MultipartFile[] files) throws IOException { final String loaNumber = request.getParameter("loaNumber"); final WorkOrder workOrder = letterOfAcceptanceService.getApprovedWorkOrder(loaNumber); final Date workCompletionDate = contractorBillRegister.getWorkOrderEstimate().getWorkCompletionDate(); final LineEstimateDetails lineEstimateDetails = lineEstimateService .findByEstimateNumber(workOrder.getEstimateNumber()); final AbstractEstimate abstractEstimate = estimateService .getAbstractEstimateByEstimateNumberAndStatus(lineEstimateDetails.getEstimateNumber()); final WorkOrderEstimate workOrderEstimate = workOrderEstimateService .getEstimateByWorkOrderAndEstimateAndStatus(workOrder.getId(), abstractEstimate.getId()); contractorBillRegister.setWorkOrder(workOrder); contractorBillRegister.setWorkOrderEstimate(workOrderEstimate); contractorBillRegister.getWorkOrderEstimate().setWorkCompletionDate(workCompletionDate); validateInput(contractorBillRegister, lineEstimateDetails, resultBinder, request); contractorBillRegister = addBillDetails(contractorBillRegister, lineEstimateDetails, resultBinder, request); contractorBillRegisterService.validateRefundAmount(contractorBillRegister, resultBinder); contractorBillRegisterService.validateMileStonePercentage(contractorBillRegister, resultBinder); if (!contractorBillRegisterService.checkForDuplicateAccountCodes(contractorBillRegister)) resultBinder.reject("error.contractorbill.duplicate.accountcodes", "error.contractorbill.duplicate.accountcodes"); if (!contractorBillRegisterService.validateDuplicateRefundAccountCodes(contractorBillRegister)) resultBinder.reject("error.contractorbill.duplicate.refund.accountcodes", "error.contractorbill.duplicate.refund.accountcodes"); contractorBillRegisterService.validateTotalDebitAndCreditAmount(contractorBillRegister, resultBinder); if (resultBinder.hasErrors()) { setDropDownValues(model);//from w w w . j ava 2 s. c o m model.addAttribute("lineEstimateDetails", lineEstimateDetails); model.addAttribute("workOrder", workOrder); model.addAttribute("workOrderEstimate", workOrderEstimate); model.addAttribute("netPayableAmount", request.getParameter("netPayableAmount")); model.addAttribute("netPayableAccountCode", request.getParameter("netPayableAccountCode")); model.addAttribute("stateType", contractorBillRegister.getClass().getSimpleName()); model.addAttribute("approvalDesignation", request.getParameter("approvalDesignation")); model.addAttribute("approvalPosition", request.getParameter("approvalPosition")); prepareWorkflow(model, contractorBillRegister, new WorkflowContainer()); model.addAttribute("mode", "edit"); model.addAttribute("billDetailsMap", contractorBillRegisterService.getBillDetailsMap(contractorBillRegister, model)); model.addAttribute("cutOffDate", worksApplicationProperties.getContractorBillCutOffDate()); return "contractorBill-form"; } else { Long approvalPosition = 0l; String approvalComment = ""; if (request.getParameter("approvalComment") != null) approvalComment = request.getParameter("approvalComent"); if (request.getParameter("workFlowAction") != null) workFlowAction = request.getParameter("workFlowAction"); if (request.getParameter("approvalPosition") != null && !request.getParameter("approvalPosition").isEmpty()) approvalPosition = Long.valueOf(request.getParameter("approvalPosition")); Integer partBillCount = contractorBillRegisterService .getMaxSequenceNumberByWorkOrder(workOrderEstimate); if (partBillCount == null || partBillCount == 0) partBillCount = 1; else partBillCount++; contractorBillRegister.setBillSequenceNumber(partBillCount); final ContractorBillNumberGenerator c = beanResolver .getAutoNumberServiceFor(ContractorBillNumberGenerator.class); final String contractorBillNumber = c.getNextNumber(contractorBillRegister); contractorBillRegister.setBillnumber(contractorBillNumber); contractorBillRegister.setPassedamount(contractorBillRegister.getBillamount()); ContractorBillRegister savedContractorBillRegister = null; try { savedContractorBillRegister = contractorBillRegisterService.create(contractorBillRegister, lineEstimateDetails, files, approvalPosition, approvalComment, null, workFlowAction); } catch (final ValidationException e) { // TODO: Used ApplicationRuntimeException for time being since // there is issue in session after // checkBudgetAndGenerateBANumber API call. Needs to replace // with errors.reject throw new ApplicationRuntimeException("error.contractorbill.budgetcheck.insufficient.amount"); /* * for (final ValidationError error : e.getErrors()) { if(error.getMessage().contains("Budget Check failed for ")) * { errors.reject(messageSource.getMessage( "error.contractorbill.budgetcheck.insufficient.amount",null, null)+ * ". " +error.getMessage()); } else errors.reject(error.getMessage()); } */ } final String pathVars = worksUtils.getPathVars(savedContractorBillRegister.getStatus(), savedContractorBillRegister.getState(), savedContractorBillRegister.getId(), approvalPosition); return "redirect:/contractorbill/contractorbill-success?pathVars=" + pathVars + "&billNumber=" + savedContractorBillRegister.getBillnumber(); } }
From source file:org.egov.works.web.controller.contractorbill.CreateContractorBillController.java
private ContractorBillRegister addBillDetails(final ContractorBillRegister contractorBillRegister, final LineEstimateDetails lineEstimateDetails, final BindingResult resultBinder, final HttpServletRequest request) { if (contractorBillRegister.getBillDetailes() == null || contractorBillRegister.getBillDetailes().isEmpty()) resultBinder.reject("error.contractorbill.accountdetails.required", "error.contractorbill.accountdetails.required"); for (final EgBilldetails egBilldetails : contractorBillRegister.getBillDetailes()) if (!contractorBillRegister.getEgBilldetailes().isEmpty() && contractorBillRegister.getEgBilldetailes().size() == 1) { for (final EgBilldetails refundBill : contractorBillRegister.getRefundBillDetails()) if (refundBill.getGlcodeid() != null) contractorBillRegister.addEgBilldetailes(contractorBillRegisterService.getBillDetails( contractorBillRegister, refundBill, lineEstimateDetails, resultBinder, request)); if (egBilldetails.getGlcodeid() != null) contractorBillRegister.addEgBilldetailes(contractorBillRegisterService.getBillDetails( contractorBillRegister, egBilldetails, lineEstimateDetails, resultBinder, request)); } else if (egBilldetails.getGlcodeid() != null) contractorBillRegister.addEgBilldetailes(contractorBillRegisterService.getBillDetails( contractorBillRegister, egBilldetails, lineEstimateDetails, resultBinder, request)); contractorBillRegisterService.validateZeroCreditAndDebitAmount(contractorBillRegister, resultBinder); final String netPayableAccountCodeId = request.getParameter("netPayableAccountCode"); final String netPayableAmount = request.getParameter("netPayableAmount"); if (org.apache.commons.lang.StringUtils.isNotBlank(netPayableAccountCodeId) && org.apache.commons.lang.StringUtils.isNotBlank(netPayableAmount)) { final EgBilldetails billdetails = new EgBilldetails(); billdetails.setGlcodeid(new BigDecimal(netPayableAccountCodeId)); billdetails.setCreditamount(new BigDecimal(netPayableAmount)); contractorBillRegister.addEgBilldetailes(contractorBillRegisterService.getBillDetails( contractorBillRegister, billdetails, lineEstimateDetails, resultBinder, request)); }//from w ww .j a va 2 s .c om return contractorBillRegister; }
From source file:org.egov.works.web.controller.contractorbill.UpdateContractorBillController.java
@RequestMapping(value = "/update/{contractorBillRegisterId}", method = RequestMethod.POST) public String update( @Valid @ModelAttribute("contractorBillRegister") ContractorBillRegister contractorBillRegister, final BindingResult errors, final RedirectAttributes redirectAttributes, final Model model, final HttpServletRequest request, @RequestParam("file") final MultipartFile[] files) throws ApplicationException, IOException { String mode = ""; String workFlowAction = ""; ContractorBillRegister updatedContractorBillRegister = null; if (request.getParameter("mode") != null) mode = request.getParameter("mode"); if (request.getParameter("workFlowAction") != null) workFlowAction = request.getParameter("workFlowAction"); Long approvalPosition = 0l;// w w w . j av a 2 s . c o m String approvalComment = ""; if (request.getParameter("approvalComent") != null) approvalComment = request.getParameter("approvalComent"); if (request.getParameter("approvalPosition") != null && !request.getParameter("approvalPosition").isEmpty()) approvalPosition = Long.valueOf(request.getParameter("approvalPosition")); // For Get Configured ApprovalPosition from workflow history if (approvalPosition == null || approvalPosition.equals(Long.valueOf(0))) approvalPosition = contractorBillRegisterService.getApprovalPositionByMatrixDesignation( contractorBillRegister, approvalPosition, null, mode, workFlowAction); if ((approvalPosition == null || approvalPosition.equals(Long.valueOf(0))) && request.getParameter("approvalPosition") != null && !request.getParameter("approvalPosition").isEmpty()) approvalPosition = Long.valueOf(request.getParameter("approvalPosition")); try { if (contractorBillRegister.getStatus().getCode() .equals(ContractorBillRegister.BillStatus.REJECTED.toString()) && workFlowAction.equals(WorksConstants.FORWARD_ACTION)) contractorBillRegisterService.checkBudgetAndGenerateBANumber(contractorBillRegister); } catch (final ValidationException e) { // TODO: Used ApplicationRuntimeException for time being since there // is issue in session after // checkBudgetAndGenerateBANumber API call. Needs to replace with // errors.reject throw new ApplicationRuntimeException("error.contractorbill.budgetcheck.insufficient.amount"); /* * for (final ValidationError error : e.getErrors()) { if(error.getMessage().contains("Budget Check failed for ")) { * errors.reject(messageSource.getMessage( "error.contractorbill.budgetcheck.insufficient.amount",null,null) +". " * +error.getMessage()); } else errors.reject(error.getMessage()); } */ } if (contractorBillRegister.getStatus().getCode() .equals(ContractorBillRegister.BillStatus.REJECTED.toString()) && workFlowAction.equals(WorksConstants.FORWARD_ACTION) && mode.equals("edit")) { final WorkOrder workOrder = contractorBillRegister.getWorkOrder(); final LineEstimateDetails lineEstimateDetails = lineEstimateService .findByEstimateNumber(workOrder.getEstimateNumber()); validateInput(contractorBillRegister, lineEstimateDetails, errors, request); contractorBillRegister.getEgBilldetailes().clear(); contractorBillRegister = addBillDetails(contractorBillRegister, lineEstimateDetails, errors, request); contractorBillRegister.setPassedamount(contractorBillRegister.getBillamount()); if (!contractorBillRegisterService.checkForDuplicateAccountCodes(contractorBillRegister)) errors.reject("error.contractorbill.duplicate.accountcodes", "error.contractorbill.duplicate.accountcodes"); if (!contractorBillRegisterService.validateDuplicateRefundAccountCodes(contractorBillRegister)) errors.reject("error.contractorbill.duplicate.refund.accountcodes", "error.contractorbill.duplicate.refund.accountcodes"); contractorBillRegisterService.validateTotalDebitAndCreditAmount(contractorBillRegister, errors); contractorBillRegisterService.validateRefundAmount(contractorBillRegister, errors); contractorBillRegisterService.validateMileStonePercentage(contractorBillRegister, errors); } if (errors.hasErrors()) { setDropDownValues(model); return loadViewData(model, request, contractorBillRegister); } else { if (null != workFlowAction) updatedContractorBillRegister = contractorBillRegisterService.updateContractorBillRegister( contractorBillRegister, approvalPosition, approvalComment, null, workFlowAction, mode, files); redirectAttributes.addFlashAttribute("contractorBillRegister", updatedContractorBillRegister); final String pathVars = worksUtils.getPathVars(updatedContractorBillRegister.getStatus(), updatedContractorBillRegister.getState(), updatedContractorBillRegister.getId(), approvalPosition); return "redirect:/contractorbill/contractorbill-success?pathVars=" + pathVars + "&billNumber=" + updatedContractorBillRegister.getBillnumber(); } }
From source file:org.egov.works.web.controller.contractorbill.UpdateContractorBillController.java
private ContractorBillRegister addBillDetails(final ContractorBillRegister contractorBillRegister, final LineEstimateDetails lineEstimateDetails, final BindingResult resultBinder, final HttpServletRequest request) { if (contractorBillRegister.getBillDetailes() == null || contractorBillRegister.getBillDetailes().isEmpty()) resultBinder.reject("error.contractorbill.accountdetails.required", "error.contractorbill.accountdetails.required"); for (final EgBilldetails egBilldetails : contractorBillRegister.getBillDetailes()) if (!contractorBillRegister.getEgBilldetailes().isEmpty() && contractorBillRegister.getEgBilldetailes().size() == 1) { for (final EgBilldetails refundBill : contractorBillRegister.getRefundBillDetails()) if (refundBill.getGlcodeid() != null) contractorBillRegister.addEgBilldetailes(contractorBillRegisterService.getBillDetails( contractorBillRegister, refundBill, lineEstimateDetails, resultBinder, request)); if (egBilldetails.getGlcodeid() != null) contractorBillRegister.addEgBilldetailes(contractorBillRegisterService.getBillDetails( contractorBillRegister, egBilldetails, lineEstimateDetails, resultBinder, request)); } else if (egBilldetails.getGlcodeid() != null) contractorBillRegister.addEgBilldetailes(contractorBillRegisterService.getBillDetails( contractorBillRegister, egBilldetails, lineEstimateDetails, resultBinder, request)); contractorBillRegisterService.validateZeroCreditAndDebitAmount(contractorBillRegister, resultBinder); final String netPayableAccountId = request.getParameter("netPayableAccountId"); final String netPayableAccountCodeId = request.getParameter("netPayableAccountCode"); final String netPayableAmount = request.getParameter("netPayableAmount"); if (StringUtils.isNotBlank(netPayableAccountCodeId) && StringUtils.isNotBlank(netPayableAccountCodeId) && StringUtils.isNotBlank(netPayableAmount)) { final EgBilldetails billdetails = new EgBilldetails(); billdetails.setId(Integer.valueOf(netPayableAccountId)); billdetails.setGlcodeid(new BigDecimal(netPayableAccountCodeId)); billdetails.setCreditamount(new BigDecimal(netPayableAmount)); contractorBillRegister.addEgBilldetailes(contractorBillRegisterService.getBillDetails( contractorBillRegister, billdetails, lineEstimateDetails, resultBinder, request)); }/*from ww w . j av a 2s. c om*/ return contractorBillRegister; }
From source file:org.egov.works.web.controller.lineestimate.CreateSpillOverLineEstimateController.java
private void validateBudgetHead(final LineEstimate lineEstimate, final BindingResult errors) { if (lineEstimate.getBudgetHead() != null) { Boolean check = false;//from w w w. j av a 2 s .c o m final List<CChartOfAccountDetail> accountDetails = new ArrayList<CChartOfAccountDetail>(); accountDetails.addAll(lineEstimate.getBudgetHead().getMaxCode().getChartOfAccountDetails()); for (final CChartOfAccountDetail detail : accountDetails) if (detail.getDetailTypeId() != null && detail.getDetailTypeId().getName().equalsIgnoreCase(WorksConstants.PROJECTCODE)) check = true; if (!check) errors.reject("error.budgethead.validate", "error.budgethead.validate"); } }
From source file:org.egov.works.web.controller.lineestimate.CreateSpillOverLineEstimateController.java
private void validateLineEstimate(final LineEstimate lineEstimate, final BindingResult errors) { if (!lineEstimateService.getLineEstimateHiddenFields().contains("subject") && lineEstimate.getSubject() == null) errors.reject("error.subject.required", "error.subject.required"); if (!lineEstimateService.getLineEstimateHiddenFields().contains("description") && lineEstimate.getDescription() == null) errors.reject("error.description.required", "error.description.required"); }