It's all about the answers!

Ask a question

How to get list of severities using Java API?


Krzysztof Ka┼║mierczyk (7.3k34391) | asked Dec 15 '11, 3:45 a.m.
Hello I would like to set the severity for my work item.

Here is my code:



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();
List<ICategory> findCategories= service.findCategories(projectArea, ICategory.FULL_PROFILE, monitor);
ICategory category = findCategories.get(0);
workItem.setCategory(category);
workItem.setCreator(repo.loggedInContributor());
workItem.setSeverity(arg0);
IDetailedStatus s = wc.save(null);


But I have no idea how can I fetch list of severities available. Any ideas?

One answer



permanent link
Jared Russell (1.3k12019) | answered Dec 19 '11, 1:52 p.m.

IProcessClientService processClient =
(IProcessClientService) repository.getClientLibrary(IProcessClientService.class);
URI uri = URI.create("My Project".replaceAll(" ", "%20"));
IProjectArea projectArea =
(IProjectArea) processClient.findProcessArea(uri, null, monitor);
IProjectAreaHandle projectAreaHandle = projectArea.getProjectArea();

IWorkItemClient workItemClient =
(IWorkItemClient) repository.getClientLibrary(IWorkItemClient.class);
IAttribute severityAttribtute =
workItemClient.findAttribute(projectAreaHandle, IWorkItem.SEVERITY_PROPERTY, monitor);
IEnumeration<? extends ILiteral> severities =
workItemClient.resolveEnumeration((IAttributeHandle) severityAttribtute.getItemHandle(), monitor);

ILiteral majorSeverity = null;
for(ILiteral severity : severities.getEnumerationLiterals()) {
if(severity.getName().equals("Major")) {
majorSeverity = severity;
break;
}
}

IWorkItem workItem = ...
IWorkItemWorkingCopyManager wcm = workItemClient.getWorkItemWorkingCopyManager();
wcm.connect((IWorkItemHandle) workItem.getItemHandle(), IWorkItem.FULL_PROFILE, monitor);
WorkItemWorkingCopy workingCopy = wcm.getWorkingCopy((IWorkItemHandle) workItem.getItemHandle());
IWorkItem workItemCopy = workingCopy.getWorkItem();
workItemCopy.setValue(severityAttribtute, majorSeverity.getIdentifier2().getStringIdentifier());
workingCopy.save(monitor);



Hello I would like to set the severity for my work item.

Here is my code:



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();
List<ICategory> findCategories= service.findCategories(projectArea, ICategory.FULL_PROFILE, monitor);
ICategory category = findCategories.get(0);
workItem.setCategory(category);
workItem.setCreator(repo.loggedInContributor());
workItem.setSeverity(arg0);
IDetailedStatus s = wc.save(null);


But I have no idea how can I fetch list of severities available. Any ideas?

Your answer


Register or to post your answer.