Skip to content

Commit

Permalink
Gh-2560 get traits operation configurable (#2579)
Browse files Browse the repository at this point in the history
* Update docs links in README

* Revert "Update docs links in README"

This reverts commit 2d87bf3.

* gh-2559 added hasTrait, its handler and corresponding tests (#2561)

* gh-2559 added hasTrait, its handler and corresponding tests

* gh-2559 amended comment in HasTrait, added additional tests for the handler

* gh-2559 null check & tidy test

Co-authored-by: t92549 <80890692+t92549@users.noreply.github.com>

* Update links to Gaffer docs in all files (#2566)

Co-authored-by: t92549 <80890692+t92549@users.noreply.github.com>

* gh-2560 GetTraitsHandler is initalised with traits dependednt on store type

* gh-2560 reviewed comments

* gh-2560 unused imports

* gh-2560 review comments

* checkstyle

* gh-2560 fixed federated test

* gh-2560 fixed GraphTest

* gh-2560 fixed TestStore

* gh-2560-getTraitsOperation (#2582)

Removing redundant adding of GetTraitHandler from addAdditionalOperationHandlers() because it has its own method getGetTraitsHandler().

* gh-2560: Added fix to SingleUseMapStoreWithoutVisibilitySupport

* gh-2560: Fixed Set copy issue in GetTraitsHandler constructor

* gh-2560: Added extra protections to GetTraitsHandler

Co-authored-by: GCHQDeveloper314 <94527357+GCHQDeveloper314@users.noreply.github.com>
Co-authored-by: t92549 <80890692+t92549@users.noreply.github.com>
Co-authored-by: GCHQDev404 <45399082+GCHQDev404@users.noreply.github.com>
  • Loading branch information
4 people committed Feb 4, 2022
1 parent f83376d commit 28e9411
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
import uk.gov.gchq.gaffer.store.TestTypes;
import uk.gov.gchq.gaffer.store.library.GraphLibrary;
import uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary;
import uk.gov.gchq.gaffer.store.operation.GetTraits;
import uk.gov.gchq.gaffer.store.operation.handler.GetTraitsHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OperationHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler;
import uk.gov.gchq.gaffer.store.schema.Schema;
Expand Down Expand Up @@ -2725,6 +2727,11 @@ protected OperationHandler<? extends AddElements> getAddElementsHandler() {
return null;
}

@Override
protected OutputOperationHandler<GetTraits, Set<StoreTrait>> getGetTraitsHandler() {
return new GetTraitsHandler(new HashSet<>(0));
}

@Override
protected Class<? extends Serialiser> getRequiredParentSerialiserClass() {
return ToBytesSerialiser.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import uk.gov.gchq.gaffer.store.Context;
import uk.gov.gchq.gaffer.store.Store;
import uk.gov.gchq.gaffer.store.StoreTrait;
import uk.gov.gchq.gaffer.store.operation.GetTraits;
import uk.gov.gchq.gaffer.store.operation.handler.GetTraitsHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OperationHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler;

Expand Down Expand Up @@ -85,6 +87,12 @@ protected OperationHandler<? extends AddElements> getAddElementsHandler() {
return null;
}

@Override
protected OutputOperationHandler<GetTraits, Set<StoreTrait>> getGetTraitsHandler() {
// mockStore.getGetTraitsHandler() would be better but protected
return new GetTraitsHandler(mockStore.getTraits());
}

@Override
public boolean isSupported(final Class<? extends Operation> operationClass) {
return mockStore.isSupported(operationClass);
Expand Down
13 changes: 11 additions & 2 deletions core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
import uk.gov.gchq.gaffer.store.operation.handler.DiscardOutputHandler;
import uk.gov.gchq.gaffer.store.operation.handler.ForEachHandler;
import uk.gov.gchq.gaffer.store.operation.handler.GetSchemaHandler;
import uk.gov.gchq.gaffer.store.operation.handler.GetTraitsHandler;
import uk.gov.gchq.gaffer.store.operation.handler.GetVariableHandler;
import uk.gov.gchq.gaffer.store.operation.handler.GetVariablesHandler;
import uk.gov.gchq.gaffer.store.operation.handler.GetWalksHandler;
Expand Down Expand Up @@ -866,6 +865,16 @@ public List<OperationChainOptimiser> getOperationChainOptimisers() {
*/
protected abstract OperationHandler<? extends AddElements> getAddElementsHandler();

/**
* Get this Stores implementation of the handler for {@link
* uk.gov.gchq.gaffer.store.operation.GetTraits}.
* All Stores must implement this.
*
* @return the implementation of the handler for {@link
* uk.gov.gchq.gaffer.store.operation.GetTraits}
*/
protected abstract OutputOperationHandler<GetTraits, Set<StoreTrait>> getGetTraitsHandler();

/**
* Get this Store's implementation of the handler for {@link
* uk.gov.gchq.gaffer.operation.OperationChain}.
Expand Down Expand Up @@ -1073,7 +1082,7 @@ private void addCoreOpHandlers() {

// Traits
addOperationHandler(HasTrait.class, new HasTraitHandler());
addOperationHandler(GetTraits.class, new GetTraitsHandler());
addOperationHandler(GetTraits.class, getGetTraitsHandler());
}

private void addConfiguredOperationHandlers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@
import static org.apache.commons.collections.CollectionUtils.isNotEmpty;

public class GetTraitsHandler implements OutputOperationHandler<GetTraits, Set<StoreTrait>> {
private final Set<StoreTrait> storeTraits;
private Set<StoreTrait> currentTraits;

public GetTraitsHandler(final Set<StoreTrait> storeTraits) {
this.storeTraits = Collections.unmodifiableSet(Sets.newHashSet(storeTraits));
}

@Override
public Set<StoreTrait> doOperation(final GetTraits operation, final Context context, final Store store) throws OperationException {
if (!operation.isCurrentTraits()) {
return store.getTraits();
return storeTraits;
}

if (null == currentTraits) {
Expand All @@ -49,7 +54,7 @@ public Set<StoreTrait> doOperation(final GetTraits operation, final Context cont
}

private Set<StoreTrait> createCurrentTraits(final Store store) {
final Set<StoreTrait> traits = Sets.newHashSet(store.getTraits());
final Set<StoreTrait> traits = Sets.newHashSet(storeTraits);
final Schema schema = store.getSchema();

final boolean hasAggregatedGroups = isNotEmpty(schema.getAggregatedGroups());
Expand Down
11 changes: 11 additions & 0 deletions core/store/src/test/java/uk/gov/gchq/gaffer/store/StoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
import uk.gov.gchq.gaffer.store.operation.declaration.OperationDeclaration;
import uk.gov.gchq.gaffer.store.operation.declaration.OperationDeclarations;
import uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler;
import uk.gov.gchq.gaffer.store.operation.handler.GetTraitsHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OperationHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler;
import uk.gov.gchq.gaffer.store.operation.handler.export.set.ExportToSetHandler;
Expand Down Expand Up @@ -1152,6 +1153,11 @@ protected OperationHandler<AddElements> getAddElementsHandler() {
return addElementsHandler;
}

@Override
protected OutputOperationHandler<GetTraits, Set<StoreTrait>> getGetTraitsHandler() {
return new GetTraitsHandler(traits);
}

@Override
protected Object doUnhandledOperation(final Operation operation, final Context context) {
doUnhandledOperationCalls.add(operation);
Expand Down Expand Up @@ -1247,6 +1253,11 @@ protected OperationHandler<AddElements> getAddElementsHandler() {
return addElementsHandler;
}

@Override
protected OutputOperationHandler<GetTraits, Set<StoreTrait>> getGetTraitsHandler() {
return new GetTraitsHandler(traits);
}

@Override
protected Object doUnhandledOperation(final Operation operation, final Context context) {
doUnhandledOperationCalls.add(operation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import uk.gov.gchq.gaffer.store.StoreException;
import uk.gov.gchq.gaffer.store.StoreProperties;
import uk.gov.gchq.gaffer.store.StoreTrait;
import uk.gov.gchq.gaffer.store.operation.GetTraits;
import uk.gov.gchq.gaffer.store.operation.handler.GetTraitsHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OperationHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler;
import uk.gov.gchq.gaffer.store.schema.Schema;
Expand Down Expand Up @@ -107,6 +109,11 @@ protected OperationHandler<? extends AddElements> getAddElementsHandler() {
return null;
}

@Override
protected OutputOperationHandler<GetTraits, Set<StoreTrait>> getGetTraitsHandler() {
return new GetTraitsHandler(traits);
}

@Override
protected Class<? extends Serialiser> getRequiredParentSerialiserClass() {
return ToBytesSerialiser.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public void setUp() throws Exception {
public Set<StoreTrait> getTraits() {
return Sets.newHashSet(expectedTraits);
}
@Override
protected OutputOperationHandler<GetTraits, Set<StoreTrait>> getGetTraitsHandler() {
return new GetTraitsHandler(expectedTraits);
}
};
assertNotEquals(StoreTrait.ALL_TRAITS, expectedTraits);
string = new Schema.Builder().type(STRING, String.class).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import uk.gov.gchq.gaffer.store.StoreException;
import uk.gov.gchq.gaffer.store.StoreProperties;
import uk.gov.gchq.gaffer.store.StoreTrait;
import uk.gov.gchq.gaffer.store.operation.GetTraits;
import uk.gov.gchq.gaffer.store.operation.HasTrait;
import uk.gov.gchq.gaffer.store.schema.Schema;
import uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition;
Expand Down Expand Up @@ -63,6 +64,10 @@ public void setUp() throws Exception {
public Set<StoreTrait> getTraits() {
return Sets.newHashSet(expectedTraits);
}
@Override
protected OutputOperationHandler<GetTraits, Set<StoreTrait>> getGetTraitsHandler() {
return new GetTraitsHandler(expectedTraits);
}
};
assertNotEquals(StoreTrait.ALL_TRAITS, expectedTraits);
string = new Schema.Builder().type(STRING, String.class).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser;
import uk.gov.gchq.gaffer.store.Store;
import uk.gov.gchq.gaffer.store.StoreTrait;
import uk.gov.gchq.gaffer.store.operation.GetTraits;

import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -61,6 +62,11 @@ protected OperationHandler<? extends AddElements> getAddElementsHandler() {
return null;
}

@Override
protected OutputOperationHandler<GetTraits, Set<StoreTrait>> getGetTraitsHandler() {
return new GetTraitsHandler(new HashSet<>(0));
}

@Override
protected Class<? extends Serialiser> getRequiredParentSerialiserClass() {
return ToBytesSerialiser.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
import uk.gov.gchq.gaffer.store.StoreException;
import uk.gov.gchq.gaffer.store.StoreProperties;
import uk.gov.gchq.gaffer.store.StoreTrait;
import uk.gov.gchq.gaffer.store.operation.GetTraits;
import uk.gov.gchq.gaffer.store.operation.handler.GetTraitsHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OperationHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler;
import uk.gov.gchq.gaffer.store.schema.Schema;
Expand Down Expand Up @@ -395,6 +397,11 @@ protected OperationHandler<? extends AddElements> getAddElementsHandler() {
return new AddElementsHandler();
}

@Override
protected OutputOperationHandler<GetTraits, Set<StoreTrait>> getGetTraitsHandler() {
return new GetTraitsHandler(TRAITS);
}

@Override
public Set<StoreTrait> getTraits() {
return TRAITS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ protected void addAdditionalOperationHandlers() {
addOperationHandler(RemoveGraph.class, new FederatedRemoveGraphHandler());

addOperationHandler(FederatedOperationChain.class, new FederatedOperationChainHandler());
addOperationHandler(GetTraits.class, new FederatedGetTraitsHandler());
addOperationHandler(GetAllGraphInfo.class, new FederatedGetAllGraphInfoHandler());
addOperationHandler(ChangeGraphAccess.class, new FederatedChangeGraphAccessHandler());
addOperationHandler(ChangeGraphId.class, new FederatedChangeGraphIdHandler());
Expand Down Expand Up @@ -442,6 +441,11 @@ protected OperationHandler<? extends AddElements> getAddElementsHandler() {
return (OperationHandler) new FederatedOperationHandler();
}

@Override
protected OutputOperationHandler<GetTraits, Set<StoreTrait>> getGetTraitsHandler() {
return new FederatedGetTraitsHandler();
}

@Override
protected Class<? extends Serialiser> getRequiredParentSerialiserClass() {
return Serialiser.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import uk.gov.gchq.gaffer.store.StoreTrait;
import uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary;
import uk.gov.gchq.gaffer.store.operation.GetTraits;
import uk.gov.gchq.gaffer.store.operation.handler.GetTraitsHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OperationHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler;
import uk.gov.gchq.gaffer.store.schema.Schema;
Expand Down Expand Up @@ -287,6 +288,11 @@ protected OperationHandler<? extends AddElements> getAddElementsHandler() {
return null;
}

@Override
protected OutputOperationHandler<GetTraits, Set<StoreTrait>> getGetTraitsHandler() {
return new GetTraitsHandler(STORE_TRAITS);
}

@Override
protected Class<? extends Serialiser> getRequiredParentSerialiserClass() {
return null;
Expand All @@ -301,6 +307,11 @@ public static class TestStoreAltImpl extends TestStoreImpl {
public Set<StoreTrait> getTraits() {
return STORE_TRAITS;
}

@Override
protected OutputOperationHandler<GetTraits, Set<StoreTrait>> getGetTraitsHandler() {
return new GetTraitsHandler(STORE_TRAITS);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import uk.gov.gchq.gaffer.store.StoreException;
import uk.gov.gchq.gaffer.store.StoreProperties;
import uk.gov.gchq.gaffer.store.StoreTrait;
import uk.gov.gchq.gaffer.store.operation.GetTraits;
import uk.gov.gchq.gaffer.store.operation.handler.GetTraitsHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OperationHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler;
import uk.gov.gchq.gaffer.store.operation.handler.job.GetAllJobDetailsHandler;
Expand Down Expand Up @@ -152,6 +154,11 @@ protected OperationHandler<? extends AddElements> getAddElementsHandler() {
return new AddElementsHandler();
}

@Override
protected OutputOperationHandler<GetTraits, Set<StoreTrait>> getGetTraitsHandler() {
return new GetTraitsHandler(TRAITS);
}

@Override
protected Class<? extends Serialiser> getRequiredParentSerialiserClass() {
return Serialiser.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
package uk.gov.gchq.gaffer.mapstore;

import uk.gov.gchq.gaffer.store.StoreTrait;
import uk.gov.gchq.gaffer.store.operation.GetTraits;
import uk.gov.gchq.gaffer.store.operation.handler.GetTraitsHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler;

import java.util.HashSet;
import java.util.Set;
Expand All @@ -32,4 +35,9 @@ public class SingleUseMapStoreWithoutVisibilitySupport extends SingleUseMapStore
public Set<StoreTrait> getTraits() {
return TRAITS;
}

@Override
protected OutputOperationHandler<GetTraits, Set<StoreTrait>> getGetTraitsHandler() {
return new GetTraitsHandler(TRAITS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
import uk.gov.gchq.gaffer.store.StoreProperties;
import uk.gov.gchq.gaffer.store.StoreTrait;
import uk.gov.gchq.gaffer.store.TypeReferenceStoreImpl;
import uk.gov.gchq.gaffer.store.operation.GetTraits;
import uk.gov.gchq.gaffer.store.operation.handler.GetTraitsHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OperationHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler;
import uk.gov.gchq.gaffer.store.schema.Schema;
Expand Down Expand Up @@ -323,6 +325,15 @@ protected OperationHandler<? extends AddElements> getAddElementsHandler() {
return null;
}

@Override
protected OutputOperationHandler<GetTraits, Set<StoreTrait>> getGetTraitsHandler() {
try {
return new GetTraitsHandler(fetchTraits());
} catch (final StoreException e) {
throw new GafferRuntimeException(e.getMessage(), e);
}
}

@Override
protected OperationHandler<? extends OperationChain<?>> getOperationChainHandler() {
return new uk.gov.gchq.gaffer.proxystore.operation.handler.OperationChainHandler<>(opChainValidator, opChainOptimisers);
Expand Down

0 comments on commit 28e9411

Please sign in to comment.