use of org.hisp.dhis.dto.schemas.Schema in project dhis2-core by dhis2.
the class DataGenerator method generateObjectMatchingSchema.
public static JsonObject generateObjectMatchingSchema(List<SchemaProperty> schemaProperties) {
JsonObject objectBody = new JsonObject();
for (SchemaProperty prop : schemaProperties) {
JsonElement element;
if (prop.getPropertyType() == PropertyType.REFERENCE) {
List<SchemaProperty> referenceProperties = new SchemasActions().getRequiredProperties(prop.getName());
JsonObject referenceObject = generateObjectMatchingSchema(referenceProperties);
String uid = new RestApiActions(prop.getRelativeApiEndpoint()).post(referenceObject).extractUid();
referenceObject.addProperty("id", uid);
element = referenceObject;
} else if (prop.getPropertyType() == PropertyType.IDENTIFIER) {
if (!StringUtils.containsAny(prop.getName(), "id", "uid", "code")) {
Schema schema = new SchemasActions().getSchema(prop.getName());
JsonObject referenceObject = generateObjectMatchingSchema(schema.getRequiredProperties());
String uid = new RestApiActions(schema.getPlural()).post(referenceObject).extractUid();
element = new JsonPrimitive(uid);
} else {
element = new JsonPrimitive(new IdGenerator().generateUniqueId());
}
} else {
element = generateRandomValueMatchingSchema(prop);
}
objectBody.add(prop.getName(), element);
}
return objectBody;
}
Aggregations