use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.
the class DoublesUnionSerialiserTest method testSerialiser.
private void testSerialiser(final DoublesUnion union) {
final double quantile1 = union.getResult().getQuantile(0.5D);
final byte[] unionSerialised;
try {
unionSerialised = SERIALISER.serialise(union);
} catch (final SerialisationException exception) {
fail("A SerialisationException occurred");
return;
}
final DoublesUnion unionDeserialised;
try {
unionDeserialised = SERIALISER.deserialise(unionSerialised);
} catch (final SerialisationException exception) {
fail("A SerialisationException occurred");
return;
}
assertEquals(quantile1, unionDeserialised.getResult().getQuantile(0.5D), DELTA);
}
use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.
the class ProxyStore method handleResponse.
protected <OUTPUT> OUTPUT handleResponse(final Response response, final TypeReference<OUTPUT> outputTypeReference) throws StoreException {
final String outputJson = response.hasEntity() ? response.readEntity(String.class) : null;
if (200 != response.getStatus() && 204 != response.getStatus()) {
LOGGER.warn("Gaffer bad status " + response.getStatus());
LOGGER.warn("Detail: " + outputJson);
throw new StoreException("Delegate Gaffer store returned status: " + response.getStatus() + ". Response content was: " + outputJson);
}
OUTPUT output = null;
if (null != outputJson) {
try {
output = deserialise(outputJson, outputTypeReference);
} catch (final SerialisationException e) {
throw new StoreException(e.getMessage(), e);
}
}
return output;
}
use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.
the class AbstractCoreKeyAccumuloElementConverter method getPropertiesFromColumnVisibility.
@Override
public Properties getPropertiesFromColumnVisibility(final String group, final byte[] columnVisibility) throws AccumuloElementConversionException {
final Properties properties = new Properties();
final SchemaElementDefinition elementDefinition = schema.getElement(group);
if (null == elementDefinition) {
throw new AccumuloElementConversionException("No SchemaElementDefinition found for group " + group + ", is this group in your schema or do your table iterators need updating?");
}
if (null != schema.getVisibilityProperty()) {
final TypeDefinition propertyDef = elementDefinition.getPropertyTypeDef(schema.getVisibilityProperty());
if (null != propertyDef) {
final Serialisation serialiser = propertyDef.getSerialiser();
try {
if (columnVisibility == null || columnVisibility.length == 0) {
final Object value = serialiser.deserialiseEmptyBytes();
if (value != null) {
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.exception.SerialisationException in project Gaffer by gchq.
the class ByteEntityRangeFactory method getRange.
@Override
protected <T extends GetElementsOperation<?, ?>> List<Range> getRange(final Object vertex, final T operation, final IncludeEdgeType includeEdgesParam) throws RangeFactoryException {
final IncludeIncomingOutgoingType inOutType = operation.getIncludeIncomingOutGoing();
final IncludeEdgeType includeEdges;
final boolean includeEntities;
if (SeedMatchingType.EQUAL.equals(operation.getSeedMatching())) {
includeEdges = IncludeEdgeType.NONE;
includeEntities = true;
} else {
includeEdges = includeEdgesParam;
includeEntities = operation.isIncludeEntities();
}
byte[] serialisedVertex;
try {
serialisedVertex = ByteArrayEscapeUtils.escape(schema.getVertexSerialiser().serialise(vertex));
} catch (final SerialisationException e) {
throw new RangeFactoryException("Failed to serialise identifier", e);
}
if (!includeEntities && includeEdges == IncludeEdgeType.NONE) {
throw new IllegalArgumentException("Need to include either Entities or Edges or both when getting Range");
}
if (includeEdges == IncludeEdgeType.NONE) {
// return only entities
return Collections.singletonList(new Range(getEntityKey(serialisedVertex, false), true, getEntityKey(serialisedVertex, true), true));
} else {
if (includeEntities) {
if (includeEdges == IncludeEdgeType.DIRECTED) {
// return onlyDirectedEdges and entities
if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
return Arrays.asList(new Range(getEntityKey(serialisedVertex, false), true, getEntityKey(serialisedVertex, true), true), new Range(getDirectedEdgeKeyDestinationFirst(serialisedVertex, false), true, getDirectedEdgeKeyDestinationFirst(serialisedVertex, true), true));
} else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
return Collections.singletonList(new Range(getEntityKey(serialisedVertex, false), true, getDirectedEdgeKeySourceFirst(serialisedVertex, true), true));
} else {
return Collections.singletonList(new Range(getEntityKey(serialisedVertex, false), false, getDirectedEdgeKeyDestinationFirst(serialisedVertex, true), false));
}
} else if (includeEdges == IncludeEdgeType.UNDIRECTED) {
// Entity only range and undirected only range
return Arrays.asList(new Range(getUnDirectedEdgeKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true), new Range(getEntityKey(serialisedVertex, false), true, getEntityKey(serialisedVertex, true), true));
} else {
// Return everything
if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
return Arrays.asList(new Range(getEntityKey(serialisedVertex, false), true, getEntityKey(serialisedVertex, true), true), new Range(getDirectedEdgeKeyDestinationFirst(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
} else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
return Arrays.asList(new Range(getEntityKey(serialisedVertex, false), true, getDirectedEdgeKeySourceFirst(serialisedVertex, true), true), new Range(getUnDirectedEdgeKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
} else {
return Collections.singletonList(new Range(getEntityKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
}
}
} else if (includeEdges == IncludeEdgeType.DIRECTED) {
if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
return Collections.singletonList(new Range(getDirectedEdgeKeyDestinationFirst(serialisedVertex, false), true, getDirectedEdgeKeyDestinationFirst(serialisedVertex, true), true));
} else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
return Collections.singletonList(new Range(getDirectedEdgeKeySourceFirst(serialisedVertex, false), true, getDirectedEdgeKeySourceFirst(serialisedVertex, true), true));
} else {
return Collections.singletonList(new Range(getDirectedEdgeKeySourceFirst(serialisedVertex, false), true, getDirectedEdgeKeyDestinationFirst(serialisedVertex, true), true));
}
} else if (includeEdges == IncludeEdgeType.UNDIRECTED) {
return Collections.singletonList(new Range(getUnDirectedEdgeKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
} else {
// return all edges
if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
return Collections.singletonList(new Range(getDirectedEdgeKeyDestinationFirst(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
} else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
return Arrays.asList(new Range(getDirectedEdgeKeySourceFirst(serialisedVertex, false), true, getDirectedEdgeKeySourceFirst(serialisedVertex, true), true), new Range(getUnDirectedEdgeKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
} else {
final Pair<Key> keys = getAllEdgeOnlyKeys(serialisedVertex);
return Collections.singletonList(new Range(keys.getFirst(), false, keys.getSecond(), false));
}
}
}
}
use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.
the class ClassicRangeFactory method getKeyFromEdgeSeed.
@Override
protected <T extends GetElementsOperation<?, ?>> Key getKeyFromEdgeSeed(final EdgeSeed seed, final T operation, final boolean endKey) throws RangeFactoryException {
final byte directionFlag1 = seed.isDirected() ? (operation.getIncludeIncomingOutGoing() == IncludeIncomingOutgoingType.INCOMING ? ClassicBytePositions.INCORRECT_WAY_DIRECTED_EDGE : ClassicBytePositions.CORRECT_WAY_DIRECTED_EDGE) : ClassicBytePositions.UNDIRECTED_EDGE;
final Serialisation vertexSerialiser = schema.getVertexSerialiser();
// Serialise source and destination to byte arrays, escaping if
// necessary
byte[] source;
try {
source = ByteArrayEscapeUtils.escape(vertexSerialiser.serialise(seed.getSource()));
} catch (final SerialisationException e) {
throw new RangeFactoryException("Failed to serialise Edge Source", e);
}
byte[] destination;
try {
destination = ByteArrayEscapeUtils.escape(vertexSerialiser.serialise(seed.getDestination()));
} catch (final SerialisationException e) {
throw new RangeFactoryException("Failed to serialise Edge Destination", e);
}
// Length of row key is the length of the source
// plus the length of the destination
// plus one for the delimiter in between the source and destination
// plus one for the delimiter in between the destination and the direction flag
// plus one for the direction flag at the end.
byte[] key;
if (endKey) {
key = new byte[source.length + destination.length + 4];
key[key.length - 3] = ByteArrayEscapeUtils.DELIMITER;
key[key.length - 2] = directionFlag1;
key[key.length - 1] = ByteArrayEscapeUtils.DELIMITER_PLUS_ONE;
} else {
key = new byte[source.length + destination.length + 3];
key[key.length - 2] = ByteArrayEscapeUtils.DELIMITER;
key[key.length - 1] = directionFlag1;
}
// Create first key: source DELIMITER destination DELIMITER (CORRECT_WAY_DIRECTED_EDGE or UNDIRECTED_EDGE)
// Here if we desire an EdgeID we and the user has asked for incoming
// edges only for related items, we put the destination first so we find the flipped edge's key,
// this key will pass the filter iterators check for incoming edges, but
// the result will be flipped back to the correct edge on the client end conversion
// Simply put when looking up an EDGE ID that ID counts as both incoming
// and outgoing so we use the reversed key when looking up incoming.
byte[] firstValue;
byte[] secondValue;
if (operation.getIncludeIncomingOutGoing() == IncludeIncomingOutgoingType.INCOMING) {
firstValue = destination;
secondValue = source;
} else {
firstValue = source;
secondValue = destination;
}
System.arraycopy(firstValue, 0, key, 0, firstValue.length);
key[firstValue.length] = ByteArrayEscapeUtils.DELIMITER;
System.arraycopy(secondValue, 0, key, firstValue.length + 1, secondValue.length);
return new Key(key, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, Long.MAX_VALUE);
}
Aggregations