use of uk.gov.gchq.gaffer.operation.impl.ForEach in project Gaffer by gchq.
the class ForEachIT method shouldExecuteForEachOperationOnGetElementsWithEmptyIterable.
@Test
public void shouldExecuteForEachOperationOnGetElementsWithEmptyIterable() throws OperationException {
// Given
final ForEach<ElementSeed, Iterable<String>> op = new ForEach.Builder<ElementSeed, Iterable<String>>().input(Collections.singletonList(new EdgeSeed("doesNotExist", "doesNotExist", true))).operation(new OperationChain.Builder().first(new ToSingletonList<EntitySeed>()).then(new GetElements()).then(new ToCsv.Builder().includeHeader(false).generator(new CsvGenerator.Builder().vertex("vertex").destination("dest").build()).build()).build()).build();
// When
final List<Iterable<String>> results = Lists.newArrayList(graph.execute(op, getUser()));
// Then
assertThat(results).hasSize(1);
assertThat(Lists.newArrayList(results.get(0))).isEqualTo(Collections.emptyList());
}
use of uk.gov.gchq.gaffer.operation.impl.ForEach in project Gaffer by gchq.
the class Store method validateSchemas.
public void validateSchemas() {
final ValidationResult validationResult = new ValidationResult();
if (null == schema) {
validationResult.addError("Schema is missing");
} else {
validationResult.add(schema.validate());
getSchemaElements().forEach((key, value) -> value.getProperties().forEach(propertyName -> {
final Class propertyClass = value.getPropertyClass(propertyName);
final Serialiser serialisation = value.getPropertyTypeDef(propertyName).getSerialiser();
if (null == serialisation) {
validationResult.addError(String.format("Could not find a serialiser for property '%s' in the group '%s'.", propertyName, key));
} else if (!serialisation.canHandle(propertyClass)) {
validationResult.addError(String.format("Schema serialiser (%s) for property '%s' in the group '%s' cannot handle property found in the schema", serialisation.getClass().getName(), propertyName, key));
}
}));
validateSchema(validationResult, getSchema().getVertexSerialiser());
getSchema().getTypes().forEach((k, v) -> validateSchema(validationResult, v.getSerialiser()));
}
if (!validationResult.isValid()) {
throw new SchemaException("Schema is not valid. " + validationResult.getErrorString());
}
}
use of uk.gov.gchq.gaffer.operation.impl.ForEach in project Gaffer by gchq.
the class ForEachIT method shouldExecuteForEachOperationOnGetElementsWithValidResults.
@Test
public void shouldExecuteForEachOperationOnGetElementsWithValidResults() throws OperationException {
// Given
final ForEach<String, Iterable<String>> op = new ForEach.Builder<String, Iterable<String>>().input(Collections.singletonList(SOURCE_DIR_1)).operation(new OperationChain.Builder().first(new ToSingletonList<>()).then(new ToEntitySeeds()).then(new GetElements()).then(new ToList<Element>()).then(new ToCsv.Builder().includeHeader(false).generator(new CsvGenerator.Builder().vertex("vertex").destination("dest").build()).build()).build()).build();
// When
final List<Iterable<String>> results = Lists.newArrayList(graph.execute(op, getUser()));
// Then
assertThat(results).hasSize(1);
assertThat(Sets.newHashSet(results.get(0))).isEqualTo(Sets.newHashSet(SOURCE_DIR_1 + ",", "," + DEST_DIR_1));
}
Aggregations