Complex Service

Table of Contents

logo-large

Tutorial Actifsource Tutorial – Complex Service
Required Time - 60 Minutes
Prerequisites - Actifsource Tutorial – Installing Actifsource
- Actifsource Tutorial – Simple Service
Goal - Use Java Functions to reuse text fragments in your templates and capture complex expressions to keep your templates clean and easy to read

- Use Function Spaces to keep Java Functions organized
Topics covered - - Extracting Java Functions from template code
- Editing Java Functions
- Advanced Template Editor Context Operations
- Functions Spaces and Template Functions
- Built-in Java Functions
- Place generated code in specific folders
- Copy with Context
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

  • Prepare a new actifsource Project as seen in the Actifsource Tutorial – Simple Service

  • Learn how to extract Java Functions from template code to cope with complex situations
    image2 image2

  • Edit Java Functions

  • Learn about advanced Context Operations in the Template Editor

  • Learn about Function Spaces and how to place functions

  • Use built-in functions
    image3 image3

  • Generate code for specific folders

  • Copy template code with its Context

Part I: Preparation

  • Prepare a new actifsource Project as seen in the Actifsource Tutorial – Simple Service

    • Setup the Target Folder src

    • Create a Generic Domain Model

    • Create a Specific Domain Model

    • Create a Code Template

  • Use the following package structure

image4 image4

Create a Generic Domain Model

image5 image5

  • Create a Generic Domain Model in the DiagramEditor named ServiceDesign in the Package generic

  • The Design shall contain the following Domain Classes

    • Service, Call, Parameter, Type
  • Insert a Composition between

    • Service and Call

    • Call and Parameter

  • Insert a Association between

    • Call and Type

    • Parameter and Type

  • Adjust the Cardinalities as shown above

Warning: The layout for the relations transition and targetState might differ in your editor

Create a Specific Domain Model

image6 image6

  • Create a Service named Patient in the Package specific

  • Add the Calls Create and Delete

  • Add the Parameter LastName, FirstName and Id as shown above

  • Add the returnTypes as shown above

image7 image7

  • Create a Code Template named ServiceImpl in the Package template

  • Write code as shown above

  • The function shall be placed in the Context Call Selector is Service.call

  • The function parameters shall be placed in the Context Parameter; Selector is Call.parameter

  • Save the Code Template

image8 image8

  • You’ll find the generated code PatientImpl.java in the Target Folder src

Part II: Java Functions

  • Use Java Functions to

    • extract recurring text fragments from your templates

    • capture complex expressions to keep your templates clean and easy to read

  • Use Java Classes generated from your Generic Domain Model to write and maintain complex Java Functions

Extract Function

image9 image9

  • We should extract identical terms to honor the DRY principle (Don’t Repeat Yourself)
Info

Note that the term Service.name_Impl is used twice

image10 image10

  • In your template select the text you want to extract into a function
  • The light bulb at the left hand indicates Quick Assist is available

image2 image2

  • Activate QuickAssist by clicking the light bulb or by pressing Ctrl+1
  • Click Extract JavaFunction

image11 image11

  • Name the function className
  • Click Finish

Using Function

image12 image12

  • The new function className returns the extracted fragment from your template
  • The static function className is added to the static Java class ServiceImpl.ServiceFunctions in class ServiceImpl; this class is automatically generated by actifsource
  • The term Service.name_Impl has been replaced by the function Service.className
  • Java Functions are shown in italics in the actifsource Template Editor

image13 image13

  • Let’s replace the second occurrence of the term Service.name_Impl
  • Use Content Assist (Ctrl+Space) on Service to insert the function className for your class name

image14 image14

  • Open the underlying Function Model (Ctrl+Alt+Left-Click)
  • Alternatively, you can use the Tool Open Link in JavaEditor from the actifsource Template Editor toolbar image15 image15

Editing Functions

image16 image16

  • Change function declaration here if needed
  • Please notice that the Function declaration was placed in the template

image17 image17

image14 image14

  • Open the underlying Java Function (Ctrl+Left-Click)
  • Alternatively, you can use the Tool Open Link in JavaEditor from the actifsource Template Editor toolbar image18 image18

image19 image19

  • The class ServiceImpl is opened in the Java Editor showing your function className

image20 image20

Info

Note that actifsource generates a select method for each property of the corresponding class in the Generic Domain Model. You may use these methods to traverse your Generic Domain Model using the respective selectPROPERTY() methods in your Java Functions

image21 image21

  • Make sure to place additional imports within the corresponding Protected Regions
  • Please note that all code outside Protected Regions will be overwritten if the respective source file is re-generated.

Part III Function Spaces

  • Function Declarations are managed as actifsource Resources
  • All Function Declarations are placed in Functions Spaces
  • Templates are Functions Spaces by default
  • Functions Spaces can exist without Templates
  • Function Spaces are Resources and can therefore be placed in Packages

Advanced Context Operations

image22 image22

  • Let’s add a new line after the Call Context in the Service Context
  • Place cursor on the last position of the Call Context
Info

Note that the corresponding Context Bar is highlighted

image23 image23

  • Press Cursor-Right
  • While the cursor stays at its position, the Service Context is now highlighted
  • Alternatively, you can use the context navigation from the actifsource Template Editor toolbar image24 image24

image25 image25

  • Press Enter
  • A new line has been added in the Parent Context

Add Context via Quick Assist

image26 image26

  • Let’s look at a quick and easy way to insert a new Context
  • Insert the Variable Service.call using Content Assist (Ctrl+Space)

image27 image27

  • The light bulb at the left hand indicates Quick Assist is available
  • Activate QuickAssist by clicking the light bulb or pressing Ctrl+1

image28 image28

  • Click on Create Line Context

image29 image29

  • The Variable Service.call has been replaced by Call
Info

Note that a new Call Context (Selector: Service.call) has been added

Built-In Functions

image3 image3

  • Let’s use Built-In Functions on Attributes
  • Press '.' (dot) and Content Assist (Ctrl+Space) after name to see all available Built-In Functions

image30 image30

  • Complete the member variable declaration as shown above

Extract Function in Function Space

image31 image31

  • Call.name_Impl shall be the name of a new Template
  • Select the term Call.name_Impl
  • Activate QuickAssist by clicking on the light bulb or pressing Ctrl+1
  • Click Extract TemplateFunction
  • Template Functions behave like templates and are easier to handle than Java functions

image32 image32

  • Name the function className
  • Click New Template to create a new template which acts as Function Space for the new function className
Info

Note that the default Function Space for this new function is the Template ServiceImpl

image33 image33

  • Check the Package
  • Name the Template CallImpl
  • Press Finish

image34 image34

  • Press Finish
Info

Note that the Function Space has been changed from ServiceImpl to CallImpl

image35 image35

  • The Term Call.name_Impl has been replaced by Call.className@CallImpl
  • className@CallImpl indicates that the Function className belongs to the Function Space CallImpl

image36 image36

  • A new Template named CallImpl has been created in the Package template
  • Use the Function className in the file line of your template
Info

Note that className is the Function which we extracted in the template ServiceImpl before

image37 image37

  • Write a simple class as shown above
  • Write a method execute with returnType and Parameter
  • Please notice that you might copy the whole parameter expression from the ServiceImpl Template
  • Place a Protected Context in the function body

Templates and Folders

image38 image38

  • Open the underlying Template Function for className (Ctrl+Left-Click)
  • Alternatively, you can use the Tool Open Link in JavaEditor from the actifsource Template Editor toolbar image18 image18

image39 image39

  • The function className is handled as a Template Function (partial template)
  • Template Functions are easy to handle
  • A TemplateFunction may call itself to follow recursive meta model designs (Composite Pattern)

image40 image40

  • Generated artifacts are placed in the Target Folder of your project

  • You may want to place generated artifacts in specific sub folders

  • Add Service.name/ as folder information in the file line of the Template ServiceImpl as shown above

image41 image41

  • We want all Call implementations to be generated in the same folder as their corresponding Service
  • Add Service.name as the folder name in the file line of the Template CallImpl as shown above
  • Save the Templates CallImpl and ServiceImpl
  • Protected Regions of the generated files are preserved image42 image42
Info
  • Note that files generated from this template are moved to the new location automatically

Copy with Context

image43 image43

  • Extract a TemplateLineFunction memberName for the member variable name

image44 image44

  • Also use the function memberName in the function body as shown above

image45 image45

  • Open the underlying TemplateLineFunction for memberName (Ctrl+Left-Click)
  • Alternatively, you can use the Tool Open Link in JavaEditor from the actifsource Template Editor toolbar image18 image18

image46 image46

  • The function className is handled as a TemplateLineFunction
  • Template Line Functions are the easiest way to reuse information
  • Template Line Functions do not allow context

image47 image47

  • We want to copy Parameter.name including the Parameter Context and the separating comma from the functions parameter list
  • Select the Term Parameter.name
  • From the Context Menu, select Copy with Context
  • From the Subcontext Menu, select Parameter
Info

Note also the shortcuts Alt+PageUp to select the parent context, and Ctrl+C to copy a context

image48 image48

  • Place your cursor between the brackets
  • Select Paste from the Context Menu (Ctrl+V)

image49 image49

  • The text and its corresponding context are inserted

actifsource-point-large