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