Rally Software

Expand all | Collapse all

JAVA REST API fails on workspace lookup, sometimes...

Jump to Best Answer
  • 1.  JAVA REST API fails on workspace lookup, sometimes...

    Posted 02-14-2019 02:55 PM

    Looking to retreive a Workspace URL for a given workspace name.  using the current workspace name in the parms.    Problems is, the query fails when there are special characters (I think it is the special characters), in my case a dash '-' in the Workspace Name string.  I've tryed delimiting by double-quote, but that gives me a parse error.  Thoughts appreciated...

     

       public static String getWorkspaceURL (RallyRestApi restApi, ParametersBean parms) {
            
            String workspaceURL = new String();
            
            try {    
                QueryRequest query = new QueryRequest("Workspace");
                query.setFetch(new Fetch(new String[] {"_ref"}));
                query.setPageSize(2);
                query.setLimit(2);
                query.setScopedDown(false);
                query.setScopedUp(false);
                query.setQueryFilter((new QueryFilter("Name", "=",  parms.getCurrentWorkspace())));
                QueryResponse response = restApi.query(query);

     

                if (response.wasSuccessful()) {
                    JsonArray tempProject = response.getResults();
                    JsonObject obj1 = tempProject.get(0).getAsJsonObject();
                    workspaceURL = obj1.get("_ref").getAsString();
                    ;
                } else {
                    logger.info("The following errors occurred: ");
                    for (String err : response.getErrors()) {
                        logger.error("\t" + err);
                    }
                    logger.error("Rally API Call Error Occurred");
                    logger.error("REST Call: " + query.toString());
                    System.exit(1);
                }
            } catch (Exception e) {
                logger.error("Rally: Error getting WorkspaceURL for " + parms.getCurrentWorkspace());
                e.printStackTrace();
                System.exit(1);
            }
            return (workspaceURL);
        }

     

     


  • 2.  Re: JAVA REST API fails on workspace lookup, sometimes...

    Broadcom Employee
    Posted 02-15-2019 04:42 PM

    Hi! I'm a little rusty on my App SDK, but there's a function "toQueryString" on Objects. If you use that, it might get the encoding right for you. Details at https://docs.ca.com/ca-agile-central/saas/apps/2.1/doc/#!/api/Ext.Object-method-toQueryString. For how you're calling the API, is there an equivalent. A hyphen should be fine for a URL, but maybe there's a different character?

     

    It might help also if you share the query that the code generates when it breaks, or try putting that directly into your web browser and play with it to try to identify the correct alternative.



  • 3.  Re: JAVA REST API fails on workspace lookup, sometimes...
    Best Answer

    Broadcom Employee
    Posted 02-15-2019 04:55 PM

    Hi.

     

    If my understanding is correct:  You are trying to pass a workspace's name as a query string argument and then pull up the workspace object based on that name and then find data/details of that workspace.

     

    If that is your intent then it can't be done in the way you're attempting. What happens is that since any WSAPI call (which is what essentially is executed by your Java classes) is executed within the confines of a workspace then you can't fetch workspace objects other than the one in your context. I presume that this code will work if you attempt to pull up information of the default workspace of the user who is executing your calls.

     

    So, essentially WSAPI is limited to only the workspace endpoint object that matches the workspace object in your context.

     

    The way to overcome this is to use the Subscription endpoint where you can find your subscription's workspaces, then you shall switch your context to that target workspace to be able to query it further.

     

    Here a tech doc that explains it:

    Agile Central - WSAPI: Not finding workspaces when - CA Knowledge 

     

    Let us know if helped.

     

    Sagi



  • 4.  Re: JAVA REST API fails on workspace lookup, sometimes...

    Posted 02-20-2019 12:13 PM

    Thanks Sagi.  Exactly the problem.  I'll collect the available workspace Name and _ref for the user then scan the list internally for the Workspace in question, then I'll use the _ref for the follow-on queries/gets.



  • 5.  Re: JAVA REST API fails on workspace lookup, sometimes...

    Posted 02-20-2019 12:13 PM

    Got it. Thanks for the response.