CUBA Hands on Lab

Embed Size (px)

Citation preview

  • 8/18/2019 CUBA Hands on Lab

    1/133

    Develop a Fully Functional

    Business Application in Hours w

    CUBA Platform

  • 8/18/2019 CUBA Hands on Lab

    2/133

    2

    Objectives

    This document will guide you through the key features of the CUBA Platform framework and s

    accelerate develoment of enterrise alications in the format of !ands"on"#abs$

    %stimated time to comlete this lab is & hours$

    The estimation is given for develoers'

    who have general (basic) knowledge

    of *ava +%$

  • 8/18/2019 CUBA Hands on Lab

    3/133

    &

    ,hat is CUBA Platform-

    A high level *ava framework for raid enterrise software develoment$ The latform rovide

    features.

    ● /ich web0deskto U1● C/U● /ole based and row level security● /eorting● Charts● 3ull te4t search●

    /%+T"AP1● +calable deloyment

    https://www.cuba-platform.com/https://www.cuba-platform.com/

  • 8/18/2019 CUBA Hands on Lab

    4/133

    5

    ,hat we are going to automate

    ,hat we are going to autom

  • 8/18/2019 CUBA Hands on Lab

    5/1336

    Alication for a small bicycle worksho

    The data mo

    +hort functional secification from the alication.

    +tore customers with their name' mobile hone and email● Customer email to be used to notify about order status

    ● /ecord information about orders. rice for reair

    and time sent by mechanic

    ● 7ee track of sare arts in stock and enable

    search for arts

    Automatically calculate rice based on sare arts used and

    time elased

    ● Control security ermissions for screens' C/U oerations and

    records8 attributes

    ● Audit of critical data changes

    ● Charts and reorts

    ,hat we are going to automate

  • 8/18/2019 CUBA Hands on Lab

    6/1339

    Alication features

    Our alication will.

    ● !ave /ich ,eb U1' with Aja4 communication● Perform basic C/U oerations● Contain the business logic for calculating rices● :anage user access rights● Present data in the form of reorts and charts● !ave audit caabilities● Allow us to create mobile alications

    or website using /%+T"AP1

    Just two hours -

    and we are ready for production

    ,hat we are going to automate

  • 8/18/2019 CUBA Hands on Lab

    7/133;

    %nvironment and tools

  • 8/18/2019 CUBA Hands on Lab

    8/133<

    eveloment environment

    =$ ownload CUBA +tudio htts.00www$cuba"latform$com0download 

    2$ 1nstall 1ntelli* 1%A

    &$ 1nstall CUBA Plugin for 1ntelli* 1%A

    %nvironment and tools

    % i t d t l

    https://www.cuba-platform.com/downloadhttps://www.cuba-platform.com/download

  • 8/18/2019 CUBA Hands on Lab

    9/133

    >

    !ow to install CUBA Plugin for 1ntelli* 1%A

    =$ /un 1ntelli* 1%A

    2$ Oen menu Configure " Plugins

    %nvironment and tools

    % i t d t l

  • 8/18/2019 CUBA Hands on Lab

    10/133

    =?

    !ow to install CUBA Plugin for 1ntelli* 1%A

    &$ Click on Browse reositories

    %nvironment and tools

    %nvironment and tools

  • 8/18/2019 CUBA Hands on Lab

    11/133

    ==

    !ow to install CUBA Plugin for 1ntelli* 1%A

    5$ 3ind CUBA lugin

    6$ Click 1nstall

    %nvironment and tools

  • 8/18/2019 CUBA Hands on Lab

    12/133

    =2

    @etting started

    @etting started

  • 8/18/2019 CUBA Hands on Lab

    13/133

    =&

    ,hat is CUBA +tudio-

    CUBA !tudio  a web based develoment tool that

    ● Offers a uick way to configure a roject and describe data model● :anages B scrits● %nables scaffolding and visual design for the user interface● ,orks in arallel with your favorite 1%.

    1ntelli* 1%A or %clise

    @etting started

    @etting started

  • 8/18/2019 CUBA Hands on Lab

    14/133

    =5

    +tart CUBA +tudio

    =$ /un CUBA +tudio

    2$ Click !tart in the launcher window

    &$ @o to the browser by clicking the Arrow button

    @etting started

    @etting started

  • 8/18/2019 CUBA Hands on Lab

    15/133

    =6

    Create a new roject

    =$ Click Create "ew on welcome screen

    2$ 3ill u roject name. workshop

    &$ Click #$ and youll get into the CUBA +tudio worksace

    @etting started

    @etting started

  • 8/18/2019 CUBA Hands on Lab

    16/133

    =9

    CUBA +tudio worksace

    Using CUBA +tudio you can easily create %ntities' !creens and stubs for +ervices$

    Dou can hide0show the Help anel using menu Help - !how help panel

    =$ Click %dit in the Pro&ect Properties section

    @etting started

    @etting started

  • 8/18/2019 CUBA Hands on Lab

    17/133

    =;

    Project roerties screen

    This is a age where we configure our roject$

    The CUBA Platform suorts Postgre+E#' :+ +E#' Oracle and !+E# databases$

    @etting started

    @etting started

  • 8/18/2019 CUBA Hands on Lab

    18/133

    =<

    +tudio will automatically add necessary

    deendencies and regenerate roject files for

    1%$

    Use reuired modules

    =$ +elect checkbo4es for reports' fts (full te4t search) and charts in the Base pro&ects section

    2$ Click #$ in the uer art of the age

    &$ +tudio will warn us about changing the roject build file' just click #$$

    g

  • 8/18/2019 CUBA Hands on Lab

    19/133

    =>

    ata model

    ata model

  • 8/18/2019 CUBA Hands on Lab

    20/133

    2?

    Create the data model

    =$ Oen the %ntities section of the navigation anel

    2$ Click "ew entity

    &$ 1nut Class name. Client 5$ Click #$

    ata model

  • 8/18/2019 CUBA Hands on Lab

    21/133

    2=

    %ntity designer 

    !ere we can secify a arent class and corresonding table in the database' define attribute

    manage other otions$

    Our class inherits StandardEntity' the service class which suorts !oft Deletion and contains a

    latform internal attributes (createTs' createdBy and others)$

    ata model

  • 8/18/2019 CUBA Hands on Lab

    22/133

    22

    Attribute editor 

    =$ Add a new attribute by clicking "ew

    2$ %nter Fame. name

    &$ +elect the 'andatory checkbo45$ Click on Add

    Attribute editor enables us to create or edit attribute

    and its arameters' such as Attribute tye' *ava Tye'

    /ead only' :andatory' Uniue' etc$

    ata model

  • 8/18/2019 CUBA Hands on Lab

    23/133

    2&

    Client entity and its attributes

    +imilarly' we add phoneNumber  and email$

    =$ Add phoneNumber  as a mandatory attribute with the length of 2? and uniue flag2$ Add email as a mandatory attribute with the length of 6? and flagged as uniue

    ata model

  • 8/18/2019 CUBA Hands on Lab

    24/133

    25

    1nstance name

    (nstance name is a default string reresentation of %ntity for user interface (tables' drodown

    =$ @o to the (nstance name tab

    2$ +elect name and phoneNumber 

    ata model

  • 8/18/2019 CUBA Hands on Lab

    25/133

    26

    @enerated source code for the Client entity

    =$ Click on the !ource tab of the %ntity desi)ner

    This is a regular *ava class' annotated with the javax.persistence annotations and sulemenannotations$

    Dou can change source code of an entity manually

    and the +tudio will read your changes and aly those

    back to model$

    ata model

  • 8/18/2019 CUBA Hands on Lab

    26/133

    29

    # +crits

    =$ Click on DD* Preview tab of the %ntity desi)ner

    2$ Click #$ to save the Client  entity

    This tab illustrates review of +E# scrit for corresonding table creation$

    ata model

  • 8/18/2019 CUBA Hands on Lab

    27/133

    2;

    :echanic entity

    =$ Click "ew entity

    2$ 1nut Mechanic as entity name and click #$

    &$ Create "ew attribute5$ +et attribute name to user 

    6$ +et Attri+ute type. SS!C"T"!N

    9$ +et Type. #ser $sec%#ser&

    ;$ +et Cardinality. MN'(T!(!NE

  • 8/18/2019 CUBA Hands on Lab

    28/133

    2<

    :echanic entity H hourly/ate attribute

    =$ Click "ew to create attribute

    2$ +et "ame. hourly)ate

    &$ +et Type. Bi*+ecimal5$ +elect 'andatory checkbo4

    6$ Click the Add button

    ata model

  • 8/18/2019 CUBA Hands on Lab

    29/133

    2>

    :echanic entity H instance name

    =$ @o to the (nstance name tab

    2$ +elect user  for the 'echanic,s instance name

    &$ +ave the 'echanic entity by clicking #$

    ata model

  • 8/18/2019 CUBA Hands on Lab

    30/133

    &?

    +arePart entity

    =$ Create "ew entity with Class name. Spare,art 

    2$ Add the title attribute as a mandatory and uniue !trin)

    &$ Add the description attribute. !trin)I clean u the value of length field' so description will hlength

    5$ Add the price attribute. mandatory' Bi)Decimal

    ata model

  • 8/18/2019 CUBA Hands on Lab

    31/133

    &=

    +arePart entity H instance name

    =$ @o to the (nstance name tab

    2$ +elect the title attribute for the Spare,art  instance name

    &$ Click #$ to save the entity

    ata model

  • 8/18/2019 CUBA Hands on Lab

    32/133

    &2

    Order+tatus enum

    To create the !rder  entity well need to create the !rderStatus enum first$

    =$ @o to the %numerations section in the navigation anel2$ Click "ew

    &$ %nter Class "ame. !rderStatus

    5$ Add values.

    NE- /

    "N(,)!0)ESS 1/

    )E+' 2/

    ata model

  • 8/18/2019 CUBA Hands on Lab

    33/133

    &&

    Order+tatus enum H source code

    =$ +imilar to entities' we can check the generated *ava code in the !ource tab

    2$ Click #$ to save the enum

    Dou can change source code of enum manually

    here and the +tudio can read it back fromthe source to its enum model$

    ata model

  • 8/18/2019 CUBA Hands on Lab

    34/133

    &5

    Order entity

    =$ @o to the %ntities section of the navigation anel

    2$ Create new entity 

    &$ +et !rder as the Class name5$ Add new attribute named. client 

    Attri+ute type. SS!C"T"!N

    Type. Client 

    Cardinality. MN'(T!(!NE

    'andatory. true

    6$ +imilarly add the mechanic attribute with

    Type. Mechanic

    ata model

  • 8/18/2019 CUBA Hands on Lab

    35/133

    &6

    Order entity H descrition' hours+ent' amount

    =$ Add description attribute. !trin)' clean u the value of length field' so description will have

    2$ Add hoursSpent  attribute. (nte)er

    &$ Add amount  attribute. Bi)Decimal

    ata model

  • 8/18/2019 CUBA Hands on Lab

    36/133

    &9

    Order entity H arts attribute

    =$ Create a "ew attribute. parts

    Attri+ute type. SS!C"T"!N

    Type. Spare,art Cardinality. MN'(T!(MN' 

    2$ Click on the Add button

    &$ The +tudio will offer to create a reverse attribute

    from the Spare,art  entity to link it to !rder '

     just click "o

    ata model

  • 8/18/2019 CUBA Hands on Lab

    37/133

    &;

    Order entity H status attribute

    =$ Create "ew attribute. status

    2$ +et Attri+ute type. EN#M

    &$ +et Type. !rderStatus5$ Click Add

    ata model

  • 8/18/2019 CUBA Hands on Lab

    38/133

    &<

    Order entity H done

    =$ +et (nstance name for the !rder  entity to its description attribute

    2$ Check the attributes list of the !rder  entity. client ' mechanic' description' hoursSpent ' amo

    &$ Click #$ to save the entity

  • 8/18/2019 CUBA Hands on Lab

    39/133

    &>

    atabase

    atabase

  • 8/18/2019 CUBA Hands on Lab

    40/133

    5?

    @enerate B scrits

    =$ Click the /enerate DB scripts link 1n the bottom of the %ntities section

    2$ The CUBA +tudio has generated a scrit to create tables and constraints

    &$ Click !ave and close5$ The +tudio has saved the scrits into a secial directory of our roject' so we will be able to

    needed

    atabase

  • 8/18/2019 CUBA Hands on Lab

    41/133

    5=

    =$ 1nvoke the 0un 1 Create data+ase action from the menu to create a database

    2$ The CUBA +tudio warns us that the old B will be deleted' click #$

    The +tudio oututs rocess stages to the log$ ,hen Build !uccessful message is shown' our B

    Create database

  • 8/18/2019 CUBA Hands on Lab

    42/133

    52

    User 1nterface

    User 1nterface

  • 8/18/2019 CUBA Hands on Lab

    43/133

    5&

    +creens scaffolding

    Fow lets create standard browser and editor screens for the Spare,art  entity$

    =$ +elect Spare,art  in the navigation anel2$ Click on the Create standard screens link 

    &$ Click Create

    On this screen we can secify where to lace

    the screens and which menu item

    will be used to oen the browser screen$

    The following terminology is used.● Browser screen H screen with list of records● %ditor screen H simle edit form for record

    User 1nterface

  • 8/18/2019 CUBA Hands on Lab

    44/133

    55

    +creen designer 

    The +tudio has generated 2 screens$ #ets have a look at sparepart-edit23ml$

    =$ +elect sparepart-edit23ml in the !creens section2$ Click %dit

    &$ The CUBA +tudio features a built"in ,D+1,1@

    screens editor to seed u U1 develoment

    5$ Click Close

    User 1nterface

  • 8/18/2019 CUBA Hands on Lab

    45/133

    56

    ata binding

    Comonents are connected with data sources' which are configurable from the Datasource

    =$ +elect sparepart-+rowse23ml2$ Click %dit

    &$ @o to the Datasources tab

    atasources use *PE# ueries to load data$

    U1

    User 1nterface

  • 8/18/2019 CUBA Hands on Lab

    46/133

    59

    eclarative U1 definition

    =$ U1 is described declaratively using J:#' we can see an e4amle of the descri

    tab

    The J:# view is synchroniKed with

    the grahical design' and if we make

    changes in J:#' then the grahical

    view will be udated and vice versa$

    U1

    User 1nterface

  • 8/18/2019 CUBA Hands on Lab

    47/133

    5;

    +creen controller 

    =$ @o to the Controller tab

    2$ Aart from J:#' the +tudio creates a controller for each screen' which is a *ava class that

    logic and handling comonent events&$ Click Close

    U1

    User 1nterface

  • 8/18/2019 CUBA Hands on Lab

    48/133

    5<

    @enerate screens for Client entity

    =$ Oen the %ntities section of the navigation anel

    2$ +elect the Client  entity

    &$ Click Create standard screens5$ Click Create

    U1

    User 1nterface

  • 8/18/2019 CUBA Hands on Lab

    49/133

    5>

    Liew$ #oading of entity grahs from B

    The Mechanic entity is linked to #ser $ +o' we need to load related #ser  entity to dislay it in the

    editor screens$ 1n CUBA' this is done via secial object H 5iew' which describes what entity a

    loaded from the database$ #ets create a view for the Mechanic entity' which will include #se

    =$ +elect the Mechanic entity

    2$ Click "ew view

    &$ Choose %3tends view. (local' as we want to

    include all local attributes

    5$ +elect the user  attribute'

    secify (minimal view for this attribute

     6minimal view includes only attributesthat are secified in the

    (nstance "ame of an entity

    6$ Click #$ to save the view

    U1

    User 1nterface

  • 8/18/2019 CUBA Hands on Lab

    50/133

    6?

    @enerate screens for :echanic

    =$ +elect the Mechanic entity

    2$ Click Create standard screens

    &$ Choose mechanic3view for browser and editor screens5$ Click Create

    U1

    User 1nterface

  • 8/18/2019 CUBA Hands on Lab

    51/133

    6=

    Liew for Order browser and editor 

    Fow we need to create screens for the !rder  entity$ ,ell also need to create a secial view

    =$ Oen the %ntities section of the navigation anel

    2$ +elect the !rder  entity

    &$ Click "ew view

    5$ +et %3tends to (local to include

    all local roerties

    6$ Tick client ' mechanic and

    select the (minimal view for them

    9$ Tick title and price for parts

    ;$ Click #$ to save the view

    U1

    User 1nterface

  • 8/18/2019 CUBA Hands on Lab

    52/133

    62

    @enerate screens for the Order entity

    =$ +elect the !rder  entity

    2$ Click Create standard screens

    &$ Choose order-view for browser and editor screens

    5$ Click Create

    U1

    User 1nterface

  • 8/18/2019 CUBA Hands on Lab

    53/133

    6&

    #et8s test it

    Our alication is done' of course' to a first aro4imation$

    #ets comile and launch itM

    =$ 1nvoke the 0un - !tart application action from the menu$

    2$ +tudio will deloy a local Tomcat instance in the

    roject subdirectory' deloy the comiled

    alication there and launch it$

    &$ Oen the alication by clicking a link 

    in the bottom art of the +tudio$

  • 8/18/2019 CUBA Hands on Lab

    54/133

    65

    3irst launch and C/U

    3irst launch and C/U

  • 8/18/2019 CUBA Hands on Lab

    55/133

    66

    #ogin screen

    The system login screen has aeared$ This is a standard CUBA screen' which can be custom

    in CUBA' to meet secific reuirements$

    =$ Click !u+mit to login

    3irst launch

    3irst launch and C/U

  • 8/18/2019 CUBA Hands on Lab

    56/133

    69

    Order browser 

    +ince we have not changed the alication menu' our items are dislayed by default under

    menu$

    =$ Oen Application 1 #rders from the menu

    This is a standard browser screen with a filter

    on to and a table below$

    U1

    3irst launch

    3irst launch and C/U

  • 8/18/2019 CUBA Hands on Lab

    57/133

    6;

    Order edit screen

    =$ Click Create and enter the description

    2$ +elect +tatus. "ew

    &$ Click button 789 to select a client  for the order 

    U1

    3irst launch

    3irst launch and C/U

    3irst launch and C/U

  • 8/18/2019 CUBA Hands on Lab

    58/133

    6<

    Client browser 

    +o far we dont have any clients$ #et8s create one$

    =$ Click Create

    2$ 3ill attributes of the new client

    "ame. lex

    Phone num+er. 444344344

    %mail. alex5test.com

    &$ Click #$

    5$ Click !elect to set client to the order 

    U1

    3irst launch

    3irst launch and C/U

    mailto:[email protected]:[email protected]

  • 8/18/2019 CUBA Hands on Lab

    59/133

    6>

    Assign mechanic for the order 

    Dou are now back to the !rder  editor screen

    =$ Click button 789 at the right of the mechanic field in the #rder editor

    2$ Click Create to add a new mechanic

    &$ %nter hourly rate

    5$ +elect admin user for this mechanic

    6$ Click #$

    9$ +elect mechanic for the order 

    Dou can go back to any of oened screens

    using navigation at the to of screen$

    U1

    3irst launch

    3irst launch and C/U

  • 8/18/2019 CUBA Hands on Lab

    60/133

    9?

    C/U alication

    =$ Click #$ to save the order 

    This is a small working C/U alication that writes data to the database and allows you to si

    orders$

    ,e can search for orders using our 3ilter$

    Table comonent enables us to hide

    and change width of columns$ Also

    our table is sortable$

  • 8/18/2019 CUBA Hands on Lab

    61/133

    9=

    1ntegration with 1% and roject struct

    1ntegration with 1% and roject structure

  • 8/18/2019 CUBA Hands on Lab

    62/133

    92

    @o to the 1%

    7ee your alication u and running and follow the stes.

    =$ #aunch 1ntelli* 1%A$ The 1% should be u and running to enable integration with the CUBA

    2$ @o to the +tudio and click the (D% button in the Pro&ect properties section

    The roject will come u in the 1%$

    j

    1ntegration with 1% and roject structure

  • 8/18/2019 CUBA Hands on Lab

    63/133

    9&

    Project structure

    By default any roject consists of 5 modules. )lo+al' core' we+' )ui$

    The )lo+al module contains data model classes' core " middle tier services' )ui " screens and

    " web client"secific code$

    Dou can have other clients in your roject'

    such as a deskto alication or a web ortal'

    which will be laced in searate modules$

    The roject root directory contains

    the alication build scrits$

    Alications are built using @radle$

    CUBA +t di 1% i t ti

    1ntegration with 1% and roject structure

  • 8/18/2019 CUBA Hands on Lab

    64/133

    95

    CUBA +tudio 1% integration

    =$ @o to the !creens section of the navigation anel in the CUBA +tudio

    2$ +elect the order-edit23ml screen

    &$ Click the (D% button on to of the section

    1ntelli* 1%A will oen the order-edit23ml file$

    ,e can edit any file of the roject manually

    using 1ntelli* 1%A (or your favorite 1%)$

    + t d f lt +t t f d

    1ntegration with 1% and roject structure

  • 8/18/2019 CUBA Hands on Lab

    65/133

    96

    +et default +tatus for an order 

    +tay in the 1% and follow the stes.

    =$ !old Ctrl button and click on !rderEdit  in class attribute of the J:# descritor to navigate t

    imlementation

    2$ Override method initNew"tem

    &$ +et status !rderStatus.NE-  to the assed order 

     public class OrderEdit extends AbstractEditor {

      @Override

       protected void initNewItem(Order item) {

      super.initNewItem(item);

      item.setStatus(OrderStatus.NEW );

      }

    }

    ! t d l

    1ntegration with 1% and roject structure

  • 8/18/2019 CUBA Hands on Lab

    66/133

    99

    !ot deloy

    =$ Oen our alication in the browser 

    2$ Oen0/eoen Application 1 #rders screen

    &$ Click Create

    5$ ,e see our changes' although we havent restarted the server 

    6$ The CUBA +tudio automatically detects and the

    hot"deloys changes' e4cet for the data

    model' which saves a lot of time while

    U1 develoment

  • 8/18/2019 CUBA Hands on Lab

    67/133

    9;

    @eneric filter 

    3ilter comonent

    @eneric filter 

  • 8/18/2019 CUBA Hands on Lab

    68/133

    9<

    3ilter comonent

    =$ Add a few orders to the system

    2$ Click Add new condition

    &$ +elect Client

    5$ +et lex as value for condition for the Client attribute

    6$ +elect Description

    9$ Change 7:9 oeration to 7contains9

    ;$ %nter a word to Description field

  • 8/18/2019 CUBA Hands on Lab

    69/133

    9>

    Actions

    +tandard actions

    Actions

  • 8/18/2019 CUBA Hands on Lab

    70/133

    ;?

    +tandard actions

    The standard screens contain Create' %dit' and 0emove actions by default$

    #ets add an action to e3port the order list to %3cel$

    =$ Oen order-+rowse23ml screen in the +tudio$2$ +elect table comonent' go to roerties anel

    &$ Click the edit button in the actions roerty

    ;2 Add a new action row to the list

    6$ +ecify id as excel for this action

    9$ Click #$

    %4cel action

    Actions

  • 8/18/2019 CUBA Hands on Lab

    71/133

    ;=

    %4cel action

    =$ Add a new button to the button anel (dru) and drop it into the hierarchy of comonents

    2$ +elect ordersTable.excel action for button using roerties anel

    &$ +ave the screen

    5$ Oen0/eoen the #rders screen6$ Click %3cel to e4ort your orders to an 4ls file

    The latform has standard actions for

    common oerations. Create' %dit' 0emove'

    (nclude' %3clude (for sets)' 0efresh' %3cel'

    and you can create your own actions$

  • 8/18/2019 CUBA Hands on Lab

    72/133

    ;2

    +ecurity

    +ecurity subsystem

    +ecurity

  • 8/18/2019 CUBA Hands on Lab

    73/133

    ;&

    +ecurity subsystem

    The latform has built"in functionality to manage users and access rights$ This functionality is a

    Administration menu$

    The CUBA latform security model is role"based and controls C/U ermissions for entities' attmenu items and screen comonents and suorts

    custom access restrictions$

    All security settings can be configured at runtime$

    There is also an additional facility to control

    row level access$

    :echanic role

    +ecurity

  • 8/18/2019 CUBA Hands on Lab

    74/133

    ;5

    :echanic role

    ,e need the 'echanic role for our alication$ A 'echanic will be able to modify an order a

    number of hours they sent' and add or remove sare arts$ The 'echanic role will have limi

    functions$ Only admin will be allowed to create orders' clients and sare arts$

    =$ Oen Administration 1 0oles from the menu

    2$ Click Create

    &$ +et "ame. Mechanic

    +creen ermissions

    +ecurity

  • 8/18/2019 CUBA Hands on Lab

    75/133

    ;6

    +creen ermissions

    ,e want to restrict access to Administration screens for all 'echanic users' so lets forbid the

    menu and 0eports menu items$ Also' mechanics dont need access to the mechanics and cl

    lets forbid the corresonding screens$

    =$ +elect 0eports row in the table with !creens

    2$ +elect deny checkbo4 at the right

    &$ +imilarly deny access for Administration'

    Clients and 'echanics

    C/U ermissions

    +ecurity

  • 8/18/2019 CUBA Hands on Lab

    76/133

    ;9

    C/U ermissions

    =$ Oen the %ntities tab

    2$ Unset the Assi)ned #nly checkbo4

    &$ Click Apply

    5$ +elect the Client  entity and forbid create' update and delete oerations6$ +ame for the Mechanic and Spare,art  entities

    9$ 3or #rder' well restrict only create and delete

    Attribute ermissions

    +ecurity

  • 8/18/2019 CUBA Hands on Lab

    77/133

    ;;

    Attribute ermissions

    =$ Oen the Attri+utes tab

    2$ Unset the Assi)ned #nly checkbo4

    &$ Click Apply

    5$ +elect #rder row and tick read only for client 'mechanic and description

    6$ +et hide for amount attribute

    9$ Click #$ to save the role

    Few user

    +ecurity

  • 8/18/2019 CUBA Hands on Lab

    78/133

    ;<

    Few user 

    =$ Oen Administration 1 Users from the menu

    2$ Click Create

    &$ +et *o)in. jack

    5$ +ecify assword and assword confirmation6$ +et "ame. Jac

  • 8/18/2019 CUBA Hands on Lab

    79/133

    ;>

    /ole based security in action

    =$ #ogin to the system as jack

    =2 0eports and Administrations menus are now hidden

    &$ Oen Application 1 #rders from the menu

    ;2 %dit e4isting order 6$ The description' client  and mechanic fields

    are readonly

    9$ The amount  field is hidden

    /ow level security

    +ecurity

  • 8/18/2019 CUBA Hands on Lab

    80/133

  • 8/18/2019 CUBA Hands on Lab

    81/133

  • 8/18/2019 CUBA Hands on Lab

    82/133

  • 8/18/2019 CUBA Hands on Lab

    83/133

  • 8/18/2019 CUBA Hands on Lab

    84/133

  • 8/18/2019 CUBA Hands on Lab

    85/133

  • 8/18/2019 CUBA Hands on Lab

    86/133

  • 8/18/2019 CUBA Hands on Lab

    87/133

  • 8/18/2019 CUBA Hands on Lab

    88/133

  • 8/18/2019 CUBA Hands on Lab

    89/133

    Business logic changes can haen very often' so it would be better to ut it in a searate cla

    different system arts will be able to invoke to calculate the rice for reair$ #ets create a stu

    from the +tudio and imlement the rice calculation logic there$ And in our screen' well crea

    invoke this service$

    =$ @o to the !ervices section in the +tudio

    2$ Click "ew

    &$ Change the last art of 1nterface name to

    !rderService

  • 8/18/2019 CUBA Hands on Lab

    90/133

    Add method to a service

    +ervices

  • 8/18/2019 CUBA Hands on Lab

    91/133

    >=

    =$ Click #$ to save interface stub

    2$ +elect the !rderService item in the navigation anel

    &$ Click (D%

    5$ 1n the 1ntellij 1%A' well see the service interface' lets add the amount calculation methodBi*+ecimal calculatemount8!rder order9

     package com.coman!.wor"s#o.service;

    import com.coman!.wor"s#o.entit!.Order;

    import $ava.mat#.%i&'ecima;

     public interface OrderService {

      Strin& NAME "workshop_OrderService";

      %i&'ecima cacuateAmount(Order order);

    }

    +ervice method imlementation

    +ervices

  • 8/18/2019 CUBA Hands on Lab

    92/133

    >2

    =$ @o to !rderServiceBean using the green navigation icon at the left

    2$ 1mlement the method

     package com.coman!.wor"s#o.service;

    import com.coman!.wor"s#o.entit!.*;

    import or&.srin&+ramewor".stereot!e.Service ;

    import $ava.mat#.%i&'ecima;

    @Service(OrderService.NAME )

     public class OrderService%ean implements OrderService {

      @Override

       public %i&'ecima cacuateAmount(Order order) {

      %i&'ecima amount new %i&'ecima(,);

      if (order.&et-oursSent() null) {

      amount amount.add(new %i&'ecima(order.&et-oursSent())  .muti!(order.&et/ec#anic().&et-our!0ate()));

      }

      if (order.&et1arts() null) {

      for (Sare1art art 2 order.&et1arts()) {

      amount amount.add(art.&et1rice());

      }

      }

      return amount;

      }

    }

    Call the service method from U1

    +ervices

  • 8/18/2019 CUBA Hands on Lab

    93/133

    >&

    =$ @o back to the +tudio

    2$ +elect the order-edit23ml screen in the !creens section of the navigation anel

    &$ Click (D%

    5$ @o to the screen controller (!rderEdit  class)6$ Add !rderService field to class and annotate it

    with (n&ect annotation

    9$ Override the preCommit89 method and

    invoke the calculation method of !rderService

     public class OrderEdit extends AbstractEditor {

      @In$ect

       private OrderService orderService;

      33 ...

      @Override

       protected boolean re4ommit() {

      Order order &etItem();

      order.setAmount(orderService.cacuateAmount(order));

      return super.re4ommit();

      }

    }

    Test the service call

    +ervices

  • 8/18/2019 CUBA Hands on Lab

    94/133

    >5

    =$ /estart your alication using the 0un 1 0estart application action from the +tudio

    2$ Oen Application 1 #rders from the menu

    &$ Oen editor screen for any order 

    5$ +et Hours !pent6$ Click #$ to save order 

    9$ ,e can see a newly calculated value

    of the amount in the table

  • 8/18/2019 CUBA Hands on Lab

    95/133

    >6

    Charts

    Charts

    Charts

  • 8/18/2019 CUBA Hands on Lab

    96/133

    >9

    #ets assume our mechanic uses and likes the alication but now he wants to add statistics$

    showing the amount of orders er mechanic to reward them at the end of the month$

    To imlement this functionality well use the charts module of the CUBA latform' based on AmCharts$

    1t allows us to dislay interactive charts in

    a web alication based on system data

    and secify chart configuration via J:#$

    Add chart comonent to screen

    # t l th k di t ib ti h t th h i b

    Charts

  • 8/18/2019 CUBA Hands on Lab

    97/133

    >;

    #ets lace the work distribution chart on the mechanics browser screen$

    =$ Oen mechanic-+rowse23ml  screen in the +tudio

    2$ Place the cursor into the comonents alette' tye Chart &$ The +tudio will filter the comonent list and show

    us comonents to dislay charts

    5$ rag PieChart and dro it to the U1 editor area

    6$ +et id for chart. ratin*Chart 

    9$ +et width =??N and height 2??4

    using Properties anel

    ;$ Click #$ to save the screen

    #oad data for chart

    T l d d t f h t l t d l th d i ! d S i

    Charts

  • 8/18/2019 CUBA Hands on Lab

    98/133

    ><

    To load data for our chart' lets declare a new method in !rderService$

    =$ @o to !rderService from the +tudio by selecting the service and clicking the (D% button

    2$ Add the method definition to the interface.

     package com.coman!.wor"s#o.service;

    import com.coman!.wor"s#o.entit!./ec#anic;

    import com.coman!.wor"s#o.entit!.Order;

    import $ava.mat#.%i&'ecima;

    import $ava.uti./a;

     public interface OrderService {

      Strin& NAME "workshop_OrderService";

      %i&'ecima cacuateAmount(Order order);

      /a &et/ec#anicOrdersStats();

    }

    CUBA Persistence

    Th th d ill t i th b f d f h h i f th d t b i

    Charts

  • 8/18/2019 CUBA Hands on Lab

    99/133

    >>

    The method will retrieve the number of orders for each mechanic from the database using a

    Persistence interface is resonsible for interaction with the database and allows you to create

    e4ecute oerations using EntityMana*er $

    =$ Oen the !rderServiceBean class

    2$ 1nject the ,ersistence object into the class

    &$ Add stub for *etMechanics!rdersStats method

    *PE# Euery

    ,ell use the following trivial *PE# uery to get the number of orders for each mechanic.

    Charts

  • 8/18/2019 CUBA Hands on Lab

    100/133

    =??

    ,e ll use the following trivial *PE# uery to get the number of orders for each mechanic.

     select o.mechanic: count8o.id9 ;rom workshop%!rder o *roup by o.mechanic

    1t aggregates orders by the mechanic field

    and returns the number of orders for each

    mechanic$

    The comlete imlementation of the method is

    available on the ne4t slide$

    ata loading using CUBA Persistence@Override

    Charts

  • 8/18/2019 CUBA Hands on Lab

    101/133

    =?=

    @7ransactiona

     public /a &et/ec#anicOrdersStats() {

      Entit!/ana&er em  persistence.&etEntit!/ana&er();

      8uer! 9uer! em.create8uer!(

      "select o.mechanic.id, count(o.id) " :

      "from workshopOrder o group b! o.mechanic");

      6ist resut6ist 9uer!.&et0esut6ist();

      /a stats new -as#/a();

      for (Ob$ect o 2 resut6ist) {

      ==I' mec#anicId (==I') o,;

      /ec#anic mec#anic em.+ind(/ec#anic.class5mec#anicId5 iew. MINIMAL );

      stats.ut(mec#anic5 (6on&)o?);

      }

      return stats;

    }

    1nject chart comonent to a screen

    = @o to the mechanic3browse screen using the +tudio (D% button

    Charts

  • 8/18/2019 CUBA Hands on Lab

    102/133

    =?2

    =$ @o to the mechanic3browse screen using the +tudio (D% button

    2$ Oen *ava controller (MechanicBrowse class)

    &$ Use Alt-(nsert shortcut to inject ratin*Chart  object to the controller 

    ata binding for chart

    ,e can connect the chart to data in two ways The first way is to use a data source returning

    Charts

  • 8/18/2019 CUBA Hands on Lab

    103/133

    =?&

    ,e can connect the chart to data in two ways$ The first way is to use a data source returning

    entities$ 1f we don8t have an entity' that describes the content of a chart item we cannot follow

    The second way is to use the +ata,rovider  interface' which allows us to use arbitrary data in a

    understood by the chart$

    Our data model doesnt have an entity

    that describes the stats on mechanics'

    so well use the second way$

    =$ Override the init89 method

    Use Ctrl-# to uick override

    2$ Add !rderService field with 5"nject  annotation

    Connect chart with data

    +et data to chart using

  • 8/18/2019 CUBA Hands on Lab

    104/133

    =?5

    +et data to chart using

  • 8/18/2019 CUBA Hands on Lab

    105/133

    =?6

    ,e have connected the data collection' but how will the chart know which fields to use for il

    Oen mechanic3browse.xml in the 1%

    =$ +ecify two attributes of the chart. value=ield 

    and title=ield$ They determine which fields

    will be used in the chart

    2$ Add a legend element to set osition of the

    legend for the chart.

     

    Oen screen with chart

    >2 0estart the alication using the +tudio

    Charts

  • 8/18/2019 CUBA Hands on Lab

    106/133

    =?9

    g

    2$ Oen Application 1 'echanics from the menu

    Fow we know e4actly who should get a bonus$

  • 8/18/2019 CUBA Hands on Lab

    107/133

    =?;

    /eorting

    /eorts

    A rare business alication goes without reorts$ Thats why our mechanic has asked us to ma

    /eorting

  • 8/18/2019 CUBA Hands on Lab

    108/133

    =?<

    showing undertaken work for a certain eriod of time$

    =$ Oen 0eports 1 0eports from the menu

    2$ Click Create 1 Usin) wiard

    &$ +elect %ntity. !rder  (workshop%!rder )

    5$ +et Template type. >

    6$ +et 0eport "ame. !rders

    9$ +elect 0eport type. )eport ;or list o; entities

    by ?uery

    ;$ Click !et uery

    /eort uery builder 

    0eport ?iard allows us to create a uery using the grahical e4ressions constructor$

    /eorting

  • 8/18/2019 CUBA Hands on Lab

    109/133

    =?>

    =$ Click Add

    2$ +elect the Created at attribute

    &$ Change oeration for created condition to 7:9

    5$ Click Add once again

    6$ +elect the Created at attribute

    9$ Change oeration for created condition to 7:9

    ;$ Click #$

  • 8/18/2019 CUBA Hands on Lab

    110/133

    ==?

    2$ Click #$

    &$ Click "e3t

    +ave reort

    =$ Click !ave to save the reort

    /eorting

  • 8/18/2019 CUBA Hands on Lab

    111/133

    ===

    Change arameter names

    The ?iard will oen the reort editor so that we can make additional changes' if needed$

    /eorting

  • 8/18/2019 CUBA Hands on Lab

    112/133

    ==2

    =$ Oen Parameters and Formats tab

    2$ %dit the CreateTs arameter 

    &$ +et Parameter Fame. Start date

    5$ Click #$

    6$ %dit the CreateTs1 arameter 

    9$ +et Parameter Fame. End date

    ;$ Click #$

  • 8/18/2019 CUBA Hands on Lab

    113/133

    ==&

    2$ +elect the reort

    &$ Click 0un

    5$ %nter !tart date and %nd date

    6$ Click 0un report

    The system has generated an 4!*4 file' we can

    download it and view its content$ ue to the

    fact that the reort temlates have the same

    format as the one that is reuired for the outut'

    we can easily reare temlates from

    customers reort e4amles$

    /eort editor 

    Dou can also create reorts manually using the )eport editor $ ata can be e4tracted via SA<

    /eorting

  • 8/18/2019 CUBA Hands on Lab

    114/133

    ==5

    0roovy scrits$

    The temlate is created in >9' +!C8>9' !+T ' @TM

  • 8/18/2019 CUBA Hands on Lab

    115/133

    ==6

    3ull Te4t +earch

    3ull Te4t +earch

    Our system stores information about sare arts' but there are uite a few of them$ 1t would b

    3ull Te4t +earch

  • 8/18/2019 CUBA Hands on Lab

    116/133

    ==9

    them simly by tying a string like we google in a browser$

    The CUBA Platform includes the Full Te3t !earch module

    based on Aache #ucene$ 1t inde4es content'

    including files of different formats' and enables

    te4t search using this inde4$

    +earch results are filtered according to security

    constraints$

    Adding sare arts

    =$ Oen Application 1 !pare Parts from the menu

    3ull Te4t +earch

  • 8/18/2019 CUBA Hands on Lab

    117/133

    ==;

    2$ Add sare arts.

     Shimano Saint M>/ =lat )ace ,edals

     Shimano >T S,+ >C )ace MD/ ,edals

    )oad ,edals

    &$ Add these sare arts to random orders

    Configure 3ull Te4t +earch 1nde4

    =$ Oen the +tudio

    2 @ t #th ti f th i ti l

    3ull Te4t +earch

  • 8/18/2019 CUBA Hands on Lab

    118/133

    ==<

    2$ @o to #thers section of the navigation anel

    &$ Click %dit for Full-Te3t !earch confi)uration

    5$ By default' the +tudio has added all our entities to the inde4 configuration$

    3rom this screen we can manage entities and fields

    that will be inde4ed

    6$ Click #$

    %nable 3ull Te4t +earch for the alication

    3urther configuration will be done via the CUBA interface$

    3ull Te4t +earch

  • 8/18/2019 CUBA Hands on Lab

    119/133

    ==>

    =$ Oen Administration 1 J'4 Console from the menu

    2$ This is a web version of the console for the

    *:J interfaceI it allows us to manage internal

    system mechanisms

    &$ 3ind =tsMana*er  using the

    !earch +y #+&ect"ame field

    5$ Oen =tsMana*er  

    6$ Change the %na+led roerty to true

    Add records to inde4

    =$ +croll down to see reindexll and processAueue methods of =tsMana*er 

    2 1 k th =t M i d ll89 th d

    3ull Te4t +earch

  • 8/18/2019 CUBA Hands on Lab

    120/133

    =2?

    2$ 1nvoke the =tsMana*er   reindexll89 method

    &$ 1nvoke the =tsMana*er   processAueue89 method

    5$ The system will dislay the current inde4ed

    number of records

    6$ Click Close

    3T+ in action

    >2 *o) out from the system

    = *o) in again

    3ull Te4t +earch

  • 8/18/2019 CUBA Hands on Lab

    121/133

    =2=

    =2 *o) in again

    &$ 1n the alication to anel' the search field will aear' allowing you to search through a

    objects

    5$ #et8s find something' for e4amle. race

    6$ Dou will see the screen with search results'

    which contains not only sare arts' but also

    orders that have sare arts with this word in

    its name

    3T+ integration with filters

    But what if we want to search only for sare arts-

    3ull Te4t +earch

  • 8/18/2019 CUBA Hands on Lab

    122/133

    =22

    =$ Oen Application 1 !pare Parts from the menu

    2$ +elect Full Te3t !earch checkbo4 in the filter anel

    &$ The te4t field will aear 

    5$ #et8s enter something' for e4amle. road

    6$ Click !earch

    9$ The table will dislay records that contain road

    in their description

    +o' now mechanics will be able to find sare arts

    by descrition uickly

  • 8/18/2019 CUBA Hands on Lab

    123/133

    =2&

    Audit

    Audit

    1t haens when one day someone has accidentally erased the order descrition$ 1t is not a

    the client on the hone aologiKe and ask them to reeat the what needs to be done #ets

    Audit

  • 8/18/2019 CUBA Hands on Lab

    124/133

    =25

    the client on the hone' aologiKe and ask them to reeat the what needs to be done$ #et s

    be avoided$ CUBA has a built"in mechanism to track entity changes' which you can configure

    oerations with critical system data$

    #ets aly it for logging order changes$

    =$ Oen Administration 1 %ntity lo) from the menu

    2$ @o to the !etup tab

    &$ Click Create

    5$ +et "ame. !rder  (workshop%!rder )Auto. true

    Attri+utes. all

    6$ Click !ave

    Audit in action

    =$ #et8s change an order descrition (or even clean it u)

    2 Oen Administration 1 %ntity *o)

    Audit

  • 8/18/2019 CUBA Hands on Lab

    125/133

    =26

    2$ Oen Administration %ntity *o)

    &$ Click Clear to reset security records filter 

    5$ Click !earch

    The table shows changes and the user that made

    them' the changed fields and their new values$

    By sorting the changes by date and filtering them

    for a articular record' well be able to restore

    the entire chronology of events$

  • 8/18/2019 CUBA Hands on Lab

    126/133

    =29

    /%+T"AP1

    Portal module

    #ets try to add one more tye of interface to our roject " web ortal$ +imilar to the web clien

    deloyed searately from the middle tier$ +imilar to the web client' it will have access to the m

    /%+T"AP1

  • 8/18/2019 CUBA Hands on Lab

    127/133

    =2;

    y y '

    services' even in distributed configuration$ The ortal is intended for a customer faced cl ients

    devices or fancy web ages$

    >2 #pen the +tudio

    =2 !top the alication

    &$ @o to the Pro&ect properties section

    5$ Click the Create portal module link 

    6$ Confirm action by clicking #$

    9$ At the bottom of the +tudio window' well see

    a new link to the ,eb ortal age

    @eneric /%+T AP1

    The ortal is a classic +ring :LC alication that has access to the entities and services of t

    system$ A new module' portal' will be added to our roject$ 1t will have the source code of +

    /%+T"AP1

  • 8/18/2019 CUBA Hands on Lab

    128/133

    =2<

    y p j

    controllers and configuration files$

    1n addition to classic +ring :LC alication based on the ortal module' you can build A*A

    alications that use the /%+T interface to access the data$ The universal 0%!T-AP( of the lat

    to load and save all entities defined in the alication data model by sending simle !TTP re

    This rovides an easy way to integrate with a wide range of third"arty alications from th

    code' e4ecuted in the browser' to mobile alications or arbitrary systems running *ava' $F%T

    other latform$

  • 8/18/2019 CUBA Hands on Lab

    129/133

    /%+T AP1 H *PE# uery

    #ets load the list of new orders in *+OF using the following uery.

     select o ;rom workshop%!rder o where o.status F /

    /%+T"AP1

  • 8/18/2019 CUBA Hands on Lab

    130/133

    =&?

    /%+T"AP1 reuest.

    htt.00localhost.

  • 8/18/2019 CUBA Hands on Lab

    131/133

    =&=

    Dou can run it in roduction environment (including clouds) as is and it will be suitable for its

    Dou can add much more functionality using CUBA additional modules' and this enables you

    alication to big strong solution$

    ,e have many more featuresM

    1n this session covers just a few features of CUBA' but

  • 8/18/2019 CUBA Hands on Lab

    132/133

    =&2

    the latform has many more$$$

    1f you want to learn more about additional modules

    and comonents just take a look at CUBA

    documentation.

    htts.00www$cuba"latform$com0manual 

    https://www.cuba-platform.com/manualhttps://www.cuba-platform.com/manual

  • 8/18/2019 CUBA Hands on Lab

    133/133

    =&&

    Guestions

    Lisit our forum

    htts.00www$cuba"latform$com0suor

    https://www.cuba-platform.com/supporthttps://www.cuba-platform.com/support