Skip to content

Quick Start

shiryaeva edited this page Dec 8, 2018 · 18 revisions

This section describes the process of creating an application using CUBA CLI.

Make sure that the necessary software is already installed and set up on your computer, see Installation.

1. CUBA CLI basics

CUBA CLI is a tool for CUBA Platform projects scaffolding. CLI can work in two modes: shell mode and single command mode.

2. Creating a project

  1. Open a terminal and start CUBA CLI.
cuba-cli

Start CUBA CLI

  1. Input command create-app. You can use TAB auto-completion.
create-app

Create app

  1. CLI will ask you questions about the project. If a question implies default answer, you can press enter to accept it. You will be asked the following questions:
  • Repository to be used in the project - binary artifacts repository URL. The artifacts that the project depends on are loaded from the repository when that project is built.
  • Project name – the project name. For sample projects CLI generates random names that can be selected by default.
  • Project namespace – the namespace which will be used as a prefix for entity names and database tables. The namespace can consist of Latin letters only and should be as short as possible.
  • Root package – the root package of Java classes.
  • Platform version – the platform version used in the project. The platform artifacts will be automatically downloaded from the repository on project build. Choose the latest.
  • Database – the SQL database to use. Choose HSQLDB.

Setup project settings

  1. The empty project will be created in a new folder in the current directory.

New project

  1. Close CLI or open new terminal window and navigate to the project folder. Run ./gradlew assemble
./gradlew assemble

Assemble

  1. Run ./gradlew startDb to start the local HyperSQL server.
./gradlew startDb
  1. Run ./gradlew createDb to create a database.
./gradlew createDb

Scripts executed

  1. Start the locat Tomcat server by running ./gradlew setupTomcat deploy start.
gradlew setupTomcat deploy start

Start Tomcat

  1. In your browser go to http://localhost:8080/app

The username and password are admin / admin.

3. Importing project into IDE

  1. Open IntelliJ IDEA
  2. File -> Open, navigate to project directory, choose build.gradle, press OK.
  3. In Gradle settings choose Use gradle 'wrapper' task configuration.
  4. Press OK.

4. Creating entities

  1. In the terminal navigate to project directory.
  2. Start CUBA CLI.
  3. Enter create-entity. You will be asked the following questions:
  • Entity name – entity class name. Enter Customer.
  • Package name – entity class package name. Accept default.
  • Entity type – entity may be Persistent, Persistent embedded or Not Persistent. Choose Persistent to make the entity able to be saved in the database.
create-entity

Start CUBA CLI

  1. Let's add some fields. Open the created class in your IDE. Add the following field and methods:
@Column(name = "NAME")
protected String name;

public void setName(String name) {
    this.name = name;
}

public String getName() {
    return name;
}
  1. Now let's add the new column to the SQL create and update scripts. Open the generated {yymmdd}-createCustomer.sql update script in the modules/core/db/update/hsql/{yy}/ folder and add the NAME column to it:
-- begin SALES_CUSTOMER
create table DEMO_CUSTOMER (
    ID varchar(36) not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    VERSION integer,
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    DELETE_TS timestamp,
    DELETED_BY varchar(50),
    --  add your columns here
    NAME varchar(255),
    --
    primary key (ID)
)^
-- end SALES_CUSTOMER

Add the new column to the generated 10.created-db.sql create script, too.

See the CUBA Platform documentation to learn more about create and update scripts.

  1. Run ./gradlew updateDb to create the table for the Customer entity.
gradlew updateDb

5. Creating standard screens

  1. In the terminal navigate to project directory.
  2. Start CUBA CLI.
  3. Enter create-screen
  4. Select Create new browse screen to create the Browse screen. You will be asked the following questions:
  • Choose entity – select Customer.
  • Package name – the screens package name. Accept default.
  • Screen id - the identifier of the screen in web-screens.xml file. Accept default.
  • Descriptor name - the name of the XML-descriptor file. Accept default.
  • Controller name - the name of the screen controller file. Accept default.

Create entity browser

  1. Enter create-screenagain, select Create new edit screen and repeat the steps above to create the Edit screen for the Customer entity.

Create entity editor

The created standard screens have been created in the web module package.