Skip to content

PoC of python API #3

@OlivierVoron

Description

@OlivierVoron

Initiate a first approach for implementing a client API for OperatorFabric:

  • create a branch
  • merge proposed pull request
  • correct initial errors (see below)
  • write in README.me how to use it
  • add a compatibility matrix with tested version of operator-fabric-getting-started server

Last updated: 27th August 2024

Initial errors

OperatorFabric server used for testing: operator-fabric-getting-started server (branch: release4.2.0)
The server should be launched prior to testing and the examples should have been run without errors.

Use Python 3.10 and import the requirements.
Then execute the following actions to test opfab.send_card() function:

import api
opfab = api.OperatorFabricClient("http://localhost:2002/", "admin", "test", "http://localhost:89/auth/realms/dev/protocol/openid-connect/token")
opfab.send_card()

Actual status of identified errors when calling opfab.send_card() function:

  • Error01 - DONE- "Cannot invoke "java.util.List.stream()" - found a solution by changing the sending card url and correcting some default fields - see additional commit after merged pull request
  • Error02 - DONE- BAD_REQUEST ‘process and/or state does not exist’- found a solution by checking the existing of a bundle, process and perimeter for the version used in the card
  • Error03 - DONE- 301 Moved Permanently - found a solution by removing trailing `/ in nginx.conf
  • Error04 - DONE - no i18n translation for key=defaultProcess.title - found a solution by changing the keys used for summary and title to correspond to existing i18n values. Please notice that the i18.json file is not similar between the process version 1 and 2 and some keys do not exist in both versions.

Error01 - error when calling opfab.send_card() - Cannot invoke "java.util.List.stream()"

When sending card using defaultProcess values by using simple opfab.send_card() , the following results:
Content of the card sent:

{
  "publisher": "message-publisher",
  "process": "defaultProcess",
  "processVersion": "2",
        "processInstanceId": "hello-world-1",
  "state": "messageState",
  "severity": "INFORMATION",
        "startDate": 1724743760203,
        "summary": {
                "key": "defaultProcess.summary"
        },
        "title": {
                "key": "defaultProcess.title"
        },
  "data": {
    "message": "Hello World !!! That's my first message"
  },
  "groupRecipients": [
    "Dispatcher"
  ]
}

ERROR results of POST opfab card-publication url command:

...
'localizedMessage': 'Cannot invoke "java.util.List.stream()" because the return value of "org.opfab.cards.consultation.model.CardsFilter.getFilters()" is null'

>>> opfab.send_card();
DEBUG 2024-08-27 15:46:07,494 api                            send_card             339 : {
    "publisher": "message-publisher",
    "process": "defaultProcess",
    "processVersion": "2",
    "processInstanceId": "3616755b-cbff-461a-bb06-97f5a424d3f5",
    "state": "messageState",
    "severity": "INFORMATION",
    "summary": {
        "key": "defaultProcess.summary"
    },
    "title": {
        "key": "defaultProcess.title"
    },
    "startDate": 1724769967494,
    "data": {
        "message": "Hello World !!! That's my first message"
    },
    "groupRecipients": [
        "Dispatcher"
    ]
}
DEBUG 2024-08-27 15:46:07,495 urllib3.connectionpool         _new_conn             243 : Starting new HTTP connection (1): localhost:2002
DEBUG 2024-08-27 15:46:07,506 urllib3.connectionpool         _make_request         546 : http://localhost:2002 "POST /cards/cards HTTP/11" 500 28034
ERROR 2024-08-27 15:46:07,507 api                            send_card             344 : b'
... see logs
...

error01_initial_error.log

Error01 - Solution

Change post url from query_url = "cardspub/cards" to query_url = "cardspub/cards"
See additional commit after merged pull request

Error02 - BAD_REQUEST ‘process and/or state does not exist’

When sending a card, you may have the following error:

{"status":"BAD_REQUEST","message":"Impossible to publish card because process and/or state does not exist (process=defaultProcess, state=messageState, processVersion=2, processInstanceId=edf35784-e89a-40b2-94a8-fce4d8472428)"}

Error02 - Solution

Solution Error02: You should execute the example2 of getting started to create and push the version 2 of the bundles for process=defaultProcess or change default version by 1 into the default parameter of the function.

Error03 - 301 Moved Permanently

see logs in file
error03_301_moved_permanently.log

Error03 - Solution

Verify existence of /cardspub/cards path in nginx.conf andcorrect nginx.conf by removing the last / in opfab-getting-started server configuration using the following:

location /cardspub/cards {
    proxy_set_header Host $http_host;
    proxy_pass http://cards-publication:2102/cards;
}

Error04 - no i18n translation for key=defaultProcess.title

When sending card using defaultProcess.summary and defaultProcess.title, the following results:

Content of the card sent: see card in Error01

ERROR results of POST opfab card-publication url command:

{"status":"BAD_REQUEST","message":"Impossible to publish card : no i18n file for process=defaultProcess, processVersion=2 (processInstanceId=c5ab5a3b-52b0-4d85-978c-96e80e290e53)"}

Solution Error04

Change keys used for title and summary to correspond to actual i18n.json file settings:

  • Use for example "key": "message.summary" and "key": "message.title" for version 1.
  • Use for example "key": "defaultProcess.summary" and "key": "defaultProcess.title" for version 2.

Please notice that the i18.json file is not similar between the process version 1 and 2 and some keys are not present in both versions.


END of FILE.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions