How can I programmatically get the list of Plans in an RTC Project Area using plain java client api and then access the workitems ?
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
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
showing 5 of 7
show 2 more comments
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