workitem create with default attachment (via svn copy)?

Description
moem1
Posts: 36
Joined: Wed Feb 23, 2011 4:27 pm

workitem create with default attachment (via svn copy)?

Postby moem1 » Wed May 09, 2012 7:03 pm

Hi,

I've used the "Workitem create template" extension (PE-34) but it doesn't support copying attachments from the template work-item to the new work-items.

Is it possible for a Polarion work-item to fire off an "svn copy" command upon creation? What I would like to do is this:

1) WI-99 (for example) gets created
2) A init script fires that does an svn copy from a pre-defined location like this:
svn copy ^/templates/file1.xls ^/project1/.polarion/tracker/workitems/00-99/WI-99/attachment1-file1.xls

Can someone provide an example of how I could do the above? Is it possible for Polarion to perform the svn copy as the currently logged in user?

Thanks,

- Mark

moem1
Posts: 36
Joined: Wed Feb 23, 2011 4:27 pm

Re: workitem create with default attachment (via svn copy)?

Postby moem1 » Wed May 09, 2012 9:45 pm

Some progress, I created a JavaScript file that I can use the Workflow action ScriptEngine (PE-1) to call. I can give my svn source path vi the ScriptEngine parameters and get that from the arguments as well as the WI's svn path:

var wi = workflowContext.getWorkItem();
var source = arguments.getAsString("source");
var wi_loc = wi.getLocation().getLocationPath();

From there, I could do a system call Runtime.getRuntime().exec() to brute force an "svn copy" running as a generic service account. That's kind of messy though.

I see I can also do wi.createAttachment() but I can't find any examples of that. And, does createAttachment() expect a client side file path? Or can I provide a server side file? Or better yet, an svn repository file path?

Can anyone provide a short example snippet of using createAttachment()?

Thanks!

- Mark

moem1
Posts: 36
Joined: Wed Feb 23, 2011 4:27 pm

Re: workitem create with default attachment (via svn copy)?

Postby moem1 » Wed May 09, 2012 10:22 pm

Pardon my processing this "out loud" ... more progress, I can now create the attachment with lines like this ...

var in_fs = new FileInputStream("/tmp/test.xls");
wi.createAttachment("test.xls", source, in_fs).save();

I could export a temp file from svn to "/tmp/test.xls" on the server and read it in like shown above, but maybe there are svn functions I can call to create the input stream and avoid the temp file?

- Mark

moem1
Posts: 36
Joined: Wed Feb 23, 2011 4:27 pm

Re: workitem create with default attachment (via svn copy)?

Postby moem1 » Thu May 10, 2012 5:05 pm

Ok, kind of brute force, but the below is working for me. I think the ideal script would be no temp file, running svn as the current user (instead of a service account, called "abc" in my example), and an svn copy (instead of export and createAttachment).

- Mark

ps. merging Java and JavaScript can be powerful but also causes a few quirks where things overlap!

// // Polarion Scripting JavaScript: svn copy of template file to new work-item attachments // //
// Polarion Workflow Actions ScriptFunction Parameters //
// engine JavaScript
// script copy_from_svn_to_attachments.js
// source http://server/repo/path/to/attachment/file.ext

// enable Java functions
importPackage(java.io);
importPackage(java.lang);
importPackage(java.util);

// get context and parameters
var wi = workflowContext.getWorkItem();
var source = arguments.getAsString("source");

// export source file from svn to temp file
var temp_file = new StringBuilder().append("/tmp/copy_from_svn_to_attachments-").append(UUID.randomUUID()).append(".").append("tmp").toString();
var aCmd = ["/bin/sh", "-c", "/usr/bin/svn export --non-interactive --username abc --password xyz '" + source + "' '" + temp_file + "' >/dev/null 2>&1"];
var process = Runtime.getRuntime().exec(aCmd);
process.waitFor();
// tidy up open file descriptors
process.getInputStream().close();
process.getOutputStream().close();
process.getErrorStream().close();

// get base filename of source
var file_name = new String(source).replace(/.*\//, '');

// read temp_file into attachment
var in_fs = new FileInputStream(temp_file);
wi.createAttachment(file_name, "Copied from " + source, in_fs).save();
in_fs.close();

// remove temp file
var f = new File(temp_file);
// work-around delete method being a JavaScript reserved word
f['delete']();

mbidner
Posts: 15
Joined: Thu May 04, 2017 9:55 am

Re: workitem create with default attachment (via svn copy)?

Postby mbidner » Fri Nov 30, 2018 9:13 am

Hello all,

I have a similar (maybe the same) use case.
Six years after these post (and changes in Polarion), I have the following use case:
I add a graphic in the description field of a template work item.
Then I create a work item inside a Live Doc based on this template work item.
The graphic is then visible (before storing the Live Doc).
After storing the work item by saving the Live Doc this graphic is not available anymore ("Ooops. This attachement war probably removed. See history fo rmore details).

Is it possible to insert a graphic in the description field of the template work item and "transfer" it to the created work item?

BR
Michael

Jürgen
Posts: 82
Joined: Tue Sep 12, 2017 1:02 pm

Re: workitem create with default attachment (via svn copy)?

Postby Jürgen » Mon Dec 03, 2018 6:25 am

Hello, Michael

I do not know what is happening there, but could you maybe test to create a work item from the template outside a document?

I think when you create a WI inside a document, the image then is attached to the document instead of the work item.

mbidner
Posts: 15
Joined: Thu May 04, 2017 9:55 am

Re: workitem create with default attachment (via svn copy)?

Postby mbidner » Mon Dec 03, 2018 11:54 am

Hello,

I made some further analysis.

When I create a work item from work item space (not inside a live doc), the graphic I put in the work item template is not visbile and the title of the work item is not "edit", that means if I create the work item without any text for the title, this work item title is created with first row (or maximum 80 chars) of template description as title.

When I create a work item inside a live doc, the behaviour is similar, but I can see that there was previous a link to a graphic. Problem during work item creation: the URL from the graphic changes from template work item URL to new URL of created work item. And there is no attachement added to the document properties.

So if Polarion would not change this URL during work item creation, the new work item would be "linked" to the graphic of the template work item (and the graphic should be visible inside the description).


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: Google [Bot] and 8 guests