Example usage for org.springframework.validation BindingResult reject

List of usage examples for org.springframework.validation BindingResult reject

Introduction

In this page you can find the example usage for org.springframework.validation BindingResult reject.

Prototype

void reject(String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage);

Source Link

Document

Register a global error for the entire target object, using the given error description.

Usage

From source file:org.egov.stms.web.controller.transactions.SewerageUpdateConnectionController.java

@RequestMapping(value = "/update/{applicationNumber}", method = RequestMethod.POST)
public String update(@ModelAttribute SewerageApplicationDetails sewerageApplicationDetails,
        final BindingResult resultBinder, final RedirectAttributes redirectAttributes,
        final HttpServletRequest request, final HttpSession session, final Model model,
        @RequestParam("files") final MultipartFile[] files, @RequestParam final String removedInspectRowId,
        @RequestParam final String removedEstimationDtlRowId) {
    String mode = "";
    String workFlowAction = "";

    if (request.getParameter("workFlowAction") != null)
        workFlowAction = request.getParameter("workFlowAction");
    sewerageApplicationValidator.validateNewApplicationUpdate(sewerageApplicationDetails, resultBinder,
            workFlowAction);/*  www.  j av  a2  s .  c o  m*/

    if (workFlowAction != null && WF_STATE_CONNECTION_EXECUTION_BUTTON.equalsIgnoreCase(workFlowAction)) {
        final SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
        if (sewerageApplicationDetails.getConnection().getExecutionDate() == null)
            resultBinder.rejectValue("connection.executionDate", "err.executiondate.required.validate");
        else if (org.apache.commons.lang.StringUtils

                .isNotEmpty(sewerageApplicationDetails.getConnection().getExecutionDate().toString())) {
            formatter.format(sewerageApplicationDetails.getConnection().getExecutionDate());
            if (sewerageApplicationDetails.getConnection().getExecutionDate()
                    .compareTo(sewerageApplicationDetails.getApplicationDate()) < 0)
                resultBinder.reject("err.connectionexecution.date.validate",
                        new String[] { formatter.format(sewerageApplicationDetails.getApplicationDate()) },
                        "err.connectionexecution.date.validate");

        }
    }

    if (request.getParameter("mode") != null)
        mode = request.getParameter("mode");

    if (resultBinder.hasErrors()) {
        model.addAttribute("sewerageApplcationDetails", sewerageApplicationDetails);
        loadViewData(model, request, sewerageApplicationDetails);
        return NEWCONNECTION_EDIT;
    }

    request.getSession().setAttribute(SewerageTaxConstants.WORKFLOW_ACTION, workFlowAction);
    if ((sewerageApplicationDetails.getStatus().getCode()
            .equalsIgnoreCase(SewerageTaxConstants.APPLICATION_STATUS_CREATED)
            || sewerageApplicationDetails.getStatus().getCode()
                    .equalsIgnoreCase(SewerageTaxConstants.APPLICATION_STATUS_INSPECTIONFEEPAID)
            || sewerageApplicationDetails.getStatus().getCode()
                    .equalsIgnoreCase(SewerageTaxConstants.APPLICATION_STATUS_FEECOLLECTIONPENDING)
            || sewerageApplicationDetails.getStatus().getCode()
                    .equalsIgnoreCase(SewerageTaxConstants.APPLICATION_STATUS_INITIALAPPROVED)
            || sewerageApplicationDetails.getStatus().getCode()
                    .equalsIgnoreCase(SewerageTaxConstants.APPLICATION_STATUS_DEEAPPROVED))
            && "edit".equalsIgnoreCase(mode))
        if (workFlowAction.equalsIgnoreCase(SewerageTaxConstants.WFLOW_ACTION_STEP_FORWARD)
                || workFlowAction.equalsIgnoreCase(SewerageTaxConstants.WF_ESTIMATION_NOTICE_BUTTON)) {

            final List<SewerageConnectionEstimationDetails> existingSewerage = populateEstimationDetails(
                    sewerageApplicationDetails);

            final List<SewerageFieldInspectionDetails> existingInspection = populateInspectionDetails(
                    sewerageApplicationDetails, request, files);

            populateFeesDetails(sewerageApplicationDetails);
            sewerageApplicationDetailsService.save(sewerageApplicationDetails);
            if (existingSewerage != null && !existingSewerage.isEmpty())
                sewerageEstimationDetailsService.deleteAllInBatch(existingSewerage);

            if (existingInspection != null && !existingInspection.isEmpty())
                sewerageFieldInspectionDetailsService.deleteAllInBatch(existingInspection);

        } else if (workFlowAction.equalsIgnoreCase(SewerageTaxConstants.WFLOW_ACTION_STEP_REJECT)) {
            sewerageApplicationDetailsService.getCurrentSession().evict(sewerageApplicationDetails);
            sewerageApplicationDetails = sewerageApplicationDetailsService
                    .findBy(sewerageApplicationDetails.getId());
        }

    if (sewerageApplicationDetails.getStatus().getCode() != null
            && sewerageApplicationDetails.getStatus().getCode()
                    .equalsIgnoreCase(SewerageTaxConstants.APPLICATION_STATUS_INITIALAPPROVED)
            || sewerageApplicationDetails.getStatus().getCode()
                    .equalsIgnoreCase(SewerageTaxConstants.APPLICATION_STATUS_DEEAPPROVED)
            || sewerageApplicationDetails.getStatus().getCode()
                    .equalsIgnoreCase(SewerageTaxConstants.APPLICATION_STATUS_INSPECTIONFEEPAID)
                    && !workFlowAction.equalsIgnoreCase(SewerageTaxConstants.WFLOW_ACTION_STEP_REJECT))
        populateDonationSewerageTax(sewerageApplicationDetails);

    Long approvalPosition = 0l;
    String approvalComment = "";

    if (request.getParameter(APPROVAL_COMENT) != null)
        approvalComment = request.getParameter(APPROVAL_COMENT);

    if (request.getParameter(APPROVAL_POSITION) != null && !request.getParameter(APPROVAL_POSITION).isEmpty())
        approvalPosition = Long.valueOf(request.getParameter(APPROVAL_POSITION));

    if ((approvalPosition == null || approvalPosition.equals(Long.valueOf(0)))
            && request.getParameter(APPROVAL_POSITION) != null
            && !request.getParameter(APPROVAL_POSITION).isEmpty())
        approvalPosition = Long.valueOf(request.getParameter(APPROVAL_POSITION));

    if (!resultBinder.hasErrors()) {
        try {
            if (null != workFlowAction
                    && workFlowAction.equalsIgnoreCase(SewerageTaxConstants.PREVIEWWORKFLOWACTION)
                    && sewerageApplicationDetails.getApplicationType().getCode()
                            .equals(SewerageTaxConstants.NEWSEWERAGECONNECTION))
                return "redirect:/transactions/workorder?pathVar="
                        + sewerageApplicationDetails.getApplicationNumber();

            sewerageApplicationDetailsService.updateSewerageApplicationDetails(sewerageApplicationDetails,
                    approvalPosition, approvalComment,
                    sewerageApplicationDetails.getApplicationType().getCode(), workFlowAction, mode, null,
                    request, session);
        } catch (final ValidationException e) {
            throw new ValidationException(e);
        }
        if (workFlowAction != null && !workFlowAction.isEmpty()
                && workFlowAction.equalsIgnoreCase(SewerageTaxConstants.WF_ESTIMATION_NOTICE_BUTTON))
            return "redirect:/transactions/estimationnotice?pathVar="
                    + sewerageApplicationDetails.getApplicationNumber();
        if (workFlowAction != null && !workFlowAction.isEmpty()
                && workFlowAction.equalsIgnoreCase(SewerageTaxConstants.WF_CLOSERACKNOWLDGEENT_BUTTON))
            return "redirect:/applications/acknowlgementNotice?pathVar="
                    + sewerageApplicationDetails.getApplicationNumber();
        if (workFlowAction != null && !workFlowAction.isEmpty()
                && workFlowAction.equalsIgnoreCase(SewerageTaxConstants.WFLOW_ACTION_STEP_CANCEL))
            return "redirect:/transactions/rejectionnotice?pathVar="
                    + sewerageApplicationDetails.getApplicationNumber() + "&" + "approvalComent="
                    + request.getParameter(APPROVAL_COMENT);
        final Assignment currentUserAssignment = assignmentService.getPrimaryAssignmentForGivenRange(
                securityUtils.getCurrentUser().getId(), new Date(), new Date());
        String nextDesign;
        Assignment assignObj = null;
        List<Assignment> asignList = Collections.emptyList();

        if (approvalPosition == null || approvalPosition == 0) {
            Assignment workflowInitiatorAssignment = sewerageWorkflowService
                    .getWorkFlowInitiator(sewerageApplicationDetails);
            if (workflowInitiatorAssignment != null)
                approvalPosition = (workflowInitiatorAssignment).getPosition().getId();
        }

        if (approvalPosition != null)
            assignObj = assignmentService.getPrimaryAssignmentForPositon(approvalPosition);
        if (assignObj != null) {
            asignList = new ArrayList<>();
            asignList.add(assignObj);
        } else if (assignObj == null && approvalPosition != null)
            asignList = assignmentService.getAssignmentsForPosition(approvalPosition, new Date());

        nextDesign = asignList.isEmpty() ? StringUtils.EMPTY : asignList.get(0).getDesignation().getName();

        final String pathVars = sewerageApplicationDetails.getApplicationNumber() + ","
                + sewerageTaxUtils.getApproverName(approvalPosition) + ","
                + (currentUserAssignment != null ? currentUserAssignment.getDesignation().getName() : "") + ","
                + (nextDesign != null ? nextDesign : "");
        return "redirect:/transactions/application-success?pathVars=" + pathVars;
    } else
        return loadViewData(model, request, sewerageApplicationDetails);
}

From source file:org.egov.works.contractorbill.service.ContractorBillRegisterService.java

public void validateRefundAmount(final ContractorBillRegister contractorBillRegister,
        final BindingResult resultBinder) {
    int index = 0;
    for (final EgBilldetails egBillDetail : contractorBillRegister.getRefundBillDetails()) {
        if (egBillDetail.getGlcodeid() != null && egBillDetail.getDebitamount() == null)
            resultBinder.rejectValue("refundBillDetails[" + index + "].debitamount",
                    "error.refundamount.required");
        if (egBillDetail.getDebitamount() != null && egBillDetail.getGlcodeid() == null)
            resultBinder.rejectValue("refundBillDetails[" + index + "].glcodeid",
                    "error.refundaccountcode.required");
        if (egBillDetail.getGlcodeid() != null && egBillDetail.getDebitamount() != null) {
            final CChartOfAccounts coa = chartOfAccountsHibernateDAO
                    .findById(egBillDetail.getGlcodeid().longValue(), false);
            final String amounts = getTotalDebitAndCreditAmountByAccountCode(
                    contractorBillRegister.getWorkOrderEstimate().getId(), new BigDecimal(coa.getId()),
                    contractorBillRegister.getId() != null ? contractorBillRegister.getId() : -1);
            if (!org.apache.commons.lang.StringUtils.isBlank(amounts)) {
                final String[] creditDebitAmounts = amounts.split(",");
                BigDecimal withheldAmount = BigDecimal.ZERO;
                BigDecimal refundedAmount = BigDecimal.ZERO;
                if (!creditDebitAmounts[0].equals("0"))
                    withheldAmount = new BigDecimal(creditDebitAmounts[0]);
                if (!creditDebitAmounts[1].equals("0"))
                    refundedAmount = new BigDecimal(creditDebitAmounts[1]);

                if (withheldAmount.equals("0"))
                    resultBinder.reject("error.contractorBill.nowithheldtorefund",
                            new String[] { coa.getGlcode() }, null);
                else {

                    final BigDecimal validRefundAmount = egBillDetail.getDebitamount().add(refundedAmount);
                    final BigDecimal diffAmount = validRefundAmount.subtract(withheldAmount);
                    if (validRefundAmount.compareTo(new BigDecimal(creditDebitAmounts[0])) == 1
                            && !contractorBillRegister.getWorkOrderEstimate().getEstimate()
                                    .getLineEstimateDetails().getLineEstimate().isSpillOverFlag())
                        resultBinder.reject("error.contractorBill.validate.refundAmount",
                                new String[] { coa.getGlcode(), diffAmount.toString() }, null);
                }/*from  ww w.  java2  s.  c  o  m*/
            }
        }
        index++;
    }

}

From source file:org.egov.works.web.controller.contractorbill.CreateContractorBillController.java

private void validateInput(final ContractorBillRegister contractorBillRegister,
        final LineEstimateDetails lineEstimateDetails, final BindingResult resultBinder,
        final HttpServletRequest request) {
    final boolean validateBillInWorkflow = letterOfAcceptanceService
            .validateContractorBillInWorkflowForWorkorder(contractorBillRegister.getWorkOrder().getId());
    if (!validateBillInWorkflow)
        resultBinder.reject("error.contractorbill.in.workflow.for.workorder",
                new String[] { contractorBillRegister.getWorkOrder().getWorkOrderNumber() }, null);

    BigDecimal totalBillAmountIncludingCurrentBill = contractorBillRegister.getBillamount();
    final BigDecimal totalBillAmount = contractorBillRegisterService
            .getTotalBillAmountByWorkOrder(contractorBillRegister.getWorkOrder());
    if (totalBillAmount != null)
        totalBillAmountIncludingCurrentBill = totalBillAmountIncludingCurrentBill.add(totalBillAmount);
    if (lineEstimateDetails.getLineEstimate().isBillsCreated()
            && lineEstimateDetails.getGrossAmountBilled() != null)
        totalBillAmountIncludingCurrentBill = totalBillAmountIncludingCurrentBill
                .add(lineEstimateDetails.getGrossAmountBilled());
    if (totalBillAmountIncludingCurrentBill.doubleValue() > contractorBillRegister.getWorkOrder()
            .getWorkOrderAmount())//  w  w  w . j a va2  s . c o  m
        resultBinder
                .reject("error.contractorbill.totalbillamount.exceeds.workorderamount",
                        new String[] { String.valueOf(totalBillAmountIncludingCurrentBill),
                                String.valueOf(contractorBillRegister.getWorkOrder().getWorkOrderAmount()) },
                        null);

    if (org.apache.commons.lang.StringUtils.isBlank(contractorBillRegister.getBilltype()))
        resultBinder.rejectValue("billtype", "error.billtype.required");
    if (contractorBillRegister.getEgBillregistermis() != null
            && contractorBillRegister.getEgBillregistermis().getPartyBillDate() != null
            && contractorBillRegister.getEgBillregistermis().getPartyBillDate()
                    .before(contractorBillRegister.getWorkOrder().getWorkOrderDate()))
        resultBinder.rejectValue("egBillregistermis.partyBillDate",
                "error.validate.partybilldate.lessthan.loadate");

    if (contractorBillRegister.getMbHeader() != null) {
        if (org.apache.commons.lang.StringUtils.isBlank(contractorBillRegister.getMbHeader().getMbRefNo()))
            resultBinder.rejectValue("mbHeader.mbRefNo", "error.mbrefno.required");

        if (contractorBillRegister.getMbHeader().getMbDate() == null)
            resultBinder.rejectValue("mbHeader.mbDate", "error.mbdate.required");

        if (contractorBillRegister.getMbHeader().getFromPageNo() == null)
            resultBinder.rejectValue("mbHeader.fromPageNo", "error.frompageno.required");

        if (contractorBillRegister.getMbHeader().getToPageNo() == null)
            resultBinder.rejectValue("mbHeader.toPageNo", "error.topageno.required");

        if (contractorBillRegister.getMbHeader().getFromPageNo() == 0
                || contractorBillRegister.getMbHeader().getToPageNo() == 0)
            resultBinder.reject("error.validate.mb.pagenumbers.zero", "error.validate.mb.pagenumbers.zero");

        if (contractorBillRegister.getMbHeader().getFromPageNo() != null
                && contractorBillRegister.getMbHeader().getToPageNo() != null && contractorBillRegister
                        .getMbHeader().getFromPageNo() > contractorBillRegister.getMbHeader().getToPageNo())
            resultBinder.reject("error.validate.mb.frompagenumber.greaterthan.topagenumber",
                    "error.validate.mb.frompagenumber.greaterthan.topagenumber");

        if (contractorBillRegister.getMbHeader().getMbDate() != null && contractorBillRegister.getMbHeader()
                .getMbDate().before(contractorBillRegister.getWorkOrder().getWorkOrderDate()))
            resultBinder.rejectValue("mbHeader.mbDate", "error.validate.mbdate.lessthan.loadate");
    }

    if (org.apache.commons.lang.StringUtils.isBlank(request.getParameter("netPayableAccountCode")))
        resultBinder.reject("error.netpayable.accountcode.required", "error.netpayable.accountcode.required");
    if (org.apache.commons.lang.StringUtils.isBlank(request.getParameter("netPayableAmount"))
            || Double.valueOf(request.getParameter("netPayableAmount").toString()) <= 0)
        resultBinder.reject("error.netpayable.amount.required", "error.netpayable.amount.required");

    // TODO: from this line code should be removed after user data entry is
    // finished.
    if (contractorBillRegister.getEgBillregistermis() != null
            && contractorBillRegister.getEgBillregistermis().getPartyBillDate() != null
            && contractorBillRegister.getEgBillregistermis().getPartyBillDate()
                    .after(contractorBillRegister.getBilldate()))
        resultBinder.rejectValue("egBillregistermis.partyBillDate", "error.partybilldate.billdate");
    final Date workCompletionDate = contractorBillRegister.getWorkOrderEstimate().getWorkCompletionDate();
    if (contractorBillRegister.getBilltype().equals(BillTypes.Final_Bill.toString())
            && workCompletionDate == null)
        resultBinder.rejectValue("workOrderEstimate.workCompletionDate", "error.workcompletiondate.required");

    final Date currentDate = new Date();
    if (workCompletionDate != null) {
        if (workCompletionDate.after(currentDate))
            resultBinder.rejectValue("workOrderEstimate.workCompletionDate",
                    "error.workcompletiondate.futuredate");
        if (workCompletionDate
                .before(contractorBillRegister.getWorkOrderEstimate().getWorkOrder().getWorkOrderDate()))
            resultBinder.rejectValue("workOrderEstimate.workCompletionDate",
                    "error.workcompletiondate.workorderdate");
        if (workCompletionDate.after(contractorBillRegister.getBilldate()))
            resultBinder.rejectValue("workOrderEstimate.workCompletionDate",
                    "error.workcompletiondate.billdate");
    }

    if (lineEstimateDetails.getLineEstimate().isSpillOverFlag()) {
        final String cutoffDateString = worksApplicationProperties.getContractorBillCutOffDate();
        final DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
        try {
            if (StringUtils.isNotBlank(cutoffDateString)) {
                final Date cutOffdate = df.parse(cutoffDateString);
                if (contractorBillRegister.getBilldate().before(cutOffdate))
                    resultBinder.rejectValue(BILLDATE, "error.billdate.cutoff");
            } else {
                final Date currentFinYear = lineEstimateService.getCurrentFinancialYear(currentDate)
                        .getStartingDate();
                if (contractorBillRegister.getBilldate().before(currentFinYear))
                    resultBinder.rejectValue(BILLDATE, "error.billdate.finyear");
            }
            if (contractorBillRegister.getBilldate().after(currentDate))
                resultBinder.rejectValue(BILLDATE, "error.billdate.futuredate");
            if (contractorBillRegister.getBilldate()
                    .before(contractorBillRegister.getWorkOrder().getWorkOrderDate()))
                resultBinder.rejectValue(BILLDATE, "error.billdate.workorderdate");

        } catch (final ParseException e) {
            e.printStackTrace();
        }

    }

}

From source file:org.egov.works.web.controller.contractorbill.UpdateContractorBillController.java

private void validateInput(final ContractorBillRegister contractorBillRegister,
        final LineEstimateDetails lineEstimateDetails, final BindingResult resultBinder,
        final HttpServletRequest request) {

    BigDecimal totalBillAmountIncludingCurrentBill = contractorBillRegister.getBillamount();
    final BigDecimal totalBillAmount = contractorBillRegisterService
            .getTotalBillAmountByWorkOrderAndNotContractorBillRegister(contractorBillRegister.getWorkOrder(),
                    contractorBillRegister.getId());
    if (totalBillAmount != null)
        totalBillAmountIncludingCurrentBill = totalBillAmountIncludingCurrentBill.add(totalBillAmount);
    if (lineEstimateDetails.getLineEstimate().isBillsCreated()
            && lineEstimateDetails.getGrossAmountBilled() != null)
        totalBillAmountIncludingCurrentBill = totalBillAmountIncludingCurrentBill
                .add(lineEstimateDetails.getGrossAmountBilled());
    if (totalBillAmountIncludingCurrentBill.doubleValue() > contractorBillRegister.getWorkOrder()
            .getWorkOrderAmount())/*  w  ww.j  ava 2 s  .  c  o  m*/
        resultBinder
                .reject("error.contractorbill.totalbillamount.exceeds.workorderamount",
                        new String[] { String.valueOf(totalBillAmountIncludingCurrentBill),
                                String.valueOf(contractorBillRegister.getWorkOrder().getWorkOrderAmount()) },
                        null);

    if (StringUtils.isBlank(contractorBillRegister.getBilltype()))
        resultBinder.rejectValue("billtype", "error.billtype.required");
    if (contractorBillRegister.getEgBillregistermis() != null
            && contractorBillRegister.getEgBillregistermis().getPartyBillDate() != null
            && contractorBillRegister.getEgBillregistermis().getPartyBillDate()
                    .before(contractorBillRegister.getWorkOrder().getWorkOrderDate()))
        resultBinder.rejectValue("egBillregistermis.partyBillDate",
                "error.validate.partybilldate.lessthan.loadate");

    if (contractorBillRegister.getMbHeader() != null) {
        if (StringUtils.isBlank(contractorBillRegister.getMbHeader().getMbRefNo()))
            resultBinder.rejectValue("mbHeader.mbRefNo", "error.mbrefno.required");

        if (contractorBillRegister.getMbHeader().getMbDate() == null)
            resultBinder.rejectValue("mbHeader.mbDate", "error.mbdate.required");

        if (contractorBillRegister.getMbHeader().getFromPageNo() == null)
            resultBinder.rejectValue("mbHeader.fromPageNo", "error.frompageno.required");

        if (contractorBillRegister.getMbHeader().getToPageNo() == null)
            resultBinder.rejectValue("mbHeader.toPageNo", "error.topageno.required");

        if (contractorBillRegister.getMbHeader().getFromPageNo() == 0
                || contractorBillRegister.getMbHeader().getToPageNo() == 0)
            resultBinder.reject("error.validate.mb.pagenumbers.zero", "error.validate.mb.pagenumbers.zero");

        if (contractorBillRegister.getMbHeader().getFromPageNo() != null
                && contractorBillRegister.getMbHeader().getToPageNo() != null && contractorBillRegister
                        .getMbHeader().getFromPageNo() > contractorBillRegister.getMbHeader().getToPageNo())
            resultBinder.reject("error.validate.mb.frompagenumber.greaterthan.topagenumber",
                    "error.validate.mb.frompagenumber.greaterthan.topagenumber");

        if (contractorBillRegister.getMbHeader().getMbDate() != null && contractorBillRegister.getMbHeader()
                .getMbDate().before(contractorBillRegister.getWorkOrder().getWorkOrderDate()))
            resultBinder.rejectValue("mbHeader.mbDate", "error.validate.mbdate.lessthan.loadate");
    }

    if (StringUtils.isBlank(request.getParameter("netPayableAccountCode")))
        resultBinder.reject("error.netpayable.accountcode.required", "error.netpayable.accountcode.required");
    if (StringUtils.isBlank(request.getParameter("netPayableAmount"))
            || Double.valueOf(request.getParameter("netPayableAmount").toString()) <= 0)
        resultBinder.reject("error.netpayable.amount.required", "error.netpayable.amount.required");

    if (contractorBillRegister.getBilltype().equals(BillTypes.Final_Bill.toString())
            && contractorBillRegister.getWorkOrderEstimate().getWorkCompletionDate() == null)
        resultBinder.rejectValue("workOrderEstimate.workCompletionDate", "error.workcompletiondate.required");

    final Date currentDate = new Date();
    final Date workCompletionDate = contractorBillRegister.getWorkOrderEstimate().getWorkCompletionDate();
    if (workCompletionDate != null) {
        if (workCompletionDate.after(currentDate))
            resultBinder.rejectValue("workOrderEstimate.workCompletionDate",
                    "error.workcompletiondate.futuredate");
        if (workCompletionDate
                .before(contractorBillRegister.getWorkOrderEstimate().getWorkOrder().getWorkOrderDate()))
            resultBinder.rejectValue("workOrderEstimate.workCompletionDate",
                    "error.workcompletiondate.workorderdate");
        if (workCompletionDate.after(contractorBillRegister.getBilldate()))
            resultBinder.rejectValue("workOrderEstimate.workCompletionDate",
                    "error.workcompletiondate.billdate");
    }
}

From source file:org.egov.works.web.controller.lineestimate.CreateSpillOverLineEstimateController.java

private void validateBudgetAmount(final LineEstimate lineEstimate, final BindingResult errors) {
    final List<Long> budgetheadid = new ArrayList<Long>();
    budgetheadid.add(lineEstimate.getBudgetHead().getId());

    try {//from ww  w.j a v a 2  s. c o m
        final BigDecimal budgetAvailable = budgetDetailsDAO.getPlanningBudgetAvailable(
                lineEstimateService.getCurrentFinancialYear(new Date()).getId(),
                Integer.parseInt(lineEstimate.getExecutingDepartment().getId().toString()),
                lineEstimate.getFunction().getId(), null,
                lineEstimate.getScheme() == null ? null
                        : Integer.parseInt(lineEstimate.getScheme().getId().toString()),
                lineEstimate.getSubScheme() == null ? null
                        : Integer.parseInt(lineEstimate.getSubScheme().getId().toString()),
                null, budgetheadid, Integer.parseInt(lineEstimate.getFund().getId().toString()));

        BigDecimal totalAppropriationAmount = BigDecimal.ZERO;

        for (final LineEstimateDetails led : lineEstimate.getLineEstimateDetails())
            if (lineEstimate.isBillsCreated() && led.getGrossAmountBilled() != null)
                totalAppropriationAmount = totalAppropriationAmount
                        .add(led.getEstimateAmount().subtract(led.getGrossAmountBilled()));
            else
                totalAppropriationAmount = totalAppropriationAmount.add(led.getEstimateAmount());
        if (BudgetControlType.BudgetCheckOption.MANDATORY.toString()
                .equalsIgnoreCase(budgetControlTypeService.getConfigValue())
                && budgetAvailable.compareTo(totalAppropriationAmount) == -1)
            errors.reject("error.budgetappropriation.amount",
                    new String[] { budgetAvailable.toString(), totalAppropriationAmount.toString() }, null);
    } catch (final ValidationException e) {
        // TODO: Used ApplicationRuntimeException for time being since there is issue in session after
        // budgetDetailsDAO.getPlanningBudgetAvailable API call
        // TODO: needs to replace with errors.reject
        for (final ValidationError error : e.getErrors())
            throw new ApplicationRuntimeException(error.getKey());
        /*
         * for (final ValidationError error : e.getErrors()) errors.reject(error.getMessage());
         */
    }
}

From source file:org.egov.works.web.controller.lineestimate.UpdateLineEstimateController.java

private void validateBudgetAmount(final LineEstimate lineEstimate, final BindingResult errors) {

    final List<Long> budgetheadid = new ArrayList<Long>();
    budgetheadid.add(lineEstimate.getBudgetHead().getId());

    try {//from   w ww . j  av  a 2  s. c o  m
        final BigDecimal budgetAvailable = budgetDetailsDAO.getPlanningBudgetAvailable(
                lineEstimateService.getCurrentFinancialYear(new Date()).getId(),
                Integer.parseInt(lineEstimate.getExecutingDepartment().getId().toString()),
                lineEstimate.getFunction().getId(), null,
                lineEstimate.getScheme() == null ? null
                        : Integer.parseInt(lineEstimate.getScheme().getId().toString()),
                lineEstimate.getSubScheme() == null ? null
                        : Integer.parseInt(lineEstimate.getSubScheme().getId().toString()),
                null, budgetheadid, Integer.parseInt(lineEstimate.getFund().getId().toString()));

        BigDecimal totalEstimateAmount = BigDecimal.ZERO;

        for (final LineEstimateDetails led : lineEstimate.getLineEstimateDetails())
            totalEstimateAmount = led.getEstimateAmount().add(totalEstimateAmount);

        if (BudgetControlType.BudgetCheckOption.MANDATORY.toString()
                .equalsIgnoreCase(budgetControlTypeService.getConfigValue())
                && budgetAvailable.compareTo(totalEstimateAmount) == -1)

            errors.reject("error.budgetappropriation.amount",
                    new String[] { budgetAvailable.toString(), totalEstimateAmount.toString() }, null);
    } catch (final ValidationException e) {
        // TODO: Used ApplicationRuntimeException for time being since there
        // is issue in session after
        // budgetDetailsDAO.getPlanningBudgetAvailable API call
        // TODO: needs to replace with errors.reject
        for (final ValidationError error : e.getErrors())
            throw new ApplicationRuntimeException(error.getKey());
        /*
         * for (final ValidationError error : e.getErrors())
         * errors.reject(error.getMessage());
         */
    }
}

From source file:org.egov.wtms.web.controller.application.MeterReadingController.java

@RequestMapping(value = "/meterentry/{consumerCode}", method = RequestMethod.POST)
public String updateMeterEntry(@ModelAttribute final WaterConnectionDetails waterConnectionDetails,
        final BindingResult errors, final RedirectAttributes redirectAttrs, final Model model,
        final HttpServletRequest request) {
    Date givenDate = null;/*ww w .j a v a  2  s  . c om*/
    if (request.getParameter(METER_CURRENT_READING_DATE) != null)
        givenDate = toDateUsingDefaultPattern(request.getParameter(METER_CURRENT_READING_DATE));
    if (connectionDemandService.meterEntryAllReadyExistForCurrentMonth(waterConnectionDetails, givenDate))
        return REDIRECT_TO_METERDEMANDNOTICE + waterConnectionDetails.getConnection().getConsumerCode();
    final MeterReadingConnectionDetails meterReadingConnectionDetailObj = new MeterReadingConnectionDetails();
    Long previousReading = 0l;
    Long currentReadingValue = null;
    Boolean meterDamaged;
    Boolean currentMonthIncluded = false;
    if ("true".equals(request.getParameter("waterConnectionDetails.meterConnection.isMeterDamaged"))) {
        meterDamaged = true;
        meterReadingConnectionDetailObj.setMeterDamaged(meterDamaged);
    }
    Date currentDate = null;
    Date previousDate = null;
    currentDate = toDateUsingDefaultPattern(request.getParameter(METER_CURRENT_READING_DATE));
    if (request.getParameter("previousreadingDate") != null)
        previousDate = toDateUsingDefaultPattern(request.getParameter("previousreadingDate"));
    if (currentDate != null) {
        final DateTime currentDateTime = new DateTime(currentDate);
        final int midday = currentDateTime.dayOfMonth().getMaximumValue() / 2;
        final DateTime midDate = new DateTime(currentDate).withDayOfMonth(midday);
        final DateTime previousMonthStartDate = new DateTime(currentDate).minusMonths(1).withDayOfMonth(1);

        if (currentDate.before(midDate.toDate())
                && isPreviousMonthDemandExist(previousMonthStartDate, waterConnectionDetails))
            errors.reject("err.invalid.meter.reading.date",
                    new String[] { getFormattedDate(previousMonthStartDate.toDate(), "MMMM YYYY"),
                            getFormattedDate(midDate.toDate(), "dd MMMM YYYY") },
                    "err.invalid.meter.reading.date");
        else if (!currentDate.before(midDate.toDate()))
            currentMonthIncluded = true;
    }

    if (errors.hasErrors()) {
        loadViewData(model, waterConnectionDetails);
        return NEWCONNECTIONMETERENTRY;
    }

    if (isNotBlank(request.getParameter(PREVIOUSREADING)))
        previousReading = Long.valueOf(request.getParameter(PREVIOUSREADING));

    if (isNotBlank(request.getParameter(METERCURRENTREADING)))
        currentReadingValue = Long.valueOf(request.getParameter(METERCURRENTREADING));

    if (currentReadingValue != null && currentReadingValue < previousReading)
        throw new ValidationException("err.invalid.meter.reading");
    final WaterConnectionDetails waterconnectionDetails = billCalculationAndDemandUpdate(waterConnectionDetails,
            request, meterReadingConnectionDetailObj, previousReading, currentDate, previousDate,
            currentMonthIncluded);
    final WaterConnectionDetails savedWaterConnectionDetails = waterConnectionDetailsRepository
            .save(waterconnectionDetails);
    waterConnectionDetailsService.updateIndexes(savedWaterConnectionDetails);
    return REDIRECT_TO_METERDEMANDNOTICE + savedWaterConnectionDetails.getConnection().getConsumerCode();
}