Skip to content

Commit

Permalink
Merge pull request #50 from dixudx/development
Browse files Browse the repository at this point in the history
doc and tests for saved queries
  • Loading branch information
dixudx committed Sep 10, 2015
2 parents e75a394 + bf3ea9f commit 244a633
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 7 deletions.
4 changes: 4 additions & 0 deletions doc/source/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ Models

.. autoclass:: rtcclient.models.Comment
:members:


.. autoclass:: rtcclient.models.SavedQuery
:members:
39 changes: 38 additions & 1 deletion doc/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,46 @@ will be fetched.
# below query string means: query all the workitems with title "use case 1"
>>> myquerystr = 'dc:title="use case 1"'
>>> returned_prop = "dc:title,dc:identifier,rtc_cm:state,rtc_cm:ownedBy"
>>> queried_wis = myquery.queryWorkitems(query_str=myquerystr,
>>> queried_wis = myquery.queryWorkitems(myquerystr,
projectarea_name=projectarea_name,
returned_properties=returned_prop)

More detailed and advanced syntax on querying, please refer to
:ref:`query syntax <query_syntax>`.


Query Workitems by Saved Query
------------------------------

You may have created several customized queries through RTC Web GUI or got
some saved queries created by other team members. Using these saved queries

>>> myquery = myclient.query # query class
>>> saved_query_url = 'http://test.url:9443/jazz/xxxxxxxx&id=xxxxx'
>>> projectarea_name = "my_projectarea_name"
# get all saved queries
# WARNING: now the RTC server cannot correctly list all the saved queries
# It seems to be a bug of RTC. Recommend using `runSavedQueryByUrl` to
# query all the workitems if the query is saved.
>>> allsavedqueries = myquery.getAllSavedQueries(projectarea_name=projectarea_name)
# saved queries created by [email protected]
>>> allsavedqueries = myquery.getAllSavedQueries(projectarea_name=projectarea_name,
creator="[email protected]")
# my saved queries
>>> mysavedqueries = myquery.getMySavedQueries(projectarea_name=projectarea_name)
>>> mysavedquery = mysavedqueries[0]
>>> returned_prop = "dc:title,dc:identifier,rtc_cm:state,rtc_cm:ownedBy"
>>> queried_wis = myquery.runSavedQuery(mysavedquery,
returned_properties=returned_prop)


Query Workitems by Saved Query Url
----------------------------------

You can also query all the workitems directly using your saved query's url.

>>> myquery = myclient.query # query class
>>> saved_query_url = 'http://test.url:9443/jazz/xxxxxxxx&id=xxxxx'
>>> returned_prop = "dc:title,dc:identifier,rtc_cm:state,rtc_cm:ownedBy"
>>> queried_wis = myquery.runSavedQueryByUrl(saved_query_url,
returned_properties=returned_prop)
23 changes: 20 additions & 3 deletions rtcclient/query.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from rtcclient.base import RTCBase
import logging
from rtcclient import urlquote
from rtcclient.models import SavedQuery
from rtcclient import exception


class Query(RTCBase):
Expand Down Expand Up @@ -102,13 +102,17 @@ def getAllSavedQueries(self, projectarea_id=None, projectarea_name=None,
fcreator = self.rtc_obj.getOwnedBy(creator).url
filter_rule = [("dc:creator", "@rdf:resource",
fcreator)]
self.log.debug("Add rules for fetching all saved queries: "
"created by %s", creator)

if saved_query_name is not None:
ftitle_rule = ("dc:title", None, saved_query_name)
if filter_rule is None:
filter_rule = [ftitle_rule]
else:
filter_rule.append(ftitle_rule)
self.log.debug("Add rules for fetching all saved queries: "
"saved query title is %s", saved_query_name)

return (self.rtc_obj
._get_paged_resources("SavedQuery",
Expand Down Expand Up @@ -140,6 +144,8 @@ def getSavedQueriesByName(self, saved_query_name, projectarea_id=None,
:rtype: list
"""

self.log.info("Start to fetch all saved queries with the name %s",
saved_query_name)
return self.getAllSavedQueries(projectarea_id=projectarea_id,
projectarea_name=projectarea_name,
creator=creator,
Expand Down Expand Up @@ -168,6 +174,7 @@ def getMySavedQueries(self, projectarea_id=None, projectarea_name=None,
:rtype: list
"""

self.log.info("Start to fetch my saved queries")
return self.getAllSavedQueries(projectarea_id=projectarea_id,
projectarea_name=projectarea_name,
creator=self.rtc_obj.username,
Expand All @@ -184,7 +191,12 @@ def runSavedQueryByUrl(self, saved_query_url, returned_properties=None):
:rtype: list
"""

saved_query_id = saved_query_url.split("=")[-1]
try:
saved_query_id = saved_query_url.split("=")[-1]
except:
error_msg = "No saved query id is found in the url"
self.log.error(error_msg)
raise exception.BadValue(error_msg)
return self._runSavedQuery(saved_query_id,
returned_properties=returned_properties)

Expand All @@ -201,7 +213,12 @@ def runSavedQuery(self, saved_query_obj, returned_properties=None):
:rtype: list
"""

saved_query_id = saved_query_obj.results.split("/")[-2]
try:
saved_query_id = saved_query_obj.results.split("/")[-2]
except:
error_msg = "Cannot get the correct saved query id"
self.log.error(error_msg)
raise exception.RTCException(error_msg)
return self._runSavedQuery(saved_query_id,
returned_properties=returned_properties)

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ description-file = README.rst
keywords =
rtcclient
Rational Team Concert
RTC
license = Apache License, Version 2.0
home-page = https://github.com/dixudx/rtcclient
classifier =
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ def rtcclient(mocker):
mocked_headers.return_value = mock_resp

return RTCClient(url="http://test.url:9443/jazz",
username="user",
username="[email protected]",
password="password",
searchpath=_search_path)
32 changes: 32 additions & 0 deletions tests/fixtures/savedqueries.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<oslc_cm:Collection xmlns:oslc_cm="http://open-services.net/xmlns/cm/1.0/" xmlns:dc="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rtc_cm="http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/" oslc_cm:totalCount="3">
<rtc_cm:Query rdf:resource="http://test.url:9443/jazz/resource/itemOid/com.ibm.team.workitem.query.QueryDescriptor/_1CR5MMfiEd6yW_0tvNlbrw">
<dc:identifier/>
<dc:title>Closed created by me</dc:title>
<rtc_cm:projectArea rdf:resource="http://test.url:9443/jazz/oslc/projectareas/_0qMJUMfiEd6yW_0tvNlbrw"/>
<dc:description>Work items I have created which have been resolved</dc:description>
<rtc_cm:results oslc_cm:collref="http://test.url:9443/jazz/oslc/queries/_1CR5MMfiEd6yW_0tvNlbrw/rtc_cm:results"/>
<dc:creator rdf:resource="http://test.url:9443/jts/users/tester1%40email.com"/>
<dc:modified>2014-02-22T01:23:47.490Z</dc:modified>
<rtc_cm:modifiedBy rdf:resource="http://test.url:9443/jts/users/ADMIN"/>
</rtc_cm:Query>
<rtc_cm:Query rdf:resource="http://test.url:9443/jazz/resource/itemOid/com.ibm.team.workitem.query.QueryDescriptor/_1CTHUMfiEd6yW_0tvNlbrw">
<dc:identifier/>
<dc:title>Open Track Build Items</dc:title>
<rtc_cm:projectArea rdf:resource="http://test.url:9443/jazz/oslc/projectareas/_0qMJUMfiEd6yW_0tvNlbrw"/>
<dc:description>All unresolved Track Build Items</dc:description>
<rtc_cm:results oslc_cm:collref="http://test.url:9443/jazz/oslc/queries/_1CTHUMfiEd6yW_0tvNlbrw/rtc_cm:results"/>
<dc:creator rdf:resource="http://test.url:9443/jts/users/tester2%40email.com"/>
<dc:modified>2014-02-22T01:23:47.495Z</dc:modified>
<rtc_cm:modifiedBy rdf:resource="http://test.url:9443/jts/users/ADMIN"/>
</rtc_cm:Query>
<rtc_cm:Query rdf:resource="http://test.url:9443/jazz/resource/itemOid/com.ibm.team.workitem.query.QueryDescriptor/_1CU8gMfiEd6yW_0tvNlbrw">
<dc:identifier/>
<dc:title>Open Adoptions</dc:title>
<rtc_cm:projectArea rdf:resource="http://test.url:9443/jazz/oslc/projectareas/_CuZu0HUwEeKicpXBddtqNA"/>
<dc:description/>
<rtc_cm:results oslc_cm:collref="http://test.url:9443/jazz/oslc/queries/_1CU8gMfiEd6yW_0tvNlbrw/rtc_cm:results"/>
<dc:creator rdf:resource="http://test.url:9443/jts/users/tester2%40email.com"/>
<dc:modified>2014-02-22T01:23:47.499Z</dc:modified>
<rtc_cm:modifiedBy rdf:resource="http://test.url:9443/jts/users/ADMIN"/>
</rtc_cm:Query>
</oslc_cm:Collection>
Loading

0 comments on commit 244a633

Please sign in to comment.