use of com.github.davidmoten.odata.client.generator.Names.SchemaAndType in project odata-client by davidmoten.
the class Generator method generate.
public void generate() {
log("-----------------------------------");
log("Generating code for namespaces:");
//
schemas.forEach(s -> log(" " + s.getNamespace()));
log("Types:");
//
schemas.stream().flatMap(s -> Util.filter(s.getComplexTypeOrEntityTypeOrTypeDefinition(), TEntityType.class).map(//
t -> new SchemaAndType<TEntityType>(s, t))).map(//
x -> names.toTypeWithNamespace(x.schema, x.type.getName())).forEach(x -> log(" " + x));
log("-----------------------------------");
log("Replacing aliases");
Util.replaceAliases(schemas);
log("Finding collection types");
Set<String> collectionTypes = findTypesUsedInCollections(names, schemas);
for (Schema schema : schemas) {
log("Generating for namespace=" + schema.getNamespace());
log(" creating maps");
Map<String, List<Action>> typeActions = createTypeActions(schema, names, false);
log(" entity actions count = " + typeActions.size());
Map<String, List<Function>> typeFunctions = createTypeFunctions(schema, names, false);
log(" entity functions count = " + typeFunctions.size());
Map<String, List<Action>> collectionTypeActions = createTypeActions(schema, names, true);
log(" collection actions count = " + collectionTypeActions.size());
Map<String, List<Function>> collectionTypeFunctions = createTypeFunctions(schema, names, true);
System.out.println(" collection functions count = " + collectionTypeFunctions.size());
log(" checking entities have keys");
//
Util.types(schema, TEntityType.class).map(//
x -> new EntityType(x, names)).filter(//
x -> !x.hasKey()).forEach(x -> log(" " + x.getFullType() + " has no keys"));
log(" writing schema info");
writeSchemaInfo(schema);
// write enums
log(" writing enums");
//
Util.types(schema, TEnumType.class).forEach(x -> writeEnum(schema, x));
// write entityTypes
log(" writing entities");
//
Util.types(schema, TEntityType.class).forEach(x -> writeEntity(x, typeActions, typeFunctions));
// write complexTypes
log(" writing complex types");
//
Util.types(schema, TComplexType.class).forEach(x -> writeComplexType(schema, x));
// write entity collection requests
log(" writing entity collection requests");
//
Util.types(schema, TEntityType.class).forEach(x -> writeEntityCollectionRequest(schema, x, collectionTypeActions, collectionTypeFunctions, collectionTypes));
log("writing entity set requests");
//
Util.types(schema, TEntityContainer.class).flatMap(c -> //
Util.filter(c.getEntitySetOrActionImportOrFunctionImport(), //
TEntitySet.class).map(//
x -> new Pair<TEntityContainer, TEntitySet>(c, x))).forEach(x -> writeEntitySet(schema, x));
// write containers
log(" writing container");
//
Util.types(schema, TEntityContainer.class).forEach(x -> writeContainer(schema, x));
// write single requests
log(" writing entity requests");
//
Util.types(schema, TEntityType.class).forEach(x -> writeEntityRequest(schema, x, typeActions, typeFunctions));
log(" writing complex type requests");
//
Util.types(schema, TComplexType.class).forEach(x -> writeComplexTypeRequest(schema, x));
}
}
Aggregations