Search in sources :

Example 16 with If

use of uk.gov.gchq.gaffer.operation.impl.If in project Gaffer by gchq.

the class IfScoreResolverTest method shouldGetScoreWithFullyPopulatedOperation.

@Test
public void shouldGetScoreWithFullyPopulatedOperation() {
    // Given
    final Count count = mock(Count.class);
    final GetAllElements getAllElements = mock(GetAllElements.class);
    final GetWalks getWalks = mock(GetWalks.class);
    final Conditional conditional = mock(Conditional.class);
    given(conditional.getTransform()).willReturn(count);
    final If operation = new If.Builder<>().conditional(conditional).then(getWalks).otherwise(getAllElements).build();
    final LinkedHashMap<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
    opScores.put(Count.class, 1);
    opScores.put(GetAllElements.class, 3);
    opScores.put(GetWalks.class, 4);
    final DefaultScoreResolver defaultResolver = new DefaultScoreResolver(opScores);
    final IfScoreResolver resolver = new IfScoreResolver();
    // When
    final int score = resolver.getScore(operation, defaultResolver);
    // Then
    assertEquals(4, score);
}
Also used : GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) Count(uk.gov.gchq.gaffer.operation.impl.Count) Operation(uk.gov.gchq.gaffer.operation.Operation) LinkedHashMap(java.util.LinkedHashMap) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) If(uk.gov.gchq.gaffer.operation.impl.If) Test(org.junit.jupiter.api.Test)

Example 17 with If

use of uk.gov.gchq.gaffer.operation.impl.If 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 18 with If

use of uk.gov.gchq.gaffer.operation.impl.If in project Gaffer by gchq.

the class IfIT method shouldReturnOriginalInputWhenConditionIsFalseAndNoOtherwise.

@Test
public void shouldReturnOriginalInputWhenConditionIsFalseAndNoOtherwise() throws OperationException {
    // Given
    final If<Object, Object> ifOperation = new If<>();
    ifOperation.setInput(INPUT_CAMEL_CASE);
    ifOperation.setConditional(new Conditional(new IsA("java.lang.Integer")));
    ifOperation.setThen(new Map<>(Lists.newArrayList(new ToLong(), new ToList())));
    // When
    final Object output = graph.execute(ifOperation, getUser());
    // Then
    assertThat(output).isEqualTo(INPUT_CAMEL_CASE).isInstanceOf(String.class);
}
Also used : ToLong(uk.gov.gchq.koryphe.impl.function.ToLong) IsA(uk.gov.gchq.koryphe.impl.predicate.IsA) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) If(uk.gov.gchq.gaffer.operation.impl.If) ToList(uk.gov.gchq.koryphe.impl.function.ToList) Test(org.junit.Test)

Example 19 with If

use of uk.gov.gchq.gaffer.operation.impl.If in project Gaffer by gchq.

the class IfIT method shouldReturnOriginalInputWhenConditionIsTrueAndNoThen.

@Test
public void shouldReturnOriginalInputWhenConditionIsTrueAndNoThen() throws OperationException {
    // Given
    final If<Object, Object> ifOperation = new If<>();
    ifOperation.setInput(INPUT_CAMEL_CASE);
    ifOperation.setConditional(new Conditional(new IsA("java.lang.String")));
    ifOperation.setOtherwise(new Map<>(Lists.newArrayList(new ToLong(), new ToList())));
    // When
    final Object output = graph.execute(ifOperation, getUser());
    // Then
    assertThat(output).isEqualTo(INPUT_CAMEL_CASE).isInstanceOf(String.class);
}
Also used : ToLong(uk.gov.gchq.koryphe.impl.function.ToLong) IsA(uk.gov.gchq.koryphe.impl.predicate.IsA) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) If(uk.gov.gchq.gaffer.operation.impl.If) ToList(uk.gov.gchq.koryphe.impl.function.ToList) Test(org.junit.Test)

Example 20 with If

use of uk.gov.gchq.gaffer.operation.impl.If in project Gaffer by gchq.

the class IfIT method shouldRunThenOperationWhenConditionIsTrue.

@Test
public void shouldRunThenOperationWhenConditionIsTrue() throws OperationException {
    // Given
    final If<Object, Object> ifOperation = new If<>();
    ifOperation.setInput(INPUT_CAMEL_CASE);
    ifOperation.setConditional(new Conditional(new IsA("java.lang.String")));
    ifOperation.setThen(new Map<>(Lists.newArrayList(new ToUpperCase(), new ToList())));
    ifOperation.setOtherwise(new Map<>(Lists.newArrayList(new ToLowerCase(), new ToList())));
    // When
    final Object output = graph.execute(ifOperation, getUser());
    // Then
    assertThat(output).isEqualTo(Lists.newArrayList(INPUT_CAMEL_CASE.toUpperCase())).isInstanceOf(List.class);
}
Also used : IsA(uk.gov.gchq.koryphe.impl.predicate.IsA) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) If(uk.gov.gchq.gaffer.operation.impl.If) ToLowerCase(uk.gov.gchq.koryphe.impl.function.ToLowerCase) ToList(uk.gov.gchq.koryphe.impl.function.ToList) ToUpperCase(uk.gov.gchq.koryphe.impl.function.ToUpperCase) Test(org.junit.Test)

Aggregations

If (uk.gov.gchq.gaffer.operation.impl.If)20 Conditional (uk.gov.gchq.gaffer.operation.util.Conditional)16 Test (org.junit.jupiter.api.Test)14 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)10 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)10 Operation (uk.gov.gchq.gaffer.operation.Operation)7 GetWalks (uk.gov.gchq.gaffer.operation.impl.GetWalks)7 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)6 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)6 Test (org.junit.Test)5 ToList (uk.gov.gchq.koryphe.impl.function.ToList)5 IsA (uk.gov.gchq.koryphe.impl.predicate.IsA)5 LinkedHashMap (java.util.LinkedHashMap)4 Count (uk.gov.gchq.gaffer.operation.impl.Count)4 CountGroups (uk.gov.gchq.gaffer.operation.impl.CountGroups)3 DiscardOutput (uk.gov.gchq.gaffer.operation.impl.DiscardOutput)3 Limit (uk.gov.gchq.gaffer.operation.impl.Limit)3 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)3 Context (uk.gov.gchq.gaffer.store.Context)3 User (uk.gov.gchq.gaffer.user.User)3