use of uk.gov.gchq.gaffer.store.schema.TypeDefinition 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.store.schema.TypeDefinition 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.store.schema.TypeDefinition in project Gaffer by gchq.
the class ElementSerialisation method getPropertiesFromColumnQualifier.
public Properties getPropertiesFromColumnQualifier(final String group, final byte[] bytes) throws SerialisationException {
final SchemaElementDefinition elementDefinition = schema.getElement(group);
if (null == elementDefinition) {
throw new SerialisationException("No SchemaElementDefinition found for group " + group + ", is this group in your schema or do your table iterators need updating?");
}
final Properties properties = new Properties();
if (null == bytes || bytes.length == 0) {
return properties;
}
int carriage = CompactRawSerialisationUtils.decodeVIntSize(bytes[0]) + Bytes.toBytes(group).length;
final int arrayLength = bytes.length;
final Iterator<String> propertyNames = elementDefinition.getGroupBy().iterator();
while (propertyNames.hasNext() && carriage < arrayLength) {
final String propertyName = propertyNames.next();
final TypeDefinition typeDefinition = elementDefinition.getPropertyTypeDef(propertyName);
final ToBytesSerialiser serialiser = (null != typeDefinition) ? (ToBytesSerialiser) typeDefinition.getSerialiser() : null;
if (null != serialiser) {
final int numBytesForLength = CompactRawSerialisationUtils.decodeVIntSize(bytes[carriage]);
int currentPropLength;
try {
// this value is never greater than int.
currentPropLength = (int) CompactRawSerialisationUtils.readLong(bytes, carriage);
} catch (final SerialisationException e) {
throw new SerialisationException("Exception reading length of property");
}
carriage += numBytesForLength;
if (currentPropLength > 0) {
try {
properties.put(propertyName, serialiser.deserialise(bytes, carriage, currentPropLength));
carriage += currentPropLength;
} catch (final SerialisationException e) {
throw new SerialisationException("Failed to deserialise property " + propertyName, e);
}
} else {
try {
properties.put(propertyName, serialiser.deserialiseEmpty());
} catch (final SerialisationException e) {
throw new SerialisationException("Failed to deserialise property " + propertyName, e);
}
}
}
}
return properties;
}
Aggregations