use of uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException in project Gaffer by gchq.
the class Gaffer1BloomElementFunctorTest method shouldTransformRangeWhenUsingRangeNotExact.
@Test
public void shouldTransformRangeWhenUsingRangeNotExact() {
try {
// Create SimpleEntity
final Entity simpleEntity = new Entity.Builder().group(TestGroups.ENTITY).vertex("1").build();
final Key key = elementConverter.getKeyFromEntity(simpleEntity);
final Range range = Range.exact(key.getRow());
final org.apache.hadoop.util.bloom.Key expectedBloomKey1 = new org.apache.hadoop.util.bloom.Key(ELEMENT_FUNCTOR.getVertexFromRangeKey(key.getRowData().getBackingArray()));
assertNotNull(ELEMENT_FUNCTOR.transform(range));
assertEquals(expectedBloomKey1, ELEMENT_FUNCTOR.transform(range));
} catch (final AccumuloElementConversionException e) {
fail("ConversionException " + e);
}
}
use of uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException in project Gaffer by gchq.
the class AbstractCoreKeyAccumuloElementConverter method getEdgeFromKey.
@SuppressWarnings("WeakerAccess")
protected Edge getEdgeFromKey(final Key key, final byte[] row, final boolean includeMatchedVertex) {
final byte[][] result = new byte[2][];
final EdgeDirection direction = getSourceAndDestinationFromRowKey(row, result);
final EdgeId.MatchedVertex matchedVertex;
if (!includeMatchedVertex) {
matchedVertex = null;
} else if (EdgeDirection.DIRECTED_REVERSED == direction) {
matchedVertex = EdgeId.MatchedVertex.DESTINATION;
} else {
matchedVertex = EdgeId.MatchedVertex.SOURCE;
}
final String group = getGroupFromColumnFamily(key.getColumnFamilyData().getBackingArray());
try {
final Edge edge = new Edge(group, ((ToBytesSerialiser) schema.getVertexSerialiser()).deserialise(result[0]), ((ToBytesSerialiser) schema.getVertexSerialiser()).deserialise(result[1]), direction.isDirected(), matchedVertex, null);
addPropertiesToElement(edge, key);
return edge;
} catch (final SerialisationException e) {
throw new AccumuloElementConversionException("Failed to re-create Edge from key", e);
}
}
use of uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException in project Gaffer by gchq.
the class AbstractCoreKeyAccumuloElementConverter method getEdgeId.
protected EdgeId getEdgeId(final byte[] row, final boolean includeMatchedVertex) {
final byte[][] result = new byte[2][];
final EdgeDirection direction = getSourceAndDestinationFromRowKey(row, result);
final EdgeId.MatchedVertex matchedVertex;
if (!includeMatchedVertex) {
matchedVertex = null;
} else if (EdgeDirection.DIRECTED_REVERSED == direction) {
matchedVertex = EdgeId.MatchedVertex.DESTINATION;
} else {
matchedVertex = EdgeId.MatchedVertex.SOURCE;
}
try {
return new EdgeSeed(((ToBytesSerialiser) schema.getVertexSerialiser()).deserialise(result[0]), ((ToBytesSerialiser) schema.getVertexSerialiser()).deserialise(result[1]), direction.isDirected(), matchedVertex);
} catch (final SerialisationException e) {
throw new AccumuloElementConversionException("Failed to create EdgeId from Accumulo row key", e);
}
}
use of uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException 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.accumulostore.key.exception.AccumuloElementConversionException 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;
}
Aggregations