How to get list of severities using Java API?
Hello I would like to set the severity for my work item.
Here is my code:
But I have no idea how can I fetch list of severities available. Any ideas?
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
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?