Example usage for org.springframework.validation BindingResult rejectValue

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

Introduction

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

Prototype

void rejectValue(@Nullable String field, String errorCode);

Source Link

Document

Register a field error for the specified field of the current object (respecting the current nested path, if any), using the given error description.

Usage

From source file:org.egov.stms.transactions.service.SewerageConnectionService.java

@SuppressWarnings("null")
public void validateDocuments(final List<SewerageApplicationDetailsDocument> applicationDocs,
        final SewerageApplicationDetailsDocument applicationDocument, final int i,
        final BindingResult resultBinder) {

    if (applicationDocument != null && applicationDocument.getDocumentTypeMaster().isMandatory()) {

        if (applicationDocument.getDocumentNumber() == null) {
            final String fieldError = "appDetailsDocument[" + i + "].documentNumber";
            resultBinder.rejectValue(fieldError, "documentNumber.required");
        }/*  ww w.  ja  va 2 s  .c  o  m*/
        if (applicationDocument.getDocumentDate() == null) {
            final String fieldError = "appDetailsDocument[" + i + "].documentDate";
            resultBinder.rejectValue(fieldError, "documentDate.required");
        }

        Iterator<MultipartFile> stream = null;
        if (ArrayUtils.isNotEmpty(applicationDocument.getFiles()))
            stream = Arrays.asList(applicationDocument.getFiles()).stream().filter(file -> !file.isEmpty())
                    .iterator();
        if (ArrayUtils.isEmpty(applicationDocument.getFiles()) || stream == null
                || stream != null && !stream.hasNext()) {
            final String fieldError = "appDetailsDocument[" + i + "].files";
            resultBinder.rejectValue(fieldError, "files.required");
        } else if (validApplicationDocument(applicationDocument))
            applicationDocs.add(applicationDocument);
    } else {
        if (applicationDocument.getDocumentNumber() == null && applicationDocument.getDocumentDate() != null) {
            final String fieldError = "appDetailsDocument[" + i + "].documentNumber";
            resultBinder.rejectValue(fieldError, "documentNumber.required");
        }
        if (applicationDocument.getDocumentNumber() != null && applicationDocument.getDocumentDate() == null) {
            final String fieldError = "appDetailsDocument[" + i + "].documentDate";
            resultBinder.rejectValue(fieldError, "documentDate.required");
        }
        if (applicationDocument.getDocumentNumber() != null && applicationDocument.getDocumentDate() != null) {
            Iterator<MultipartFile> stream = null;
            if (ArrayUtils.isNotEmpty(applicationDocument.getFiles()))
                stream = Arrays.asList(applicationDocument.getFiles()).stream().filter(file -> !file.isEmpty())
                        .iterator();
            if (ArrayUtils.isEmpty(applicationDocument.getFiles()) || stream == null
                    || stream != null && !stream.hasNext()) {
                final String fieldError = "appDetailsDocument[" + i + "].files";
                resultBinder.rejectValue(fieldError, "files.required");
            }
        }
        if (validApplicationDocument(applicationDocument))
            applicationDocs.add(applicationDocument);
    }
}

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);/*ww w  .  j ava 2 s .  co 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);
                }// www .  j a va 2  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())//  ww  w . java  2s  . com
        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 w  w .j  av a  2 s .co 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.letterofacceptance.UpdateLetterOfAcceptanceController.java

@RequestMapping(value = "/modify/{id}", method = RequestMethod.POST)
public String modify(@ModelAttribute("workOrder") final WorkOrder workOrder, final Model model,
        final BindingResult resultBinder, final HttpServletRequest request) throws ApplicationException {
    final List<String> workOrderNumbers = letterOfAcceptanceService
            .getApprovedWorkOrdersForCreateContractorBill(workOrder.getWorkOrderNumber());
    if (workOrderNumbers.isEmpty()) {
        resultBinder.rejectValue("", "error.modify.loa.finalbill.exists");
    }//from   w w w  .  ja  v  a 2 s  . c  om

    final LineEstimateDetails lineEstimateDetails = lineEstimateService
            .findByEstimateNumber(workOrder.getEstimateNumber());

    final Double revisedWorkOrderAmount = Double.valueOf(request.getParameter("revisedWorkOrderAmount"));
    final Double revisedValue = Double.valueOf(request.getParameter("revisedValue"));
    Double balanceAmount = 0.0;
    Double grossBillAmount = 0.0;
    final DecimalFormat df = new DecimalFormat("0.00");
    grossBillAmount = letterOfAcceptanceService.getGrossBillAmountOfBillsCreated(workOrder.getWorkOrderNumber(),
            WorksConstants.APPROVED, ContractorBillRegister.BillStatus.CANCELLED.toString());
    if (grossBillAmount == null)
        grossBillAmount = 0.0;
    final BigDecimal ledGrossBillAmount = lineEstimateDetails.getGrossAmountBilled();
    if (revisedWorkOrderAmount >= 0 && "-".equals(workOrder.getPercentageSign())) {
        if (lineEstimateDetails.getLineEstimate().isSpillOverFlag())
            balanceAmount = ledGrossBillAmount != null
                    ? workOrder.getWorkOrderAmount() - grossBillAmount - revisedValue
                            - ledGrossBillAmount.doubleValue()
                    : workOrder.getWorkOrderAmount() - grossBillAmount - revisedValue;

        else
            balanceAmount = workOrder.getWorkOrderAmount() - grossBillAmount - revisedValue;
        if (balanceAmount < 0) {
            if (lineEstimateDetails.getLineEstimate().isSpillOverFlag())
                grossBillAmount += lineEstimateDetails.getGrossAmountBilled().doubleValue();

            resultBinder.rejectValue("", "error.modify.loa.appropriation.amount",
                    new String[] { df.format(grossBillAmount), df.format(revisedWorkOrderAmount) }, null);
        }
    } else if (revisedWorkOrderAmount >= 0 && "+".equals(workOrder.getPercentageSign()))
        balanceAmount = revisedWorkOrderAmount - workOrder.getWorkOrderAmount();

    if (revisedWorkOrderAmount == 0)
        resultBinder.rejectValue(StringUtils.EMPTY, "error.modify.loa.agreement.amount");

    if (resultBinder.hasErrors()) {
        model.addAttribute("lineEstimateDetails", lineEstimateDetails);
        model.addAttribute("mode", "modify");
        model.addAttribute("lineEstimateDetails", lineEstimateDetails);
        model.addAttribute("revisedValue", request.getParameter("revisedValue"));
        return "letterOfAcceptance-modify";
    } else {
        WorkOrder savedWorkOrder = null;
        try {
            savedWorkOrder = letterOfAcceptanceService.update(workOrder, lineEstimateDetails, revisedValue,
                    revisedWorkOrderAmount);
        } catch (final ValidationException e) {
            final List<Long> budgetheadid = new ArrayList<>();
            budgetheadid.add(lineEstimateDetails.getLineEstimate().getBudgetHead().getId());

            try {
                final BigDecimal budgetAvailable = budgetDetailsDAO.getPlanningBudgetAvailable(
                        lineEstimateService.getCurrentFinancialYear(new Date()).getId(),
                        Integer.parseInt(lineEstimateDetails
                                .getLineEstimate().getExecutingDepartment().getId().toString()),
                        lineEstimateDetails.getLineEstimate().getFunction().getId(), null,
                        lineEstimateDetails.getLineEstimate().getScheme() == null ? null
                                : Integer.parseInt(
                                        lineEstimateDetails.getLineEstimate().getScheme().getId().toString()),
                        lineEstimateDetails.getLineEstimate().getSubScheme() == null ? null
                                : Integer.parseInt(lineEstimateDetails.getLineEstimate().getSubScheme().getId()
                                        .toString()),
                        null, budgetheadid,
                        Integer.parseInt(lineEstimateDetails.getLineEstimate().getFund().getId().toString()));
                final String errorMessage = messageSource.getMessage("error.budgetappropriation.amount",
                        new String[] { budgetAvailable.toString(), df.format(balanceAmount) }, null);
                model.addAttribute("message", errorMessage);
            } catch (final ValidationException v) {
                model.addAttribute("errorMessage", v.getErrors().get(0).getMessage());
            }

            return "lineestimate-success";
        }
        return "redirect:/letterofacceptance/loa-success?loaNumber=" + savedWorkOrder.getWorkOrderNumber()
                + "&isModify=true";
    }
}

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

private void validateLineEstimateDetails(final LineEstimate lineEstimate, final BindingResult errors) {
    Integer index = 0;//from   ww  w  .  j ava 2  s .  c o  m
    for (final LineEstimateDetails led : lineEstimate.getLineEstimateDetails()) {

        final LineEstimateDetails estimateNumber = lineEstimateDetailService
                .getLineEstimateDetailsByEstimateNumber(led.getEstimateNumber());
        if (lineEstimate.getCouncilResolutionNumber() != null) {
            final LineEstimate councilResolutionNumber = lineEstimateService
                    .getLineEstimateByCouncilResolutionNumber(lineEstimate.getCouncilResolutionNumber());
            if (councilResolutionNumber != null)
                errors.rejectValue("lineEstimateDetails[" + index + "].lineEstimate.councilResolutionNumber",
                        "error.councilresolutionnumber.unique");
        }
        final LineEstimateDetails workIdentificationNumber = lineEstimateDetailService
                .getLineEstimateDetailsByProjectCode(led.getProjectCode().getCode());
        if (estimateNumber != null)
            errors.rejectValue("lineEstimateDetails[" + index + "].estimateNumber",
                    "error.estimatenumber.unique");
        if (workIdentificationNumber != null)
            errors.rejectValue("lineEstimateDetails[" + index + "].projectCode.code", "error.win.unique");
        if (led.getActualEstimateAmount() != null && !(led.getActualEstimateAmount().signum() == 1))
            errors.rejectValue("lineEstimateDetails[" + index + "].actualEstimateAmount",
                    "error.actualestimateamount.required");
        if (led.getEstimateAmount().compareTo(led.getActualEstimateAmount()) == -1)
            errors.rejectValue("lineEstimateDetails[" + index + "].actualEstimateAmount", "error.actualamount");
        index++;
    }
}

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

private void validateTechSanctionDetails(final LineEstimate lineEstimate, final BindingResult errors) {
    if (lineEstimate.getTechnicalSanctionDate() == null)
        errors.rejectValue("technicalSanctionDate", "error.techdate.notnull");
    if (lineEstimate.getTechnicalSanctionDate() != null
            && lineEstimate.getTechnicalSanctionDate().before(lineEstimate.getAdminSanctionDate()))
        errors.rejectValue("technicalSanctionDate", "error.technicalsanctiondate");
    if (lineEstimate.getTechnicalSanctionNumber() == null)
        errors.rejectValue("technicalSanctionNumber", "error.technumber.notnull");
    if (lineEstimate.getTechnicalSanctionNumber() != null) {
        final LineEstimate existingLineEstimate = lineEstimateService
                .getLineEstimateByTechnicalSanctionNumber(lineEstimate.getTechnicalSanctionNumber());
        if (existingLineEstimate != null)
            errors.rejectValue("technicalSanctionNumber", "error.technumber.unique");
    }//  w w  w.j a v  a  2 s . c o m
}

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

private void validateAdminSanctionDetail(final LineEstimate lineEstimate, final BindingResult errors) {
    if (lineEstimate.getAdminSanctionDate() != null
            && lineEstimate.getAdminSanctionDate().before(lineEstimate.getLineEstimateDate()))
        errors.rejectValue("adminSanctionDate", "error.adminsanctiondate");
    if (lineEstimate.getCouncilResolutionDate() != null
            && lineEstimate.getCouncilResolutionDate().before(lineEstimate.getLineEstimateDate()))
        errors.rejectValue("councilResolutionDate", "error.councilresolutiondate");
    if (StringUtils.isBlank(lineEstimate.getAdminSanctionNumber()))
        errors.rejectValue("adminSanctionNumber", "error.adminsanctionnumber.notnull");
    if (StringUtils.isBlank(lineEstimate.getAdminSanctionBy()))
        errors.rejectValue("adminSanctionBy", "error.adminsanctionby.notnull");
    if (lineEstimate.getAdminSanctionNumber() != null) {
        final LineEstimate checkLineEstimate = lineEstimateService
                .getLineEstimateByAdminSanctionNumber(lineEstimate.getAdminSanctionNumber());

        if (checkLineEstimate != null)
            errors.rejectValue("adminSanctionNumber", "error.adminsanctionnumber.unique");
    }//from  w w  w  .  jav  a  2 s . co  m
}

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

private void validateAdminSanctionDetail(final LineEstimate lineEstimate, final BindingResult errors) {
    if (lineEstimate.getCouncilResolutionDate() != null
            && lineEstimate.getCouncilResolutionDate().before(lineEstimate.getLineEstimateDate()))
        errors.rejectValue("councilResolutionDate", "error.councilresolutiondate");
    if (StringUtils.isBlank(lineEstimate.getAdminSanctionNumber()))
        errors.rejectValue("adminSanctionNumber", "error.adminsanctionnumber.notnull");
    if (lineEstimate.getAdminSanctionNumber() != null) {
        final LineEstimate checkLineEstimate = lineEstimateService
                .getLineEstimateByAdminSanctionNumber(lineEstimate.getAdminSanctionNumber());

        if (checkLineEstimate != null)
            errors.rejectValue("adminSanctionNumber", "error.adminsanctionnumber.unique");
    }//from   w  ww. j a v a 2  s.c  om
}