0% found this document useful (0 votes)
28 views40 pages

Python Guide for Enterprise Integration

This document serves as a technical guide for using the Enterprise Integration Framework on DS Cloud with Python. It covers essential concepts such as web services, event management, and provides practical examples for integrating external ERP systems. The guide is designed for users with a basic understanding of Python and web services, offering step-by-step instructions and code samples to facilitate learning and implementation.

Uploaded by

fibrilado
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views40 pages

Python Guide for Enterprise Integration

This document serves as a technical guide for using the Enterprise Integration Framework on DS Cloud with Python. It covers essential concepts such as web services, event management, and provides practical examples for integrating external ERP systems. The guide is designed for users with a basic understanding of Python and web services, offering step-by-step instructions and code samples to facilitate learning and implementation.

Uploaded by

fibrilado
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

DS Cloud

Enterprise Integration Framework


© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021

Web Services and Event management using


Python

Å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

Integration Framework on DS Cloud


 The examples are written in Python, which is a beginner friendly language and also easily to
translate to other languages
 Included are the following concepts:
 Web Services (using Python ”requests” module)
 Event Management (using Python ”stomp” module)
 Building of a complete use case, ”Add Enterprise Item Number from external ERP”
 After completing the exercises in this guide, you will have a good understanding of the
Enterprise Integration Framework and can look into developing more advanced iPaaS solutions

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

”Value Engagement for All” community on the Partner Portal:

 Link
[Link]

5
Supporting files
Python examples provided with the guide
 [Link]
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021

 Contains credentials for DS Cloud login and Agent ID / password


 [Link]
 Various stand alone web services examples using DS Cloud
 [Link]
 Event listener example for listening on events from DS Cloud
 Example use case, ”Update Enterprise Item Number from external ERP”

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]

 This guide is based on Python 3.9.7


 Create a Virtual Environment (optional, but recommended)
 See [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

 pip install requests


 pip install [Link]

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]

 Create a folder for the Python code, e.g. “EIF”


 Open the folder in VSCode
 Create a new file, “[Link]” with a simple print statement
 Select the Python interpreter as
the virtual environment created earlier
 Verify that the code runs successfully

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

# Credentials for DS Cloud


username = ‘your username'
password = ‘your password'

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

launch the ”Agent Management” widget


 Create a new agent. Impersonated user should not have an Administrator role.

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

Update the corresponding variables in


[Link] and [Link]
13
Preparation
DS Cloud Configuration – Event Publishing
 With the ”Enterprise Integration Architect” role assigned (requires PFI license),
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021

launch the ”Event Publishing” widget


 Enable all events

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

calling Web Services with Python


 We will use the ”requests” library (added as a preparation step earlier)
 A basic understanding of Web Services is recommended, e.g. using Postman and the guide linked
earlier (on the ”Value Engagement For All” community)
 The following Web Services are used in the Python code examples:
 Get Login Session
 Get CSRF Token
 Search Engineering Items
 Get Engineering Item
 Add/Modify/Get Enterprise Item Number
See Developer Assistance for details
16
on all available Web Services
Web Services
Introduction
 In [Link], the following functions are defined:
© 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

 Verify that the variables in the beginning of [Link] are updated


 Uncomment the code for ”Example 1” in [Link]
 Update ”search_string” to something that will give a few search hits
 Run the code, the resulting JSON structure with the search result will be printed

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

 Update the ”id” to an id for an engineering item


 Use the previous example to find this, it’s the ”id” field in the JSON data
 Run the code, the resulting JSON structure with the engineering item will be
printed

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

 Update the ”id” to an id for an engineering item


 Run the code, verify the output

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

Developer Assistance for a detailed technical description


 It’s possible to listen and subscribe to these messages using external frameworks /
applications
 We will use Python and the ”Stomp”
library to achieve this, starting by
configuring the Stomp listener and then
verify we can view the events
 Next step is to build a more advanced
use case, involving updating the
Enterprise Item Number automatically

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”

See the following link for a quick start


guide on [Link]
25 [Link]
Event Listener
Example 1 – Listen on event
 Verify that the agent credentials are correct in [Link]
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021

 Verify that the variables in the beginning of [Link] are updated


 Uncomment the code for ”Example 1” in [Link]

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

 On DS Cloud, open the 3DSpace widget and upload a document to a


collaborative space:

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

 A new event (item created) will be generated from DS Cloud


 Note thatthere is a delay of up to 5 minutes before the event is sent, as it’s only done after
a new indexation has been run
 When the event is received, check the output (Document created):

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

Use Case Example

Update Enterprise Item Number from external


ERP when engineering item is created

31
Use case example
Punctual Operations
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021

What How

Punctual Operations • iPaaS / Custom service for Integration


Enterprise Numbering

• 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

Front Left Wing Get Eng Item Meta-data information


V1
Eng. Item
Id = 85CB466DA3B1256000027C ✔
{

Name = prd-16454-0000125 ✔ "name":"prd-16454-0000125",


"title":"Font Left Wing",

Title = Font Left Wing ✔ "id":"85CB466DA3B1256000027C",


"created":"Dec 11, 2018 12:53 PM",
...
✔ }
Geometry1

2
Generate ERP
Request body
{
”BaseMeasureUnitType":”Piece",
”Description":"Font Left Wing",
3
”MaterialCrossProcessCategory":

...
{”ProductCategoryInternalId":”103”} iPaaS calls ERP to generate Material and Part Number
}

Front Left Wing


V1
Eng. Item {
Material ID PN1368
”MaterialId” : ”PN1368”,

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 ✔

Part Number = PN1368


✔ 5
Update Eng Item with Part Number 4
{
"name":"prd-16454-0000125", Generate
"title":"Font Left Wing",
"id":"85CB466DA3B1256000027C", 3DEXPERIENCE
"created":"Dec 11, 2018 12:53 PM",
“Part Number”:"PN1368" Request body
33 ...
}
There is no connection to a real
Event Listener use case ERP system in this example, but the
code can easily be expanded to
Example 2 – Add Enterprise Item Number from ERP include such integration.
 Uncomment the code for Example 2 in [Link]
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021

 Run the code


 Create a new Engineering Item
 When the event is received, a new Enterprise Item Number will be created
(simulating an external ERP)
 The Enterprise Item Number will be added to the newly created Engineering Item
34
Event Listener use case
Example 2 – Add Enterprise Item Number from ERP
 Verify that the Enterprise Item Number has been added:
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021

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

and Event management using the Enterprise Integration Framework


 The next step can be to look into various framworks and iPaaS solutions, e.g:
 Node-RED ([Link]
 Apache NiFi ([Link]

Integration Platform as a Service (iPaaS) is a suite of


cloud services enabling development, execution and
governance of integration flows connecting any
combination of on premises and cloud-based processes,
services, applications and data within individual or across
37
multiple organizations.
Where to go from here
Summary and wrap up
 Enterprise Integration Framework Communities
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021

 Community link for DS Internal -> Enterprise Integration Framework Forum


 Community link on Partner Portal -> Enterprise Integration Framework Pilots
 Developers Guides on [Link]:

38
Web Services reference
 Developer Assistance on DS Doc
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021

Examples of the many


39
Web Services available
© Dassault Systèmes | Confidential Information | 11/1/2021 | ref.: 3DS_Document_2021

40

You might also like