@Test public void fromUrnTooShort() { VfCheckStringDerivedFromOneOfIdentifiers vf = new VfCheckStringDerivedFromOneOfIdentifiers(VF_NAME, engine); ValidationResult result = vf.validate("00172f", 6, ids( id("ccnb", "cnb000572615"), id("urnnbn", "urn:nbn:cz:nk-123"), id("uuid", "b50eb6b0-f0a4-11e3-b72e-005056827e52") ), prefixes("cnb", "urn:nbn:cz:", "uuid:") ); assertTrue(result.hasProblems()); }
@Override public ValidationResult validate() { try { checkContractCompliance(); ValueEvaluation paramStringEval = valueParams.getParams(PARAM_STRING).get(0).getEvaluation(); String string = (String) paramStringEval.getData(); if (string == null) { return invalidValueParamNull(PARAM_STRING, paramStringEval); } ValueEvaluation paramMinMatchLengthEVal = valueParams.getParams(PARAM_MIN_MATCH_LENGTH).get(0).getEvaluation(); Integer minMatchLength = (Integer) paramMinMatchLengthEVal.getData(); if (minMatchLength == null) { return invalidValueParamNull(PARAM_MIN_MATCH_LENGTH, paramMinMatchLengthEVal); } ValueEvaluation paramIdPrefixesEval = valueParams.getParams(PARAM_ID_PREFIXES).get(0).getEvaluation(); List<String> idPrefixes = (List<String>) paramIdPrefixesEval.getData(); if (idPrefixes == null) { return invalidValueParamNull(PARAM_ID_PREFIXES, paramIdPrefixesEval); } ValueEvaluation paramIdentifiersEval = valueParams.getParams(PARAM_IDENTIFIERS).get(0).getEvaluation(); List<Identifier> identifiers = (List<Identifier>) paramIdentifiersEval.getData(); if (idPrefixes == null) { return invalidValueParamNull(PARAM_IDENTIFIERS, paramIdentifiersEval); } return validate(string, minMatchLength, identifiers, idPrefixes); } catch (ContractException e) { return invalidContractNotMet(e); } catch (Throwable e) { return invalidUnexpectedError(e); } }
VfCheckStringDerivedFromOneOfIdentifiers extends ValidationFunction { @Override public ValidationResult validate() { try { checkContractCompliance(); ValueEvaluation paramStringEval = valueParams.getParams(PARAM_STRING).get(0).getEvaluation(); String string = (String) paramStringEval.getData(); if (string == null) { return invalidValueParamNull(PARAM_STRING, paramStringEval); } ValueEvaluation paramMinMatchLengthEVal = valueParams.getParams(PARAM_MIN_MATCH_LENGTH).get(0).getEvaluation(); Integer minMatchLength = (Integer) paramMinMatchLengthEVal.getData(); if (minMatchLength == null) { return invalidValueParamNull(PARAM_MIN_MATCH_LENGTH, paramMinMatchLengthEVal); } ValueEvaluation paramIdPrefixesEval = valueParams.getParams(PARAM_ID_PREFIXES).get(0).getEvaluation(); List<String> idPrefixes = (List<String>) paramIdPrefixesEval.getData(); if (idPrefixes == null) { return invalidValueParamNull(PARAM_ID_PREFIXES, paramIdPrefixesEval); } ValueEvaluation paramIdentifiersEval = valueParams.getParams(PARAM_IDENTIFIERS).get(0).getEvaluation(); List<Identifier> identifiers = (List<Identifier>) paramIdentifiersEval.getData(); if (idPrefixes == null) { return invalidValueParamNull(PARAM_IDENTIFIERS, paramIdentifiersEval); } return validate(string, minMatchLength, identifiers, idPrefixes); } catch (ContractException e) { return invalidContractNotMet(e); } catch (Throwable e) { return invalidUnexpectedError(e); } } }
VfCheckStringDerivedFromOneOfIdentifiers extends ValidationFunction { @Override public ValidationResult validate() { try { checkContractCompliance(); ValueEvaluation paramStringEval = valueParams.getParams(PARAM_STRING).get(0).getEvaluation(); String string = (String) paramStringEval.getData(); if (string == null) { return invalidValueParamNull(PARAM_STRING, paramStringEval); } ValueEvaluation paramMinMatchLengthEVal = valueParams.getParams(PARAM_MIN_MATCH_LENGTH).get(0).getEvaluation(); Integer minMatchLength = (Integer) paramMinMatchLengthEVal.getData(); if (minMatchLength == null) { return invalidValueParamNull(PARAM_MIN_MATCH_LENGTH, paramMinMatchLengthEVal); } ValueEvaluation paramIdPrefixesEval = valueParams.getParams(PARAM_ID_PREFIXES).get(0).getEvaluation(); List<String> idPrefixes = (List<String>) paramIdPrefixesEval.getData(); if (idPrefixes == null) { return invalidValueParamNull(PARAM_ID_PREFIXES, paramIdPrefixesEval); } ValueEvaluation paramIdentifiersEval = valueParams.getParams(PARAM_IDENTIFIERS).get(0).getEvaluation(); List<Identifier> identifiers = (List<Identifier>) paramIdentifiersEval.getData(); if (idPrefixes == null) { return invalidValueParamNull(PARAM_IDENTIFIERS, paramIdentifiersEval); } return validate(string, minMatchLength, identifiers, idPrefixes); } catch (ContractException e) { return invalidContractNotMet(e); } catch (Throwable e) { return invalidUnexpectedError(e); } } VfCheckStringDerivedFromOneOfIdentifiers(String name, Engine engine); }
VfCheckStringDerivedFromOneOfIdentifiers extends ValidationFunction { @Override public ValidationResult validate() { try { checkContractCompliance(); ValueEvaluation paramStringEval = valueParams.getParams(PARAM_STRING).get(0).getEvaluation(); String string = (String) paramStringEval.getData(); if (string == null) { return invalidValueParamNull(PARAM_STRING, paramStringEval); } ValueEvaluation paramMinMatchLengthEVal = valueParams.getParams(PARAM_MIN_MATCH_LENGTH).get(0).getEvaluation(); Integer minMatchLength = (Integer) paramMinMatchLengthEVal.getData(); if (minMatchLength == null) { return invalidValueParamNull(PARAM_MIN_MATCH_LENGTH, paramMinMatchLengthEVal); } ValueEvaluation paramIdPrefixesEval = valueParams.getParams(PARAM_ID_PREFIXES).get(0).getEvaluation(); List<String> idPrefixes = (List<String>) paramIdPrefixesEval.getData(); if (idPrefixes == null) { return invalidValueParamNull(PARAM_ID_PREFIXES, paramIdPrefixesEval); } ValueEvaluation paramIdentifiersEval = valueParams.getParams(PARAM_IDENTIFIERS).get(0).getEvaluation(); List<Identifier> identifiers = (List<Identifier>) paramIdentifiersEval.getData(); if (idPrefixes == null) { return invalidValueParamNull(PARAM_IDENTIFIERS, paramIdentifiersEval); } return validate(string, minMatchLength, identifiers, idPrefixes); } catch (ContractException e) { return invalidContractNotMet(e); } catch (Throwable e) { return invalidUnexpectedError(e); } } VfCheckStringDerivedFromOneOfIdentifiers(String name, Engine engine); @Override ValidationResult validate(); }
VfCheckStringDerivedFromOneOfIdentifiers extends ValidationFunction { @Override public ValidationResult validate() { try { checkContractCompliance(); ValueEvaluation paramStringEval = valueParams.getParams(PARAM_STRING).get(0).getEvaluation(); String string = (String) paramStringEval.getData(); if (string == null) { return invalidValueParamNull(PARAM_STRING, paramStringEval); } ValueEvaluation paramMinMatchLengthEVal = valueParams.getParams(PARAM_MIN_MATCH_LENGTH).get(0).getEvaluation(); Integer minMatchLength = (Integer) paramMinMatchLengthEVal.getData(); if (minMatchLength == null) { return invalidValueParamNull(PARAM_MIN_MATCH_LENGTH, paramMinMatchLengthEVal); } ValueEvaluation paramIdPrefixesEval = valueParams.getParams(PARAM_ID_PREFIXES).get(0).getEvaluation(); List<String> idPrefixes = (List<String>) paramIdPrefixesEval.getData(); if (idPrefixes == null) { return invalidValueParamNull(PARAM_ID_PREFIXES, paramIdPrefixesEval); } ValueEvaluation paramIdentifiersEval = valueParams.getParams(PARAM_IDENTIFIERS).get(0).getEvaluation(); List<Identifier> identifiers = (List<Identifier>) paramIdentifiersEval.getData(); if (idPrefixes == null) { return invalidValueParamNull(PARAM_IDENTIFIERS, paramIdentifiersEval); } return validate(string, minMatchLength, identifiers, idPrefixes); } catch (ContractException e) { return invalidContractNotMet(e); } catch (Throwable e) { return invalidUnexpectedError(e); } } VfCheckStringDerivedFromOneOfIdentifiers(String name, Engine engine); @Override ValidationResult validate(); static final String PARAM_STRING; static final String PARAM_IDENTIFIERS; static final String PARAM_MIN_MATCH_LENGTH; static final String PARAM_ID_PREFIXES; }