Python Guide for Enterprise Integration
Python Guide for Enterprise Integration
Åke Johansson
EuroNorth Industry Process Consultant Senior
Enterprise Integration Framework with Python
Introduction and scope
This is a hands on technical guide on building various examples using the Enterprise
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
2
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
3
Preparation
Enterprise Integration Framework introduction
Recommended preparation
As introduction to the Enterprise Integration Framework, please have a look at
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
this post:
Link
[Link]
4
Enterprise Integration Framework introduction
Recommended preparation
An basic understanding of web services is recommended, please refer to the
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
Link
[Link]
5
Supporting files
Python examples provided with the guide
[Link]
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
6
Preparation Note!
A basic understanding of Python is
[Link] you need to catch up,
Python Environment
the following tutorial can be a good start:
Install Python 3 [Link]
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
[Link]
Run:
python -m venv EIF-env
EIF-env\Scripts\[Link]
7
Preparation
Python Environment continued
Using the activated virtual environment, import the following modules
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
8
Preparation
Visual Studio Code
Install Visual Studio Code (optional, any IDE or text editor can be used)
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
[Link]
9
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
10
Preparation
Visual Studio Code
Install the following recommended plugins in VSCode
Preparation
Credentials
Keep the user credentials separate from the main code as follows:
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
Update [Link] and add your username and password used on DS Public cloud
11
Preparation
DS Cloud Configuration - Agent
With the ”Enterprise Integration Architect” role assigned (requires PFI license),
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
Note!
Copy the Agent ID and Agent
Password to the [Link] file.
The Agent Password is only
12 displayed once after agent creation.
Preparation
DS Cloud Configuration – Service URLs
In the Agent Management app, open “Available Services”
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
14
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
15
Web Services tutorial
Web Services
Introduction
Before building more advanced business logic, it’s good to first practice on some basic examples
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
See the docstring in the beginning of each function for a detailed description
All web services besides ”get_login_session” uses the Basic authentication mode
(Agent id + password)
17
Web Services
Example 1 – Search engineering items
Verify that the agent credentials are correct in [Link]
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
18
Web Services
Example 2 – Get engineering item
Uncomment the code for ”Example 2” in [Link]
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
19
Web Services
Example 3 – Add enterprise item number
Uncomment the code for ”Example 3” in [Link]
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
20
Web Services
Example 4 – Get Enterprise item number
Uncomment the code for ”Example 4” in [Link]
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
Update the ”id” to the item with the added enterprise item number
Run the code, verify the output
21
Web Services
Example 5 – Update Enterprise item number
Uncomment the code for ”Example 5” in [Link]
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
Update the ”id” to the item with the added enterprise item number
Run the code, verify the output
22
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
23
Event Listener tutorial
Event Listener
Introduction
Events from DS Cloud 3DEXPERIENCE Platform are published on a message bus, see
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
24
Event Listener
Introduction
In [Link], the Stomp library is used for creating a listener that listens on events published
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
from DS Cloud
A custom class, ”EIFListener” is defined based on the Stomp library connection listener
The method ”on_message” is automatically called when a message is received
”on_message” uses various helper methods for e.g. printing of an incoming message,
checking for message type etc
”on_message” also handles the use case ”Add Enterprise Item Number from external
ERP when a new engineering item is created”
26
Event Listener
Example 1 – Listen on event (continued)
Run the code, a notification will be printed every 10:th second
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
Note!
Do this as the user that was defined in
27 the Agent earlier.
Event Listener
Example 1 – Listen on event (continued)
Continue to monitor the output from [Link]
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
Note!
The code will continue to run until
stopped manually. The Stomp listener
manages a thread for processing the
28 events.
Event Listener
Example 1 – Listen on event (continued)
In ENOVIA – Product Structure Editor, create a new part
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
Wait for the event to be published and verify the output (Engineering Item created)
29
Event Listener
Example 1 – Listen on event (continued)
In ENOVIA – Engineering Release, change the Maturity State of the part to
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
”Released”
Wait for the event to be published and verify the output (Status Changed)
30
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
31
Use case example
Punctual Operations
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
What How
• Event-based Architecture
WHEN : Eng Item is created in 3DEXPERIENCE
Events published by respective Services
WHAT : Part Number is allocated by ERP Message Bus Service to manage Events
WHY : Unique corporate item referential
• REST Web-Services
Design & Engineering (P) Provided by 3DEXPERIENCE platform
Services (e.g. 3DSpace)
32
Enterprise Integration : Eng. Item Part Number – Flow (Punctual Operation)
3DEXPERIENCE
iPaaS / Custom Service
Eng Item created
0 1
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
2
Generate ERP
Request body
{
”BaseMeasureUnitType":”Piece",
”Description":"Font Left Wing",
3
”MaterialCrossProcessCategory":
...
{”ProductCategoryInternalId":”103”} iPaaS calls ERP to generate Material and Part Number
}
Id = 85CB466DA3B1256000027C ✔ ”BaseMeasureUnitType":”Piece",
”Description":"Font Left Wing",
”MaterialCrossProcessCategory":
Material Name Front Left Wing
✔
Name = prd-16454-0000125 ...
{”ProductCategoryInternalId":”103”} Material Type Finished Product
Title = Font Left Wing ✔ }
Base Unit Piece
Geometry1 ✔
35
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
36
Where to go from here
Where to go from here
Summary and wrap up
The aim of this guide was to give various hands on examples on Web Services
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
38
Web Services reference
Developer Assistance on DS Doc
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021
40