[Wiki] Duplicate a document to another space

Description
jbod
Posts: 7
Joined: Tue Mar 10, 2015 12:28 pm

[Wiki] Duplicate a document to another space

Postby jbod » Wed Mar 11, 2015 3:01 pm

Hello,

I'm currently trying to duplicate a template document into another space using the Wiki API but it seems not to work the way I do it. I use the duplicate method from the ModuleManager as follow:

Code: Select all

## Getting some variables for various usage
#set ($trackerProject = $trackerService.getTrackerProject($page.getSpace().getProjectId()))
#set ($moduleManager = $trackerService.getModuleManager())

## Getting the location of the template document to be copied
#set ($templateDocLocation = $trackerProject.location.getLocation("_tools/documentTemplate"))
#set ($templateDoc = $moduleManager.getModule($trackerProject, $templateDocLocation))

## Getting the location of the targeted space
#set ($targetSpaceLocation = $trackerProject.location.getLocation("_reports"))

## Creating empty array for last arguments of the duplicate method
#set ($array1 = [])
#set ($array2 = [])

## Now duplicating the document
#set ($newDocument = $moduleManager.duplicate($templateDoc, $trackerProject, $targetSpaceLocation, "Test document", null, null, null, $array1, $array2))


Executing this piece of code displays nothing at all, nor errors. And finally, the $newDocument variable is null and the template document is not duplicated.

In addition, I ensure that the document "_tools/documentTemplate" and the space "_report" exist in the project where the Wiki script is executed.

Have you got any idea about this case?

Regards,
Jbod

martins
Posts: 181
Joined: Thu Nov 05, 2009 3:24 pm

Re: [Wiki] Duplicate a document to another space

Postby martins » Thu Mar 12, 2015 8:24 am

Hello Jbod,

is your wiki code embedded in a transaction? At least the line with the .duplicate method should be surrounded by

Code: Select all

$transactionService.beginTx()
and

Code: Select all

$transactionService.commitTx()


Kind regards

Martin

jbod
Posts: 7
Joined: Tue Mar 10, 2015 12:28 pm

Re: [Wiki] Duplicate a document to another space

Postby jbod » Thu Mar 12, 2015 10:34 am

Hi martins, thank you for your answer.

I just tried surrounding the duplicate method with the transaction methods you told me, but this does not change anything: the document is still not duplicated and nothing more is displayed.

I did not use a transaction here because I did not get any exception related to transactions (another Wiki code which required a transaction was complaining about the fact I forgot it).

Regards,
Jbod

martins
Posts: 181
Joined: Thu Nov 05, 2009 3:24 pm

Re: [Wiki] Duplicate a document to another space

Postby martins » Tue Mar 24, 2015 6:41 am

Hello Jbod,

If you try to duplicate a document within a Wiki page and without a transaction you definitely get an error

Code: Select all

 Invocation of method 'duplicate' in class $IModuleManager_14c4998ad6d threw exception class com.polarion.platform.persistence.WrapperException : com.polarion.subterra.persistence.PersistenceException: com.polarion.platform.service.repository.RepositoryException: Transaction problem: the connection can be created in active transaction context only
I reproduced this with current version of Polarion just this minute.

So if you do not get this error message, your code is obvious not executed at all. Therefore the problem seems to be outside of the code snippet you published.

Kind regards

Martin

jbod
Posts: 7
Joined: Tue Mar 10, 2015 12:28 pm

Re: [Wiki] Duplicate a document to another space

Postby jbod » Thu Mar 26, 2015 5:33 pm

Hello Martin,

Here is the code I just tried, this is the same but with transactions activated and some sentences displayed:

Code: Select all

## Getting some variables for various usage
#set ($trackerProject = $trackerService.getTrackerProject($page.getSpace().getProjectId()))
Tracker Project: $trackerProject<br/>

#set ($moduleManager = $trackerService.getModuleManager())
Module manager: $moduleManager<br/>

## Getting the location of the template document to be copied
#set ($templateDocLocation = $trackerProject.location.getLocation("_tools/documentTemplate"))
Template doc location: ${templateDocLocation}<br/>

#set ($templateDoc = $moduleManager.getModule($trackerProject, $templateDocLocation))
Template doc module: ${templateDoc}<br/>

## Getting the location of the targeted space
#set ($targetSpaceLocation = $trackerProject.location.getLocation("_reports"))
Space location: ${targetSpaceLocation}<br/>

## Creating empty array for last arguments of the duplicate method
#set ($array1 = [])
#set ($array2 = [])

## Starting a transaction
$transactionService.beginTx()
Beginning transaction<br/>

## Now duplicating the document
#set ($newDocument = $moduleManager.duplicate($templateDoc, $trackerProject, $targetSpaceLocation, "Test document", null, null, null, $array1, $array2))

The duplicate result: ${newDocument}<br/>

## Ending the transaction
$transactionService.commitTx()
Ended transaction<br/>

When executing this code, here is what's displayed:

Code: Select all

Tracker Project: PObject(Project; subterra:data-service:objects:/default/myproject${Project}myproject)
Module manager:
Template doc location: Locationpath _tools._documentTemplate
Template doc module: PObject(Module; subterra:data-service:objects:/default/myproject${Module}_tools._documentTemplate)
Space location: Location_tools.path Reports
Beginning transaction
The duplicate result: ${newDocument}
Ended transaction

So the code is executed but the duplicate method seems to have no effect as it returns nothing. No other errors are displayed.

If you don't experience the same behaviour, I suspect a problem with my Polarion configuration but I really don't know what could injure it. I just installed some plugins like the "Wiki Scripting Tools" one but nothing that may damage the original Polarion API.

Have you any idea about that?

Kind regards,
Jbod

martins
Posts: 181
Joined: Thu Nov 05, 2009 3:24 pm

Re: [Wiki] Duplicate a document to another space

Postby martins » Fri Mar 27, 2015 6:44 am

Hello Jbod,

replace

Code: Select all

#set ($array1 = [])
#set ($array2 = [])

by

Code: Select all

#set ($array1 = $objectFactory.newSet())
#set ($array2 = $objectFactory.newSet())

and it works.

Kind regards

Martin


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: ernestjl2 and 8 guests