It's all about the answers!

Ask a question

Creating items programmatically.


Petcharat Viriyakattiyaporn (4113) | asked Jul 20 '08, 5:50 p.m.
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.

11 answers



permanent link
yogesh arora (86102) | answered Jan 11 '09, 3:16 p.m.
Thanks a lot for your help

permanent link
Martha (Ruby) Andrews (3.0k44251) | answered Jan 10 '09, 2:55 p.m.
JAZZ DEVELOPER
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

permanent link
yogesh arora (86102) | answered Jan 09 '09, 8:21 p.m.
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

permanent link
Christof Marti (681) | answered Jul 28 '08, 3:40 a.m.
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

permanent link
Petcharat Viriyakattiyaporn (4113) | answered Jul 25 '08, 1:12 a.m.
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

permanent link
Petcharat Viriyakattiyaporn (4113) | answered Jul 24 '08, 7:53 p.m.
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. :)

permanent link
Jared Burns (4.5k29) | answered Jul 23 '08, 7:19 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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

permanent link
Petcharat Viriyakattiyaporn (4113) | answered Jul 23 '08, 5:31 p.m.
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

permanent link
Christof Marti (681) | answered Jul 22 '08, 5:11 a.m.
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

permanent link
Petcharat Viriyakattiyaporn (4113) | answered Jul 21 '08, 5:58 p.m.
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.

Your answer


Register or 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.