in src/main/java/com/epam/digital/data/platform/generator/factory/impl/nested/NestedCommandHandlerScopeFactory.java [53:84]
private Stream<NestedCommandHandlerScope> createNestedNodeScopeHandlers(
String structureName, NestedNode node, Context context) {
if (node.getChildNodes().entrySet().isEmpty()) {
return Stream.empty();
}
var table = findTable(node.getTableName(), context);
var nestedColumnNames = node.getChildNodes().keySet();
var nestedColumns =
table.getColumns().stream()
.filter(column -> nestedColumnNames.contains(column.getName()))
.collect(toList());
var simpleFieldNames =
table.getColumns().stream()
.filter(Predicate.not(nestedColumns::contains))
.map(Column::getName)
.map(this::getPropertyName)
.collect(toList());
var schemaName = getSchemaName(structureName, table.getName()) + "Nested";
var scope = new NestedCommandHandlerScope();
scope.setClassName(schemaName + "UpsertCommandHandler");
scope.setSchemaName(schemaName);
scope.setRootEntityName(getSchemaName(table.getName()) + "Model");
scope.setRootHandler(getPropertyName(node.getTableName()) + "UpsertCommandHandler");
scope.setSimpleFields(simpleFieldNames);
scope.getNestedHandlers().addAll(getChildHandlers(structureName, node, nestedColumns));
var childScopes =
node.getChildNodes().values().stream()
.flatMap(childNode -> createNestedNodeScopeHandlers(structureName, childNode, context));
return Stream.concat(Stream.of(scope), childScopes);
}