0

I created a script which updates work items in a polarion document. However, right now each workitem update is a single save. But my script updates all work items in the document, which results in a large number of save actions in the api and thus a large set of clutter in the history. If you edit a polarion document yourself, it will update all workitems. Is it possible to do this same thing with the polarion API?

I tried

  • Using the tracker service to update work items. This only allows a single work item to be updated.
  • Using the web development tools to try and get information from the API. This seems to use a UniversalService for which no documentation is available at the API site https://almdemo.polarion.com/polarion/sdk/index.html

Update 1:

I am using the python polarion package to update the workitems.Python polarion Based on the answer by @boaz I tried the following code:

project = client.getProject(project_name)
doc = project.getDocument(document_location)
workitems = doc.getWorkitems()

session_service = client.getService("Session")
tracker_service = client.getService("Tracker")
session_service.beginTransaction()

for workitem in workitems:
    workitem.description = workitem._polarion.TextType(
            content=str(datetime.datetime.now()), type='text/html', contentLossy=False)
    update_list = {
        "uri": workitem.uri,
        "description": workitem.description
    }
    tracker_service.updateWorkItem(update_list)

session_service.endTransaction(False)

The login step that @boaz indicated is done in the backend (See: https://github.com/jesper-raemaekers/python-polarion/blob/3e61527cf0f1f3c8614a30289a0a3409d2d8712d/polarion/polarion.py#L103)

However, this gives the following Java exception:

java.lang.RuntimeException: java.lang.NullPointerException

Update 2

There seems to be an issue with the session. If I call the following code:

session_service.logIn(user, password)
print(session_service.hasSubject())

it prints False.

The same thing happens when using the transaction:

session_service.beginTransaction()
print(session_service.transactionExists())

also prints False

  • Your code looks like it should work. A NullPointerException on the Polarion side is usually some silly mistake, like trying to access a field that doesn't exist in the item. Did you have a look at the Polarion logs? Look for the NullPointerException in the most recent `Polarion/data/logs/main/` log file. – Boaz Jan 16 '23 at 20:45
  • @Boaz There seem to be other issues. If I try: session_service.logIn(user, pass) print(session_service .hasSubject()) it will print False. So apparently the session is not saved correctly. I asked our admin for access to the logs. – Sybren Zwetsloot Jan 17 '23 at 10:53
  • The same thing seems to happen using the beginTransaction method. If I call that and then call the transactionExists method, it will return False. – Sybren Zwetsloot Jan 17 '23 at 11:20
  • I can't comment on the Python part as I haven't tried it. It may not translate your calls correcly into the SOAP and may need debugging. On the Polarion side debugging is easier if you install a local trial instance, which you can download from the [Siemens website](https://www.plm.automation.siemens.com/store/en-us/trial/polarion-alm-download.html).Then you have full access to the logs locally. – Boaz Jan 17 '23 at 15:02
  • Turns out that there was an initialization step that was causing the issue in the package. Removing that resulted in correct behaviour. – Sybren Zwetsloot Jan 19 '23 at 15:16
  • Thanks for the update! It would be appreciated if you can share your working solution (you can post it as an answer to your question), so that others who need to use transactions using the Python package will not have to re-discover it. – Boaz Jan 20 '23 at 06:31

1 Answers1

0

Try wrapping your changes in a SessionWebService transaction, see JavaDoc:

    sessionService = factory.getSessionService();
    sessionService.logIn(prop.getProperty("user"), 
        prop.getProperty("passwd"));
    sessionService.beginTransaction();

    // ...
    // your changes
    // ...

    sessionService.endTransaction(false);
    sessionService.endSession();

As shown in the example in Polarion/polarion/SDK/examples/com.polarion.example.importer.

This will commit all your changes in one single SVN commit.

Boaz
  • 58
  • 2
  • 6
  • That doesn't seem to work. I am using the python polarion package. Will add this as details in my original question. – Sybren Zwetsloot Jan 16 '23 at 10:04
  • Thanks for adding that information. I tried using a python client a few years ago but it was a pain, so I reverted back to Java which was much friendlier to use thanks to IntelliJ Idea code completion when using the Siemens-supplied library. The code above should work exaclty the same way in Python though, exactly as you added to the question. – Boaz Jan 16 '23 at 20:40