Global Context ID Enumerations

Description
kaitlyn.opperman
Posts: 8
Joined: Mon Apr 28, 2014 7:08 pm

Global Context ID Enumerations

Postby kaitlyn.opperman » Mon Apr 28, 2014 7:43 pm

I am trying to migrate a macro from our SANDBOX project to a Wiki page at the default/root level of our Polarion platform. I am using Polarion ALM 2013 SR3, and we have the "Wiki Scropting Tools Extension" installed.

Here is what worked on the SANDBOX Wiki page:

Code: Select all

## ------------------
## Access the Enumeration
## ------------------
#set($enumType = $polarionTool.typeFactory.getEnumType("status"))
#set($projectId      = $doc.getProject($doc.space))

#set($contextId = $trackerService.getTrackerProject("$projectId").contextId)

#set($dataService = $trackerService.dataService)
#set($myEnum = $dataService.getEnumerationForEnumId($enumType,$contextId))

## ------------------
## Build the Enumeration list
## ------------------
#set($enum_queries = [])
#set($enum_strings = [])
#foreach($enumeration in $myEnum.getAllOptions())
  #set($dummy = $enum_queries.add("status.KEY:$enumeration.getId()"))
  #set($dummy = $enum_strings.add("$enumeration.getName()"))
#end ## End adding each enumeration option

## ------------------
## Debug printing of the enumeration fields
## ------------------
Enumeration: $myEnum\\
Items: $myEnum.getAllOptions()\\
Queries: $enum_queries\\
Strings: $enum_strings\\


The above populates a page of strings that are then used later when invoked in the SANDBOX project. While migrating, I ran into the problem that in the global scope, there is no project, and the ContextID returned is null. The page displays an error message when a null ContextID argument is used.
Error number 4001 in 4: Error while parsing velocity page page/Debug/TestPage Wrapped Exception: Invocation of method 'getTrackerProject' in class $ITrackerService_1458cb8d12c threw exception class com.polarion.platform.persistence.WrapperException : com.polarion.subterra.index.QueryIndexException: Failed to parse query: (id:"") AND NOT IS_LOCAL:true


I tried to work around this by invoking a global context ID instead as follows:

Code: Select all

## ------------------
## Access the Enumeration
## ------------------
#set($enumType = $polarionTool.typeFactory.getEnumType("status"))
#set($projectId      = $doc.getProject($doc.space))
#if($projectId == "")
  #set($repoService = $polarionTool.repositoryService)
  #set($projectId   = "SANDBOX") ## allow access to any ContextId object
  #set($contextId   = $trackerService.getTrackerProject("$projectId").contextId.globalContextId) ## Global context enumeration doesn't work, an empty list is returned
##  #set($contextId = $trackerService.getTrackerProject("$projectId").contextId) ## Project context
#else
  #set($contextId = $trackerService.getTrackerProject("$projectId").contextId)
#end
#set($dataService = $trackerService.dataService)
#set($myEnum = $dataService.getEnumerationForEnumId($enumType,$contextId))

## ------------------
## Build the Enumeration list
## ------------------
#set($enum_queries = [])
#set($enum_strings = [])
#foreach($enumeration in $myEnum.getAllOptions())
  #set($dummy = $enum_queries.add("status.KEY:$enumeration.getId()"))
  #set($dummy = $enum_strings.add("$enumeration.getName()"))
#end ## End adding each enumeration option

## ------------------
## Debug printing of the enumeration fields
## ------------------
Enumeration: $myEnum\\
Items: $myEnum.getAllOptions()\\
Queries: $enum_queries\\
Strings: $enum_strings\\

The global enumeration above is returning an empty list of items.

I realize there are several open features in the Polarion API regarding global context and functions (IRepositoryConfigService TODO Implement handling of the null context => global context), but I am looking for an immediate workaround.

1. What is the appropriate context to use to access/parse the "global" enumeration xml file instead of a project specific one?
2. Is there a more direct or simplistic way to access a global enumeration list?

Stepan Roh
Posts: 34
Joined: Tue Apr 04, 2006 8:46 am

Re: Global Context ID Enumerations

Postby Stepan Roh » Wed Apr 30, 2014 7:17 am

Hello.

Using ContextId.getGlobalContextId() is unfortunately almost always wrong, the correct global context id is ContextId.getGlobalContextId(IRepositoryService.DEFAULT) (use "default" string instead of DEFAULT constant in the Wiki). The reason is that the context hierarchy is like this:

global
global for default repository
top-level groups and projects

All the "global" configuration stored in repository lives on the "global for default repository" level.

Best regards,
Stepan Roh
Polarion Software
Stepan Roh
Polarion Software

kaitlyn.opperman
Posts: 8
Joined: Mon Apr 28, 2014 7:08 pm

Re: Global Context ID Enumerations

Postby kaitlyn.opperman » Tue May 06, 2014 12:03 pm

Thank you for the explanation Stepan.

I could not get your suggestion to work directly with our setup, but the differentiation between the top level global and the actual first repository global was enough to build the following test page:

Code: Select all

#set($repoService = $polarionTool.repositoryService)
#set($projectId   = "SANDBOX") ## allow access to any ContextId object
#set($contextId   = $trackerService.getTrackerProject("$projectId").contextId)
#set($contextId2  = $trackerService.getTrackerProject("$projectId").contextId)
#set($contextId2 = $contextId2.removeClusterName) ## Attempt to modify the existing context object

## Default global context, above all repository access
#set($globalContextId        = $contextId.globalContextId)

## Trying to get repository using the suggested format
#set($globalRepoContextId1   = $contextId.globalContextId($repoService.DEFAULT)) ##Wiki pages cannot do constants, so should not work
#set($globalRepoContextId2   = $contextId.globalContextId("default"))
#set($globalRepoContextId3   = $contextId.globalContextId('default')) ##Should be the same as Id2 above
#set($globalRepoContextId4   = $contextId.globalContextId(''))
#set($globalRepoContextId5   = $contextId.globalContextId('/'))

## Trying another method
#set($customContextId1       = $contextId.getContextIdFromClusterAndContext('default', 'global'))
#set($customContextId2       = $contextId.getContextIdFromClusterAndContext('default', ''))
#set($customContextId3       = $contextId.getContextIdFromClusterAndContext('default', '/'))

## Context id can be represented as "normalized" string with exact format: global context id is empty string, cluster-less context id is context name, global context id with cluster is slash ('/'), cluster name and slash ('/'), context id with cluster is slash ('/'), cluster name, slash ('/') and context name. Baselines are appended to context names with preceding slash ('/').

Classes:\\
PT: $polarionTool.class\\
TS: $trackerService.class\\
RS: $repoService.class\\
CI: $contextId.class\\

CI Print: $contextId\\
CI2 Print: $contextId2\\

CIg: $globalContextId\\

CI1: $globalRepoContextId1\\
CI2: $globalRepoContextId2\\
CI3: $globalRepoContextId3\\
CI4: $globalRepoContextId4\\
CI5: $globalRepoContextId5\\

CC1: $customContextId1\\
CC2: $customContextId2\\
CC3: $customContextId3\\

#set($enumType = $polarionTool.typeFactory.getEnumType("status"))
#set($dataService = $trackerService.dataService)
#set($myEnum1 = $dataService.getEnumerationForEnumId($enumType,$customContextId1))
#set($myEnum2 = $dataService.getEnumerationForEnumId($enumType,$customContextId2))
#set($myEnum3 = $dataService.getEnumerationForEnumId($enumType,$customContextId3))

## #E1: $myEnum1.getAllOptions()\\ ##Throws an error, context does not exist
## #E2: $myEnum2.getAllOptions()\\ ##This one works
## #E3: $myEnum3.getAllOptions()\\ ##This one works also


This produced the following results (in a code section for the size control):

Code: Select all

Classes:
PT: class $PolarionTool_145cef89924
TS: class $ITrackerService_145cef896c5
RS: class $IRepositoryService_145cef89748
CI: class com.polarion.subterra.base.data.identification.ContextId

CI Print: ContextIdSoftware Release.cluster default, context SANDBOX
CI2 Print: ContextIdSoftware Release.cluster default, context SANDBOX

CIg: ContextIdSoftware Release.context [global]

CI1: $globalRepoContextId1
CI2: $globalRepoContextId2
CI3: $globalRepoContextId3
CI4: $globalRepoContextId4
CI5: $globalRepoContextId5

CC1: ContextIdSoftware Release.cluster default, context global
CC2: ContextIdSoftware Release.cluster default, context
CC3: ContextIdcluster default, context /Home


I can use the getContextIdFromClusterAndContext with 'default' and either an empty string or a single slash. I'm not sure why the global version would not take the 'default' argument, but this solves my problem of accessing the "top level repository" enumerations.


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: No registered users and 8 guests