It's all about the answers!

Ask a question

How can I programmatically get the list of Plans in an RTC Project Area using plain java client api and then access the workitems ?


Anirban Roy (1318) | asked Jun 06 '17, 7:27 a.m.

 Our organization uses an RTC server to maintain all the work items. I need to develop a java client and connect to the jazz server [https://<OurOurganizationRTCWebSite>:9443/ccm/].I have done the login part but I need to retrieve the RTC plans from the project areas and then from the plans retrieve the work items.

Please help me.
Its urgent

2 answers



permanent link
Ralph Schoon (63.5k33646) | answered Jun 06 '17, 7:55 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

There is no really supported Java Plan API. Plans are no longer supported in the Eclipse client either.  A plan is also really only a work item query. You should not try to work with the plans API, you should use the work item API.


Instead of trying to work with a plan use https://rsjazz.wordpress.com/2012/11/19/using-expressions-for-automation/ expressions and set the values such as planned for and the filed against. values. 

Pretty much all code needed for the work item API can be found in the work item command line, including tooling to get iterations from timelines etc.:   https://rsjazz.wordpress.com/2017/03/29/the-work-item-command-line-is-now-open-source/


 


Comments
Anirban Roy commented Jun 07 '17, 2:28 a.m.

 Hi ralph,

Thanks ,but it would be better if you provide me the code for getting the timeline and  from timeline  iterations and then retrieve the workitems and its attributes.
I am in desire need .Please help me.


Ralph Schoon commented Jun 07 '17, 2:32 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

If you would be in dire need, you would basically look into the code provided on the links.


Ralph Schoon commented Jun 07 '17, 3:05 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

In addition, the code published in the blogs actually compiles which code pasted here does not.


Anirban Roy commented Jun 08 '17, 7:03 a.m.

 Thanks Ralph,

Can I get all work items id of a particular iteration from that particular iteration?If so, help me 


Anirban Roy commented Jun 08 '17, 7:10 a.m.

And along with with its attributes


Ralph Schoon commented Jun 08 '17, 7:16 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Yes, you can use queries or expressions to do so. I provided you links with what you need to get started if you where interested. Expressions are harder, because you have to find the iteration objects in the database. The blog I am referring to provides pretty much all the API code you would need in examples. Additional examples can be found here in this forum if you know how to search. 


Good luck.

  


Anirban Roy commented Jun 12 '17, 7:19 a.m. | edited unknown


I have used the code below but i cannot get the name of the workitems and all its attributes .Also i need to get from which iteration the workitrem came. Please help me

showing 5 of 7 show 2 more comments

permanent link
Anirban Roy (1318) | answered Jun 12 '17, 7:30 a.m.

 

public class mRTC232 { 

    static String repository_address = "xxxxxx ";
    static String userId = "xxxxx"; 
    static String password = "xxxxx"; 
    static String projectAreaName = "xxxx"; 

    public static void main(String[] args) throws TeamRepositoryException { 

        System.out.println("Main runned"); 
        TeamPlatform.startup(); 
        ITeamRepository repository = TeamPlatform.getTeamRepositoryService() 
                .getTeamRepository(repository_address); 

        repository.registerLoginHandler(new ITeamRepository.ILoginHandler() { 
            public ILoginInfo challenge(ITeamRepository repository) { 
                return new ILoginInfo() { 
                    public String getUserId() { 
                        return userId; 
                    } 

                    public String getPassword() { 
                        return password; 
                    } 
                }; 
            } 
        }); 

        // IProgressMonitor monitor = new SysoutProgressMonitor(); 
        IProgressMonitor monitor = null; 
        try { 
            repository.login(null); 
        } catch (TeamRepositoryException e) { 
            e.printStackTrace(); 
        } 
        if (repository.getState() == 1) { 
            System.out.println("CONNECTED to: " + repository_address); 
        } 

        // -------------- 
        IWorkItemClient service = (IWorkItemClient) repository 
                .getClientLibrary(IWorkItemClient.class); 
        IQueryClient queryClient = (IQueryClient) repository 
                .getClientLibrary(IQueryClient.class); 
        IProcessClientService processClient = (IProcessClientService) repository 
                .getClientLibrary(IProcessClientService.class);
        
        // Replace
       / URI uri = URI.create(projectAreaName.replaceAll(" ", "%20")); 
        IProjectArea projectArea = (IProjectArea) processClient 
                .findProcessArea(uri, null, null);
        /
        
       
            
            IProcessItemService itemService = (IProcessItemService) repository
    .getClientLibrary(IProcessItemService.class);
    List pAreas = itemService.findAllProjectAreas(null, null);  
       
            
            for (Iterator iterator = pAreas.iterator(); iterator.hasNext();) {
IProjectArea projectAreas = (IProjectArea) iterator.next();
if(projectAreas.getName().equals("Tools"))
{
IAuditableClient iac = (IAuditableClient) repository.getClientLibrary(IAuditableClient.class); 
       
       // getting workitems 
       Term term = new Term(Operator.AND); 
       IQueryResult<IResolvedResult<IWorkItem>> result = queryClient 
               .getResolvedExpressionResults(projectAreas, term, 
                       IWorkItem.FULL_PROFILE); 

       for (int k = 0; result.hasNext(null); k++) { 
           System.out.println("WORKITEM------------------------------------------------"); 

           IResolvedResult<IWorkItem> resolved = result.next(null); 
System.out.println(resolved.getItem().toString());
}
}
            //Custom attributes 
           // WorkItem wi = new WorkItem(); 
           / if (!resolved.getItem().getCustomAttributes().isEmpty()) { 
                for (int i = 0; i < resolved.getItem().getCustomAttributes() 
                        .size(); i++) { 
                    com.ibm.team.workitem.common.model.IAttributeHandle handle = resolved 
                            .getItem().getCustomAttributes().get(i); 
                    com.ibm.team.workitem.common.model.IAttribute attribute = (IAttribute) repository 
                            .itemManager().fetchCompleteItem(handle, 
                                    IItemManager.DEFAULT, 
                                    new NullProgressMonitor()); // 
                    System.out.println("The attribute id: " 
                            + attribute.getIdentifier()); 
                    System.out.println("The attribute name: " 
                            + attribute.getDisplayName()); 
                   System.out.println(attribute.getOrigin()+"   "+attribute.getAttributeType()+" "+attribute.modified()+" "+attribute.getContextId()+" "+attribute.getModifiedBy());
                            printAttributes(resolved.getItem(), repository, iac, projectArea, monitor); 
                    try { 
                        
                    } catch (Exception e) { 
                        System.out.println("ASSERTION FAILED!!!!"); 
                    } /
               // } 
            
            //Builtin attributtes 
            
            List<IAttributeHandle> builtInAttributeHandles = service 
                    .findBuiltInAttributes(projectAreas, monitor); 
            IFetchResult builtIn = repository.itemManager() 
                    .fetchCompleteItemsPermissionAware(builtInAttributeHandles, 
                            IItemManager.REFRESH, monitor); 
            
            for (Iterator it = builtIn.getRetrievedItems().iterator(); it 
                    .hasNext();) { 
                com.ibm.team.workitem.common.model.IAttributeHandle handle = (IAttributeHandle) it 
                        .next(); 
                com.ibm.team.workitem.common.model.IAttribute attribute = (IAttribute) repository 
                        .itemManager() 
                        .fetchCompleteItem(handle, IItemManager.DEFAULT, 
                                new NullProgressMonitor()); 
                System.out.println("  Built In Attribute: " 
                        + attribute.getDisplayName()+ attribute.); 
                System.out.println(" Type: " + attribute.getAttributeType()); 
               / try { 
                    // wi.getAttributeValue(attribute, resolved.getItem()); 
                    System.out.println("  Value " 
                            + resolved.getItem().getValue(attribute)); 

                } catch (AssertionFailedException e) { 
                    System.out.println(e.toString()); 
                } /
            } 
            
        } 
        
        
    }
    
    
  

    static void printAttributes(IWorkItem workItem,ITeamRepository repository, 
            IAuditableClient auditableClient, IProjectArea projectArea, 
            org.eclipse.core.runtime.IProgressMonitor monitor) { 
        
        IWorkItemCommon workItemCommon = (IWorkItemCommon) repository.getClientLibrary(IWorkItemCommon.class); 
        
        try { 
            for (IAttribute ia : workItemCommon.findAttributes(projectArea, 
                    monitor)) { 

                if ((workItem.hasAttribute(ia))  && ! ia.isBuiltIn()) 
 { 
                    System.out.println("\t\t\tprocessing for variable=" 
                            + ia.getDisplayName() + " attrib type=" 
                            + ia.getAttributeType() + " kind=" 
                            + ia.getFullTextKind()); 
                    try { 
                        // this will throw exception if not enumeration 
                        IEnumeration<ILiteral> enumeration = (IEnumeration<ILiteral>) workItemCommon 
                                .resolveEnumeration(ia, monitor); 
                        if (enumeration != null) { 
                            String[] iaval = ia 
                                    .getValue(auditableClient, workItem, 
                                            monitor).toString().split(":"); 
                            if (iaval.length > 1 && iaval[1] != null) { 
                                List<ILiteral> enumerationLiterals = enumeration 
                                        .getEnumerationLiterals(); 
                                for (ILiteral literal : enumerationLiterals) { 
                                    if (literal.getIdentifier2() 
                                            .getStringIdentifier() 
                                            .equalsIgnoreCase(iaval[1])) { 
                                        System.out 
                                                .println("\t\t\t\t --> attribute name=" 
                                                        + ia.getIdentifier() 
                                                        + ", type" 
                                                        + "=" 
                                                        + ia.getAttributeType() 
                                                        + " literal=" 
                                                        + literal 
                                                                .getIdentifier2() 
                                                                .getStringIdentifier() 
                                                        + " literal name=" 
                                                        + literal.getName()); 
                                        break; 
                                    } 
                                } 
                            } 
                        } 
                    } catch (Exception e) { 
                        System.out.println("\t\t\t\tattribute name=" 
                                + ia.getIdentifier() 
                                + ", type" 
                                + "=" 
                                + ia.getAttributeType() 
                                + " value=" 
                                + ia.getValue(auditableClient, workItem, 
                                        monitor)); 
                    } 
                } 
            } 
        } catch (Exception e) { 
            // TODO Auto-generated catch block 
            System.out.println("outer Exception=" + e.toString()); 
        } 
    } 

}// Main END 


Comments
Anirban Roy commented Jun 12 '17, 7:49 a.m.

 I have used the code but i cannot get the name of the workitems and all its attributes .Also i need to get from which iteration the workitrem came. Please help me.urgent!!!

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.