@Test public void paramPatternMissing() { EvaluationFunction evFunction = engine.buildEvaluationFunction(FUNCTION_NAME) .withValueParamByReference(PARAM_DIR, ValueType.FILE, PSP_VAR); ValueEvaluation evaluation = evFunction.evaluate(); assertEquals(null, evaluation.getData()); }
@Override public ValueEvaluation evaluate() { try { checkContractCompliance(); boolean errorIfDirNull = true; List<ValueParam> paramErrorIfDirNull = valueParams.getParams(PARAM_ERROR_IF_DIR_NULL); if (!paramErrorIfDirNull.isEmpty()) { errorIfDirNull = (boolean) paramErrorIfDirNull.get(0).getEvaluation().getData(); } ValueEvaluation paramDir = valueParams.getParams(PARAM_DIR).get(0).getEvaluation(); File dir = (File) paramDir.getData(); if (dir == null) { if (errorIfDirNull) { return errorResultParamNull(PARAM_DIR, paramDir); } else { return okResult(Collections.emptyList()); } } else if (!dir.exists()) { return errorResultFileDoesNotExist(dir); } else if (!dir.isDirectory()) { return errorResultFileIsNotDir(dir); } else if (!dir.canRead()) { return errorResultCannotReadDir(dir); } PatternEvaluation patternParam = patternParams.getParam(PARAM_PATTERN).getEvaluation(); if (!patternParam.isOk()) { return errorResultPatternParamNull(PARAM_PATTERN, patternParam); } File[] files = dir.listFiles(); List<File> filesMatching = new ArrayList<>(files.length); for (File file : files) { if (patternParam.matches(file.getName())) { filesMatching.add(file); } } return okResult(filesMatching); } catch (ContractException e) { return errorResultContractNotMet(e); } catch (Throwable e) { return errorResultUnexpectedError(e); } }
EfFindFilesInDirByPattern extends EvaluationFunction { @Override public ValueEvaluation evaluate() { try { checkContractCompliance(); boolean errorIfDirNull = true; List<ValueParam> paramErrorIfDirNull = valueParams.getParams(PARAM_ERROR_IF_DIR_NULL); if (!paramErrorIfDirNull.isEmpty()) { errorIfDirNull = (boolean) paramErrorIfDirNull.get(0).getEvaluation().getData(); } ValueEvaluation paramDir = valueParams.getParams(PARAM_DIR).get(0).getEvaluation(); File dir = (File) paramDir.getData(); if (dir == null) { if (errorIfDirNull) { return errorResultParamNull(PARAM_DIR, paramDir); } else { return okResult(Collections.emptyList()); } } else if (!dir.exists()) { return errorResultFileDoesNotExist(dir); } else if (!dir.isDirectory()) { return errorResultFileIsNotDir(dir); } else if (!dir.canRead()) { return errorResultCannotReadDir(dir); } PatternEvaluation patternParam = patternParams.getParam(PARAM_PATTERN).getEvaluation(); if (!patternParam.isOk()) { return errorResultPatternParamNull(PARAM_PATTERN, patternParam); } File[] files = dir.listFiles(); List<File> filesMatching = new ArrayList<>(files.length); for (File file : files) { if (patternParam.matches(file.getName())) { filesMatching.add(file); } } return okResult(filesMatching); } catch (ContractException e) { return errorResultContractNotMet(e); } catch (Throwable e) { return errorResultUnexpectedError(e); } } }
EfFindFilesInDirByPattern extends EvaluationFunction { @Override public ValueEvaluation evaluate() { try { checkContractCompliance(); boolean errorIfDirNull = true; List<ValueParam> paramErrorIfDirNull = valueParams.getParams(PARAM_ERROR_IF_DIR_NULL); if (!paramErrorIfDirNull.isEmpty()) { errorIfDirNull = (boolean) paramErrorIfDirNull.get(0).getEvaluation().getData(); } ValueEvaluation paramDir = valueParams.getParams(PARAM_DIR).get(0).getEvaluation(); File dir = (File) paramDir.getData(); if (dir == null) { if (errorIfDirNull) { return errorResultParamNull(PARAM_DIR, paramDir); } else { return okResult(Collections.emptyList()); } } else if (!dir.exists()) { return errorResultFileDoesNotExist(dir); } else if (!dir.isDirectory()) { return errorResultFileIsNotDir(dir); } else if (!dir.canRead()) { return errorResultCannotReadDir(dir); } PatternEvaluation patternParam = patternParams.getParam(PARAM_PATTERN).getEvaluation(); if (!patternParam.isOk()) { return errorResultPatternParamNull(PARAM_PATTERN, patternParam); } File[] files = dir.listFiles(); List<File> filesMatching = new ArrayList<>(files.length); for (File file : files) { if (patternParam.matches(file.getName())) { filesMatching.add(file); } } return okResult(filesMatching); } catch (ContractException e) { return errorResultContractNotMet(e); } catch (Throwable e) { return errorResultUnexpectedError(e); } } EfFindFilesInDirByPattern(String name, Engine engine); }
EfFindFilesInDirByPattern extends EvaluationFunction { @Override public ValueEvaluation evaluate() { try { checkContractCompliance(); boolean errorIfDirNull = true; List<ValueParam> paramErrorIfDirNull = valueParams.getParams(PARAM_ERROR_IF_DIR_NULL); if (!paramErrorIfDirNull.isEmpty()) { errorIfDirNull = (boolean) paramErrorIfDirNull.get(0).getEvaluation().getData(); } ValueEvaluation paramDir = valueParams.getParams(PARAM_DIR).get(0).getEvaluation(); File dir = (File) paramDir.getData(); if (dir == null) { if (errorIfDirNull) { return errorResultParamNull(PARAM_DIR, paramDir); } else { return okResult(Collections.emptyList()); } } else if (!dir.exists()) { return errorResultFileDoesNotExist(dir); } else if (!dir.isDirectory()) { return errorResultFileIsNotDir(dir); } else if (!dir.canRead()) { return errorResultCannotReadDir(dir); } PatternEvaluation patternParam = patternParams.getParam(PARAM_PATTERN).getEvaluation(); if (!patternParam.isOk()) { return errorResultPatternParamNull(PARAM_PATTERN, patternParam); } File[] files = dir.listFiles(); List<File> filesMatching = new ArrayList<>(files.length); for (File file : files) { if (patternParam.matches(file.getName())) { filesMatching.add(file); } } return okResult(filesMatching); } catch (ContractException e) { return errorResultContractNotMet(e); } catch (Throwable e) { return errorResultUnexpectedError(e); } } EfFindFilesInDirByPattern(String name, Engine engine); @Override ValueEvaluation evaluate(); }
EfFindFilesInDirByPattern extends EvaluationFunction { @Override public ValueEvaluation evaluate() { try { checkContractCompliance(); boolean errorIfDirNull = true; List<ValueParam> paramErrorIfDirNull = valueParams.getParams(PARAM_ERROR_IF_DIR_NULL); if (!paramErrorIfDirNull.isEmpty()) { errorIfDirNull = (boolean) paramErrorIfDirNull.get(0).getEvaluation().getData(); } ValueEvaluation paramDir = valueParams.getParams(PARAM_DIR).get(0).getEvaluation(); File dir = (File) paramDir.getData(); if (dir == null) { if (errorIfDirNull) { return errorResultParamNull(PARAM_DIR, paramDir); } else { return okResult(Collections.emptyList()); } } else if (!dir.exists()) { return errorResultFileDoesNotExist(dir); } else if (!dir.isDirectory()) { return errorResultFileIsNotDir(dir); } else if (!dir.canRead()) { return errorResultCannotReadDir(dir); } PatternEvaluation patternParam = patternParams.getParam(PARAM_PATTERN).getEvaluation(); if (!patternParam.isOk()) { return errorResultPatternParamNull(PARAM_PATTERN, patternParam); } File[] files = dir.listFiles(); List<File> filesMatching = new ArrayList<>(files.length); for (File file : files) { if (patternParam.matches(file.getName())) { filesMatching.add(file); } } return okResult(filesMatching); } catch (ContractException e) { return errorResultContractNotMet(e); } catch (Throwable e) { return errorResultUnexpectedError(e); } } EfFindFilesInDirByPattern(String name, Engine engine); @Override ValueEvaluation evaluate();  }