☕ Java & Kotlin edition
Welcome to the open-source CAE Common Primary Adapters repository! This SDK module is designed to provide a collection of commonly used primary adapters — components that trigger the execution of use cases. It serves as a convenient starting point for creating these software components, offering seamless integration with other CAE components by default.
In this repository, each folder corresponds to a specific common primary adapter. All of them share the prefix 'cae-cpa', which stands for 'CAE (Clean Arch Enablers) Common Primary Adapters', followed by the name of the actual component.
State Symbol Key:
✅
— Under release state✔️
— Under snapshot state⏳
— Under full development state
This component provides a framework for building CLI tools. You can declare commands, define their parameters, and use them to dispatch executable actions within the CLI process.
<dependency>
<groupId>com.clean-arch-enablers</groupId>
<artifactId>command-controller</artifactId>
<version>${version}</version>
</dependency>
With this script the CLI app would be set to display the name as cae-cli
, its version as 1.0.0
. The commands accepted would be NewFunctionUseCaseCommand
, NewConsumerUseCaseCommand
, NewSupplierUseCaseCommand
, NewRunnableUseCaseCommand
, NewProjectCommand
, RotateToMonolayerCommand
.
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CaeCliBootstrapSettings {
public static void run(){
ClientSettingsProvider.SINGLETON.setClientName("cae-cli");
ClientSettingsProvider.SINGLETON.setVersion("1.0.0");
CommandRepository.SINGLETON.registerNewCommands(List.of(
new NewFunctionUseCaseCommand(),
new NewConsumerUseCaseCommand(),
new NewSupplierUseCaseCommand(),
new NewRunnableUseCaseCommand(),
new NewProjectCommand(),
new RotateToMonolayerCommand()
));
}
}
With this script the NewProjectCommand
class becomes a Command
. Within its constructor 4 command parameters are declared: monolayer
(a flag, optional), artifactId
(required parameter), groupId
(required parameter) and caeVersion
(required parameter).
Whenever the command gets executed, its flow is whatever is inside its applyInternalLogic
method. In this instance, the logic is to call the GenerateProjectStructureUseCase
which is an API from the
cae-meta-structure library.
public class NewProjectCommand extends Command {
public NewProjectCommand() {
super("new-project");
this.registerParameter("monolayer", CommandParameterDefinitions.newOptionalFlagParameter());
this.registerParameter("artifactId", CommandParameterDefinitions.newRequiredDefaultParameter());
this.registerParameter("groupId", CommandParameterDefinitions.newRequiredDefaultParameter());
this.registerParameter("caeVersion", CommandParameterDefinitions.newRequiredDefaultParameter());
}
@Override
protected void applyInternalLogic() {
var isMonolayer = this.getCommandParameters().get("monolayer").isPresent();
var artifactId = this.getCommandParameters().get("artifactId").getActualValue();
var groupId = this.getCommandParameters().get("groupId").getActualValue();
var frameworkVersion = this.getCommandParameters().get("caeVersion").getActualValue();
var useCaseInput = GenerateProjectStructureUseCaseInput.builder()
.artifactId(artifactId)
.groupId(groupId)
.monolayer(isMonolayer)
.caeFrameworkVersion(frameworkVersion)
.build();
var useCase = new GenerateProjectStructureUseCaseImplementation();
useCase.execute(useCaseInput, UseCaseExecutionCorrelation.ofNew());
}
}
After declaring and registering your commands in the CommandRepository
, you can dispatch them by following the script below in the main class of your CLI application.
public class CaeCli {
public static void main(String[] args) {
CaeCliBootstrapSettings.run(); //This line serves as a simple wrapper for the command registration phase and is arbitrary.
CommandController.serve(CommandRequest.of(args));
}
}