Skip to content

Commit

Permalink
gh-2909 improved getting operation declarations json
Browse files Browse the repository at this point in the history
  • Loading branch information
GCHQDev404 committed Mar 3, 2023
1 parent d3d5aff commit c58059b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
10 changes: 0 additions & 10 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 @@ -199,7 +199,6 @@
*/
public abstract class Store {
private static final Logger LOGGER = LoggerFactory.getLogger(Store.class);
public static final String ADD_GRAPH_DECLARATIONS = "gaffer.federatedstore.addgraph.declarations";
private final Class<? extends Serialiser> requiredParentSerialiserClass;
private final Map<Class<? extends Operation>, OperationHandler> operationHandlers = new LinkedHashMap<>();
protected final List<OperationChainOptimiser> opChainOptimisers = new ArrayList<>();
Expand Down Expand Up @@ -1102,15 +1101,6 @@ private void addConfiguredOperationHandlers() {
addOperationHandler(definition.getOperation(), definition.getHandler());
}
}

if (properties.containsKey(ADD_GRAPH_DECLARATIONS)) {
final String json = properties.get(ADD_GRAPH_DECLARATIONS);
final OperationDeclarations operationDeclarations = OperationDeclarations.fromJson(json);
for (final OperationDeclaration definition : operationDeclarations.getOperations()) {
addOperationHandler(definition.getOperation(), definition.getHandler());
}
}

}

protected void startCacheServiceLoader(final StoreProperties properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class StoreProperties implements Cloneable {

public static final String STORE_PROPERTIES_CLASS = "gaffer.store.properties.class";
public static final String OPERATION_DECLARATIONS = "gaffer.store.operation.declarations";
public static final String OPERATION_DECLARATIONS_JSON = "gaffer.store.operation.declarations.json";

public static final String JOB_TRACKER_ENABLED = "gaffer.store.job.tracker.enabled";

Expand Down Expand Up @@ -275,18 +276,21 @@ public void merge(final StoreProperties properties) {
*/
@JsonIgnore
public OperationDeclarations getOperationDeclarations() {
OperationDeclarations declarations = null;
OperationDeclarations.Builder declarations = new OperationDeclarations.Builder();

final String declarationsPaths = get(StoreProperties.OPERATION_DECLARATIONS);
if (null != declarationsPaths) {
declarations = OperationDeclarations.fromPaths(declarationsPaths);
OperationDeclarations.fromPaths(declarationsPaths).getOperations()
.forEach(d -> declarations.declaration(d));
}

if (null == declarations) {
declarations = new OperationDeclarations.Builder().build();
if (containsKey(OPERATION_DECLARATIONS_JSON)) {
final String json = get(OPERATION_DECLARATIONS_JSON);
OperationDeclarations.fromJson(json).getOperations()
.forEach(d -> declarations.declaration(d));
}

return declarations;
return declarations.build();
}

public String getStoreClass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import static uk.gov.gchq.gaffer.federatedstore.FederatedGraphStorage.USER_IS_ATTEMPTING_TO_OVERWRITE;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.SCHEMA_EDGE_BASIC_JSON;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.loadSchemaFromJson;
import static uk.gov.gchq.gaffer.store.Store.ADD_GRAPH_DECLARATIONS;
import static uk.gov.gchq.gaffer.store.StoreProperties.OPERATION_DECLARATIONS_JSON;
import static uk.gov.gchq.gaffer.user.StoreUser.authUser;
import static uk.gov.gchq.gaffer.user.StoreUser.blankUser;
import static uk.gov.gchq.gaffer.user.StoreUser.testUser;
Expand Down Expand Up @@ -443,7 +443,7 @@ public void shouldAddGraphWithHandler() throws Exception {

final AccumuloProperties clone = PROPERTIES.clone();

clone.set(ADD_GRAPH_DECLARATIONS, new String(JSONSerialiser.serialise(new OperationDeclarations.Builder()
clone.set(OPERATION_DECLARATIONS_JSON, new String(JSONSerialiser.serialise(new OperationDeclarations.Builder()
.declaration(new OperationDeclaration.Builder()
.handler(new TestErrorHandler())
.operation(GetAllElements.class)
Expand Down

0 comments on commit c58059b

Please sign in to comment.