Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Querying with Plain Java Client API problem :(

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); 

0 votes



4 answers

Permanent link
'term' is not an Expression..
you want either Expression1 or Expression2..

0 votes

Comments

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

Thanks anyway.

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

My definition is as below.

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

ok, the api and the error say handle.

Argument must be an instance of IAuditableHandle

so try, projectArea.getItemHandle()

are you developing in Eclipse?

 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.

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.

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

showing 5 of 7 show 2 more comments

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

0 votes

Comments

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.

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

0 votes

Comments

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.

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.

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


Permanent link
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();
        }
    }
}

0 votes

Comments

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

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

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

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,952
× 369

Question asked: Jul 26 '16, 5:01 p.m.

Question was seen: 3,855 times

Last updated: Aug 03 '16, 3:00 a.m.

Confirmation Cancel Confirm