Development Guide
In this section, practical development steps are discussed for anyone interested in contributing to the VLINGO XOOM Designer project.

Features

The XOOM Designer codebase mainly contains the implementation of the following features:
  • XOOM Designer: the visual model designer itself that, besides the project generation, provides a rapid configuration for VLINGO XOOM components.
  • XOOM CLI: provides shortcuts for initializing XOOM Designer and interacting with Docker, Gloo Gateway API, and Kubernetes;
Although sharing the same codebase, these two features are not strongly dependent, so it's meant to be kept semantically and structurally separate. In that sense, the Designer and CLI implementations are respectively placed under the package io.vlingo.xoom.designer and io.vlingo.xoom.cli.
Next, the practical sections show how to maintain and expand both features.

Introduction to CLI

Once the XOOM Designer is correctly installed, the CLI is accessed from the terminal by calling the executable bash script (ex. ./xoom docker package). Internally, this script runs the Designer jar and passes the command, i.e. docker package, to the CommandLineInterfaceInitializer class:
1
public class CommandLineInterfaceInitializer {
2
3
public static void main(final String[] args) {
4
...
5
6
final Task task = Task.triggeredBy(resolveCommand(args));
7
8
runTask(task, Arrays.asList(args));
9
}
10
11
...
12
}
Copied!
The code snippet above shows that an implementation of io.vlingo.xoom.cli.task.Task is triggered by the user command, implying that there is one Task subclass for each supported task. Next, the task implementation responsible for initializing the Designer service is demonstrated:
1
public class DesignerTask extends Task {
2
3
private final DesignerInitializer initializer;
4
5
...
6
7
@Override
8
public void run(final List<String> args) {
9
this.initializer.start(OptionValue.mapValues(options, args));
10
}
11
12
}
Copied!
The OptionValue class helps tasks to support execution options, which are passed along with the bash command. For instance, the designer server port can be customized as follows:
1
$ ./xoom designer --port 8081
Copied!
The concluding step of a Task implementation is to edit the ComponentRegistration class mapping the task as an element of the cliTasks list. That makes XOOM CLI able to run the task when the corresponding command is executed:
1
2
public class ComponentsRegistration {
3
4
public static void registerWith(final Logger logger,
5
final CommandExecutionProcess commandExecutionProcess,
6
final XoomTurboProperties properties) {
7
ComponentRegistry.register("cliTasks", Arrays.asList(new DesignerTask(commandExecutionProcess), new DockerPackageTask(commandExecutionProcess) ...);
8
}
Copied!

Introduction to Designer

The following diagram gives us an overview of how the Designer components interact for generating a project:
XOOM Designer components
The Designer-embedded user interface illustrated above is built with Svelte. It consumes a Rest API submitting the model details to the server-side. Once successfully processed, XOOM Designer uses Apache FreeMarker for generating classes, configuration, and deployment files. That said, let's see how to add templates at the code level.
For any development on XOOM Designer you must set an environment variable named VLINGO_XOOM_STARTER_HOME. Although you have likely already set this property in order to use the XOOM Designer, that was as an enduser, which has a different value. As a developer working on the Designer, you must set this to the absolute path of a directory relative to where the vlingo-xoom-starter repository has been cloned.
Using a *nix shell, such as bash, set like this:
1
$ VLINGO_XOOM_DESIGNER_HOME=[git-clone-path]/dist/designer
2
$ export VLINGO_XOOM_DESIGNER_HOME
Copied!
On Windows you can use the System Properties > Advanced > Environment Variables... to set the property permanently. For a one-time setting before running the design tool you can use the command line:
1
C:\> set VLINGO_XOOM_DESIGNER_HOME=[git-clone-path]\dist\designer
Copied!
After making changes, from the root project directory, build and run the Designer. On *nix run these commands:
1
$ mvn clean package -P frontend
2
...
3
$ java -jar target/xoom-designer-1.6.1-SNAPSHOT.jar gui
Copied!
This works on Windows:
1
C:\[git-clone-path]> mvn clean package -P frontend
2
...
3
C:\[git-clone-path]> java -jar target\xoom-designer-1.6.1-SNAPSHOT.jar gui
Copied!
For more details see README.md in the xoom-designer repository.

Model Processing Steps

While the previous section provides a quick introduction to the Designer components, this section focuses on explaining each step involved in the Designer Model processing, going through the layers, from the external to the inner, API to the full project generation.
First, let's consider how the web-based UI interacts with the Rest API when the project generation is requested:
Project Generation - UI and Rest API communication
The figure above shows the two requests submitted when the user finishes the Designer model and clicks the generate button. The first request checks if the generation path is valid by creating the full directory tree where the generated project is going to be installed. If it succeeds, the project generation is subsequently requested. The handler methods responsible for processing these requests are presented below:
1
package io.vlingo.xoom.designer.infrastructure.restapi;
2
3
public class ModelProcessingResource extends DynamicResourceHandler {
4
5
private final ModelProcessingManager modelProcessingManager;
6
7
...
8
9
public Completes<Response> startGeneration(final DesignerModel model) {
10
return modelProcessingManager.generate(model, modelProcessingInformation, logger).andThenTo(scene -> {
11
final Response.Status responseStatus = scene.isFailed() ? InternalServerError : Ok;
12
return Completes.withSuccess(Response.of(responseStatus, serialized(scene.report)));
13
});
14
}
15
16
public Completes<Response> makeGenerationPath(final GenerationPath path) {
17
try {
18
modelProcessingManager.createGenerationPath(new File(path.path));
19
return Completes.withSuccess(Response.of(Created, headers(of(Location, path.path)), path.serialized()));
20
} catch (final GenerationPathAlreadyExistsException e) {
21
return Completes.withSuccess(Response.of(Conflict, path.serialized()));
22
} catch (final GenerationPathCreationException e) {
23
return Completes.withSuccess(Response.of(Forbidden, path.serialized()));
24
}
25
}
26
27
...
28
}
Copied!
ModelProcessingResource depends on ModelProcessingManager for making the generation path and generating the project. Let's get deeper into the code and see how ModelProcessingManager implements the project generation.
1
public class ModelProcessingManager {
2
3
private final List<CodeGenerationStep> codeGenerationSteps = new ArrayList<>();
4
5
public ModelProcessingManager(final List<CodeGenerationStep> codeGenerationSteps) {
6
this.codeGenerationSteps.addAll(codeGenerationSteps);
7
}
8
9
public Completes<ModelProcessingScene> generate(final DesignerModel model,
10
final ModelProcessingInformation information,
11
final Logger logger) {
12
return validate(model, information)
13
.andThenTo(scene -> mapContext(scene, logger))
14
.andThen(scene -> processSteps(scene));
15
}
16
17
private Completes<ModelProcessingScene> validate(final DesignerModel model,
18
final ModelProcessingInformation information) {
19
final ModelProcessingScene scene = ModelProcessingScene.with(model, information);
20
final String validationErrors = String.join(", ", model.validate());
21
if(validationErrors.isEmpty()) {
22
return Completes.withSuccess(scene);
23
}
24
return Completes.withFailure(scene.onValidationFail(validationErrors));
25
}
26
27
private Completes<ModelProcessingScene> mapContext(final ModelProcessingScene scene,
28
final Logger logger) {
29
try {
30
final CodeGenerationContext codeGenerationContext =
31
CodeGenerationContextMapper.map(scene.designerModel,
32
scene.information.generationTarget, logger);
33
34
return Completes.withSuccess(scene.addCodeGenerationContext(codeGenerationContext));
35
} catch (final Exception exception) {
36
exception.printStackTrace();
37
return Completes.withFailure(scene.onContextMappingFail(exception));
38
}
39
}
40
41
private ModelProcessingScene processSteps(final ModelProcessingScene scene) {
42
try {
43
codeGenerationSteps.stream()
44
.filter(step -> step.shouldProcess(scene.codeGenerationContext))
45
.forEach(step -> step.process(scene.codeGenerationContext));
46
47
return scene.onCodeGenerationSucceed();
48
} catch (final Exception exception) {
49
...
50
}
51
}
Copied!
Reading the ModelProcessingManager code from the top, it's clear that its constructor receives a CodeGenerationStep list. The details of this ModelProcessingManager dependency are explained later, but, for now, just keep in mind that the list elements are every step responsible for creating or customizing a piece of the generated project such as configuration files, source code, and other resources.
The ModelProcessingManager.generate is the high-level method for the project generation. It uses some auxiliary methods in order to keep the code more organized and readable. Here are the competencies of each one of these auxiliary methods:
  • ModelProcessingManager.validate - checks if the submitted DesignerModel is valid. Otherwise, the project generation fails.
  • ModelProcessingManager.mapContext - maps a DesignerModel to CodeGenerationContext that gathers all the information required for the CodeGenerationSteps
  • ModelProcessing.processSteps - iterates through the CodeGenerationStep list and processes the steps when the CodeGenerationStep.shouldProcess returns true.
That said, let's have a look at the elements of the CodeGenerationStep list declared in io.vlingo.xoom.designer.Configuration:
1
public class Configuration {
2
3
...
4
5
private static List<CodeGenerationStep> codeGenerationSteps() {
6
return Arrays.asList(
7
//Preliminary
8
new CodeGenerationParameterValidationStep(),
9
new MainClassResolverStep(),
10
new StagingFolderCleanUpStep(Phase.PRE_GENERATION),
11
new TemporaryTaskFolderCreationStep(),
12
//Java
13
new ReadmeFileGenerationStep(),
14
new ApplicationSettingsGenerationStep(),
15
new ValueObjectGenerationStep(),
16
new ModelGenerationStep(),
17
new DataObjectGenerationStep(),
18
new ProjectionGenerationStep(),
19
new StorageGenerationStep(),
20
new RestResourceGenerationStep(),
21
new AutoDispatchMappingGenerationStep(),
22
new ExchangeGenerationStep(),
23
new SchemataGenerationStep(),
24
new BootstrapGenerationStep(),
25
new EntityUnitTestGenerationStep(),
26
new QueriesUnitTestGenerationStep(),
27
new ProjectionUnitTestGenerationStep(),
28
new RestResourceAbstractUnitTestGenerationStep(),
29
new RestResourceUnitTestGenerationStep(),
30
new ClusterSettingsGenerationStep(),
31
new DesignerModelGenerationStep(),
32
new DockerfileGenerationStep(),
33
new KubernetesManifestFileGenerationStep(),
34
//React
35
new StaticFilesGenerationStep(),
36
new LayoutGenerationStep(),
37
new AggregateManagementGenerationStep(),
38
//Concluding
39
new ContentCreationStep(),
40
new MavenWrapperInstallationStep(),
41
new SchemaPushStep(...),
42
new SchemaPullStep(...),
43
new StagingFolderCleanUpStep(Phase.POST_GENERATION)
44
);
45
}
46
47
}
Copied!
The steps are grouped either by the generation phase or the programming language/technology on which a specific project part is generated. The preliminary steps are responsible for preparing the internal Designer resources for a new project generation and also defining TemplateParameter values to be used in the later steps.
The core steps, declared between the preliminary and concluding steps, extend TemplateProcessingStep which is a subclass of CodeGenerationStep. This extension allows these steps to easily process Freemarker templates based on Java/React technologies.
At last, the concluding steps, like the preliminary steps, are simple CodeGenerationStep extensions that respectively perform the following tasks:
  • Physically create the template output processed in the core steps;
  • Copy necessary resources to the generated project;
  • Executes Maven-based Schemata goals;
  • Clear leftovers of the generated project from Designer internals;
The next section discusses how to implement a CodeGenerationStep and create/update code templates.

Create / Update Code Templates

The main constituent parts for every auto-generated class / project resouce are:
Considering those parts, let's take AggregateProtocol class generation as an example and go through the implementation details, starting from the template file:
1
package ${packageName};
2
3
<#if imports?has_content>
4
<#list imports as import>
5
import ${import.qualifiedClassName};
6
</#list>
7
</#if>
8
9
public interface ${aggregateProtocolName} {
10
<#if !useCQRS>
11
12
/*
13
* Returns my current state.
14
*
15
* @return {@code Completes<${stateName}>}
16
*/
17
Completes<${stateName}> currentState();
18
</#if>
19
20
}
Copied!
The Aggregate Protocol template file requires some parameter values to generate an Aggregate Protocol class. The parameters handling and mapping are addressed by AggregateProtocolTemplateData as follows:
1
public class AggregateProtocolTemplateData extends TemplateData {
2
3
private final String protocolName;
4
private final TemplateParameters parameters;
5
6
public AggregateProtocolTemplateData(final String packageName,
7
final CodeGenerationParameter aggregate,
8
final List<Content> contents,
9
final Boolean useCQRS) {
10
this.protocolName = aggregate.value;
11
this.parameters = TemplateParameters.with(TemplateParameter.PACKAGE_NAME, packageName)
12
.addImports(resolveImports(aggregate, contents))
13
.and(TemplateParameter.AGGREGATE_PROTOCOL_NAME, aggregate.value)
14
.and(TemplateParameter.STATE_NAME, JavaTemplateStandard.AGGREGATE_STATE.resolveClassname(aggregate.value))
15
.and(TemplateParameter.USE_CQRS, useCQRS);
16
}
17
18
private Set<String> resolveImports(final CodeGenerationParameter aggregate, final List<Content> contents) {
19
return ValueObjectDetail.resolveImports(contents, aggregate.retrieveAllRelated(Label.STATE_FIELD));
20
}
21
22
@Override
23
public String filename() {
24
return standard().resolveFilename(protocolName, parameters);
25
}
26
27
@Override
28
public TemplateParameters parameters() {
29
return parameters;
30
}
31
32
@Override
33
public TemplateStandard standard() {
34
return JavaTemplateStandard.AGGREGATE_PROTOCOL;
35
}
36
37
}
Copied!
The full package name and the AggregateProtocol class name are mapped to the template parameters in loadParameters. Additionally, TemplateData requires the filename method implementation, which commonly uses the filename resolution logic in the corresponding TemplateStandard.
1
public class ModelGenerationStep extends TemplateProcessingStep {
2
3
@Override
4
protected List<TemplateData> buildTemplatesData(final CodeGenerationContext context) {
5
return ModelTemplateDataFactory.from(context);
6
}
7
8
@Override
9
public boolean shouldProcess(final CodeGenerationContext context) {
10
return context.hasParameter(Label.AGGREGATE);
11
}
12
13
}
Copied!
ModelGenerationStep implements the buildTemplateData method that passes parameter values, coming from the Web-based UI, to RestResourceTemplateData. In this particular scenario, ModelTemplateDataFactory is an additional and optional class that helps building AggregateProtocolTemplateData. The shouldProcess method is also optional and useful when a TemplateProcessingStep subclass needs to be conditionally skipped.
Finally, TemplateProcessingSteps has to be added to the Configuration steps list:
1
2
private static List<CodeGenerationStep> codeGenerationSteps() {
3
return Arrays.asList(
4
...
5
//Java
6
new ReadmeFileGenerationStep(),
7
new ApplicationSettingsGenerationStep(),
8
new ValueObjectGenerationStep(),
9
new ModelGenerationStep(),
10
new DataObjectGenerationStep()
11
12
....
13
);
14
Copied!
Eventually, some peripheral points in the code are also involved. The following list is mainly related when a new template file is added:
1. Create an enum value in Template passing the template filename (without extension) in the constructor. Example:
1
2
public enum Template {
3
4
//Other template filenames
5
6
AGGREGATE_PROTOCOL("AggregateProtocol")
7
8
//Enum attributes
9
}
10
Copied!
2. Map the new standard file to an existing TemplateStandard or create one. Sometimes there are multiple files for the same standard. For instance, there is one Aggregate template file for each Storage (Journal, State Store, Object Store). That means TemplateStandard is responsible for grouping template files by standard and helps the TemplateProcessor to find the proper file based on TemplateParameters such as StorageType. The examples below demonstrate the Aggregate Protocol and Value Object standards.
1
public enum JavaTemplateStandard {
2
3
AGGREGATE_PROTOCOL(parameters -> Template.AGGREGATE_PROTOCOL.filename),
4
VALUE_OBJECT(parameters -> Template.VALUE_OBJECT.filename),
5
6
//Other standards
7
}
8
Copied!
3. In case it doesn't already exist, create an enum value in TemplateParameter for each template parameter.
To sum up, those are the common steps regarding code template files on xoom-designer. Our team is available to discuss and provide more information on Gitter and our public Slack workspace.