Search in sources :

Example 6 with ForEach

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());
}
Also used : GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) CsvGenerator(uk.gov.gchq.gaffer.data.generator.CsvGenerator) ForEach(uk.gov.gchq.gaffer.operation.impl.ForEach) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ToCsv(uk.gov.gchq.gaffer.operation.impl.output.ToCsv) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) ToSingletonList(uk.gov.gchq.gaffer.operation.impl.output.ToSingletonList) Test(org.junit.Test)

Example 7 with ForEach

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());
    }
}
Also used : GetExportsHandler(uk.gov.gchq.gaffer.store.operation.handler.export.GetExportsHandler) SetVariable(uk.gov.gchq.gaffer.operation.impl.SetVariable) Collections.unmodifiableList(java.util.Collections.unmodifiableList) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) GenerateElements(uk.gov.gchq.gaffer.operation.impl.generate.GenerateElements) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Max(uk.gov.gchq.gaffer.operation.impl.compare.Max) Element(uk.gov.gchq.gaffer.data.element.Element) GetJobResultsHandler(uk.gov.gchq.gaffer.store.operation.handler.job.GetJobResultsHandler) DiscardOutputHandler(uk.gov.gchq.gaffer.store.operation.handler.DiscardOutputHandler) SortHandler(uk.gov.gchq.gaffer.store.operation.handler.compare.SortHandler) SchemaOptimiser(uk.gov.gchq.gaffer.store.schema.SchemaOptimiser) ValidateOperationChainHandler(uk.gov.gchq.gaffer.store.operation.handler.ValidateOperationChainHandler) ToArrayHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToArrayHandler) SetVariableHandler(uk.gov.gchq.gaffer.store.operation.handler.SetVariableHandler) Map(java.util.Map) If(uk.gov.gchq.gaffer.operation.impl.If) Count(uk.gov.gchq.gaffer.operation.impl.Count) DeleteNamedViewHandler(uk.gov.gchq.gaffer.store.operation.handler.named.DeleteNamedViewHandler) ToEntitySeedsHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToEntitySeedsHandler) ToSingletonList(uk.gov.gchq.gaffer.operation.impl.output.ToSingletonList) MaxHandler(uk.gov.gchq.gaffer.store.operation.handler.compare.MaxHandler) ToArray(uk.gov.gchq.gaffer.operation.impl.output.ToArray) OperationDeclaration(uk.gov.gchq.gaffer.store.operation.declaration.OperationDeclaration) AddSchemaToLibraryHandler(uk.gov.gchq.gaffer.store.operation.handler.AddSchemaToLibraryHandler) ToEntitySeeds(uk.gov.gchq.gaffer.operation.impl.output.ToEntitySeeds) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) ForEachHandler(uk.gov.gchq.gaffer.store.operation.handler.ForEachHandler) LimitHandler(uk.gov.gchq.gaffer.store.operation.handler.LimitHandler) AddNamedViewHandler(uk.gov.gchq.gaffer.store.operation.handler.named.AddNamedViewHandler) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache) Set(java.util.Set) ToListHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToListHandler) ExportToSet(uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet) ReflectionUtil(uk.gov.gchq.koryphe.util.ReflectionUtil) OperationChainDAO(uk.gov.gchq.gaffer.operation.OperationChainDAO) CountGroupsHandler(uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler) AddNamedOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.named.AddNamedOperationHandler) ForEach(uk.gov.gchq.gaffer.operation.impl.ForEach) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) OutputOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) IfHandler(uk.gov.gchq.gaffer.store.operation.handler.IfHandler) JobTracker(uk.gov.gchq.gaffer.jobtracker.JobTracker) GetAllNamedViews(uk.gov.gchq.gaffer.named.view.GetAllNamedViews) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) FilterHandler(uk.gov.gchq.gaffer.store.operation.handler.function.FilterHandler) GetVariables(uk.gov.gchq.gaffer.operation.impl.GetVariables) ArrayList(java.util.ArrayList) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) LinkedHashMap(java.util.LinkedHashMap) GetVariable(uk.gov.gchq.gaffer.operation.impl.GetVariable) Transform(uk.gov.gchq.gaffer.operation.impl.function.Transform) ToStreamHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToStreamHandler) GetAllNamedOperations(uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations) GetAllJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetAllJobDetails) ToVertices(uk.gov.gchq.gaffer.operation.impl.output.ToVertices) NoGraphLibrary(uk.gov.gchq.gaffer.store.library.NoGraphLibrary) DeleteNamedOperation(uk.gov.gchq.gaffer.named.operation.DeleteNamedOperation) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) ViewValidator(uk.gov.gchq.gaffer.store.schema.ViewValidator) StreamSupport(java.util.stream.StreamSupport) Sort(uk.gov.gchq.gaffer.operation.impl.compare.Sort) Aggregate(uk.gov.gchq.gaffer.operation.impl.function.Aggregate) LinkedHashSet(java.util.LinkedHashSet) CancelScheduledJobHandler(uk.gov.gchq.gaffer.store.operation.handler.job.CancelScheduledJobHandler) Properties(java.util.Properties) OperationUtil(uk.gov.gchq.gaffer.store.operation.OperationUtil) ToMap(uk.gov.gchq.gaffer.operation.impl.output.ToMap) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) ToSet(uk.gov.gchq.gaffer.operation.impl.output.ToSet) AddStorePropertiesToLibraryHandler(uk.gov.gchq.gaffer.store.operation.handler.AddStorePropertiesToLibraryHandler) IdentifierType(uk.gov.gchq.gaffer.data.element.IdentifierType) ToSingletonListHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToSingletonListHandler) MinHandler(uk.gov.gchq.gaffer.store.operation.handler.compare.MinHandler) Operation(uk.gov.gchq.gaffer.operation.Operation) Schema(uk.gov.gchq.gaffer.store.schema.Schema) GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) OperationChainHandler(uk.gov.gchq.gaffer.store.operation.handler.OperationChainHandler) AddStorePropertiesToLibrary(uk.gov.gchq.gaffer.store.operation.add.AddStorePropertiesToLibrary) OperationHandler(uk.gov.gchq.gaffer.store.operation.handler.OperationHandler) JoinHandler(uk.gov.gchq.gaffer.store.operation.handler.join.JoinHandler) GetTraitsHandler(uk.gov.gchq.gaffer.store.operation.handler.GetTraitsHandler) GenerateElementsHandler(uk.gov.gchq.gaffer.store.operation.handler.generate.GenerateElementsHandler) Job(uk.gov.gchq.gaffer.jobtracker.Job) GetJobDetailsHandler(uk.gov.gchq.gaffer.store.operation.handler.job.GetJobDetailsHandler) LoggerFactory(org.slf4j.LoggerFactory) ToCsvHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToCsvHandler) ToCsv(uk.gov.gchq.gaffer.operation.impl.output.ToCsv) WhileHandler(uk.gov.gchq.gaffer.store.operation.handler.WhileHandler) GetVariableHandler(uk.gov.gchq.gaffer.store.operation.handler.GetVariableHandler) OperationDeclarations(uk.gov.gchq.gaffer.store.operation.declaration.OperationDeclarations) Filter(uk.gov.gchq.gaffer.operation.impl.function.Filter) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) GetAllNamedViewsHandler(uk.gov.gchq.gaffer.store.operation.handler.named.GetAllNamedViewsHandler) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ToStream(uk.gov.gchq.gaffer.operation.impl.output.ToStream) MapHandler(uk.gov.gchq.gaffer.store.operation.handler.MapHandler) GetAllNamedOperationsHandler(uk.gov.gchq.gaffer.store.operation.handler.named.GetAllNamedOperationsHandler) CacheServiceLoader(uk.gov.gchq.gaffer.cache.CacheServiceLoader) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) GetSetExport(uk.gov.gchq.gaffer.operation.impl.export.set.GetSetExport) GetTraits(uk.gov.gchq.gaffer.store.operation.GetTraits) GenerateObjectsHandler(uk.gov.gchq.gaffer.store.operation.handler.generate.GenerateObjectsHandler) GetJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) ToSetHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToSetHandler) GetExports(uk.gov.gchq.gaffer.operation.impl.export.GetExports) Join(uk.gov.gchq.gaffer.operation.impl.join.Join) List(java.util.List) AddSchemaToLibrary(uk.gov.gchq.gaffer.store.operation.add.AddSchemaToLibrary) ToVerticesHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToVerticesHandler) ReduceHandler(uk.gov.gchq.gaffer.store.operation.handler.ReduceHandler) CloseableUtil(uk.gov.gchq.gaffer.commonutil.CloseableUtil) OperationException(uk.gov.gchq.gaffer.operation.OperationException) GetSchema(uk.gov.gchq.gaffer.store.operation.GetSchema) CountHandler(uk.gov.gchq.gaffer.store.operation.handler.CountHandler) DeleteNamedOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.named.DeleteNamedOperationHandler) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) ToList(uk.gov.gchq.gaffer.operation.impl.output.ToList) Operations(uk.gov.gchq.gaffer.operation.Operations) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) GetSetExportHandler(uk.gov.gchq.gaffer.store.operation.handler.export.set.GetSetExportHandler) AggregateHandler(uk.gov.gchq.gaffer.store.operation.handler.function.AggregateHandler) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) GetAllJobDetailsHandler(uk.gov.gchq.gaffer.store.operation.handler.job.GetAllJobDetailsHandler) User(uk.gov.gchq.gaffer.user.User) CancelScheduledJob(uk.gov.gchq.gaffer.operation.impl.job.CancelScheduledJob) GetWalksHandler(uk.gov.gchq.gaffer.store.operation.handler.GetWalksHandler) DeleteNamedView(uk.gov.gchq.gaffer.named.view.DeleteNamedView) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) HashMap(java.util.HashMap) GetJobResults(uk.gov.gchq.gaffer.operation.impl.job.GetJobResults) ExportToSetHandler(uk.gov.gchq.gaffer.store.operation.handler.export.set.ExportToSetHandler) Input(uk.gov.gchq.gaffer.operation.io.Input) NamedOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.named.NamedOperationHandler) OperationChainOptimiser(uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) ToMapHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToMapHandler) Output(uk.gov.gchq.gaffer.operation.io.Output) While(uk.gov.gchq.gaffer.operation.impl.While) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Logger(org.slf4j.Logger) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) JobStatus(uk.gov.gchq.gaffer.jobtracker.JobStatus) TransformHandler(uk.gov.gchq.gaffer.store.operation.handler.function.TransformHandler) ValidateHandler(uk.gov.gchq.gaffer.store.operation.handler.ValidateHandler) ExecutorService(uk.gov.gchq.gaffer.commonutil.ExecutorService) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) AddNamedView(uk.gov.gchq.gaffer.named.view.AddNamedView) Reduce(uk.gov.gchq.gaffer.operation.impl.Reduce) GetSchemaHandler(uk.gov.gchq.gaffer.store.operation.handler.GetSchemaHandler) GetVariablesHandler(uk.gov.gchq.gaffer.store.operation.handler.GetVariablesHandler) Min(uk.gov.gchq.gaffer.operation.impl.compare.Min) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) ValidationResult(uk.gov.gchq.koryphe.ValidationResult)

Example 8 with ForEach

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));
}
Also used : ToEntitySeeds(uk.gov.gchq.gaffer.operation.impl.output.ToEntitySeeds) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) CsvGenerator(uk.gov.gchq.gaffer.data.generator.CsvGenerator) ForEach(uk.gov.gchq.gaffer.operation.impl.ForEach) ToCsv(uk.gov.gchq.gaffer.operation.impl.output.ToCsv) ToSingletonList(uk.gov.gchq.gaffer.operation.impl.output.ToSingletonList) Test(org.junit.Test)

Aggregations

ForEach (uk.gov.gchq.gaffer.operation.impl.ForEach)8 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)5 Test (org.junit.Test)4 List (java.util.List)3 Test (org.junit.jupiter.api.Test)3 Element (uk.gov.gchq.gaffer.data.element.Element)3 Context (uk.gov.gchq.gaffer.store.Context)3 Store (uk.gov.gchq.gaffer.store.Store)3 User (uk.gov.gchq.gaffer.user.User)3 HashMap (java.util.HashMap)2 Set (java.util.Set)2 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)2 CsvGenerator (uk.gov.gchq.gaffer.data.generator.CsvGenerator)2 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)2 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)2 ToCsv (uk.gov.gchq.gaffer.operation.impl.output.ToCsv)2 ToEntitySeeds (uk.gov.gchq.gaffer.operation.impl.output.ToEntitySeeds)2 ToSingletonList (uk.gov.gchq.gaffer.operation.impl.output.ToSingletonList)2 Lists (com.google.common.collect.Lists)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1