NdsBeisEsb/src/main/java/com/northgateps/nds/beis/esb/process/ValidateRegisterPrsExemptionNdsRequest.java
/**
	 * Validates a RegisterPrsExemption request
	 * 
	 * @param request
	 * @return request - after validation
	 * @throws NdsApplicationException
	 * @throws NdsBusinessException
	 */
Validates a RegisterPrsExemption request

@param request
@return request - after validation
@throws NdsApplicationException
@throws NdsBusinessException
Validates a RegisterPrsExemption request @param request @return request - after validation @throws NdsApplicationException @throws NdsBusinessException
public RegisterPrsExemptionNdsRequest validate(final RegisterPrsExemptionNdsRequest request)
			throws NdsApplicationException, NdsBusinessException {
		List<ValidationViolation> violations = new ArrayList<ValidationViolation>();
		logger.info("Validating RegisterPrsExemption request");
		if (request.getUserName() == null) {
			throw new NdsApplicationException("Expected username but it was null");
		}
		if (request.getTenant() == null) {
			throw new NdsApplicationException("Expected tenant but it was null");
		}
		if (request.getRegisterPrsExemptionDetails() == null) {
			throw new NdsApplicationException("Expected PRS Exemption details but it was null");
		}
		ConfigurationManager configurationManager = ConfigurationFactory.getConfiguration();
		final String rejectedPostcodeList = configurationManager.getString("exemption.excludedPostcodes");
		Pattern pattern = Pattern.compile(rejectedPostcodeList);
		Matcher m = pattern.matcher(request.getRegisterPrsExemptionDetails().getExemptionDetails().getEpc()
				.getPropertyAddress().getPostcode());
		if (m.find())
			violations.add(new ValidationViolation("postcode",
					"This address has a postcode that is not in England or Wales. You can only register an exemption for a property in England or Wales"));
		request.getRegisterPrsExemptionDetails().getExemptionDetails().validate("ExemptionDetails", violations,
				new ValidationContext<ExemptionDetailEsbModel>(new ExemptionDetailEsbModel() {
					@Override
					public ExemptionDetail getExemptionDetail() {
						return request.getRegisterPrsExemptionDetails().getExemptionDetails();
					}
				}, ValidationDomain.COMPLETE, scriptsLoader, getModelAnnotationsProvider(), null));
		if (violations.size() > 0) {
			throw new NdsBusinessException(RegisterPrsExemptionNdsResponse.class, violations);
		}
		return request;
	}
public RegisterPrsExemptionNdsRequest validate ( final RegisterPrsExemptionNdsRequest request ) throws NdsApplicationException , NdsBusinessException { List < ValidationViolation > violations = new ArrayList < ValidationViolation > ( ) ; logger . info ( "Validating RegisterPrsExemption request" ) ; if ( request . getUserName ( ) == null ) { throw new NdsApplicationException ( "Expected username but it was null" ) ; } if ( request . getTenant ( ) == null ) { throw new NdsApplicationException ( "Expected tenant but it was null" ) ; } if ( request . getRegisterPrsExemptionDetails ( ) == null ) { throw new NdsApplicationException ( "Expected PRS Exemption details but it was null" ) ; } ConfigurationManager configurationManager = ConfigurationFactory . getConfiguration ( ) ; final String rejectedPostcodeList = configurationManager . getString ( "exemption.excludedPostcodes" ) ; Pattern pattern = Pattern . compile ( rejectedPostcodeList ) ; Matcher m = pattern . matcher ( request . getRegisterPrsExemptionDetails ( ) . getExemptionDetails ( ) . getEpc ( ) . getPropertyAddress ( ) . getPostcode ( ) ) ; if ( m . find ( ) ) violations . add ( new ValidationViolation ( "postcode" , "This address has a postcode that is not in England or Wales. You can only register an exemption for a property in England or Wales" ) ) ; request . getRegisterPrsExemptionDetails ( ) . getExemptionDetails ( ) . validate ( "ExemptionDetails" , violations , new ValidationContext < ExemptionDetailEsbModel > ( new ExemptionDetailEsbModel ( ) { @ Override public ExemptionDetail getExemptionDetail ( ) { return request . getRegisterPrsExemptionDetails ( ) . getExemptionDetails ( ) ; } } , ValidationDomain . COMPLETE , scriptsLoader , getModelAnnotationsProvider ( ) , null ) ) ; if ( violations . size ( ) > 0 ) { throw new NdsBusinessException ( RegisterPrsExemptionNdsResponse . class , violations ) ; } return request ; }
Validates a RegisterPrsExemption request
Validates a RegisterPrsExemption request
// Code for validating Scottish and Northern Ireland postcodes while // registering an exemption