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

plain java snippet work item

in plain java ,snippet5. java creates a work item.But

I don't want to create a new project area in jazz platform , it is not important the code is java or egl. the code is first create a project area ,then create work item. i wanna create work item in existing project areas in Jazz platform.

The code like this ;

public static IWorkItemHandle createWorkItem(ITeamRepository repo, IProgressMonitor monitor) throws TeamRepositoryException {
ITeamAreaHandle teamAreaHandle = Snippet3.createProject(repo, "Snippet 5");
ITeamArea teamArea = (ITeamArea) repo.itemManager().fetchCompleteItem(teamAreaHandle, IItemManager.DEFAULT, monitor);
IProjectAreaHandle projectArea = teamArea.getProjectArea();
IWorkItemClient service = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);
IWorkItemType workItemType = service.findWorkItemType(projectArea, "defect", monitor);
IWorkItemHandle handle = service.getWorkItemWorkingCopyManager().connectNew(workItemType, monitor);
WorkItemWorkingCopy wc = service.getWorkItemWorkingCopyManager().getWorkingCopy(handle);
IWorkItem workItem = wc.getWorkItem();
try {
List<ICategory> findCategories= service.findCategories(projectArea, ICategory.FULL_PROFILE, monitor);
ICategory category = findCategories.get(0);
workItem.setCategory(category);
workItem.setCreator(repo.loggedInContributor());
workItem.setOwner(repo.loggedInContributor());
workItem.setHTMLSummary(XMLString.createFromPlainText("Example work item"));
IDetailedStatus s = wc.save(null);
if(! s.isOK()) {
throw new TeamRepositoryException("Error saving work item", s.getException());
}
} finally {
service.getWorkItemWorkingCopyManager().disconnect(workItem);
}
workItem = (IWorkItem) repo.itemManager().fetchCompleteItem(workItem, IItemManager.DEFAULT, monitor);
monitor.subTask("Created a work item " + workItem.getId());
return workItem;
}

2 votes



One answer

Permanent link
Thanks for posting your code to create a new work-item:
IWorkItemType workItemType = service.findWorkItemType(projectArea, "defect", monitor); 
IWorkItemHandle handle = service.getWorkItemWorkingCopyManager().connectNew(workItemType, monitor); 
WorkItemInitialization operation= new WorkItemInitialization(summary, category);
IWorkItemHandle handle= operation.run(workItemType, null);
It helps us! :)

You can retrieve an existing project area by its name:
String name = ...;
IProcessClientService processClient = (IProcessClientService) repo.getClientLibrary(IProcessClientService.class);
URI uri = URI.create(name.replaceAll(" ", "%20"));
IProjectArea prjArea = (IProjectArea) processClient.findProcessArea(uri, null, null);
Cheers.

2 votes

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,927

Question asked: Nov 02 '10, 12:52 p.m.

Question was seen: 4,900 times

Last updated: Jun 04 '13, 4:58 a.m.

Confirmation Cancel Confirm