Hello Linx

The HelloLinx sample solution is pre-loaded on your Linx Application Server, which is hosted in the Linx Application Cloud.

The following is included in the sample environment:

  • The HelloLinx solution that is already deployed to Linx Application Server.

  • A SQLite database, with a Greetings table that contains 2 columns: Name and Greeting.

  • A folder called hellolinx, with the following sub-folders:

    • import
    • archive
    • samples (containing sample text files that can be used when running the solution)


What does the sample solution do?

The HelloLinx solution has a timer event that executes at 1 minute intervals (configurable) to check in the import folder for the existence of text files.

If a text file exists, a new record is written to the Greetings table of your database, with the file name (without the .txt file extension) inserted into the Name column of the table and the file's content inserted into the Greeting column.

Note:

  • The idea is to add a text file that has a person's name as the file name (e.g. John.txt) and with a greeting as the file content, e.g. "Hi there!". There are a few sample files in the samples folder of your F-drive.

The text file is then automatically moved from the import directory to the archive directory.

The solution also has a REST web service with 2 paths (operations):

  • /hello/{name} - This operation checks in the Greetings table for a record of the name provided in the web service- URL. (Existence of the database record is dependent on the Timer event already having found a file with a file name of the same value as the name provided in the URL, and successfully writing the record to the database, as explained above.) If the database record is found, the associated greeting is displayed in the browser.

  • /joke - This operation calls an API (http://api.icndb.com/jokes/random) that returns a random joke. The joke is then displayed in the browser.


Download

HelloLinx


What you see when you open HelloLinx

When you open the HelloLinx solution in the Linx Application Designer, you will see the following:

Solution Explorer

The Solution Explorer is in the top-left of your screen and displays the high-level "containers" that make up your solution. In this case:

  • Solution: HelloLinx
  • Project: LinxProject
  • CustomType: ChuckNorrisJson
  • Services and their associated service events: RESTService (Hello and Joke), and Timer (TimerEvent)


Click on TimerEvent.

Main canvas

The main canvas, located in the centre of the screen, displays the Functions and Types that provide the functionality of a process or service. In the case of the TimerEvent, there is a FileList Function, and nested below that, these Functions: TextFileRead, ExecuteSQL (renamed to DBInsertNewGreeting) and FileMove.

Each Function and Type has a set of properties for which specific values can be set to determine the behaviour of that Function or Type.


Click on FileList.

Properties section

The Properties section is in the bottom-left of the screen and displays the properties associated with the selected Function, Type or Service. In the case of FileList, the available properties include Folder path and Search pattern.

Plugins section

The Plugins section, on the right of the screen, displays all the Plugins that have been added to the Solution. (To add more plugins, click the Add Plugins button at the top of the section.) Each Plugin contains Functions, Types and Services that can be added to a process or service event, by dragging and dropping them onto the main canvas.


How HelloLinx was created

The design process of adding functionality to the HelloLinx solution, involved the following:


1.   Add plugins to the Solution

In the Plugins section, click the Add Plugins button and then add these plugins:

  • Database
  • File
  • Web


2.   Add a Timer service

From the Utilities plugin, drag the Timer service onto the Solution Explorer section.

2.1   Set the Timer's execution times

Set the Timer's properties:

  • Mode: Select Interval

  • Run every: instead of entering a specific value here, add a re-usable Setting that can easily be updated on the server. (To add, click on Settings on the toolbar, then add the Name (TimerInterval), Type, and a Value of 00:01:00.)

  • Back to the Timer properties: now select TimerInterval for the Run every property.


2.2   Design the Timer Event

Click on the Timer's TimerEvent.

  • Drag the FileList function onto main canvas.
    • Set these properties:
      • Folder path: F:\mydrive\hellolinx\import\
      • Loop results: Select
      • Search pattern: *.txt
  • Drag TextFileRead onto main canvas, below 'File'.
    • Set these properties:
      • File path: ="F:\mydrive\hellolinx\import\" + FileList.File.FileName
  • Drag ExecuteSQL onto the main canvas, below 'TextFileRead'
    • Set these properties:
      • Connection type: ODBC
      • Connection string: Driver={SQLite3 ODBC Driver};Database=F:\mydrive\hellolinx\greetings.sqlite3;
      • SQL: Click on [...] to view the SQL statement in SQL Editor. The statement inserts the name of the text file and the contents of the file into the Greetings table.
  • Drag FileMove onto the main canvas
    • Set these properties:
      • Source file path: ="F:\mydrive\hellolinx\import\" + FileList.File.FileName
      • Dest. folder path: F:\mydrive\hellolinx\archive
      • File exists: Select 'Increment file name'


3.   Add a REST web service

3.1   Define the API

  • Drag the RESTWebService service onto the Solution Explorer section.
    • Set these properties:
      • API description: The API contains operations (paths): Hello and Joke. Linx creates corresponding events for each.
      • Base URI: The URI where the web service will be published. The operation paths are appended to the base URI.


3.2   Design the Hello event

Click on the Hello event (When running the Hello operation, a user will submit a person's name as part of the web service URL, with a greeting being returned.)

  • Drag the ExecuteSQL function onto the main canvas
    • Set these properties:
      • Connection type: ODBC
      • Connection string: Driver={SQLite3 ODBC Driver};Database=F:\mydrive\hellolinx\greetings.sqlite3;
      • SQL: Click on [...] to view the SQL statement in SQL Editor. The statement selects the greeting that is associated with the name provided in the web service URL.
      • Return options: Select 'First row, else empty row'

  • Drag the IfElse function onto the main canvas
    • Set these properties:
      • Show else: Select
      • Stop when true: Select
      • Conditions:
        • Name: IfEmpty
        • Value: GetGreetingFromDatabase.Greeting == $.System.Null || GetGreetingFromDatabase.Greeting == ""

  • Drag the SetValue function onto the main canvas, under 'IfEmpty' and rename to 'SetOutputToInstructionalMessage'.
    • Set these properties:
      • Target: Select $.Output.Data

      • Source: In the Fields Editor, for Response200, add a message for when a greeting is not returned from the DB, i.e. when a corresponding text file was not placed in the import folder

  • Drag the SetValue function onto the main canvas, under 'Else' and rename to 'SetOutputToGreeting'
    • Set these properties:
      • Target: Select $.Output.Data

      • Source: In the Fields Editor, for Response200, add the value that must be returned to the web service user, i.e. =GetGreetingFromDatabase.Greeting


3.3   Design the Joke event

Before adding functions to the Joke event, a Custom Type (ChuckNorrisJson) is created to be used in the Joke event.

  • To Add, click on Custom Type on the toolbar
    • The Custom Type now appears in the Solution Explorer section
    • Rename the Custom Type to 'ChuckNorrisJson'
    • Set these Properties:
      • Name: in this case it is named 'value'
      • Type: String
      • Value: blank

  • Click on the Joke event. (When a user runs the Joke web service operation, a random joke will be retrieved from a jokes web service and returned to the user.)

  • Drag the CallRESTWebService function onto the main canvas
    • Set these properties:

  • Drag a String type onto the main canvas.
    • Set the property value to CallRESTWebService.ResponseBody.value, which is the joke that is returned from the web service call.

  • Drag a SetValue function onto the main canvas
    • Set these properties:
      • Target: $.Output.Data.Response200
      • Source: =FunctionOutput (this value representscreated the joke that was returned by the web service call)


Also see

How to create a Basic Solution

How to work with Plugins