use of uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition in project Gaffer by gchq.
the class AbstractCoreKeyAccumuloElementConverter method getPropertiesFromColumnQualifier.
@Override
public Properties getPropertiesFromColumnQualifier(final String group, final byte[] bytes) throws AccumuloElementConversionException {
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?");
}
final Properties properties = new Properties();
if (bytes == null || bytes.length == 0) {
return properties;
}
int lastDelimiter = 0;
final int arrayLength = bytes.length;
long currentPropLength;
final Iterator<String> propertyNames = elementDefinition.getGroupBy().iterator();
while (propertyNames.hasNext() && lastDelimiter < arrayLength) {
final String propertyName = propertyNames.next();
final TypeDefinition typeDefinition = elementDefinition.getPropertyTypeDef(propertyName);
final Serialisation<?> serialiser = (typeDefinition != null) ? typeDefinition.getSerialiser() : null;
if (null != serialiser) {
final int numBytesForLength = CompactRawSerialisationUtils.decodeVIntSize(bytes[lastDelimiter]);
final byte[] length = new byte[numBytesForLength];
System.arraycopy(bytes, lastDelimiter, length, 0, numBytesForLength);
try {
currentPropLength = CompactRawSerialisationUtils.readLong(length);
} catch (final SerialisationException e) {
throw new AccumuloElementConversionException("Exception reading length of property", e);
}
lastDelimiter += numBytesForLength;
if (currentPropLength > 0) {
try {
properties.put(propertyName, serialiser.deserialise(Arrays.copyOfRange(bytes, lastDelimiter, lastDelimiter += currentPropLength)));
} catch (SerialisationException e) {
throw new AccumuloElementConversionException("Failed to deserialise property " + propertyName, e);
}
}
}
}
return properties;
}
use of uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition in project Gaffer by gchq.
the class ExamplesService method generateElements.
@Override
public GenerateElements generateElements() {
final GenerateElements<ExampleDomainObject> op = new GenerateElements<>(new ExampleDomainObjectGenerator());
final ArrayList<ExampleDomainObject> objs = new ArrayList<>();
if (hasEntities()) {
final SchemaElementDefinition entityDef = getSchema().getEntity(getAnEntityGroup());
objs.add(new ExampleDomainObject(getAnEntityGroup(), getExampleVertex(entityDef.getIdentifierClass(IdentifierType.VERTEX), 1)));
objs.add(new ExampleDomainObject(getAnEntityGroup(), getExampleVertex(entityDef.getIdentifierClass(IdentifierType.VERTEX), 2)));
}
if (hasEdges()) {
final SchemaElementDefinition edgeDef = getSchema().getEdge(getAnEdgeGroup());
objs.add(new ExampleDomainObject(getAnEdgeGroup(), getExampleVertex(edgeDef.getIdentifierClass(IdentifierType.SOURCE), 1), getExampleVertex(edgeDef.getIdentifierClass(IdentifierType.DESTINATION), 1), isAnEdgeDirected()));
}
op.setInput(objs);
populateOperation(op);
return op;
}
use of uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition in project Gaffer by gchq.
the class ValidatedElementsTest method setup.
@Before
public void setup() {
elements = new ArrayList<>();
filters = new ArrayList<>();
schema = mock(Schema.class);
for (int i = 0; i < 3; i++) {
elements.add(mock(Element.class));
filters.add(mock(ElementFilter.class));
final String group = "group " + i;
given(elements.get(i).getGroup()).willReturn(group);
given(filters.get(i).filter(elements.get(i))).willReturn(true);
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
given(schema.getElement(group)).willReturn(elementDef);
given(elementDef.getValidator(true)).willReturn(filters.get(i));
}
given(filters.get(1).filter(elements.get(1))).willReturn(false);
}
use of uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition in project Gaffer by gchq.
the class ValidateHandlerTest method shouldValidatedElements.
@Test
public void shouldValidatedElements() throws OperationException {
// Given
final ValidateHandler handler = new ValidateHandler();
final Store store = mock(Store.class);
final Validate validate = mock(Validate.class);
final Element elm1 = mock(Element.class);
final CloseableIterable<Element> elements = new WrappedCloseableIterable<>(Collections.singletonList(elm1));
final Schema schema = mock(Schema.class);
final Context context = new Context();
given(validate.getElements()).willReturn(elements);
given(validate.isSkipInvalidElements()).willReturn(false);
given(store.getSchema()).willReturn(schema);
final String group = "group";
given(elm1.getGroup()).willReturn(group);
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
final ElementFilter validator = mock(ElementFilter.class);
given(validator.filter(elm1)).willReturn(true);
given(elementDef.getValidator(true)).willReturn(validator);
given(schema.getElement(group)).willReturn(elementDef);
// When
final Iterable<Element> result = handler.doOperation(validate, context, store);
// Then
final Iterator<Element> itr = result.iterator();
final Element elm1Result = itr.next();
assertSame(elm1, elm1Result);
assertFalse(itr.hasNext());
}
use of uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition in project Gaffer by gchq.
the class ElementValidatorTest method shouldReturnTrueWhenSchemaValidateWithoutIsAWithValidElement.
@Test
public void shouldReturnTrueWhenSchemaValidateWithoutIsAWithValidElement() {
// Given
final Schema schema = mock(Schema.class);
final String group = TestGroups.EDGE;
final Element elm = mock(Element.class);
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
final ElementFilter filter = mock(ElementFilter.class);
final boolean includeIsA = false;
final ElementValidator validator = new ElementValidator(schema, includeIsA);
given(elm.getGroup()).willReturn(group);
given(schema.getElement(group)).willReturn(elementDef);
given(elementDef.getValidator(includeIsA)).willReturn(filter);
given(filter.filter(elm)).willReturn(true);
// When
final boolean isValid = validator.validate(elm);
// Then
assertTrue(isValid);
}
Aggregations