Search in sources :

Example 1 with Serialiser

use of uk.gov.gchq.gaffer.serialisation.Serialiser in project gaffer-doc by gchq.

the class PropertiesWalkthrough method listToBytesSerialisers.

protected boolean listToBytesSerialisers(final Class<?> clazz) {
    final List<Class> toBytesSerialiserClasses = new ArrayList<>();
    for (final Serialiser serialise : TO_BYTES_SERIALISERS) {
        if (serialise.canHandle(clazz)) {
            toBytesSerialiserClasses.add(serialise.getClass());
        }
    }
    if (toBytesSerialiserClasses.contains(JavaSerialiser.class)) {
        if (toBytesSerialiserClasses.contains(AvroSerialiser.class)) {
            if (toBytesSerialiserClasses.size() > 2) {
                toBytesSerialiserClasses.remove(JavaSerialiser.class);
                toBytesSerialiserClasses.remove(AvroSerialiser.class);
            }
        } else {
            if (toBytesSerialiserClasses.size() > 1) {
                toBytesSerialiserClasses.remove(JavaSerialiser.class);
            }
        }
    } else if (toBytesSerialiserClasses.contains(AvroSerialiser.class)) {
        if (toBytesSerialiserClasses.size() > 1) {
            toBytesSerialiserClasses.remove(AvroSerialiser.class);
        }
    }
    final List<String> toBytesSerialiserClassNames = new ArrayList<>();
    for (final Class toBytesSerialiserClass : toBytesSerialiserClasses) {
        toBytesSerialiserClassNames.add(WalkthroughStrSubstitutor.getJavaDocLink(toBytesSerialiserClass, false));
    }
    if (!toBytesSerialiserClasses.isEmpty()) {
        print(SERIALISERS_KEY, "\nTo Bytes Serialisers:");
        print(SERIALISERS_KEY, "\n- " + StringUtils.join(toBytesSerialiserClassNames, "\n- "));
    }
    return !toBytesSerialiserClasses.isEmpty();
}
Also used : Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) JavaSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) AvroSerialiser(uk.gov.gchq.gaffer.serialisation.AvroSerialiser) ArrayList(java.util.ArrayList) AvroSerialiser(uk.gov.gchq.gaffer.serialisation.AvroSerialiser)

Example 2 with Serialiser

use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.

the class MultiSerialiserStorage method canHandle.

/**
 * @param handleClass class to check
 * @return {@link ToBytesSerialiser#canHandle(Class)}
 * @see ToBytesSerialiser
 */
public boolean canHandle(final Class handleClass) {
    boolean rtn = false;
    final Byte key = classToKey.get(handleClass);
    if (null != key) {
        Serialiser serialiser = keyToSerialiser.get(key);
        rtn = null != serialiser && serialiser.canHandle(handleClass);
    }
    return rtn;
}
Also used : ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser)

Example 3 with Serialiser

use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.

the class SchemaTest method shouldBuildSchema.

@Test
public void shouldBuildSchema() {
    // Given
    final Serialiser vertexSerialiser = mock(Serialiser.class);
    // When
    final Schema schema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition()).entity(TestGroups.ENTITY, new SchemaEntityDefinition()).entity(TestGroups.ENTITY_2, new SchemaEntityDefinition()).edge(TestGroups.EDGE_2, new SchemaEdgeDefinition()).vertexSerialiser(vertexSerialiser).type(TestTypes.PROP_STRING, String.class).visibilityProperty(TestPropertyNames.VISIBILITY).config("key", "value").build();
    // Then
    assertEquals(2, schema.getEdges().size());
    assertNotNull(schema.getEdge(TestGroups.EDGE));
    assertNotNull(schema.getEdge(TestGroups.EDGE_2));
    assertEquals(2, schema.getEntities().size());
    assertNotNull(schema.getEntity(TestGroups.ENTITY));
    assertNotNull(schema.getEntity(TestGroups.ENTITY_2));
    assertEquals(String.class, schema.getType(TestTypes.PROP_STRING).getClazz());
    assertSame(vertexSerialiser, schema.getVertexSerialiser());
    assertEquals(TestPropertyNames.VISIBILITY, schema.getVisibilityProperty());
    assertEquals("value", schema.getConfig("key"));
}
Also used : RawLongSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawLongSerialiser) MapSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.MapSerialiser) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) JavaSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) StringToStringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.tostring.StringToStringSerialiser) Test(org.junit.jupiter.api.Test)

Example 4 with Serialiser

use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.

the class SchemaTest method shouldThrowExceptionWhenMergeSchemasWithConflictingVertexSerialiser.

@Test
public void shouldThrowExceptionWhenMergeSchemasWithConflictingVertexSerialiser() {
    // Given
    final Serialiser vertexSerialiser1 = new StringSerialiser();
    final Serialiser vertexSerialiser2 = new StringToStringSerialiser();
    final Schema schema1 = new Schema.Builder().vertexSerialiser(vertexSerialiser1).build();
    final Schema schema2 = new Schema.Builder().vertexSerialiser(vertexSerialiser2).build();
    // When / Then
    assertThatExceptionOfType(SchemaException.class).isThrownBy(() -> new Schema.Builder().merge(schema1).merge(schema2).build()).withMessageContaining("vertex serialiser");
}
Also used : StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) StringToStringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.tostring.StringToStringSerialiser) RawLongSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawLongSerialiser) MapSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.MapSerialiser) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) JavaSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) StringToStringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.tostring.StringToStringSerialiser) StringToStringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.tostring.StringToStringSerialiser) Test(org.junit.jupiter.api.Test)

Example 5 with Serialiser

use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.

the class AccumuloSerialisationFactoryTest method shouldReturnCustomSerialiserForCustomClass.

@Test
public void shouldReturnCustomSerialiserForCustomClass() throws SerialisationException {
    // Given
    final SerialisationFactory factory = new AccumuloSerialisationFactory();
    final Class<?> clazz = HyperLogLogPlus.class;
    // When
    final Serialiser serialiser = factory.getSerialiser(clazz);
    // Then
    assertTrue(serialiser.canHandle(clazz));
    assertEquals(HyperLogLogPlusSerialiser.class, serialiser.getClass());
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) HyperLogLogPlusSerialiser(uk.gov.gchq.gaffer.sketches.clearspring.cardinality.serialisation.HyperLogLogPlusSerialiser) SerialisationFactory(uk.gov.gchq.gaffer.store.SerialisationFactory) Test(org.junit.jupiter.api.Test)

Aggregations

Serialiser (uk.gov.gchq.gaffer.serialisation.Serialiser)28 Test (org.junit.jupiter.api.Test)18 JavaSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser)18 StringSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser)16 ToBytesSerialiser (uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser)10 BooleanSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.BooleanSerialiser)8 OrderedIntegerSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.ordered.OrderedIntegerSerialiser)8 RawDateSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDateSerialiser)8 RawDoubleSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDoubleSerialiser)8 RawFloatSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawFloatSerialiser)8 StringToStringSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.tostring.StringToStringSerialiser)6 MapSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.MapSerialiser)5 RawLongSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawLongSerialiser)5 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)4 Schema (uk.gov.gchq.gaffer.store.schema.Schema)4 ArrayList (java.util.ArrayList)3 JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)3 AvroSerialiser (uk.gov.gchq.gaffer.serialisation.AvroSerialiser)3 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)3 HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)2