Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Creating items programmatically.

Hi,

Is it possible to create an instance of subclasses of IItem (e.g. IWorkItem, IChangeSet, and IChange) programmatically? Currently, I'm using IItemType.createItem(...) to create a work item, but it doesn't seem to work.

0 votes



11 answers

Permanent link
IItemType.createItem(...) creates an item in memory without saving it in the repository. Can you please provide more info on what does not work?

0 votes


Permanent link
What I tried to do was this:
fTeamRepo = login();
IWorkItem work1 = (IWorkItem) IWorkItem.ITEM_TYPE.createItem(fTeamRepo);
IWorkItemClient workItemClient= (IWorkItemClient) fTeamRepo.getClientLibrary(IWorkItemClient.class);
IWorkItemWorkingCopyManager manager = workItemClient.getWorkItemWorkingCopyManager();
IWorkItemHandle handle = (IWorkItemHandle) work1.getItemHandle();
manager.connect(handle, IWorkItem.SMALL_PROFILE, null);

However, I got this error:
com.ibm.team.repository.common.ItemNotFoundException: CRJAZ0215I Item not found: com.ibm.team.workitem.common.internal.model.impl.WorkItemHandleImpl@18741874 (stateId: <unset>, itemId: , origin: com.ibm.team.repository.client.internal.TeamRepository@67866786, immutable: <unset>)

I ran this program on local mode, connecting to the default Derby repositoryDB.

0 votes


Permanent link
Please take a look at https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation, work items need some additional initialization that involves additional parameters and could not be implemented in IItemType.createItem().

Regards,

Christof
Jazz Work Item team

0 votes


Permanent link
Hi Christof,

I looked at the wiki page that you pointed to, but I noticed that it didn't explain how I could create a new project area programmatically. So, I went off to try to create project area as follow:
IProjectArea projectArea = itemService.createProjectArea();
projectArea.setName("Test Project Area");
/*IProcessDefinition processDef = itemService.findProcessDefinition("Eclipse Way",
IProcessClientService.ALL_PROPERTIES, null);*/
List procDefs = itemService.findAllProcessDefinitions(IProcessClientService.ALL_PROPERTIES, null);

projectArea.setProcessDefinition((IProcessDefinition) procDefs.get(0));
IContributor thisUser = fTeamRepo.loggedInContributor();
projectArea.addMember(thisUser);

IProjectArea savedProject = (IProjectArea) itemService.save(projectArea, null);

However, I couldn't find any pre-defined IProcessDefinition and when I tried to save the projectArea with null process definition, it gave me an error that I don't have a valid process definition associated to the project area. Can you help me out, please?

Thanks,
Petcharat

0 votes


Permanent link
If you're just writing a JUnit test, then you'll want to create a
process definition as well. (If you're writing real code, then you'll
want to get a project area from some other source, not create one
yourself.) Process definition creation is pretty straight-forward. The
biggest piece of code you'll have to write will be something to create
the IContent items that persist the process specification and process
state. For our JUnit tests, we just read these from XML files that we
keep in our test projects.

Take a look at AbstractTeamProcessTest#setupProjectArea(...). If you
walk through this code, you'll find all the pieces you need.

Jared Burns
Jazz Process Team


petcharatv wrote:
Hi Christof,

I looked at the wiki page that you pointed to, but I noticed that it
didn't explain how I could create a new project area
programmatically. So, I went off to try to create project area as
follow:
IProjectArea projectArea = itemService.createProjectArea();
projectArea.setName("Test Project Area");
/*IProcessDefinition processDef =
itemService.findProcessDefinition("Eclipse Way",
IProcessClientService.ALL_PROPERTIES, null);*/
List procDefs =
itemService.findAllProcessDefinitions(IProcessClientService.ALL_PROPERTIES,
null);

projectArea.setProcessDefinition((IProcessDefinition)
procDefs.get(0));
IContributor thisUser = fTeamRepo.loggedInContributor();
projectArea.addMember(thisUser);

IProjectArea savedProject = (IProjectArea)
itemService.save(projectArea, null);

However, I couldn't find any pre-defined IProcessDefinition and when I
tried to save the projectArea with null process definition, it gave me
an error that I don't have a valid process definition associated to
the project area. Can you help me out, please?

Thanks,
Petcharat

0 votes


Permanent link
Yeah..I want to write JUnit tests. That's why I need to create new project area and work items programmatically. Anyway, I looked at AbstractTeamProcessTest and it has exactly what I needed. Thanks a lot for your help. :)

0 votes


Permanent link
Hi,

Sorry, I still have one last small question. I was trying to create a new category and save it to the new project area that I created by doing this:
// Setup categories in the project area.
IAuditableClient auditableClient= (IAuditableClient) fTeamRepo.getClientLibrary(IAuditableClient.class);
CategoriesManager catManager = CategoriesManager.createInstance(auditableClient,
fProjectArea, null);
CategoryTreeNode rootNode = catManager.getRoot();
CategoryTreeNode childCat = rootNode.createChil(CATEGORY_ID);
catManager.save(null);

But I got an error: Permission denied, I couldn't save the category.

If I continued to create a work item, using:
IAuditableClient auditableClient= (IAuditableClient) fTeamRepo.getClientLibrary(IAuditableClient.class);
WorkItemInitialization operation= new WorkItemInitialization(summary, category);
IWorkItemHandle handle= operation.run(workItemType, null);
IWorkItem workItem= auditableClient.resolveAuditable(handle, IWorkItem.FULL_PROFILE, null);

I got an error ItemNotFound, saying it couldn't find the Category that I gave as argument.

Can you help me out, please?

Thanks

0 votes


Permanent link
Your process template for tests needs to include permissions for saving categories:

<project>
...other configuration...
<permissions>
<role>
...other operations...
<project>
<action>
</project>
</role>
</permissions>
</project>

HTH,

Christof
Jazz Work Item team

0 votes


Permanent link
Hi

i am also trying to do the same things. I have to write junit test case for which i need to create project area and work items in that project area.

I tried searching in the Jazz code for AbstractTeamProcessTest , but i could not find it. Since this post is pretty old , maybe the test has been changed. Can u please help me in finding the code for doing the same.

Thanks
Yogesh

0 votes


Permanent link
Hello,
The AbstractTeamProcessTest is in the com.ibm.team.process.client.tests package.
Martha
Jazz Developer
Hi

i am also trying to do the same things. I have to write junit test case for which i need to create project area and work items in that project area.

I tried searching in the Jazz code for AbstractTeamProcessTest , but i could not find it. Since this post is pretty old , maybe the test has been changed. Can u please help me in finding the code for doing the same.

Thanks
Yogesh

0 votes

1–15 items
page 1of 1 pagesof 2 pages

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,938

Question asked: Jul 20 '08, 5:50 p.m.

Question was seen: 13,287 times

Last updated: Jul 20 '08, 5:50 p.m.

Confirmation Cancel Confirm