File-based data - Insert JSON data in SQL-Database

Overview

This Scenario describes step by step how JSON-data can be inserted into an SQL database with the SMARTUNIFIER.

Scenario Overview

Prerequisite

JSON-file

{
 "equipmentId": "Equipment_A1234",
 "orderNr": "Order_000101",
 "materialNr": "A1C55100",
 "quality": "IO"
}

SQL-Server Database

Create Database Command: CREATE DATABASE unifier

Create Schema Command: CREATE SCHEMA dbo

Create Table Command: create table dbo.SU_DEMO_UC1_TABLE(EQUIPMENT_ID varchar(max), ORDER_NR varchar(max), MATERIAL_NR varchar(max), QUALITY varchar(max))

Or any other SQL Database supported by SMARTUNIFIER.

Information Model

Information Model - JSON-file

Create an Information Model that represents the structure of the JSON-file

Structure of the JSONFile Information Model:

  • Event that represents the trigger for the Mapping

  • Variables under the Event represent the key-value pairs from the JSON-file

Information Model - File

Information Model - SQL-Database

Create an Information Model that represents the database

Structure of the Database Information Model:

  • Event that represents the table of the database

  • Variables under the Event represent the columns within the table

Information Model - Database

Communication Channel

Communication Channel - JSON-file

In this scenario the JSON-file is processed by the SMARTUNIFIER with the build-in File Consumer

Create File Consumer Channel:

  • Select the JSONFile Information Model created previously

  • Select File reader (JSON) as Channel Type

Configuration:

  • Specify paths to following folder:

    • InFolder

    • ProcessFolder

    • OutFolder

    • ErrorFolder

Channel - File
  • Select the Event to configure the FileNameFilter

Channel - File

Communication Channel - SQL Database

In this scenario the JSON-file is processed by the SMARTUNIFIER with the build-in File Consumer.

Create Database Channel:

  • Select the Database Information Model created previously

  • Select SqlDatabase as Channel Type

Configuration:

  • Select the root node of the Information Model and configure the database access

Channel - Database
  • Select the Event node in the Information Model and configure the table settings

    • Enable the checkbox Insert

    • Enter the name for the Table as well as the Schema

Channel - Database
  • Select the Variable node EquipmentId in the Information Model and configure the columns (Repeat this step with the rest of the Variables)

    • Enable the checkbox AssignDatabaseColumn

    • Enter the name for the Column

Channel - Database

Mapping

Create a new Mapping with the Information Models created previously (JSONFile and Database).

Create a Rule that handles the assignment of values from the JSON-file to the database.

  • Enter a Rule Name

  • Drag and Drop the File Event into the Trigger field

  • Drag and Drop the DatabaseInsertEvent into the Actions panel

  • Assign source to target (Repeat for all Variables)

  • Drag and Drop the Variable equipmentId from the json model into the according Source field

Mapping

Device Type

Create a new Device Type.

  • Select the Mapping JsonToDB created previously

  • Assign the Channels (Database and JSONFile) to their belonging Information Model

DeviceType

Instance

Create a new Instance

  • Select the Device Type UC1_DeviceType created previously

  • Change the name of the Instance to UC1_Instance

  • If necessary: Changes of the Channel configuration can be made

Instance

Deployment

Create a new Local Deployment

  • Select the Instance UC1_Instance

  • Select the Log File Configuration Info (Defines the log level)

Add Deployment

Deploy and Start the Instance UC1_Instance

Deployment

Execution

In order to insert the data of the JSON-file into the SQL database move the file into the specified InFolder.