It's all about the answers!

Ask a question

Search WorkItems based on the value of the Custom Attribute.


Sujith Gannamaneni (1637) | asked Aug 25 '14, 4:04 p.m.
edited Aug 25 '14, 4:05 p.m.
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



permanent link
sam detweiler (12.5k6195201) | answered Aug 25 '14, 4:09 p.m.
see Ralph's blog post about using queries like this

https://rsjazz.wordpress.com/2012/10/29/using-work-item-queris-for-automation/

Comments
Sujith Gannamaneni commented Aug 25 '14, 4:13 p.m. | edited Aug 25 '14, 4:23 p.m.

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)

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))
            {
            }


Sujith Gannamaneni commented Aug 26 '14, 8:40 a.m.

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


permanent link
sam detweiler (12.5k6195201) | answered Aug 26 '14, 8:53 a.m.
edited Aug 26 '14, 8:53 a.m.
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. 


sam detweiler commented Aug 26 '14, 9:06 a.m. | edited Aug 26 '14, 9:08 a.m.

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)


permanent link
Sujith Gannamaneni (1637) | answered Aug 27 '14, 11:03 a.m.
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);
        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);

Comments
sam detweiler commented Aug 27 '14, 11:19 a.m.

very nice. thank you


permanent link
Sujith Gannamaneni (1637) | answered Aug 26 '14, 9:18 a.m.
edited Aug 26 '14, 9:34 a.m.
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 = "**********";
        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
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
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


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 G


Sujith Gannamaneni commented Aug 26 '14, 11:28 a.m.

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


1
sam detweiler commented Aug 26 '14, 11:33 a.m. | edited Aug 26 '14, 11:33 a.m.

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


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.

IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(projectArea, IWorkItem.PROJECT_AREA_PROPERTY, auditableClient, monitor);
              



sam detweiler commented Aug 26 '14, 12:05 p.m.

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


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.

Thanks
Sujith G


1
sam detweiler commented Aug 26 '14, 1:46 p.m. | edited Aug 26 '14, 1:53 p.m.

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


Sujith Gannamaneni commented Aug 26 '14, 2:01 p.m. | edited Aug 26 '14, 2:02 p.m.

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
// 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


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. :(
 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

showing 5 of 13 show 8 more comments

permanent link
Sujith Gannamaneni (1637) | answered Aug 26 '14, 3:12 p.m.
edited Aug 26 '14, 3:14 p.m.
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.

{
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
1
sam detweiler commented Aug 26 '14, 3:21 p.m.


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)


Sujith Gannamaneni commented Aug 26 '14, 3:30 p.m. | edited unknown

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


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.

Thanks
Sujith G


sam detweiler commented Aug 26 '14, 5:13 p.m.

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..


permanent link
Sujith Gannamaneni (1637) | answered Aug 27 '14, 11:06 a.m.
edited Aug 27 '14, 11:07 a.m.
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'
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();


Sujith Gannamaneni commented Aug 27 '14, 11:42 a.m. | edited Aug 27 '14, 11:42 a.m.

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

rtc server folder/server/logs


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..

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


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

permanent link
Sujith Gannamaneni (1637) | answered Aug 27 '14, 11:53 a.m.
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);
        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);



permanent link
Sujith Gannamaneni (1637) | answered Aug 27 '14, 12:13 p.m.
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)


permanent link
Sujith Gannamaneni (1637) | answered Aug 27 '14, 12:48 p.m.
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?
    com.ibm.pureradnetezza.services.RTCPlainJavaConnection.getTeamRepositoryConnection(RTCPlainJavaConnection.java:62)   com.ibm.pureradnetezza.controller.HomePageController.search(HomePageController.java:49)

appears to assume that login worked correctly


permanent link
Sujith Gannamaneni (1637) | answered Aug 27 '14, 1:16 p.m.
Below is the exact code which I am deploying

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
sam detweiler commented Aug 27 '14, 1:53 p.m.

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'


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..

can you timestamp and see where the time is being spent?

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.