How do I create a plan with the Java API?
I tried to write a commandline tool, which creates plans with help of the Java-API. I like to have a csv file which contains a list of plans to create. Each row has Owner, IterationID, Plantype, IncludeAllItems.
There is a Wiki article with an example how to copy plans. So I tried to follow this:
https://jazz.net/wiki/bin/view/Main/InformalProjectCopy (Section Agile Planning)
Now I'm stuck, because I get an exception on the save methode:
IterationPlanSaveResult saveResult= target.save(plan, monitor);
Error: !ContentStorage.attributeDoesNotMatch!
(I was not able to find out which attribute doesn't match.)
Has anybody an idea what is wrong? Or has anybody a code-snippet which is working to create plans?
I'm running v.3.0.1.3 and 4.0. If it works only for 4.0 it's ok for me.
(I know there are already some very old enhancement requests for supporting this in the API. But all are pre-2.0 and on state triaged, so I thought have a try.)
Accepted answer
With help of IBM, we found the issue. In the wiki page and in my code we didn't created the wiki pages for the plan.
My working code looks now like this:
public static void createPlan (String planName, IIteration planIteration, String planType, IProcessArea planTeam, IContributor creator) {
// get classes for plan creation
IAuditableCommon audit = (IAuditableCommon) this.teamRepository.getClientLibrary(IAuditableCommon.class);
IIterationPlanService planService = (IIterationPlanService)((IClientLibraryContext) teamRepository).getServiceInterface(IIterationPlanService.class);
// create necessary plan items
IIterationPlanRecord plan = (IIterationPlanRecord) IIterationPlanRecord.ITEM_TYPE.createItem();
IWikiPage wiki = (IWikiPage) IWikiPage.ITEM_TYPE.createItem();
// setup plan values
plan.setName(planName);
plan.setIteration(planIteration);
plan.setPlanType(planType);
plan.setOwner(planTeam);
// setup wiki page
wiki.setName("");
wiki.setWikiID(IIterationPlanRecord.OVERVIEW_PAGE_ID);
wiki.setCreator(creator);
wiki.setOwner(plan);
String encoding = "UTF8";
String xmlText = "";
byte[] bytes = xmlText.getBytes(encoding);
InputStream inputStream = new ByteArrayInputStream(bytes);
wiki.setContent(audit.storeContent(IContent.CONTENT_TYPE_TEXT, encoding, inputStream, bytes.length, null));
// save plan
DTO_IterationPlanSaveResult saveResult = planService.save(project, plan, wiki);
if (saveResult.isSetIterationPlanRecord() == false) {
System.out.println("Saving failed!");
}
}
Note: this is not a public API. If you like to have a supported API for this, please vote here and write comments on: https://jazz.net/jazz/web/projects/Rational%20Team%20Concert#action=com.ibm.team.workitem.viewWorkItem&id=65697
Comments
Thanks for sharing.
Is this interal API not part of the Plain Java Client Libraries (4.0.3, 4.0.4)? Somehow I can't find the needed classes (e.g. IIterationPlanRecord, IIterationPlanService).
Could you point me in the right direction?
Thanks
This is internal API as mentioned by Bruno. However, dependent on your setup, try to import com.ibm.team.apt.* with * client or common.
I was able to find the classes in an environment where I have setup the SDK as well as the plain Java Client Libraries. I tried this with 4.0.1and 4.0.5 so I would assume the ones in between have the internal API as well.
I have desribed how I set up my environment here: https://rsjazz.wordpress.com/2013/02/28/setting-up-rational-team-concert-for-api-development/
I checked the Plain Java Client Libraries. They don't contain the com.ibm.team.apt packages. These are only contained in the SDK. So I would assume it would be necessary to run this kinds of code in a client based on the SDK, e.g. from an Eclipse RTC client.
Comments
Guido Schneider
Jul 20 '12, 10:12 a.m.because this field is to short I post an answer below as addendum: