Skip to content

This Polarion extension provides additional functionality which is not implemented in standard Polarion API for some reason.

Notifications You must be signed in to change notification settings

SchweizerischeBundesbahnen/ch.sbb.polarion.extension.api-extender

Repository files navigation

API extension for Polarion ALM

This Polarion extension provides additional functionality which is not implemented in standard Polarion API for some reason.

Custom field for project

Polarion project does not support setting custom fields out of the box. This API extension can be used to solve this problem.

This API can be called using REST API and in Velocity Context.

Build

This extension can be produced using maven:

mvn clean package

Installation to Polarion

To install JSON editor extension to Polarion ch.sbb.polarion.extension.json.editor-<version>.jar should be copied to <polarion_home>/polarion/extensions/json-editor/eclipse/plugins It can be done manually or automated using maven build:

mvn clean install -P install-to-local-polarion

For automated installation with maven env variable POLARION_HOME should be defined and point to folder where Polarion is installed.

Changes only take effect after restart of Polarion.

Polarion configuration

REST API

Get version:

curl --location 'https://<HOST>:<PORT>/polarion/api-extender/rest/api/version' \
    --header 'Authorization: Bearer <TOKEN_GOES_HERE>'

Response example:

{
  "bundleName":"API Extension for Polarion ALM",
  "bundleVendor":"SBB AG",
  "automaticModuleName":"ch.sbb.polarion.extension.api_extender",
  "bundleVersion":"1.0.0",
  "bundleBuildTimestamp":"2023-06-27 12:43",
  "bundleBuildTimestampDigitsOnly":"202306271243"
}

Get custom field value:

curl --location 'https://<HOST>:<PORT>/polarion/api-extender/rest/api/projects/<PROJECT_ID>/keys/<CUSTOM_FIELD>' \
    --header 'Authorization: Bearer <TOKEN_GOES_HERE>'

Get global record value:

curl --location 'https://<HOST>:<PORT>/polarion/api-extender/rest/api/records/<RECORD>' \
    --header 'Authorization: Bearer <TOKEN_GOES_HERE>'

Response example:

{
  "value": "custom_value"
}

Set custom field value:

curl --location 'https://<HOST>:<PORT>/polarion/api-extender/rest/api/projects/<PROJECT_ID>/keys/<CUSTOM_FIELD>' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Bearer <TOKEN_GOES_HERE>' \
    --data '{
      "value": "<VALUE>"
    }'

Set global record value:

curl --location 'https://<HOST>:<PORT>/polarion/api-extender/rest/api/records/<RECORD>' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Bearer <TOKEN_GOES_HERE>' \
    --data '{
      "value": "<VALUE>"
    }'

Live Report Page

Get version:

#set ($version = $customFieldsProject.getVersion())
#if ($version)
    API Extender version = $version
#end

or

#set ($version = $globalRecords.getVersion())
#if ($version)
    API Extender version = $version
#end

Get custom field value:

#set ($field = $customFieldsProject.getCustomField('elibrary', 'custom_field'))
#if ($field)
    $field.getValue()
    <br>
#end

Get global record value:

#set ($field = $globalRecords.getRecord('record_name'))
#if ($field)
    $field.getValue()
    <br>
#end

Due to Polarion limitations we are not able to save custom fields in Live Report Page using Velocity, but we can use JavaScript for this.

Set custom field value:

<input id='cfp_project' type='text' value='elibrary' name='project'/>
<input id='cfp_key' type='text' value='custom_field' name='key'/>
<input id='cfp_value' type='text' value='custom_value' name='value'/>
<script>
    function save_project_custom_field() {
        const project = document.getElementById('cfp_project').value;
        const key = document.getElementById('cfp_key').value;
        const value = document.getElementById('cfp_value').value;
        const requestBody = (value === null || value === "") ? "" : JSON.stringify({'value': value});

        fetch('/polarion/api-extender/rest/internal/projects/' + project + '/keys/' + key, {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            body: requestBody
        })
        .then(response => {
            if (response.ok) {
                return "Saved!"
            } else {
                return response.text()
            }
        })
        .then(text => {
             alert(text)
        });
    }
</script>
<button onclick='save_project_custom_field()'>Save</button>

Set global record value:

<input id='record_key' type='text' value='record_name' name='record_name'/>
<input id='record_value' type='text' value='record_value' name='record_value'/>
<script>
    function save_record() {
        const key = document.getElementById('record_key').value;
        const value = document.getElementById('record_value').value;
        const requestBody = (value === null || value === "") ? "" : JSON.stringify({'value': value});

        fetch('/polarion/api-extender/rest/internal/records/' + key, {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            body: requestBody
        })
            .then(response => {
                if (response.ok) {
                    return "Saved!"
                } else {
                    return response.text()
                }
            })
            .then(text => {
                alert(text)
            });
    }
</script>
<button onclick='save_record()'>Save</button>

Note that internal API in URL should be used.

Classic Wiki Page

Get custom field value:

#set($projects = $projectService.searchProjects("","id"))

#foreach($project in $projects)
    #set($projectId = $project.id)
    #set($field = $customFieldsProject.getCustomField($projectId, 'custom_field'))
    #if ($field)
        $projectId custom_field = $field.getValue()
        <br>
        #set($field = false)
    #end
#end

Get global record value:

$globalRecords.getRecord('record_name')

Set custom field value:

$customFieldsProject.setCustomField('elibrary', 'custom_field', 'new_value')

Set global record value:

$globalRecords.setRecord('record_name', 'record_value')

About

This Polarion extension provides additional functionality which is not implemented in standard Polarion API for some reason.

Topics

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors 4

  •  
  •  
  •  
  •