List of usage examples for org.springframework.validation BindingResult rejectValue
void rejectValue(@Nullable String field, String errorCode);
From source file:org.egov.wtms.application.service.NewConnectionService.java
public void validateDocumentsRequired(final ApplicationDocuments applicationDocument, final BindingResult resultBinder, final int i) { if (applicationDocument.getDocumentNumber() == null && applicationDocument.getDocumentDate() != null) { final String fieldError = "applicationDocs[" + i + "].documentNumber"; resultBinder.rejectValue(fieldError, "documentNumber.required"); }/* ww w. j a v a 2 s . com*/ if (applicationDocument.getDocumentNumber() != null && applicationDocument.getDocumentDate() == null) { final String fieldError = "applicationDocs[" + i + "].documentDate"; resultBinder.rejectValue(fieldError, "documentDate.required"); } if (applicationDocument.getDocumentNumber() != null && applicationDocument.getDocumentDate() != null) { Iterator<MultipartFile> stream = null; if (applicationDocument.getFiles()[0].getSize() > 0) stream = Arrays.asList(applicationDocument.getFiles()).stream().filter(file -> !file.isEmpty()) .iterator(); if (stream == null) { final String fieldError = "applicationDocs[" + i + "].files"; resultBinder.rejectValue(fieldError, "files.required"); } } }
From source file:org.egov.wtms.application.service.NewConnectionService.java
public void validateDocumentsForBPLCategory(final List<ApplicationDocuments> applicationDocs, final ApplicationDocuments applicationDocument, final BindingResult resultBinder, final int i) { if (applicationDocument.getDocumentNumber() == null) { final String fieldError = "applicationDocs[" + i + "].documentNumber"; resultBinder.rejectValue(fieldError, "documentNumber.required"); }//w w w .ja va2s.c o m if (applicationDocument.getDocumentDate() == null) { final String fieldError = "applicationDocs[" + i + "].documentDate"; resultBinder.rejectValue(fieldError, "documentDate.required"); } Iterator<MultipartFile> stream; if (applicationDocument.getFiles()[0].getSize() > 0) { stream = Arrays.asList(applicationDocument.getFiles()).stream().filter(file -> !file.isEmpty()) .iterator(); if (stream != null && connectionDetailService.validApplicationDocument(applicationDocument)) applicationDocs.add(applicationDocument); } else { final String fieldError = "applicationDocs[" + i + "].files"; resultBinder.rejectValue(fieldError, "files.required"); } }
From source file:org.egov.wtms.application.service.NewConnectionService.java
public void validateExisting(final WaterConnectionDetails waterConnectionDetails, final BindingResult errors) { if (waterConnectionDetails.getConnection() != null) { List<WaterConnection> waterConnectionList = new ArrayList<>(); if (waterConnectionDetails.getConnection().getOldConsumerNumber() != null) waterConnectionList = waterConnectionService .findByOldConsumerNumber(waterConnectionDetails.getConnection().getOldConsumerNumber()); if (!waterConnectionList.isEmpty()) errors.rejectValue("connection.oldConsumerNumber", "err.oldConsumerCode.already.exists"); }//from w w w .j a v a2 s. co m if (waterConnectionDetails.getConnectionType() != null && waterConnectionDetails.getConnectionType() == ConnectionType.METERED) validateMeterConnectionDetails(waterConnectionDetails, errors); }
From source file:org.egov.wtms.application.service.NewConnectionService.java
public void validateMeterConnectionDetails(final WaterConnectionDetails waterConnectionDetails, final BindingResult errors) { if (waterConnectionDetails.getExecutionDate() == null) errors.rejectValue("executionDate", ERROR_REQUIRED); if (waterConnectionDetails.getExistingConnection().getMeterNo() == null) errors.rejectValue("existingConnection.meterNo", ERROR_REQUIRED); if (waterConnectionDetails.getExistingConnection().getPreviousReading() == null) errors.rejectValue("existingConnection.previousReading", ERROR_REQUIRED); if (waterConnectionDetails.getExistingConnection().getReadingDate() == null) errors.rejectValue("existingConnection.readingDate", ERROR_REQUIRED); if (waterConnectionDetails.getExistingConnection().getCurrentReading() == null) errors.rejectValue("existingConnection.currentReading", ERROR_REQUIRED); }
From source file:org.egov.wtms.web.controller.application.AdditionalConnectionController.java
@RequestMapping(value = "/addconnection/addConnection-create", method = RequestMethod.POST) public String create(@Valid @ModelAttribute final WaterConnectionDetails addConnection, final BindingResult resultBinder, final RedirectAttributes redirectAttributes, final Model model, @RequestParam final String workFlowAction, final HttpServletRequest request, final BindingResult errors) { final Boolean isCSCOperator = waterTaxUtils.isCSCoperator(securityUtils.getCurrentUser()); final Boolean citizenPortalUser = waterTaxUtils.isCitizenPortalUser(securityUtils.getCurrentUser()); final Boolean loggedUserIsMeesevaUser = waterTaxUtils.isMeesevaUser(securityUtils.getCurrentUser()); final Boolean isAnonymousUser = waterTaxUtils.isAnonymousUser(securityUtils.getCurrentUser()); model.addAttribute("isAnonymousUser", isAnonymousUser); if (loggedUserIsMeesevaUser && request.getParameter(MEESEVAAPPLICATIONNUMBER) != null) addConnection.setMeesevaApplicationNumber(request.getParameter(MEESEVAAPPLICATIONNUMBER)); model.addAttribute("citizenPortalUser", citizenPortalUser); if (!isCSCOperator && !citizenPortalUser && !loggedUserIsMeesevaUser && !isAnonymousUser) { final Boolean isJuniorAsstOrSeniorAsst = waterTaxUtils .isLoggedInUserJuniorOrSeniorAssistant(securityUtils.getCurrentUser().getId()); if (!isJuniorAsstOrSeniorAsst) throw new ValidationException("err.creator.application"); }//from w w w.j av a 2 s . c om final WaterConnectionDetails parent = waterConnectionDetailsService .getActiveConnectionDetailsByConnection(addConnection.getConnection().getParentConnection()); final String message = additionalConnectionService.validateAdditionalConnection(parent); if (!message.isEmpty() && !"".equals(message)) return "redirect:/application/addconnection/" + addConnection.getConnection().getParentConnection().getConsumerCode(); final List<ApplicationDocuments> applicationDocs = new ArrayList<>(); int i = 0; if (!addConnection.getApplicationDocs().isEmpty()) for (final ApplicationDocuments applicationDocument : addConnection.getApplicationDocs()) { if (applicationDocument.getDocumentNumber() == null && applicationDocument.getDocumentDate() != null) { final String fieldError = "applicationDocs[" + i + "].documentNumber"; resultBinder.rejectValue(fieldError, "documentNumber.required"); } if (applicationDocument.getDocumentNumber() != null && applicationDocument.getDocumentDate() == null) { final String fieldError = "applicationDocs[" + i + "].documentDate"; resultBinder.rejectValue(fieldError, "documentDate.required"); } else if (connectionDetailService.validApplicationDocument(applicationDocument)) applicationDocs.add(applicationDocument); i++; } if (ConnectionType.NON_METERED.equals(addConnection.getConnectionType())) waterConnectionDetailsService.validateWaterRateAndDonationHeader(addConnection); if (addConnection.getState() == null) addConnection.setStatus(waterTaxUtils.getStatusByCodeAndModuleType( WaterTaxConstants.APPLICATION_STATUS_CREATED, WaterTaxConstants.MODULETYPE)); if (resultBinder.hasErrors()) { final WaterConnectionDetails parentConnectionDetails = waterConnectionDetailsService .getActiveConnectionDetailsByConnection(addConnection.getConnection()); loadBasicDetails(addConnection, model, parentConnectionDetails, addConnection.getMeesevaApplicationNumber()); final WorkflowContainer workflowContainer = new WorkflowContainer(); workflowContainer.setAdditionalRule(addConnection.getApplicationType().getCode()); prepareWorkflow(model, addConnection, workflowContainer); model.addAttribute("approvalPosOnValidate", request.getParameter(APPROVALPOSITION)); model.addAttribute(ADDITIONALTULE, addConnection.getApplicationType().getCode()); model.addAttribute(STATETYPE, addConnection.getClass().getSimpleName()); model.addAttribute(CURRENTUSER, waterTaxUtils.getCurrentUserRole(securityUtils.getCurrentUser())); return ADDCONNECTION_FORM; } addConnection.setApplicationDate(new Date()); addConnection.getApplicationDocs().clear(); addConnection.setApplicationDocs(applicationDocs); processAndStoreApplicationDocuments(addConnection); Long approvalPosition = 0l; String approvalComment = ""; String workFlowActionValue = ""; if (request.getParameter("approvalComent") != null) approvalComment = request.getParameter("approvalComent"); if (request.getParameter("workFlowAction") != null) workFlowActionValue = request.getParameter("workFlowAction"); if (request.getParameter(APPROVALPOSITION) != null && !request.getParameter(APPROVALPOSITION).isEmpty()) approvalPosition = Long.valueOf(request.getParameter(APPROVALPOSITION)); final Boolean applicationByOthers = waterTaxUtils.getCurrentUserRole(securityUtils.getCurrentUser()); if (applicationByOthers != null && applicationByOthers.equals(true) || citizenPortalUser || isAnonymousUser) { final Position userPosition = waterTaxUtils .getZonalLevelClerkForLoggedInUser(addConnection.getConnection().getPropertyIdentifier()); if (userPosition != null) approvalPosition = userPosition.getId(); else { final WaterConnectionDetails parentConnectionDetails = waterConnectionDetailsService .getActiveConnectionDetailsByConnection(addConnection.getConnection()); loadBasicDetails(addConnection, model, parentConnectionDetails, null); final WorkflowContainer workflowContainer = new WorkflowContainer(); workflowContainer.setAdditionalRule(addConnection.getApplicationType().getCode()); prepareWorkflow(model, addConnection, workflowContainer); model.addAttribute(ADDITIONALTULE, addConnection.getApplicationType().getCode()); model.addAttribute(STATETYPE, addConnection.getClass().getSimpleName()); model.addAttribute(CURRENTUSER, waterTaxUtils.getCurrentUserRole(securityUtils.getCurrentUser())); errors.rejectValue("connection.propertyIdentifier", "err.validate.connection.user.mapping", "err.validate.connection.user.mapping"); model.addAttribute("noJAORSAMessage", "No JA/SA exists to forward the application."); return ADDCONNECTION_FORM; } } if (isAnonymousUser) addConnection.setSource(ONLINE); else if (isCSCOperator) addConnection.setSource(CSC); else if (citizenPortalUser && (addConnection.getSource() == null || StringUtils.isBlank(addConnection.getSource().toString()))) addConnection.setSource(waterTaxUtils.setSourceOfConnection(securityUtils.getCurrentUser())); else if (loggedUserIsMeesevaUser) { addConnection.setSource(MEESEVA); if (addConnection.getMeesevaApplicationNumber() != null) addConnection.setApplicationNumber(addConnection.getMeesevaApplicationNumber()); } else addConnection.setSource(Source.SYSTEM); waterConnectionDetailsService.createNewWaterConnection(addConnection, approvalPosition, approvalComment, addConnection.getApplicationType().getCode(), workFlowActionValue); if (loggedUserIsMeesevaUser) return "redirect:/application/generate-meesevareceipt?transactionServiceNumber=" + addConnection.getApplicationNumber(); else return "redirect:/application/citizeenAcknowledgement?pathVars=" + addConnection.getApplicationNumber(); }
From source file:org.egov.wtms.web.controller.application.ChangeOfUseController.java
@RequestMapping(value = "/changeOfUse/changeOfUse-create", method = RequestMethod.POST) public String create(@Valid @ModelAttribute final WaterConnectionDetails changeOfUse, final BindingResult resultBinder, final RedirectAttributes redirectAttributes, final HttpServletRequest request, final Model model, @RequestParam final String workFlowAction, final BindingResult errors) { final Boolean isCSCOperator = waterTaxUtils.isCSCoperator(securityUtils.getCurrentUser()); final Boolean citizenPortalUser = waterTaxUtils.isCitizenPortalUser(securityUtils.getCurrentUser()); final Boolean loggedInMeesevaUser = waterTaxUtils.isMeesevaUser(securityUtils.getCurrentUser()); final Boolean isAnonymousUser = waterTaxUtils.isAnonymousUser(securityUtils.getCurrentUser()); model.addAttribute("isAnonymousUser", isAnonymousUser); if (loggedInMeesevaUser && request.getParameter("meesevaApplicationNumber") != null) changeOfUse.setMeesevaApplicationNumber(request.getParameter("meesevaApplicationNumber")); model.addAttribute("citizenPortalUser", citizenPortalUser); if (!isCSCOperator && !citizenPortalUser && !loggedInMeesevaUser && !isAnonymousUser) { final Boolean isJuniorAsstOrSeniorAsst = waterTaxUtils .isLoggedInUserJuniorOrSeniorAssistant(securityUtils.getCurrentUser().getId()); if (!isJuniorAsstOrSeniorAsst) throw new ValidationException("err.creator.application"); }//from w w w.j av a2 s . co m final List<ApplicationDocuments> applicationDocs = new ArrayList<>(); final WaterConnectionDetails connectionUnderChange = waterConnectionDetailsService .findByConsumerCodeAndConnectionStatus(changeOfUse.getConnection().getConsumerCode(), ConnectionStatus.ACTIVE); final WaterConnectionDetails parent = waterConnectionDetailsService.getParentConnectionDetails( connectionUnderChange.getConnection().getPropertyIdentifier(), ConnectionStatus.ACTIVE); String message = ""; if (parent != null) message = changeOfUseService.validateChangeOfUseConnection(parent); String consumerCode = ""; if (!message.isEmpty() && !"".equals(message)) { if (changeOfUse.getConnection().getParentConnection() != null) consumerCode = changeOfUse.getConnection().getParentConnection().getConsumerCode(); else consumerCode = changeOfUse.getConnection().getConsumerCode(); return "redirect:/application/changeOfUse/" + consumerCode; } int i = 0; if (!changeOfUse.getApplicationDocs().isEmpty()) for (final ApplicationDocuments applicationDocument : changeOfUse.getApplicationDocs()) { if (applicationDocument.getDocumentNumber() == null && applicationDocument.getDocumentDate() != null) { final String fieldError = "applicationDocs[" + i + "].documentNumber"; resultBinder.rejectValue(fieldError, "documentNumber.required"); } if (applicationDocument.getDocumentNumber() != null && applicationDocument.getDocumentDate() == null) { final String fieldError = "applicationDocs[" + i + "].documentDate"; resultBinder.rejectValue(fieldError, "documentDate.required"); } else if (connectionDetailService.validApplicationDocument(applicationDocument)) applicationDocs.add(applicationDocument); i++; } if (ConnectionType.NON_METERED.equals(changeOfUse.getConnectionType())) waterConnectionDetailsService.validateWaterRateAndDonationHeader(changeOfUse); if (resultBinder.hasErrors()) { final WaterConnectionDetails parentConnectionDetails = waterConnectionDetailsService .getActiveConnectionDetailsByConnection(changeOfUse.getConnection()); loadBasicData(model, parentConnectionDetails, changeOfUse, changeOfUse, changeOfUse.getMeesevaApplicationNumber()); final WorkflowContainer workflowContainer = new WorkflowContainer(); workflowContainer.setAdditionalRule(changeOfUse.getApplicationType().getCode()); prepareWorkflow(model, changeOfUse, workflowContainer); model.addAttribute("approvalPosOnValidate", request.getParameter(APPROVAL_POSITION)); model.addAttribute("additionalRule", changeOfUse.getApplicationType().getCode()); model.addAttribute("validationmessage", resultBinder.getFieldErrors().get(0).getField() + " = " + resultBinder.getFieldErrors().get(0).getDefaultMessage()); model.addAttribute("stateType", changeOfUse.getClass().getSimpleName()); model.addAttribute("currentUser", waterTaxUtils.getCurrentUserRole(securityUtils.getCurrentUser())); return CHANGEOFUSE_FORM; } if (changeOfUse.getState() == null) changeOfUse.setStatus(waterTaxUtils.getStatusByCodeAndModuleType( WaterTaxConstants.APPLICATION_STATUS_CREATED, WaterTaxConstants.MODULETYPE)); changeOfUse.getApplicationDocs().clear(); changeOfUse.setApplicationDocs(applicationDocs); processAndStoreApplicationDocuments(changeOfUse); Long approvalPosition = 0l; String approvalComent = ""; if (request.getParameter("approvalComent") != null) approvalComent = request.getParameter("approvalComent"); if (request.getParameter(APPROVAL_POSITION) != null && !request.getParameter(APPROVAL_POSITION).isEmpty()) approvalPosition = Long.valueOf(request.getParameter(APPROVAL_POSITION)); final Boolean applicationByOthers = waterTaxUtils.getCurrentUserRole(securityUtils.getCurrentUser()); if (applicationByOthers != null && applicationByOthers.equals(true) || citizenPortalUser || isAnonymousUser) { final Position userPosition = waterTaxUtils .getZonalLevelClerkForLoggedInUser(changeOfUse.getConnection().getPropertyIdentifier()); if (userPosition != null) approvalPosition = userPosition.getId(); else { final WaterConnectionDetails parentConnectionDetails = waterConnectionDetailsService .getActiveConnectionDetailsByConnection(changeOfUse.getConnection()); loadBasicData(model, parentConnectionDetails, changeOfUse, changeOfUse, null); final WorkflowContainer workflowContainer = new WorkflowContainer(); workflowContainer.setAdditionalRule(changeOfUse.getApplicationType().getCode()); prepareWorkflow(model, changeOfUse, workflowContainer); model.addAttribute("additionalRule", changeOfUse.getApplicationType().getCode()); model.addAttribute("stateType", changeOfUse.getClass().getSimpleName()); model.addAttribute("currentUser", waterTaxUtils.getCurrentUserRole(securityUtils.getCurrentUser())); errors.rejectValue("connection.propertyIdentifier", "err.validate.connection.user.mapping", "err.validate.connection.user.mapping"); model.addAttribute("noJAORSAMessage", "No JA/SA exists to forward the application."); return CHANGEOFUSE_FORM; } } changeOfUse.setApplicationDate(new Date()); if (isAnonymousUser) changeOfUse.setSource(ONLINE); else if (isCSCOperator) changeOfUse.setSource(CSC); else if (citizenPortalUser && (changeOfUse.getSource() == null || StringUtils.isBlank(changeOfUse.getSource().toString()))) changeOfUse.setSource(waterTaxUtils.setSourceOfConnection(securityUtils.getCurrentUser())); else if (loggedInMeesevaUser) { changeOfUse.setSource(MEESEVA); if (changeOfUse.getMeesevaApplicationNumber() != null) changeOfUse.setApplicationNumber(changeOfUse.getMeesevaApplicationNumber()); } else changeOfUse.setSource(Source.SYSTEM); changeOfUseService.createChangeOfUseApplication(changeOfUse, approvalPosition, approvalComent, changeOfUse.getApplicationType().getCode(), workFlowAction); if (loggedInMeesevaUser) return "redirect:/application/generate-meesevareceipt?transactionServiceNumber=" + changeOfUse.getApplicationNumber(); else return "redirect:/application/citizeenAcknowledgement?pathVars=" + changeOfUse.getApplicationNumber(); }
From source file:org.egov.wtms.web.controller.application.UpdateConnectionController.java
private void validateSanctionDetails(final WaterConnectionDetails waterConnectionDetails, final BindingResult errors) { if (waterConnectionDetails.getApprovalNumber() == null) errors.rejectValue("approvalNumber", "approvalNumber.required"); if (waterConnectionDetails.getApprovalDate() == null) errors.rejectValue("approvalDate", "approvalDate.required"); }
From source file:org.egov.wtms.web.controller.search.CommonWaterTaxSearchController.java
@PostMapping(value = "commonSearch-form/") public String searchConnectionSubmit(@ModelAttribute ConnectionSearchRequest searchRequest, BindingResult resultBinder, Model model, HttpServletRequest request) { WaterConnectionDetails waterConnectionDetails = null; String applicationType = request.getParameter(APPLICATIONTYPE); if (searchRequest.getMeesevaApplicationNumber() != null) model.addAttribute(MEESEVA_APPLICATION_NUMBER, searchRequest.getMeesevaApplicationNumber()); if (isNotBlank(applicationType) && applicationType.equals(RECONNECTION)) waterConnectionDetails = waterConnectionDetailsService.findByConsumerCodeAndConnectionStatus( searchRequest.getConsumerCode(), ConnectionStatus.CLOSED); else// w w w . j a v a2s .c o m waterConnectionDetails = waterConnectionDetailsService.findByConsumerCodeAndConnectionStatus( searchRequest.getConsumerCode(), ConnectionStatus.INPROGRESS); if (waterConnectionDetails == null) waterConnectionDetails = waterConnectionDetailsService.findByConsumerCodeAndConnectionStatus( searchRequest.getConsumerCode(), ConnectionStatus.ACTIVE); if (waterConnectionDetails == null) { resultBinder.rejectValue(WATERCHARGES_CONSUMERCODE, INVALID_CONSUMERNUMBER); model.addAttribute(APPLICATIONTYPE, applicationType); return COMMON_FORM_SEARCH; } if (isNotBlank(applicationType) && applicationType.equals(ADDNLCONNECTION)) if (waterConnectionDetails.getCloseConnectionType() != null && waterConnectionDetails.getCloseConnectionType().equals(PERMENENTCLOSECODE)) { model.addAttribute(MODE, ERROR_MODE); model.addAttribute(APPLICATIONTYPE, applicationType); resultBinder.rejectValue(WATERCHARGES_CONSUMERCODE, CONNECTION_CLOSED); return COMMON_FORM_SEARCH; } else if ((CHANGEOFUSE.equals(waterConnectionDetails.getApplicationType().getCode()) || NEWCONNECTION.equals(waterConnectionDetails.getApplicationType().getCode()) || RECONNECTION.equals(waterConnectionDetails.getApplicationType().getCode())) && ConnectionStatus.ACTIVE.equals(waterConnectionDetails.getConnectionStatus()) && waterConnectionDetails.getConnection().getParentConnection() == null) return "redirect:/application/addconnection/" + waterConnectionDetails.getConnection().getConsumerCode(); else { model.addAttribute(MODE, ERROR_MODE); model.addAttribute(APPLICATIONTYPE, applicationType); resultBinder.rejectValue(WATERCHARGES_CONSUMERCODE, INVALID_CONSUMERNUMBER); return COMMON_FORM_SEARCH; } if (isNotBlank(applicationType) && applicationType.equals(CHANGEOFUSE)) if (waterConnectionDetails.getCloseConnectionType() != null && waterConnectionDetails.getCloseConnectionType().equals(PERMENENTCLOSECODE)) { model.addAttribute(APPLICATIONTYPE, applicationType); model.addAttribute(MODE, ERROR_MODE); resultBinder.rejectValue(WATERCHARGES_CONSUMERCODE, CONNECTION_CLOSED); return COMMON_FORM_SEARCH; } else if ((waterConnectionDetails.getApplicationType().getCode().equals(NEWCONNECTION) || waterConnectionDetails.getApplicationType().getCode().equals(ADDNLCONNECTION) || waterConnectionDetails.getApplicationType().getCode().equals(CHANGEOFUSE) || RECONNECTION.equalsIgnoreCase(waterConnectionDetails.getApplicationType().getCode())) && waterConnectionDetails.getConnectionStatus().equals(ConnectionStatus.ACTIVE)) return "redirect:/application/changeOfUse/" + waterConnectionDetails.getConnection().getConsumerCode(); else { model.addAttribute(APPLICATIONTYPE, applicationType); model.addAttribute(MODE, ERROR_MODE); resultBinder.rejectValue(WATERCHARGES_CONSUMERCODE, INVALID_CONSUMERNUMBER); return COMMON_FORM_SEARCH; } if (isNotBlank(applicationType) && applicationType.equals(SEARCH_MENUTREE_APPLICATIONTYPE_CLOSURE)) if (isNotBlank(waterConnectionDetails.getCloseConnectionType()) && waterConnectionDetails.getCloseConnectionType().equals(PERMENENTCLOSECODE)) { model.addAttribute(MODE, ERROR_MODE); model.addAttribute(APPLICATIONTYPE, applicationType); resultBinder.rejectValue(WATERCHARGES_CONSUMERCODE, CONNECTION_CLOSED); return COMMON_FORM_SEARCH; } else if ((waterConnectionDetails.getApplicationType().getCode().equals(NEWCONNECTION) || waterConnectionDetails.getApplicationType().getCode().equals(ADDNLCONNECTION) || waterConnectionDetails.getApplicationType().getCode().equals(CHANGEOFUSE) || waterConnectionDetails.getApplicationType().getCode().equals(RECONNECTION)) && waterConnectionDetails.getConnectionStatus().equals(ConnectionStatus.ACTIVE)) return "redirect:/application/close/" + waterConnectionDetails.getConnection().getConsumerCode(); else { model.addAttribute(MODE, ERROR_MODE); resultBinder.rejectValue(WATERCHARGES_CONSUMERCODE, ERR_CLOSURE_NOT_ALLOWED, new String[] { waterConnectionDetails.getApplicationType().getName(), waterConnectionDetails.getApplicationNumber() }, ERR_CLOSURE_NOT_ALLOWED); return COMMON_FORM_SEARCH; } if (isNotBlank(applicationType) && applicationType.equals(RECONNECTION)) if (waterConnectionDetails.getCloseConnectionType() != null && waterConnectionDetails.getCloseConnectionType().equals(PERMENENTCLOSECODE)) { model.addAttribute(MODE, ERROR_MODE); model.addAttribute(APPLICATIONTYPE, applicationType); resultBinder.rejectValue(WATERCHARGES_CONSUMERCODE, CONNECTION_CLOSED); return COMMON_FORM_SEARCH; } else if (waterConnectionDetails.getApplicationType().getCode().equals(CLOSINGCONNECTION) && waterConnectionDetails.getConnectionStatus().equals(ConnectionStatus.CLOSED) && waterConnectionDetails.getStatus().getCode().equals(APPLICATION_STATUS_CLOSERSANCTIONED) && waterConnectionDetails.getCloseConnectionType().equals("T")) return "redirect:/application/reconnection/" + waterConnectionDetails.getConnection().getConsumerCode(); else { model.addAttribute(MODE, ERROR_MODE); model.addAttribute(APPLICATIONTYPE, applicationType); resultBinder.rejectValue(WATERCHARGES_CONSUMERCODE, INVALID_CONSUMERNUMBER); return COMMON_FORM_SEARCH; } if (isNotBlank(applicationType) && applicationType.equals(SEARCH_MENUTREE_APPLICATIONTYPE_METERED)) if ((waterConnectionDetails.getApplicationType().getCode().equals(NEWCONNECTION) || waterConnectionDetails.getApplicationType().getCode().equals(ADDNLCONNECTION) || waterConnectionDetails.getApplicationType().getCode().equals(CHANGEOFUSE)) && waterConnectionDetails.getConnectionStatus().equals(ConnectionStatus.ACTIVE) && waterConnectionDetails.getConnectionType().name().equals(CONNECTIONTYPE_METERED)) return "redirect:/application/meterentry/" + waterConnectionDetails.getConnection().getConsumerCode(); else { model.addAttribute(MODE, ERROR_MODE); model.addAttribute(APPLICATIONTYPE, applicationType); resultBinder.rejectValue(WATERCHARGES_CONSUMERCODE, INVALID_CONSUMERNUMBER); return COMMON_FORM_SEARCH; } if (isNotBlank(applicationType) && applicationType.equals(DATAENTRYEDIT)) if ((waterConnectionDetails.getApplicationType().getCode().equals(NEWCONNECTION) || waterConnectionDetails.getApplicationType().getCode().equals(ADDNLCONNECTION)) && waterConnectionDetails.getConnectionStatus().equals(ConnectionStatus.ACTIVE) && waterConnectionDetails.getLegacy()) { WaterConnectionDetails connectionDetails = waterConnectionDtlsService .findByApplicationNumberOrConsumerCode( waterConnectionDetails.getConnection().getConsumerCode()); if (connectionDetails != null) if (MIGRATED_CONNECTION.equalsIgnoreCase(connectionDetails.getConnectionReason())) { model.addAttribute(MODE, ERROR_MODE); model.addAttribute(APPLICATIONTYPE, applicationType); resultBinder.rejectValue(WATERCHARGES_CONSUMERCODE, ERR_MIGRATED_CONN); return COMMON_FORM_SEARCH; } else { BigDecimal demand = waterConnectionDetailsService .getTotalDemandTillCurrentFinYear(connectionDetails); BigDecimal arrearBalance = waterConnectionDetailsService.getTotalAmount(connectionDetails); if (demand.compareTo(arrearBalance) > 0) { model.addAttribute(MODE, ERROR_MODE); model.addAttribute(APPLICATIONTYPE, applicationType); resultBinder.rejectValue(WATERCHARGES_CONSUMERCODE, ERR_DATAENTRY_MODIFY); return COMMON_FORM_SEARCH; } } return "redirect:/application/newConnection-editExisting/" + waterConnectionDetails.getConnection().getConsumerCode(); } else { model.addAttribute(MODE, ERROR_MODE); model.addAttribute(APPLICATIONTYPE, applicationType); resultBinder.rejectValue(WATERCHARGES_CONSUMERCODE, INVALID_CONSUMERNUMBER); return COMMON_FORM_SEARCH; } if (isNotBlank(applicationType) && applicationType.equals(SEARCH_MENUTREE_APPLICATIONTYPE_COLLECTTAX)) { BigDecimal amoutToBeCollected = ZERO; if (waterTaxUtils.getCurrentDemand(waterConnectionDetails).getDemand() != null) amoutToBeCollected = waterConnectionDetailsService.getTotalAmount(waterConnectionDetails); AssessmentDetails assessmentDetails = propertyExtnUtils.getAssessmentDetailsForFlag( waterConnectionDetails.getConnection().getPropertyIdentifier(), PropertyExternalService.FLAG_FULL_DETAILS, BasicPropertyStatus.ALL); if (assessmentDetails != null) if (amoutToBeCollected.doubleValue() == 0) { model.addAttribute(MODE, ERROR_MODE); model.addAttribute(APPLICATIONTYPE, applicationType); resultBinder.rejectValue(WATERCHARGES_CONSUMERCODE, COLLECTION_ALREADY_DONE); return COMMON_FORM_SEARCH; } else if (amoutToBeCollected.doubleValue() > 0 && (waterConnectionDetails.getConnectionType().equals(ConnectionType.METERED) || waterConnectionDetails.getConnectionType().equals(ConnectionType.NON_METERED)) && !waterConnectionDetails.getApplicationType().getCode().equals(CLOSECONNECTION) && !waterConnectionDetails.getConnectionStatus().equals(ConnectionStatus.INACTIVE)) return "redirect:/application/generatebill/" + waterConnectionDetails.getConnection().getConsumerCode(); else { model.addAttribute(MODE, ERROR_MODE); model.addAttribute(APPLICATIONTYPE, applicationType); resultBinder.rejectValue(WATERCHARGES_CONSUMERCODE, INVALID_CONSUMERNUMBER); return COMMON_FORM_SEARCH; } } if (isNotBlank(applicationType) && applicationType.equals(EDITCOLLECTION)) if ((waterConnectionDetails.getApplicationType().getCode().equals(NEWCONNECTION) || waterConnectionDetails.getApplicationType().getCode().equals(ADDNLCONNECTION)) && waterConnectionDetails.getConnectionStatus().equals(ConnectionStatus.ACTIVE) && waterConnectionDetails.getLegacy()) return "redirect:/application/editCollection/" + waterConnectionDetails.getConnection().getConsumerCode(); else { model.addAttribute(MODE, ERROR_MODE); model.addAttribute(APPLICATIONTYPE, applicationType); resultBinder.rejectValue(WATERCHARGES_CONSUMERCODE, INVALID_CONSUMERNUMBER); return COMMON_FORM_SEARCH; } if (isNotBlank(applicationType) && applicationType.equals(GENERATEBILL)) if (waterConnectionDetails.getApplicationType().getCode().equals(NEWCONNECTION) || waterConnectionDetails.getApplicationType().getCode().equals(ADDNLCONNECTION) || waterConnectionDetails.getApplicationType().getCode().equals(CHANGEOFUSE) && waterConnectionDetails.getConnectionStatus().equals(ConnectionStatus.ACTIVE) && waterConnectionDetails.getConnectionType().equals(ConnectionType.NON_METERED)) return "redirect:/report/generateBillForHSCNo/" + waterConnectionDetails.getConnection().getConsumerCode(); else { model.addAttribute(MODE, ERROR_MODE); model.addAttribute(APPLICATIONTYPE, applicationType); resultBinder.rejectValue(WATERCHARGES_CONSUMERCODE, INVALID_CONSUMERNUMBER); return COMMON_FORM_SEARCH; } if (isNotBlank(applicationType) && applicationType.equals(EDITDEMAND)) if (waterConnectionDetails.getApplicationType().getCode().equals(NEWCONNECTION) || waterConnectionDetails.getApplicationType().getCode().equals(ADDNLCONNECTION) || waterConnectionDetails.getApplicationType().getCode().equals(CHANGEOFUSE) && waterConnectionDetails.getConnectionStatus().equals(ConnectionStatus.ACTIVE) && waterConnectionDetails.getLegacy()) return "redirect:/application/editDemand/" + waterConnectionDetails.getConnection().getConsumerCode(); else { model.addAttribute(MODE, ERROR_MODE); model.addAttribute(APPLICATIONTYPE, applicationType); resultBinder.rejectValue(WATERCHARGES_CONSUMERCODE, INVALID_CONSUMERNUMBER); return COMMON_FORM_SEARCH; } return ""; }
From source file:org.gbif.portal.web.controller.registration.RegistrationController.java
/** * Create a new user in LDAP./* ww w. j a v a 2 s . c om*/ * * @param request * @param response * @return * @throws Exception */ public ModelAndView newUser(HttpServletRequest request, HttpServletResponse response) throws Exception { if (!isFormSubmission(request)) { ModelAndView mav = new ModelAndView("newUser"); UserLogin ul = new UserLogin(); mav.addObject("user", ul); return mav; } UserLogin ul = new UserLogin(); ServletRequestDataBinder binder = createBinder(request, ul); binder.bind(request); BindingResult result = binder.getBindingResult(); String systemUserName = getSystemUserName(ul.getUsername()); String suggestedUsername = null; // validate if (StringUtils.isEmpty(ul.getUsername())) { result.rejectValue("username", ErrorMessageKeys.MUST_BE_SPECIFIED); } else if (ul.getUsername().length() < minimumUsernameLength) { result.rejectValue("username", ErrorMessageKeys.MUST_BE_MINIMIUM_LENGTH); } else if (!validateUsername(ul.getUsername())) { result.rejectValue("username", ErrorMessageKeys.CONTAINS_INVALID_CHARS); } else if (ldapUtils.userNameInUse(systemUserName)) { // iterate until a username available for (int i = 0; i < Integer.MAX_VALUE; i++) { suggestedUsername = getSystemUserName(ul.getUsername() + i); if (!ldapUtils.userNameInUse(suggestedUsername)) { break; } } result.rejectValue("username", ErrorMessageKeys.USERNAME_IN_USE); } if (StringUtils.isEmpty(ul.getFirstName())) { result.rejectValue("firstName", ErrorMessageKeys.MUST_BE_SPECIFIED); } if (StringUtils.isEmpty(ul.getSurname())) { result.rejectValue("surname", ErrorMessageKeys.MUST_BE_SPECIFIED); } if (!StringUtils.isEmpty(ul.getEmail())) { Pattern p = Pattern.compile(".+@.+\\.[a-z]+"); Matcher m = p.matcher(ul.getEmail()); boolean validEmail = m.matches(); if (!validEmail) result.rejectValue("email", ErrorMessageKeys.INVALID_VALUE); } else { result.rejectValue("email", ErrorMessageKeys.MUST_BE_SPECIFIED); } if (StringUtils.isEmpty(ul.getPassword())) { result.rejectValue("password", ErrorMessageKeys.MUST_BE_SPECIFIED); } else if (!validatePassword(ul.getPassword())) { result.rejectValue("password", ErrorMessageKeys.MUST_BE_MINIMIUM_LENGTH); } if (result.hasErrors()) { ModelAndView mav = new ModelAndView("newUser"); if (suggestedUsername != null) { mav.addObject("suggestedUsername", suggestedUsername); } mav.addObject(BindingResult.MODEL_KEY_PREFIX + "user", result); return mav; } // send verification email SimpleMailMessage verificationMessage = new SimpleMailMessage(userTemplateMessage); verificationMessage.setTo(ul.getEmail()); String encryptedPassword = passwordUtils.encryptPassword(ul.getPassword(), true); verificationMessage.setSubject("Confirm e-mail address for GBIF Data Portal"); verificationMessage.setText("Please visit the following link to confirm your e-mail address:\n\n" + "http://" + request.getHeader("host") + request.getContextPath() + "/user/verification" + "?fn=" + ul.getFirstName() + "&sn=" + ul.getSurname() + "&e=" + ul.getEmail() + "&u=" + ul.getUsername() + "&p=" + encryptedPassword); try { mailSender.send(verificationMessage); } catch (MailException e) { // simply log it and go on... logger.error("Couldn't send message", e); ModelAndView mav = new ModelAndView("registrationVerificationFailureView"); mav.addObject("user", ul); return mav; } // successful ModelAndView mav = new ModelAndView("registrationVerificationSuccessView"); mav.addObject("user", ul); return mav; }
From source file:org.gbif.portal.web.controller.registration.RegistrationController.java
/** * Validate this details of this data resource * /*from w ww .j a v a 2 s .c o m*/ * @param resourceDetail * @param result */ private void validateDataResource(ResourceDetail resourceDetail, BindingResult result) { if (StringUtils.isEmpty(resourceDetail.getName())) { result.rejectValue("name", ErrorMessageKeys.MUST_BE_SPECIFIED); } if (StringUtils.isEmpty(resourceDetail.getCode())) { result.rejectValue("code", ErrorMessageKeys.MUST_BE_SPECIFIED); } if (StringUtils.isEmpty(resourceDetail.getAccessPoint())) { result.rejectValue("accessPoint", ErrorMessageKeys.MUST_BE_SPECIFIED); } if (resourceDetail.getNorthCoordinate() != null) { if (resourceDetail.getNorthCoordinate() > 90 || resourceDetail.getNorthCoordinate() < -90) result.rejectValue("northCoordinate", ErrorMessageKeys.INVALID_LATITUDE); } if (resourceDetail.getSouthCoordinate() != null) { if (resourceDetail.getSouthCoordinate() > 90 || resourceDetail.getSouthCoordinate() < -90) result.rejectValue("southCoordinate", ErrorMessageKeys.INVALID_LATITUDE); } if (resourceDetail.getEastCoordinate() != null) { if (resourceDetail.getEastCoordinate() > 180 || resourceDetail.getEastCoordinate() < -180) result.rejectValue("eastCoordinate", ErrorMessageKeys.INVALID_LONGITUDE); } if (resourceDetail.getWestCoordinate() != null) { if (resourceDetail.getWestCoordinate() > 180 || resourceDetail.getWestCoordinate() < -180) result.rejectValue("westCoordinate", ErrorMessageKeys.INVALID_LONGITUDE); } if (resourceDetail.getWestCoordinate() != null && resourceDetail.getEastCoordinate() != null && resourceDetail.getWestCoordinate() > resourceDetail.getEastCoordinate()) { result.rejectValue("westCoordinate", ErrorMessageKeys.WEST_GREATER_THAN_EAST); } if (resourceDetail.getNorthCoordinate() != null && resourceDetail.getSouthCoordinate() != null && resourceDetail.getSouthCoordinate() > resourceDetail.getNorthCoordinate()) { result.rejectValue("southCoordinate", ErrorMessageKeys.SOUTH_GREATER_THAN_NORTH); } }