@Test public void testValidate(){ System.out.println("validate"); String reqPhone = "000000000000"; instance.setConditionalRequirements(new HashMap<String, List<SubField>>()); instance.setConditionalValidator(new ConditionalRequirementValidator()); IncomingMessageFormParameterDefinitionImpl pDef1 = new IncomingMessageFormParameterDefinitionImpl(); pDef1.setRequired(true); pDef1.setParamType("ALPHANUM"); pDef1.setLength(10); pDef1.setName("chpsId"); IncomingMessageFormParameterDefinitionImpl pDef2 = new IncomingMessageFormParameterDefinitionImpl(); pDef2.setRequired(true); pDef2.setParamType("ALPHANUM"); pDef2.setLength(20); pDef2.setName("patientRegNum"); IncomingMessageFormDefinition formDef = new IncomingMessageFormDefinitionImpl(); formDef.setFormCode("NONE"); formDef.setIncomingMsgParamDefinitions(new HashSet<IncomingMessageFormParameterDefinition>()); formDef.getIncomingMsgParamDefinitions().add(pDef1); formDef.getIncomingMsgParamDefinitions().add(pDef2); IncomingMessageFormParameterImpl param1 = new IncomingMessageFormParameterImpl(); param1.setName("chpsId"); param1.setValue("testchps"); IncomingMessageFormParameterImpl param2 = new IncomingMessageFormParameterImpl(); param2.setName("patientRegNum"); param2.setValue("testpatient"); IncomingMessageForm form = new IncomingMessageFormImpl(); form.setIncomingMsgFormParameters(new HashMap<String,IncomingMessageFormParameter>()); form.setIncomingMsgFormDefinition(formDef); form.getIncomingMsgFormParameters().put(param1.getName().toLowerCase(),param1); IncMessageFormStatus expResult = IncMessageFormStatus.INVALID; expect( mockCore.createIncomingMessageFormParameter() ).andReturn(new IncomingMessageFormParameterImpl()); replay(mockCore, mockParamValidator); IncMessageFormStatus result = instance.validate(form, reqPhone); verify(mockCore, mockParamValidator); assertEquals(expResult, result); assertEquals(param1.getIncomingMsgFormParamDefinition(), pDef1); assertTrue(form.getIncomingMsgFormParameters().size() == 2); assertEquals(form.getMessageFormStatus(), IncMessageFormStatus.INVALID); form.setMessageFormStatus(IncMessageFormStatus.NEW); form.getIncomingMsgFormParameters().clear(); form.getIncomingMsgFormParameters().put(param1.getName().toLowerCase(),param1); form.getIncomingMsgFormParameters().put(param2.getName().toLowerCase(),param2); expResult = IncMessageFormStatus.VALID; reset(mockCore, mockParamValidator); replay(mockCore, mockParamValidator); result = instance.validate(form, reqPhone); verify(mockCore, mockParamValidator); assertEquals(expResult, result); assertEquals(param2.getIncomingMsgFormParamDefinition(), pDef2); assertTrue(form.getIncomingMsgFormParameters().size() == 2); assertEquals(form.getMessageFormStatus(), IncMessageFormStatus.VALID); reset(mockCore, mockParamValidator); expResult = IncMessageFormStatus.INVALID; SubField sf = new SubField(); sf.setFieldName("chpscompound"); sf.setParentField("chpsId"); sf.setReplaceOn("*"); List<SubField> conditionals = new ArrayList<SubField>(); conditionals.add(sf); expect( mockCore.createIncomingMessageFormParameter() ).andReturn(new IncomingMessageFormParameterImpl()); instance.getConditionalRequirements().put(form.getIncomingMsgFormDefinition().getFormCode(), conditionals); replay(mockCore, mockParamValidator); result = instance.validate(form, reqPhone); verify(mockCore, mockParamValidator); assertEquals(expResult, result); assertEquals(param2.getIncomingMsgFormParamDefinition(), pDef2); assertTrue(form.getIncomingMsgFormParameters().size() == 3); assertEquals(form.getMessageFormStatus(), IncMessageFormStatus.INVALID); }
public IncMessageFormStatus validate(IncomingMessageForm form, String requesterPhone) { ValidatorGroup group; IncMessageFormStatus status; form.setMessageFormStatus(IncMessageFormStatus.VALID); List<SubField> subs = null; List<SubField> conditionals = null; if (subFields != null && subFields.containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { subs = subFields.get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); } if (conditionalRequirements != null && conditionalRequirements.containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { conditionals = conditionalRequirements.get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); } Map<String, IncomingMessageFormParameter> params = form.getIncomingMsgFormParameters(); if (subs != null) { for (SubField sub : subs) { if (params.containsKey(sub.getFieldName().toLowerCase())) { if (params.containsKey(sub.getParentField().toLowerCase()) && (params.get(sub.getParentField().toLowerCase()).getValue().equalsIgnoreCase(sub.getReplaceOn()) || ("*".equalsIgnoreCase(sub.getReplaceOn()) && params.get(sub.getFieldName().toLowerCase()) != null && params.get(sub.getFieldName().toLowerCase()).getValue() != null && !"".equals(params.get(sub.getFieldName().toLowerCase()).getValue().trim()))) && params.containsKey(sub.getFieldName().toLowerCase())) { params.get(sub.getParentField().toLowerCase()).setValue(params.get(sub.getFieldName().toLowerCase()).getValue()); } else if (sub.getReplaceOn() == null || sub.getReplaceOn().isEmpty()) { if (!params.containsKey(sub.getParentField().toLowerCase())) { IncomingMessageFormParameter param = coreManager.createIncomingMessageFormParameter(); param.setDateCreated(new Date()); param.setName(sub.getParentField().toLowerCase()); param.setIncomingMsgForm(form); param.setMessageFormParamStatus(IncMessageFormParameterStatus.NEW); params.put(sub.getParentField().toLowerCase(), param); } if (params.get(sub.getParentField().toLowerCase()).getValue() == null || params.get(sub.getParentField().toLowerCase()).getValue().isEmpty()) { params.get(sub.getParentField().toLowerCase()).setValue(params.get(sub.getFieldName().toLowerCase()).getValue()); } } } } } if (conditionals != null) { conditionalValidator.validate(form, conditionals, coreManager); } try { for (IncomingMessageFormParameterDefinition paramDef : form.getIncomingMsgFormDefinition().getIncomingMsgParamDefinitions()) { paramDef.getParamType(); if (form.getIncomingMsgFormParameters().containsKey(paramDef.getName().toLowerCase())) { form.getIncomingMsgFormParameters().get(paramDef.getName().toLowerCase()).setIncomingMsgFormParamDefinition(paramDef); form.setLastModified(new Date()); if (paramDef.getParamType().endsWith("_ARRAY")) { String type = paramDef.getParamType().substring(0, paramDef.getParamType().lastIndexOf("_")); group = paramValidators.get(type.toUpperCase()); if (group == null) { throw new Exception("Validator [" + paramDef.getParamType().toUpperCase() + "] not found"); } status = validateArray(form.getIncomingMsgFormParameters().get(paramDef.getName().toLowerCase()), group); } else { group = paramValidators.get(paramDef.getParamType().toUpperCase()); if (group == null) { throw new Exception("Validator [" + paramDef.getParamType().toUpperCase() + "] not found"); } status = validateSingle(form.getIncomingMsgFormParameters().get(paramDef.getName().toLowerCase()), group); } if (status != IncMessageFormStatus.VALID) { form.setMessageFormStatus(status); } form.setLastModified(new Date()); } else { if (paramDef.isRequired()) { IncomingMessageFormParameter param = coreManager.createIncomingMessageFormParameter(); param.setIncomingMsgFormParamDefinition(paramDef); param.setName(paramDef.getName()); param.setDateCreated(new Date()); param.setIncomingMsgForm(form); param.setValue(null); param.setErrCode(0); param.setErrText("missing"); param.setMessageFormParamStatus(IncMessageFormParameterStatus.INVALID); form.setMessageFormStatus(IncMessageFormStatus.INVALID); form.setLastModified(new Date()); form.getIncomingMsgFormParameters().put(paramDef.getName().toLowerCase(), param); } } } } catch (Exception ex) { logger.fatal("Error validating form", ex); form.setMessageFormStatus(IncMessageFormStatus.ERROR); } if (compositeRequirements.containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { List<CompositeRequirementValidator> requirements = compositeRequirements.get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); for (CompositeRequirementValidator validator : requirements) { if (!validator.validate(form, coreManager)) { form.setMessageFormStatus(IncMessageFormStatus.INVALID); } } } return form.getMessageFormStatus(); }
IncomingMessageFormValidatorImpl implements IncomingMessageFormValidator { public IncMessageFormStatus validate(IncomingMessageForm form, String requesterPhone) { ValidatorGroup group; IncMessageFormStatus status; form.setMessageFormStatus(IncMessageFormStatus.VALID); List<SubField> subs = null; List<SubField> conditionals = null; if (subFields != null && subFields.containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { subs = subFields.get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); } if (conditionalRequirements != null && conditionalRequirements.containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { conditionals = conditionalRequirements.get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); } Map<String, IncomingMessageFormParameter> params = form.getIncomingMsgFormParameters(); if (subs != null) { for (SubField sub : subs) { if (params.containsKey(sub.getFieldName().toLowerCase())) { if (params.containsKey(sub.getParentField().toLowerCase()) && (params.get(sub.getParentField().toLowerCase()).getValue().equalsIgnoreCase(sub.getReplaceOn()) || ("*".equalsIgnoreCase(sub.getReplaceOn()) && params.get(sub.getFieldName().toLowerCase()) != null && params.get(sub.getFieldName().toLowerCase()).getValue() != null && !"".equals(params.get(sub.getFieldName().toLowerCase()).getValue().trim()))) && params.containsKey(sub.getFieldName().toLowerCase())) { params.get(sub.getParentField().toLowerCase()).setValue(params.get(sub.getFieldName().toLowerCase()).getValue()); } else if (sub.getReplaceOn() == null || sub.getReplaceOn().isEmpty()) { if (!params.containsKey(sub.getParentField().toLowerCase())) { IncomingMessageFormParameter param = coreManager.createIncomingMessageFormParameter(); param.setDateCreated(new Date()); param.setName(sub.getParentField().toLowerCase()); param.setIncomingMsgForm(form); param.setMessageFormParamStatus(IncMessageFormParameterStatus.NEW); params.put(sub.getParentField().toLowerCase(), param); } if (params.get(sub.getParentField().toLowerCase()).getValue() == null || params.get(sub.getParentField().toLowerCase()).getValue().isEmpty()) { params.get(sub.getParentField().toLowerCase()).setValue(params.get(sub.getFieldName().toLowerCase()).getValue()); } } } } } if (conditionals != null) { conditionalValidator.validate(form, conditionals, coreManager); } try { for (IncomingMessageFormParameterDefinition paramDef : form.getIncomingMsgFormDefinition().getIncomingMsgParamDefinitions()) { paramDef.getParamType(); if (form.getIncomingMsgFormParameters().containsKey(paramDef.getName().toLowerCase())) { form.getIncomingMsgFormParameters().get(paramDef.getName().toLowerCase()).setIncomingMsgFormParamDefinition(paramDef); form.setLastModified(new Date()); if (paramDef.getParamType().endsWith("_ARRAY")) { String type = paramDef.getParamType().substring(0, paramDef.getParamType().lastIndexOf("_")); group = paramValidators.get(type.toUpperCase()); if (group == null) { throw new Exception("Validator [" + paramDef.getParamType().toUpperCase() + "] not found"); } status = validateArray(form.getIncomingMsgFormParameters().get(paramDef.getName().toLowerCase()), group); } else { group = paramValidators.get(paramDef.getParamType().toUpperCase()); if (group == null) { throw new Exception("Validator [" + paramDef.getParamType().toUpperCase() + "] not found"); } status = validateSingle(form.getIncomingMsgFormParameters().get(paramDef.getName().toLowerCase()), group); } if (status != IncMessageFormStatus.VALID) { form.setMessageFormStatus(status); } form.setLastModified(new Date()); } else { if (paramDef.isRequired()) { IncomingMessageFormParameter param = coreManager.createIncomingMessageFormParameter(); param.setIncomingMsgFormParamDefinition(paramDef); param.setName(paramDef.getName()); param.setDateCreated(new Date()); param.setIncomingMsgForm(form); param.setValue(null); param.setErrCode(0); param.setErrText("missing"); param.setMessageFormParamStatus(IncMessageFormParameterStatus.INVALID); form.setMessageFormStatus(IncMessageFormStatus.INVALID); form.setLastModified(new Date()); form.getIncomingMsgFormParameters().put(paramDef.getName().toLowerCase(), param); } } } } catch (Exception ex) { logger.fatal("Error validating form", ex); form.setMessageFormStatus(IncMessageFormStatus.ERROR); } if (compositeRequirements.containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { List<CompositeRequirementValidator> requirements = compositeRequirements.get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); for (CompositeRequirementValidator validator : requirements) { if (!validator.validate(form, coreManager)) { form.setMessageFormStatus(IncMessageFormStatus.INVALID); } } } return form.getMessageFormStatus(); } }
IncomingMessageFormValidatorImpl implements IncomingMessageFormValidator { public IncMessageFormStatus validate(IncomingMessageForm form, String requesterPhone) { ValidatorGroup group; IncMessageFormStatus status; form.setMessageFormStatus(IncMessageFormStatus.VALID); List<SubField> subs = null; List<SubField> conditionals = null; if (subFields != null && subFields.containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { subs = subFields.get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); } if (conditionalRequirements != null && conditionalRequirements.containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { conditionals = conditionalRequirements.get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); } Map<String, IncomingMessageFormParameter> params = form.getIncomingMsgFormParameters(); if (subs != null) { for (SubField sub : subs) { if (params.containsKey(sub.getFieldName().toLowerCase())) { if (params.containsKey(sub.getParentField().toLowerCase()) && (params.get(sub.getParentField().toLowerCase()).getValue().equalsIgnoreCase(sub.getReplaceOn()) || ("*".equalsIgnoreCase(sub.getReplaceOn()) && params.get(sub.getFieldName().toLowerCase()) != null && params.get(sub.getFieldName().toLowerCase()).getValue() != null && !"".equals(params.get(sub.getFieldName().toLowerCase()).getValue().trim()))) && params.containsKey(sub.getFieldName().toLowerCase())) { params.get(sub.getParentField().toLowerCase()).setValue(params.get(sub.getFieldName().toLowerCase()).getValue()); } else if (sub.getReplaceOn() == null || sub.getReplaceOn().isEmpty()) { if (!params.containsKey(sub.getParentField().toLowerCase())) { IncomingMessageFormParameter param = coreManager.createIncomingMessageFormParameter(); param.setDateCreated(new Date()); param.setName(sub.getParentField().toLowerCase()); param.setIncomingMsgForm(form); param.setMessageFormParamStatus(IncMessageFormParameterStatus.NEW); params.put(sub.getParentField().toLowerCase(), param); } if (params.get(sub.getParentField().toLowerCase()).getValue() == null || params.get(sub.getParentField().toLowerCase()).getValue().isEmpty()) { params.get(sub.getParentField().toLowerCase()).setValue(params.get(sub.getFieldName().toLowerCase()).getValue()); } } } } } if (conditionals != null) { conditionalValidator.validate(form, conditionals, coreManager); } try { for (IncomingMessageFormParameterDefinition paramDef : form.getIncomingMsgFormDefinition().getIncomingMsgParamDefinitions()) { paramDef.getParamType(); if (form.getIncomingMsgFormParameters().containsKey(paramDef.getName().toLowerCase())) { form.getIncomingMsgFormParameters().get(paramDef.getName().toLowerCase()).setIncomingMsgFormParamDefinition(paramDef); form.setLastModified(new Date()); if (paramDef.getParamType().endsWith("_ARRAY")) { String type = paramDef.getParamType().substring(0, paramDef.getParamType().lastIndexOf("_")); group = paramValidators.get(type.toUpperCase()); if (group == null) { throw new Exception("Validator [" + paramDef.getParamType().toUpperCase() + "] not found"); } status = validateArray(form.getIncomingMsgFormParameters().get(paramDef.getName().toLowerCase()), group); } else { group = paramValidators.get(paramDef.getParamType().toUpperCase()); if (group == null) { throw new Exception("Validator [" + paramDef.getParamType().toUpperCase() + "] not found"); } status = validateSingle(form.getIncomingMsgFormParameters().get(paramDef.getName().toLowerCase()), group); } if (status != IncMessageFormStatus.VALID) { form.setMessageFormStatus(status); } form.setLastModified(new Date()); } else { if (paramDef.isRequired()) { IncomingMessageFormParameter param = coreManager.createIncomingMessageFormParameter(); param.setIncomingMsgFormParamDefinition(paramDef); param.setName(paramDef.getName()); param.setDateCreated(new Date()); param.setIncomingMsgForm(form); param.setValue(null); param.setErrCode(0); param.setErrText("missing"); param.setMessageFormParamStatus(IncMessageFormParameterStatus.INVALID); form.setMessageFormStatus(IncMessageFormStatus.INVALID); form.setLastModified(new Date()); form.getIncomingMsgFormParameters().put(paramDef.getName().toLowerCase(), param); } } } } catch (Exception ex) { logger.fatal("Error validating form", ex); form.setMessageFormStatus(IncMessageFormStatus.ERROR); } if (compositeRequirements.containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { List<CompositeRequirementValidator> requirements = compositeRequirements.get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); for (CompositeRequirementValidator validator : requirements) { if (!validator.validate(form, coreManager)) { form.setMessageFormStatus(IncMessageFormStatus.INVALID); } } } return form.getMessageFormStatus(); }  }
IncomingMessageFormValidatorImpl implements IncomingMessageFormValidator { public IncMessageFormStatus validate(IncomingMessageForm form, String requesterPhone) { ValidatorGroup group; IncMessageFormStatus status; form.setMessageFormStatus(IncMessageFormStatus.VALID); List<SubField> subs = null; List<SubField> conditionals = null; if (subFields != null && subFields.containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { subs = subFields.get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); } if (conditionalRequirements != null && conditionalRequirements.containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { conditionals = conditionalRequirements.get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); } Map<String, IncomingMessageFormParameter> params = form.getIncomingMsgFormParameters(); if (subs != null) { for (SubField sub : subs) { if (params.containsKey(sub.getFieldName().toLowerCase())) { if (params.containsKey(sub.getParentField().toLowerCase()) && (params.get(sub.getParentField().toLowerCase()).getValue().equalsIgnoreCase(sub.getReplaceOn()) || ("*".equalsIgnoreCase(sub.getReplaceOn()) && params.get(sub.getFieldName().toLowerCase()) != null && params.get(sub.getFieldName().toLowerCase()).getValue() != null && !"".equals(params.get(sub.getFieldName().toLowerCase()).getValue().trim()))) && params.containsKey(sub.getFieldName().toLowerCase())) { params.get(sub.getParentField().toLowerCase()).setValue(params.get(sub.getFieldName().toLowerCase()).getValue()); } else if (sub.getReplaceOn() == null || sub.getReplaceOn().isEmpty()) { if (!params.containsKey(sub.getParentField().toLowerCase())) { IncomingMessageFormParameter param = coreManager.createIncomingMessageFormParameter(); param.setDateCreated(new Date()); param.setName(sub.getParentField().toLowerCase()); param.setIncomingMsgForm(form); param.setMessageFormParamStatus(IncMessageFormParameterStatus.NEW); params.put(sub.getParentField().toLowerCase(), param); } if (params.get(sub.getParentField().toLowerCase()).getValue() == null || params.get(sub.getParentField().toLowerCase()).getValue().isEmpty()) { params.get(sub.getParentField().toLowerCase()).setValue(params.get(sub.getFieldName().toLowerCase()).getValue()); } } } } } if (conditionals != null) { conditionalValidator.validate(form, conditionals, coreManager); } try { for (IncomingMessageFormParameterDefinition paramDef : form.getIncomingMsgFormDefinition().getIncomingMsgParamDefinitions()) { paramDef.getParamType(); if (form.getIncomingMsgFormParameters().containsKey(paramDef.getName().toLowerCase())) { form.getIncomingMsgFormParameters().get(paramDef.getName().toLowerCase()).setIncomingMsgFormParamDefinition(paramDef); form.setLastModified(new Date()); if (paramDef.getParamType().endsWith("_ARRAY")) { String type = paramDef.getParamType().substring(0, paramDef.getParamType().lastIndexOf("_")); group = paramValidators.get(type.toUpperCase()); if (group == null) { throw new Exception("Validator [" + paramDef.getParamType().toUpperCase() + "] not found"); } status = validateArray(form.getIncomingMsgFormParameters().get(paramDef.getName().toLowerCase()), group); } else { group = paramValidators.get(paramDef.getParamType().toUpperCase()); if (group == null) { throw new Exception("Validator [" + paramDef.getParamType().toUpperCase() + "] not found"); } status = validateSingle(form.getIncomingMsgFormParameters().get(paramDef.getName().toLowerCase()), group); } if (status != IncMessageFormStatus.VALID) { form.setMessageFormStatus(status); } form.setLastModified(new Date()); } else { if (paramDef.isRequired()) { IncomingMessageFormParameter param = coreManager.createIncomingMessageFormParameter(); param.setIncomingMsgFormParamDefinition(paramDef); param.setName(paramDef.getName()); param.setDateCreated(new Date()); param.setIncomingMsgForm(form); param.setValue(null); param.setErrCode(0); param.setErrText("missing"); param.setMessageFormParamStatus(IncMessageFormParameterStatus.INVALID); form.setMessageFormStatus(IncMessageFormStatus.INVALID); form.setLastModified(new Date()); form.getIncomingMsgFormParameters().put(paramDef.getName().toLowerCase(), param); } } } } catch (Exception ex) { logger.fatal("Error validating form", ex); form.setMessageFormStatus(IncMessageFormStatus.ERROR); } if (compositeRequirements.containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { List<CompositeRequirementValidator> requirements = compositeRequirements.get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); for (CompositeRequirementValidator validator : requirements) { if (!validator.validate(form, coreManager)) { form.setMessageFormStatus(IncMessageFormStatus.INVALID); } } } return form.getMessageFormStatus(); }  IncMessageFormStatus validate(IncomingMessageForm form, String requesterPhone); CoreManager getCoreManager(); void setCoreManager(CoreManager coreManager); void setParamValidators(LinkedHashMap<String, ValidatorGroup> paramValidators); void setSubFields(Map<String, List<SubField>> subFields); void setCompositeRequirements(Map<String, List<CompositeRequirementValidator>> compositeRequirements); Map<String, List<SubField>> getConditionalRequirements(); void setConditionalRequirements(Map<String, List<SubField>> conditionalRequirements); ConditionalRequirementValidator getConditionalValidator(); void setConditionalValidator(ConditionalRequirementValidator conditionalValidator); }
IncomingMessageFormValidatorImpl implements IncomingMessageFormValidator { public IncMessageFormStatus validate(IncomingMessageForm form, String requesterPhone) { ValidatorGroup group; IncMessageFormStatus status; form.setMessageFormStatus(IncMessageFormStatus.VALID); List<SubField> subs = null; List<SubField> conditionals = null; if (subFields != null && subFields.containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { subs = subFields.get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); } if (conditionalRequirements != null && conditionalRequirements.containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { conditionals = conditionalRequirements.get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); } Map<String, IncomingMessageFormParameter> params = form.getIncomingMsgFormParameters(); if (subs != null) { for (SubField sub : subs) { if (params.containsKey(sub.getFieldName().toLowerCase())) { if (params.containsKey(sub.getParentField().toLowerCase()) && (params.get(sub.getParentField().toLowerCase()).getValue().equalsIgnoreCase(sub.getReplaceOn()) || ("*".equalsIgnoreCase(sub.getReplaceOn()) && params.get(sub.getFieldName().toLowerCase()) != null && params.get(sub.getFieldName().toLowerCase()).getValue() != null && !"".equals(params.get(sub.getFieldName().toLowerCase()).getValue().trim()))) && params.containsKey(sub.getFieldName().toLowerCase())) { params.get(sub.getParentField().toLowerCase()).setValue(params.get(sub.getFieldName().toLowerCase()).getValue()); } else if (sub.getReplaceOn() == null || sub.getReplaceOn().isEmpty()) { if (!params.containsKey(sub.getParentField().toLowerCase())) { IncomingMessageFormParameter param = coreManager.createIncomingMessageFormParameter(); param.setDateCreated(new Date()); param.setName(sub.getParentField().toLowerCase()); param.setIncomingMsgForm(form); param.setMessageFormParamStatus(IncMessageFormParameterStatus.NEW); params.put(sub.getParentField().toLowerCase(), param); } if (params.get(sub.getParentField().toLowerCase()).getValue() == null || params.get(sub.getParentField().toLowerCase()).getValue().isEmpty()) { params.get(sub.getParentField().toLowerCase()).setValue(params.get(sub.getFieldName().toLowerCase()).getValue()); } } } } } if (conditionals != null) { conditionalValidator.validate(form, conditionals, coreManager); } try { for (IncomingMessageFormParameterDefinition paramDef : form.getIncomingMsgFormDefinition().getIncomingMsgParamDefinitions()) { paramDef.getParamType(); if (form.getIncomingMsgFormParameters().containsKey(paramDef.getName().toLowerCase())) { form.getIncomingMsgFormParameters().get(paramDef.getName().toLowerCase()).setIncomingMsgFormParamDefinition(paramDef); form.setLastModified(new Date()); if (paramDef.getParamType().endsWith("_ARRAY")) { String type = paramDef.getParamType().substring(0, paramDef.getParamType().lastIndexOf("_")); group = paramValidators.get(type.toUpperCase()); if (group == null) { throw new Exception("Validator [" + paramDef.getParamType().toUpperCase() + "] not found"); } status = validateArray(form.getIncomingMsgFormParameters().get(paramDef.getName().toLowerCase()), group); } else { group = paramValidators.get(paramDef.getParamType().toUpperCase()); if (group == null) { throw new Exception("Validator [" + paramDef.getParamType().toUpperCase() + "] not found"); } status = validateSingle(form.getIncomingMsgFormParameters().get(paramDef.getName().toLowerCase()), group); } if (status != IncMessageFormStatus.VALID) { form.setMessageFormStatus(status); } form.setLastModified(new Date()); } else { if (paramDef.isRequired()) { IncomingMessageFormParameter param = coreManager.createIncomingMessageFormParameter(); param.setIncomingMsgFormParamDefinition(paramDef); param.setName(paramDef.getName()); param.setDateCreated(new Date()); param.setIncomingMsgForm(form); param.setValue(null); param.setErrCode(0); param.setErrText("missing"); param.setMessageFormParamStatus(IncMessageFormParameterStatus.INVALID); form.setMessageFormStatus(IncMessageFormStatus.INVALID); form.setLastModified(new Date()); form.getIncomingMsgFormParameters().put(paramDef.getName().toLowerCase(), param); } } } } catch (Exception ex) { logger.fatal("Error validating form", ex); form.setMessageFormStatus(IncMessageFormStatus.ERROR); } if (compositeRequirements.containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { List<CompositeRequirementValidator> requirements = compositeRequirements.get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); for (CompositeRequirementValidator validator : requirements) { if (!validator.validate(form, coreManager)) { form.setMessageFormStatus(IncMessageFormStatus.INVALID); } } } return form.getMessageFormStatus(); }  IncMessageFormStatus validate(IncomingMessageForm form, String requesterPhone); CoreManager getCoreManager(); void setCoreManager(CoreManager coreManager); void setParamValidators(LinkedHashMap<String, ValidatorGroup> paramValidators); void setSubFields(Map<String, List<SubField>> subFields); void setCompositeRequirements(Map<String, List<CompositeRequirementValidator>> compositeRequirements); Map<String, List<SubField>> getConditionalRequirements(); void setConditionalRequirements(Map<String, List<SubField>> conditionalRequirements); ConditionalRequirementValidator getConditionalValidator(); void setConditionalValidator(ConditionalRequirementValidator conditionalValidator);  }