use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.
the class GraphDelegate method resolveSchemaForGraph.
protected Schema resolveSchemaForGraph(final Store store, final Schema schema, final List<String> parentSchemaIds, final Pair<Schema, StoreProperties> existingGraphPair) {
Schema resultSchema;
if (null != existingGraphPair) {
// If there is an existing graph then ignore any user provided schemas and just use the existing schema
resultSchema = existingGraphPair.getFirst();
} else {
final GraphLibrary graphLibrary = store.getGraphLibrary();
resultSchema = (null == graphLibrary) ? schema : graphLibrary.resolveSchema(schema, parentSchemaIds);
}
return resultSchema;
}
use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.
the class ExportToOtherAuthorisedGraphHandlerTest method shouldCreateGraphWithParentSchemaIdAndStorePropertiesIdAndAuths.
@Test
public void shouldCreateGraphWithParentSchemaIdAndStorePropertiesIdAndAuths(@TempDir Path tmpPath) {
// Given
GraphLibrary graphLibrary = new FileGraphLibrary(tmpPath.toString());
Schema schema1 = new Schema.Builder().build();
graphLibrary.addOrUpdate(GRAPH_ID + 1, SCHEMA_ID, schema, STORE_PROPS_ID, storeProperties);
graphLibrary.addSchema(SCHEMA_ID_1, schema1);
given(store.getGraphLibrary()).willReturn(graphLibrary);
List<String> opAuths = Lists.newArrayList("auth1");
idAuths.put(GRAPH_ID + 2, opAuths);
idAuths.put(SCHEMA_ID_1, opAuths);
idAuths.put(STORE_PROPS_ID, opAuths);
final ExportToOtherAuthorisedGraph export = new ExportToOtherAuthorisedGraph.Builder().graphId(GRAPH_ID + 2).parentSchemaIds(SCHEMA_ID_1).parentStorePropertiesId(STORE_PROPS_ID).build();
// When
Graph graph = createGraph(export);
// Then
assertEquals(GRAPH_ID + 2, graph.getGraphId());
assertEquals(schema1, graph.getSchema());
assertEquals(storeProperties, graph.getStoreProperties());
}
use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.
the class ExportToOtherAuthorisedGraphHandlerTest method shouldThrowExceptionWhenExportingToSameGraph.
@Test
public void shouldThrowExceptionWhenExportingToSameGraph(@TempDir Path tmpPath) {
GraphLibrary graphLibrary = new FileGraphLibrary(tmpPath.toString());
// Given
given(store.getGraphLibrary()).willReturn(graphLibrary);
final ExportToOtherAuthorisedGraph export = new ExportToOtherAuthorisedGraph.Builder().graphId(GRAPH_ID).build();
// When / Then
assertThatIllegalArgumentException().isThrownBy(() -> createGraph(export)).withMessageContaining("Cannot export to the same Graph");
}
use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.
the class ExportToOtherAuthorisedGraphHandlerTest method shouldCreateGraphWithParentSchemaIdAndStorePropertiesIdAndNoStorePropsAuths.
@Test
public void shouldCreateGraphWithParentSchemaIdAndStorePropertiesIdAndNoStorePropsAuths(@TempDir Path tmpPath) {
GraphLibrary graphLibrary = new FileGraphLibrary(tmpPath.toString());
// Given
Schema schema1 = new Schema.Builder().build();
graphLibrary.addOrUpdate(GRAPH_ID + 1, SCHEMA_ID, schema, STORE_PROPS_ID, storeProperties);
graphLibrary.addSchema(SCHEMA_ID_1, schema1);
given(store.getGraphLibrary()).willReturn(graphLibrary);
List<String> opAuths = Lists.newArrayList("auth1");
idAuths.put(GRAPH_ID + 2, opAuths);
idAuths.put(SCHEMA_ID_1, opAuths);
final ExportToOtherAuthorisedGraph export = new ExportToOtherAuthorisedGraph.Builder().graphId(GRAPH_ID + 2).parentSchemaIds(SCHEMA_ID_1).parentStorePropertiesId(STORE_PROPS_ID).build();
// When / Then
assertThatIllegalArgumentException().isThrownBy(() -> createGraph(export)).withMessageContaining("User is not authorised to export using storePropertiesId");
}
use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.
the class ExportToOtherAuthorisedGraphHandlerTest method shouldThrowExceptionWithParentSchemaIdAndStorePropertiesIdAndNoGraphAuths.
@Test
public void shouldThrowExceptionWithParentSchemaIdAndStorePropertiesIdAndNoGraphAuths(@TempDir Path tmpPath) {
GraphLibrary graphLibrary = new FileGraphLibrary(tmpPath.toString());
// Given
Schema schema1 = new Schema.Builder().build();
graphLibrary.addOrUpdate(GRAPH_ID + 1, SCHEMA_ID, schema, STORE_PROPS_ID, storeProperties);
graphLibrary.addSchema(SCHEMA_ID_1, schema1);
given(store.getGraphLibrary()).willReturn(graphLibrary);
List<String> opAuths = Lists.newArrayList("auth1");
idAuths.put(SCHEMA_ID_1, opAuths);
idAuths.put(STORE_PROPS_ID, opAuths);
final ExportToOtherAuthorisedGraph export = new ExportToOtherAuthorisedGraph.Builder().graphId(GRAPH_ID + 2).parentSchemaIds(SCHEMA_ID_1).parentStorePropertiesId(STORE_PROPS_ID).build();
// When / Then
assertThatIllegalArgumentException().isThrownBy(() -> createGraph(export)).withMessageContaining("User is not authorised to export using graphId");
}
Aggregations