It's all about the answers!

Ask a question

Querying with Plain Java Client API problem :(


Abraham Ayorinde (112) | asked Jul 26 '16, 5:01 p.m.
edited Aug 01 '16, 12:41 p.m. by David Lafreniere (4.6k7)
This line:
 queryClient.getResolvedExpressionResults(projectArea, term, IWorkItem.SMALL_PROFILE);
has raised the error
Argument must be an instance of IAuditableHandle, queryClient.getResolvedExpressionResults
	
	
	
	
The arguments should comply with the following specification:
IWorkItem> IQueryResult<IResolvedResult<IWorkItem>> com.ibm.team.workitem.common.IQueryCommon.getResolvedExpressionResults
The code section below provides more context.

IQueryableAttribute attribute = findAttribute(projectArea, IWorkItem.OWNER_PROPERTY, myProgressMonitor, repo);
	

AttributeExpression Expression1= new AttributeExpression(attribute, AttributeOperation.EQUALS, "dude");
	
IQueryableAttribute attribute2 = findAttribute(projectArea,IWorkItem.CREATOR_PROPERTY, myProgressMonitor, repo);
AttributeExpression Expression2 = new AttributeExpression(attribute2, AttributeOperation.EQUALS, "guy");
Term term= new Term(Operator.AND); term.add(Expression1); term.add(Expression2);
IQueryClient queryClient= (IQueryClient) repo.getClientLibrary(IQueryClient.class);
queryClient.getResolvedExpressionResults(projectArea, term, IWorkItem.SMALL_PROFILE); 

4 answers



permanent link
sam detweiler (12.4k6180201) | answered Jul 27 '16, 7:47 a.m.
'term' is not an Expression..
you want either Expression1 or Expression2..

Comments
Abraham Ayorinde commented Jul 27 '16, 8:20 a.m.

I was hopeful, but I still receive the same error. :(

Thanks anyway.


sam detweiler commented Jul 27 '16, 8:59 a.m.

ok, well, that only leaves 1 parameter left.. what is the definition of projectArea?>


Abraham Ayorinde commented Jul 27 '16, 10:32 a.m.
My definition is as below.

IProjectArea projectArea = (IProjectArea)processClient.findProcessArea(uri,null,null);
    

sam detweiler commented Jul 27 '16, 11:39 a.m.

ok, the api and the error say handle.

Argument must be an instance of IAuditableHandle

so try, projectArea.getItemHandle()

are you developing in Eclipse?


Abraham Ayorinde commented Jul 27 '16, 12:30 p.m.

 Yes.  I'm developing in RTC (it's an eclipse based ide).


Perhaps you can direct me to information about all the API's and perhaps I can figure it out that way.  That's been my biggest problem, I'm not even sure what is really what, so I am trying to make sense of everything by copying the code samples I find.

But I would still encourage everyone to try finding an explicit answer.


sam detweiler commented Jul 27 '16, 1:04 p.m.

Some of the api is documented in the javadoc you can get from the download site..
not all, none of the server side, and NO logic info at all.


Abraham Ayorinde commented Jul 27 '16, 3:00 p.m.

 Ralph Schoon can you help me?  I know you can. :)

showing 5 of 7 show 2 more comments

permanent link
Ralph Schoon (58.0k23642) | answered Jul 28 '16, 2:08 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
You can find examples here: https://rsjazz.wordpress.com/ , so help yourself. There is example code for querying. You have a debugger, you have instanceof. See what types you have. Looking at the code does not always help.

Comments
Abraham Ayorinde commented Aug 02 '16, 8:10 a.m.

How am I supposed to debug when I don't have the API source code?

If I'm not mistaken, your query examples are for the server side of things.  I'm looking for something on the client side.


Ralph Schoon commented Aug 02 '16, 8:15 a.m. | edited Aug 02 '16, 8:22 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

You should really really carefully follow https://rsjazz.wordpress.com/2015/09/30/learning-to-fly-getting-started-with-the-rtc-java-apis/ and do the Extensions Workshop. Then you could debug using the SDK. The SDK contains the API source code. If you can't, forget trying to write extensions.

My Query examples are client as well as server side and the SDK is also client side and allows debugging both areas. You can learn that in the extensions workshop and in said couple of posts mentioned above.


permanent link
Abraham Ayorinde (112) | answered Aug 02 '16, 10:05 a.m.
 I happened to have searched the board for some keywords and I see that this has been an existing problem, for some at least, since 2011.  Ralph I believe you even suggested that the individual who first raised the problem create a work ticket because something is really wrong.

Anyway, the individual Zybnek Vavros discovered that if he adds a dependency to jaxen as the xml parser then the issue goes away.

(The original question can be found here: https://jazz.net/forum/questions/66113/server-problem-with-iauditableclient)
<dependency>

<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>

Comments
Ralph Schoon commented Aug 02 '16, 10:12 a.m. | edited Aug 02 '16, 10:15 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

No, the user reports that the error starts occurring if they use that XML parser and goes away if the XML parser gets removed from the dependencies or they use a newer version.

Yes, I have seen issues like that as well. It is almost impossible to find that in a forum question. A work item usually does not help either.

Sometimes you can find hints on stackoverflow or Eclipse.org. It is always a good idea to keep the dependencies list clean and small.


Abraham Ayorinde commented Aug 02 '16, 10:17 a.m.

Actually he said that the error goes away when he uses version 1.0 FCS of jaxen.


So there's an issue with the xml parser nevertheless.


Ralph Schoon commented Aug 02 '16, 10:22 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

But that is not our parser it is some other parser he used.


permanent link
sam detweiler (12.4k6180201) | answered Aug 02 '16, 11:38 a.m.
edited Aug 02 '16, 12:15 p.m.
so, here is my little sample, using your code.. works..
this took about 30 minutes to put together, using previous code I had
(published here https://jazz.net/forum/questions/94776/assertionfailedexception-problem-with-getting-the-values-of-attributes a LONG time ago),
ralphs blog, and hints from eclipse.
I have never constructed a query before.

takes repo url, userid, password, project name and user_name_to_find..

only does 'owner'

package com.sd.tools;

import java.net.URI;

import com.ibm.team.process.client.IProcessClientService;
import com.ibm.team.process.common.IProjectArea;
import com.ibm.team.repository.client.ITeamRepository;
import com.ibm.team.repository.client.TeamPlatform;
import com.ibm.team.repository.client.ITeamRepository.ILoginHandler;
import com.ibm.team.repository.client.ITeamRepository.ILoginHandler.ILoginInfo;
import com.ibm.team.repository.common.IContributor;
import com.ibm.team.repository.common.TeamRepositoryException;

import com.ibm.team.workitem.client.IAuditableClient;
import com.ibm.team.workitem.client.IQueryClient;
import com.ibm.team.workitem.client.IWorkItemClient;
import com.ibm.team.workitem.common.IAuditableCommon;
import com.ibm.team.workitem.common.expression.AttributeExpression;
import com.ibm.team.workitem.common.expression.Expression;
import com.ibm.team.workitem.common.expression.IQueryableAttribute;
import com.ibm.team.workitem.common.expression.QueryableAttributes;
//import com.ibm.team.workitem.common.expression.Term;
import com.ibm.team.workitem.common.model.AttributeOperation;
import com.ibm.team.workitem.common.model.IWorkItem;
import com.ibm.team.workitem.common.query.IQueryResult;

public class QueryUser {
    private static class mylog implements org.eclipse.core.runtime.IProgressMonitor
    {

        public void beginTask(String arg0, int arg1)
        {
            // TODO Auto-generated method stub

        }

        public void done()
        {
            // TODO Auto-generated method stub

        }

        public void internalWorked(double arg0)
        {
            // TODO Auto-generated method stub

        }

        public boolean isCanceled()
        {
            // TODO Auto-generated method stub
            return false;
        }

        public void setCanceled(boolean arg0)
        {
            // TODO Auto-generated method stub

        }

        public void setTaskName(String arg0)
        {
            // TODO Auto-generated method stub

        }

        public void subTask(String arg0)
        {
            // TODO Auto-generated method stub

        }

        public void worked(int arg0)
        {
            // TODO Auto-generated method stub

        }

    }
    private static class LoginHandler implements ILoginHandler, ILoginInfo
    {

        private String fUserId;
        private String fPassword;

        private LoginHandler(String userId, String password)
        {
            fUserId = userId;
            fPassword = password;
        }

        public String getUserId()
        {
            return fUserId;
        }

        public String getPassword()
        {
            return fPassword;
        }

        public ILoginInfo challenge(ITeamRepository repository)
        {
            return this;
        }
    }
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        boolean debug = false;
        String repositoryURI = args[0];
        String userId = args[1];
        String password = args[2];
        String projectAreaName = args[3];
        String queryUserid = args[4];
        mylog monitor = new mylog();
        TeamPlatform.startup();
        if (debug)
            System.out.println("platform started\n");
       
        ITeamRepository teamRepository = TeamPlatform
                .getTeamRepositoryService().getTeamRepository(repositoryURI);
        if (debug)
            System.out.println("logging in\n");
        teamRepository.registerLoginHandler(new LoginHandler(userId, password));
        try {
            teamRepository.login(null);

            if (debug)
                System.out.println("logged in\n");
       
        URI uri = URI.create(projectAreaName.replaceAll(" ", "%20"));

        IProjectArea projectArea = null;

        IProcessClientService processClient = (IProcessClientService) teamRepository
                .getClientLibrary(IProcessClientService.class);
        projectArea = (IProjectArea) processClient.findProcessArea(uri,
                    null, null);
        IAuditableClient auditableClient = (IAuditableClient) teamRepository
                .getClientLibrary(IAuditableClient.class);
        IWorkItemClient workItemClient = (IWorkItemClient) teamRepository
                .getClientLibrary(IWorkItemClient.class);       
        IQueryClient queryClient = workItemClient.getQueryClient();
       
        IAuditableCommon auditableCommon = (IAuditableCommon) auditableClient.getTeamRepository().getClientLibrary(IAuditableCommon.class);
        IQueryableAttribute attribute = QueryableAttributes.getFactory(
                    IWorkItem.ITEM_TYPE).findAttribute(projectArea,
                    IWorkItem.OWNER_PROPERTY, auditableCommon, monitor);
         
        IContributor dude_user =  teamRepository.contributorManager().fetchContributorByUserId(queryUserid, null);
         
        Expression isOwner = new AttributeExpression(attribute,
                    AttributeOperation.EQUALS, dude_user);   
           
        IQueryResult qr =queryClient.getResolvedExpressionResults(projectArea, isOwner, IWorkItem.SMALL_PROFILE);

            System.out.println("number of items returned="+qr.getResultSize(monitor).getTotalAvailable());

        } catch (TeamRepositoryException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}


Comments
Ralph Schoon commented Aug 02 '16, 12:44 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Thanks as always Sam. I had rather him fixing his environment for debugging. That is the bigger problem, I think.


sam detweiler commented Aug 02 '16, 3:36 p.m.

I understand.. but this is SO easy.. make a user library for the plain javalibs. and one for the sdk libs, and a third for the planning libs (apt...)..

then include the right one as needed..

then its debug like any java app.   I found two places that are ugly ..
1. if the projectarea handle is null (not found), then you get an assertion error,
instead of a useful exception.  the assertion doesn't says project is null.
2. if the object into the query (IContributor in this case) is null (not found), you also get an assertion error.. also doesn't say expression object is null

Jazz developers, PLEASE don't use asserts..  throw useful exceptions..
plugins are a lot more challenging..


Ralph Schoon commented Aug 03 '16, 3:00 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I only setup the SDK and create a user library for the plain Java API. As explained in my getting started. Then use a plugin to make PDE show the source for plain java.

Your answer


Register or to post your answer.