public ValidationResult testWithValidationResult(final Element element) { final ValidationResult result = new ValidationResult(); elementTuple.setElement(element); components.stream() .filter(predicate -> !predicate.test(elementTuple)) .forEach(predicate -> result.addError(getErrorMsg(predicate))); return result; }
@Test public void shouldTestElementOnPredicate2WithValidationResult() { // Given final KoryphePredicate2<String, String> predicate2 = new KoryphePredicate2<String, String>() { @Override public boolean test(final String o, final String o2) { return "value".equals(o) && "value2".equals(o2); } }; final ElementFilter filter = new ElementFilter.Builder() .select("prop1", "prop2") .execute(predicate2) .build(); final Entity element1 = new Entity.Builder() .property("prop1", "value") .property("prop2", "value2") .build(); final Entity element2 = new Entity.Builder() .property("prop1", "unknown") .property("prop2", "value2") .build(); // When final ValidationResult result1 = filter.testWithValidationResult(element1); final ValidationResult result2 = filter.testWithValidationResult(element2); // Then assertTrue(result1.isValid()); assertFalse(result2.isValid()); assertTrue("Result was: " + result2.getErrorString(), result2.getErrorString().contains("{prop1: <java.lang.String>unknown, prop2: <java.lang.String>value2}")); }
@Override public void validateGraph(final Store store, final String graphId, final Schema schema, final StoreProperties storeProperties, final List<String> parentSchemaIds, final String parentStorePropertiesId, final Pair<Schema, StoreProperties> existingGraphPair) { ValidationResult result = super.validate(store, graphId, schema, storeProperties, parentSchemaIds, parentStorePropertiesId, existingGraphPair, new ValidationResult()); Set<String> errors = result.getErrors(); result.getErrors().removeIf(s -> s.equals(String.format(CANT_BOTH_BE_NULL, SCHEMA_STRING, PARENT_SCHEMA_IDS)) || s.equals(String.format(CANT_BOTH_BE_NULL, STORE_PROPERTIES_STRING, PARENT_STORE_PROPERTIES_ID))); result = new ValidationResult(); for (final String error : errors) { result.addError(error); } if (graphId.equals(store.getGraphId())) { result.addError(String.format(CANNOT_EXPORT_TO_THE_SAME_GRAPH_S, graphId)); } if (!result.isValid()) { throw new IllegalArgumentException(result.getErrorString()); } }
public void validateGraph(final Store store, final String graphId, final Schema schema, final StoreProperties storeProperties, final List<String> parentSchemaIds, final String parentStorePropertiesId, final Pair<Schema, StoreProperties> existingGraphPair) { ValidationResult result = validate(store, graphId, schema, storeProperties, parentSchemaIds, parentStorePropertiesId, existingGraphPair, new ValidationResult()); if (!result.isValid()) { throw new IllegalArgumentException(result.getErrorString()); } }
@Override public ValidationResult assignable(final Class<?>... arguments) { if (isInput) { if (input instanceof InputValidator) { return ((InputValidator) input).isInputValid(arguments); } } else if (input instanceof OutputValidator) { return ((OutputValidator) input).isOutputValid(arguments); } final ValidationResult result = new ValidationResult(); if (null != types) { if (null != numClasses && types.length != arguments.length) { result.addError("Incompatible number of types. " + input.getClass() + ": " + Arrays.toString(types) + ", arguments: " + Arrays.toString(arguments)); return result; } if (null == numClasses) { for (final Class type : arguments) { result.add(types[0].assignable(type)); } } else { int i = 0; for (final Class type : arguments) { result.add(types[i].assignable(type)); i++; } } } return result; }
public ValidationResult(final String errorMsg) { addError(errorMsg); }
public void add(final ValidationResult validationResult, final String errorMessage) { if (!validationResult.isValid()) { isValid = false; if (null == errors) { errors = new LinkedHashSet<>(validationResult.getErrors()); } else { errors.addAll(validationResult.getErrors()); } if (null != errorMessage) { errors.add(errorMessage); } } }
@Override public ValidationResult isInputValid(final Class<?>... arguments) { if (null == components) { return new ValidationResult(); } final ValidationResult result = new ValidationResult(); for (final C component : components) { result.add(Signature.getInputSignature(component).assignable(arguments)); } return result; } }
protected boolean listAggregators(final Class<?> clazz) { final List<String> aggregateClasses = new ArrayList<>(); for (final BinaryOperator function : AGGREGATE_FUNCTIONS) { final Signature signature = Signature.getInputSignature(function); if (signature.assignable(clazz).isValid()) { aggregateClasses.add(WalkthroughStrSubstitutor.getJavaDocLink(function.getClass(), false)); } } if (!aggregateClasses.isEmpty()) { log(AGGREGATORS_KEY, "\nAggregators:"); log(AGGREGATORS_KEY, "\n- " + StringUtils.join(aggregateClasses, "\n- ")); } return !aggregateClasses.isEmpty(); }
@Override public ValidationResult isInputValid(final Class<?>... arguments) { if (null == predicate) { return new ValidationResult(); } return Signature.getInputSignature(predicate).assignable(arguments); } }
public void logWarns() { getErrors().forEach(LOGGER::warn); }
public void add(final ValidationResult validationResult) { add(validationResult, null); }
@Override public void validateGraph(final Store store, final String graphId, final Schema schema, final StoreProperties storeProperties, final List<String> parentSchemaIds, final String parentStorePropertiesId, final Pair<Schema, StoreProperties> existingGraphPair) { ValidationResult result = super.validate(store, graphId, schema, storeProperties, parentSchemaIds, parentStorePropertiesId, existingGraphPair, new ValidationResult()); Set<String> errors = result.getErrors(); result.getErrors().removeIf(s -> s.equals(String.format(S_CANNOT_BE_USED_WITHOUT_A_GRAPH_LIBRARY, PARENT_SCHEMA_IDS)) || s.equals(String.format(GRAPH_ID_S_CANNOT_BE_CREATED_WITHOUT_DEFINED_KNOWN_S, graphId, SCHEMA_STRING)) || s.equals(String.format(GRAPH_ID_S_CANNOT_BE_CREATED_WITHOUT_DEFINED_KNOWN_S, graphId, STORE_PROPERTIES_STRING))); result = new ValidationResult(); for (final String error : errors) { result.addError(error); result.addError(String.format(STORE_GRAPH_LIBRARY_IS_NULL)); } else { result.addError(String.format(USER_IS_NOT_AUTHORISED_TO_EXPORT_USING_S_S, GRAPH_ID, graphId)); for (final String parentSchemaId : parentSchemaIds) { if (!isAuthorised(user, idAuths.get(parentSchemaId))) { result.addError(String.format(USER_IS_NOT_AUTHORISED_TO_EXPORT_USING_S_S, SCHEMA_ID, parentSchemaId)); result.addError(String.format(USER_IS_NOT_AUTHORISED_TO_EXPORT_USING_S_S, STORE_PROPERTIES_ID, parentStorePropertiesId)); result.addError(String.format(GRAPH_S_ALREADY_EXISTS_SO_YOU_CANNOT_USE_A_DIFFERENT_S_DO_NOT_SET_THE_S_FIELD, graphId, SCHEMA_STRING, PARENT_SCHEMA_IDS)); result.addError(String.format(GRAPH_S_ALREADY_EXISTS_SO_YOU_CANNOT_USE_A_DIFFERENT_S_DO_NOT_SET_THE_S_FIELD, graphId, STORE_PROPERTIES_STRING, PARENT_STORE_PROPERTIES_ID)); result.addError(String.format(GRAPH_LIBRARY_CANNOT_BE_FOUND_WITH_GRAPHID_S, graphId));
public static void validate(final Store store, final String graphId, final Schema schema, final StoreProperties storeProperties, final List<String> parentSchemaIds, final String parentStorePropertiesId, final Pair<Schema, StoreProperties> existingGraphPair) { ValidationResult result = validate(store, graphId, schema, storeProperties, parentSchemaIds, parentStorePropertiesId, existingGraphPair, new ValidationResult()); if (!result.isValid()) { throw new IllegalArgumentException(result.getErrorString()); } }
@Override public ValidationResult validate() { final ValidationResult result = Output.super.validate(); if (!view.hasEdges() && !view.hasEntities()) { result.addError("Cannot create a GraphFrame unless the View contains edges or entities."); } return result; }
protected boolean listPredicates(final Class<?> clazz) { final List<String> validateClasses = new ArrayList<>(); for (final Predicate function : PREDICATES) { try { final Signature signature = Signature.getInputSignature(function); if (signature.assignable(clazz).isValid()) { validateClasses.add(WalkthroughStrSubstitutor.getJavaDocLink(function.getClass(), false)); } } catch (final Exception e) { // just add the function. validateClasses.add(WalkthroughStrSubstitutor.getJavaDocLink(function.getClass(), false)); } } if (!validateClasses.isEmpty()) { log(PREDICATES_KEY, "\nPredicates:"); log(PREDICATES_KEY, "\n- " + StringUtils.join(validateClasses, "\n- ")); } return !validateClasses.isEmpty(); }
public void logTrace() { getErrors().forEach(LOGGER::trace); }
@Override public ValidationResult validate() { final ValidationResult result = Operation.super.validate(); result.add(FieldUtil.validateRequiredFields( new Tuple3<>("proportionToSample must be greater than 0", proportionToSample, new IsMoreThan(0f)) )); return result; }
@Override public ValidationResult isInputValid(final Class<?>... arguments) { final ValidationResult result = new ValidationResult(); if (null == arguments || 2 != arguments.length || null == arguments[0] || null == arguments[1]) { result.addError("Incorrect number of arguments for " + getClass().getName() + ". 2 arguments are required."); return result; } if (!arguments[0].equals(arguments[1]) || !Comparable.class.isAssignableFrom(arguments[0])) { result.addError("Inputs must be the same class type and comparable: " + arguments[0] + "," + arguments[1]); } return result; } }
final ValidationResult validationResult = new ValidationResult(); for (final IteratorScope iteratorScope : EnumSet.allOf(IteratorScope.class)) { final IteratorSetting aggItrSetting; validationResult.addError("Aggregator iterator for scope " + iteratorScope.name() + " is not as expected. " + "Expected: " + requiredAggItrSetting + ", but found: " + aggItrSetting); validationResult.addError("Validator iterator for scope " + iteratorScope.name() + " is not as expected. " + "Expected: " + requiredValidatorItrSetting + ", but found: " + validatorItrSetting); validationResult.addError("The versioning iterator for scope " + iteratorScope.name() + " should not be set on the table."); validationResult.addError("Bloom filter is not enabled. " + Property.TABLE_BLOOM_ENABLED.getKey() + " = " + bloomFilterEnabled); validationResult.addError("Bloom key functor class is incorrect. " + "Expected: " + CoreKeyBloomFunctor.class.getName() + ", but found: " + bloomKeyFunctor); if (!validationResult.isValid()) { throw new StoreException("Your table " + tableName + " is configured incorrectly. " + validationResult.getErrorString() + "\nEither delete the table and let Gaffer create it for you or fix it manually using the Accumulo shell or the Gaffer AddUpdateTableIterator utility.");