Quick Start: Generating Your First Application
Before going through the following steps, make sure you have completed the installation process. This page assumes that you have already performed all the installation steps.
Generating, building, and running an application includes the following steps:
Define a business model in a JDL file;
Run the Application Generator tool with this JDL file as an input;
Build the application using the Gradle build scripts generated with the application;
Create Docker images for the application microservices;
Launch the application.
Steps 1 and 2 are described on this page. The next section, Configure Access, provides the steps required to ensure access to the DecisionBrain repositories. Then, Section Build and Run Your Application covers Steps 3 to 5.
Define the Business Model in a JDL File
To perform this Quick Start tutorial, you should first copy the following contents into a file named entities.jdl. Place this file in a directory of your choice. During next step, the application code will be generated in a subdirectory of this directory.
Hints for creating the JDL file
To create the entities.jdl file from the contents provided below, use your favorite method--here are some options.
Start by copying the contents below, typically by using the "Copy to clipboard" button that appears when hovering the text.
Then, paste this text in a new file named entities.jdl.
On macOS, this can be achieved by executing
pbpaste > entities.jdlOn macOS and Linux, this can be achieved by executing
cat > entities.jdlthen pasting the copied text in the terminal, and typing
^Don a new line.On all systems, it can also be achieved by creating the
entities.jdlfile in a programming editor, and pasting the copied text into this file. Just make sure that you do not use a word processor like MS Word, but a text editor made for programming, such as VS Code.
Sample Business Model
The following JDL text is to be saved in a file named entities.jdl. To know more about how to write a JDL file, please refer to Business Model Configuration.
application {
// DOM [java.collectorClass] : [<%=collectorClass%>]
}
entity Country {
// DOM [simple.primary.keys] : [id]
id String required,
name String
}
entity Plant {
// DOM [simple.primary.keys] : [plantId]
plantId String required,
}
entity Resource {
// DOM [simple.primary.keys] : [id]
id String required,
name String
}
entity ResourceCapacity {
quantity Integer
}
entity Activity {
// DOM [simple.primary.keys] : [id]
id String required,
name String,
durationInHours Double
}
entity Precedence {
}
entity Requirement {
quantity Integer
}
entity Schedule {
start Instant,
end Instant
}
entity SolutionSummary {
// DOM [single.row] : [true]
start Instant,
end Instant,
timespan Integer
}
entity ResourceUsagePerDay {
// DOM [simple.primary.keys] : [day]
day Integer,
numberOfHours Integer,
}
relationship ManyToOne {
// DOM [affects.primary.key] : [true]
Requirement{activity} to Activity{requirements},
// DOM [affects.primary.key] : [true]
Requirement{resource} to Resource{requirements},
// DOM [affects.primary.key] : [true]
Precedence{first} to Activity{successors},
// DOM [affects.primary.key] : [true]
Precedence{second} to Activity{predecessors},
// DOM [affects.primary.key] : [true]
Schedule{resource} to Resource{schedules}
// DOM [affects.primary.key] : [true]
Schedule{activity} to Activity{schedules}
// DOM [affects.primary.key] : [true]
ResourceUsagePerDay{resource} to Resource{usagePerDay}
// DOM [affects.primary.key] : [true]
Plant{country} to Country{plants}
// DOM [affects.primary.key] : [true]
Activity{plant} to Plant{activities}
}
relationship OneToOne {
// DOM [affects.primary.key] : [true]
ResourceCapacity{resource} to Resource{capacity}
}Prepare the Application Generator Script
The Application Generator tool of the platform is provided as a Docker image named db-gene/generator, which is accessible from the DecisionBrain registries. However, to ease its use, a Bash script is provided that executes the Generator tool.
The text of this script can be found below. You should copy it in a file named generator.sh, which you will typically put in the same directory as the entities.jdl file that your created at the previous step. To do so, you can use the same method, as described in Section Hints for creating the JDL file.
#!/usr/bin/env bash
# put the default version you want to use here. You can change it using the "-v VERSION" option if needed.
VERSION=@DOC_PRODUCT_VERSION@
function Usage {
echo "Usage: $(basename "$0") [-v VERSION]" 1>&2
echo "Generate an application within the current folder." 1>&2
echo "The JDL or DBM file used to generate the application must be located in the current folder." 1>&2
echo " [-v VERSION] if provided, VERSION must represent the Platform generator version (for ex: @DOC_PRODUCT_VERSION@)" 1>&2
echo "" 1>&2
echo "Examples:" 1>&2
echo " $ $(basename "$0") # calls generator $VERSION" 1>&2
echo " $ $(basename "$0") -v 5.0.0 # calls generator 5.0.0" 1>&2
exit 1
}
if [ "$1" == "--help" ]
then Usage
fi
if [ "$1" == "-v" ]
then
shift
VERSION="$1"
shift
fi
TASK="@gene/gene"
# mount current folder on '/tmp' and run the generator
TARGET_FOLDER=$(pwd)
if [ "$OSTYPE" == "msys" ]
then
TARGET_FOLDER=$(cmd //c cd)
fi
echo Mounting $TARGET_FOLDER as generation folder
docker run --rm -it -v "$TARGET_FOLDER":/tmp product-dbgene-prod-docker-group.decisionbrain.cloud/db-gene/generator:$VERSION $TASK "$@"Call the Application Generator
Preliminary Steps
Once you have created the generator.sh script with the contents above, there are two more steps before you can run this script.
First, you must give yourself execution rights on this file by running the following command:
chmod +x generator.shThen, you must log into the Docker registry where the Application Generator Docker image invoked by the script is stored. To this end, run the following command and provide the installation credentials that you have been given.
docker login product-dbgene-prod-docker-group.decisionbrain.cloudRun the Script
Open a command line tool and move to the folder where you have stored the entities.jdl and generator.sh files. Your application will be generated in a subdirectory of this directory.
After executing the preliminary steps above, run the following command and answer the questions as explained in the table below.
./generator.shNote: Some generation problems are addressed in the Troubleshooting section.
| Question | Description | Example |
|---|---|---|
| Your project name | The short name of your project, to be used in a number of places to generate identifiers. For example, it will be used as the name of the directory that will be created to contain the generated application. It also will be used to identify your application components. This name should not contain any special character or whitespace | my-project |
| Project title | A longer name for your project. This will appear for example as the title of your web-based user interface. | My First Project |
| The project generation destination | Always answer . to this question. |
. |
| Your project package | The Java package that will be used (as a root) in the generated classes. | com.example.project |
| Collector class name | The simple, unqualified name of the Java class that will be generated and used as the business model collector, that is, the entry point for in-memory data handling in your application. It is a good idea to use a name close to your application name. | ProjectCollector |
| What type of your model definition do you have ? | The Application Generator tool can be used to migrate an existing IBM DOC 3.x application. In that case, the data model can be provided in DBM, a specific IBM DOC 3.x format. In the present tutorial, we use the JDL format. | jdl |
| Path to your jdl file | Since the JDL file must be stored in the directory where you execute the Application Generator script, this will be the local name of your JDL file. | entities.jdl |
Here is a transcript of a session where an application called capacity-planning was created in the current folder:
$ ./generator.sh
Mounting /Users/alice/Work/example as generation folder
Generating using version @DOC_PRODUCT_VERSION@
**********************************************************
Gene CLI Project Generator
Copyright (c) 2020 DecisionBrain SAS. All Rights Reserved.
**********************************************************
? Your project name capacity-planning
? Project title (will appear in the interface and documentation) Capacity Planning
? The project generation destination .
? Your project package com.example.capacity-planning
? Collector class name (no package, ex: MyCollector) CapacityPlanning
? What type of your model definition do you have ? DOC 3.9 (dbm file) or jdl ? jdl
? Path to your jdl file entities.jdl
create capacity-planning/.gitattributes
create capacity-planning/README.md
create capacity-planning/build.gradle
...
create capacity-planning/gene-model/spec/entities.jdl
...
Processing dotfiles
/tmp/capacity-planning/.gitignore
/tmp/capacity-planning/workers/python-engine-worker/worker-shell/.gitignore
/tmp/capacity-planning/web/.gitignore
/tmp/capacity-planning/web/.npmrcNote that the Application Generator tool has copied your original JDL file to the gene-model/spec subdirectory of the project that was generated (see near the end of the transcript above). Should you want to change your data model in the future, you should edit this file. The original file is not used in the generated application.
Also, you can notice that the original JDL file that you used as input to the Application Generator tool contains a <%=collectorClass%> placeholder. If you need to generate your project again and provide a different collector class name, be sure to use your original JDL file.
The next steps include building the application, the code of which was just generated. This requires to configure the access to DecisionBrain repositories. Both aspects are covered in the next sections.