Querying Jazz RTC Work Items via OSLC

2020-07-27 06:04发布

I am able to get workitem if I know the ticket id using following request https://example.com:8081/ccm/oslc/workitems/37702.json. I want to query RTC to get all wrorkitems owned by a gievn user or based on tags.

I am using the folllowing query to get data but unable to get the details.

Search based on owner of workitem https://example.com:8081/ccm/oslc?oslc_cm.query=dc:owner="abc@gmail.com"

Search based on tags https://example.com:8081/ccm/oslc?oslc_cm.query=dc:subject="mc"

3条回答
贪生不怕死
2楼-- · 2020-07-27 06:27

Another way of getting data out of jazz is using SPARQL. You can find the SPARQL endpoint from the rootservices (GET h_ttps://jazzserver:9443/ccm/rootservices) by looking for jp06:query.

While I'm sure it's possible to construct the SPARQL by hand, it is far easier to use the new-in-6.0 report builder, using LQE as the data source. Go to the format->Advanced area to see the generated SPARQL, and should you feel the urge you can edit there although you lose the graphical query building when you do that. It's a few clicks to create a SPARQL query which will return all the WIs created by Fred (using his user ID fred) like:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX oslc_config: <http://open-services.net/ns/config#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX oslc: <http://open-services.net/ns/core#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX oslc_cm: <http://open-services.net/ns/cm#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX process: <http://jazz.net/ns/process#>

SELECT DISTINCT 
    ?rtc_cm_WorkItem1_projectArea
    ?rtc_cm_WorkItem1_shortId
    ?rtc_cm_WorkItem1_title
    ?rtc_cm_WorkItem1
    ?rtc_cm_WorkItem1_creator
WHERE {
  VALUES ( ?rtc_cm_WorkItem1_creator_enumValue )
  {
    ( <https://jazzserver:9443/jts/users/fred> )
  }
  ?rtc_cm_WorkItem1_uri rdf:type oslc_cm:ChangeRequest.
  ?rtc_cm_WorkItem1_uri dcterms:creator ?rtc_cm_WorkItem1_creator_enumValue.
  OPTIONAL {?rtc_cm_WorkItem1_creator_enumValue foaf:name ?rtc_cm_WorkItem1_creator_enumName.}
  ?rtc_cm_WorkItem1_uri dcterms:title ?rtc_cm_WorkItem1_title.
  OPTIONAL {
    ?rtc_cm_WorkItem1_uri process:projectArea ?rtc_cm_WorkItem1_projectArea_enumValue.
    OPTIONAL {?rtc_cm_WorkItem1_projectArea_enumValue rdfs:label|dcterms:title ?rtc_cm_WorkItem1_projectArea_enumName.}
  }
  OPTIONAL {?rtc_cm_WorkItem1_uri oslc:shortId ?rtc_cm_WorkItem1_shortId.}
  OPTIONAL {?rtc_cm_WorkItem1_ver dcterms:isVersionOf ?rtc_cm_WorkItem1_uri; rdf:type oslc_config:VersionResource.}
  OPTIONAL {?rtc_cm_WorkItem1_uri process:projectArea ?rtc_cm_WorkItem1_paUri.}
  FILTER( !bound(?rtc_cm_WorkItem1_paUri) || NOT EXISTS{ ?rtc_cm_WorkItem1_paUri oslc:archived true. })
  BIND( IF (bound(?rtc_cm_WorkItem1_ver), concat(str(?rtc_cm_WorkItem1_uri), "?oslc_config.context="), ?rtc_cm_WorkItem1_uri) as ?rtc_cm_WorkItem1)
  BIND( COALESCE(?rtc_cm_WorkItem1_creator_enumName, ?rtc_cm_WorkItem1_creator_enumValue) as ?rtc_cm_WorkItem1_creator)
  BIND( COALESCE(?rtc_cm_WorkItem1_projectArea_enumName, ?rtc_cm_WorkItem1_projectArea_enumValue) as ?rtc_cm_WorkItem1_projectArea)
}

Then, to get the result as an Atom feed, do a GET from h_ttps:/jazzserver:9443/ccm/query with parameter query=YourSPARQL which must be encoded of course.

I'm sure it's not to hard to build this simple query by hand, but Report Builder makes it trivial, and also it understands the metamodel so helps with selecting relationships and attribute names - less errors because you don't have to (mis)type these. Also you can publish/share the queries, and use them to populate dashboards :-)

Hopefully one of these three methods will meet your needs.

查看更多
兄弟一词,经得起流年.
3楼-- · 2020-07-27 06:27

The reportable REST API might offer another way of getting the info you want: https://jazz.net/wiki/bin/view/Main/ReportsRESTAPI

For example, this query returns XML list of work item IDs created by Fred: h_ttps://jazzserver:9443/ccm/rpt/repository/workitem?fields=workitem/workItem[creator/name=%27Fred%27]/id

Note the Fred is the user's name, NOT the user ID (user ID is used to login). In the oslc example I posted, the user id is used.

查看更多
相关推荐>>
4楼-- · 2020-07-27 06:37

ADDITION: There is a lot more detail on OSLC queries on CCM for work items here https://jazz.net/wiki/bin/view/Main/ResourceOrientedWorkItemAPIv2#Querying_Work_Items

Not sure about your example, but what I show below works in Jazz 6.0. There may be other ways to do this. You might get more responses asking on jazz.net.

BTW I've had to obfuscate/mutilate the urls in this post because I don't have enough rep points. They aren't real URLs anyway. Fix by deleting _ from h_ttps.

There is an OSLC spec for CM query: http://open-services.net/bin/view/Main/OSLCCoreSpecQuery

To apply a query to a project area, first you have to get the project area identifier, you get that from the list of projects, and you get the URL to get the list of projects by querying the rootservices.

In this example my server is on jazzserver:9443. All the GETs need a header Accept value application/xml. It's probably possible to get JSON format results.

So it goes like this:

  1. You probably have to authenticate your client with the server before continuing

  2. GET https://jazzserver:9443/ccm/rootservices

XML result, extract the url for the list of project areas in tag jp06:projectAreas attribute rdf:resource e.g. <jp06:projectAreas rdf:resource="h_ttps://jazzserver:9443/ccm/process/project-areas"/>

  1. GET h_ttps://jazzserver:9443/ccm/process/project-areas

XML result, extract the project URL from text content of jp06:url nested as follows:

jp06:project-areas... jp06:project-area... jp06:url

In my case this is h_ttps://jazzserver:9443/ccm/process/project-areas/_pXsVsRmqEeWdnsGEjrjqng

The _pXsVsRmqEeWdnsGEjrjqng is the project identifier.

  1. Execute the query by GET from the project area list of workitems like this h_ttps://jazzserver:9443/ccm/oslc/contexts/_pXsVsRmqEeWdnsGEjrjqng/workitems?oslc.query=dc.owner="fred"

HOWEVER NOTE the step 4 URL is simplified - specifically, the parameter value dc.owner="fred" has to be encoded so the " and = aren't misinterpreted by your browser as they would be if you simply paste that URL into your browser address bar - I did this query in POSTER by putting the parameter name/value into the parameters.

HTH

查看更多
登录 后发表回答