How to get the "Filed Against" value from RTCJavaP
I need to get the "Filed Against" value from RTC by using java plain api. I wrote following code:
This does not work, is there someone can help on this? Thanks a lot!
IAttribute component= workItemClient.findAttribute(projectAreaHandle, IWorkItem.CATEGORY_PROPERTY, monitor);
Identifier<ILiteral> component1= (com.ibm.team.workitem.common.model.Identifier<ILiteral>)workItem.getValue(component);
IEnumeration<ILiteral> componentEnumeratoin = (IEnumeration<ILiteral>)workItemClient.resolveEnumeration(component, monitor);
ILiteral component2 = componentEnumeratoin.findEnumerationLiteral(component1);
This does not work, is there someone can help on this? Thanks a lot!
Accepted answer
I would suggest to look here: https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/
4 other answers
here is customizing code about plain jave api support by ibm.
how to get category name about workitemId
IProgressMonitor monitor = new SysoutProgressMonitor();
ITeamRepository repo = Snippet1.login(monitor);
IItemManager itm = repo.itemManager();
IWorkItemClient service = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);
IWorkItem workItem = service.findWorkItemById(workItemId, IWorkItem.FULL_PROFILE, monitor);
ICategory category = (ICategory) itm.fetchCompleteItem(workItem.getCategory(), IItemManager.DEFAULT, monitor);
System.out.println("This is category: " + category.getName());
how to get category name about workitemId
IProgressMonitor monitor = new SysoutProgressMonitor();
ITeamRepository repo = Snippet1.login(monitor);
IItemManager itm = repo.itemManager();
IWorkItemClient service = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);
IWorkItem workItem = service.findWorkItemById(workItemId, IWorkItem.FULL_PROFILE, monitor);
ICategory category = (ICategory) itm.fetchCompleteItem(workItem.getCategory(), IItemManager.DEFAULT, monitor);
System.out.println("This is category: " + category.getName());
I need to check the existing value of "Filed Against" value and then set it to new value.
Appriciate any suggessions or Piece of code.
Thanks in Advance
Radhika Bandari
public static void main(String[] args) {
TeamPlatform.startup();
try {
IProgressMonitor monitor = new SysoutProgressMonitor();
ITeamRepository repo = Snippet1.login(monitor);
// update workItem values
updateWorkItem(repo, 69, monitor);
} catch (TeamRepositoryException e) {
System.out.println("Unable to login: " + e.getMessage());
} finally {
TeamPlatform.shutdown();
}
}
public static IWorkItemHandle updateWorkItem(ITeamRepository repo, int workItemId, IProgressMonitor monitor) throws TeamRepositoryException {
IItemManager itm = repo.itemManager();
IWorkItemClient service = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);
IWorkItem workItem = service.findWorkItemById(workItemId, IWorkItem.FULL_PROFILE, monitor);
//get existing category value.
ICategory category = (ICategory) itm.fetchCompleteItem(workItem.getCategory(), IItemManager.DEFAULT, monitor);
System.out.println("This is category: " + category.getName());
// ready new category value.
List<String> path= Arrays.asList("JUnit/Tests".split("/"));
ICategoryHandle newCategoryHandle = service.findCategoryByNamePath(workItem.getProjectArea(), path, monitor);
IWorkItemWorkingCopyManager wcm = service.getWorkItemWorkingCopyManager();
wcm.connect(workItem, IWorkItem.FULL_PROFILE, monitor);
try {
WorkItemWorkingCopy wc = wcm.getWorkingCopy(workItem);
// set new category value.
wc.getWorkItem().setCategory(newCategoryHandle);
//String actionName = "com.ibm.team.workitem.defectWorkflow.action.startWorking";
String actionName = "modify";
wc.setWorkflowAction(actionName);
System.out.println(wc.getWorkflowAction());
IDetailedStatus s = wc.save(monitor);
if (!s.isOK()) {
throw new TeamRepositoryException("Error saving work item", s.getException());
}
} finally {
wcm.disconnect(workItem);
}
return workItem;
}
Object data=arg0.getOperationData();
ISaveParameter param=null;
if (data instanceof ISaveParameter) {
param = (ISaveParameter) data;
}
IWorkItem workItem= newstate(data);
IAuditableCommon iAuditableCommon = (param).getSaveOperationParameter().getAuditableCommon();
IWorkItemCommon workItemCommon =iAuditableCommon.getPeer(IWorkItemCommon.class);
ICategoryHandle iCategoryHandle = workItem.getCategory();