use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project Gaffer by gchq.
the class MultiSerialiserStorageTest method checkBasicPut.
private void checkBasicPut() throws GafferCheckedException {
assertEquals((Object) BYTE, mss.getKeyFromValue(VALUE));
ToBytesSerialiser actualClassFromByte = mss.getSerialiserFromKey(BYTE);
assertNotNull(actualClassFromByte, "Byte key not found");
assertEquals(SERIALISER_CLASS, actualClassFromByte, "Wrong SerialiserClass returned for key");
ToBytesSerialiser actualClassFromValue = mss.getSerialiserFromValue(Integer.MAX_VALUE);
assertNotNull(actualClassFromValue, "Value class not found");
assertEquals(SERIALISER_CLASS, actualClassFromValue, "Wrong SerialiserClass returned for value class");
}
use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project Gaffer by gchq.
the class AbstractCoreKeyAccumuloElementConverter method addDeserialisedProperty.
private int addDeserialisedProperty(final byte[] bytes, final int carriage, final Properties properties, final SchemaElementDefinition elementDefinition, final String propertyName) throws SerialisationException {
int rtn = carriage;
final TypeDefinition typeDefinition = elementDefinition.getPropertyTypeDef(propertyName);
final ToBytesSerialiser serialiser = (null != typeDefinition) ? (ToBytesSerialiser) typeDefinition.getSerialiser() : null;
if (null != serialiser) {
final int numBytesForLength = CompactRawSerialisationUtils.decodeVIntSize(bytes[rtn]);
final int currentPropLength = getCurrentPropLength(bytes, rtn);
int from = rtn += numBytesForLength;
rtn += currentPropLength;
Object deserialisedObject = getDeserialisedObject(serialiser, bytes, from, currentPropLength);
properties.put(propertyName, deserialisedObject);
}
return rtn;
}
use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project Gaffer by gchq.
the class AbstractCoreKeyAccumuloElementConverter method getPropertiesFromColumnVisibility.
@Override
public Properties getPropertiesFromColumnVisibility(final String group, final byte[] columnVisibility) {
final Properties properties = new Properties();
final SchemaElementDefinition elementDefinition = getSchemaElementDefinition(group);
if (null != schema.getVisibilityProperty()) {
final TypeDefinition propertyDef = elementDefinition.getPropertyTypeDef(schema.getVisibilityProperty());
if (null != propertyDef) {
final ToBytesSerialiser serialiser = (ToBytesSerialiser) propertyDef.getSerialiser();
try {
if (null == columnVisibility || columnVisibility.length == 0) {
final Object value = serialiser.deserialiseEmpty();
if (null != value) {
properties.put(schema.getVisibilityProperty(), value);
}
} else {
properties.put(schema.getVisibilityProperty(), serialiser.deserialise(columnVisibility));
}
} catch (final SerialisationException e) {
throw new AccumuloElementConversionException(e.getMessage(), e);
}
}
}
return properties;
}
use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project Gaffer by gchq.
the class AbstractCoreKeyAccumuloElementConverter method buildColumnVisibility.
@Override
public byte[] buildColumnVisibility(final String group, final Properties properties) {
byte[] rtn = AccumuloStoreConstants.EMPTY_BYTES;
final SchemaElementDefinition elementDefinition = getSchemaElementDefinition(group);
if (null != schema.getVisibilityProperty()) {
final TypeDefinition propertyDef = elementDefinition.getPropertyTypeDef(schema.getVisibilityProperty());
if (null != propertyDef) {
final Object property = properties.get(schema.getVisibilityProperty());
final ToBytesSerialiser serialiser = (ToBytesSerialiser) propertyDef.getSerialiser();
if (null != property) {
try {
rtn = serialiser.serialise(property);
} catch (final SerialisationException e) {
throw new AccumuloElementConversionException(e.getMessage(), e);
}
} else {
rtn = serialiser.serialiseNull();
}
}
}
return rtn;
}
use of uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser in project Gaffer by gchq.
the class ClassicRangeFactory method getRange.
@Override
protected List<Range> getRange(final Object vertex, final GraphFilters operation, final boolean includeEdgesParam) throws RangeFactoryException {
final boolean includeEdges;
final boolean includeEntities;
final boolean seedEqual = operation instanceof SeedMatching && SeedMatchingType.EQUAL.equals(((SeedMatching) operation).getSeedMatching());
if (seedEqual) {
includeEdges = false;
includeEntities = true;
} else {
includeEdges = includeEdgesParam;
includeEntities = operation.getView().hasEntities();
}
byte[] serialisedVertex;
try {
serialisedVertex = ByteArrayEscapeUtils.escape(((ToBytesSerialiser) schema.getVertexSerialiser()).serialise(vertex));
} catch (final SerialisationException e) {
throw new RangeFactoryException("Failed to serialise identifier", e);
}
if (!includeEntities && !includeEdges) {
throw new IllegalArgumentException("Need to include either Entities or Edges or both when getting Range from a type and value");
}
if (includeEntities && includeEdges) {
return Collections.singletonList(getRange(serialisedVertex));
} else if (includeEntities) {
return Collections.singletonList(getEntityRangeFromVertex(serialisedVertex));
} else {
return Collections.singletonList(getEdgeRangeFromVertex(serialisedVertex));
}
}
Aggregations