Search WorkItems based on the value of the Custom Attribute.
I need to retrieve the WorkItems of a particular Project Area based on the value of custom attribute which will be entered by the user as a search key work. I developing a web application to search the work items based on the value of the custom attribute. At this point I am able to retrieve the all the work items of type defect from a particular Project area.
Now I am struck at returning the work items with the custom attribute value as entered by the user from the web application. Please try to guide me to reach my goal.
Thank you.
Sujith
20 answers
https://rsjazz.wordpress.com/2012/10/29/using-work-item-queris-for-automation/
Comments
Yeah, but I am a bit confused with the concept of custom attributes. As in my doubt is, the custom attributes assigned at the Project Area level or at the Work Item level. At present i have the Work Item object. Can I get the custom attribute name and value from the work item object.
the definition of a custom attribute is at the project (could be in multiple workitems) AND workitem level (in this one)
nothing really special to get the data
see my sample pgm to print attributes from workitems in a query
accepted answer here https://jazz.net/forum/questions/94776/assertionfailedexception-problem-with-getting-the-values-of-attributes
this code does
private static void printResolved(IQueryClient queryClient,
execute query
loop thru all workitems in the query result
print attributes for this workitem
see the function static void printAttributes(IWorkItem workItem,
loop thru all attributes in project, check if in this workitem
for (IAttribute ia : workItemCommon.findAttributes(projectArea,
monitor))
{
}
Thanks a ton Sam. It worked :)
I have one small question regarding the fetching time of data from the API. Its taking a while, at first time launch of the web application and then the time is reduced on later pings. Can you tell me how to reduce the fetching time and restrict the logging in to the API on every time when I ping the method.
Thanks
Sujith G
I changed the loop to process the query results first, into a local array, then process the results from there. total query time was 12 seconds. a long time for a UI based app, but noise for batch. (total elapsed time for our app was still 8 hours, but it didn't fail cause of query timeout)..
you don't have to logon each time, assuming the same process.. the logon timeout can be set really high..
// and set the connection timeout, has to be set before login
server.setConnectionTimeout(seconds);
and u can recover from it.. I captured the exception, checked for timeout, and added an hour to the last setting
and logged on again.
catch (Exception ex)
{
if (ex.getMessage().contains("error occurred: \"java.net.SocketTimeoutException\""))
{
System.out.println("connection timeout, login and try again");
server.logout();
server.setConnectionTimeout(server.getConnectionTimeout()
+ one_hour);
server.login(null);
Comments
Yeah, thats a good idea to cut short the fetching time. And will there be any affect when I m trying to us load profile as Large Profile instead of Small Profile. Is it possible to create a custom load profile with custom attributes set along with the built in ones.
well, it either everything (ALL), or something less (SMALL, MEDIUM or your custom list)
here is an example of a special profile for details on a contributor (user)
ItemProfile.createProfile(IContributor.ITEM_TYPE, new String[] {
IContributor.ARCHIVED_PROPERTY,
IContributor.NAME_PROPERTY,
IContributor.EMAIL_ADDRESS_PROPERTY })
and here is one for a single attribute for the source code IComponent object
ItemProfile.createProfile(IComponent.ITEM_TYPE, IComponent.NAME_PROPERTY)
each object will give u a list of the properties available (I see these in Eclipse)
IAuditableCommon auditableCommon = (IAuditableCommon) repo.getClientLibrary(IAuditableCommon.class); IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(iProjectArea,IWorkItem.PROJECT_AREA_PROPERTY, auditableCommon, monitor);
IQueryableAttribute type = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(iProjectArea,IWorkItem.TYPE_PROPERTY, auditableCommon, monitor);
IQueryableAttribute custAttr = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(iProjectArea,"**********************", auditableCommon, monitor);
Expression inProjectArea = new AttributeExpression(attribute,AttributeOperation.EQUALS, iProjectArea);
Expression isType = new AttributeExpression(type,AttributeOperation.EQUALS, "defect");
Expression iscustAttr1 = new AttributeExpression(custAttr,AttributeOperation.CONTAINS,"*******************");
Expression iscustAttr2 = new AttributeExpression(custAttr,AttributeOperation.CONTAINS,"*******************");
Term orTerm= new Term(Term.Operator.OR);
orTerm.add(iscustAttr1);
orTerm.add(iscustAttr2);
Term typeinProjectArea= new Term(Term.Operator.AND);
typeinProjectArea.add(inProjectArea);
typeinProjectArea.add(isType);
typeinProjectArea.add(orTerm);
IQueryCommon queryCommon = (IQueryCommon) repo.getClientLibrary(IQueryCommon.class);
IQueryDescriptor descriptor = queryCommon.createQuery(iProjectArea, "MyQuery", "MyQuery", typeinProjectArea);
public class RTCPlainJavaConnection {
public static void getTeamRepositoryConnection(){
String repoUri = "***************************************";
final String userId = "***********************";
final String password = "**********";
SysoutProgressMonitor monitor=new SysoutProgressMonitor();
TeamPlatform.startup();
try {
// Login to the repository using the provided credentials
ITeamRepository repo = TeamPlatform.getTeamRepositoryService().getTeamRepository(repoUri);
//password=ObfuscationHelper.decryptString(password);
repo.registerLoginHandler(new ILoginHandler2() {
@Override
public ILoginInfo2 challenge(ITeamRepository arg0) {
return new UsernameAndPasswordLoginInfo(userId, password);
}
});
repo.login(monitor);
getProjectAreas(repo, monitor);
} catch (TeamRepositoryException x) {
x.printStackTrace();
}
}
@SuppressWarnings("unchecked")
public static void getProjectAreas(ITeamRepository repo, SysoutProgressMonitor monitor) throws TeamRepositoryException{
IProcessItemService connect = (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
List<IProjectArea> p = connect.findAllProjectAreas(null, monitor);
System.out.println("Project Areas :");
for(IProjectArea projectArea: p){
System.out.println(projectArea.getName());
}
getWorkItemsOfProjectArea(repo, p , monitor);
}
public static void getWorkItemsOfProjectArea(ITeamRepository repo,List<IProjectArea> p, SysoutProgressMonitor monitor) throws TeamRepositoryException{
for(IProjectArea projectArea: p){
if(projectArea.getName().equals("**********************")){
IAuditableCommon auditableClient = (IAuditableCommon) repo.getClientLibrary(IAuditableCommon.class);
IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(projectArea, IWorkItem.PROJECT_AREA_PROPERTY, auditableClient, monitor);
Expression expression = new AttributeExpression(attribute, AttributeOperation.EQUALS, projectArea);
resultsResolvedByExpression(repo, projectArea, expression, IWorkItem.LARGE_PROFILE,monitor);
}
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void resultsResolvedByExpression(
ITeamRepository teamRepository, IProjectArea projectArea,
Expression expression, ItemProfile profile , SysoutProgressMonitor monitor)
throws TeamRepositoryException {
IWorkItemClient workItemClient = (IWorkItemClient) teamRepository
.getClientLibrary(IWorkItemClient.class);
IQueryClient queryClient = workItemClient.getQueryClient();
IQueryResult<IResolvedResult<IWorkItem>> results = queryClient
.getResolvedExpressionResults(projectArea, expression, profile);
results.setLimit(Integer.MAX_VALUE);
System.out.println("The WorkItems of "+projectArea.getName()+" Project Area:");
getDefectWorkItems(results,monitor,teamRepository);
}
@SuppressWarnings("rawtypes")
public static List getDefectWorkItems(IQueryResult<IResolvedResult<IWorkItem>> results,SysoutProgressMonitor monitor,ITeamRepository repo) throws TeamRepositoryException{
int i=0;
List<IWorkItem> defectWorkitems=new ArrayList<IWorkItem>();
List customAttributes=null;
while(results.hasNext(monitor)){
IResolvedResult<IWorkItem> result = results.next(monitor);
IWorkItem workItem = (IWorkItem) result.getItem();
customAttributes=workItem.getCustomAttributes();
if(workItem.getWorkItemType().equals("defect")){
for (Iterator iterator = customAttributes .iterator(); iterator.hasNext();) {
IAttributeHandle iAttributeHandle = (IAttributeHandle) iterator.next();
IAttribute iAttribute = (IAttribute) repo
.itemManager().fetchCompleteItem(
iAttributeHandle, IItemManager.DEFAULT ,monitor);
if (workItem.hasAttribute(iAttribute)) {
if(iAttribute.getDisplayName().equals("*************************")){
if(String.valueOf(workItem.getValue(iAttribute)).equals("SearchKey")){
Object value = workItem.getValue(iAttribute);
System.out.println(iAttribute.getDisplayName()+":"+String.valueOf(value));
}
}
}
}
defectWorkitems.add(workItem);
}
i++;
}
System.out.println(customAttributes.size());
System.out.println("Total Defect WorkItems:" + defectWorkitems.size());
System.out.println("Total WorkItems in **************:"+i);
return defectWorkitems;
}
public static void main(String[] args){
RTCPlainJavaConnection.getTeamRepositoryConnection();
}
}
Comments
small change.. I would move all the service interface gets to one place, one time
IProcessItemService connect = (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
they won't change
more important change.. construct your query to only bring back the workitems of interest.. type-defect and attribute!=null.. then u will have less data and a smaller loop
1 vote
Thanks a lot Sam. This surely help me in making my web application more efficient than what it is now. Will make the changes and let you know if I have any queries. once again Thank You.
-Sujith G
Hi Sam,
Is there a way to get a specific project area instead of getting a list of all project areas and iterating through the list to get the desired project area.
Thanks
Sujith G
sure..given u have its name string.
from the top of my sample code
URI uri = URI.create(projectAreaName.replaceAll(" ", "%20"));
IProjectArea iprja = (IProjectArea) processClient.findProcessArea(uri, null, null);
returned value=null if not found
1 vote
Thanks Sam. And one more thing So I have to change below attribute to get the defect only at the first place rite.
IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(projectArea, IWorkItem.PROJECT_AREA_PROPERTY, auditableClient, monitor);
that only gets the projectarea property.
you would a workitem type property (type=defect)
and the custom attribute (attribute=value)
so you would need a compound query, a AND b AND c
Thank a lot Sam. I have made a compound query for project Area Property and Work Item Type ID...Have to figure out how to add the custom Attribute expression to the query.
Thanks
Sujith G
you find the custom attribute object by using its 'id' string.
IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(
>IWorkItem.PROJECT_AREA_PROPERTY is a String
"com.sd.workitem.defect.field_id" is a String
1 vote
Yeah, I know the ID string of my custom Attribute. So, I think the WorkItemTypeID in the second expression should be replaced by the Custom Attribute ID, Am I right Sam??
IQueryableAttribute type = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(iProjectArea,IWorkItem.TYPE_PROPERTY, auditableCommon, monitor); Expression isCustomAttribute= new AttributeExpression(type,AttributeOperation.EQUALS, "CustomAttributeID");
yes, correct
Okay, So where should I pass the user entered Custom Attribute value from the web application which will return only the work items with that Custom Attribute value ??
in your original code you used
// the object of the attribute
IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(projectArea, IWorkItem.PROJECT_AREA_PROPERTY, auditableClient, monitor);
// say when attribute equals value
Expression expression = new AttributeExpression(attribute, AttributeOperation.EQUALS, projectArea);
so you should have
attribute-project = specific projectarea_handle
AND
attribute-workitem_type= defect
AND
attribute-custom = value entered by user
1 vote
Yup, got it Sam. Sorry, my bad I think the earlier question was so stupid. :(
Anyways thanks a lot for helping me out till now. Actually, I m very new to RTC Plain Java API and that's the reason I wanted to be more specific in very thing.
Thanks
Sujith G
{ IAuditableCommon auditableCommon = (IAuditableCommon) repo.getClientLibrary(IAuditableCommon.class); IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(iProjectArea,IWorkItem.PROJECT_AREA_PROPERTY, auditableCommon, monitor); IQueryableAttribute type = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(iProjectArea,"*****************", auditableCommon, monitor); IQueryableAttribute custAttr = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(iProjectArea,IWorkItem.CUSTOM_ATTRIBUTES_PROPERTY, auditableCommon, monitor); Expression inProjectArea = new AttributeExpression(attribute,AttributeOperation.EQUALS, iProjectArea); Expression isType = new AttributeExpression(type,AttributeOperation.EQUALS, "defect"); Expression iscustAttr1 = new AttributeExpression(custAttr,AttributeOperation.CONTAINS,SerialNumberNPSNumberSplitUtil.splitSerialAndNPSNumber(searchKey)[0]);
Expression iscustAttr2 = new AttributeExpression(custAttr,AttributeOperation.CONTAINS,SerialNumberNPSNumberSplitUtil.splitSerialAndNPSNumber(searchKey)[1]);
Term typeinProjectArea= new Term(Term.Operator.AND);
typeinProjectArea.add(inProjectArea);
typeinProjectArea.add(isType);
typeinProjectArea.add(iscustAttr);
IQueryCommon queryCommon = (IQueryCommon) repo.getClientLibrary(IQueryCommon.class);
IQueryDescriptor descriptor = queryCommon.createQuery(iProjectArea, "MyQuery", "MyQuery", typeinProjectArea);
}
Comments
you would have to make an OR term
Term orTerm= new Term(Term.Operator.OR);
draw it out on paper
a & b & (custAttr or custAttr2)
I'm not as good on the grouping..
but the OR is an expression
a & b & expression (the OR)
1 vote
Thanks you so much Sam. you made my day. The search module is running like a charm. It would be great if I can get connected with you on LinkedIn.
Thanks
Sujith G
Thanks you so much Sam. you made my day. The search module is running like a charm. It would be great if I can get connected with you on LinkedIn.
Thanks
Sujith G
glad I could help.
maybe you could post that little section of your code that builds the query expression for others (and me!) to learn from..
CRJAZ1244I Not logged in to the repository at URL "http://****//**"
Comments
did you package the rtc plainjava toolkit with your web app. or install it on the linux server and put it where the webapp can connect to it?
But I have bundled all the Jar files along with the Webapp is that not sufficient ?? because even on my local system I have not done anything extra other than putting all the jars in the lib folder of my web app. :(
I just asked.. you said 'yes, bundled with web app'
can you access the rtc server via web browser from that linux machine?
it sounds like a network issue to me.
did u look at the ccm.log to see the stack trace from
repo.login(monitor);
getProjectAreas(repo, monitor);
} catch (TeamRepositoryException x) {
x.printStackTrace();
Hmm, for now I am accessing the linux server from putty terminal in my local system. And where can I find the cmm.log file ?
mine is in
rtc server folder/server/logs
I m afraid I wont be able to access it. Its also a remote server to me :(
sorry, sent you in the wrong direction.. I gave you the rtc server info.. not the server you were installing the app into.. my fault..
you should probably look in the tomcat catalina.out file..
tomcat/logs/catalina.out
I think this is where application errors are logged if they don't do their own logging
I think we are stuck here, and I m very bad at handling issue related to server :(
IAuditableCommon auditableCommon = (IAuditableCommon) repo.getClientLibrary(IAuditableCommon.class); IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(iProjectArea,IWorkItem.PROJECT_AREA_PROPERTY, auditableCommon, monitor);
IQueryableAttribute type = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(iProjectArea,IWorkItem.TYPE_PROPERTY, auditableCommon, monitor);
IQueryableAttribute custAttr = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(iProjectArea,"********************", auditableCommon, monitor);
Expression inProjectArea = new AttributeExpression(attribute,AttributeOperation.EQUALS, iProjectArea);
Expression isType = new AttributeExpression(type,AttributeOperation.EQUALS, "defect");
Expression iscustAttr1 = new AttributeExpression(custAttr,AttributeOperation.CONTAINS,"*********************");
Expression iscustAttr2 = new AttributeExpression(custAttr,AttributeOperation.CONTAINS,"*********************");
Term orTerm= new Term(Term.Operator.OR);
orTerm.add(iscustAttr1);
orTerm.add(iscustAttr2);
Term typeinProjectArea= new Term(Term.Operator.AND);
typeinProjectArea.add(inProjectArea);
typeinProjectArea.add(isType);
typeinProjectArea.add(orTerm);
IQueryCommon queryCommon = (IQueryCommon) repo.getClientLibrary(IQueryCommon.class);
IQueryDescriptor descriptor = queryCommon.createQuery(iProjectArea, "MyQuery", "MyQuery", typeinProjectArea);
SEVERE: Exception loading sessions from persistent storage
java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2298)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2767)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:798)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:298)
at org.apache.catalina.util.CustomObjectInputStream.<init>(CustomObjectInputStream.java:56)
at org.apache.catalina.session.StandardManager.doLoad(StandardManager.java:244)
at org.apache.catalina.session.StandardManager.load(StandardManager.java:202)
at org.apache.catalina.session.StandardManager.startInternal(StandardManager.java:489)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5499)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1898)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
com.ibm.team.repository.common.NotLoggedInException: CRJAZ1244I Not logged in to the repository at URL "https://jazzsdi04.svl.ibm.com:9445/ccm/". com.ibm.team.repository.client.internal.ServiceInterfaceProxy.ensureLoggedIn(ServiceInterfaceProxy.java:230) com.ibm.team.repository.client.internal.ServiceInterfaceProxy.validateServiceCall(ServiceInterfaceProxy.java:184) com.ibm.team.repository.client.internal.ServiceInterfaceProxy.invoke(ServiceInterfaceProxy.java:87) $Proxy150.findProcessArea(Unknown Source) com.ibm.team.process.internal.client.ProcessClientService$15.run(ProcessClientService.java:842) com.ibm.team.repository.client.internal.TeamRepository$3.run(TeamRepository.java:1287) com.ibm.team.repository.common.transport.CancelableCaller.call(CancelableCaller.java:79) com.ibm.team.repository.client.internal.TeamRepository.callCancelableService(TeamRepository.java:1280) com.ibm.team.process.internal.client.ProcessClientService.doFindProcessArea(ProcessClientService.java:836) com.ibm.team.process.internal.client.ProcessClientService.findProcessArea(ProcessClientService.java:794) com.ibm.pureradnetezza.services.RTCPlainJavaConnection.getProjectAreas(RTCPlainJavaConnection.java:69) com.ibm.pureradnetezza.services.RTCPlainJavaConnection.getTeamRepositoryConnection(RTCPlainJavaConnection.java:62) com.ibm.pureradnetezza.controller.HomePageController.search(HomePageController.java:49) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:601) org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) javax.servlet.http.HttpServlet.service(HttpServlet.java:620) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
public class RTCPlainJavaConnection {
public static List<IWorkItem> getTeamRepositoryConnection(String searchKey) throws TeamRepositoryException{
String repoUri = "************************************";
final String userId = "*******************";
final String password = "***********";
String projectAreaName = "************************";
ITeamRepository repo = null;
SysoutProgressMonitor monitor=new SysoutProgressMonitor();
TeamPlatform.startup();
try {
// Login to the repository using the provided credentials
repo = TeamPlatform.getTeamRepositoryService().getTeamRepository(repoUri);
//password=ObfuscationHelper.decryptString(password);
repo.registerLoginHandler(new ILoginHandler2() {
@Override
public ILoginInfo2 challenge(ITeamRepository arg0) {
return new UsernameAndPasswordLoginInfo(userId, password);
}
});
repo.login(monitor);
} catch (TeamRepositoryException x) {
x.printStackTrace();
}
return getProjectAreas(repo, projectAreaName, monitor, searchKey);
}
//Get the desired Project Area by using IProjectArea
public static List<IWorkItem> getProjectAreas(ITeamRepository repo, String projectAreaName, SysoutProgressMonitor monitor, String searchKey) throws TeamRepositoryException{
IProcessItemService connect = (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
URI uri = URI.create(projectAreaName.replaceAll(" ", "%20"));
IProjectArea iProjetctArea = (IProjectArea) connect.findProcessArea(uri, null, monitor);
if (iProjetctArea == null)
{
System.out.println("Project area not found.");
return null;
} else{
System.out.println("Project Area Selected : "+iProjetctArea.getName());
return getWorkItemsOfProjectArea(repo, iProjetctArea , monitor, searchKey);
}
}
//Query to get the Work Items from the acquired Project Area, those which are of type Defect and also which has ID as User Search Key.
public static List<IWorkItem> getWorkItemsOfProjectArea(ITeamRepository repo,IProjectArea iProjectArea, SysoutProgressMonitor monitor, String searchKey) throws TeamRepositoryException{
IAuditableCommon auditableCommon = (IAuditableCommon) repo.getClientLibrary(IAuditableCommon.class);
IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(iProjectArea,IWorkItem.PROJECT_AREA_PROPERTY, auditableCommon, monitor);
IQueryableAttribute type = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(iProjectArea,IWorkItem.TYPE_PROPERTY, auditableCommon, monitor);
IQueryableAttribute custAttr = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(iProjectArea,"********************", auditableCommon, monitor);
Expression inProjectArea = new AttributeExpression(attribute,AttributeOperation.EQUALS, iProjectArea);
Expression isType = new AttributeExpression(type,AttributeOperation.EQUALS, "defect");
Expression iscustAttr1 = new AttributeExpression(custAttr,AttributeOperation.CONTAINS,"********************");
Expression iscustAttr2 = new AttributeExpression(custAttr,AttributeOperation.CONTAINS,"********************");
Term orTerm= new Term(Term.Operator.OR);
orTerm.add(iscustAttr1);
orTerm.add(iscustAttr2);
Term typeinProjectArea= new Term(Term.Operator.AND);
typeinProjectArea.add(inProjectArea);
typeinProjectArea.add(isType);
typeinProjectArea.add(orTerm);
IQueryCommon queryCommon = (IQueryCommon) repo.getClientLibrary(IQueryCommon.class);
IQueryDescriptor descriptor = queryCommon.createQuery(iProjectArea, "MyQuery", "MyQuery", typeinProjectArea);
return resultsResolvedByExpression(repo, iProjectArea, descriptor, IWorkItem.LARGE_PROFILE,monitor,searchKey);
}
//Get the result set for the above compound query and store it in Resolved Result List.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static List<IWorkItem> resultsResolvedByExpression(
ITeamRepository teamRepository, IProjectArea projectArea,
IQueryDescriptor query, ItemProfile profile , SysoutProgressMonitor monitor, String searchKey)
throws TeamRepositoryException {
IWorkItemClient workItemClient = (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);
IQueryClient queryClient = workItemClient.getQueryClient();
IQueryResult<IResolvedResult<IWorkItem>> results = queryClient.getResolvedQueryResults(query, profile);
results.setLimit(Integer.MAX_VALUE);
System.out.println("The WorkItems of "+projectArea.getName()+" Project Area:");
return getDefectWorkItems(results,monitor,teamRepository, searchKey);
}
//Get the Work Item from the Resolved Result List and get all the Custom Attributes of that Work Item and return the ArrayList with the WorkItems
@SuppressWarnings("rawtypes")
public static List<IWorkItem> getDefectWorkItems(IQueryResult<IResolvedResult<IWorkItem>> results,SysoutProgressMonitor monitor,ITeamRepository repo, String searchKey) throws TeamRepositoryException{
List<IWorkItem> defectWorkitems=new ArrayList<IWorkItem>();
List customAttributes=null;
while(results.hasNext(monitor)){
IResolvedResult<IWorkItem> result = results.next(monitor);
IWorkItem workItem = (IWorkItem) result.getItem();
customAttributes=workItem.getCustomAttributes();
for (Iterator iterator = customAttributes .iterator(); iterator.hasNext();) {
IAttributeHandle iAttributeHandle = (IAttributeHandle) iterator.next();
IAttribute iAttribute = (IAttribute) repo
.itemManager().fetchCompleteItem(
iAttributeHandle, IItemManager.DEFAULT ,monitor);
if (workItem.hasAttribute(iAttribute)) {
if(iAttribute.getDisplayName().equals("****************")){
Object value = workItem.getValue(iAttribute);
}
}
}
defectWorkitems.add(workItem);
}
System.out.println("Total Defect WorkItems:" + defectWorkitems.size());
return defectWorkitems;
}
}
Comments
I understand.. but if there is a login problem, your code continues on
repo.login(monitor);
} catch (TeamRepositoryException x) {
x.printStackTrace();
}
return getProjectAreas(repo, projectAreaName, monitor, searchKey);
there should have been some other feedback, because the exception says 'not logged in'
maybe in localhost log in the same folder as catalina.out.
I usually use eclipse to debug all these problems...
search in google for instructions on setup
'debug tomcat web application in eclipse'
yeah, because If there is a problem in the code. It shouldn't be working on the local machine too. So do you mean to tell me to use remote debug option in eclipse ?
I don't know.. I haven't had any time to look at your issue..
can you timestamp and see where the time is being spent?