public static <T> void putResource(Thing thing, AttributeType<T> attributeType, T resource) { Attribute attributeInstance = attributeType.create(resource); thing.has(attributeInstance); }
@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; }