use of uk.gov.gchq.gaffer.serialisation.Serialisation in project Gaffer by gchq.
the class SchemaTest method shouldMergeDifferentSchemasOppositeWayAround.
@Test
public void shouldMergeDifferentSchemasOppositeWayAround() {
// Given
final String type1 = "type1";
final String type2 = "type2";
final Serialisation vertexSerialiser = mock(Serialisation.class);
final Schema schema1 = new Schema.Builder().edge(TestGroups.EDGE).entity(TestGroups.ENTITY).vertexSerialiser(vertexSerialiser).type(type1, Integer.class).visibilityProperty(TestPropertyNames.VISIBILITY).build();
final Schema schema2 = new Schema.Builder().entity(TestGroups.ENTITY_2).edge(TestGroups.EDGE_2).type(type2, String.class).build();
// When
final Schema mergedSchema = new Schema.Builder().merge(schema2).merge(schema1).build();
// Then
assertEquals(2, mergedSchema.getEdges().size());
assertNotNull(mergedSchema.getEdge(TestGroups.EDGE));
assertNotNull(mergedSchema.getEdge(TestGroups.EDGE_2));
assertEquals(2, mergedSchema.getEntities().size());
assertNotNull(mergedSchema.getEntity(TestGroups.ENTITY));
assertNotNull(mergedSchema.getEntity(TestGroups.ENTITY_2));
assertEquals(Integer.class, mergedSchema.getType(type1).getClazz());
assertEquals(String.class, mergedSchema.getType(type2).getClazz());
assertSame(vertexSerialiser, mergedSchema.getVertexSerialiser());
assertEquals(TestPropertyNames.VISIBILITY, mergedSchema.getVisibilityProperty());
}
use of uk.gov.gchq.gaffer.serialisation.Serialisation in project Gaffer by gchq.
the class SchemaTest method shouldMergeDifferentSchemas.
@Test
public void shouldMergeDifferentSchemas() {
// Given
final String type1 = "type1";
final String type2 = "type2";
final Serialisation vertexSerialiser = mock(Serialisation.class);
final Schema schema1 = new Schema.Builder().edge(TestGroups.EDGE).entity(TestGroups.ENTITY).vertexSerialiser(vertexSerialiser).type(type1, Integer.class).visibilityProperty(TestPropertyNames.VISIBILITY).build();
final Schema schema2 = new Schema.Builder().entity(TestGroups.ENTITY_2).edge(TestGroups.EDGE_2).type(type2, String.class).build();
// When
final Schema mergedSchema = new Schema.Builder().merge(schema1).merge(schema2).build();
// Then
assertEquals(2, mergedSchema.getEdges().size());
assertNotNull(mergedSchema.getEdge(TestGroups.EDGE));
assertNotNull(mergedSchema.getEdge(TestGroups.EDGE_2));
assertEquals(2, mergedSchema.getEntities().size());
assertNotNull(mergedSchema.getEntity(TestGroups.ENTITY));
assertNotNull(mergedSchema.getEntity(TestGroups.ENTITY_2));
assertEquals(Integer.class, mergedSchema.getType(type1).getClazz());
assertEquals(String.class, mergedSchema.getType(type2).getClazz());
assertSame(vertexSerialiser, mergedSchema.getVertexSerialiser());
assertEquals(TestPropertyNames.VISIBILITY, mergedSchema.getVisibilityProperty());
}
use of uk.gov.gchq.gaffer.serialisation.Serialisation in project Gaffer by gchq.
the class Store method validateSchemas.
public void validateSchemas() {
boolean valid = schema.validate();
final HashMap<String, SchemaElementDefinition> schemaElements = new HashMap<>();
schemaElements.putAll(getSchema().getEdges());
schemaElements.putAll(getSchema().getEntities());
for (final Entry<String, SchemaElementDefinition> schemaElementDefinitionEntry : schemaElements.entrySet()) {
for (final String propertyName : schemaElementDefinitionEntry.getValue().getProperties()) {
Class propertyClass = schemaElementDefinitionEntry.getValue().getPropertyClass(propertyName);
Serialisation serialisation = schemaElementDefinitionEntry.getValue().getPropertyTypeDef(propertyName).getSerialiser();
if (null == serialisation) {
valid = false;
LOGGER.error("Could not find a serialiser for property '" + propertyName + "' in the group '" + schemaElementDefinitionEntry.getKey() + "'.");
} else if (!serialisation.canHandle(propertyClass)) {
valid = false;
LOGGER.error("Schema serialiser (" + serialisation.getClass().getName() + ") for property '" + propertyName + "' in the group '" + schemaElementDefinitionEntry.getKey() + "' cannot handle property found in the schema");
}
}
}
if (!valid) {
throw new SchemaException("Schema is not valid. Check the logs for more information.");
}
}
use of uk.gov.gchq.gaffer.serialisation.Serialisation in project Gaffer by gchq.
the class SchemaOptimiser method getDefaultVertexSerialiser.
private Serialisation getDefaultVertexSerialiser(final Schema schema, final boolean isStoreOrdered) {
if (null != schema.getVertexSerialiser()) {
return schema.getVertexSerialiser();
}
final Set<Class<?>> vertexClasses = new HashSet<>();
for (final SchemaEntityDefinition definition : schema.getEntities().values()) {
vertexClasses.add(definition.getIdentifierClass(IdentifierType.VERTEX));
}
for (final SchemaEdgeDefinition definition : schema.getEdges().values()) {
vertexClasses.add(definition.getIdentifierClass(IdentifierType.SOURCE));
vertexClasses.add(definition.getIdentifierClass(IdentifierType.DESTINATION));
}
vertexClasses.remove(null);
if (!vertexClasses.isEmpty()) {
Serialisation serialiser = null;
if (vertexClasses.size() == 1) {
serialiser = serialisationFactory.getSerialiser(vertexClasses.iterator().next(), isStoreOrdered);
} else {
for (final Class<?> clazz : vertexClasses) {
serialiser = serialisationFactory.getSerialiser(clazz, isStoreOrdered);
boolean canHandlerAll = true;
for (final Class<?> clazz2 : vertexClasses) {
if (!serialiser.canHandle(clazz2)) {
canHandlerAll = false;
serialiser = null;
break;
}
}
if (canHandlerAll) {
break;
}
}
}
if (null == serialiser) {
throw new IllegalArgumentException("No default serialiser could be found that would support all vertex class types " + vertexClasses.toString() + ", please implement your own or change your vertex class types.");
}
if (serialiser instanceof JavaSerialiser) {
LOGGER.warn("Java serialisation is not recommended for vertex serialisation - it may cause aggregation to fail. Please implement your own or change your vertex class types.");
}
return serialiser;
}
return null;
}
use of uk.gov.gchq.gaffer.serialisation.Serialisation in project Gaffer by gchq.
the class SerialisationFactoryTest method shouldReturnOrderedSerialiserForAString.
@Test
public void shouldReturnOrderedSerialiserForAString() throws SerialisationException {
// Given
final SerialisationFactory factory = new SerialisationFactory();
final Class<?> clazz = String.class;
final boolean ordered = true;
// When
final Serialisation serialiser = factory.getSerialiser(clazz, ordered);
// Then
assertTrue(serialiser.canHandle(clazz));
assertEquals(StringSerialiser.class, serialiser.getClass());
}
Aggregations