1 使用RTC Java API进行登录:
Login的步骤分为以下:
1 初始化启动RTC的平台TeamPlatform:TeamPlatform.startup();
2 获取RTC repository的连接
ITeamRepository teamRepository =
TeamPlatform.getTeamRepositoryService().getTeamRepository(repositoryURI);
其中repositoryURI为你需要连接的jazz server 的URI
3 注册用户:
teamRepository.registerLoginHandler(new LoginHandler(userId, password));
4 登陆:
IProgressMonitor monitor = new NullProgressMonitor();
teamRepository.login(monitor);
范例代码:
private static ITeamRepository login(String repositoryURI, String userId,String password) throws TeamRepositoryException{
ITeamRepository repository= TeamPlatform
.getTeamRepositoryService().getTeamRepository(repositoryURI);
repository.registerLoginHandler(new LoginHandler(userId, password));
repository.login(null);
return repository;
}
2 利用API进行查询:
1 获取查询客户端,审计客户端以及过程服务和进程监控;
IQueryClient queryClient= (IQueryClient) repository.getClientLibrary(IQueryClient.class);
IProcessClientService processClient =
(IProcessClientService) repository.getClientLibrary(IProcessClientService.class);
IAuditableClient auditableClient =
(IAuditableClient) repository.getClientLibrary(IAuditableClient.class);
2获取Project Area的引用
URI uri = URI.create(project_name.replace(" ", "%20"));
IProjectArea projectArea = (IProjectArea)processClient.findProcessArea(uri,null,null);
System.out.println(projectArea.getName());
其中project_name是你要查询的project area所对应的name
3 得到Project Area的查询属性对象
IQueryableAttributeFactory factory = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE);
IQueryableAttribute projectAreaAttribute =
factory.findAttribute(projectArea, IWorkItem.PROJECT_AREA_PROPERTY,
auditableClient, monitor);
4 构建查询表达式:AttributeOperation可以有多种操作符
AttributeExpression projectAreaExpression =
new AttributeExpression(projectAreaAttribute, AttributeOperation.EQUALS, projectArea);
如果有多个查询条件,可以使用Term来进行构建。
如Term term = new Term(Operator.AND);
term.add(projectAreaExpression1);
if (team_area != ""){
term.add(projectAreaExpression2);
}
term.add(projectAreaExpression3);
if (tag_term_and != null){
term.add(tag_term_and);
}
if (iteration_term_or !=null){
term.add(iteration_term_or);
}
5 获取查询结果:
IQueryResult> result =
queryClient.getResolvedExpressionResults(projectArea, term,IWorkItem.FULL_PROFILE);
6 遍历查询对象:
if (result !=null){
result.setLimit(num);
IAttribute type_attr= client.findAttribute(projectArea, IWorkItem.TYPE_PROPERTY,null);
IAttribute id_attr= client.findAttribute(projectArea, IWorkItem.ID_PROPERTY,null);
IAttribute summary_attr= client.findAttribute(projectArea, IWorkItem.SUMMARY_PROPERTY,null);
IAttribute owner_attr= client.findAttribute(projectArea, IWorkItem.OWNER_PROPERTY,null);
IAttribute priority_attr= client.findAttribute(projectArea, IWorkItem.PRIORITY_PROPERTY,null);
IAttribute severity_attr= client.findAttribute(projectArea, IWorkItem.SEVERITY_PROPERTY,null);
IAttribute creation_date_attr= client.findAttribute(projectArea, IWorkItem.CREATION_DATE_PROPERTY,null);
IAttribute modified_attr= client.findAttribute(projectArea, IWorkItem.MODIFIED_PROPERTY,null);
IAttribute tag_attr= client.findAttribute(projectArea, IWorkItem.TAGS_PROPERTY,null);
IAttribute resolution_date_attr= client.findAttribute(projectArea, IWorkItem.RESOLUTION_DATE_PROPERTY,null);
while (result.hasNext(null)) {
IResolvedResult resolved = result.next(null);
IWorkItem iwi = (IWorkItem) repository.itemManager().fetchCompleteItem(resolved.getItem(), IItemManager.DEFAULT, null);
String id = resolved.getItem().getValue(id_attr).toString();
String summary = resolved.getItem().getValue(summary_attr).toString();
......
....
}
3 获取development line 和iteration:
In the server side, once we have an item handle com.ibm.team.repository.service.IRepositoryItemService.fetchItem(IItemHandle, String[]) can be used to fetch the item. It would look like
IIteration iteration = getService(IRepositoryItemService.class).fetchItem(iterationHandle, IRepositoryItemService.COMPLETE)
To have access to the getService() method the server side advisor should extend com.ibm.team.repository.service.AbstractService.java. The steps are detailed in https://jazz.net/wiki/bin/view/Main/TeamProcessDeveloperGuide#Adding_New_Operation_Advisors.
In the client side advisor, code to fetch an item using its handle would look like
IProcessArea processArea = operation.getProcessArea(); //operation is the AdvisableOperation instance passed to the client side advisor
ITeamRepository repository = (ITeamRepository) processArea.getOrigin();
IItemManager itemManager = repository.itemManager();
IIteration iteration = (IIteration) itemManager.fetchCompleteItem(iterationHandle, IItemManager.DEFAULT, monitor);
有的时候一个project的development line分为好几个iteration,因此在查询的时候如果指定了plan for 为某个具体的iteration的handle,需要找到对应的iteration然后再构造查询表达式。
IDevelopmentLine line = null; if (developmentHandles != null) { List developmentLines = repository.itemManager().fetchCompleteItems(Arrays.asList(developmentHandles), IItemManager.DEFAULT, null); for (Iterator e = developmentLines.iterator(); e.hasNext();) { line = (IDevelopmentLine) e.next(); System.out.println("++++++"+line.getName()+"++++++"); IIterationHandle[] iterationHandles = line.getIterations(); if (iterationHandles !=null){ List iterationlines = repository.itemManager().fetchCompleteItems(Arrays.asList(iterationHandles), IItemManager.DEFAULT, null); IIteration iteration = null; for (Iterator e1 = iterationlines.iterator(); e1.hasNext();) { iteration = (IIteration) e1.next(); String interation_name = iteration.getName(); System.out.println("===="+interation_name+"====");