查詢是用 SPARQL 查詢語言寫成。(SPARQL 是「已鏈結生命週期資料」的查詢語言。)因此,您必須知道 SPARQL 查詢語言,才能從頭開始建立查詢。
下列步驟顯示如何建立和執行三項自訂查詢。每一個查詢都有加上註釋,因此您可以自訂它供自己使用。
下列範例顯示如何查詢指派給 Susan 並已開啟的所有工程變更要求。
指派給 Susan 並已開啟的 ECR
# Name: Open ECRs assigned to Susan
# Description: Show all open ECRs assigned to Susan
# Prefixes used in this query
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX oslc_cm: <http://open-services.net/ns/cm#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?cr ?title ?contrib
WHERE
{
# Find all ECRs - in this example, we find work items of type "Task"; change this to the type of work item you use
?cr rdf:type oslc_cm:ChangeRequest ;
dcterms:type "Task"^^xsd:string ;
dcterms:title ?title ;
dcterms:contributor ?contrib .
# Change the name string to match the user name you want
FILTER regex(str(?contrib),"susan")
# Find open CRs (those with status that is none of closed, fixed, or verified)
# You can adjust this to use any combination of the OSLC CM state predicates
# oslc_cm:closed, oslc_cm:inprogress, oslc_cm:fixed, oslc_cm:approved, oslc_cm:reviewed, and oslc_cm:verified
{
?cr oslc_cm:closed "false"^^xsd:boolean ;
oslc_cm:fixed "false"^^xsd:boolean .
}
# for example, the following alternative to the above clause would find CRs that are either in progress or not closed:
# {
# { ?cr oslc_cm:inprogress "true"^^xsd:boolean } UNION { ?cr oslc_cm:closed "false"^^xsd:boolean }
# }
}
下列範例顯示如何查詢失敗並指派給我的測試案例。
失敗的測試
# Name: Failing tests
# Descriptions: Testcases that fail and are assigned to me
# Prefixes used in this query
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX oslc_qm: <http://open-services.net/ns/qm#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?testcase ?title
WHERE
{
# Find failing test results, and their owning testcase
?testResult rdf:type oslc_qm:TestResult ;
oslc_qm:status "com.ibm.rqm.execution.common.state.failed"^^xsd:string ;
oslc_qm:reportsOnTestCase ?testcase .
# Select just the testcases assigned to me
# Change the name string to match the user name you want
?testcase dcterms:contributor ?user.
FILTER regex(str(?user), "tony")
# Find the matching testcase titles
?testcase dcterms:title ?title .
}
下列範例顯示如何查詢受變更要求的變更所影響的構件。
受 CR 的變更所影響的構件
# Description: Find artifacts impacted by a change to a Change Request
# Follows links such as CR->tracks->REQ->[elaboratedBy->REQ | specifiedBy->REQ]->[verifiedBy->TC | elaboratedBy->ME]
# Prefixes used in this query
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX oslc_cm: <http://open-services.net/ns/cm#>
PREFIX oslc_rm: <http://open-services.net/ns/rm#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?cr ?type ?title ?owner
WHERE
{
?cr a oslc_cm:ChangeRequest ;
dcterms:identifier ?id ;
(oslc_cm:tracksRequirement|oslc_rm:trackedBy|oslc_rm:elaboratedBy|oslc_rm:specifiedBy|oslc_rm:validatedBy)* ?uri .
?uri dcterms:title ?title
OPTIONAL
{
?uri rdf:type/rdfs:label ?type ;
}
OPTIONAL
{
# This part of the query picks up user names from either JTS user URIs or from DOORS FOAF entries,
# and avoids getting the DOORS user URI as well as that FOAF entry
{
?uri dcterms:contributor/foaf:name ?owner
}
UNION
{
?uri dcterms:contributor ?owner
FILTER NOT EXISTS { ?owner foaf:name ?x }
}
}
}
# Either provide one or more work item ID numbers here,
# or remove or comment out the entire VALUES section to look at all work items
VALUES ?id
{
"626"^^xsd:string
"627"^^xsd:string
}