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

Quality Gate Status Bugs Code Smells Coverage Duplicated Lines (%) Lines of Code Reliability Rating Security Rating Maintainability Rating Vulnerabilities

API extension for Polarion ALM

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

Important

Starting from version 2.0.0 only latest version of Polarion is supported. Right now it is Polarion 2512.

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.

Quick start

The latest version of the extension can be downloaded from the releases page and installed to Polarion instance without necessity to be compiled from the sources. The extension should be copied to <polarion_home>/polarion/extensions/ch.sbb.polarion.extension.api-extender/eclipse/plugins and changes will take effect after Polarion restart.

Important

Don't forget to clear <polarion_home>/data/workspace/.config folder after extension installation/update to make it work properly.

Documentation

Polarion configuration

REST API

This extension provides REST API. OpenAPI Specification can be obtained here.

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')

Tools

This extension includes several velocity tools to facilitate development and maintenance.

Collections Tool

Sort a map by its values in ascending or descending order:

#set($sortedMap = $collectionsTool.sortMap($unsortedMap, true))

Wrap given list of objects into a IPObjectList:

#set(list = $collectionsTool.convertArrayListToWeakPObjectList($workItems))

Regex Tool

Extract regex matches in the given text, returning the matches and their respective groups:

#set($matches = $regexTool.findMatches('(\d+)', "test123and456"))

About

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

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors