public static Stream<? extends Thing> allInstancesFrom(GraknTx graph) { return graph.admin().getMetaConcept().instances(); }
@Override protected Relationship generateFromTx() { Stream<? extends Thing> things = tx().admin().getMetaConcept().instances(); Optional<Relationship> relation = things.flatMap(thing -> thing.relationships()).findAny(); if (relation.isPresent()) { return relation.get(); } else { // Give up and fall back to normal generator return genFromTx(Relations.class).generate(random, status); } } }
@Override protected final T generateFromTx() { T thing; S type = genFromTx(generatorClass).makeExcludeAbstractTypes().excludeMeta().generate(random, status); //noinspection unchecked Collection<T> instances = (Collection<T> ) type.instances().collect(toSet()); if (instances.isEmpty()) { thing = newInstance(type); } else { thing = random.choose(instances); } if(withResource && !thing.attributes().findAny().isPresent()){ //A new attribute type is created every time a attribute is lacking. //Existing attribute types and resources of those types are not used because we end up mutating the // the schema in strange ways. This approach is less complex but ensures everything has a attribute // without conflicting with the schema //Create a new attribute type AttributeType.DataType<?> dataType = gen(AttributeType.DataType.class); Label label = genFromTx(Labels.class).mustBeUnused().generate(random, status); AttributeType attributeType = tx().putAttributeType(label, dataType); //Create new attribute Attribute attribute = newResource(attributeType); //Link everything together type.has(attributeType); thing.has(attribute); } return thing; }