RTC Java API 学习笔记

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<IResolvedResult<IWorkItem>> 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<IWorkItem> 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+"====");

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

惹不起的程咬金

来都来了,不赏点银子么

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值