Search WorkItems based on the value of the Custom Attribute.
Hi
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
see Ralph's blog post about using queries like this
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.
sam detweiler
commented Aug 25 '14, 5:23 p.m.
the definition of a custom attribute is at the project (could be in multiple workitems) AND workitem level (in this one)
Sujith Gannamaneni
commented Aug 26 '14, 8:40 a.m.
Thanks a ton Sam. It worked :)
|
the sample does that double nested loop. On one of my enagagements we had to process 8,000 workitems.. the query kept timing out after 30 minutes, but we weren't done.. (total processing took 8 hours)..
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
Sujith Gannamaneni
commented Aug 26 '14, 9:01 a.m.
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 you go, below is the code snippet in which I am building the query expression.
IAuditableCommon auditableCommon = (IAuditableCommon) repo.getClientLibrary(IAuditableCommon.class); IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(iProjectArea,IWorkItem.PROJECT_AREA_PROPERTY, auditableCommon, monitor); |
Thanks Sam. One last thing, can you please have a look at my code and tell me if I have to make any changes in it to make it more efficient.
public class RTCPlainJavaConnection { public static void getTeamRepositoryConnection(){ String repoUri = "***************************************"; final String userId = "***********************"; final String password = "**********"; @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); 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); @SuppressWarnings({ "rawtypes", "unchecked" }) public static void resultsResolvedByExpression( ITeamRepository teamRepository, IProjectArea projectArea, Expression expression, ItemProfile profile , SysoutProgressMonitor monitor) @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>(); public static void main(String[] args){ RTCPlainJavaConnection.getTeamRepositoryConnection(); } } Comments 1
sam detweiler
commented Aug 26 '14, 9:25 a.m.
small change.. I would move all the service interface gets to one place, one time
Sujith Gannamaneni
commented Aug 26 '14, 9:31 a.m.
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 Gannamaneni
commented Aug 26 '14, 11:28 a.m.
Hi Sam,
1
sure..given u have its name string.
Sujith Gannamaneni
commented Aug 26 '14, 11:36 a.m.
Thanks Sam. And one more thing So I have to change below attribute to get the defect only at the first place rite.
sam detweiler
commented Aug 26 '14, 12:05 p.m.
that only gets the projectarea property.
Sujith Gannamaneni
commented Aug 26 '14, 1:42 p.m.
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.
1
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");
sam detweiler
commented Aug 26 '14, 2:08 p.m.
yes, correct
Sujith Gannamaneni
commented Aug 26 '14, 2:14 p.m.
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 ??
1
sam detweiler
commented Aug 26 '14, 2:29 p.m.
in your original code you used
Sujith Gannamaneni
commented Aug 26 '14, 2:40 p.m.
Yup, got it Sam. Sorry, my bad I think the earlier question was so stupid. :(
showing 5 of 13
show 8 more comments
|
I have a situation where in I am splitting the search key into two and have to check if any of those are present in the custom-attribute value. How can I do that in Term with AND and OR.
Comments 1
sam detweiler
commented Aug 26 '14, 3:21 p.m.
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.
Sujith Gannamaneni
commented Aug 26 '14, 3:31 p.m.
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.
sam detweiler
commented Aug 26 '14, 5:13 p.m.
glad I could help.
|
And Sam, I have a problem with my Web Application. Actually When i am running the application on my local tomcat server, the application is running fine. But when I m deploying it into the remote tomcat server on a Linux machine, its giving the following error.
CRJAZ1244I Not logged in to the repository at URL "http://****//**"Comments
sam detweiler
commented Aug 27 '14, 11:16 a.m.
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?
Sujith Gannamaneni
commented Aug 27 '14, 11:29 a.m.
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. :(
sam detweiler
commented Aug 27 '14, 11:36 a.m.
I just asked.. you said 'yes, bundled with web app'
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 ?
sam detweiler
commented Aug 27 '14, 11:51 a.m.
mine is in
Sujith Gannamaneni
commented Aug 27 '14, 11:59 a.m.
I m afraid I wont be able to access it. Its also a remote server to me :(
sam detweiler
commented Aug 27 '14, 12:05 p.m.
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..
Sujith Gannamaneni
commented Aug 27 '14, 12:41 p.m.
I think we are stuck here, and I m very bad at handling issue related to server :(
showing 5 of 8
show 3 more comments
|
Here you go below is the code snippet for building the query expression
IAuditableCommon auditableCommon = (IAuditableCommon) repo.getClientLibrary(IAuditableCommon.class); IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(iProjectArea,IWorkItem.PROJECT_AREA_PROPERTY, auditableCommon, monitor); |
This is the error i see in the log
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) |
Sam below is the exact error which I am getting when I go with search after deploying
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) Comments
sam detweiler
commented Aug 27 '14, 12:54 p.m.
where do you login?
|
Below is the exact code which I am deploying
public class RTCPlainJavaConnection { public static List<IWorkItem> getTeamRepositoryConnection(String searchKey) throws TeamRepositoryException{ //Get the desired Project Area by using IProjectArea //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. //Get the result set for the above compound query and store it in Resolved Result List. //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 Comments
sam detweiler
commented Aug 27 '14, 1:53 p.m.
I understand.. but if there is a login problem, your code continues on
Sujith Gannamaneni
commented Aug 27 '14, 2:04 p.m.
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 ?
sam detweiler
commented Sep 30 '14, 10:13 a.m.
I don't know.. I haven't had any time to look at your issue..
|
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.